summaryrefslogtreecommitdiffstats
path: root/2021/21/code.tl
diff options
context:
space:
mode:
Diffstat (limited to '2021/21/code.tl')
-rw-r--r--2021/21/code.tl52
1 files changed, 52 insertions, 0 deletions
diff --git a/2021/21/code.tl b/2021/21/code.tl
new file mode 100644
index 0000000..3622b02
--- /dev/null
+++ b/2021/21/code.tl
@@ -0,0 +1,52 @@
+(defstruct player ()
+ num
+ pos
+ (val 0))
+
+(defun read-input (: (name "input"))
+ (flow (file-get-lines name)
+ (keep-matches (`Player @num starting position: @pos` @1)
+ (new player num (toint num) pos (pred (toint pos))))))
+
+(defun counter (start)
+ (lambda () (pinc start)))
+
+(defun solve-one (: (name :))
+ (let ((count 0)
+ (die (counter 1)))
+ (buildn
+ (pend (read-input name))
+ (whilet ((p (del)))
+ (inc count)
+ (upd p.pos (+ [die] [die] [die]) (mod @1 10))
+ (if (>= (inc p.val (succ p.pos)) 1000)
+ (return (* count 3 (del).val)))
+ (add p)))))
+
+(defstruct game
+ players)
+
+(defun quantum-turn (ga)
+
+(defun solve-two (: (name :))
+ (let ((ga (new game players (read-input name))))
+ (
+
+
+ (die (counter 1))
+ (player-stream (repeat (read-input name))))
+ (each ((p player-stream))
+ (let ((npos (mod (+ p.pos [die die die] 10)))
+ (nval (
+ (if (>= npos 21))
+ ((
+
+
+ (buildn
+ (pend (read-input name))
+ (whilet ((p (del)))
+ (inc count)
+ (upd p.pos (+ [die] [die] [die]) (mod @1 10))
+ (if (>= (inc p.val (succ p.pos)) 21)
+ (return p))
+ (add p)))))