From 6eb7994377f20d35ab1eeb0da69cfb6fe1fdd68d Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Tue, 18 Dec 2018 10:39:27 +0000 Subject: [PATCH] Day 18 solution. --- p18.dyalog | 7 +++++++ p18.txt | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 p18.dyalog create mode 100644 p18.txt diff --git a/p18.dyalog b/p18.dyalog new file mode 100644 index 0000000..b51443f --- /dev/null +++ b/p18.dyalog @@ -0,0 +1,7 @@ +⎕IO←0 +p←↑⊃⎕NGET'p18.txt' 1 +f←{(⍺='.')∧2<+/⍵='|':'|' ⋄ (⍺='|')∧2<+/⍵='#':'#' ⋄ (⍺='#')∧(1=+/⍵='#')∨0=+/⍵='|':'.' ⋄ ⍺} +g←{⍵f⍤¯2{,⍵}⌺3 3⊢⍵} +v←{×/+/'|#'∘.=,⍵} ⍝ value +v g⍣10⊢p ⍝ part 1 +v ⍬{(≢⍺)≠n←⍺⍳⊂⍵:⍺⊃⍨n+((≢⍺)-n)|1E9-n ⋄ (⍺,⊂⍵)∇g ⍵}p ⍝ part 2 diff --git a/p18.txt b/p18.txt new file mode 100644 index 0000000..2a072eb --- /dev/null +++ b/p18.txt @@ -0,0 +1,50 @@ +|#.....|...#|#...|......|..||.##..##..|||#|....|.. +.#.#.#..|.#..||.##....|#.|.##....##..#|...#..#.|.. +#..##...|#.#||#....##...#....##..#.#.|...|.#.....# +.|.|.|..||#.....#.#..#..........#.||.#..|.|#.|.#.. +#..|.......#||.........||.#...#|.....||.|#...|#..# +|.#|.....#|##.|||.#|#|.#..|..#..#..||...||.......# +|..#|..#||#..#.......#.#|.#...........#.##........ +.....||.#.#|..#...|.#...#.#..........|...|.#....#| +.|.##|.|...#.|#..|.||.#.|.#.|.#..#.|#|...|##..##|. +...#....#...|.|.##.###.#|...#..........||...|...|| +|#..##|..|...#..#...||......|.|.#..#...#|..|#|..## +#.|..#..#.....|.##..#|.....##......|...||..#..#... +|#.....|#||#.....|.##|.#.#.#.#.|#.#...|#|#..||.... +...##|....|.|..|#.||||.##.#..#..###..|.#.#|.#...|. +..||.||..|....|.#.|....#..|#.|#..#.|.|.|||......#. +...#.#|..#|.###.##..|...#.||#....||....||..#....|. +.#|.|......#.##.....#.....#.#..|..|#|#..#......|.. +.#.|.|##...||#...#|....|||.....##......|...|#|...| +|...|##.|....|.....|||.#.##..|.##|#....#...|....#. +..#.||.##.#...|#...#|##.||##.#.....|...|...#|.|... +#.#.|..#.#.###...|..||..|...||.|..#.#...#..|..|... +.#.|.#|.|.##.|..##.#|.#.##...|||...#|..|.#.##...|. +....##|..|.#.....|.|.#..|#..#|..#.#....#..#......# +|...||..|.#..|..#.###||.......###.....#..........| +.|.||....|#..#.|...|.#..##...|.........#..#|.|.#.. +.|...|.|#|.||#...#...#.|..|...|||#....||#..|....#. +|......#......#.|#.....|#||.#...#...##....#..#.... +.......|#.|#...|.#.....#..||....#..#...|.#.#||.### +##.#.#|..||##.#|.|.#......###.|...#|...#|.##....|| +..#.|...#.|.........|#.......|.....#.|..#..|...|#| +|||...|..|#|...##.......|....||.|.##..|.....#.#|.. +#.#...|..##.##.#...#..#.|.##...|##.#|..|..#.....|. +.#|..#.|#|.#......#..#...||.........#.#...##||.... +#|##..#....#.....|..................#..|.#|...#..| +.....#..........#.|..#..|.....|#....||###.|......| +.....#.|.....|...#..#....|#...|#.#|##....#..||...| +.#|..||.#.|.....#...|##.#|.|.#...|..#|##.|..|.#... +.......|.||..||..#..|#.#|....#..####.##...#....#.. +#..||..|..........|.#.......#..|..#|.|.....#.....# +#...#....#|.##..#...#..|#.#..|||.#.#..||...|.|..#. +...#.##..||.#.#....|...|..#.#..|||...#......|#..#. +.|..#||..|##..|.|.#.|..#..|....|..||.#|.|...#.|#.. +.....###..|||...||.|.|.|.|#..##|..##....###.||..|. +.|....#.#|#.......|.|..#......###.|.|..|.......#.. +.#.#.....|.|....#..|...|.|..#.|##....#..||...#...| +|#|..#|...####....#.#.|.|.|..#..##|##..#..|||#..|. +#|#...#|....|....###...|.....|..|....|.....##..|.. +.|...#...##|.|##..|...|.|#...|.#.|.....|..|....||. +#...#||.#....|..|..#.|#.||.|.|#...#.|.#...||#.#.|| +....|...||...#..#|..|##.#.|.##.#|...#||.|.|.#..#|#