17eacdbd1e81

2020/12
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 05 Dec 2021 11:43:05 -0500
parents bd509ececdf0
children ecdb89564123
branches/tags (none)
files data/2020/12.txt src/2020/days/day-12.lisp

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/2020/12.txt	Sun Dec 05 11:43:05 2021 -0500
@@ -0,0 +1,787 @@
+F77
+E4
+S2
+W1
+L180
+N4
+R180
+S3
+W5
+F86
+L90
+E1
+F16
+R90
+N1
+E1
+F86
+S1
+F36
+E2
+L180
+N5
+F46
+N1
+L90
+F43
+S5
+R90
+F41
+W5
+N1
+F65
+E4
+N1
+W3
+F92
+N5
+F33
+R90
+S5
+L90
+W1
+R180
+L90
+S5
+F27
+R90
+N4
+R90
+F43
+E5
+S2
+F68
+N5
+R90
+F68
+R180
+S2
+E2
+S3
+F41
+L180
+E3
+R90
+F73
+R90
+N1
+L180
+N3
+L180
+W3
+S1
+R180
+N3
+F26
+N5
+F27
+L90
+F30
+R180
+N4
+R90
+E5
+N1
+F70
+E1
+L90
+N3
+F100
+L90
+E5
+L90
+S2
+F85
+W5
+R90
+F85
+E3
+R90
+E5
+F41
+R180
+S1
+L90
+F93
+S1
+F7
+N3
+R270
+W4
+S1
+F47
+R90
+N2
+W4
+F21
+S1
+W1
+F44
+L180
+E5
+N3
+W4
+F11
+L180
+E2
+F36
+W4
+F34
+R90
+F30
+N1
+E1
+F21
+N4
+F59
+E3
+F33
+N1
+L180
+W1
+R90
+E3
+F84
+W3
+R90
+W1
+N1
+R90
+F27
+S3
+L90
+N4
+E3
+F97
+N3
+F30
+W3
+F77
+E5
+F1
+R90
+F96
+E5
+N5
+W2
+L90
+S1
+F46
+N4
+F41
+W5
+L90
+S5
+F79
+R90
+F32
+S3
+R90
+F5
+L90
+E1
+R180
+W2
+N3
+L90
+S1
+R90
+W1
+F78
+W5
+N2
+E2
+R90
+S4
+S2
+E4
+F59
+R270
+W2
+L180
+S3
+R90
+W2
+F41
+N3
+F21
+L270
+F73
+N3
+E4
+L90
+E3
+F97
+E5
+N4
+W4
+F42
+W5
+S3
+R180
+N1
+F56
+E2
+F23
+R90
+F37
+L90
+S5
+W5
+R270
+E4
+F43
+W4
+R90
+E3
+N2
+R90
+S4
+L90
+N5
+F52
+E3
+L90
+F18
+F89
+L90
+W4
+F18
+E1
+L90
+E2
+F40
+F44
+R90
+N5
+R90
+S1
+L90
+F19
+N5
+L180
+N5
+W3
+N4
+F73
+R90
+E5
+R180
+F86
+E5
+S5
+F71
+W4
+F76
+S2
+R180
+S1
+L90
+S2
+F67
+R90
+N5
+E1
+F100
+S3
+W3
+N5
+R90
+F66
+L90
+E1
+L90
+W1
+F93
+S2
+F62
+F31
+L180
+F20
+R180
+F23
+W3
+F53
+W3
+R90
+E5
+R90
+N3
+R90
+E5
+F11
+W4
+R90
+W2
+R180
+E3
+N4
+E3
+F88
+L90
+N2
+W1
+R90
+F13
+N5
+W4
+F7
+S4
+W3
+F34
+E5
+S3
+F32
+F27
+N4
+F49
+S1
+F86
+S1
+F91
+S3
+F80
+R90
+S5
+E2
+L90
+F30
+W1
+R180
+W3
+S1
+R90
+F78
+W5
+N3
+R90
+S4
+F47
+F55
+N5
+L90
+F86
+S3
+E3
+F45
+S1
+F78
+S3
+F37
+E2
+F14
+L180
+E3
+F49
+N1
+L180
+F42
+F3
+N5
+E5
+F96
+S2
+L90
+F27
+E5
+S3
+W3
+S5
+F73
+N1
+W5
+S4
+L90
+W1
+S3
+W3
+R90
+E3
+L90
+F44
+L90
+R180
+F89
+W3
+R180
+F34
+E1
+F35
+N5
+R90
+N5
+F68
+L90
+F82
+S4
+F36
+W2
+S1
+S3
+R90
+N5
+E5
+F18
+R180
+S1
+F87
+R90
+F34
+R180
+N5
+E4
+F12
+E4
+L90
+S3
+E1
+S5
+W2
+F16
+E2
+F15
+N3
+W1
+F17
+S5
+L180
+F60
+N3
+F75
+R90
+F30
+E4
+R90
+F90
+S2
+F13
+E2
+F3
+E1
+F60
+S5
+E2
+F74
+L90
+S3
+W3
+F57
+N4
+E2
+F33
+S4
+F64
+N5
+L90
+F29
+N5
+S2
+R90
+F46
+S4
+E5
+L90
+F68
+W5
+S2
+R180
+F27
+W3
+L90
+S5
+R90
+E1
+R180
+F100
+S4
+W3
+R90
+E1
+S4
+W5
+F20
+W1
+N1
+R90
+E1
+N4
+E1
+F54
+N3
+F77
+L270
+N1
+F26
+N4
+E5
+S5
+N1
+F98
+E4
+F52
+W1
+F6
+R180
+N1
+F31
+W3
+N2
+F100
+L180
+E3
+F43
+R180
+E4
+F8
+L90
+W3
+L270
+N2
+R90
+N2
+E4
+L90
+E5
+E4
+S3
+F89
+L180
+S3
+N5
+R90
+F53
+F43
+R180
+E5
+N5
+F88
+W1
+E4
+L90
+W2
+N5
+F75
+L90
+E1
+S4
+F65
+N3
+W3
+F88
+E2
+S3
+E2
+N2
+R90
+S2
+F98
+N4
+S2
+F13
+R90
+N3
+F74
+R90
+F56
+S2
+E3
+S4
+F72
+N2
+R90
+F21
+E4
+N4
+L90
+F72
+L90
+N1
+N2
+F61
+W2
+L90
+F28
+S3
+W5
+S5
+F81
+S1
+E5
+N3
+F49
+N1
+F4
+N3
+F78
+E1
+F81
+N3
+W4
+F12
+L90
+S3
+E4
+F2
+W2
+R90
+S1
+W2
+F40
+S1
+W1
+W4
+N4
+L90
+N2
+E1
+L180
+N5
+F30
+L90
+N3
+F84
+W1
+F6
+S3
+F72
+N2
+W4
+S4
+W4
+E5
+L90
+L90
+N4
+S2
+F19
+N1
+W5
+N4
+L90
+N2
+F54
+L90
+W4
+F96
+N4
+R180
+S2
+F53
+R90
+S3
+E5
+N5
+L180
+E5
+S4
+L90
+N5
+L90
+E3
+L90
+F63
+S2
+L90
+F35
+N2
+F52
+W1
+L90
+F94
+N5
+E5
+R270
+N2
+R180
+S2
+E2
+N2
+S3
+F86
+N1
+F54
+N1
+L90
+W2
+R90
+E4
+R90
+N3
+R90
+F30
+S4
+F98
+W2
+S5
+R90
+N5
+W2
+S1
+F36
+S3
+R90
+S1
+F84
+S5
+N5
+L180
+F16
+N1
+F55
+L90
+N4
+S2
+S3
+R90
+S5
+W5
+N1
+E4
+S5
+W1
+L180
+F100
+E4
+S3
+E3
+N3
+E1
+L90
+W4
+F60
+W5
+L270
+W1
+S2
+L90
+R90
+F52
+S1
+W3
+N4
+F30
+E2
+F9
+F87
+S5
+R90
+S4
+W5
+R180
+S3
+E4
+S4
+L90
+W3
+F94
+F85
+R90
+E4
+W2
+S2
+L180
+W4
+F28
+E3
+N5
+F53
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/2020/days/day-12.lisp	Sun Dec 05 11:43:05 2021 -0500
@@ -0,0 +1,49 @@
+(advent:defpackage* :advent/2020/12)
+(in-package :advent/2020/12)
+
+(defun parse (stream)
+  (iterate (for line :in-stream stream :using #'read-line)
+           (ppcre:register-groups-bind (ch n)
+               ("([NSEWLRF])([0-9]+)" line)
+             (collect (cons (char ch 0) (parse-integer n))))))
+
+(defun north (n) (* n #c( 0  1)))
+(defun south (n) (* n #c( 0 -1)))
+(defun east  (n) (* n #c( 1  0)))
+(defun west  (n) (* n #c(-1  0)))
+(defun rot   (n) (expt #c(0 1) (/ n 90)))
+
+(defun part1 (path)
+  (iterate (with pos = #c(0 0))
+           (with heading = #c(1 0))
+           (for (action . n) :in path)
+           (ecase action
+             (#\N (incf pos (north n)))
+             (#\S (incf pos (south n)))
+             (#\E (incf pos (east n)))
+             (#\W (incf pos (west n)))
+             (#\L (mulf heading (rot n)))
+             (#\R (divf heading (rot n)))
+             (#\F (incf pos (* heading n))))
+           (returning pos)))
+
+(defun part2 (path)
+  (iterate (with waypoint = #c(10 1))
+           (with pos = #c(0 0))
+           (for (action . n) :in path)
+           (ecase action
+             (#\N (incf waypoint (north n)))
+             (#\S (incf waypoint (south n)))
+             (#\E (incf waypoint (east n)))
+             (#\W (incf waypoint (west n)))
+             (#\L (mulf waypoint (rot n)))
+             (#\R (divf waypoint (rot n)))
+             (#\F (incf pos (* waypoint n))))
+           (returning pos)))
+
+(define-problem (2020 12) (data parse) (1106 107281)
+  (values (manhattan-distance (part1 data))
+          (manhattan-distance (part2 data))))
+
+
+#; Scratch --------------------------------------------------------------------