This commit is contained in:
Dory 2023-12-14 02:01:31 -08:00
parent 7a66d289ea
commit db08023b9e
3 changed files with 155 additions and 0 deletions

100
14/input.txt Normal file
View File

@ -0,0 +1,100 @@
#.O.O......##.......O.#O....O....O.O...O..O..##O#..O..#...##...........#..O..OO.O#O...OO.O..#...#..#
......O.#...#..O.O.....#O...#..OO.O.........O..O.#..O.#.O...O.##......O..O.#....#......O....O....O#O
...#...O..O..#.O...O##.O....##.....OOO#....#.O..O#O.OOO.........O....#.O...O.O...O...#.#..O..#.O.#.#
#...##...O.OO....OO.#..O#...O..#O.O...O.......#.##.###....O..O.O.#.#O........OO..##.................
...#O....#.O.....O.O..O.#.......#.#.#O....O....OOO.#.....O.#...#...O..##..##O.#O....O.#O.#O..#..O.OO
...O....O..#.....O..O..O#.O...O..#..OO###.O.....#.OO....O#......O#..........#....#.O#.O.O.#.....O.O.
....O...#..O.........O...OO#O......OOO..#..O....#..#...O...O..#...O.O..#O...#O.O...O..###..#.O.#....
...O.#O.#..##O.O.#...O...#....O..#.####....OO.#.#...........O.O...#..........O..O#.O..O....#.......#
........O.........O....OO...........##...O.#.OO.....#....#.O###.......O#O..#.#.O#..#....O..#......O.
O..#....O#O.#..O...............#..#..........OO#.#.#.#...#..#..O.#...#......O..#...O...O..O.......O.
OO#.O##OO......O.#..#O....O#......O..O...O...OO...#...........O...#......O....O.OOO#..#.....O.OO..O.
O.#.OO...#..#..O...#....#..O.O....O.OOO..O....#...O....O.O....O.O#........#.##.......O..O#.O....#...
......O..O..O..###.#..O..#...#..#.##O.#O.OO...O.O..#OO...O...O.#O..O..#....#O....OO#.#...O...O..#.#O
.#.#O..#O....O.##.#O.#O.O.O....#.....OO#O...OO....#O...O##..OO.OOO......#.....#..#O.OO...#..#....O..
..OO.#.#..#....#..#.......OO..OOO.#...#..O##.O..##O..O....OO#.OO...#O.##.#......#O#.O#..O##...#.....
O.#.....#.O.OO.O......##.........O.O#.O...#......O#.....O.....O#..O.#O..O.#......#..O..O.O..........
...O..O..O.#.##.O..#.........#...#O..#....O#...#..O###.O...#.......O...#.#.#...O.....#O...O....##O.#
.#OO..O........O.O...#.#.....O..O..OO.O....O..##....OO....O...O..O#..O.OO.#...O.O.#.O.#O....O.......
....O.O.O.O..O#..##..O.O.O..O.#.OO.O..#.OOO.O.#.OO.O.#O........#O..O.......O..O..#..O..#..#.O.#.....
.#.O..#.O#O.O.......O.#.#O.OO..O..OO..O#.O.O#O....##OO.......O..#O.O.O#.....#..#..#..O#O.......#O.O.
....O..O#....O#.#O..#.OOOO..#.......OO.......##...#O....O...#..#..#.O..OO..O.#..#.O....#.#.##OO.....
.#O..###..#O#.O#O....O.##..........O.#..O..O.OO.O##...#O.#.O.O...#..#O.........#...#..#.........#O..
#.#.......#O..#..##..O.#...#O#...#.#.O..O.OO##.O....#.....O..OOO.............O..##..#..#..O....#...#
#.#..O..........#.O.#O..O.#...#.#O#..O.#....#.#....#O.......#O.#.O.O.##..OO....O.##..O#....O.....O.O
.O...##...O..#..O#O...O#.....O.#O....OO.O.#O..#....OO.#.O.........#......#O.........O...#.O...#O.O#.
...O.....#........O.#O...#..#..##.......O.O#....#.O...OO##OOO#.#..O#OO..OO..##O....O.#.O...O....##..
............#.O.O#O..#..#..O.........#O..O....OO..#..#..O.#.O.#..O..O..O..#OO...O...OO#O.OO....#..O.
...O.O.....O..O.##.....OO..#O...O...O..O.#...#......O..O.......OO..OO....#OO.O..#........##.O.O....O
#O#......O.O.O#..O.O..OO..#O#..#OO.#...O...O.O.O....#..O#O..O###O.##OO#.O.O.......O.O#..#O.O.O.#...#
..O........OOO.O....OOOO......#.O...#.....O.O#......O#O.O.#O.....#..O....O#.O....O..#..O..O....O...#
...O......O..#....O...#O..OO..#.#OO.O...OOO......#.........#OOO.#.#........O...#OO.O.OOO....O.O#....
......#.O...OO#...#O.#..##.O.#..O..O..O.O.#.O.O.##.#O#O...#OOO...#..O....O..O...OOO..O..#.##....O..#
...O....O.#O.OO..#O...#.#....#O.##OO..#..OO..#....OO.O#....O.O..#.#..O...#.O.#.O.#..O..O..#..O#O.OO.
..O..O.O......O#..#..O..O..O#..#.......#.....#O..O...#O..O..OO#.#.##...OO#..##.O.O.O.O........####.#
#.O#......OO...#.###...OO......#..#.....#.#.##.O..#.#..OO..#...OO#.O#.#..O##....O.....#..#OOO.....#.
.#......O....O.#...O..##.O..#..#O...#.O#....#.O#....O.O#.O#.#.OO.O..O#....O....#...O.O#......O#OO...
....#O#...#.O#.....O.O..OO##O....#.O..O...O..O.OO#...O#.#...O.O.O.....O#..O...#O.....#...O#O...O#.#.
#..O..O..OO..#.O#.......O......#...O.#..#O#..#.O.#.O#...#O.....O.OO..#...O...O.##.....O....OO..#....
..#......O#O...#.........#...O#.#..O.#..O.O.......#O.#...OOO....O#....OO..OOO.......#O....OO........
O.O.#..#..#O........##OO...O.O#....#...#O.......#.O#O...O..O.O##.O..#..OOOO#...O.#O..O#...O.O#O..#O.
.....#O#.#O......OO..O.....#....#.#.O.O.##.O##.....O..O......#O#OOO.....#.....#OO..###.#...O.O.#.#..
#...##.OO.....O.....OO......#.O.O..O......#....##O##..OOO..#.....#...O.......O.......O....##........
.###..#...O..O.#.....O#........O...##O....#.O.#.O.O.#O.......O#..#...OO...O#.OO...O.....O.O.O..OO#.O
...O..#...#..##..#.O##.##O.....O.#..#O.......OO#..O#.OO...##O......OOO...O.O..O#...#.##..O...O..#..O
....O.......#..O#..#O..O....O.O....#...O....O.##.#OOOO....O.#...#O...O#.#.......#.......OO#.#...#.#.
#.OO.O##...O...##.O#..O#......#.#..OO.OO.#.O.O##.#....O.O.##O.....#O..#........#O#...#...#.....O#.#.
O.O.#..##.....##O.......O..OO..#.O......#.......#O....#.......O.#OO...O.O....#.##.....#.....OO......
O#..##..O........#.#..O.#.....#O....O#.....O...#O.......O.O.........O....O.#..O#.O.....#O.#.#.O.#.O.
...O.OO.OO.O..O...#.#.#.O.O.OOO......O.#.#.O.#..O..#.OO.O..##O.......O.........OOO#.O.O...#O.O....O.
O.##...#.#..O#.#..#..O...#...#...O..O..#..O...#O....O..#.##O....O..O..O.##O...O....O..##O..OO.#.....
...OOO.O....O.O.#....O#.OO..#.#.O.#.O#.O...O#O#......##..........#...O......O...#...O....O.#...#....
...#..##.O.#O#.O.#...#..O...O#O....##..OO##..#OO.........#...O#..O#.OOO...OO...#.O.#.OO##..#O#.#...#
O##...#......#O.O#...O....O...#O#.O...O.O.OOO....O.....##....O..#O.O....#.#...O........##OO#.O##...#
OO..#.....O..O#.O...O..OO....#.....##...#..O...#O..#.#O.#O.#O##...#....O....#.O.......#......O.....O
O.O....O##.OO...O.....#......#....O.#O.#...OO#.OO......OO...O#....OO#O...O....##....#...........O.O.
.....O..O.OO....O#..#....#.O....#....#O..##..O..#..........O.OO#.OOO...........O#O.O.......#......OO
.O.#.#.O..O.#....OOO.O..O....O...O......O.O.O..#O.#.#.....OOO.........#.O....#O.O..#O....O#........O
.##.OO#.O.....O..O..#.O..O.O.....O.O.#.O.....OOO.........O.O.O...#..O#..O..O..#O.O.#.#..O.#..#..O#.#
O...#..#..O...O...#..O..O.O.O...........#...#..#........#..OO.#O....#...#....O.........O.#.......#..
O..O###.##.#............#...OO#......#.O..O..#...O.O....O##...#.O.......#.#O..O........##...#.O....O
..#O#....##.O.....###..O.#O.O........#.......O.#...#O..#..OO...#.O...O.OO........###....##OO...O.O..
...O.....O..##....O.O##.OO...O.#.#.#.#.#......O.........O.O#....#.#..O.#.O#OO#.....O.OOO...O....OO..
#..#O...O....................O.#.......O.O...........#O.O....OO.O......O.O##O#.#O.O.O.O...O.O.#.O#O.
.O..O..#...OO.##.#...#.O#.O.###...O......O.......#.O##.O.....##.O......#.O...OO....O#.#..#..O.O.....
....O#.O.O...OO#.O.O#.O...#..........OO....#......O.O#.O.#......O...OOOO..O...##.#...O..#..O..##O.OO
...OO..#O.##O..O...#O.#..O..#.#.#..O#.O..#..#.....O...#.O#..........O....##.O...#O......OO.O..O.....
.#O##.O..#.OO#..O..##O..#.#...........O##.#O.OO#O.....O#..O.....O......O.....O..O...O.#..#..O...#O##
...........#.O#O.#O..O#.....##O....O.#....OO...#..OO..#.O.O#.#OOO....O...#O..#.O#......O.....#.##O..
..##.O.O...O.O..#.......#.O.OO..O....#....O.O.OO..#...O#O##.OO.O.#..#.#O.....##....O.O.O.....#..##.O
#.O.O...#....#..##..O.O.#O.....OO.#O...O......#.O.....OO..O.O.O.O...O..#....#OO.......#......O.#.O..
....#....OO..O##.O..O..OO.OOO.O.O.OO.O...##....O#O.....O....#.#.O...OO.O..#...#.OOO#O..#...OO......#
.O#.OO.O......##....#.#..O#OO..#....#....##O#.O.#...#O..#...OO......O...O#.#.O.O.O..O....O.#O.......
.##OO....##..O...##....O.#.#OOOO.O.#..O..O...#...O.O..O.OO..##..#O.O.......O#O....OO.OO.OO..........
.........O.#..#.....O..OO...#..O.OO...#.O.O.....#....O#..#.OOO.#...#..O.#....#O.......O.O...OO#..O..
#..OO#O......O.O...O#.#..#.O...##O#..O.....OO.O.##.O#O#...O#...#O.O.OO....#O#OO.O.#...O....##.......
OO..OO.....#OO.....O........O.......O#.O......O#.#O...#...O.##.#...O.....O.....O....#O...##O.......#
.#.OO..OOOO..O#O..O......O.#.OO.#.O.........O#OO..#.O.#..#O...O.........O#.#.O#O.OOO.O..#...#.O....#
O#...O#.#..O#.......O....#..#.O#.O.#....#....O..#......O...O...O..##.#O#O......O...#..#..OO..#.OOO..
#.....OO..O..#.OO..#...#.....O#.................##.......O.O..#...#O.O...OO....#OO#....O..O.O..O.O..
..#.......O#O..O.OOO.#........#..OO..O#.#.#..................O..OOO..#.O.....##O....O#..O.OO.O..#O.O
OO...OOO.....O..#O.##.O...#O...O....#......O.O..#OO#O..###O.......O...O..O..............O#....OO.O..
.O..O.#..O........#...##.....O...O##O.O..#.....O.#..#..OO#......O....#..OO.#......O...#O...##......O
...#.##O#.....O..O...O##O...#.O.#.O..O.O....#..O.O#....OO#OO..##.....#...O..##OO.O.O...O#O.....#O...
...#O.OO....O#...O...O....#O..................#.O.O..O.O...O..##O...O#.OO.#..#.#......O.#...O.......
..O...#O.##...O...O...O#O.O..#..O.#O#O....#.#O..#O....O...#.#......#.......#..OO.O.........###O##...
....#O...O.........O............#.OO##.O.O.OO.........O.#.O.#OO.....O..O..##...O#..........#.O..#.O.
.##.O#.O...O#O..#.O...#OO......O..OOOO.......O.O..#....#OO....O.O#O.......#O.....#OO.#.............#
..##..#OO#.......O....................O.........OO..#...O...O.###O..O.......#..O.#.....O.O...O.....O
....#......#..O..#.O.O..O..O...#O.O....#.....O..O.#..#O.#.O#.O#..#.....O.##.O..O#............#.#....
##..#...#..O.O.#O.......O#O..O..O...#O.O............#OO.OO.O...O..#..O..O.O#.O#.....O.O....#.####.#.
O...O#..O#..#.O...OO....#.....OO##.........O.O...O..#..OO#..##.O....O.#..O..O......O....O....O#....O
....#OO.O...OO.....O..##O.#.#..##.#.......O....#O..#......O.#....O.#...#O...O.OO..#OO....#....O.O#O.
...####..O.O....#.#O...#O........OO.O.#O.O.#....#.O...........#....#..O##.O.#OO..#..OO.....OO#.#.##.
.O.O..#....#..#O...#O.....O.#O..O.O#....#...#......#..O.O..#O.O.......#..#..OO..#...#....###O.#...OO
....O#.##...#...........#O.O.O...O.#.O#...#.#.OO#O.O.#OO#.....#...O.O#O.#....O.O.....O.O...#...#.OO.
O..O...OO.#...O.##....#.......##.O..#.##.OOO...#.......O..O.#...#..#....#O.O..O.....O.....O.O.##....
.#OO.##...O.#.............O.#...#....##...O.O.#..O..#O..#.###..OO.#OO#.O.........#...O.......#..#O.O
...O..O...OO.#...O#.#...O..#...O..OO....O.OO.OOO.O...O..O.##O.O.##...O.O.##...#O#....O..OO...#.#.#..
.#...#..O.O.##...#.#..O...OO.##.O....O.O......O.#..O#.#.#..O....#....#O.#..OO...O.OO#.O#...#.O..##..
#..O..#..........O.O#....#OO..#.#...#....#.....#....O....OO...O#....#.#.O##..##O#...#.......#.#O.O#O

