+/AoC
advent of code
git clone https://git.julia.blue/+/AoC
a7718a0
master
1from operator import add ,sub 2 3tupadd = lambda a ,b :tuple (map (add ,a ,b )) 4dirs = {"L" : (- 1 ,0 ),"R" : (1 ,0 ),"U" : (0 ,1 ),"D" : (0 ,- 1 )} 5rope = 10 * [(0 ,0 )] 6part1 = set () 7part2 = set () 8 9for line in open ("input" ): 10dir ,times = line .split () 11for _ in range (int (times )): 12rope [0 ]= tupadd (rope [0 ],dirs [dir ]) 13for i in range (1 ,10 ): 14dist = tuple (map (sub ,rope [i - 1 ],rope [i ])) 15norm = lambda n :abs (n )and n // abs (n )or 0 16if any (map (lambda x :x not in (- 1 ,0 ,1 ),dist )): 17rope [i ]= tupadd (rope [i ],map (norm ,dist )) 18part1 .add (rope [1 ]) 19part2 .add (rope [- 1 ]) 20 21len (part1 )) 22len (part2 )) 23 24# for y in range(5): 25# print("".join("#" if (x, 4 - y) in part1 else "." for x in range(5)))