r/adventofcode • • Dec 02 '16

SOLUTION MEGATHREAD --- 2016 Day 2 Solutions ---

--- Day 2: Bathroom Security ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).


BLINKENLIGHTS ARE MANDATORY [?]

Edit: Told you they were mandatory. >_>

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

20 Upvotes

210 comments sorted by

View all comments

Show parent comment

3

u/John_Earnest Dec 02 '16 edited Dec 02 '16

Nice. I was thinking about the simplification of 2 2&0 0| to 2&0| while laying in bed last night, but I hadn't considered trying to make the dictionary definition smaller. Good use of the identity matrix builtin.

Any ideas on a smaller representation for part 2's lookup table? We can dispense with 0N and the need to clamp coordinates if we used 0 for invalid cells and wrap the edge of the table with 0 to catch all the boundary conditions:

l: 0: "../../Desktop/Advent/02.in"
d: "URDL"!(0 -1;1 0;0 1;-1 0)
t: +4(+|" ",)/"|"\"  1  | 234 |56789| ABC |  D  "
t./:1 3{x{$[" "~t.x+y;x;x+y]}/y}\d l

Edit: several additional golfs for my part 1:

l: 0: "../../Desktop/Advent/02.in"
d: "URDL"!(0 -1;1 0;0 1;-1 0)
1+3/|+1{x(2&0|+)/y}\d l

{2&0|x+y} can be replaced with the tacit expression (2&0|+), where + is an ambivalent verb and therefore the train can be applied as dyadic. In both the 'decode' operation 3 3/ and the initial position of 1 1 I can get away with using a scalar.

2

u/AoC-- Dec 02 '16 edited Dec 03 '16

Just an idea for part 2, made essentially by extending part 1:

l:0:"02.in"
d:"DRUL"!(=2),-=2
b:|2 1 0 1 2@ /boundaries
"  1   234 56789 ABC   D  "@5/'2 0{x{(b x)|(4-b x)&x+y}/y}\d l

2

u/AoC-- Dec 03 '16 edited Dec 03 '16

A different "lookup table" (not much of a table, really) variant for part 2:

l:0:"02.in"
d:"URDL"!-5 1 5 -1
t:"1   234 56789 ABC   D"
t@8{x{(x+y;x)32=t@x+y}/y}\d l