mirror of
https://github.com/plasmaofthedawn/2023adventofcode.git
synced 2024-10-18 14:26:24 -05:00
Compare commits
No commits in common. "a615d0482d9ecb9764ba2521cd762214da111a78" and "dec7e6e1171505454078da12084a4b4f78cf18db" have entirely different histories.
a615d0482d
...
dec7e6e117
35
Makefile
35
Makefile
@ -108,41 +108,6 @@ day11part2:
|
|||||||
@echo
|
@echo
|
||||||
./build/day11part2
|
./build/day11part2
|
||||||
|
|
||||||
day12part1:
|
|
||||||
fpc src/day12/part1.pas -obuild/day12part1
|
|
||||||
@echo
|
|
||||||
./build/day12part1
|
|
||||||
|
|
||||||
day12part2:
|
|
||||||
fpc src/day12/part2.pas -obuild/day12part2
|
|
||||||
@echo
|
|
||||||
./build/day12part2
|
|
||||||
|
|
||||||
day13part1:
|
|
||||||
fpc src/day13/part1.pas -obuild/day13part1
|
|
||||||
@echo
|
|
||||||
./build/day13part1
|
|
||||||
|
|
||||||
day13part2:
|
|
||||||
fpc src/day13/part2.pas -obuild/day13part2
|
|
||||||
@echo
|
|
||||||
./build/day13part2
|
|
||||||
|
|
||||||
day13part1z80:
|
|
||||||
zasm z80src/day13/part1.z80 -o build/day13part1.bin
|
|
||||||
cat z80src/preamble build/day13part1.bin > build/day13part1.bin0
|
|
||||||
@echo
|
|
||||||
./z80sim -xbuild/day13part1.bin0
|
|
||||||
|
|
||||||
day14part1:
|
|
||||||
fpc src/day14/part1.pas -obuild/day14part1
|
|
||||||
@echo
|
|
||||||
./build/day14part1
|
|
||||||
|
|
||||||
day14part2:
|
|
||||||
fpc src/day14/part2.pas -obuild/day14part2
|
|
||||||
@echo
|
|
||||||
./build/day14part2
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm build/*
|
rm build/*
|
10
readme.md
10
readme.md
@ -30,13 +30,3 @@ run them in the root dir though
|
|||||||
|
|
||||||
thankies.
|
thankies.
|
||||||
|
|
||||||
# z80
|
|
||||||
|
|
||||||
i did day 13 in z80 assembly language too. it's in z80src
|
|
||||||
|
|
||||||
it uses zasm to compile and z80sim from [z80pack](https://www.autometer.de/unix4fun/z80pack/).
|
|
||||||
|
|
||||||
i edited z80sim to not print out that giant logo at the beginning but otherwise it's just the newest one built.
|
|
||||||
the binary is included though lol.
|
|
||||||
|
|
||||||
|
|
||||||
|
1000
resources/day12.txt
1000
resources/day12.txt
File diff suppressed because it is too large
Load Diff
@ -1,6 +0,0 @@
|
|||||||
???.### 1,1,3
|
|
||||||
.??..??...?##. 1,1,3
|
|
||||||
?#?#?#?#?#?#?#? 1,3,1,6
|
|
||||||
????.#...#... 4,1,1
|
|
||||||
????.######..#####. 1,6,5
|
|
||||||
?###???????? 3,2,1
|
|
1350
resources/day13.txt
1350
resources/day13.txt
File diff suppressed because it is too large
Load Diff
@ -1,100 +0,0 @@
|
|||||||
#...#...O....OO.#O.O........#.OO.#.O..O.O.#.#..O#..O...#.#......#..O.....O.###O..OO.#.....O.O.......
|
|
||||||
O.#..#..O.O...O..#OO#...#.#.OO....O.#.....O.#OOO.#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.O
|
|
||||||
##O....O....#.OOO...O.#....O#.O#OO....O....O#...O..O#O.#..O.OO...O..O..#.#O..OO.O...O..#.#OO#.......
|
|
||||||
.O.O#OO..#...#..........O#.O..##.O..OO.O...#........O##.OOOO..#.#....O..O#O.#O.##..OO..O...#..O##...
|
|
||||||
OO...O##.....#...O.#O.....#.OOO.#.##...##...##.O.....##....O..O..#..#..OO...#..........OO..#.O#...O.
|
|
||||||
.OO#..#.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....OO.OO..O#.O#..#.O......#..O...#.O.##.#....O.OO.#...O...O#
|
|
||||||
.#.O.....O...O...O...O.#.........OO.....#................O....O..#..........##.O#.OO..O###..#.......
|
|
||||||
#O...#O..O#.......O...#..O...OO..#...O........#....O#..OO...O.O..#.OOO.....O..O.#...O.OO#.OO#.OO.O#.
|
|
||||||
......#.O...O...O.O...#...#O.O#....#.O..###..O....#.#.O.OO#....O#.....O...#.O......##......#O..#OO..
|
|
||||||
#OO.##...#..O....#...#...OO...........OO.O.OOOO...#...#O..#...#O#.O.O......O....O..#.O..O...#O#.O.O.
|
|
||||||
#...O.OO...#.#.OO...O#O....OO....#O....O.O#..#....O...##..O..O.#..#..#...........O...OO#.#..O.....O#
|
|
||||||
..#..O.O#.....O....O#..#........OO#.#...#O.O....O#....O#...O..#....OO#.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.O##.....OOO#...#O.O#O.....#.O#..........O#O.....O.OOO..##.#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....#..O....#O.....OO#..O.O..####..#...O..O...OOO.#OO..#....#...OO..O.....#O..O..#
|
|
||||||
O#...##...#..#O#..#O#..O#....OO..O#O#.....OOOOOO#.#.O.O..O.OO.O........O...#.#......OO#...#..#.#...#
|
|
||||||
..OO.O..OO.OO....#........#O.#...#O....#...O.OO...O#..O......O.###....#O......#.....####...#..#.#OO.
|
|
||||||
..O.O..O#....#.O.#.#.#.O#..O.......OO.........##.O.....#OOO..O#..#OO#.....O...OO.O.O...#...OO#.O.#..
|
|
||||||
O...#........###..##..O#.#O.O..O.#OO.OO...#....#O.O#O..OO...##....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.O...O.#O.#.O#.O......#........OO...O....#.O........O#.OO#..........O.O..OOOOO#.#.
|
|
||||||
O..##.##...........O##.#...#.O.#.OO..O.O...OO#.#..#...O..O....#..#..#...O###......O#.#O#..O.#....O.#
|
|
||||||
#.O.O.O.###.##......#.OO...OO.O..OOO.O.OOO.....##..O#...O......O.#O..#...#...OO..O#......O....##.O.#
|
|
||||||
#...#.O.O....O..#...#........##O#O#O..##O.#......O...OO#O...OOOO#O..OO##..#......O.#O.#.O#.OO...O..#
|
|
||||||
#..#........#O.#O.#...O...O....#OO...O....#...O..#......#..O..O...##........O..#.O..#.#OO..OO.O##.O.
|
|
||||||
..#...#...OO.#.O#O.O.##..#..##..O#...O#....#..O....OO.OOO..O#.#....O.......OO.#.O#.....O.#O.O.#.....
|
|
||||||
.......O...O..O...#.O..OO...O.....O.O#..#OO#.O...O..O#O..O..#.OO.......O..O....OOOO..O.#.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..O..O#O..O.O#O.#O.#..OO.....#.O.#O#..##.#.O.O...OO....#..
|
|
||||||
....#.O..O..#...#....O............O.O.#O.#.O...O....O.#.OO....O..O##...O##......O....O...OO........#
|
|
||||||
.#O...O..O.O.#O.......O###OO.O.O.O.....##O..OO...#.O..#OO..#...#...#.O.O###.....#O#..##.#O.....O....
|
|
||||||
..#.###.#..##......#..#.#OO..O......O..#OOO.#O...#....OO.##O...O..#.#O....#OO....O.#.......#....O...
|
|
||||||
#OO...#......#..#........#.OO.##....#...OOOO..O#O..O.#..#O........#O.OO#..........OO..OO....O..#O.#.
|
|
||||||
..##.##.O....#.##O..#...###..O##.#.#......O#O..###..##......O...#.....##.#...........O.O.O....O.#...
|
|
||||||
...O.#..#......#.OO..#..O##...O..O...OO##...OO.O#....O.O.#.O.....O..#..O..#...O..#O.....O.O..O.O#.##
|
|
||||||
O......###OOO#.#.....OO...O.....O.##.....OO..........OO#O#.O.#.#O....O..#O.#..........##O...#O....O.
|
|
||||||
..#...#...OO.OO#.....OO...O.O.O.##.##O##..O.#.O#..O.O.....OOOO....#....O.O.#..##OO.O#..#O.O.#...O...
|
|
||||||
.#.OO.##....O..O...O..#.##.O#OO..#.....OO.........O.OOO.#..O....O....OOO.#.OO..O..#...O#OO.OO##.#.O.
|
|
||||||
.#.OO.O#.O.O.....#O..O.O..O......O.#O...O..O...##.O#..#.O.....O...O....OO.OOO..OO.O...OO..#.#..OOO#.
|
|
||||||
.#..O.#.O..#.OOO....#O#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....
|
|
||||||
O#.O...O.##O..OO..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#.#..#.O..##O.O.#.OO....O#..........O..#.##..#..O.#...#O.OO..
|
|
||||||
.O..#....OO...O.......#...#...O.##...O..O.O.........OO#O.OO.O..O...O.##.....##.....##O..#......O....
|
|
||||||
#..O.O..OO....O.O#.#O#........O..OO#.OO#O.O..O..#......O#...##.......#..##..O.#..#.O.O...#....#.O...
|
|
||||||
#..O.#...OO#.OO#.O.OO.O##.#....OO....#........#.O.O....O.#..O#..#....#.O#..O#..O.....OO..OOOO.....O.
|
|
||||||
.O..OO#.O#OO..#O..O.#......O..O..O.#O.#..#.#.O..O.O..O.....##.OO..#O.#............O#...#......O.OO.#
|
|
||||||
O......##OO....O...O......#...O..O.#...OO#O..O.OOO..O.....O...#.##..OOO.##...O.O....O#O....##...#...
|
|
||||||
..OO..#.O.O..#O.O...O...#...O.O#.##O....##...###O..O...O.O##..........###...O...O..#...#.#.....O....
|
|
||||||
#..OO....O..#O..OO...OO.............O.O..OOO.O.#.....O#O....#O.....#.O..O....O..O....O..O....O.#....
|
|
||||||
OO.O##..O...#O........#O...#OOOO.O..O....O...O..O..O#.O.O..##.##..O.#O...O#...#..O...O...OO.......O.
|
|
||||||
#..O#..O...O.#......#OO.OO.O.#...O...O#...#...O..##O#....#......#.....#..#O...#.O.O..............O#.
|
|
||||||
##..OO#..........#.O..OOOOO..#...#....#.#..O#O...O....#.O.#O#OO.#......#...O........O...O#....#....O
|
|
||||||
.....O...O#....O..O..OO.O..#...O.#..#..#...O#..#O....O.#.....#O....O...##....#..#......###.O.....O#.
|
|
||||||
#...O#..O..O#..OO....#.#...#O#..#.....#..#..................OO....O......OO.........O###O#....OO.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.#..O.O..O#......O.O..O#
|
|
||||||
...O.#.#..O.#..###..#...#.....O..O.....OO#..O..#.O..#....OOO...........#.......#..OO..OO#.#O....#O..
|
|
||||||
.O.O...#....#.#O..#..OO#..#....OO....#O..O#.#..#..O.#..O.#O#..OO........#O.#...OO....OO......#.#O...
|
|
||||||
OO.O.O#..#.#.#.O.OOO...#....O..O##...O.OO#.#.....O.....#.....O....#.........O...O..........OOO.O.OOO
|
|
||||||
......O...O...###....##.O.O..OOO..O.O......O.#.......#..O..........O#..#..#O.#.##.....###.#O#O#O..#.
|
|
||||||
O..#..#O.OO.......#.OO...#OO..OO.O#O.....#.#.O..OOO.OO.##O.O#...#.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.OO#.O.#..OO............O.O.O.#..OO#....##O.....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..#..OOO.#..##.....OO.O.....OOO.#..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......O..OOO..OO.###
|
|
||||||
#O.#.O...O.....O....#OO##...OO..#...OO.#O.OOO.O..#O....O............#....#....#...........O.OOO#.OO.
|
|
||||||
.O.O.#OO#O.O.OO#..O..#....O.#..O...O....O.#OO#O...##.......O...O.....#.O...#...O.##O...OOO.O........
|
|
||||||
.O#..O.......#..##..OO#.....O.#.OO#...#O.O..O......O..OO.#...#.#............O#O.OO.......O#........#
|
|
||||||
.OO#..O##...........O.OO.....#.##....O#.#.#O..O...O..#..#..O.......#......#.#...........###O##......
|
|
||||||
...#...#.....O........OO..#.#...O.#.....#.OO.....#.O.#OO......#OO..#.....#..O##..O..#...O.O.......O#
|
|
||||||
O...O...#O..#O#O.......#..#O....#OO....#.#O.....O....O##.#...O.......#.....#........#O.O...O...O....
|
|
||||||
..#.....OO.#.OO....O#O....O#O...O.O...#O.##....##O...#..##O#.OO#O..OOO.#.#......O.OO.O..O.O.OO.#O.#.
|
|
||||||
.......O.....##...O#.#O.#....O.....O........#...#.OO...#...OO........#OO#...#..OO..O...#....O#.#OO.O
|
|
||||||
..#..O.OO....O...#.......OO.O.##...#...O...#.O#.OO#....O...O..O###.O.###O..#....##.O.##....O..##...#
|
|
||||||
.......OOO.....OO..#..O..#O.OOO#O.....O.O#.....O....###..O#..OO..O....###O.OO...#..#.O....#.O.O..#OO
|
|
||||||
.#...#.........#.###..#...#.#...#O.#..O#O#OOOO#.#.O.....O.#....#..O......#OO....O..O.O.#.O......O..O
|
|
||||||
O.O....O....O..O......O...#.....O##....OOO.....#.OO.#..O....O..O.O#.O#.OO......#....#......OO......O
|
|
||||||
..#O.#O.....O...#O...##.O#..O...#..##.O.O.O....#.....#.O#O.....#............O....#.#...#....###...#.
|
|
||||||
.O..O...OO.....#...........##...O#.O##O........OO..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#....O.....O#O..O##O#..O..O.O.....O........#.#......O#..O..OO.OO#.....OO........O......O#...O.#..
|
|
||||||
....#.....O..#......O...##.O.O.#..#.....O.O..#.O#.#O...##....O.......#O..O.....#..#.....#.....#.....
|
|
||||||
.OO....OOO.OO....O...#.......O......#O.#O..O.O#O..............O.#......#.#.......#....#.O....#.#O.#.
|
|
||||||
OO...OO.#.O#OO#........##.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.....##..O#O...#O....O....O#OOO.#
|
|
||||||
.OO#..#..O..........##.O.#OO#..O.O.#...#....O..O#.O..#.#.....O.O..#..OO..##O#...O.O.O#........O.....
|
|
||||||
.O............#.O...#...#....###.O#.#.#....O.....OO...#O.#.O..O##...#O.#O..OO#..#.O#.#.....O#.......
|
|
||||||
#..O#..#.OOO#O...O.O..O..#OOO....#...........O##...OOO##O....O.O...O..O#O.........O.OO.....O....O...
|
|
||||||
.#....#OO..##O..#O##O.#O....#......O.OO..........##.OO#O...#.....O.O.....O#..OO.#........O..O.O..O..
|
|
||||||
....O.##...#.O.........O.OO....#....##O..#O.......#..O.##O#..#O..#.....O.O#O....#...O..O.OO.........
|
|
||||||
..###.O.....##.....OO.O..OO.O..#...O.....#....O.O...............O.##.#.O#O#.#...O..#.OOOOO....#.#.#.
|
|
||||||
O...O....O.#.#.O#.O#..#......O#.....OO.##....OO.....O.......O....O.O.....#...O..OO#..OO..O....#OOO.#
|
|
||||||
#.#.#.O..#.O...#....#..O....O......O..#..O.OO#O......O.......O.O.........O...O.......OO.##.......#.#
|
|
||||||
O#..........O...#O.###....#O..O.#......O....#.O.O...O...O.....O#..#.O#..O.#.O..OOO#.O...#..O.#O.....
|
|
@ -1,11 +0,0 @@
|
|||||||
##########
|
|
||||||
O....#....
|
|
||||||
O.OO#....#
|
|
||||||
.....##...
|
|
||||||
OO.#O....O
|
|
||||||
.O.....O#.
|
|
||||||
O.#..O.#.#
|
|
||||||
..O..#O..O
|
|
||||||
.......O..
|
|
||||||
#....###..
|
|
||||||
#OO..#....
|
|
@ -1,205 +0,0 @@
|
|||||||
{$mode objfpc}
|
|
||||||
|
|
||||||
program day12part1;
|
|
||||||
uses sysutils;
|
|
||||||
|
|
||||||
type
|
|
||||||
int32array = array of int32;
|
|
||||||
stringarray = array of string;
|
|
||||||
|
|
||||||
function sum(l: array of int32; start: int32 = 0): int32;
|
|
||||||
var
|
|
||||||
i: int32;
|
|
||||||
begin
|
|
||||||
sum := 0;
|
|
||||||
for i := start to length(l) - 1 do
|
|
||||||
sum := l[i] + sum;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function split_to_int(s: string; delim: char): int32array ;
|
|
||||||
var
|
|
||||||
i, last_delim, count : int32;
|
|
||||||
c: char;
|
|
||||||
begin
|
|
||||||
|
|
||||||
{ there will always be at least one number }
|
|
||||||
count := 1;
|
|
||||||
{ count number of delimeters }
|
|
||||||
for c in s do
|
|
||||||
begin
|
|
||||||
if c = delim then
|
|
||||||
count := count + 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ allocate enough space for count}
|
|
||||||
setlength(split_to_int, count);
|
|
||||||
|
|
||||||
count := 0;
|
|
||||||
last_delim := 0;
|
|
||||||
|
|
||||||
{ second interation }
|
|
||||||
for i := 1 to length(s) do
|
|
||||||
begin
|
|
||||||
{ if this is a delimeter }
|
|
||||||
if s[i] = delim then
|
|
||||||
begin
|
|
||||||
{ add the value between this delimiter and the previous one to splitted }
|
|
||||||
val(
|
|
||||||
copy(s, last_delim + 1, i - last_delim - 1), split_to_int[count]
|
|
||||||
);
|
|
||||||
count := count + 1;
|
|
||||||
last_delim := i;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ don't forget the final value }
|
|
||||||
val(
|
|
||||||
copy(s, last_delim + 1, length(s) - last_delim), split_to_int[count]
|
|
||||||
);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function split_to_str(s: string; delim: char): stringarray;
|
|
||||||
var
|
|
||||||
i, last_delim, count : int32;
|
|
||||||
c: char;
|
|
||||||
begin
|
|
||||||
|
|
||||||
{ there will always be at least one number }
|
|
||||||
count := 1;
|
|
||||||
{ count number of delimeters }
|
|
||||||
for c in s do
|
|
||||||
begin
|
|
||||||
if c = delim then
|
|
||||||
count := count + 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ allocate enough space for count}
|
|
||||||
setlength(split_to_str, count);
|
|
||||||
|
|
||||||
count := 0;
|
|
||||||
last_delim := 0;
|
|
||||||
|
|
||||||
{ second interation }
|
|
||||||
for i := 1 to length(s) do
|
|
||||||
begin
|
|
||||||
{ if this is a delimeter }
|
|
||||||
if s[i] = delim then
|
|
||||||
begin
|
|
||||||
{ add the value between this delimiter and the previous one to splitted }
|
|
||||||
split_to_str[count] := copy(s, last_delim + 1, i - last_delim - 1);
|
|
||||||
count := count + 1;
|
|
||||||
last_delim := i;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ don't forget the final value }
|
|
||||||
split_to_str[count] := copy(s, last_delim + 1, length(s) - last_delim)
|
|
||||||
end;
|
|
||||||
|
|
||||||
function will_fit(s: string; idx, length: int32): boolean;
|
|
||||||
var
|
|
||||||
i: int32;
|
|
||||||
begin
|
|
||||||
will_fit := true;
|
|
||||||
for i := idx to idx + length - 1 do
|
|
||||||
begin
|
|
||||||
if s[i] = '.' then
|
|
||||||
begin
|
|
||||||
will_fit := false;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function all_after_not(s: string; idx: int32; c: char): boolean;
|
|
||||||
var
|
|
||||||
i: int32;
|
|
||||||
begin
|
|
||||||
all_after_not := true;
|
|
||||||
for i := idx to length(s) do
|
|
||||||
begin
|
|
||||||
if s[i] = c then
|
|
||||||
begin
|
|
||||||
all_after_not := false;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function possibilties(s: string; l: array of int32; start_s: int32 = 1; start_l: int32 = 0): int32;
|
|
||||||
var
|
|
||||||
i: int32;
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
possibilties := 0;
|
|
||||||
|
|
||||||
// writeln(s, l[start_l], length(l), start_s, start_l);
|
|
||||||
|
|
||||||
{ if there is only one spring left then }
|
|
||||||
if length(l) - start_l = 1 then
|
|
||||||
begin
|
|
||||||
|
|
||||||
{ check every possibility }
|
|
||||||
for i := start_s to length(s) - l[start_l] + 1 do
|
|
||||||
begin
|
|
||||||
{ if it will fit here, then it's valid }
|
|
||||||
if will_fit(s, i, l[start_l]) and all_after_not(s, i + l[start_l], '#') then
|
|
||||||
possibilties := possibilties + 1;
|
|
||||||
|
|
||||||
{ if we pass by a #, then it's not valid anymore as the # won't be filled }
|
|
||||||
if s[i] = '#' then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
|
|
||||||
for i := start_s to length(s) - sum(l, start_l) - length(l) + start_l + 2 do
|
|
||||||
begin
|
|
||||||
{ if it will fit and we aren't skipping a '#', recursively find possibilities }
|
|
||||||
|
|
||||||
if will_fit(s, i, l[start_l]) and (s[i + l[start_l]] <> '#') then
|
|
||||||
possibilties := possibilties + possibilties(s, l, i + l[start_l] + 1, start_l + 1);
|
|
||||||
|
|
||||||
{ if we pass by a #, then it's not valid anymore as the # won't be filled }
|
|
||||||
if s[i] = '#' then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
|
|
||||||
s: string;
|
|
||||||
pattern: array of int32;
|
|
||||||
|
|
||||||
split: array of string;
|
|
||||||
|
|
||||||
file_: text;
|
|
||||||
|
|
||||||
total: int32;
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
assign(file_, 'resources/day12.txt');
|
|
||||||
reset(file_);
|
|
||||||
|
|
||||||
total := 0;
|
|
||||||
|
|
||||||
while not EOF(file_) do
|
|
||||||
begin
|
|
||||||
|
|
||||||
readln(file_, s);
|
|
||||||
split := split_to_str(s, ' ');
|
|
||||||
|
|
||||||
pattern := split_to_int(split[1], ',');
|
|
||||||
|
|
||||||
total := total + possibilties(split[0], pattern);
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
writeln('The sum is ', total);
|
|
||||||
end.
|
|
||||||
|
|
@ -1,250 +0,0 @@
|
|||||||
{$mode objfpc}
|
|
||||||
{$RANGECHECKS ON}
|
|
||||||
|
|
||||||
program day12part1;
|
|
||||||
uses sysutils;
|
|
||||||
|
|
||||||
type
|
|
||||||
int64array = array of int64;
|
|
||||||
stringarray = array of string;
|
|
||||||
|
|
||||||
function sum(l: array of int64; start: int64 = 0): int64;
|
|
||||||
var
|
|
||||||
i: int64;
|
|
||||||
begin
|
|
||||||
sum := 0;
|
|
||||||
for i := start to length(l) - 1 do
|
|
||||||
sum := l[i] + sum;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function split_to_int(s: string; delim: char): int64array ;
|
|
||||||
var
|
|
||||||
i, last_delim, count : int64;
|
|
||||||
c: char;
|
|
||||||
begin
|
|
||||||
|
|
||||||
{ there will always be at least one number }
|
|
||||||
count := 1;
|
|
||||||
{ count number of delimeters }
|
|
||||||
for c in s do
|
|
||||||
begin
|
|
||||||
if c = delim then
|
|
||||||
count := count + 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ allocate enough space for count}
|
|
||||||
setlength(split_to_int, count);
|
|
||||||
|
|
||||||
count := 0;
|
|
||||||
last_delim := 0;
|
|
||||||
|
|
||||||
{ second interation }
|
|
||||||
for i := 1 to length(s) do
|
|
||||||
begin
|
|
||||||
{ if this is a delimeter }
|
|
||||||
if s[i] = delim then
|
|
||||||
begin
|
|
||||||
{ add the value between this delimiter and the previous one to splitted }
|
|
||||||
val(
|
|
||||||
copy(s, last_delim + 1, i - last_delim - 1), split_to_int[count]
|
|
||||||
);
|
|
||||||
count := count + 1;
|
|
||||||
last_delim := i;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ don't forget the final value }
|
|
||||||
val(
|
|
||||||
copy(s, last_delim + 1, length(s) - last_delim), split_to_int[count]
|
|
||||||
);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function split_to_str(s: string; delim: char): stringarray;
|
|
||||||
var
|
|
||||||
i, last_delim, count : int64;
|
|
||||||
c: char;
|
|
||||||
begin
|
|
||||||
|
|
||||||
{ there will always be at least one number }
|
|
||||||
count := 1;
|
|
||||||
{ count number of delimeters }
|
|
||||||
for c in s do
|
|
||||||
begin
|
|
||||||
if c = delim then
|
|
||||||
count := count + 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ allocate enough space for count}
|
|
||||||
setlength(split_to_str, count);
|
|
||||||
|
|
||||||
count := 0;
|
|
||||||
last_delim := 0;
|
|
||||||
|
|
||||||
{ second interation }
|
|
||||||
for i := 1 to length(s) do
|
|
||||||
begin
|
|
||||||
{ if this is a delimeter }
|
|
||||||
if s[i] = delim then
|
|
||||||
begin
|
|
||||||
{ add the value between this delimiter and the previous one to splitted }
|
|
||||||
split_to_str[count] := copy(s, last_delim + 1, i - last_delim - 1);
|
|
||||||
count := count + 1;
|
|
||||||
last_delim := i;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ don't forget the final value }
|
|
||||||
split_to_str[count] := copy(s, last_delim + 1, length(s) - last_delim)
|
|
||||||
end;
|
|
||||||
|
|
||||||
function will_fit(s: string; idx, length: int64): boolean;
|
|
||||||
var
|
|
||||||
i: int64;
|
|
||||||
begin
|
|
||||||
will_fit := true;
|
|
||||||
for i := idx to idx + length - 1 do
|
|
||||||
begin
|
|
||||||
if s[i] = '.' then
|
|
||||||
begin
|
|
||||||
will_fit := false;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function all_after_not(s: string; idx: int64; c: char): boolean;
|
|
||||||
var
|
|
||||||
i: int64;
|
|
||||||
begin
|
|
||||||
all_after_not := true;
|
|
||||||
for i := idx to length(s) do
|
|
||||||
begin
|
|
||||||
if s[i] = c then
|
|
||||||
begin
|
|
||||||
all_after_not := false;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
cache: array[0..1000, 0..1000] of int64;
|
|
||||||
|
|
||||||
procedure clear_cache();
|
|
||||||
var
|
|
||||||
i, j: int64;
|
|
||||||
begin
|
|
||||||
for i := 0 to 1000 do
|
|
||||||
begin
|
|
||||||
for j:= 0 to 1000 do
|
|
||||||
begin
|
|
||||||
cache[i, j] := -1;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function possibilties(s: string; l: array of int64; start_s: int64 = 1; start_l: int64 = 0): int64;
|
|
||||||
var
|
|
||||||
i: int64;
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
possibilties := 0;
|
|
||||||
|
|
||||||
{ clear the cache if we r starting }
|
|
||||||
if start_l = 0 then
|
|
||||||
clear_cache();
|
|
||||||
|
|
||||||
{ return cache if we have the value }
|
|
||||||
if cache[start_s, start_l] <> -1 then
|
|
||||||
begin
|
|
||||||
possibilties := cache[start_s, start_l];
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ if there is only one spring left then }
|
|
||||||
if length(l) - start_l = 1 then
|
|
||||||
begin
|
|
||||||
|
|
||||||
{ check every possibility }
|
|
||||||
for i := start_s to length(s) - l[start_l] + 1 do
|
|
||||||
begin
|
|
||||||
{ if it will fit here, then it's valid }
|
|
||||||
if will_fit(s, i, l[start_l]) and all_after_not(s, i + l[start_l], '#') then
|
|
||||||
possibilties := possibilties + 1;
|
|
||||||
|
|
||||||
{ if we pass by a #, then it's not valid anymore as the # won't be filled }
|
|
||||||
if s[i] = '#' then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
|
|
||||||
for i := start_s to length(s) - sum(l, start_l) - length(l) + start_l + 2 do
|
|
||||||
begin
|
|
||||||
{ if it will fit and we aren't skipping a '#', recursively find possibilities }
|
|
||||||
|
|
||||||
if will_fit(s, i, l[start_l]) and (s[i + l[start_l]] <> '#') then
|
|
||||||
possibilties := possibilties + possibilties(s, l, i + l[start_l] + 1, start_l + 1);
|
|
||||||
|
|
||||||
{ if we pass by a #, then it's not valid anymore as the # won't be filled }
|
|
||||||
if s[i] = '#' then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
cache[start_s, start_l] := possibilties;
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
function duplicate_int_array(arr: int64array; times: int64): int64array;
|
|
||||||
var
|
|
||||||
i: int64;
|
|
||||||
begin
|
|
||||||
setlength(duplicate_int_array, length(arr) * times);
|
|
||||||
|
|
||||||
for i := 0 to length(arr) * times - 1 do
|
|
||||||
begin
|
|
||||||
duplicate_int_array[i] := arr[i mod length(arr)];
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
|
|
||||||
s: string;
|
|
||||||
pattern: array of int64;
|
|
||||||
|
|
||||||
split: array of string;
|
|
||||||
|
|
||||||
file_: text;
|
|
||||||
|
|
||||||
total: int64;
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
assign(file_, 'resources/day12.txt');
|
|
||||||
reset(file_);
|
|
||||||
|
|
||||||
total := 0;
|
|
||||||
|
|
||||||
while not EOF(file_) do
|
|
||||||
begin
|
|
||||||
|
|
||||||
readln(file_, s);
|
|
||||||
split := split_to_str(s, ' ');
|
|
||||||
|
|
||||||
pattern := split_to_int(split[1], ',');
|
|
||||||
|
|
||||||
//total := total + possibilties(split[0], pattern);
|
|
||||||
|
|
||||||
total := total + possibilties(split[0] + '?' + split[0] + '?' + split[0] + '?' + split[0] + '?' + split[0],
|
|
||||||
duplicate_int_array(pattern, 5));
|
|
||||||
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
writeln('The sum is ', total);
|
|
||||||
end.
|
|
||||||
|
|
@ -1,142 +0,0 @@
|
|||||||
{$mode objfpc}
|
|
||||||
{$RANGECHECKS ON}
|
|
||||||
|
|
||||||
program day13part1;
|
|
||||||
uses sysutils;
|
|
||||||
|
|
||||||
type
|
|
||||||
Tmap = record
|
|
||||||
map: array[1..100] of string;
|
|
||||||
height: int32;
|
|
||||||
width: int32;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function max(a, b: int32): int32;
|
|
||||||
begin
|
|
||||||
max := a;
|
|
||||||
if b > a then
|
|
||||||
max := b;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ check for mirrors that lay vertically (column mirror) }
|
|
||||||
function check_v_mirror(map: Tmap; col: int32): boolean;
|
|
||||||
var
|
|
||||||
i, j: int32;
|
|
||||||
begin
|
|
||||||
|
|
||||||
check_v_mirror := true;
|
|
||||||
for j := 1 to map.height do
|
|
||||||
begin
|
|
||||||
for i := max(1, 2 * col - map.width + 1) to col do
|
|
||||||
begin
|
|
||||||
// writeln(i, ' ', col*2 - i);
|
|
||||||
if map.map[j, i] <> map.map[j, col * 2 - i + 1] then
|
|
||||||
begin
|
|
||||||
check_v_mirror := false;
|
|
||||||
break
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if not check_v_mirror then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
|
|
||||||
check_v_mirror := check_v_mirror;
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ check for mirrors that lay vertically (column mirror) }
|
|
||||||
function check_h_mirror(map: Tmap; row: int32): boolean;
|
|
||||||
var
|
|
||||||
i, j: int32;
|
|
||||||
begin
|
|
||||||
|
|
||||||
check_h_mirror := true;
|
|
||||||
for j := 1 to map.width do
|
|
||||||
begin
|
|
||||||
for i := max(1, 2 * row - map.height + 1) to row do
|
|
||||||
begin
|
|
||||||
//writeln(i, ' ', row*2 - i + 1);
|
|
||||||
if map.map[i, j] <> map.map[row * 2 - i + 1, j] then
|
|
||||||
begin
|
|
||||||
check_h_mirror := false;
|
|
||||||
break
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if not check_h_mirror then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
function get_mirror(map: Tmap): int32;
|
|
||||||
var
|
|
||||||
i: int32;
|
|
||||||
begin
|
|
||||||
{ check vertical ones first }
|
|
||||||
for i := 1 to map.width - 1 do
|
|
||||||
begin
|
|
||||||
if check_v_mirror(map, i) then
|
|
||||||
begin
|
|
||||||
get_mirror := i;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ check horizontal ones now }
|
|
||||||
for i := 1 to map.height - 1 do
|
|
||||||
begin
|
|
||||||
if check_h_mirror(map, i) then
|
|
||||||
begin
|
|
||||||
get_mirror := i shl 6 + i shl 5 + i shl 2;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
|
|
||||||
map: Tmap;
|
|
||||||
file_: text;
|
|
||||||
s: string;
|
|
||||||
total, map_count: int32;
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
assign(file_, 'resources/day13.txt');
|
|
||||||
reset(file_);
|
|
||||||
|
|
||||||
total := 0;
|
|
||||||
map_count := 0;
|
|
||||||
|
|
||||||
while not EOF(file_) do
|
|
||||||
begin
|
|
||||||
|
|
||||||
readln(file_, s);
|
|
||||||
writeln(s);
|
|
||||||
if length(s) = 0 then
|
|
||||||
begin
|
|
||||||
// come back to this
|
|
||||||
|
|
||||||
total := total + get_mirror(map);
|
|
||||||
|
|
||||||
map_count := 0;
|
|
||||||
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
|
|
||||||
map_count := map_count + 1;
|
|
||||||
map.map[map_count] := s;
|
|
||||||
map.height := map_count;
|
|
||||||
map.width := length(s);
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
writeln(total);
|
|
||||||
|
|
||||||
end.
|
|
@ -1,149 +0,0 @@
|
|||||||
{$mode objfpc}
|
|
||||||
{$RANGECHECKS ON}
|
|
||||||
|
|
||||||
program day13part1;
|
|
||||||
uses sysutils;
|
|
||||||
|
|
||||||
type
|
|
||||||
Tmap = record
|
|
||||||
map: array[1..100] of string;
|
|
||||||
height: int32;
|
|
||||||
width: int32;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function max(a, b: int32): int32;
|
|
||||||
begin
|
|
||||||
max := a;
|
|
||||||
if b > a then
|
|
||||||
max := b;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ check for mirrors that lay vertically (column mirror) }
|
|
||||||
function check_v_mirror(map: Tmap; col: int32): boolean;
|
|
||||||
var
|
|
||||||
i, j: int32;
|
|
||||||
errors: int32;
|
|
||||||
begin
|
|
||||||
|
|
||||||
errors := 0;
|
|
||||||
for j := 1 to map.height do
|
|
||||||
begin
|
|
||||||
for i := max(1, 2 * col - map.width + 1) to col do
|
|
||||||
begin
|
|
||||||
// writeln(i, ' ', col*2 - i);
|
|
||||||
if map.map[j, i] <> map.map[j, col * 2 - i + 1] then
|
|
||||||
begin
|
|
||||||
errors := errors + 1;
|
|
||||||
if errors > 1 then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if errors > 1 then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
|
|
||||||
check_v_mirror := errors = 1;
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ check for mirrors that lay vertically (column mirror) }
|
|
||||||
function check_h_mirror(map: Tmap; row: int32): boolean;
|
|
||||||
var
|
|
||||||
i, j: int32;
|
|
||||||
errors: int32;
|
|
||||||
begin
|
|
||||||
|
|
||||||
errors := 0;
|
|
||||||
for j := 1 to map.width do
|
|
||||||
begin
|
|
||||||
for i := max(1, 2 * row - map.height + 1) to row do
|
|
||||||
begin
|
|
||||||
//writeln(i, ' ', row*2 - i + 1);
|
|
||||||
if map.map[i, j] <> map.map[row * 2 - i + 1, j] then
|
|
||||||
begin
|
|
||||||
errors := errors + 1;
|
|
||||||
if errors > 1 then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if errors > 1 then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
|
|
||||||
check_h_mirror := errors = 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
function get_mirror(map: Tmap): int32;
|
|
||||||
var
|
|
||||||
i: int32;
|
|
||||||
begin
|
|
||||||
{ check vertical ones first }
|
|
||||||
for i := 1 to map.width - 1 do
|
|
||||||
begin
|
|
||||||
if check_v_mirror(map, i) then
|
|
||||||
begin
|
|
||||||
get_mirror := i;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ check horizontal ones now }
|
|
||||||
for i := 1 to map.height - 1 do
|
|
||||||
begin
|
|
||||||
if check_h_mirror(map, i) then
|
|
||||||
begin
|
|
||||||
get_mirror := i shl 6 + i shl 5 + i shl 2;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if get_mirror = 0 then
|
|
||||||
writeln('oh fuck');
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
|
|
||||||
map: Tmap;
|
|
||||||
file_: text;
|
|
||||||
s: string;
|
|
||||||
total, map_count: int32;
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
assign(file_, 'resources/day13.txt');
|
|
||||||
reset(file_);
|
|
||||||
|
|
||||||
total := 0;
|
|
||||||
map_count := 0;
|
|
||||||
|
|
||||||
while not EOF(file_) do
|
|
||||||
begin
|
|
||||||
|
|
||||||
readln(file_, s);
|
|
||||||
if length(s) = 0 then
|
|
||||||
begin
|
|
||||||
|
|
||||||
total := total + get_mirror(map);
|
|
||||||
|
|
||||||
map_count := 0;
|
|
||||||
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
|
|
||||||
map_count := map_count + 1;
|
|
||||||
map.map[map_count] := s;
|
|
||||||
map.height := map_count;
|
|
||||||
map.width := length(s);
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
|
||||||
|
|
||||||
writeln(total);
|
|
||||||
|
|
||||||
end.
|
|
@ -1,61 +0,0 @@
|
|||||||
{$mode objfpc}
|
|
||||||
{$RANGECHECKS ON}
|
|
||||||
|
|
||||||
program day14part1;
|
|
||||||
uses sysutils;
|
|
||||||
|
|
||||||
var
|
|
||||||
|
|
||||||
file_: text;
|
|
||||||
s: string;
|
|
||||||
|
|
||||||
map: array[1..1000] of string;
|
|
||||||
|
|
||||||
current_boulders: int32;
|
|
||||||
height, width: int32;
|
|
||||||
i, j, k: int32;
|
|
||||||
|
|
||||||
sum: int32;
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
assign(file_, 'resources/day14.txt');
|
|
||||||
reset(file_);
|
|
||||||
|
|
||||||
height := 1;
|
|
||||||
fillchar(map[1], 255, '#');
|
|
||||||
|
|
||||||
while not eof(file_) do
|
|
||||||
begin
|
|
||||||
height := height + 1;
|
|
||||||
readln(file_, map[height]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
width := length(map[2]);
|
|
||||||
|
|
||||||
sum := 0;
|
|
||||||
|
|
||||||
for i := 1 to width do
|
|
||||||
begin
|
|
||||||
|
|
||||||
current_boulders := 0;
|
|
||||||
|
|
||||||
for j := 1 to height do
|
|
||||||
begin
|
|
||||||
case map[height - j + 1][i] of
|
|
||||||
'O': current_boulders := current_boulders + 1;
|
|
||||||
'#':
|
|
||||||
begin
|
|
||||||
for k := j - current_boulders to j - 1 do
|
|
||||||
begin
|
|
||||||
sum := sum + k;
|
|
||||||
end;
|
|
||||||
current_boulders := 0;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
writeln('sum: ', sum);
|
|
||||||
|
|
||||||
end.
|
|
File diff suppressed because it is too large
Load Diff
@ -1,342 +0,0 @@
|
|||||||
.org 0x0000
|
|
||||||
|
|
||||||
LD HL, FILE;
|
|
||||||
|
|
||||||
main_loop:
|
|
||||||
|
|
||||||
CALL LOAD_MAP
|
|
||||||
PUSH HL
|
|
||||||
CALL CHECK_MAP
|
|
||||||
POP HL
|
|
||||||
JR C, vert
|
|
||||||
|
|
||||||
;; ld a into bc
|
|
||||||
LD B, 0;
|
|
||||||
LD C, A;
|
|
||||||
|
|
||||||
;; add it into IX
|
|
||||||
ADD IX, BC
|
|
||||||
|
|
||||||
JR vh_end
|
|
||||||
|
|
||||||
vert
|
|
||||||
|
|
||||||
;; ld a into bc
|
|
||||||
LD B, 0;
|
|
||||||
LD C, A;
|
|
||||||
|
|
||||||
;; add it into IY
|
|
||||||
ADD IY, BC
|
|
||||||
|
|
||||||
vh_end
|
|
||||||
|
|
||||||
;; test if (HL) is 0
|
|
||||||
XOR A
|
|
||||||
CP (HL)
|
|
||||||
|
|
||||||
JR NZ, main_loop
|
|
||||||
|
|
||||||
|
|
||||||
;; mult IY by 100 into hl
|
|
||||||
PUSH IY
|
|
||||||
POP HL
|
|
||||||
|
|
||||||
ADD HL, HL
|
|
||||||
ADD HL, HL
|
|
||||||
PUSH HL ; 4
|
|
||||||
ADD HL, HL
|
|
||||||
ADD HL, HL
|
|
||||||
ADD HL, HL
|
|
||||||
PUSH HL ; 32
|
|
||||||
ADD HL, HL ; 64
|
|
||||||
POP BC
|
|
||||||
ADD HL, BC ; 64 + 32
|
|
||||||
POP BC
|
|
||||||
ADD HL, BC ; 64 + 32 + 4
|
|
||||||
|
|
||||||
;; add in IX
|
|
||||||
PUSH IX
|
|
||||||
POP BC
|
|
||||||
ADD HL, BC
|
|
||||||
|
|
||||||
HALT
|
|
||||||
|
|
||||||
; cool funny function stuff
|
|
||||||
|
|
||||||
.org 0x1000
|
|
||||||
|
|
||||||
start
|
|
||||||
defb 00h
|
|
||||||
end
|
|
||||||
defb 00h
|
|
||||||
count
|
|
||||||
defb 00h
|
|
||||||
|
|
||||||
CHECK_V_MIRROR:
|
|
||||||
; map in (HL)
|
|
||||||
; col in A
|
|
||||||
; width in B
|
|
||||||
; height in C
|
|
||||||
|
|
||||||
LD HL, map
|
|
||||||
LD DE, map
|
|
||||||
|
|
||||||
; A = 2 * col - map.width
|
|
||||||
SLA A ; A = 2 * col
|
|
||||||
PUSH AF ; save 2 * col
|
|
||||||
SUB B ; A = 2 * col - map.width
|
|
||||||
|
|
||||||
ADD A, 2 ; for off by 1 errors or some shit idfk
|
|
||||||
|
|
||||||
; clip it to be 0
|
|
||||||
JP P, v_pos
|
|
||||||
LD A, 0
|
|
||||||
v_pos
|
|
||||||
|
|
||||||
LD HL, map
|
|
||||||
|
|
||||||
LD (start), A ; move 2 * col - map width (start check) into start
|
|
||||||
LD L, A ; and to L for safekeeping
|
|
||||||
|
|
||||||
POP AF ; restore A to 2 * col;
|
|
||||||
SUB L ; A = 2 * col - start
|
|
||||||
INC A ; A = 2 * col - start + 1
|
|
||||||
|
|
||||||
LD (end), A ; store that in end
|
|
||||||
|
|
||||||
SUB L ; A is the difference
|
|
||||||
SRL A ; divide by 2
|
|
||||||
INC A ; + 1
|
|
||||||
|
|
||||||
LD (count), A ; you got the counter for the inner loop
|
|
||||||
v_loop_out
|
|
||||||
|
|
||||||
; move col into B for the counter
|
|
||||||
LD A, (count)
|
|
||||||
LD B, A
|
|
||||||
|
|
||||||
; mov start and end into the registers
|
|
||||||
LD A, (start)
|
|
||||||
LD L, A
|
|
||||||
LD A, (end)
|
|
||||||
LD E, A
|
|
||||||
v_loop_in
|
|
||||||
|
|
||||||
; compare the two characters
|
|
||||||
LD A, (DE)
|
|
||||||
CP A, (HL)
|
|
||||||
|
|
||||||
; return NZ if they're not equal
|
|
||||||
RET NZ
|
|
||||||
|
|
||||||
; next character
|
|
||||||
DEC E
|
|
||||||
INC L
|
|
||||||
|
|
||||||
; :clap: :clap: next meme
|
|
||||||
DEC B
|
|
||||||
JR NZ, v_loop_in
|
|
||||||
vq
|
|
||||||
|
|
||||||
;; go to next line
|
|
||||||
INC H
|
|
||||||
INC D
|
|
||||||
|
|
||||||
DEC C ; dec the loop counter and loop if negative
|
|
||||||
JP NZ, v_loop_out
|
|
||||||
vq2
|
|
||||||
|
|
||||||
XOR A ; set zero flag and return
|
|
||||||
RET
|
|
||||||
|
|
||||||
CHECK_H_MIRROR:
|
|
||||||
; map in (HL)
|
|
||||||
; col in A
|
|
||||||
; width in B
|
|
||||||
; height in C
|
|
||||||
|
|
||||||
LD HL, map
|
|
||||||
LD DE, map
|
|
||||||
|
|
||||||
; A = 2 * col - map.height
|
|
||||||
SLA A ; A = 2 * col
|
|
||||||
PUSH AF ; save 2 * col
|
|
||||||
SUB C ; A = 2 * col - map.height
|
|
||||||
|
|
||||||
ADD A, 2 ; for off by 1 errors or some shit idfk
|
|
||||||
|
|
||||||
; clip it to be 0
|
|
||||||
JP P, h_pos
|
|
||||||
LD A, 0
|
|
||||||
h_pos
|
|
||||||
|
|
||||||
LD (start), A ; move 2 * col - map width (start check) into start
|
|
||||||
LD D, A ; and to L for safekeeping
|
|
||||||
|
|
||||||
POP AF ; restore A to 2 * col;
|
|
||||||
SUB D ; A = 2 * col - start
|
|
||||||
INC A ; A = 2 * col - start + 1
|
|
||||||
|
|
||||||
LD (end), A ; store that in end
|
|
||||||
|
|
||||||
SUB D ; A is the difference
|
|
||||||
SRL A ; divide by 2
|
|
||||||
INC A ; + 1
|
|
||||||
|
|
||||||
LD (count), A ; you got the counter for the inner loop
|
|
||||||
h_loop_out
|
|
||||||
|
|
||||||
; move col into C for the counter
|
|
||||||
LD A, (count)
|
|
||||||
LD C, A
|
|
||||||
|
|
||||||
; mov start and end into the registers
|
|
||||||
LD A, (start)
|
|
||||||
ADD A, 60h
|
|
||||||
LD H, A
|
|
||||||
LD A, (end)
|
|
||||||
ADD A, 60h
|
|
||||||
LD D, A
|
|
||||||
h_loop_in
|
|
||||||
|
|
||||||
; compare the two characters
|
|
||||||
LD A, (DE)
|
|
||||||
CP A, (HL)
|
|
||||||
|
|
||||||
; return NZ if they're not equal
|
|
||||||
RET NZ
|
|
||||||
|
|
||||||
; next character
|
|
||||||
DEC D
|
|
||||||
INC H
|
|
||||||
|
|
||||||
; :clap: :clap: next meme
|
|
||||||
DEC C
|
|
||||||
JR NZ, h_loop_in
|
|
||||||
hq
|
|
||||||
|
|
||||||
; HALT
|
|
||||||
|
|
||||||
;; go to next line
|
|
||||||
INC E
|
|
||||||
INC L
|
|
||||||
|
|
||||||
DEC B ; dec the loop counter and loop if negative
|
|
||||||
JP NZ, h_loop_out
|
|
||||||
hq2
|
|
||||||
|
|
||||||
XOR A ; set zero flag and return
|
|
||||||
RET
|
|
||||||
|
|
||||||
CHECK_MAP:
|
|
||||||
; B is width, C is height
|
|
||||||
|
|
||||||
LD A, B
|
|
||||||
DEC A
|
|
||||||
v_detect_loop
|
|
||||||
|
|
||||||
PUSH AF ; save loop count
|
|
||||||
PUSH BC ; save width + height
|
|
||||||
LD HL, map ; map as input
|
|
||||||
|
|
||||||
CALL CHECK_V_MIRROR;
|
|
||||||
|
|
||||||
JR NZ, v_not_it
|
|
||||||
|
|
||||||
POP BC
|
|
||||||
POP AF ; fix the stack
|
|
||||||
INC A ; for off by one errors
|
|
||||||
OR A ; clear carry, cause it is a vert mirror
|
|
||||||
RET
|
|
||||||
v_not_it:
|
|
||||||
|
|
||||||
POP BC
|
|
||||||
POP AF ; get values back
|
|
||||||
|
|
||||||
DEC A
|
|
||||||
JP P, v_detect_loop
|
|
||||||
|
|
||||||
vcq
|
|
||||||
|
|
||||||
;; load height-1 into A
|
|
||||||
LD A, C
|
|
||||||
DEC A
|
|
||||||
h_detect_loop
|
|
||||||
|
|
||||||
PUSH AF ; save loop count
|
|
||||||
PUSH BC ; save width + height
|
|
||||||
LD HL, map ; map as input
|
|
||||||
|
|
||||||
CALL CHECK_H_MIRROR;
|
|
||||||
|
|
||||||
JR NZ, h_not_it
|
|
||||||
|
|
||||||
POP BC
|
|
||||||
POP AF ; fix the stack
|
|
||||||
|
|
||||||
INC A ; for off by one errors
|
|
||||||
SCF ; carry, cause it is a horiz mirror
|
|
||||||
RET
|
|
||||||
|
|
||||||
h_not_it:
|
|
||||||
|
|
||||||
POP BC
|
|
||||||
POP AF ; fix the stack
|
|
||||||
|
|
||||||
DEC A
|
|
||||||
JP P, h_detect_loop
|
|
||||||
hcq
|
|
||||||
|
|
||||||
LD A, 0xFF;
|
|
||||||
RET
|
|
||||||
|
|
||||||
LOAD_MAP:
|
|
||||||
; hl: address to start of map
|
|
||||||
; out : bc, width; height
|
|
||||||
|
|
||||||
LD BC, 0;
|
|
||||||
LD DE, map ; start of map
|
|
||||||
l_loop:
|
|
||||||
; HALT
|
|
||||||
|
|
||||||
LD A, (hl) ; get character
|
|
||||||
|
|
||||||
;; go to next thing
|
|
||||||
INC HL
|
|
||||||
|
|
||||||
CP A, 0x0A ; check if newline
|
|
||||||
JR NZ, l_not_newline
|
|
||||||
|
|
||||||
;; check E is 0, break if so
|
|
||||||
LD A, E
|
|
||||||
OR A
|
|
||||||
RET Z
|
|
||||||
|
|
||||||
;; set width to this width, increment C
|
|
||||||
LD B, E
|
|
||||||
|
|
||||||
INC C
|
|
||||||
|
|
||||||
;; mov to beginning of next line
|
|
||||||
LD E, 0
|
|
||||||
INC D
|
|
||||||
|
|
||||||
JP l_loop;
|
|
||||||
l_not_newline
|
|
||||||
|
|
||||||
LD (DE), A ; copy character
|
|
||||||
|
|
||||||
; go to next address
|
|
||||||
INC E
|
|
||||||
|
|
||||||
; loop
|
|
||||||
JP l_loop;
|
|
||||||
|
|
||||||
.org 0x6000
|
|
||||||
map
|
|
||||||
DEFM 'fukfukfukfukfukfukfukfukfukfuk'
|
|
||||||
|
|
||||||
.org 0x8000
|
|
||||||
FILE
|
|
||||||
INCBIN "input.txt"
|
|
||||||
DEFB 0
|
|
BIN
z80src/preamble
BIN
z80src/preamble
Binary file not shown.
Loading…
Reference in New Issue
Block a user