Unable to load image

rDramaAdvent of Code Day 4: Back on Track Edition

Summary for those just joining us:

Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!

Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app

What did you think about today's problem?

https://adventofcode.com/2023

Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)

21
Jump in the discussion.

No email address required.

It was easier than yesterday, managed to complete it with much fewer lines

https://i.rdrama.net/images/17017020489007528.webp

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17016793012168365.webp

Tried to use the new std::views std library which is kinda useful, but gives absolutely unhelpful error messages:

<g>\>[build] FAILED: day04/CMakeFiles/day04.dir/main.cpp.o </g>
[build] /usr/bin/ccache /usr/bin/clang++-17 -DINPUT_DIR=\"/home/ihsoy/adventofcode/inputs/\" -DSCN_HEADER_ONLY=0 -I/home/ihsoy/adventofcode/.cache/CPM/scn/ee384e4dfeb40efb93d1b2a397a81e8027027f77/include -stdlib=libc++ -g -std=c++23 -fcolor-diagnostics -MD -MT day04/CMakeFiles/day04.dir/main.cpp.o -MF day04/CMakeFiles/day04.dir/main.cpp.o.d -o day04/CMakeFiles/day04.dir/main.cpp.o -c /home/ihsoy/adventofcode/day04/main.cpp
[build] /home/ihsoy/adventofcode/day04/main.cpp:53:95: error: invalid operands to binary expression ('std::__1::ranges::transform_view<std::__1::ranges::filter_view<std::__1::ranges::split_view<std::__1::ranges::subrange<const char *>, std::__1::ranges::single_view<char>>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)>' and 'int')
[build]    53 |         auto numbers_won = numbers_played | std::views::filter([](https://auto number) { return number%2==0; });
[build]       |                                                                                         ~~~~~~^~
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:337:10: note: in instantiation of function template specialization 'day03::solution(const std::vector<std::string> &)::(anonymous class)::operator()<std::__1::ranges::transform_view<std::__1::ranges::filter_view<std::__1::ranges::split_view<std::__1::ranges::subrange<const char *>, std::__1::ranges::single_view<char>>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)>>' requested here
[build]   337 | decltype(std::declval<_Fp>()(std::declval<_Args>()...))
[build]       |          ^
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:347:19: note: while substituting deduced template arguments into function template '__invoke' [with _Fp = (lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64) &, _Args = <std::__1::ranges::transform_view<std::__1::ranges::filter_view<std::__1::ranges::split_view<std::__1::ranges::subrange<const char *>, std::__1::ranges::single_view<char>>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)> &>]
[build]   347 |   static decltype(std::__invoke(std::declval<_XFp>(), std::declval<_XArgs>()...)) __try_call(int);
[build]       |                   ^
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:353:28: note: while substituting deduced template arguments into function template '__try_call' [with _XFp = (lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64) &, _XArgs = (no value)]
[build]   353 |   using _Result = decltype(__try_call<_Fp, _Args...>(0));
[build]       |                            ^
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:401:24: note: in instantiation of template class 'std::__invokable_r<void, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64) &, std::__1::ranges::transform_view<std::__1::ranges::filter_view<std::__1::ranges::split_view<std::__1::ranges::subrange<const char *>, std::__1::ranges::single_view<char>>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)> &>' requested here
[build]   401 |     : public enable_if<__invokable<_Fp, _Args...>::value, typename __invokable_r<void, _Fp, _Args...>::_Result> {};
[build]       |                        ^
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:452:45: note: in instantiation of template class 'std::__invoke_of<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64) &, std::__1::ranges::transform_view<std::__1::ranges::filter_view<std::__1::ranges::split_view<std::__1::ranges::subrange<const char *>, std::__1::ranges::single_view<char>>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>, (lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)> &>' requested here
[build]   452 | struct _LIBCPP_TEMPLATE_VIS invoke_result : __invoke_of<_Fn, _Args...> {};
[build]       |                                             ^
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__type_traits/invoke.h:455:1: note: (skipping 39 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
[build]   455 | using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
[build]       | ^
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__concepts/invocable.h:27:21: note: while substituting template arguments into constraint expression here
[build]    27 | concept invocable = requires(_Fn&& __fn, _Args&&... __args) {
[build]       |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build]    28 |   _VSTD::invoke(_VSTD::forward<_Fn>(__fn), _VSTD::forward<_Args>(__args)...); // not required to be equality preserving
[build]       |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build]    29 | };
[build]       | <del>
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__ranges/range_adaptor.h:61:18: note: while checking the satisfaction of concept 'invocable<std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__filter::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64)>>>, std::__1::ranges::drop_view<std::__1::ranges::transform_view<std::__1::ranges::split_view<std::string_view, std::__1::ranges::single_view<char>>, std::__range_adaptor_closure_t<std::__compose_t<std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__transform::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)>>>, std::__range_adaptor_closure_t<std::__compose_t<std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__filter::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>>>, std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__split_view::__fn, std::tuple<char>>>>>>>>> &>' requested here
[build]    61 |                  invocable<_Closure, _View>
[build]       |                  ^</del>~~~~~~~~~~~~~~~~~~~~~~~
[build] /usr/lib/llvm-17/bin/../include/c++/v1/__ranges/range_adaptor.h:61:18: note: while substituting template arguments into constraint expression here
[build]    61 |                  invocable<_Closure, _View>
[build]       |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
[build] /home/ihsoy/adventofcode/day04/main.cpp:53:43: note: while checking constraint satisfaction for template 'operator|<std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__filter::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64)>>>>' required here
[build]    53 |         auto numbers_won = numbers_played | std::views::filter([](https://auto number) { return number%2==0; });
[build]       |                                           ^
[build] /home/ihsoy/adventofcode/day04/main.cpp:53:43: note: in instantiation of function template specialization 'std::__1::operator|<std::__1::ranges::drop_view<std::__1::ranges::transform_view<std::__1::ranges::split_view<std::string_view, std::__1::ranges::single_view<char>>, std::__range_adaptor_closure_t<std::__compose_t<std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__transform::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)>>>, std::__range_adaptor_closure_t<std::__compose_t<std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__filter::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>>>, std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__split_view::__fn, std::tuple<char>>>>>>>>> &, std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__filter::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64)>>>>' requested here
[build] /home/ihsoy/adventofcode/day04/main.cpp:53:43: error: invalid operands to binary expression ('invoke_result_t<__range_adaptor_closure_t<__bind_back_t<__fn, tuple<int>>>, transform_view<split_view<string_view, single_view<char>>, __range_adaptor_closure_t<__compose_t<__range_adaptor_closure_t<__bind_back_t<__fn, tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)>>>, __range_adaptor_closure_t<__compose_t<__range_adaptor_closure_t<__bind_back_t<__fn, tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>>>, __range_adaptor_closure_t<__bind_back_t<__fn, tuple<char>>>>>>>> &>' (aka 'std::__1::ranges::drop_view<std::__1::ranges::transform_view<std::__1::ranges::split_view<std::string_view, std::__1::ranges::single_view<char>>, std::__range_adaptor_closure_t<std::__compose_t<std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__transform::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:44:50)>>>, std::__range_adaptor_closure_t<std::__compose_t<std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__filter::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:42:89)>>>, std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__split_view::__fn, std::tuple<char>>>>>>>>>') and '__range_adaptor_closure_t<__bind_back_t<__fn, tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64)>>>' (aka 'std::__range_adaptor_closure_t<std::__bind_back_t<std::__1::ranges::views::__filter::__fn, std::tuple<(lambda at /home/ihsoy/adventofcode/day04/main.cpp:53:64)>>>'))
``
Jump in the discussion.

No email address required.

K

Jump in the discussion.

No email address required.

>c++

>New library

Brought it on yourself tbh :marseyboo#mer:

Jump in the discussion.

No email address required.

I did part two with List<Stack<string>>

lmao can't post code but it took like 3 minutes to run

Jump in the discussion.

No email address required.

I'm surprised he didn't structure it so that you couldn't brute force it. Congrats

Jump in the discussion.

No email address required.

I thought I did something wrong because my debug messages showed the stack 368000 layers deep at card #37 but it went pretty quick after that

Jump in the discussion.

No email address required.

i tried doing a stack and popping cards off the bottom but it got to something like 770,000 cards long after a while and i gave up. i think it might have worked if i fricked off for a few hours but my answer was over 8,000,000 so i didnt bother sticking around to find out if it would or if i would have gotten an indexing error :marseycorner:

Jump in the discussion.

No email address required.

The instructions for 2 were very confusing but the actual puzzle was pretty simple

https://i.rdrama.net/images/17016706421820533.webp

Jump in the discussion.

No email address required.

I was scared that part 2 was going to be some hideous mathematical trick but I trusted that Eric wouldn't do that in day 4 and it was OK.

Jump in the discussion.

No email address required.

I spent more time on part 2 thinking there must be some algorithm I was missing and then like 1 minute going "frick it" and writing a double for loop like apparently everyone else did.

Jump in the discussion.

No email address required.

Usually with these problems I focus on quick and dirty first (timed leaderboards lmao) then after I submit I spend some time thinking about the "right way" when the mind goblins aren't telling me to hurry

Jump in the discussion.

No email address required.

im literally screaming, Easiest one yet

Step 1:

https://i.rdrama.net/images/17016905626014988.webp

Step 2:

https://i.rdrama.net/images/17016905629446063.webp

Jump in the discussion.

No email address required.

Nim is so pretty :marseystars:

Jump in the discussion.

No email address required.

ok so ikr, its like python with a type system thats not been frankensteined where it doesnt belong

im literally screaming, One thing I dont like is that you gotta import so much stuff for basic builtins, like I had to import std/math like just to get the ^ operator

Jump in the discussion.

No email address required.

Another "the hardest part is parsing the input" question :marseyyawn:

s←~⍤∊⍨⊆⊢ ⋄ n←≢r←{⍎¨'|'s 2⊃':'s ⍵}¨⊃⎕NGET'i4.txt'1
⎕←+/⌊2*1-⍨w←+/¨¨∊/¨r
t←n/1 ⋄ w{t⊢←t+(⍵⊃t)×n↑(⍵\0),⍺\1}¨⍳n ⋄ ⎕←+/t
Jump in the discussion.

No email address required.

https://i.rdrama.net/images/17017188622996578.webp

A neat little dynamic programming method of solving it. Just start at the end and use your previous solutions to calculate the current one.

Jump in the discussion.

No email address required.

Alright.. so..... It's been executing for about 3-5 hours now

I'm unable to actually verify that the 2nd part is solved but I'm pretty sure it is

https://i.rdrama.net/images/1701705908425477.webp

Can't tell if

>skill issue

or shell issue :marseythinkorino:

either way I'm gonna switch to php I am not skilled enough to continue with shell lmao


Good ol' php to save the day :marseyembrace:

https://i.rdrama.net/images/1701725161092966.webp

Jump in the discussion.

No email address required.

Sets make this pretty easy

f = open('AOC2023Day4.txt')
import numpy as np
from collections import defaultdict
numscr = defaultdict(lambda: 1)
numscr[1] = 1
lines = f.read().strip().split('\n')
total = 0
i = 1
for line in lines:
   line = line.split(':')[-1].split('|')
   #print(line[1].strip().split(' '))
   winning = set([int(i) for i in line[0].strip().split(' ') if i != ''])
   nums = set([int(i) for i in line[1].strip().split(' ') if i != ''])
   mine = winning.intersection(nums)
   #print(mine)
   add = 0
   i += 1
   if len(mine) > 0:
       add = np.power(2,len(mine)-1)
       for j in range(i,i+len(mine)):
           numscr[j] += numscr[i-1]
   total += add
#print(numscr)
ncards = 0
for i in range(len(lines)):
   ncards += numscr[i]
print(ncards)
print(total)
Jump in the discussion.

No email address required.

I agree with everyone else that the hardest part was understanding what Part 2 wanted

https://i.rdrama.net/images/17016890771493604.webp

I believe the reason to put up with all the type shit cluttering my code is because the filters/maps are lazy eval'd and ready to be parallelised as-is, but I'm wondering if I really care

Jump in the discussion.

No email address required.

yesterday's was really annoying and after four days of string parsing problems, it was pretty easy

https://i.rdrama.net/images/17017188332174833.webp

edit: oh yeah I should have used hash for performance reasons but oh well.

Jump in the discussion.

No email address required.

Day 4 and I already crashed the compiler:

https://i.rdrama.net/images/17016912756115923.webp

Passing anything but an int or string to arrayWith causes an internal compiler error. This includes integer literals.

Jump in the discussion.

No email address required.

I am clinically r-slurred and wasted like 15 minutes repeatedly coding the wrong implementation of what they wanted in the second part, checking the spec, and then modifying my code to a new, still incorrect, behavior

Jump in the discussion.

No email address required.

Hardest part was understanding wtf part 2 wanted me to do. https://i.rdrama.net/images/1701670128120864.webp

Jump in the discussion.

No email address required.

Like day 2 felt easier than day 1, today was easier than yesterday.

Jump in the discussion.

No email address required.

Weekend tasks are usually harder, he's kind like that

Jump in the discussion.

No email address required.

Yeah I think it's planned in a way to try and stop people from burning out before they actually hit their limit

Jump in the discussion.

No email address required.

FRICK c++ I'm done with it after today's expedition into "dude, why isn't my vector erasing" :marseyraging#:

Jump in the discussion.

No email address required.

idk if im burnt out from tutoring bootcampers worse than i am over zoom for 3 hours or if its because i havent had a drink in 3 days but i still have no fricking clue what part 2 is trying to ask me to do so i shamelessly stole that part

https://i.rdrama.net/images/17017189054623787.webp

Jump in the discussion.

No email address required.

The wording is retarded, they should've given a walkthrough.

Cards (you start with 1 of each): 1 1 1 1 1 1

Scores (from part 1): 4 2 2 1 0 0

Position 1: 1 card at this position, each scores 4. So add 1 to each of the next 4 cards.

       v
Cards: 1 1 1 1 1 1
  Add: 0 1 1 1 1 0
  New: 1 2 2 2 2 1

Position 2: 2 cards at this position, each scores 2. So add 2 to each of the next 2 cards.

         v
Cards: 1 2 2 2 2 1
  Add: 0 0 2 2 0 0
  New: 1 2 4 4 2 1

Position 3: 4 cards at this position, each scores 2. So add 4 to each of the next 2 cards.

           v
Cards: 1 2 4 4 2 1
  Add: 0 0 0 4 4 0
  New: 1 2 4 8 6 1

Position 4: 8 cards at this position, each scores 1. So add 8 to each of the next 1 card.

             v
Cards: 1 2 4 8  6 1
  Add: 0 0 0 0  8 0
  New: 1 2 4 8 14 1

Position 5: 14 cards at this position, each scoring 0. So add 14 to each of the next 0 cards (nothing).

                v
Cards: 1 2 4 8 14 1
  Add: 0 0 0 0  0 0
  New: 1 2 4 8 14 1

Position 6: 1 card at this position, each scoring 0. Add nothing.

                  v
Cards: 1 2 4 8 14 1
  Add: 0 0 0 0  0 0
  New: 1 2 4 8 14 1

Final cards: 1 2 4 8 14 1

Sum: 30

Jump in the discussion.

No email address required.

I don't know what you said, because I've seen another human naked.

Jump in the discussion.

No email address required.

it's saying duplicate the subsequent cards for as many "wins" as "current card" has

Card 1 has 4 wins, now Card 1 gets its original point, and cards ( 2 + 3 + 4 + 5 ) get a point because of Card 1's wins.

Onto Card 2, it gets the initial/original point, on top of the 1 point it had received from Card 1. So Card 2 has 2 points. Say it had just 1 win. With just 1 win on Card 2, it gives a point to only the next Card 3. But it does it again for each point it has, and gives Card 3 another point. Now Card 3 has 1 point from Card 1, 1 point from Card 2, and 1 point grom Card 2's repeat. So 3 points.

When Card 3's up, on top of the 3 points it has received, it also gets its initial/original point now that it's up.. so 4 points. But say it didn't have any wins, and basically passes 0 points down, four times. The game is still on because the next Card 4 had received a point from the first Card 1 and has 3 wins.

Card 4 has the 1 point from Card 1, and gets its initial/original point, so 2 points. It gives the next 3 cards a point, then since it's got one more copy it does it again so Card 5, 6, and 7 are given a total of 2 points each. Continues on until there's a dead end, then u sum all the points.

My answer was 11,787,590 lmao

Jump in the discussion.

No email address required.

Your pulitzer's in the mail

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

:marseywinemom:


https://i.rdrama.net/images/17310210407557678.webp https://i.rdrama.net/images/17323179881945593.webp

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.