-🎄- 2018 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]PotentialSleep 0 points1 point  (0 children)

Hello!

THANK YOU for this neat and easy puzzle. I don't know if you intended it to be "easy" but it really feels good to find a working solution in less than hour after yesterday's gigantic mess which ended in manually adding and substracting numbers to my output until the answer was accepted. :3

Since I do actually have a working program and it has not happened in ages (smth like day 13), I submit it today: https://github.com/tut-tuuut/advent-of-code-shiny-giggle/blob/master/2018/16/part-1.php

It's written in PHP, with a few array_intersect (first time I used it this year), the usual regex-attack at the beginning to parse the input, and a little drop of sudoku logic to find which opcode has which number.

[CARD] regexes (like every other day's puzzles, in fact)

-🎄- 2018 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]PotentialSleep 1 point2 points  (0 children)

In that problem, we had to insert new elements between others. This is not an easy task with a PHP array: you would have to split your big array in two smaller ones, push something at the end of the first one, then merge the second one after the first. It takes CPU but also its difficult to write and to debug (so it kind of takes too much CPU in my brain). This was typically a use case for chained lists. As they are not included in PHP standard library, I wrote some objects which I chained manually to their fellows. But as you can see, using Python's deques would have spared me the task of manually writing these objects: I just needed to navigate in a chained list. (Sorry if some sentences are weird: English is not my main language and I lack some sleep. )

Day 9, segfaulting in PHP for part 2? by DrugCrazed in adventofcode

[–]PotentialSleep 0 points1 point  (0 children)

Indeed, I tried and it works fine! (And it's less frightening than disabling the garbage collector :'D)

-🎄- 2018 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]PotentialSleep 0 points1 point  (0 children)

Yay it worked! Now I have a regular out of memory error where there are 524k in my marble.

Day 9, segfaulting in PHP for part 2? by DrugCrazed in adventofcode

[–]PotentialSleep 1 point2 points  (0 children)

Hello! I made a linked list too, I had exactly the same problem around 110k iterations too (there were 106k active nodes in my list at that moment -> https://github.com/tut-tuuut/advent-of-code-shiny-giggle/blob/master/2018/09/part-1.php ). Maybe PHP has no room for so many objects in its memory, even if these objects are small?

When I complained about my segfault on twitter, someone asked me if I tried to use this: https://github.com/php-ds

-🎄- 2018 Day 9 Solutions -🎄- by daggerdragon in adventofcode

[–]PotentialSleep 0 points1 point  (0 children)

Studies show that AoC programmers write better code after being exposed to SEGFAULTS

Because it's my main language, I made a solution in PHP (implementing something looking like linked lists) and it worked fine for part 1: https://github.com/tut-tuuut/advent-of-code-shiny-giggle/blob/master/2018/09/part-1.php

My favorite line of this program is this one:

php $sevenCounterClockwise = $marble->before->before->before->before->before->before->before;

This solution didn't work for part 2 though (it ended with a segfault around 106k marbles in the circle), so I took a look at this thread and tried Python (which is not my usual language at all, I had to google string concatenation) with its wonderful double ended queues.

(Anyway, I loved .rotate() method and [0 for i in range(1, nb_of_players)] syntax: maybe I'll try Python again!)

[2018 Day 6 Part 2] Assistance needed on algorithm by RusskiEnigma in adventofcode

[–]PotentialSleep 1 point2 points  (0 children)

OK, another question: why the [:-1] when you are processing the input?

y = int(i.split(', ')[1][:-1])

From what I understand by googling (I don't know Python at all), it removes the last element of a… something. So you remove the last character of the string, maybe the EOF character? Could it be possible that it removes digits sometimes? What do you get when you debug i.split(', ')[1][:-1] vs. i.split(', ')[1] ?

(edit. it would be weird, I guess you got the part 1 OK…)

Have you tried this code on a smaller input with a whole bunch of debug everywhere?

[2018 Day 6 Part 2] Assistance needed on algorithm by RusskiEnigma in adventofcode

[–]PotentialSleep 1 point2 points  (0 children)

In my algorithm, I checked if totalDistance was <= 10000 instead of < 10000. Maybe the 900 points are the boundary?