diff --git a/AOC22.cabal b/AOC22.cabal index 916ec79..73e5bd0 100644 --- a/AOC22.cabal +++ b/AOC22.cabal @@ -23,9 +23,8 @@ source-repository head type: git location: https://github.com/githubuser/AOC22 -executable AOC22-exe - main-is: Main.hs - other-modules: +library + exposed-modules: AOCUtil Days.Day01 Days.Day02 @@ -38,13 +37,18 @@ executable AOC22-exe Days.Day09 Days.Day10 Days.Day11 + Days.Day12 + Days.Day13 + Days.Day14 + Days.Day15 + Main + other-modules: Paths_AOC22 hs-source-dirs: src - ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints build-depends: - AOC22 - , base >=4.7 && <5 + base >=4.7 && <5 + , containers , ghc - , modular-arithmetic default-language: Haskell2010 diff --git a/data/Day15.test b/data/Day15.test new file mode 100644 index 0000000..a612424 --- /dev/null +++ b/data/Day15.test @@ -0,0 +1,14 @@ +Sensor at x=2, y=18: closest beacon is at x=-2, y=15 +Sensor at x=9, y=16: closest beacon is at x=10, y=16 +Sensor at x=13, y=2: closest beacon is at x=15, y=3 +Sensor at x=12, y=14: closest beacon is at x=10, y=16 +Sensor at x=10, y=20: closest beacon is at x=10, y=16 +Sensor at x=14, y=17: closest beacon is at x=10, y=16 +Sensor at x=8, y=7: closest beacon is at x=2, y=10 +Sensor at x=2, y=0: closest beacon is at x=2, y=10 +Sensor at x=0, y=11: closest beacon is at x=2, y=10 +Sensor at x=20, y=14: closest beacon is at x=25, y=17 +Sensor at x=17, y=20: closest beacon is at x=21, y=22 +Sensor at x=16, y=7: closest beacon is at x=15, y=3 +Sensor at x=14, y=3: closest beacon is at x=15, y=3 +Sensor at x=20, y=1: closest beacon is at x=15, y=3 diff --git a/data/day12.test b/data/day12.test new file mode 100644 index 0000000..86e9cac --- /dev/null +++ b/data/day12.test @@ -0,0 +1,5 @@ +Sabqponm +abcryxxl +accszExk +acctuvwj +abdefghi diff --git a/data/day12.txt b/data/day12.txt new file mode 100644 index 0000000..bb083e9 --- /dev/null +++ b/data/day12.txt @@ -0,0 +1,41 @@ +abaaaaaccccccccccccccccccaaaaaaaaaaaaaccccaaaaaaaccccccccccccccccccccccccccccaaaaaa +abaaaaaaccaaaacccccccccccaaaaaaaaacaaaacaaaaaaaaaacccccccccccccccccccccccccccaaaaaa +abaaaaaacaaaaaccccccccccaaaaaaaaaaaaaaacaaaaaaaaaacccccccccccccaacccccccccccccaaaaa +abaaaaaacaaaaaacccccccccaaaaaaaaaaaaaaccaaacaaaccccccccccccccccaacccccccccccccccaaa +abccaaaccaaaaaacccaaaaccaaaaaaaaaaaaaccccaacaaacccccccccaacaccccacccccccccccccccaaa +abcccccccaaaaaccccaaaacccccaaaaacccaaaccaaaaaaccccccccccaaaaccccccccccccccccccccaac +abcccccccccaaaccccaaaacccccaaaaacccccccccaaaaaccccccccccklllllccccccccccccccccccccc +abcccccccccccccccccaaccccccccaaccccccccaaaaaaaccccccccckklllllllcccccddccccaacccccc +abaccccccccccccccccccccccccccaaccccccccaaaaaaaaccccccckkkklslllllcccddddddaaacccccc +abacccccccccccccccccccccccccccccccaaaccaaaaaaaaccccccckkkssssslllllcddddddddacccccc +abaccccccccccccccccccccccccccccccccaaaaccaaacaccccccckkksssssssslllmmmmmdddddaacccc +abcccccccccccccccaaacccccccccccccaaaaaaccaacccccccccckkkssssusssslmmmmmmmdddddacccc +abcccccccaaccccaaaaacccccccccccccaaaaaccccccaaaaaccckkkrssuuuussssqmmmmmmmmdddccccc +abcccccccaaccccaaaaaacccccccaaccccaaaaacccccaaaaacckkkkrruuuuuussqqqqqqmmmmdddccccc +abccccaaaaaaaacaaaaaacccccccaaaaccaaccaccccaaaaaacjkkkrrruuuxuuusqqqqqqqmmmmeeccccc +abcaaaaaaaaaaacaaaaaccccccaaaaaacccccaaccccaaaaajjjjrrrrruuuxxuvvvvvvvqqqmmmeeccccc +abcaacccaaaaccccaaaaaaacccaaaaacccacaaaccccaaaajjjjrrrrruuuxxxxvvvvvvvqqqmmeeeccccc +abaaaaccaaaaacccccccaaaccccaaaaacaaaaaaaacccaajjjjrrrrtuuuuxxxyvyyyvvvqqqnneeeccccc +abaaaaaaaaaaacccaaaaaaaccccaacaacaaaaaaaacccccjjjrrrttttuxxxxxyyyyyvvvqqnnneeeccccc +abaaaaaaaccaacccaaaaaaaaacccccccccaaaaaaccccccjjjrrrtttxxxxxxxyyyyyvvvqqnnneeeccccc +SbaaaaaacccccccccaaaaaaaaaccccccccaaaaacccccccjjjrrrtttxxxEzzzzyyyvvrrrnnneeecccccc +abaaaaacccccccccccaaaaaaacccccccccaaaaaaccccccjjjqqqtttxxxxxyyyyyvvvrrrnnneeecccccc +abaaacccccccccccaaaaaaaccaaccccccccccaaccaaaaajjjqqqttttxxxxyyyyyyvvrrrnnneeecccccc +abaaacccccccccccaaaaaaaccaaacaaacccccccccaaaaajjjjqqqtttttxxyywyyyywvrrnnnfeecccccc +abcaaacccccccaaaaaaaaaaacaaaaaaaccccccccaaaaaaciiiiqqqqtttxwyywwyywwwrrrnnfffcccccc +abcccccccccccaaaaaaaaaaccaaaaaacccccccccaaaaaacciiiiqqqqttwwywwwwwwwwrrrnnfffcccccc +abccccccccccccaaaaaacccaaaaaaaacccccccccaaaaaaccciiiiqqqttwwwwwswwwwrrrrnnfffcccccc +abccccccccccccaaaaaacccaaaaaaaaacccccccccaaacccccciiiqqqtswwwwssssrrrrrroofffcccccc +abccccccaaaaacaaaaaacccaaaaaaaaaaccccccccccccccccciiiqqqssswsssssssrrrrooofffaccccc +abccccccaaaaacaaccaaccccccaaacaaacccccccccccccccccciiiqqssssssspoorrrooooofffaacccc +abcccccaaaaaacccccccccccccaaacccccccccccccccccccccciiiqppssssspppooooooooffffaacccc +abcccccaaaaaacccccccccccccaacccccccccccccccccccccccciipppppppppppoooooooffffaaccccc +abcccccaaaaaaccccccccccccccccccccccccccccccccccccccciihppppppppgggggggggfffaaaccccc +abccccccaaacccccccccccccccccccccccaccccccccccccccccchhhhpppppphggggggggggfaaaaccccc +abaaaccccccccccccccccccccccaccccaaacccccccccccccccccchhhhhhhhhhgggggggggcaacccccccc +abaaccaaaccaccccccccccccccaaacccaaacaacccaaaaacccccccchhhhhhhhhgaaccccccccccccccccc +abaaacaaacaacccccccccaaaccaaaacaaaaaaaaccaaaaaccccccccchhhhhhaaaaacccccccccccccccca +abaaaccaaaaaccccccccccaaacaaaaaaaacaaaaccaaaaaaccccccccccaaacccaaaacccccccccccaccca +abcccaaaaaaccccccccccaaaaaaaaaaaaacaaaaccaaaaaaccccccccccaaaccccaaaccccccccccaaaaaa +abcccaaaaaaaacccccccaaaaaaaaaaaaaaaaaccccaaaaaacccccccccccccccccccccccccccccccaaaaa +abcccaacaaaaaccccccaaaaaaaaaaaaaaaaaaacccccaacccccccccccccccccccccccccccccccccaaaaa diff --git a/data/day13.test b/data/day13.test new file mode 100644 index 0000000..af73fbb --- /dev/null +++ b/data/day13.test @@ -0,0 +1,23 @@ +[1,1,3,1,1] +[1,1,5,1,1] + +[[1],[2,3,4]] +[[1],4] + +[9] +[[8,7,6]] + +[[4,4],4,4] +[[4,4],4,4,4] + +[7,7,7,7] +[7,7,7] + +[] +[3] + +[[[]]] +[[]] + +[1,[2,[3,[4,[5,6,7]]]],8,9] +[1,[2,[3,[4,[5,6,0]]]],8,9] diff --git a/data/day13.txt b/data/day13.txt new file mode 100644 index 0000000..6372818 --- /dev/null +++ b/data/day13.txt @@ -0,0 +1,449 @@ +[[1,4,7,4,8],[],[8,0,7,[],[]]] +[[10,[5,[0,2,5,3,3],[9,7,9],6],7,9,[2,9,[],4,0]],[8]] + +[[7],[7],[[[3,4,6],1,[1,2,4],[7,5,3,5,2]],[[1,3,2,7],10,[9,9,0,2]],[9],[1,[10,4,7],[5,2,1],[10,9,4,3]],[7,[8,9,9,4],[]]],[],[]] +[[8,[[]],[7,3],4],[[[2,3]],10,[[4],[3,9,4],[0,6,5],1,3]],[],[]] + +[[5],[[[],[8,0,4],1],[],2,6,10]] +[[[[3,0],[7,10,9]],[9,4,3]]] + +[[2,10,[1,[],5],[[1],[3,0,9,7,2],[6]],[[],[7,0,2]]],[[[0,10]]]] +[[3,[[],[5,0,2],2],7,[[0,2,9],2,[4]]],[3,[[4,5]],[[10,2,5,1],[1],9,[3,3,7,7,10],9]],[]] + +[[[[],9,7,[2,8,2,1],[6,3,7,6]],8]] +[[[[9,8,2],[10],[9,0,3],0,[3,5,0]]],[]] + +[[[9,10,[1,0,6],[1,2]],[[],[9,5,3],[7,3,10,1],0,0],5,10,[]],[]] +[[5,6,1,6],[8,6,5,[7,0,5,[0,4,3,6,6],[8,7,8,5]]],[[[1,2],9,1],10,4,3,[5,[5,10,9,9],7,0,[2,3]]],[[[1,5],[0],0],3,[[]]]] + +[[0,[[4,6,4,8]],3,[10]],[],[6,8,6],[8,[3,[7,7,10,6,5]],[0,8,[7],[],5]],[1,[3,[4,4,8,3,8],3,[1,9,8,3,10],[0,5,8]]]] +[[0,[],10]] + +[[[[2,4],[5],10,1],[3,6,3],8,0,9],[9,1,9],[[[1],[2,0,7],[10,2],6,[10,9]],[[10],[1,0,3],5,[1,7],[]],3]] +[[9,6,3],[[6,[8,10,3],2,[6,1],10],1],[]] + +[[8,[],[10]],[]] +[[[[8,5,6,6,5],1,[10]],[]],[],[],[7],[2,2]] + +[[9,3]] +[[0,[1],6,[10,0,6],7],[7,[1,[4,3,10],[],[6,6]],5,[9],7],[7,[[6,2,7,2,5],9,8,7,[9]]],[5]] + +[[9,9,[[10]],[8,[7]]],[8,5,7,[[6,1,8],[9,5],[],10,8],[8,[10],[],[5,3,2]]]] +[[[9,9,6],1,0,9,[[0],[8],2,0]],[[9,5],[[],[9]],3,[[0],9,3,0,8],10],[[[4],[8,2],[2,0,3]],3,6,[[3,8]],4]] + +[[4,3,[[10,8,3,1,10],[9]]]] +[[[6,[0],[3,4],[0]],[],[6,2,[],1],[[],1,[1,4,3,7],9,4]],[0,[[0],[9,2]],1]] + +[[[[8,4],[7,8,6,10,1],[]],[[2,8,10,4,5],[0,8],7,[1,5],4],8,[1]],[],[]] +[[3,[4,[3,3,4]]],[[],1,9,[0]],[[],[[6,9,1],[10,2,3,2,8],3],3,5]] + +[[[[0,3,7],3,[4,0],[6,2,0],4],1,[[3,4,7],8,[1]],2]] +[[0,6,[[6,9,6],9,[0],[2,10]],4]] + +[[2,[],6,[[8,10],7,7]],[[[1,2,3,8,3]]],[]] +[[[],9,9],[9],[[2,4,8,[7]],[1],1,9]] + +[[1],[[[],[6,7,6,8],0,[2,3]]]] +[[[[9,7,2]],3,[8],7,[[3,6,10]]],[[],10]] + +[[3,6,[5]],[5]] +[[],[0,[[6,2],[]],3,4,[[6,1,6,10],8,[5,8],5]],[1,4],[[[8]]],[4,3,[[7,2],9,[],3,3],[5,0,[9,0],10],[[7,8,2],3,3,3]]] + +[[[7,[]],[]]] +[[[[0,1,2],[3,7,6,5,9],8],[7]],[[[8,6,3,6,2],[7,0,2,5,3],[1,2,1],8]],[7,[2,[0,0,4],[4,1,8],5,[7]],4,2,5]] + +[[9,1,10,[[5],[],[2,1,4],5,0]],[10,[2,9,1],[10,[0,4],9,4],9],[[4,3,6,[0,3,10,6]],[4,[2]],9],[],[]] +[[6,[4,[2]],[],10],[[[1,1,5],[5,6,6],7],[2],[[10],[],10],[[3,3],1,5,[1,1,9,4,3]],0],[8,[],[[]],10,1],[1,[],[[7,4,2],1,0,9],2],[[0,9],[[2],9,[9,1,8]],1,[4,1,9,[3]],3]] + +[[[3,[],[9,7]],[[3,0,2,6],2,[0,9,1],[6],[7,4,0,7]],[3,[],[10,1,6,2],0],5,3],[3,[]],[],[2,[[],10,4],[6,[5]]],[]] +[[],[],[[7,[1,1],4,7,[6]],[4],[7,3,6,[4,9,8,3],7],[4,8]]] + +[[4,3,8,2,6],[[[8,1]]],[[6,3],[3],[8,[7,7,4,2]]],[8,[6,[10,10,3],0,8],[],7,[10]],[8,0,7,4]] +[[5,10],[],[6],[]] + +[[2,6]] +[[1,7]] + +[[4,0,[[],[2,6,3],10]],[[],[1]]] +[[3,10,2],[[10,[7],[7],5],[[0,4],[9,1,8,8]],1,[9],1]] + +[[3],[[[2,1,5,0]],8,7,[[5,7]],[[],2,8]],[[9,[3,5,2,8]],[[4,7,9],[8,7,4]],[3,10],3,7],[[]]] +[[5,[],3],[8,[[2,8,10],[],9,[7,9,7],[3,10,4,1,10]],6],[]] + +[7,7,4,8,0] +[7,7,4,8] + +[[],[5],[4,0,[[1]],[[],[0,1,0],[8]],[[9,8],6,[],[8,8,6,1,4]]]] +[[],[0,[]]] + +[[[],10],[[[2,7,7,0],[5,5,1,8],0,[]]],[[[5,6,4],0,3,[10,3,2,10,2]],7,9,4,6],[[[],[6],[3,7,4,6,3],4,7]],[4,[]]] +[[8]] + +[[],[],[[10,[0,7],9,[3,6],[]]],[5,[1,2,[1],[9,2,3,4]],[[6,7,7,1,10],7],[8],[[10,8],[2,3,5,2,5],[9,9,9,10,7],[8,2]]]] +[[7],[],[[[1],9,10,[9,1,1,4],6]],[[[7,4],0,[10,1],9],0,[[],[1,6,6],[]]],[]] + +[[],[10,3,1],[[[9,5,10,10,5],[4,1],5,6,10],0]] +[[4,[[8,9,0],0,[0,10,2,4],7,5],[8,2,3,5],0],[],[3,[[0,1,2,10]]],[6,[],[[],0,3,[4,4,4,3,4]],0],[[[5],5,3],[[],[3],4,0,[3,3,6]],4,[0,6,[]],[5,5,7]]] + +[[[],4,[1,0,0,7],10],[],[],[7,[8,[4,0,10]],[[4,5,4,7],6,8,1,[7,10]]],[[[3,6,0],1,8,2],[],10,0,1]] +[[4,7,5],[6,[[0,9],[1]],[[2],[8,1,2]],8,[9,[7],7,1,[7,0,6,4]]]] + +[[6,[[6,10,4,3,8],5]],[],[[[8,9,6],[5,9,8,4,4],[3,10,3]],10,9],[[8,3,[6,2,5,1],[1,7,1]],[5,[3,8,3],[2,3,7,5],8],[[7,5,2],[5],[4,1,10],9]],[5,1,7]] +[[],[5,[6,[4,0,8,10,0],[9,6]]],[[],6,[[3]]],[]] + +[[2,[]]] +[[[]]] + +[[[8,[3,9,1,0,2],[],[1,10,9,10],[1,10,3,2,7]],6,[[8,9,0],[8,1],4]],[[5,[],[3,2,3,2,2]],[],[0,[10],7,3],5],[[10]]] +[[0,10,[3,3,7,[1,1,5],5],1],[[1,5,5,7,6],[],[],7],[],[1,[9,8,[4],2]],[[],[0,0,[3],[1]],[5,[9,10,1,1],8,1]]] + +[[10,0,3],[2],[1],[[[9,9,3,10]],[],2]] +[[[0,3,[9,1,1,5],6,[]],[8,10,5,1,[8,2,4,0,8]],[[4,9,7,7,4],[7,7,7,5,5],7],[[],[2,10,4,6,2],[6],[6,4,2,2]],2]] + +[[[[9,1,2,6,9],[8,4,5]],0]] +[[9,[[6],[],2,7,0],1,[[8,0,9],[5,1,1],10,8]],[3,[[10,3,7,0,1]]],[1,[[],2,3,[5,5],0],[[8,6,1,9,2],10,[],4]],[]] + +[[0,3,6,4]] +[[7,3,[5,[5,7],[9,3,7],0],[[7,7,10,2,3]],[10,[0,9,0,5]]],[],[]] + +[[1,1,[2,[1]],[[8,2,7]]],[7],[[3],8],[[[7,1,7],[1,6,5,0,2],7,[4,3],4],1,8,2,[[8,9]]]] +[[[10,[],5]],[[3],[6,5,5,[1,2]],8,3]] + +[[6,0,8,6],[2,5,[[10,8,6,0],6,[3,10,7]],[4,[3,9],[4,6,3]],9],[]] +[[10,[],[[10,5,6,1,10],5,[9,1,1,8]],[[2,8,8,6,5],10,4,[5,0,2,6,1],5]]] + +[[[[2,8,9,4],[8,9],[7,0],[10]],4,9],[[0,[3,2,4,0]],2,[[0,0],[10,9,1],6,[5,6,3,8]]]] +[[[6,10],[9,9],[1],[4,9,6,[3,6],[]]],[6,2,6,[[7,1,4],1,7,[4]],5],[[[10,4,6]],[4]],[5,[[5]],[[7,1,7,0,1],3,2,7,[4,5,7,8]],[10,8]],[[4,[]]]] + +[[10]] +[[[7,[]],[10,[0,1,4,6,3],0]]] + +[[5],[8]] +[[[3],10,[[7,1,1,5,6],0,4,2],8,[[6,3],[10,2,9],[3,10,3,3],1]]] + +[[],[]] +[[2,1]] + +[[],[5,8,2],[[[1,0]],4,[[2,5],8,[6,0],10]],[[[3,8,10,7],8,8,1],1,9]] +[[0,4,[[7],0,[],[5,8,7,8,4]],[2,0],4],[2,5,5,[]],[],[0,[[3,3],0,[10,1,0],5]],[]] + +[[[[4,2,8],10],[7],0],[7,[10]],[[6,[],[1,5,8],[2,1,1],8]],[[]],[[[5,5,7]],[[]],[[],[],8],7]] +[[],[[[6,7,6,1,2],4,9,[7]],7,10,4],[[],4,1]] + +[[6],[],[8],[[[6],2,9],[[],1,1,[],[2,5,3]],5,8,[[8,3],7,[],[2,10,7,0],9]]] +[[8,[[9,9,1,8],6,[6,8],1,7]],[[0,[5,7,8],6,8,6],0,2,4,[[10,6,10,6,8],[8,3,7,5],[0],2,[0]]],[],[[10],[[],[8,9,3,8,2],[6,3,2,1],[7,10,8,7,1]],[7]],[2]] + +[[10,[[4,6],[9,10,8,6,6],[10,6,0],1,0]],[[3],10,[]],[[1],2],[1,[1,[3,1,2],1,10],[[9,1],[2,4,0,10,4]],[0,8,[5,1,9,9,7],3],5],[[[10,4,3,3]],[[3,6,1],1],[[4,2,10,7,3],8,[2,6,0],[6]]]] +[[8],[[[9,6,0]],[],[],10],[[[],6,[7],[2,2,9,6]],0,10,1,1],[[[1,7,0],6,10,6,2],3,[]],[2,6,6,[]]] + +[[3,[[2,10,3,2,4],7],2,[[],7]],[],[],[[[1,4,9,3],[],7,[0,7]],0,1,3,4]] +[[4,3,[4,1,[]],[[6,5,1],10,4]]] + +[[7],[0,[3,[0,9],10],[[9,5],9,7],1,[0,[0,8,9,3,7],2]],[2],[4],[[[8],4,[7,4],8],9,7,[2,5,8]]] +[[10,[[0,3],[9]]]] + +[[[[],9,[8,8,9,10,9]],[],10,10],[10,[],0]] +[[0,[],6,3,[[],[]]],[7,[8]],[[[4,3,3,2,9],10,4,[]],5],[]] + +[[3]] +[[[3],[],[6,[7,9],[1,7,3],[8]],2,0]] + +[[[[5,8],[5],[7,5,7,6,4]],[[],1,[0,10,3,0,1]]],[]] +[[[[6,10],[1,4],[7]]]] + +[[[[6],[9,8,5]],4,[[7,6,3,2],[7,3,6,3],9,[6,4,0,5]],4],[5,[],9,[[],[6,0,9,9],4]],[[],1]] +[[[[],6,3],3,[]],[0,1,[8,[1,9,10]],0],[9,[[3,0,6,0,3],0,0],[2,[8,9,3,10]],7,[[6,3,8,9,4],[2]]],[[],0],[6,[6,[4,3]],[],4,[10,9,[2,7,9,8,3],8,[]]]] + +[[5,8,[[1,8],4,[8],[10],0],8],[],[[9,9,10,1],2,[1,8,[4,7,4,1,0],[8],6]],[[],[7,0,[4,2,7,5]],10,[]]] +[[0,[5,6],10],[[[2,9,5,1],4,[5,7,6,3,10]],8,[4,[2,4,3],9],5],[],[[9,[4],[9,5]]]] + +[[[],7,[[3],8,5,[8,7]]],[[5,4,3,8,[]],7,[[]],[],[4,[6,7],7,3]]] +[[7,2,4,[8,[0,3],1,6,[]]],[],[9,6,[8,9,3,0],[]]] + +[[[],7],[0,10,[0,[9,9],8,7,[8,3,0]]]] +[[],[[[1,5],[10,4]],[[2,1,4,1],[3,2],4,[7,9,10,5,4]],7,[]]] + +[[10,4]] +[[[[8,3,10]]],[1,[[1,8,9,9,6],[6,5,2,6,3],5],8],[6,8],[10,1,[[4,4,8],7]]] + +[[[[]]],[],[9,8]] +[[0,1,8],[1,[5,1,[10,2,4,2,5],8,8],6,2],[4,[4,[3],3,[2,0,3],7],6,[]],[[[8,5,3],10,[1,2,6,6]],4]] + +[[7,[2]],[]] +[[[[1,5,10,0,2],1,[8,2,8,2],[5,10,8,2]],4,2,[2],2],[[6,[],[],[]],[[]],9],[9,3],[8,2]] + +[[],[1],[2,[[0],8,9],5,[[10,0,3,5,2],7,2,[9,2,2],[9]],[[7],[]]]] +[[6],[[[5,4],[],[4,0]],[[5,3,0],7,[8,2,10,7],[0,8,5],5],[],[0,5],5],[[10,7],4,5,9]] + +[[7,10,3,2],[1]] +[[10,[[7,7,9,4,9]],2,[3,8,[],[],10]],[7,[[2,4],7,0,[9]],4,[[10]]]] + +[[4,[2,[],[1],10],4],[[[7],[4,6],[9,1,10,0,4],3,[2]],[[7,4]]],[[4,4,5,0]],[5,1,[[3,0,8,10]]],[3,[[2],[3,8],[],[2,6]],3,[10,[7,3],9],3]] +[[[[2,0],[2,4,10,10,9],2],7,10,[],8]] + +[[[[6,4,5,2,9]],1,[3],[6,[10,1],9,[10,10],[3,1,6,10]],5],[[]],[],[8,10,2,10,[[10,8,6],2,[],[10,9,1,10],1]]] +[[[],2],[[[7,2,2,9,7],7,2,4],[[2],3,5]]] + +[[[],[[8,5,7],[0,0,10,7]],10],[[0,10]],[[8,6],4,[4],[[],[1,0,4],[5,2,0,3,8],[9,2,5,8]]]] +[[0,[[7,7]],0,[],4]] + +[[5,0],[3,[],6,[3,10,0]]] +[[[],[4,[10,3,10],[9,4,5,0]],[],[[10,7,6,6,0],1],[10,10,7,[],[1,0,4,0,7]]],[[1],[],[],[4]],[8,[],8,[[2,6,8],2,[2]],10],[[[8,3,3,5,4],[5,8,2,8,9]],4,6],[3,2]] + +[[1]] +[[9,1,2,6,3]] + +[[8],[9,[[]],9,[[0,5,8,1],7,0,3,[0,4,1,6]],[[3,8,9,6,3],[],[8,7,4,6,10],[8,7,0]]],[[[5],[9,7,6],[8,3,2],1],8,6,[10,[6,6]],9],[[],10,[7,[6,4,3],[],6,4]],[[3],[[6]],[6,[],[],[9],[10]],9,6]] +[[[],2,[0,[3,5],4,9],3,[]]] + +[[[[1],7],[[],4,[4,8,8],[10,7,3,2],[]],[]],[7,1,6,0,[3,0,[1,0,2,6,5],[2,2,9,6,2],[6,9,6,7,10]]]] +[[[[3,2,8,9,3],[6,2,4,7],[2,7],[7,2,9,2],[3,4]],[]],[[3,2],[1,2,[9,10,3],[7],[8,8,7,3]],[0],[[4],10,5,3],[6,[],[0],[]]]] + +[[[5,[],[],5],[0,[1,0,5,1,3],10]],[8,[4,10,3,[]],5,1]] +[[2,[[8,7],5],5,0],[],[[],5],[[],2,[[9],5,[7,2,1,0],[6,2,8]],[[2,4,2],8,[9,7,8,0,7]],10]] + +[[4,7,[2,3,9],3]] +[[[[0],[0,1],7],[1,[]],4],[],[[[5,8,5,8],8,[10,6,8,4,8],[10,3,7,5],10],[]],[[[1,8,6],[5],[9,2,6,3,2]],[1,[9,10,3,2,7],[2,10],10,4],7]] + +[[[],[10],[4,[2],6,[8,1],7],8],[[9,[9,8,9,10,10],7,[8,0,9,7,4],[]],[[7,2],[5,5,9,1,3],[4,8,6],[2,10],5],3,[4,[5,6],8,[]]],[8,[7,[9,1],[1,8,6,2,7]]],[8,[],[],[[0,1],8,2],0]] +[[8,[[1,6,3],1,[6,7,0],10],10],[9,[[7,6],9,[7,6,10],9],6],[10,[[6,7],9,4,5],7,0,1],[[3],[6,1,[3,4],[0,0,5],[]]],[[[0]],10,5,[[7],[],7,[7,7,3]]]] + +[[[],7,5,1],[4],[4,[[3],0,6,[9,0,3,3,0],6],9,[[9,9,2,5]]]] +[[[[10,0,7],8],[[6,9,1],3,[2,1,1,0],10],4,10]] + +[[[[10,9,4,1,9],[1,4],0],3,[9,[2,5,0,9],9,8]],[7,[8,[1],3,[6,1,7,1,5],4],[[10,2],[9,4,7,4],[10,2]]],[10,6,0],[[[10],[],[2,3,8,6,8],2,6],[[5,3,2]],9,8,1],[[4],[[2,5,3,4],1],[2,7,4,6,[4,6]]]] +[[10,[[4,0,7,7,2],[7],[6,8]],9,7],[6]] + +[[1,4,6],[],[[0,[7,6,10],[8]],[9],[[3,4],10,[9,6,5],3],[[3]]],[8,[],1,9]] +[[[5]],[[2],[[1,3,6]],0,6,10],[4,1,[10,4,10,3],2],[6,6]] + +[[],[6,1,[[5,8]],2]] +[[7,[9,[],[5]],[6,[8,1],3],8,[6,[10,0,1],3,[6],[]]],[8,1,3,[4,[5,3,5],[],[3,10],8],0]] + +[[[3],3],[3,[10,[2,6,4,7],[10,4,4,6]],[3,10],[0,8,6,2,[10,10,5,9,8]]],[[4,2,5,[],2],[[],[9,0,8],[2,4,5,0]],[[6,10,6],9],[4,4,9,4],10],[[]],[[[7]],7,[6,[6],8],8,[[8,8]]]] +[[0,[7,[3,10,4],2]],[0,1,[[1,1],[6,0,10],2,4,[10,3]],5,4],[[[3,3,2,4],[3],3,[0,2,8,5,3]]]] + +[[[],10,[4,2]],[]] +[[[4,[10,6,3,1],[0,2,10,2,3]],9,[4,1,7,9,8]],[[[5],2,2,[8,8]],7],[[],[[],[8,4,3,7],[],[2,9,4,4],[]],[[7,10,10,9,8],3,2,6],2],[3,[[4,8,8],[10,5],1,3,8]],[[[0,7,2,4,3],[],[2,10],4,4],[],1]] + +[[3,9,10],[[[4,7,4],[10,2,4,7,7],[8]],[[3,1,5,4,4]]]] +[[5,7,5,[[7,9,1]],[[9,7,1,4,2],1]],[10,10,5,[[0,0,7,8],3]],[[3],[],[1,[1,2]],[]],[[],0,6]] + +[[[[0,6,9],[9,9],7],2,3],[[[8,9,7,7],8,5,[6]],4,5]] +[[1],[10,[[]],8,[[0,2],[2,10,4],[3],[]]],[],[[1,5,[4,1,0]],[],[5,[8,2]],[5]],[0,9,[],6,7]] + +[[9,4,[9,4]]] +[[[[2],8,8,[10,1],[6]]],[[[],[8,9],6],[]],[[1,[8],5,2,10],7]] + +[[[[3,1,2,2],0,[7,1]],[],2,9,2],[[6,[4,0,0],[4,4,6,3,2],[1,10,5,10,8],5],[4,[3,8,5,3],3,[2,6,0,4,0]],[[8,5,4,6]],3],[[[10,1,5],[],[2,3,9],[4,8]],3,[3,[],8,1]],[[[7,5,2,8,7],[4,8],[10,10],3,0],[[3],[6,9,9,5,9],4],6,5,[[2,10],[10,4],1,[10,8]]]] +[[],[9,8,[0,[9]],8,[4,[3,5]]],[]] + +[[[2,1]],[],[[],2],[[[1,7,2,9,7],3,6,[5,0,7]],6],[]] +[[2,[6,[5,4,8,0],8,6],[[8,7,5,3],[5,1,3,6],[1],2,[0,1]]],[[[9]],[[],[],2],5,6,7]] + +[[[0],[9,[]]]] +[[],[1,[7,[10],[10,6],7,[7,8,9,3]],[[8],[0],[],[9]]],[[5],[6,8]],[[8,[0,4,0],5,[2,1,10,6],[]],6,6,[[],3]],[[[2,2,7,3,3]],3,3]] + +[[9,4,[[5,10],[],[],[9,8,10,0,8],[1,6,8]],8,6],[[[0,1,9],2,[9,8,2,7]],0],[]] +[[10,5,2],[[7,[8,4]],7,4],[],[6],[4]] + +[[[6,[8],[1,9,6,9],[10,1],6],[[7,3,3],2,7,[1,0,3,2,4],[7]],4],[9,[[7,5,10,4],6,4],[[4,2,9],[7,2],[0]],2]] +[[[]],[3,[[0],[9],[],[],10]],[3,10],[7,10,[],[0,7,2,8],[3,[8,6]]]] + +[[6],[],[5,[6]]] +[[],[[9,[1,1]]],[3,0,[],2,[]]] + +[[[6,10,[]],[1,[7,4],2],6,4,[[2,8,5],5,6,[1,6,9],[9,3,4,10]]],[]] +[[],[7,[5,[9,1,5,6],[1,4,10],[2,4,10,9,3]]]] + +[[],[10,0,7,0],[2]] +[[10,[[6,2,8]]],[[1,9,[]],3,4],[1,[5],1,1]] + +[[[5,7,4,1,[9,8,7,7]],[10]],[4,7,[[4,9,9],1,6,[10,4],7],[7,10,7,5],9]] +[[],[8,0],[2,[8,3,8,1]],[[[6,8,6]],[2,7,7],[[8],5,9]],[[1,[5,8,5,7]],[9],[0,8,4,7,[]],[9,5]]] + +[[[6,6],1,10,9,10]] +[[6,6,7,[[8,7,6],3,[4],10],[8,6,[0,3,9,3,0],[5,9,10]]],[8,4,[5,[9,5,2,2],[8],4,10],2,[[10,6,6,0],[6,6,7,3],6,0,[1,6,6]]],[[],[],4],[4,[1,[2,3,1,7],3],8]] + +[] +[[1,[[4,2,6,0,1],[8,6]],[6,[4,5,9,3],10,[0,7]],8],[6,3,7,[[10,7,10,4,7],[3,0,5,10,10],10]],[[]]] + +[[5,5,[[],0,[3,10],[6,3]],[9,[10,0,6,8,8]]],[[[1,3,1],8]],[],[]] +[[6,5,[8,0,9],9,2],[10,[3]]] + +[[[],8]] +[[8,0],[[6],[4,8,[9,2,2,0],[5],[]],2],[[4,3,[9,3,5,4,5]],[[1,6,0,8],5]],[4,10,[[9,8,5,10,5],2,[4,9,9,1],[10,8,9,2],[4,10,5]],[9,1]]] + +[[[[5],[3,7],9]],[[7,10,[7,6,0],[1,0,5,6],[3,5,2,4,0]],[[2,0,7,1,7],1,[7,0,4,10],6],0,[9]],[3,[3,5,[10,8],[5,9,9]],2],[6,[],1,3]] +[[[[5,4]],[[1,9,0,5,8],4,[2,6,2,0],9]],[9,[0,7,[2,8,10,6]],[[10],[4,2,4,3,4],0],4],[],[2]] + +[[[2,[2,10,4,4,6],10,6,[3,8,3,0,2]],[[3,0,2,0],[7,1],[1,0]]]] +[[[8,1,1,[9,2]],[[9,7,2],[],7,4,3],[1,[3],[2,3],3,4],[[1],[6,7,3,2]],7],[6],[[[2,5,4,4],[],4,9,4],[[10,8,4,0],8,[1,1,6,2,6],[6,8,5,10,0],7]]] + +[[],[3],[[2,5,9],2,9,[[5,9],[2,3]]],[[3,1,[3,10,4,3,9],[2,0,6]],[[6,3],6,[9,7,9,7,10],[8,7,8,0,6]],7,[],[7]]] +[[[6,8,4,[4]]]] + +[[2,7,[],[6,[1]]],[[[8,0],[4,8],[]],[0,[2,2,1,3],[8,0,3,7,4],[7,7,4,5,3],2],1,[7,[3,9],[5,6,8,8,5],[7,2,9]]],[[0,9,4,4],[9,4]]] +[[[10,[7],5,[]],10,10,4],[1,[[],0,[10,10,7],[7,10,1,4],10],4,[0,[8,9,1,8,8],3]],[]] + +[[[3],0],[[5,1,[4,10,4],9]],[6,5,[[7,1,8],2,8,[0],5]],[[[5]],[5,[7,10],[1,9],2,[9]],2],[]] +[[[[10,5,0,1]],8,[]],[[1],[7]]] + +[[3,6,4,[7,[6,9,4,9,9],8],[10]],[0,9,3,[[],8,[10,7,1,8],7,[1,2,5,7,7]]],[4],[[4],[],7],[[[2,9,1,5,6]],8,3]] +[[[5,[7,1,4,8,9]],[[2,8,8,2,10],7,[8,9],9],10,[[3,1,0,3,3],[3,7,10,0,8]],[5,2,[3],[2,3]]],[],[5,8]] + +[[[],6,10,0]] +[[[[8],9,4,[],[]],[5,10,1,[1,4,10,9,0]],2,9,1]] + +[[]] +[[[3,4]],[[8,0,[1,9,6,7]],[9,[10,2,6,3],2,[3,6,7,8,6]],[]]] + +[[[[10],0,6,3,[4,4,3,5,10]],[2,[6,4,7]]],[]] +[[5,8,[0,[0,5],[0,8],6,[]],[8]],[[[5],[7,5,8,9],[2],[]]],[6],[[8,[9,8]],[[0,10,10],[7,6,6,2,10],[10],[]],[[2]],[4,[],[2,1],[7],4],[0,7]]] + +[[0],[],[5],[4,7]] +[[3],[6,6],[5,0],[4]] + +[[[]],[9,[[1,7,8]]]] +[[[4],7,8],[[10,3]],[10,[[7,6,10,10],7,7],[7,9,1],3,2]] + +[[],[[[],[2,5,7,6,1],8,7,9],[4,[7,5],[10]],[[7,3,1,1,3],0,1]],[10,10,[4]],[],[8,[[9,4]],[8,[3,2],[7,4],0],5,8]] +[[4,[],2],[],[],[0,4]] + +[[[4,1,9,[8,6],8],[6]],[2],[2],[[[2,3],[8,7,8,1,5],4,0,2],[[3],[1,9,10,6],3,[1,1,4,1]],[[9,5,6],[10,4,10,4],1],4],[7]] +[[[1],8,[[8]],[[6,10,5],7,7,9],[3]],[5],[[8,9],[[10,1,2],[4,8],5,6],4],[[4],8,[5],[[4,9,3,2,5],8,[],[0,4,9,4],0],9]] + +[[[],[[],7,[]],8,1],[[[0,9,5,10,0],7,9,[1,5]],7,2],[[6,[4,2,0,0,1],6,2,[1,8]]],[[0,[]],5],[0,[],[[],[8,0,6],[9],2,10]]] +[[5,[[3,3,9],[3,1],[]],[9,[1,8,7,9],0,2,4]]] + +[[0],[4,9,[[],8,[2]]],[[6,4,1,[],2],8,[[9,1,2],3,7,[1,1,2]],4,[2,[10,7,7,9,0],2,10]]] +[[10,[[0,2,5,10],8,[10],1,[8]]],[[[7],[4,8],[7],[9,10],9],0],[[[0,6],[8,3,3],[5,10,1,1,1],7],[4],[10],8,6]] + +[[0,4],[4],[5,[3,[3,7,3]],[[4,1,0,7]],9],[4,[[5,6],[7],0,6,[7,6,7,0,5]]]] +[[],[1],[5,[[2,1,6]],1,[7,[8,7,6,1,4],2,[4,5]],1],[],[[9]]] + +[[1,8],[6],[[[9],[9],[2,10,8],[2,3,1,0],[6,7]],0,2,[1]],[]] +[[[1,3,8],[[4,5,4],2,[8,8,7,9],[6,8]],9],[[1,8,[4,9,9,8,8]]],[6,[1,[5,8,3,1,4],[],[9],[6,5,2]]]] + +[[],[[],[[9]]],[]] +[[5,[4,4,[1,3,8,5],10,0],0,[],7],[]] + +[[5]] +[[[],5,3,10,3],[[1],[5,[0],[],10,8],[[10,6,3,2,6],[5,10,1,7],2,[7]]],[8,[[2,3,9,2,9]],10,10]] + +[[[2,1,9],0,[10,5,6],[0]],[[4],9,[5,3]]] +[[7,2,0,9],[[1,3],4,3,7],[9],[],[5,[[8,3],7,[2,0,1,2]],9]] + +[[[5,3],5],[],[8,[1,10,[10,1]],[6,0],[[1,2,0,2],4,0],[]],[[10,6,7,1],3,[8],[[3,10,9,0],7,[5,1],3,8]],[[7,6],10]] +[[2,8],[7,3],[[1,[6,2],7],5],[[6,[1,10,4],[0,5],[4,5]],10,10],[]] + +[[2],[[[],[],[0,8,6,2,1],6,[5]],[[1,4,5,5,7],1,2],1]] +[[],[[[8,5,9,8,7],5,[7,7,10]]],[8]] + +[[[],7],[[[9,10,6,6],[6,10,1,9,4]],[1,9,0,[0,4,10],10],4],[[[5,7],6,3,6],[[9],[2,3,5],0],2],[[[10,10]],[0,[8],[6,6],5],[[8,8],5,7],[8],2],[9,9,[[]]]] +[[[8],[[9,0,6,6,5],8],[4,[7],[4,6,6],[3,3],10],8,[]],[[[8,2]]],[9,4,[[4]],[[1,5],[0],[1,6,1],[]],0],[0,3,9,[6,7,1,0,[]]]] + +[[3,[],[[1],[4],7,[1,2,0,6,5],[5]],6],[4,9,1,1],[5,[[4,2]],[]],[2],[8,2]] +[[[8,[7,9,8,0,4],[2,3,3],[],[9,5,6]],3,[2,[2,1,3,10,10],9,[4,9,2,2],8],2],[3,0,0,5,[4,[2,1],6,[2,3,9,1,8]]],[9,0,7],[8,5,1,[],9]] + +[[],[[[2],[0,4],6],4,[[1,8],8]],[[],10]] +[[[],[5],10,[[10,5,0,7],[],1,[],7]],[3,[]],[],[2,[[8],9],[3,0,1],[[3,5],[9,2]]],[]] + +[[5,[[10],6,[3]],7],[3,10,[1]],[[[7,6,8,8,10],[5,5,2],[7,1,2],[]]],[3,9,[0,3]],[7]] +[[2,[[6]],10,[9,[8],[],[1,10,4,4,9],[5]],[8]],[10],[],[3,[10,3],2,[[4,10,5,6,7],[5,7,7],6]],[10,7]] + +[[[[],[5,2,9],10]],[[6,[],[2,0]],[[0,9,0],7,[]],[[9,3]],[]]] +[[10,[[1,1,8],7,3],[[8,6,10],4,0],9,6],[],[7,[],[3,[9,1,5],[10,4,1,8,1],0],[[3,2,1],4],[[8,10]]]] + +[[],[],[[[10,3,7,10]],0,0,6,[[6,3,4,8]]],[9,[[],[2,10]]],[[8,[],[3,10,5,8,10],6,[9,6]],6]] +[[[],[9,3,[10,7],[6],7],[[6,10,10],[3],[10,7,0,5,0],7],6],[[[7,9,4,9,4],3,7,[7,1,7,4]],8,[9,7,[6,2,3,9,1]]],[4,[],3]] + +[[5,5,9],[[5,[8,9,7,2],[5,7],[5,1,4,3,4],4],[0,[],3],1,3,3],[5,5],[[2,[2,9,4],[1,3,4],[5,6,9],[1,2]],9]] +[[[[8,6,9,9]],[[8,3,7,9],[10,1,0,3],8,[0,3,10,7]],[4,5,[3,4,3,2,6]],[[10]],9],[[[]],2],[8,10]] + +[[[0,1,[7]],8,[[3],4,0],[[]]],[[0,1],[[5],10,1,[4,6,0,10,0],[5,6,10,10]],4,[1,[1,8],[4,9,9,10,5]],[8,3,1,[],9]],[6],[[],[[2],9,[7,1,6,5],[9],[10,9]]],[[[0],[9,3]],[2,5,[8,1,7],[]],[],[],5]] +[[2,[[4,3,5,5,2],4,[9,6],2,9],9,[3,2]],[[]],[[[10,9],[2],10,4,4],3,[[3,7,3],[0,2,1,9,0]],[9,6,5]]] + +[[],[[[8,7,10],6,[3,8],5],[2,1,[1,5,4,3]],9,[[],[],[8,3],6,[10]],2],[2,0,[[],3,2,5,[0,7,8]]],[[[5,5,6],[1,9],[6],[10],7],8,[[8,7,3],0]]] +[[8,[],5,0],[],[10,[[],9,4,[7]],[]],[9],[4,10,0]] + +[[5,9],[[[10,8,5,6],5,9,7,[]],[],[0]],[[1,4]],[[[5,9,4,1],[10,7,5,9],[6],0,7],[4,8],4,10,4],[6,9,[8],1]] +[[],[9,6,[6],7,0],[6]] + +[[3,1,3,5,[]]] +[[3,[[0,8,2,10,3],[5,1,3,4,0],10,9],0,6,1],[6],[0,3,8,[2,7]],[10,2,5,[7,10],[2,3,[],[2]]]] + +[[3,8,5,[7,[5,2],4],[3]],[[1,[1,0,5,1],7],4],[[8],[[1,5,9,0,9],2,[]],7,[[4],[7],[0,10,2,5,5],8],[10,[1]]],[[10],[7,[5],5,[4,3,9],[]]]] +[[],[[6],[2]],[[2,[1,9],[8,3],1],10,0],[[10,1,[5],7,2],[4,3],[[6,4,9,1,4]]],[[5,[2,6,9],[4,7,9,6,3],[1,6,0,6,0]]]] + +[[[[0],7,[0]],[],[10,3,[5,9],6,[2,7,10]]],[],[[[5,7,3,3],[3]],0,[7,9],[7,4,[9],8,8],[7]],[10,7,10,0,5]] +[[[],[],[[],8,0,[8]],0,[]],[6,3,9,5,9],[],[[],7,7,[4],[[0],[6,3,6,0,9],9]]] + +[[5,2,[[8,0,0],8,8]]] +[[6],[[4,[9,4],[3,1]],[6,2,0,[3]],0,7]] + +[[],[[],[]],[],[10,[],[[7,4,1,3,5],9,0],[],7],[]] +[[[8,7]],[1,[0,[9],2,[]],9],[[[10,3,9,5,8],[],[]],7,[9,[3,0,3,8,9]],[[2,1],[7,2,0,2,9]]],[]] + +[[[],[[7,7],[4]],6,[[],7],[]],[[[3,0,0,1],[1,9,10,4,10]],2,[10,[],[5,0],3],1,[[7,6,2],5,10,0,[7,8]]],[]] +[[[1,[2,0,9,0,8]],[[],1,0],6,[5]],[[],10,[8,[1,2]],[]]] + +[[2,7,[[3,4,4,2],1,[9],5,3],[[2],8,[3,7,5],9]],[7],[[3,4,[],[]]],[4,[],5,[10,5,[4,4,5,0],1]]] +[[[0],2,7],[]] + +[[2],[[2,7],5,[[9],10,0],[[1,5,2,7],3,10,6,[6]],[[2,0,9,4],6]],[[[10,8,7,4,9],[10],[5,1,4],9],[[10,3,10],[],[5,9,9],[10,3,2,5,9]],[[0,7,3,10],8,3,[9,7],[3,4,9,8]],7],[[1,10,6,0],5,6]] +[[[]],[[0,2,[4,1,9]],[],5,[[10,4,5,4,2],[10,3,0,1,3]]],[3,0]] + +[[8,4,4,[[],[7,9,2,8],8,6],8],[[[9],[10]],[[5,7,5],[],[4,6,0,5,5]]]] +[[2,[[6,6,0,2,5],6,[7,1,7,9],7],[[9,3],5,[9,2,7],[9,8,3],0],2],[[[3,8,3],[3,1,5],[0,0,0,6],[5,5,4,1],[3]],[0],6,[0,[]]]] + +[[2,[3],[]],[2,[[10,4,6,10,5],3,4,8]],[[[],5,1,10],[9,[8,0,2,5],9,8,[6,10,5,9,1]],[3]]] +[[4,[[7,10],9],[7,1]],[[[8],1,9,[1,10,5]],[[9]],[[4,1,3]],10,[4,2,[9],[7,8,2,1,1],5]],[[[],0,6,2],[2,[],1,[2,9,0,8,7]],[[8]],4],[[[6,3],[],5,8,[10,3,5]],6,0,6],[[[1,1,0],0,[10]]]] + +[[3,[[1,1,9],9,[6],8,4],[]]] +[[],[6,[7,1],[6,10,[0,2,1,3],[],[8,4]],10,2],[[[6,10]],8,6,[10,[0,2,3],1]],[0,5,4,6,[]]] + +[[9,[[1,8,3,2],[3],[8,2,9,3],[6,8,7]]]] +[[],[6,[[10,1,9]]],[10],[6,[[4]],[[2,8,10],[5,10],[2,8,3]],0],[7,5,1,[[7,10,3,1,9]],[[0,1,0,0,3],[]]]] + +[[1,7],[0,[],2]] +[[[[2,0,0,5,1],3,[5,6]]]] + +[[8,[[0,8],2,3],10,[[6,5,0,1,6],10,8,[10,4,5]],5],[1,4,2,6,[[9,7,10,7,9],2,5]],[5,[[6,0,4,8]],7,[[2,3,2,7]]],[[4,[],7,7,5],[[],10,[],8],[[1,6,5],2,0,8,[]],[[0,9,7,1,3],9,[7,2,9,8]],[[],[1,7],2,2]],[1,8]] +[[10,[]],[9,[]],[[4,[4],3],7,[[4,2,4],10]],[[5,[5,5,4,3],4,6,[6]],9,[[5,8,7,4,6],[],10,2,[1]]],[]] + +[[6,9],[0,2,[[9],0,[8,10,9,7]],7,[4,4,2,[]]],[[9],[7,[8,4],[8,2],0],[[4,2],[5],[4,6],[0,6]],[5]],[[[9,2],8,[0],9,[1,9,4]],[[7,0,2,5,5],1,[6,8,2],6,7]],[[10],9,3,5,[]]] +[[[[4],0],[],[5,9,[9,3,4,9,7],8],3,9],[7,8,2,3,0],[4,[5,[7,2,3,9],6,[0,4,0,3],8]]] + +[[[[2,4,0,1],[2,10,7,6,1],7,[7,1,10],7],[],[[8],1,[9,6,5,2],4,[4]]],[[4,1,[5,9,7],[4],6],4,3,[[8,2,8,8,9],[7,0,10]]],[[]],[[],[[0,0,1,3],5],9],[1]] +[[[[]],[9],[[6,5,0,0],[8,8,9,2],[10,10,10,8,2],[7,2,4,0,0]]],[8,[3,[6,1,5,7,4],5,0,4],3]] + +[[4,[]],[9,2,[0],[3,2,[2,6,7,5,6]]],[[[3],[],[4,5,9,0,2],[5,3,0,1],[2,7,7]],10,9,3,[[3,4,6,8,10],3,1,2]],[]] +[[[8,[3,2,2],10,10,[8,7,8]],[[7,2,2],[1,8,2,7],[0,2,1,2,7]],[8],7],[10,0]] + +[[[[6,6,3,4,0],5],[6,7,9],5,[[4,9,1],[9,2],0,6],[7]],[7]] +[[[0]]] + +[[[],8,[]],[1],[]] +[[6,[]],[3,4],[[7,[9],3,4,7],[10,[3,10],0,3,[1,9]],[0,5,[6,3,6,7],2,9]]] + +[7,6,8,6] +[7,6,8,6,4] + +[[[5,[10],[6,2,2],3],7,[],[],7],[[2,[7,5,3],1,7,10],6,[[],4,9],[6,[4,8]],1],[],[[[2,4,3,6,3],[0,10,8],[2,2,7]],6,[[5,7],2,5,10],[9,[0,8,0,9,7]]]] +[[10],[3,[[3,5,5],[5,2,10],[2,9,10],[1,3,3,0,7],1],[[7,2,4,3],1,[0,8]]],[5,0,[[3],5,8],[[],9,[4,10,1],7]]] + +[[9,[[],1,1,4],[10,4,[5,3,1,6],10,[]],0,0],[8,7,4],[6,[3,[9,9,6,3,3],[10,0]],[[],4,[10,0,9],1]],[[4,[6,3],[0,10,8,5,5],1,7],[[]],2,3,1]] +[[[3,[3,8],[4,9,3,8,1]]],[],[[3,[],[4,3,9],8],4,1,2,2],[],[[[5,3,8,7]]]] + +[[[[8,9,3,6,4],[9,10,3],[],6],[4,1,[0,2,3]],4,[[9,6],10,9,0]],[[[9,8,1,0],[8,9,5,4,6]]],[[]],[[3],6,[2,6,8,[2,1,3,3,6],[4,7,5,1]]],[2]] +[[],[10],[[4],10,[8]]] + +[[3,[[9,9],[4,4,5,8,3],0,4],9,[[1,9,0],4,1,0,8]]] +[[2,2,[6,4],[],7],[0],[10,8]] + +[[[[]],6,[[3,8,6,3,9]],9,6],[5,[[0,9,8,7],1,8],9,7],[4,[2,[4,8,3,6]],5,[0,8,[3,9,6,3,10]],7]] +[[0,[],8]] + +[[[[6,8],[10,1,5,1,5]],[[]],[[4,0,10,6],4,[10,5,1],9],[10],[10,[],[10,2],[10,4,3,7],[3]]],[10,2,[10,[],8],[8,[1,5,0,7,5],[],[4,9,10]],9]] +[[[],10,[],8,10],[[[],7,0,[10,0,1,10,4]],5],[8,[4,3],[[10,10,9,1],[3,0,6]],4],[[]],[]] diff --git a/data/day14.test b/data/day14.test new file mode 100644 index 0000000..4e87bb5 --- /dev/null +++ b/data/day14.test @@ -0,0 +1,2 @@ +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9 diff --git a/data/day14.txt b/data/day14.txt new file mode 100644 index 0000000..6db285a --- /dev/null +++ b/data/day14.txt @@ -0,0 +1,146 @@ +525,119 -> 525,122 -> 523,122 -> 523,125 -> 529,125 -> 529,122 -> 528,122 -> 528,119 +497,69 -> 497,73 -> 489,73 -> 489,78 -> 504,78 -> 504,73 -> 501,73 -> 501,69 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +497,69 -> 497,73 -> 489,73 -> 489,78 -> 504,78 -> 504,73 -> 501,73 -> 501,69 +487,45 -> 492,45 +494,45 -> 499,45 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +514,60 -> 519,60 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +501,16 -> 505,16 +535,160 -> 535,164 -> 529,164 -> 529,167 -> 544,167 -> 544,164 -> 539,164 -> 539,160 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +535,160 -> 535,164 -> 529,164 -> 529,167 -> 544,167 -> 544,164 -> 539,164 -> 539,160 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +501,66 -> 506,66 +535,160 -> 535,164 -> 529,164 -> 529,167 -> 544,167 -> 544,164 -> 539,164 -> 539,160 +497,63 -> 502,63 +495,22 -> 499,22 +511,89 -> 511,90 -> 524,90 -> 524,89 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +503,81 -> 503,83 -> 499,83 -> 499,87 -> 514,87 -> 514,83 -> 506,83 -> 506,81 +500,60 -> 505,60 +498,50 -> 498,51 -> 508,51 -> 508,50 +498,50 -> 498,51 -> 508,51 -> 508,50 +515,66 -> 520,66 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +510,57 -> 515,57 +518,147 -> 518,140 -> 518,147 -> 520,147 -> 520,138 -> 520,147 -> 522,147 -> 522,139 -> 522,147 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +523,157 -> 535,157 -> 535,156 +486,25 -> 490,25 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +490,43 -> 495,43 +511,89 -> 511,90 -> 524,90 -> 524,89 +486,41 -> 491,41 +535,160 -> 535,164 -> 529,164 -> 529,167 -> 544,167 -> 544,164 -> 539,164 -> 539,160 +525,119 -> 525,122 -> 523,122 -> 523,125 -> 529,125 -> 529,122 -> 528,122 -> 528,119 +518,147 -> 518,140 -> 518,147 -> 520,147 -> 520,138 -> 520,147 -> 522,147 -> 522,139 -> 522,147 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +525,119 -> 525,122 -> 523,122 -> 523,125 -> 529,125 -> 529,122 -> 528,122 -> 528,119 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +495,16 -> 499,16 +511,89 -> 511,90 -> 524,90 -> 524,89 +497,69 -> 497,73 -> 489,73 -> 489,78 -> 504,78 -> 504,73 -> 501,73 -> 501,69 +504,19 -> 508,19 +525,119 -> 525,122 -> 523,122 -> 523,125 -> 529,125 -> 529,122 -> 528,122 -> 528,119 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +484,47 -> 489,47 +518,147 -> 518,140 -> 518,147 -> 520,147 -> 520,138 -> 520,147 -> 522,147 -> 522,139 -> 522,147 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +497,69 -> 497,73 -> 489,73 -> 489,78 -> 504,78 -> 504,73 -> 501,73 -> 501,69 +528,134 -> 532,134 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +522,134 -> 526,134 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +480,45 -> 485,45 +498,47 -> 503,47 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +501,22 -> 505,22 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +507,22 -> 511,22 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +494,66 -> 499,66 +477,47 -> 482,47 +497,69 -> 497,73 -> 489,73 -> 489,78 -> 504,78 -> 504,73 -> 501,73 -> 501,69 +508,66 -> 513,66 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +513,152 -> 531,152 -> 531,151 +525,131 -> 529,131 +503,81 -> 503,83 -> 499,83 -> 499,87 -> 514,87 -> 514,83 -> 506,83 -> 506,81 +510,25 -> 514,25 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +497,69 -> 497,73 -> 489,73 -> 489,78 -> 504,78 -> 504,73 -> 501,73 -> 501,69 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +503,81 -> 503,83 -> 499,83 -> 499,87 -> 514,87 -> 514,83 -> 506,83 -> 506,81 +489,22 -> 493,22 +504,25 -> 508,25 +518,147 -> 518,140 -> 518,147 -> 520,147 -> 520,138 -> 520,147 -> 522,147 -> 522,139 -> 522,147 +531,131 -> 535,131 +525,119 -> 525,122 -> 523,122 -> 523,125 -> 529,125 -> 529,122 -> 528,122 -> 528,119 +535,160 -> 535,164 -> 529,164 -> 529,167 -> 544,167 -> 544,164 -> 539,164 -> 539,160 +492,19 -> 496,19 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +483,43 -> 488,43 +498,25 -> 502,25 +534,134 -> 538,134 +498,19 -> 502,19 +506,54 -> 511,54 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +503,81 -> 503,83 -> 499,83 -> 499,87 -> 514,87 -> 514,83 -> 506,83 -> 506,81 +503,81 -> 503,83 -> 499,83 -> 499,87 -> 514,87 -> 514,83 -> 506,83 -> 506,81 +513,152 -> 531,152 -> 531,151 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +525,119 -> 525,122 -> 523,122 -> 523,125 -> 529,125 -> 529,122 -> 528,122 -> 528,119 +518,63 -> 523,63 +518,147 -> 518,140 -> 518,147 -> 520,147 -> 520,138 -> 520,147 -> 522,147 -> 522,139 -> 522,147 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +535,160 -> 535,164 -> 529,164 -> 529,167 -> 544,167 -> 544,164 -> 539,164 -> 539,160 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +491,47 -> 496,47 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +504,63 -> 509,63 +518,147 -> 518,140 -> 518,147 -> 520,147 -> 520,138 -> 520,147 -> 522,147 -> 522,139 -> 522,147 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +525,119 -> 525,122 -> 523,122 -> 523,125 -> 529,125 -> 529,122 -> 528,122 -> 528,119 +522,66 -> 527,66 +503,81 -> 503,83 -> 499,83 -> 499,87 -> 514,87 -> 514,83 -> 506,83 -> 506,81 +511,63 -> 516,63 +535,160 -> 535,164 -> 529,164 -> 529,167 -> 544,167 -> 544,164 -> 539,164 -> 539,160 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +498,50 -> 498,51 -> 508,51 -> 508,50 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +503,81 -> 503,83 -> 499,83 -> 499,87 -> 514,87 -> 514,83 -> 506,83 -> 506,81 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +516,103 -> 516,102 -> 516,103 -> 518,103 -> 518,96 -> 518,103 -> 520,103 -> 520,97 -> 520,103 -> 522,103 -> 522,94 -> 522,103 -> 524,103 -> 524,99 -> 524,103 -> 526,103 -> 526,97 -> 526,103 -> 528,103 -> 528,96 -> 528,103 -> 530,103 -> 530,102 -> 530,103 -> 532,103 -> 532,94 -> 532,103 +498,13 -> 502,13 +503,57 -> 508,57 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +518,147 -> 518,140 -> 518,147 -> 520,147 -> 520,138 -> 520,147 -> 522,147 -> 522,139 -> 522,147 +492,25 -> 496,25 +480,38 -> 480,31 -> 480,38 -> 482,38 -> 482,35 -> 482,38 -> 484,38 -> 484,35 -> 484,38 -> 486,38 -> 486,28 -> 486,38 -> 488,38 -> 488,36 -> 488,38 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +497,69 -> 497,73 -> 489,73 -> 489,78 -> 504,78 -> 504,73 -> 501,73 -> 501,69 +518,147 -> 518,140 -> 518,147 -> 520,147 -> 520,138 -> 520,147 -> 522,147 -> 522,139 -> 522,147 +528,116 -> 528,114 -> 528,116 -> 530,116 -> 530,113 -> 530,116 -> 532,116 -> 532,112 -> 532,116 -> 534,116 -> 534,110 -> 534,116 -> 536,116 -> 536,113 -> 536,116 +507,60 -> 512,60 +523,157 -> 535,157 -> 535,156 +528,128 -> 532,128 diff --git a/data/day15.txt b/data/day15.txt new file mode 100644 index 0000000..f7e996c --- /dev/null +++ b/data/day15.txt @@ -0,0 +1,23 @@ +Sensor at x=325337, y=2568863: closest beacon is at x=-518661, y=2000000 +Sensor at x=3988825, y=837820: closest beacon is at x=4305648, y=2127118 +Sensor at x=1611311, y=2053174: closest beacon is at x=2827226, y=1579510 +Sensor at x=101890, y=3940049: closest beacon is at x=955472, y=3457514 +Sensor at x=3962702, y=2558425: closest beacon is at x=4226981, y=2604726 +Sensor at x=2957890, y=2160813: closest beacon is at x=2827226, y=1579510 +Sensor at x=3907456, y=3325610: closest beacon is at x=3696221, y=3226373 +Sensor at x=3354177, y=3435919: closest beacon is at x=3696221, y=3226373 +Sensor at x=3997379, y=3071868: closest beacon is at x=3696221, y=3226373 +Sensor at x=145143, y=1714962: closest beacon is at x=-518661, y=2000000 +Sensor at x=611563, y=3148864: closest beacon is at x=955472, y=3457514 +Sensor at x=3080405, y=3904777: closest beacon is at x=3696221, y=3226373 +Sensor at x=644383, y=10732: closest beacon is at x=364635, y=-294577 +Sensor at x=3229566, y=1694167: closest beacon is at x=2827226, y=1579510 +Sensor at x=1600637, y=3984884: closest beacon is at x=955472, y=3457514 +Sensor at x=2959765, y=2820860: closest beacon is at x=2491502, y=2897876 +Sensor at x=2235330, y=3427797: closest beacon is at x=2491502, y=2897876 +Sensor at x=2428996, y=210881: closest beacon is at x=2827226, y=1579510 +Sensor at x=369661, y=687805: closest beacon is at x=364635, y=-294577 +Sensor at x=3558476, y=2123614: closest beacon is at x=4305648, y=2127118 +Sensor at x=3551529, y=2825104: closest beacon is at x=3696221, y=3226373 +Sensor at x=64895, y=3577: closest beacon is at x=364635, y=-294577 +Sensor at x=3079531, y=1538659: closest beacon is at x=2827226, y=1579510 diff --git a/data/day16.txt b/data/day16.txt new file mode 100644 index 0000000..7c336ed --- /dev/null +++ b/data/day16.txt @@ -0,0 +1,59 @@ +Valve QE has flow rate=3; tunnels lead to valves OU, ME, UX, AX, TW +Valve TN has flow rate=16; tunnels lead to valves UW, CG, WB +Valve UX has flow rate=0; tunnels lead to valves AA, QE +Valve HK has flow rate=5; tunnels lead to valves HT, QU, TW, WV, OK +Valve SK has flow rate=14; tunnels lead to valves GH, GA, XM +Valve HY has flow rate=0; tunnels lead to valves LG, AA +Valve BK has flow rate=0; tunnels lead to valves SZ, AA +Valve BY has flow rate=11; tunnels lead to valves SP, HS, DN, KD, TK +Valve GR has flow rate=0; tunnels lead to valves FE, OK +Valve OH has flow rate=0; tunnels lead to valves BM, KE +Valve DC has flow rate=0; tunnels lead to valves AX, XH +Valve YS has flow rate=0; tunnels lead to valves XH, EU +Valve KP has flow rate=0; tunnels lead to valves KI, OF +Valve LG has flow rate=0; tunnels lead to valves FE, HY +Valve FE has flow rate=4; tunnels lead to valves RU, GR, YI, LG, ME +Valve NK has flow rate=0; tunnels lead to valves SD, BM +Valve EU has flow rate=0; tunnels lead to valves NS, YS +Valve OF has flow rate=0; tunnels lead to valves CJ, KP +Valve TW has flow rate=0; tunnels lead to valves HK, QE +Valve GL has flow rate=0; tunnels lead to valves AF, CQ +Valve OU has flow rate=0; tunnels lead to valves KN, QE +Valve BM has flow rate=24; tunnels lead to valves GH, NK, YH, OH +Valve GA has flow rate=0; tunnels lead to valves SK, SZ +Valve EI has flow rate=17; tunnels lead to valves ZX, AF +Valve QN has flow rate=25; tunnel leads to valve SD +Valve ZX has flow rate=0; tunnels lead to valves EI, WB +Valve ME has flow rate=0; tunnels lead to valves QE, FE +Valve CJ has flow rate=21; tunnels lead to valves OF, YI, KD +Valve AX has flow rate=0; tunnels lead to valves DC, QE +Valve LW has flow rate=0; tunnels lead to valves AA, HT +Valve CQ has flow rate=18; tunnels lead to valves GL, XM +Valve KN has flow rate=0; tunnels lead to valves SZ, OU +Valve HS has flow rate=0; tunnels lead to valves UZ, BY +Valve RU has flow rate=0; tunnels lead to valves TK, FE +Valve SZ has flow rate=6; tunnels lead to valves WV, GA, BK, KE, KN +Valve AF has flow rate=0; tunnels lead to valves GL, EI +Valve YI has flow rate=0; tunnels lead to valves FE, CJ +Valve HT has flow rate=0; tunnels lead to valves LW, HK +Valve WV has flow rate=0; tunnels lead to valves SZ, HK +Valve TK has flow rate=0; tunnels lead to valves BY, RU +Valve GH has flow rate=0; tunnels lead to valves BM, SK +Valve CG has flow rate=0; tunnels lead to valves TN, SP +Valve AA has flow rate=0; tunnels lead to valves HY, UX, VQ, LW, BK +Valve SP has flow rate=0; tunnels lead to valves BY, CG +Valve XM has flow rate=0; tunnels lead to valves SK, CQ +Valve DN has flow rate=0; tunnels lead to valves NS, BY +Valve XH has flow rate=22; tunnels lead to valves YS, QU, UZ, DC +Valve KI has flow rate=20; tunnels lead to valves UW, KP +Valve OK has flow rate=0; tunnels lead to valves HK, GR +Valve YH has flow rate=0; tunnels lead to valves VQ, BM +Valve UZ has flow rate=0; tunnels lead to valves XH, HS +Valve KE has flow rate=0; tunnels lead to valves OH, SZ +Valve VQ has flow rate=0; tunnels lead to valves AA, YH +Valve QU has flow rate=0; tunnels lead to valves HK, XH +Valve WB has flow rate=0; tunnels lead to valves TN, ZX +Valve UW has flow rate=0; tunnels lead to valves KI, TN +Valve SD has flow rate=0; tunnels lead to valves NK, QN +Valve NS has flow rate=23; tunnels lead to valves EU, DN +Valve KD has flow rate=0; tunnels lead to valves BY, CJ diff --git a/package.yaml b/package.yaml index 11b602c..620b0ac 100644 --- a/package.yaml +++ b/package.yaml @@ -22,6 +22,7 @@ description: Please see the README on GitHub at = 4.7 && < 5 - ghc +- containers # - modular-arithmetic ghc-options: @@ -35,19 +36,19 @@ ghc-options: - -Wpartial-fields - -Wredundant-constraints -# library: -# source-dirs: src +library: + source-dirs: src -executables: - AOC22-exe: - main: Main.hs - source-dirs: src - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - AOC22 +# executables: +# AOC22-exe: +# main: Main.hs +# source-dirs: src +# ghc-options: +# - -threaded +# - -rtsopts +# - -with-rtsopts=-N +# dependencies: +# - AOC22 # tests: # AOC22-test: diff --git a/src/AOCUtil.hs b/src/AOCUtil.hs index 30a3428..839785e 100644 --- a/src/AOCUtil.hs +++ b/src/AOCUtil.hs @@ -94,3 +94,7 @@ addT (a1, a2) (b1, b2) = (a1 + b1, a2 + b2) manhattan :: Num a => (a, a) -> (a, a) -> a manhattan (a1, a2) (b1, b2) = abs (a1 - b1) + abs (a2 - b2) + +fromEither :: Either a a -> a +fromEither (Left a) = a +fromEither (Right a) = a diff --git a/src/Days/Day11.hs b/src/Days/Day11.hs index db95295..317564a 100644 --- a/src/Days/Day11.hs +++ b/src/Days/Day11.hs @@ -4,7 +4,6 @@ import AOCUtil import Data.Bool import Data.Char import Data.List -import Data.Modular import GHC.Utils.Misc runA :: IO () diff --git a/src/Days/Day12.hs b/src/Days/Day12.hs new file mode 100644 index 0000000..18b82f8 --- /dev/null +++ b/src/Days/Day12.hs @@ -0,0 +1,59 @@ +module Days.Day12 where + +import AOCUtil +import Data.Bool +import Data.Char +import Data.List +import Data.Maybe +import Debug.Trace +import GHC.Arr +import GHC.Utils.Misc + +runA :: IO () +runA = interactF "data/day12.txt" solve + +runB :: IO () +runB = interactF "data/day12.txt" solveB + +solve :: String -> String +solve s = show . bfs [findStart m] $ m + where + m = readMap s + +solveB :: String -> String +solveB s = show . bfs (getStarts m) $ m + where + m = setupStarts $ readMap s + +data Node = Node {level :: Int, dist :: Maybe Int, isTarget :: Bool} deriving (Show) + +type Map = Array (Int, Int) Node + +readNode :: Char -> Node +readNode 'S' = Node {level = 0, dist = Just 0, isTarget = False} +readNode 'E' = Node {level = 25, dist = Nothing, isTarget = True} +readNode c = Node {level = fromEnum c - fromEnum 'a', dist = Nothing, isTarget = False} + +readMap :: String -> Map +readMap s = listArray ((0, 0), (length (head ls) - 1, length ls - 1)) . map readNode . concat . transpose $ ls + where + ls = lines s + +findStart :: Map -> (Int, Int) +findStart = fst . head . filter (isJust . dist . snd) . assocs + +setupStarts :: Map -> Map +setupStarts = amap (\m -> if level m == 0 then m {dist = Just 0} else m) + +getStarts :: Map -> [(Int, Int)] +getStarts = map fst . filter (any (== 0) . dist . snd) . assocs + +bfs :: [(Int, Int)] -> Map -> Int +bfs (p@(x, y) : ns) m + | isTarget n = fromJust $ dist n + | otherwise = bfs (ns ++ new) $ m // [((x2, y2), (m ! (x2, y2)) {dist = fmap (+ 1) d}) | (x2, y2) <- new] + where + n = m ! p + d = dist n + new = filter (isNothing . dist . (m !)) . filter ((<= level n + 1) . level . (m !)) . filter (inRange (bounds m)) $ [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)] +bfs [] _ = error "dfs could not reach target" diff --git a/src/Days/Day13.hs b/src/Days/Day13.hs new file mode 100644 index 0000000..fd7678a --- /dev/null +++ b/src/Days/Day13.hs @@ -0,0 +1,73 @@ +{-# LANGUAGE TupleSections #-} + +module Days.Day13 where + +import AOCUtil +import Data.Bool +import Data.Char +import Data.List +import Data.Maybe +import Debug.Trace +import GHC.Arr +import GHC.Utils.Misc + +runA :: IO () +runA = interactF "data/day13.txt" solve + +runB :: IO () +runB = interactF "data/day13.txt" solveB + +solve :: String -> String +solve = show . sum . map fst . filter ((== LT) . snd) . zip [1 ..] . map (uncurry cmpE . first2 . map parseElement) . splitOn "" . lines + +solveB :: String -> String +solveB = show . product . map fst . filter ((`elem` dividers) . snd) . zip [1 ..] . sortBy cmpE . (++ dividers) . map parseElement . filter (/= "") . lines + +data Element = I Int | E [Element] deriving (Eq) + +instance Show Element where + show (I i) = show i + show (E ls) = show ls + +dividers :: [Element] +dividers = [E [E [I 2]], E [E [I 6]]] + +cmpE :: Element -> Element -> Ordering +cmpE (I i) (I j) = compare i j +cmpE (E ls) (E ms) = fromMaybe EQ . listToMaybe . dropWhile (== EQ) . (++ [length ls `compare` length ms]) . zipWith cmpE ls $ ms +cmpE (E ls) (I j) = cmpE (E ls) (E [I j]) +cmpE (I i) (E ms) = cmpE (E [I i]) (E ms) + +parseElement :: String -> Element +parseElement s + | isDigit (head s) = I . read $ s + | (== '[') . head $ s = E . map parseElement . splitBlocks . tail . init $ s + +splitBlocks :: String -> [String] +splitBlocks = filter (not . null) . splitBlocks' 0 "" + +splitBlocks' :: Int -> String -> String -> [String] +splitBlocks' l p [] = [p] +splitBlocks' l prev (s : ss) + | l /= 0 && s == '[' = splitBlocks' (l + 1) (prev ++ [s]) ss -- levle up + | l /= 0 && s == ']' = splitBlocks' (l - 1) (prev ++ [s]) ss -- level down + | s == '[' = prev : splitBlocks' (l + 1) [s] ss -- levle up + | s == ']' = prev : splitBlocks' (l - 1) [] ss -- level down + | l /= 0 = splitBlocks' l (prev ++ [s]) ss + | s == ',' = prev : splitBlocks' l [] ss + | otherwise = splitBlocks' l (prev ++ [s]) ss + +-- newtype Parser a = P {parse :: String -> (String, Maybe a)} + +-- instance Functor Parser where +-- fmap f (P st) = P $ \stream -> case st stream of +-- (res, Nothing) -> (res, Nothing) +-- (res, Just a) -> (res, Just (f a)) + +-- instance Applicative Parser where +-- pure a = P (\stream -> (stream, Just a)) +-- P ff <*> P xx = P $ \stream0 -> case ff stream0 of +-- (stream1, Nothing) -> (stream1, Nothing) +-- (stream1, Just f) -> case xx stream1 of +-- (stream2, Nothing) -> (stream2, Nothing) +-- (stream2, Just x) -> (stream2, Just (f x)) diff --git a/src/Days/Day14.hs b/src/Days/Day14.hs new file mode 100644 index 0000000..9678e25 --- /dev/null +++ b/src/Days/Day14.hs @@ -0,0 +1,76 @@ +module Days.Day14 where + +import AOCUtil +import Data.Bool +import Data.Char +import Data.Either +import Data.IntSet qualified as Data.Map +import Data.List +import Data.Maybe +import Data.Set qualified +import Debug.Trace +import GHC.Arr +import GHC.Utils.Misc + +runA :: IO () +runA = interactF "data/day14.txt" solve + +runB :: IO () +runB = interactF "data/day14.txt" solveB + +type Pos = (Int, Int) + +type Path = [Pos] + +type CMap = Data.Set.Set Pos -- occupied + +solve :: String -> String +solve = show . fst . head . dropWhile (isRight . snd) . zip [0 ..] . tail . iterate (insertSand . fromEither) . Right . readMap . readPaths + +solveB :: String -> String +solveB s = show . fst . head . dropWhile (not . Data.Set.member source . snd) . zip [0 ..] . iterate (insertSand2 fl) $ m + where + m = readMap . readPaths $ s + fl = floorY m + +insertSand :: CMap -> Either CMap CMap -- Left ^= Could not insert, Right ^=could +insertSand set = maybe (Left set) (Right . flip Data.Set.insert set) $ newPos set source + +insertSand2 :: Int -> CMap -> CMap -- Left ^= Could not insert, Right ^=could +insertSand2 fl set = flip Data.Set.insert set . newPos2 fl set $ source + +newPos :: CMap -> Pos -> Maybe Pos +newPos set (x, y) + | y > maxY set = Nothing + | not $ Data.Set.member (x, y + 1) set = newPos set (x, y + 1) + | not $ Data.Set.member (x - 1, y + 1) set = newPos set (x - 1, y + 1) + | not $ Data.Set.member (x + 1, y + 1) set = newPos set (x + 1, y + 1) + | otherwise = Just (x, y) + +newPos2 :: Int -> CMap -> Pos -> Pos +newPos2 fl set (x, y) + | y + 1 == fl = (x, y) -- floor reached + | not $ Data.Set.member (x, y + 1) set = newPos2 fl set (x, y + 1) + | not $ Data.Set.member (x - 1, y + 1) set = newPos2 fl set (x - 1, y + 1) + | not $ Data.Set.member (x + 1, y + 1) set = newPos2 fl set (x + 1, y + 1) + | otherwise = (x, y) + +readPaths :: String -> [Path] +readPaths = map (map (first2 . map read . splitOn ',') . filter (/= "->") . words) . lines + +expandPath :: Path -> [Pos] +expandPath [] = [] +expandPath [p] = [p] +expandPath ((x1, y1) : (x2, y2) : ps) = [(x, y) | x <- [min x1 x2 .. max x1 x2], y <- [min y1 y2 .. max y1 y2]] ++ expandPath ((x2, y2) : ps) + +readMap :: [Path] -> CMap +readMap = Data.Set.fromList . concatMap expandPath + +source :: Pos +source = (500, 0) + +maxY :: CMap -> Int +maxY = maximum . map snd . Data.Set.toList + +floorY :: CMap -> Int +floorY = (+ 2) . maxY diff --git a/src/Days/Day15.hs b/src/Days/Day15.hs new file mode 100644 index 0000000..bc878c7 --- /dev/null +++ b/src/Days/Day15.hs @@ -0,0 +1,101 @@ +module Days.Day15 where + +import AOCUtil +import Data.Bifunctor +import Data.Bool +import Data.Char +import Data.Either +import Data.IntSet qualified as Data.Map +import Data.Ix +import Data.List +import Data.Maybe +import Data.Set qualified +import Debug.Trace +import GHC.Arr +import GHC.Utils.Misc + +runA :: IO () +runA = interactF "data/day15.txt" solve + +runB :: IO () +runB = interactF "data/day15.txt" solveB + +aLine :: Int +aLine = 2000000 + +solve :: String -> String +-- solve s = show . subtract (beaconsLine d) . length . nub . sort . filter ((== line) . snd) . concatMap coveredPos $ d +-- solve s = show . length . filter (isInRange d) $ [(x, line) | x <- [minXSens d - maxDistance d .. maxXSens d + maxDistance d]] +solve s = show . subtract (beaconsOnLine aLine d) . sum . map sLen . traceShowId . (allOnLine aLine) $ d + where + d = readData s + +solveB :: String -> String +solveB s = show . filter (any (inRange (0, sMax)) . fst) . map (\i -> ((,i) . concatMap asList2 . allOnLine i $ d)) $ [0 .. sMax] + where + d = readData s + +type Pos = (Int, Int) + +type Dat = [(Pos, Pos)] + +readData :: String -> Dat +readData = map (toData . map (read . takeWhile isDigit2) . tail . splitOn '=') . lines + +isDigit2 :: Char -> Bool +isDigit2 c = isDigit c || c == '-' + +toData :: [Int] -> (Pos, Pos) +toData [a, b, c, d] = ((a, b), (c, d)) + +onLine :: Int -> (Pos, Pos) -> Maybe (Int, Int) -- sensor, beacon -> startx starty +onLine line (s@(x, y), b) + | manhattan s b < abs (y - line) = Nothing + | otherwise = Just (x - expansion, x + expansion) + where + expansion = manhattan s b - abs (y - line) + +allOnLine :: Int -> Dat -> [(Int, Int)] +allOnLine line = foldl collapseSections [] . sort . mapMaybe (onLine line) + +beaconsOnLine :: Int -> Dat -> Int +beaconsOnLine line = length . nub . sort . filter ((== line) . snd) . map snd + +collapseSections :: [(Int, Int)] -> (Int, Int) -> [(Int, Int)] +collapseSections [] a = [a] +collapseSections (l@(s, e) : ls) n@(ns, ne) + | e < ns = n : l : ls + | otherwise = (s, max ne e) : ls -- join + +sLen :: (Int, Int) -> Int +sLen (a, b) = b - a + 1 + +sMax :: Int +sMax = 4000000 + +-- ---------------------------- + +-- maxDistance :: Dat -> Int +-- maxDistance = maximum . map (uncurry manhattan) + +-- minXSens :: Dat -> Int +-- minXSens = minimum . map (fst . fst) + +-- maxXSens :: Dat -> Int +-- maxXSens = maximum . map (fst . fst) + +-- isInRange :: Dat -> Pos -> Bool +-- isInRange dat p = any (isInRange' p) dat + +-- isInRange' :: Pos -> (Pos, Pos) -> Bool +-- isInRange' p (s, b) = manhattan s b >= manhattan s p + +-- ---------------------------------------- + +-- coveredPos :: (Pos, Pos) -> [Pos] +-- coveredPos (p@(x, y), s@(sx, sy)) = filter ((<= lim) . manhattan p) [(x, y) | x <- [x - lim .. x + lim], y <- [y - lim .. y + lim]] +-- where +-- lim = manhattan p s + +-- beaconsLine :: Int -> [(Pos, Pos)] -> Int +-- beaconsLine line = length . filter (== line) . map snd . nub . sort . map snd