3 ms·
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
by Jtsummers 5y ago
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.
- petercooper 5y agoThanks 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 https://twitter.com/janiczek/status/1465969017089363969
- Jtsummers 5y agohttps://tryapl.org 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).