45
14/part1.pl Normal file
View File

@ -0,0 +1,45 @@
:- use_module(library(pio)).
:- use_module(library(clpfd)).
:- initialization(main, main).
main([FileName|_]) :-
input(FileName, Input),
transpose(Input, Rotated),
concurrent_maplist([Row, [#|Row]]>>(true), Rotated, Rocks),
concurrent_maplist(row_weight, Rocks, Weights),
sum_list(Weights, W),
writef('%t\n', [W]).
row_weight(Row, Weight) :-
abolish_private_tables, table(rocks/3),
phrase(rocks(Rocks), Row),
convlist([N-'#', N]>>(true), Rocks, RockCounts),
sum_list(RockCounts, Weight),
writef('>> %t <-- %t\n', [Weight, Row]).
rocks([0-0]) --> eos.
rocks([LastN-I, LastN-LastI|Rocks]) -->
[0], rocks([LastN-LastI|Rocks]),
{I is LastI + 1}.
rocks([N-I, LastN-LastI|Rocks]) -->
[1], rocks([LastN-LastI|Rocks]),
{I is LastI + 1, N is LastN + 1}.
rocks([0-I, 0-LastI|Rocks]) -->
['#'], rocks([0-LastI|Rocks]),
{I is LastI + 1}.
rocks([0-I, N-'#', LastN-LastI|Rocks]) -->
['#'], rocks([LastN-LastI|Rocks]),
{LastN =\= 0, I is LastI + 1, N is LastN*(2*LastI - LastN + 1) / 2}.
% things below are for reading from input file
input(FileName, Input) :- phrase_from_file(lines(Input), FileName).
lines([]) --> eos, !.
lines([Line|Lines]) --> line(Line), lines(Lines).
line([]) --> "\n"; eos.
line([1|Chars]) --> "O", line(Chars).
line([0|Chars]) --> ".", line(Chars).
line(['#'|Chars]) --> "#", line(Chars).
eos([], []).

10
14/test.txt Normal file
View File

@ -0,0 +1,10 @@
O....#....
O.OO#....#
.....##...
OO.#O....O
.O.....O#.
O.#..O.#.#
..O..#O..O
.......O..
#....###..
#OO..#....