From b060f3f3925754a157f6f152209c54d30cdd37c7 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Mon, 17 Dec 2018 11:27:21 +0000 Subject: [PATCH] Day 9 solution using a doubly linked list. --- p9.txt | 1 + p9list.dyalog | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 p9.txt create mode 100644 p9list.dyalog diff --git a/p9.txt b/p9.txt new file mode 100644 index 0000000..aa93dd2 --- /dev/null +++ b/p9.txt @@ -0,0 +1 @@ +470 players; last marble is worth 72170 points diff --git a/p9list.dyalog b/p9list.dyalog new file mode 100644 index 0000000..9c5e88e --- /dev/null +++ b/p9list.dyalog @@ -0,0 +1,10 @@ +⎕IO←0 +(p w)←⍎¨'\d+'⎕S'&'⊃⊃⎕NGET'p9.txt'1 + +ins←{q←(p←⍵ 1⌷m)1⌷m ⋄ n←m[(p 1)(q 0)]←≢m ⋄ m⍪←p q ⋄ n} +del←{f←{⍵ 0⌷m} ⋄ p←f(r,←f(q←f⍣6⊢⍵)) ⋄ m[(p 1)(q 0)]←q p ⋄ m⍪←0 ⋄ q} +run←{ins⍣(23|⍵)del∘(ins⍣22)⍣(⌊⍵÷23)⊢0} +hscore←{⌈/+⌿z⍵⍴(⍵×z←⌈⍵÷⍨≢r)↑r+23×1+⍳≢r} + +r←⍬ ⋄ m←1 2⍴0 ⋄ (hscore p)⊣run w ⍝ part 1 +r←⍬ ⋄ m←1 2⍴0 ⋄ (hscore p)⊣run w×100 ⍝ part 2