News for hackers. Stuff that matters.
Re:Advent of Code 2021 by petercooper on Wednesday December 01, 2021 @10:20AM (#29404488)
APL is the language I only ever see around AoC. But it's so impressive too. Like the first part of today's solution is "+/¯1↓x<1⊖x" (stolen from someone on Reddit) and I'm like.. ok, I need to learn this language one day.

(Since their solution is now being discussed, it's from here: https://www.reddit.com/r/adventofcode/comments/r66vow/2021_d...)

Re:Advent of Code 2021 by Jtsummers on Wednesday December 01, 2021 @11:23AM (#29405421)
Interesting solution.

  1⊖x
Rotates the sequence so the first becomes the last.

  x < 1⊖x
Element-wise compare each, resulting in a list of 1s and 0s

  ¯1 ↓ x<1⊖x
Drop the last element because it's actually not part of the solution (thanks to the earlier rotation).

  +/ ¯1↓x<1⊖x
Sum all of them, since it's just 1s and 0s this gives a correct count. Part 2 is solvable (unless I missed something, works on the sample data) by just changing two characters from that solution. Neat.
Re:Advent of Code 2021 by petercooper on Wednesday December 01, 2021 @12:15PM (#29406309)
Thanks for the explanation! I just found someone with a different approach who has similarly broken it down on Twitter: https://twitter.com/janiczek/status/1465969017089363969
Re:Advent of Code 2021 by Jtsummers on Wednesday December 01, 2021 @12:18PM (#29406360)
https://tryapl.org

That's an online APL REPL with all the symbols listed at the top, hover to get a tooltip that tells you both how to type it into the REPL and what its name is. I'd forgotten what rotate was because my APL deep-dive was 2 or 3 years ago now. It's handy for discovering the symbols and breaking down the harder-to-understand one-liners (for novices or those unfamiliar with it).

Re:Advent of Code 2021 by maximus-decimus on Saturday December 04, 2021 @09:18AM (#29440961)
and this is the solution in Q, including paring the file: `(+/) 1_ (>':) "I" $ read0 `:input_1.txt`

I don't think their second solution actually works unless I'm missing something though : +/¯3↓x<3⊖x

This compares every element to the the one 3 positions before it, when the question was to take the sum of each 3 elements and check if it's smaller than the previous sum.

Re:Advent of Code 2021 by ollran on Wednesday December 01, 2021 @11:55AM (#29405959)
APL is quite common in the code golf scene.