From bdbd946dc9274e1f627922809cfdc7d338b6922e Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Wed, 12 Dec 2018 10:01:55 +0000 Subject: [PATCH] Day 12 solution. --- p12.dyalog | 8 ++++++++ p12.txt | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 p12.dyalog create mode 100644 p12.txt diff --git a/p12.dyalog b/p12.dyalog new file mode 100644 index 0000000..d145738 --- /dev/null +++ b/p12.dyalog @@ -0,0 +1,8 @@ +⎕IO←0 ⋄ ⎕PP←17 +s←15↓⊃p←'#'=⊃⎕NGET'p12.txt'1 ⍝ initial state +u←↑5↑¨2↓p ⋄ v←⊃∘⌽¨2↓p ⍝ patterns and replacements +f←{v[u⍳⍉0 ¯1↓(5,5+≢⍵)⍴0 0 0 0,⍵]} ⍝ next generation +g←{+/(⍸⍵)-0.5×(≢⍵)-≢s} ⍝ score function +g f⍣20⊢s ⍝ part 1 +t←f⍣{≡/(⊢-⌊/)∘⍸¨⍺⍵}s ⍝ iterate until pattern stabilises +(g t)+((g f t)-g t)×50E9-0.25×(≢t)-≢s ⍝ part 2 diff --git a/p12.txt b/p12.txt new file mode 100644 index 0000000..783bd50 --- /dev/null +++ b/p12.txt @@ -0,0 +1,34 @@ +initial state: .#..##..#.....######.....#....####.##.#.#...#...##.#...###..####.##.##.####..######......#..##.##.## + +#.... => . +.##.# => # +#..## => . +....# => . +###.# => # +...#. => # +#...# => # +#.### => . +.#... => # +...## => . +..### => . +####. => . +##.## => . +..##. => . +.#.## => # +#..#. => # +..... => . +#.#.. => . +##.#. => # +.#### => # +##### => . +#.##. => # +.#..# => # +##... => . +..#.# => # +##..# => # +.###. => . +.#.#. => # +#.#.# => # +###.. => . +.##.. => . +..#.. => .