From e06aa0990da7a316ddb0406c08f37e06ceee756b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 24 Dec 2020 10:26:42 +0100 Subject: [PATCH] Add 2020 day 20 part1 + wip part2 --- haskellAoC/inputs/2020/20 | 1727 ++++++++++++++++++++++++++++++++ haskellAoC/inputs/2020/20_test | 107 ++ haskellAoC/src/Y2020/Day20.hs | 152 ++- 3 files changed, 1984 insertions(+), 2 deletions(-) create mode 100644 haskellAoC/inputs/2020/20 create mode 100644 haskellAoC/inputs/2020/20_test diff --git a/haskellAoC/inputs/2020/20 b/haskellAoC/inputs/2020/20 new file mode 100644 index 0000000..96e9e59 --- /dev/null +++ b/haskellAoC/inputs/2020/20 @@ -0,0 +1,1727 @@ +Tile 3457: +##.###.##. +...#..##.# +#.#..###.. +##.....#.. +#.#....#.# +...##.#... +##..#....# +..###..#.. +#........# +#.##..#.#. + +Tile 3061: +##....#### +#.#....... +#.....##.. +#........# +.....#.... +##......## +.##..###.. +........#. +...#....#. +..###.#.## + +Tile 2131: +.#..#..#.# +#....#..## +#........# +#..#..#..# +.#...#..#. +##........ +##.##..### +..#..##... +......##.# +##..###### + +Tile 2087: +.##.#..... +...#...... +###....... +#.#......# +##....#.#. +.......... +........## +#.....#.#. +...##.#... +..##.##..# + +Tile 2593: +#.###.##.# +.#..#...#. +.........# +#..###.... +....##.... +##..#..#.. +###.##.... +#....####. +.#..##..#. +.#.....### + +Tile 1277: +###.#.#... +..##...... +#..#.#...# +...##.#..# +#...###.#. +..#......# +##...#.... +......#.## +##.#.##..# +..#...#... + +Tile 2917: +###.#....# +....##.### +#......#.# +#..#.#...# +#.#....##. +#..#..#.#. +..#####... +##.##.#.## +#.#....### +#####.#..# + +Tile 1579: +#.#..#..## +..#....### +##......#. +#...#..### +#..##..#.. +##.##....# +.##....#.# +#.###...#. +..#.#.#.#. +##.#.#.... + +Tile 3011: +....#.#.#. +##........ +#.#......# +#...#..#.# +........## +#..#.....# +.....#.... +#.##...... +#...#..#.. +....#..#.. + +Tile 2539: +..#.#.#.## +...#.##### +.........# +.......... +.....##..# +##....##.# +#.....#... +....##.#.. +..#.##.#.. +#.#.#....# + +Tile 1879: +##.####### +#..#....#. +........## +..#.....#. +#.#.#..#.. +...##....# +#..##..#.# +..#.....#. +#.....#... +.#####.##. + +Tile 2081: +..#....#.# +#.##.#.#.# +#....#.##. +##......## +....#.#.## +......#..# +##.......# +#........# +..#..#...# +..###..#.. + +Tile 1721: +.#.####.## +....#.#..# +#...#.#... +#...#.##.. +#.#.#.#### +#...#.#..# +.........# +..#..##.#. +#.#.#.##.# +#..#....#. + +Tile 1237: +.....###.. +.......#.. +#...#....# +......#.## +###....#.. +#.#..#.#.. +..#......# +..#..#..#. +.#........ +#.#.#.##.. + +Tile 3037: +..#..####. +........#. +...#.#...# +.##.##..#. +#.##.#.#.. +#...#.#.## +#..###.... +#......### +#.#..###.# +.##...#.## + +Tile 2719: +######.##. +#...#...#. +#..##.#..# +##........ +..#.##.... +##........ +#.###.###. +#..#....#. +##..##.... +.#....#.#. + +Tile 1013: +.#...#.##. +#..#.##... +##..#....# +#......#.. +.#..##.... +..#....... +........## +#........# +.....##... +#.#.###... + +Tile 3571: +.......#.# +.#...#...# +....##.... +#......#.# +.###.#..#. +#...##...# +##...#.#.. +......#... +#.#....#.. +##....#..# + +Tile 2269: +##.#.#...# +..#.#..... +.##.###..# +.#....##.# +#.#..#.### +#.....#..# +#.#.#....# +#..##..#.# +...#....## +...##.#... + +Tile 3709: +##...#..## +...#...#.# +#..#.#.... +..##.####. +..#...##.# +...#...#.# +#...#.#... +.#........ +.......... +#..#.#.#.# + +Tile 2143: +#.##.#.... +####...##. +#.###...#. +....##.#.# +##.##..... +.......#.# +####..##.. +.......#.. +#......#.# +####....## + +Tile 3677: +##.###.##. +.#.###..#. +..##...#.. +..#......# +##.##..... +#.#.##.#.. +..#..#.##. +##..###... +#.#......# +...###.### + +Tile 2297: +.........# +.......... +........## +#.#..#.... +##.#..###. +#........# +.....#..#. +...#...#.# +##..#..... +.#.######. + +Tile 1871: +#.#.#..... +#.#....#.# +..#...#..# +..#..##..# +#.#.##.... +......#.## +##.##.#.## +#.###.#### +#..#....#. +###.#....# + +Tile 3449: +##..#.###. +.####..... +#..###..#. +#....#.#.. +#.....#..# +#....#.#.. +#.....#..# +.#..#..... +#..#.#...# +.####.#### + +Tile 3391: +........## +##.#.#.#.# +...##....# +..###..### +.#....#..# +.#....#.#. +.......... +#...#.#.#. +.....#.#.# +#.#....... + +Tile 2243: +..#...##.# +##...##... +..#......# +..#.##.#.# +.#......#. +#.#...##.. +#.....###. +##..##.#.# +#.#....#.# +#.#..#..## + +Tile 2153: +##.###.#.# +.#.#.#.#.# +#..#..###. +.##..#.#.# +.#.....#.. +..#......# +........## +.#.....##. +.#.......# +#......### + +Tile 3659: +.#.#....## +..#..#..#. +..###...## +.......... +#.....#..# +##.#.#..## +#.###..#.. +#..#....## +#........# +#.###..##. + +Tile 2503: +##..##.#.# +#..#..#... +.....#...# +...#.....# +#.....#... +.....###.# +#..#..#... +..#...#... +#..#...##. +.###...### + +Tile 2741: +#..#.##### +..#....... +...#..##.. +#...#..... +.#.#.#.... +..###..#.. +.#.#..#..# +.##..#.##. +##.#...... +.##....#.# + +Tile 3371: +..###.#..# +#..#...... +###...#..# +.......... +.#..##...# +...#.....# +...##.#... +#.#.#..#.. +#.......#. +###.#.###. + +Tile 2731: +#...#.#... +#.#..#.... +#...#.#... +#.###.#### +.#.##....# +##..#....# +#.#....... +##..#....# +......##.. +###...###. + +Tile 3217: +.#..#..#.# +##...#...# +....##..#. +#...#.#... +#......### +##.#....## +#..#...##. +#...#...## +#.#.#..... +.#.#...... + +Tile 3911: +..###..##. +.....#.#.. +##.#...#.# +#.....#..# +.......#.# +#........# +..#....#.# +#.##....## +.....#...# +##.##.#.#. + +Tile 1637: +.#.#..#.## +##..#.#... +.#.#####.# +..#..#..#. +#......### +#......... +#.##...##. +#........# +#..#.....# +..#...#.#. + +Tile 3989: +.#..##.##. +.......... +..#.##..## +#.#..#.... +#...#....# +#..#.#.#.# +##....#..# +#.#...#... +######.##. +.#..#..### + +Tile 2213: +...#..#### +.....###.. +##....###. +#...###.## +##...####. +#......... +......#... +#.......## +###.....## +.##...###. + +Tile 1061: +.#.....##. +#...#..#.# +#.......#. +.#.......# +.....#.... +.#....#.## +##.#....## +#...#...#. +#...#.##.. +.###.....# + +Tile 2281: +..#..##.#. +..##.....# +..##.....# +..#.#....# +#.#..##.#. +#..#..#.## +#......#.. +...#...#.# +..##...... +#.###.###. + +Tile 3803: +####.##..# +#..#..#.## +.#...##... +#..#.#.##. +#...#....# +....#....# +..#.##.#.. +#..#...#.. +##........ +#...#.#... + +Tile 3347: +.##.##...# +#..#.#.... +...##.##.. +#...#..... +#.....##.. +#.#..#...# +.....#.#.# +#......... +#......... +##..#####. + +Tile 2687: +.#####.#.. +#.#.#..... +#....#.... +.##.#..... +#.##....## +#....#...# +###.##...# +##..#....# +....#....# +#.##.#.##. + +Tile 1097: +##....#..# +....##...# +#...#.#... +#....#.... +.....#..## +#..##.#..# +#....#.... +###....### +#.....#.## +#....#...# + +Tile 1483: +#..#.##... +....##.#.# +...##....# +#..##..#.# +.#...##... +.......... +#..#..##.. +....##.#.# +######.... +####....#. + +Tile 2207: +.#.###.##. +.##..#.... +....#....# +#....#.... +#....##..# +#.#.....## +...#....#. +#.#..#...# +.#.......# +.#####.##. + +Tile 1559: +.####..##. +##..##.#.# +......##.. +##.#..#..# +.#.#.#.... +#....#..#. +#..#..#.#. +#.#..#.#.# +#...##.#.. +.#...#.... + +Tile 3019: +...#.###.# +.##..#..## +...##..#.. +..#...##.# +#......#.. +#....#.### +##..#....# +#.#....#.. +#..##..#.# +#.#####..# + +Tile 2441: +...####.#. +#..#.#...# +...##.#..# +#.#......# +#..#.#.#.. +#..##....# +.####.#... +.#.#...#.. +..##..#..# +.#..#.#... + +Tile 1997: +.##.###... +......#..# +....#.#..# +..#.##...# +.....##..# +###.#.#... +##........ +#.....#... +##....#.## +######..## + +Tile 1481: +####.##### +##.#.....# +#.#....#.# +.......#.. +#........# +#....##... +...#..#..# +.#......## +....##...# +.######### + +Tile 1811: +..#..#.##. +.....#.#.. +..#...#... +##.....#.. +.#.#.....# +...#####.# +#...#.##.# +....#.#..# +....#.#... +#..#.##... + +Tile 3701: +####.###.# +###.....## +#...##.### +....###.#. +#.#.#..#.# +..###....# +.#...#...# +#.##..#... +####....## +.#####..## + +Tile 1451: +###.##.#.. +#...##.#.# +.#.......# +#.....#... +.#........ +#.......## +...##.#.#. +.#..##..## +#.#.#..... +....#....# + +Tile 3319: +....####.# +.#..#...## +..##.###.. +#...#..#.# +.#........ +......#... +........## +#.....#... +#......... +..##.##..# + +Tile 2659: +.##..#.#.. +#.#...##.. +.####..##. +.....##### +##........ +.#........ +#.#.#..... +.....##... +........## +..#....... + +Tile 1433: +#.##.##.## +.#.....#.. +....#.#... +.#..#.#### +....#.#..# +####...#.# +.#.#..#.#. +..#......# +.#.#.#.#.. +#.###.#.#. + +Tile 1409: +#..###.... +###....... +#...#..##. +#.##....## +..#...#..# +.#..##..## +..#..#...# +##..#.#### +#....##### +##..####.. + +Tile 1747: +...##.###. +##...##.#. +......#..# +#.#.....## +#..#....## +###.##.#.# +.......#.# +#...#....# +......#..# +##...####. + +Tile 2011: +.#.#..##.. +.......### +#.#.#...## +#...#.###. +......###. +....#.#... +....#.##.. +.##......# +##....###. +###.####.. + +Tile 1009: +.#.#...### +#.#.##..#. +.......... +.....#...# +.#...#..## +.#..#.#.## +#..####.## +#.##.#.#.# +..###....# +.##..#.... + +Tile 1759: +#.#######. +#..#....## +.......... +..###..#.# +#..###.... +#.######.. +...##.##.# +#......... +##.......# +#...#..### + +Tile 1223: +###..#.##. +##..##.... +...##..... +#..#.#..#. +#..##.#... +.#.......# +...#..#.#. +##.......# +##........ +.###.#...# + +Tile 2467: +.#.##.#.#. +#......... +##.....#.. +.##...#### +#..#..#..# +#.#...#... +........#. +##.......# +..#....### +##....#... + +Tile 1571: +...##.#.## +..#....... +.#.#..#..# +.......... +#.......#. +..#....#.# +#.###..... +...#..##.# +..##.#..## +####.....# + +Tile 1931: +###..#.##. +##.#..##.. +...##.##.# +........#. +.####...## +.......... +#.....#..# +#.....#..# +.#..###..# +.......##. + +Tile 2711: +#..#.#...# +#....####. +.#.#..##.# +#.#.#..### +......##.. +###...##.# +##..##.... +.....#..#. +##....##.# +.#...#.... + +Tile 3331: +...#.#.##. +.#......#. +##.#.....# +#..##....# +.........# +##....#.#. +#.#......# +#.......#. +##......## +..##..#### + +Tile 1979: +..##.#.##. +...#..###. +......#.#. +..#..#...# +#......... +#......... +..#.#...#. +#..#..#### +#...#....# +##.######. + +Tile 1229: +##.###.### +#....#.#.. +#....##... +#.....#... +#.#......# +##...#.... +.#...###.# +#..#.#..## +...#.#.... +.##...#.## + +Tile 1217: +#..#.#.... +.#....#..# +.#.....### +..#.#....# +##....#... +.#...##.## +.#..#.#.#. +.##..##... +.#....#..# +.#.#.#.#.# + +Tile 2521: +.....####. +#.#....#.. +..#..#...# +..#...#... +......#... +#.##..#..# +..#..##..# +.#..#....# +#..##..### +#.###.##.# + +Tile 2251: +#...#..### +...##.#.#. +#..#..##.. +##........ +#......... +......#.## +##.....#.. +..#.#...#. +###.#..... +.###..#.#. + +Tile 1093: +#####.#... +###.....#. +#.#.###..# +....##.... +###.....## +.#......#. +#......... +..#....... +....#..... +#.#.#.#... + +Tile 2293: +##..#.##.# +#...#....# +#..##..... +..#......# +#....#.... +.......#.. +##.....### +#....#.... +#...#..##. +########.. + +Tile 1279: +#.###.##.. +.......... +#...#....# +.....#...# +#....##### +#...#.#.#. +#..#..#..# +.......#.. +#.#...##.# +#####..#.. + +Tile 1213: +#...##.... +##.#.....# +#.....#... +#.......#. +#......... +#.#....... +#........# +#....#.... +.#..#....# +.##...##.. + +Tile 3851: +#.#...##.# +.........# +#.......#. +.#.#.#..#. +.##.....## +...##...#. +#.#...#..# +#.....#..# +.#.#...... +.#.#.##..# + +Tile 1531: +..##..#... +#....#.... +#...#.#..# +....##..#. +#..#..##.. +.##.###.## +#..#####.# +##.#.##... +#.#.##..#. +#..##.#### + +Tile 1321: +#.##.....# +###.#..... +#......... +.......#.# +#...##...# +.....###.# +..##...#.. +..#.#.##.# +####....## +.##...##.# + +Tile 1619: +.###..#### +#..##....# +#.....#... +......#... +#.......## +#....#.... +##..#..#.. +....#...#. +.#.....#.. +.#.#.##.## + +Tile 2803: +#.#.#..#.. +#...#..#.. +#####.#.#. +.##....#.# +......#..# +##..#.#..# +..#..#..#. +##......## +..#.##...# +.#.#....## + +Tile 2383: +.####.#..# +#..#..##.. +#..##.#..# +..##...#.# +##..#.##.. +.#........ +#.##..#... +#......#.. +#...#....# +##.##..#.# + +Tile 1291: +...#.#..## +##.#...... +....#.#.## +#.#.#...## +.#.##.#..# +##.#...#.. +#..#...... +#.#..#.... +#..####..# +##.....### + +Tile 1129: +#.#....##. +...#.#.#.. +.#.#.#...# +.#..#....# +.#.##....# +........#. +.##......# +...#.#.#.. +#.....##.. +.###..#... + +Tile 2857: +#.#.#.#### +...#.....# +..#.....#. +###.....#. +###...##.# +#..#.#...# +#.##.###.. +.####..### +#.##...... +..#..#.### + +Tile 2411: +......##.# +##..#....# +#.....#..# +#..#...... +.#...##..# +#.....##.. +###.#..### +#.#.#####. +#...#.#..# +.#.##.#.## + +Tile 3923: +..#####..# +#...#.#... +#...##.#.# +....#..... +.......... +#.##....#. +.........# +##.......# +#...#...## +###..##.## + +Tile 3343: +#..#.###.# +..#...##.# +..#...#... +#...#..... +..#....... +##.#..#... +...###..#. +#.#.#.#..# +...#..##.# +#..#...##. + +Tile 2017: +.#...###.. +.........# +.##....##. +....#...## +..###..... +##..##..#. +#..#.##..# +#.#..####. +##........ +..#.##.... + +Tile 3889: +#.##.##..# +.#....#.#. +.##...##.# +#..#.###.. +#..##.#... +#...##.#.. +.#....#.## +###.#.#..# +#..#...#.# +.#.#..##.. + +Tile 1823: +....##.##. +#...#...#. +..#......# +.......... +....###..# +####....#. +.##......# +...###.### +##....#... +#.#.##.... + +Tile 3769: +.#..#..... +...#.....# +#...#....# +..#..##... +.....#...# +....#..... +#...####.# +#..#.##..# +#..#....## +#######.#. + +Tile 1523: +.#.##....# +...#...#.# +#......... +.....##.#. +##.##..#.. +..#.##...# +#...#..##. +#....#.... +.#.#...#.. +#.#.###... + +Tile 2843: +...#....#. +......###. +..##....## +#.###.#..# +#..##.#... +#.##....#. +.....##... +.#.......# +##.#..#..# +#.##....#. + +Tile 2423: +#.##.##### +..#.#...#. +#.....#.#. +#..#.....# +..##..#..# +##....#..# +#......#.# +#.#..#.##. +#.....#... +.##.##.#.. + +Tile 1999: +.#..#.#### +.#.#..#... +.......... +...#.#.#.. +..#....#.# +##.#...#.. +.#..####.. +.....#.#.# +..#..#..## +##..#..#.. + +Tile 2341: +#....#.#.# +##.##....# +#..##.#... +#..#.#.... +...#..#.#. +##..##.### +#.#.....## +.......#.# +##.##..... +....#.#### + +Tile 3359: +#..###.##. +#......... +.####.###. +#.##....#. +.#..#.##.. +#......... +.#.#.#.... +..#...#..# +###......# +...#...... + +Tile 3863: +..##.##.#. +#.##..#.## +.###...... +.#.......# +..##...... +#..##..### +.##..##... +....#.#... +#.#.#.##.# +...##..##. + +Tile 3187: +#.#.#.#... +......###. +#.....#### +..#.#...#. +#....#..#. +#......#.. +#...##..#. +#........# +#.##.....# +.##.#...#. + +Tile 3119: +##.....##. +....#....# +#..#..#..# +#....##..# +........#. +...#.#.... +...##..#.. +.....#.... +#.####.... +...#..#.## + +Tile 1063: +.#.#.#.... +##........ +#..#.##... +#..#.....# +....##...# +.#......#. +..##...##. +#........# +.......... +.#..#..#.. + +Tile 1657: +.##.#.#... +##.....#.# +....#.#.#. +#....##### +###......# +.#....#..# +#.#..#.#.. +#.#.##.... +##.#...... +#..##.#... + +Tile 3257: +##.####..# +#.#.#####. +##.#..##.. +.##.#..### +..#....... +#...#.#..# +#..#.#.#.# +...#....## +##.....##. +...###..## + +Tile 1987: +.#.#..###. +.#.......# +...#....## +#...##.... +.......#.# +.#.##.#### +...#...#.. +.##...#... +.........# +.#.##..#.. + +Tile 1459: +#.....#### +......#..# +........#. +##..#..#.. +###.##.#.# +##..#...#. +##..#.###. +.##..###.# +#..####... +.#.#####.. + +Tile 3533: +#.##...#.. +.#.....#.. +#.##...... +..#.....## +....#..#.. +##..#....# +#....##..# +..#....#.. +........## +.####.##.# + +Tile 2789: +..####...# +#....###.. +#..#..##.# +#.#..#.... +#....##... +....#..... +#......... +#..#...... +.......#.# +...####.#. + +Tile 2137: +#..####.## +....##...# +.#.....#.. +#.#..##### +...#..#... +.#.....#.# +.....#..#. +##..#...## +..#.#..... +#..######. + +Tile 1181: +.#####.#.. +..#.##...# +#....#.... +#...#.#... +##.......# +.....#...# +##..#...#. +.##.##.... +#...##.... +..#.##.... + +Tile 1117: +#####.#### +.......#.. +##.#..#..# +#....#.#.. +.......... +..#...#.#. +......#... +##...#...# +....#...#. +#.....##.. + +Tile 3739: +..####.#.# +#.#.#.#... +#.......## +.##...#.#. +#....#.#.. +#...#....# +#.....##.# +.......##. +##...###.# +....##..## + +Tile 2909: +.##..###.. +#...#..... +.....#...# +..##...... +#.##.###.. +##.....#.# +#..#...### +....##.... +#......#.. +#.#...#### + +Tile 1609: +##.###.#.. +....#.#... +#.#....##. +#..##.#... +.####..#.# +.......... +##..#....# +...#..#... +#......... +....#.###. + +Tile 1753: +....#.###. +##.##..... +....##.... +#.....##.. +#.##..#... +.......... +#..#.#..#. +#.....#... +.#........ +.#.#...#.# + +Tile 2003: +#.#.####.# +#.##.#...# +####..#... +###..##... +###....... +#.....#... +..##...... +#....#..#. +#.###...#. +.#..#.###. + +Tile 1399: +#.#..##..# +....#.##.# +#..#.....# +#..#....## +#...#..#.. +#.#.#....# +......##.. +.##....... +.####.#### +...#...#.. + +Tile 1249: +..#..####. +#.##.....# +.......... +..#.....## +#.#..#...# +#..#...### +.....#.#.# +..###..#.# +.#...#..#. +.#...##.#. + +Tile 1289: +#########. +...#...... +.....##.#. +...#.#...# +#..#..#... +#....###.# +....#..#.. +.....##..# +.....#...# +.#.#####.# + +Tile 3373: +#...##..## +#..#....## +#..#...### +#......#.. +..#......# +.....#.... +#.#....... +.....#.##. +...#.#..## +..##.##... + +Tile 1613: +####...#.. +#.#....... +.......... +#....##### +#..#....## +...#..#... +.....#...# +.#......## +##....#..# +....#..### + +Tile 2029: +#..###.#.# +#.#..#...# +##...#.... +.#..#..#.. +...#...##. +##.....##. +..##...#.# +...##.#..# +#......... +.#.####.## + +Tile 2203: +..####.### +..##....## +...##..... +....#..#.# +..#...#.## +#.#....... +...###.... +#.....#..# +.........# +.###....#. + +Tile 1877: +##.....### +.....#..#. +....#...#. +##.#.....# +.#..##...# +##.#..##.. +..#...#... +#...##.... +#.#.#..... +.##..#.... + +Tile 3847: +...##.#... +.##.....## +#.#.#..##. +#.##..###. +.........# +..#...##.# +#...##..## +##..#.##.# +#..#.....# +#.##.#..#. + +Tile 1499: +..#.###### +#....##..# +##...#...# +...#.##.#. +##...#...# +....#....# +##.....#.# +#.....#... +.#....#..# +#.#.#..#.. + +Tile 3251: +.###.#.#.# +##....#### +##..#..... +#.#....#.. +...#..#.## +...#...... +#.#.##.... +......##.. +......#... +..#.##...# + +Tile 3323: +...#.#.... +........## +...#...... +#.......## +###.##..## +##.##....# +...#..#... +...###.### +##.....#.. +.###.##..# + +Tile 3109: +.#.#.#.### +######.#.. +......#... +##.#.#...# +.#...#..## +###...#.#. +....#..... +#....#..## +#...#.#... +.#....#### + +Tile 1889: +#..#.####. +#..##.##.. +...#....## +........## +#.#..##### +#......... +#.#.#..... +...###.#.. +#....#..#. +..###.#... + +Tile 2027: +#....##... +.##....#.. +#...#...## +#........# +#.....##.# +.#...#..## +#..#...### +....#..... +#..#...##. +##.#.##### + +Tile 2677: +#..###.#.# +##.#....#. +.##.###.## +#......... +#........# +.#.##.##.# +##...##..# +##......## +...#...... +#..####... + +Tile 1663: +.####.#.#. +#...#....# +###....##. +#..##.#.## +#.....#..# +.#..##.... +#....#.#.. +##........ +#..#...... +.##.##..## + +Tile 3559: +..###...#. +##........ +..#..#..#. +#......... +.#.#..##.# +##.#.....# +..#....... +#..##.#..# +###.#....# +.#..#..#.. + +Tile 3049: +.#.##...#. +#.......#. +#.##....#. +...#...#.# +.......... +####..#.#. +.##.##...# +...#..#.#. +....#....# +###.#.#.#. + +Tile 2777: +..#.#..##. +##..#...#. +.....##... +#.###...## +##...#..#. +.##......# +....#....# +##....#... +##.....#.. +###.##...# + +Tile 2551: +#.####.##. +#......... +#..##...## +..#......# +.......... +##...#..## +.........# +#.#......# +..#.....#. +...#.###.# + +Tile 3491: +#.##...### +#.#.#.#... +#.....#..# +#.....#... +##..#..##. +###......# +#......#.. +....#.##.# +#.##....## +####.#.#.# + +Tile 3947: +#.##.#.#.. +....#.#.## +...##....# +###......# +##.#..##.# +..#.#..#.. +#....#..#. +#...#....# +...#..#.## +###.##.#.. + +Tile 1361: +..#.#.#### +#..#..#.## +.#...#...# +.......... +..#......# +##........ +#.##.....# +.#.......# +#.#..#...# +#..##...#. + +Tile 2851: +.###.##... +#.....##.. +....##...# +........#. +#.#.###..# +#...#.#..# +##...#..## +...#..#... +##.......# +#####.#.## + +Tile 2381: +.#.####### +.#..#..##. +...#...... +#......### +#.#..#...# +..###..#.. +...#.#.#.. +#......#.. +..##.....# +..#.#.##.. + +Tile 1069: +.#.#...### +##..#.##.# +#.#..###.. +###...##.. +.#.#....#. +.........# +#..#...#.. +..#....##. +.#.#....## +#.....##.# diff --git a/haskellAoC/inputs/2020/20_test b/haskellAoC/inputs/2020/20_test new file mode 100644 index 0000000..b3aed46 --- /dev/null +++ b/haskellAoC/inputs/2020/20_test @@ -0,0 +1,107 @@ +Tile 2311: +..##.#..#. +##..#..... +#...##..#. +####.#...# +##.##.###. +##...#.### +.#.#.#..## +..#....#.. +###...#.#. +..###..### + +Tile 1951: +#.##...##. +#.####...# +.....#..## +#...###### +.##.#....# +.###.##### +###.##.##. +.###....#. +..#.#..#.# +#...##.#.. + +Tile 1171: +####...##. +#..##.#..# +##.#..#.#. +.###.####. +..###.#### +.##....##. +.#...####. +#.##.####. +####..#... +.....##... + +Tile 1427: +###.##.#.. +.#..#.##.. +.#.##.#..# +#.#.#.##.# +....#...## +...##..##. +...#.##### +.#.####.#. +..#..###.# +..##.#..#. + +Tile 1489: +##.#.#.... +..##...#.. +.##..##... +..#...#... +#####...#. +#..#.#.#.# +...#.#.#.. +##.#...##. +..##.##.## +###.##.#.. + +Tile 2473: +#....####. +#..#.##... +#.##..#... +######.#.# +.#...#.#.# +.######### +.###.#..#. +########.# +##...##.#. +..###.#.#. + +Tile 2971: +..#.#....# +#...###... +#.#.###... +##.##..#.. +.#####..## +.#..####.# +#..#.#..#. +..####.### +..#.#.###. +...#.#.#.# + +Tile 2729: +...#.#.#.# +####.#.... +..#.#..... +....#..#.# +.##..##.#. +.#.####... +####.#.#.. +##.####... +##..#.##.. +#.##...##. + +Tile 3079: +#.#.#####. +.#..###### +..#....... +######.... +####.#..#. +.#...#.##. +#.#####.## +..#.###... +..#....... +..#.###... \ No newline at end of file diff --git a/haskellAoC/src/Y2020/Day20.hs b/haskellAoC/src/Y2020/Day20.hs index 89839cb..c0b6e2b 100644 --- a/haskellAoC/src/Y2020/Day20.hs +++ b/haskellAoC/src/Y2020/Day20.hs @@ -1,6 +1,154 @@ module Y2020.Day20 (y20day20) where +import Data.Bits +import Data.Function (on) +import Data.List +import Data.List.Split +import qualified Data.HashMap.Strict as M + +type Coords = (Int, Int) + +data Tile = Tile { + tile_ids :: [Int] + , pixels :: [[Bool]] + , rows :: Int + , cols :: Int + , sides :: [Int] + } deriving (Show) + + +getIntValue :: [Bool] -> Int +getIntValue = fn 0 + where fn input [] = input + fn input (b:bs) = + case b of + False -> fn shifted bs + True -> fn (shifted `setBit` 0) bs + where shifted = shift input 1 + +getSides :: [[Bool]] -> [Int] +getSides input = sides' ++ reversed + where input' = transpose input + up = head input + down = last input + left = head input' + right = last input' + sides' = map getIntValue $ [up, left, right, down] + reversed = map (getIntValue . reverse) $ [up, left, right, down] + +parseTile :: [String] -> Tile +parseTile [] = error ("Input error: no tile found") +parseTile (h:t) = makeTile [tid] pxs + where tid = read $ init $ (!! 1) $ words h + pxs = map (map (== '#')) t + +makeTile :: [Int] -> [[Bool]] -> Tile +makeTile tids pxs = Tile tids pxs rs cs ss + where rs = length $ pxs + cs = length $ head $ pxs + ss = getSides pxs + +getTilesWithSide :: [Tile] -> Int -> [Int] +getTilesWithSide tiles sideid = map (head . tile_ids) $ filter (elem sideid . sides) $ tiles + +makeAdjacentPairs :: [Tile] -> [[Int]] +makeAdjacentPairs tiles = nub $ -- deduplicate + map (getTilesWithSide tiles) $ -- get associated tile_ids + map head $ filter ((== 2) . length) $ -- take only groups of 2 + group $ sort $ -- group them + concatMap sides tiles -- get all side "ids" + +getTile :: [Tile] -> Int -> Tile +getTile tiles tile_id = head $ filter ((elem tile_id) . tile_ids) tiles + +horizFlipPixels :: [[Bool]] -> [[Bool]] +horizFlipPixels px = map reverse px + +vertFlipPixels :: [[Bool]] -> [[Bool]] +vertFlipPixels px = reverse px + +rotateLeftPixels :: [[Bool]] -> [[Bool]] +rotateLeftPixels px = reverse $ transpose $ px + +mergePixels :: Int -> [[Bool]] -> [[Bool]] -> [[Bool]] +-- could compare rows / cols lengths to avoid unnecessary rotations +mergePixels i a b + | abot == btop = (init a) ++ (tail b) + | bbot == atop = (init b) ++ (tail a) + | otherwise = mergePixels (i + 1) a' b' + where atop = getIntValue $ head a + abot = getIntValue $ last a + btop = getIntValue $ head b + bbot = getIntValue $ last b + a' = fn i + fn 0 = a + fn i' + | i' `mod` 32 == 0 = vertFlipPixels a + | i' `mod` 16 == 0 = horizFlipPixels a + | i' `mod` 4 == 0 = rotateLeftPixels a + | otherwise = a + b' = rotateLeftPixels b + +mergeTiles :: Tile -> Tile -> Tile +mergeTiles t1 t2 = makeTile tids pxs + where tids = concatMap tile_ids $ [t1, t2] + pxs = mergePixels 0 (pixels t1) (pixels t2) + +buildTileLine :: [Tile] -> Tile +buildTileLine (h:[]) = h +buildTileLine (h:t) = foldl mergeTiles h t +buildTileLine [] = error ("Can't build empty line!") + +buildWholeMap :: [[Tile]] -> Tile +buildWholeMap [] = error ("Can't build empty tile map") +buildWholeMap m = buildTileLine $ map buildTileLine m + +-- adjacent pairs -> (corners, borders, innards) +classifyTiles :: [[Int]] -> ([Int], [Int], [Int]) +classifyTiles adjPairs = foldl fn ([], [], []) $ group $ sort $ concat adjPairs + where fn (cs, bs, ins) is@(i:_) + | length is == 2 = (i:cs, bs, ins) + | length is == 3 = (cs, i:bs, ins) + | length is == 4 = (cs, bs, i:ins) + fn acc _ = acc + +common :: Ord a => Eq a => [a] -> [a] -> [a] +common xs ys = fn (sort xs) (sort ys) + where fn [] _ = [] + fn _ [] = [] + fn (xh:xt) (yh:yt) + | xh == yh = xh:(common xt yt) + | xh < yh = common xt (yh:yt) + | xh > yh = common (xh:xt) yt + +-- previous line -> adjacent -> start -> available -> finishing -> line +-- buildLineId :: [Int] -> [[Int]] -> Int -> [Int] -> [Int] -> [Int] +-- buildLineId _ _ _ _ [] = error ("No finish tile available?!") +-- buildLineId prevLine adj start available finishing = result +-- where adjTiles = filter (/= start) $ concat $ filter (elem start) adj +-- adjFinish = common adjTiles finishing +-- adjAvail = common adjTiles available +-- result = case (adjFinish, adjAvail) of +-- ([], (h:_)) -> h:(nextCall h) +-- ((h:_), _) -> h:[] +-- _ -> error ("Error building line...") +-- nextCall tid = buildLineId adj tid (filter (/= tid) available) finishing + +-- buildPicIds :: [[Int]] -> [[Int]] +-- buildPicIds adj = adj +-- where (cs, bs, is) = classifyTiles adj +-- (c:cs') = cs +-- firstLine = buildLineId adj c bs cs' + + y20day20 :: [String] -> (String, String) y20day20 input = (part1, part2) - where part1 = "WIP" - part2 = "WIP" + where part1 = show $ product $ corners + part2 = show $ "WIP" + + tiles = map parseTile $ splitOn [""] input + adjPairs = makeAdjacentPairs tiles + (corners, _, _) = classifyTiles $ adjPairs + + -- tile n = getTile tiles n + -- wholePic = buildWholeMap $ map (map tile) $ buildPicIds adjPairs