From 47328684408f17df85bd182e7168853417b1a49b Mon Sep 17 00:00:00 2001 From: mid-kid Date: Sun, 13 Dec 2020 13:01:46 +0100 Subject: [PATCH] Add day 12 Oops, forgot to do this yesterday --- d12.py | 37 +++ d12_input.txt | 771 +++++++++++++++++++++++++++++++++++++++++++++++++ d12_output.txt | 2 + 3 files changed, 810 insertions(+) create mode 100755 d12.py create mode 100644 d12_input.txt create mode 100644 d12_output.txt diff --git a/d12.py b/d12.py new file mode 100755 index 0000000..8c7d7a0 --- /dev/null +++ b/d12.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +from sys import argv + +i = [(x[0], int(x[1:].strip())) for x in open(argv[1])] + +v = (0,0,0) +for d in i: + if d[0] == "F": + dv = [(1,0), (0,-1), (-1,0), (0,1)][(v[2]//90)%4] + v = (v[0]+dv[0]*d[1],v[1]+dv[1]*d[1],v[2]) + continue + v = { + "N": lambda x: (v[0],v[1]+x,v[2]), + "S": lambda x: (v[0],v[1]-x,v[2]), + "E": lambda x: (v[0]+x,v[1],v[2]), + "W": lambda x: (v[0]-x,v[1],v[2]), + "R": lambda x: (v[0],v[1],v[2]+x), + "L": lambda x: (v[0],v[1],v[2]-x), + }[d[0]](d[1]) +print(abs(v[0])+abs(v[1])) + +v = (10,1) +s = (0,0) +for d in i: + if d[0] == "F": + s = (s[0]+v[0]*d[1],s[1]+v[1]*d[1]) + continue + v = { + "N": lambda x: (v[0],v[1]+x), + "S": lambda x: (v[0],v[1]-x), + "E": lambda x: (v[0]+x,v[1]), + "W": lambda x: (v[0]-x,v[1]), + "R": lambda x: [(v[0],v[1]), (v[1],-v[0]), (-v[0],-v[1]), (-v[1],v[0])][(x//90)%4], + "L": lambda x: [(v[0],v[1]), (-v[1],v[0]), (-v[0],-v[1]), (v[1],-v[0])][(x//90)%4], + }[d[0]](d[1]) +print(abs(s[0])+abs(s[1])) diff --git a/d12_input.txt b/d12_input.txt new file mode 100644 index 0000000..c8dd854 --- /dev/null +++ b/d12_input.txt @@ -0,0 +1,771 @@ +F92 +R180 +S1 +F64 +R90 +S1 +E1 +F11 +N4 +R180 +S3 +E3 +F55 +R90 +N1 +E4 +L180 +F9 +N3 +R90 +W4 +N4 +F36 +L90 +F50 +E3 +F9 +E5 +S1 +W2 +E4 +R180 +N3 +F18 +N2 +S5 +W1 +F41 +E3 +N4 +F66 +R270 +F22 +N5 +E4 +N1 +L90 +W1 +N1 +R90 +F87 +E1 +N4 +E1 +L90 +E5 +L180 +F84 +S5 +F65 +N2 +W1 +F65 +N3 +L90 +R90 +E1 +L180 +S1 +F60 +E3 +L90 +F22 +E5 +F32 +S1 +L90 +E2 +S2 +W5 +N2 +E5 +F60 +L180 +W3 +F49 +S5 +F84 +N5 +F78 +W5 +S3 +L90 +S3 +F83 +L90 +E1 +L90 +E1 +F99 +W1 +L90 +W2 +L90 +S1 +R180 +F8 +E2 +R180 +N2 +F66 +N5 +L90 +E1 +F76 +W3 +F23 +F79 +N3 +E1 +R90 +N5 +F33 +N2 +L180 +F97 +R90 +L90 +S5 +F99 +W5 +L90 +F47 +L90 +E4 +F99 +S4 +R90 +E2 +S2 +L90 +F33 +E2 +F71 +R90 +N1 +N2 +W3 +L90 +W4 +S1 +R90 +F27 +L270 +W5 +F49 +W3 +F41 +L90 +F23 +L90 +S1 +F11 +L90 +W3 +N1 +W4 +L90 +N4 +W2 +L90 +S3 +W4 +L180 +W4 +R180 +W4 +F49 +E3 +S2 +F64 +S4 +F61 +E3 +L180 +W1 +N2 +W2 +F64 +R90 +S4 +E5 +N1 +L270 +E3 +F22 +E2 +R90 +S5 +F57 +N2 +F78 +L270 +W1 +N4 +L90 +S4 +F71 +S2 +L90 +E1 +L180 +F4 +N1 +W4 +L90 +N5 +F98 +N3 +L90 +W2 +L180 +F54 +W1 +R90 +W3 +F67 +L90 +W2 +R180 +F79 +N4 +F30 +L90 +N4 +R180 +L90 +S5 +F7 +N2 +F26 +S5 +F43 +E3 +N3 +L180 +F57 +W4 +L90 +E5 +F100 +S2 +F86 +L180 +W3 +S5 +W1 +S3 +L180 +S2 +S5 +W4 +L90 +F73 +R90 +F14 +E2 +F99 +R90 +R90 +E5 +N1 +R90 +N1 +N4 +R180 +S4 +L90 +F98 +W2 +L90 +F100 +R180 +W4 +F92 +E1 +L180 +S3 +F94 +E4 +N5 +R90 +S3 +W4 +F86 +S5 +R90 +E2 +F6 +E2 +F75 +N1 +L90 +W4 +F2 +E1 +N4 +E1 +L90 +W4 +F17 +N2 +R90 +E5 +R90 +N1 +W1 +R180 +W4 +R180 +F97 +E5 +N2 +L90 +F27 +N1 +W5 +R90 +N1 +F98 +R90 +N2 +F12 +W5 +S1 +F86 +N3 +W3 +F71 +L180 +W1 +R90 +W3 +S4 +E2 +S5 +W3 +R90 +E4 +R90 +W1 +N3 +F11 +W4 +E4 +F67 +E2 +F15 +W5 +N4 +W1 +R90 +L90 +W4 +F16 +N4 +F87 +L180 +F73 +L180 +E5 +R90 +F96 +N5 +W1 +F28 +R90 +W5 +S3 +S3 +E5 +R180 +E4 +F4 +L90 +E3 +E4 +S5 +W3 +L180 +F57 +R90 +N2 +F78 +N2 +L90 +S1 +R90 +W4 +S1 +L90 +N5 +F60 +R90 +S4 +F42 +R90 +W2 +F31 +R180 +N2 +S2 +F91 +S4 +R90 +N2 +L180 +N1 +E4 +F72 +E3 +E3 +N2 +L90 +N1 +L90 +F83 +S1 +R90 +N5 +E4 +F53 +N3 +E5 +S3 +E4 +F93 +W2 +F53 +L90 +E2 +L90 +W2 +F96 +R90 +E3 +L90 +S5 +F31 +R90 +R90 +F98 +F91 +W2 +N3 +F69 +R90 +F51 +R90 +N1 +E2 +R90 +S1 +R180 +E5 +N5 +W5 +F34 +W1 +F60 +R90 +F53 +R90 +F62 +R90 +S4 +F95 +W5 +E2 +F84 +R90 +E2 +F54 +E2 +F5 +R90 +F32 +L90 +E2 +S2 +L180 +F31 +E2 +L90 +N5 +W2 +L90 +F53 +R90 +S1 +R90 +F49 +R90 +S3 +L90 +F76 +F31 +S1 +F13 +R90 +W1 +S1 +R90 +W2 +L180 +E2 +R90 +E2 +N1 +W1 +S1 +E1 +S4 +L90 +N2 +E2 +R90 +S4 +L90 +N5 +L90 +W4 +S2 +W1 +L90 +E4 +R90 +W2 +S1 +L90 +N5 +F63 +R90 +W1 +F20 +L90 +F86 +S4 +S4 +E2 +F92 +F90 +W4 +F94 +E1 +N5 +F30 +W3 +N3 +L180 +W5 +F52 +R270 +E5 +R90 +N4 +W4 +F10 +N1 +F16 +N1 +F31 +S4 +L90 +F81 +N1 +L90 +W2 +F84 +L90 +F79 +L90 +W5 +L90 +F90 +R90 +E2 +L90 +F25 +N5 +S1 +F12 +R90 +F34 +R90 +F4 +E4 +L90 +S1 +F70 +R90 +F22 +R90 +F67 +R90 +F40 +W1 +S3 +L180 +N2 +E4 +S4 +F98 +R180 +F16 +S2 +W4 +S1 +F70 +L90 +N3 +E3 +L270 +W4 +L90 +W5 +R180 +W5 +N4 +R90 +W4 +F5 +L270 +E3 +L90 +E5 +F50 +S3 +F51 +E1 +S5 +F95 +R90 +L90 +S2 +F75 +R90 +W2 +F70 +E2 +F52 +W4 +E1 +L180 +F72 +N2 +F5 +E2 +F94 +R180 +F7 +E3 +N2 +R90 +W1 +N4 +R90 +S1 +W4 +L270 +W1 +W1 +N2 +E1 +F31 +N1 +W4 +S5 +L90 +E1 +R180 +F50 +N1 +W2 +F66 +N2 +L90 +R90 +W1 +E5 +L90 +E2 +R180 +F63 +N4 +N3 +F87 +W4 +L90 +F85 +N3 +F93 +S2 +F95 +N5 +L180 +S3 +R90 +W5 +L180 +W1 +L90 +S4 +F68 +L180 +S4 +R180 +E2 +L180 +E3 +R180 +S5 +F88 +N1 +R90 +S3 +E5 +S5 +E1 +N5 +E2 +S1 +W5 +F62 +R90 +F39 +L180 +N3 +F42 +E4 +N5 +R90 +W5 +S2 +F43 +W4 +F94 +R90 +F85 +N5 +F7 +L180 +W4 +L180 +E4 +F44 +N2 +W2 +N3 +L180 +E3 +N1 +S2 +W4 +N5 +R180 +F78 +E5 +L90 +W4 +F77 diff --git a/d12_output.txt b/d12_output.txt new file mode 100644 index 0000000..4395144 --- /dev/null +++ b/d12_output.txt @@ -0,0 +1,2 @@ +1482 +48739