2024 day16 (incomplete)
This commit is contained in:
parent
4da51514aa
commit
69febabee8
141
2024/day16/input.txt
Normal file
141
2024/day16/input.txt
Normal file
@ -0,0 +1,141 @@
|
||||
#############################################################################################################################################
|
||||
#.............#...#...........#...#...................#.........#...........#...................................#.............#.......#....E#
|
||||
#.#####.#####.#.#.#.###.#####.#.#.#.#.#########.#####.#.#######.#.#########.#######.###.###.###.#.#######.#.###.#.#########.#.#####.#.#.#.#.#
|
||||
#.#...#...#.#...#.#...#.....#.#.#.#.#.....#.....#...#...#.......#...#.....#.....#...#.#.....#.#.#.#.....#.#...#.#.#.#.......#...#...#.#.#.#.#
|
||||
###.#.#.#.#.###.#.###.#.###.#.#.#.#.#.###.#.#####.#######.#########.###.#######.#.###.#######.#.#.#####.#.###.#.#.#.#.#########.#.###.#.#.#.#
|
||||
#...#.#.#.#...#.....#...#...#...#...#.#.#...#...#.......#.........#...#.........#.#.#.........#.#.......#.#...#.#.#.#.....#.....#.#...#.#.#.#
|
||||
#.###.###.#.###.#########.#####.#####.#.#####.#.#.#.#############.#.#.#####.#####.#.#.###.###.#.###.#####.#.###.#.#.#####.###.###.#.###.#.###
|
||||
#.#.......#.....#.....#...#.....#.....#.......#...#.............#.#.#.....#.#.....#.#...#...#.#.#...#.....#.#.#.#.....#.#...#...#.#.#...#...#
|
||||
#.#########.###.#.#.###.###.###.#.#####.#################.#######.#.#####.#.#.#####.###.###.#.#.###.#.#####.#.#.#####.#.###.###.#.###.#.#.#.#
|
||||
#.#...#.....#.#...#...#.#.#.#.#.#.........#.............#...#.....#.....#.#.#...#...#...#...#.#...#.#.#...#...#...........#.#.............#.#
|
||||
#.#.#.#####.#.#.#####.#.#.#.#.#.#######.#.#.#######.###.###.#.#######.###.#.###.#.#.#.#.#.###.###.###.#.#.###.###########.#.#.#####.###.#.#.#
|
||||
#...#.....#...#...#...#.#.#...#.........#...#.....#...#.#...#...#.#...#...#.....................#...#...#...#.......#...#.#.#.#.......#.#...#
|
||||
#.#######.#####.###.#.#.#.#.#####.#####.#####.###.#####.#.#####.#.#.###.#########.#.#.#.###.#######.#.#.#.#####.#####.#.#.#.###.#.#####.#.###
|
||||
#.#.....#.....#.#...#.#.#...#.....#...#.#.#...#.....#...#.....#.#...#...#.........#.#.....#.#.......#...#.......#.....#.#.#...#...#.....#...#
|
||||
#.#.###.###.#.#.#.###.#.#.###.#####.#.#.#.#.#######.#.#######.#.###.#.###.###########.#.###.#.###########.#######.###.#.#.###.#.#.#.###.#.#.#
|
||||
#...#.#.#...#...#.#...#.#...#.#.....#.#...#.....#.#...#.......#...#.#.#.#.......#.....#...#...#.........#...#.....#.#...#...#.#.#...#.....#.#
|
||||
#####.#.###.#####.#.###.#####.#.###.#.#.#.#####.#.#.#####.###.###.###.#.#.#####.#.#####.#.#.###.#######.#####.#####.#.###.###.#.#.###.#####.#
|
||||
#.....#.....#.....#...#.#.....#...#.#.#.....#.......#...#...#.#...#...#...#.......#.....#.#.#...#.............#.....#.#.#.#...#.#.#...#...#.#
|
||||
#.#########.#.#######.#.#.#########.###.#####.#######.#.###.###.###.###.###.###.#.#.#####.#.#.#.#.#######.###.###.###.#.#.#.###.#.#.###.###.#
|
||||
#.#.......#.#.......#.#...#.......#...#.#.........#...#...#...........#...#.......#.#...#.......#.........#.......#...#...#.....#.......#...#
|
||||
#.#.#.###.#.#######.#######.#####.###.#.#.#.#####.#.#####.#.#########.###.#########.#.#.#.###########.#.###.###.#.#.###.#########.#######.#.#
|
||||
#...#.#...#.#.....#.#.......#.........#.#.#.....#...#.....#...#.....#...#.#...#.....#.#.#...#.......#...#...#...#.....#.....#.......#.....#.#
|
||||
#####.#.###.#####.#.#.###.###.#######.#.#.#####.#.###.#######.#.###.#.#.#.#.###.#.###.#.###.#######.#####.###.###.###.#####.#####.#.#.#####.#
|
||||
#.....#...#.....#.#...#...#...#.......#.#.#.....#.#...#...#...#.#...#.#.....#...#.....#...#.......#.....#...#.#.....#...#.#.........#.....#.#
|
||||
#.#.#######.###.#.#####.###.#.#.#######.#.###.#####.###.#.#####.#.###.#.#####.###.#######.#######.#.#.###.#.#.#########.#.#####.#.#######.#.#
|
||||
#.#.#...........#...#...#...#...#.....#.#...#.......#...#.......#...#.....#...#.#...#...........#.#.#...........#.....#.#.#.....#.........#.#
|
||||
#.#.#.#####.#######.#.#####.#####.###.#.###.#####.###.###########.#.#######.###.#.#.###.#####.###.#.###.#.#.###.#.###.#.#.#.###.#.#########.#
|
||||
#.#.#...............#.....#.#.....#...#...#...#...#...#...#.....#.#...........#.#.#.....#.....#...#.#.#.....#...#...#.....#.#.....#.....#...#
|
||||
#.#.#.#.#.#.#######.#####.#.#.#####.#####.###.#####.#####.#.###.#.#######.###.#.#.#####.#.#####.###.#.#######.#.###.#.#.#.#.#.#.#.###.###.###
|
||||
#.#.#.#.#.#.......#.....#.#.#.....#.......#.#.....#...#...#...#.#.......#.#...#...#.....#.....#.#...#.......#.#...#.#.#.#...#.#.....#.......#
|
||||
#.###.#.###.#####.#######.###.#.###########.#.#.#.###.#.#####.#.###.#####.#.###.###.###.#######.#.#.#####.#.#.#####.#.#.#####.#.###.#######.#
|
||||
#.....#...#.....#...#...#...#.#.#.....#.....#...#...#.#.#.....#...#.#.....#.#.....#.#...#.....#.#...#...#.#.#.......#.........#...#.......#.#
|
||||
#.#######.#.###.###.#.#.###.#.#.#.#.###.#.#.#####.###.#.#.#######.#.#.###.#.#####.#.###.#.###.#.#.###.#.#.#.#######.#########.#.#.#######.###
|
||||
#.....#...#.....#.#...#...#.#.#.#.#.....#.#...#...#...#.#.....#.#.#.#...#.#...#...#...#.#.#...#.#.#...#.#.#...#...#.#.....#.............#...#
|
||||
#####.#.#.#.#####.#######.#.#.#.#.#######.###.#.###.###.#####.#.#.###.#.#####.#######.###.#.###.#.#.###.#.###.#.#.###.###.#.###.###.#######.#
|
||||
#.#...#.#.#.#...#...........#.#...#...#.#...#.#...#...#...#.#...#...#.#.#...#.#.....#.#...#.....#...#.....#...#.#.....#.#.#.......#.#.....#.#
|
||||
#.#.###.#.#.###.#.###########.#.###.#.#.###.#.###.###.#.#.#.#.#.###.###.#.#.#.#.###.#.#.#############.#########.#######.#.###.#.###.#.###.#.#
|
||||
#...#...#.#.#...#.#...........#.....#.#.#...#...#...#...#.#.#.#...#.#...#.#.....#.....#.#...#.........#.........#.......#...#.#.....#.#...#.#
|
||||
#.###.#.###.#.###.#.#######.#.#######.#.#.#####.###.#####.#.#.#.###.#.#.#.#######.###.#.#.#.#####.#####.#########.#####.###.#.#.#####.#.###.#
|
||||
#...#.#...#.#.....#.#.....#...#...#...#.#.#.#.....#...#...#.#.#...#.#.#.#...#.......#.#...#.....#...#...#.....#...#...#...#.....#.....#.#...#
|
||||
###.#.###.#.#######.#.#########.#.###.#.#.#.#.###.#.###.###.#.#.#.#.#.#.###.#.#####.#####.#####.#.#.#.#####.#.#.#.#.#.###.###.#.#.#####.###.#
|
||||
#...#.#...#.........#...........#...#...#.#.......#.....#...#.#.#.....#.#...#.....#.#...#.#.........#.#.....#.#.#...#.....#...#.#.#...#.....#
|
||||
#.#.#.#.#########.#######.#########.###.#.#.#####.#######.###.###########.#######.#.#.#.###.#####.#.#.#.#####.#.#.#.#######.#.#.#.#.#.#####.#
|
||||
#.#...#.#...............#.....#...#.#.#.#.#...#.#...#.......#...#.........#.#...#.#...#.....#...#...#.#.#...#.#.#.#...#.#...#.#.#...#.#.#...#
|
||||
#.#.###.#.#######.#####.#.###.#.#.#.#.#.#.#.#.#.###.###.###.###.#.#########.#.#.#.#####.#####.#.#####.#.#.#.#.###.###.#.#.#####.###.#.#.#.###
|
||||
#.#...#...#.......#...#.#.#...#.#.#.#...#.#.#.....#...#.#...#...#...#.#.......#.#...#...#.....#.........#.#.#.....#.......#...#.#.........#.#
|
||||
#.#.#######.#########.#.#.#.#####.#.###.#.#.#####.###.#.#.#.#.#.###.#.#.#######.###.#####.#########.#####.#.#######.#####.#.#.#.#.#.###.###.#
|
||||
#.#.#.....#.....#.....#.#.#.....#.#...#.#.#.....#.#...#...#.#.#.#...#.....#.....#...#...#.#...#.....#.....#...#.....#...#...#...#.....#.#...#
|
||||
#.#.#.#.#.#####.#.#####.#.#####.#.#.#.#.#.#.###.###.#######.#.#.#.###.###.#.###.#.#.#.#.#.#.#.#.###.#######.#.#.#####.#.###########.#.#.#.#.#
|
||||
#.#.#.#.................#.....#.#.#...#.#.#...#.....#.......#.#.#.#.....#.#.#...#.#.#.#...#.#.#.............#.#.#...#.#.........#.....#.#.#.#
|
||||
#.#.#.#.#########.###.###.#####.#.#.#####.#.#####.###.#.#.###.###.#.#.#.###.#.###.###.#####.#.#.#.#############.###.#.#######.#.#.#.###.#.#.#
|
||||
#.#.#.....#.....#.#.......#.....#.#.#.....#.#...#.....#...#...#...#.#.#.#...#...#.....#.....#.#...#...........#.#...#.#.....#.............#.#
|
||||
#.#.###.#.###.###.###.#.###.#####.#.#.#######.#.#######.###.#.#.#####.#.#.#####.###########.#.#.###.#########.#.#.###.#.#.#.#.###.#.#.###.#.#
|
||||
#.#.....#.......#...#...#.#.#.....#.#.#...#...#.......#...#.#.........#.#...#.#...#.........#.#.........#...#.#.#...#.#.#.#.#...#.#.#...#.#.#
|
||||
#.#.###.###.###.#.#.###.#.#.###.#.#.#.#.#.#.#######.#.###.#.###.###.###.###.#.#.#.###.#######.#######.###.#.#.#.###.#.#.#.#.###.#.#.#.###.#.#
|
||||
#.#...#.....#...#.#...#...#.#...#.#.#...#.#.......#.....#.#.#...#...#.#.........#...#.#.......#.....#.#...#.#.....#.#...#.#...#...#.#.....#.#
|
||||
#.#.#.#.#####.#.#.###.#####.#.#####.#.###.#######.#.#.###.#.#.###.###.#########.###.#.#.#######.###.#.#.###.#####.#.#####.#.#######.#.#####.#
|
||||
#.#.#.#.#.....#.....#.......#.#.....#...#...#...#.#.#.....#.#.#...#.....#.........#...#...#.....#.#.#...#.#...#.......#...#.................#
|
||||
#.#.#.#.#####.###############.#.#######.#.#.###.#.#.###.###.#.#.#######.#.#.###########.###.#####.#.###.#.###.#########.#############.#######
|
||||
#...#.#.....#...#.......#...#...#.......#.#...#.#.#...#.#.....#.#.......#.#.#.......#...#...#.....#...#.#...#.................#.....#.......#
|
||||
###.#.#.###.#.#.#.#.###.###.#.#######.###.###.#.#.###.###.###.#.###.#.###.#.#.#.#.#.#.###.###.#######.#.#.#.#########.###.###.#.###.#.#####.#
|
||||
#...#.#.#.#.#.#...#...#.....#.#.....#.#...#.#.#.#.#.#...#.#...#...#.......#...#...#.#.#.#.#.........#.#.#.#.#.......#.....#.#...#.#.#...#.#.#
|
||||
#.#.#.#.#.#.#########.#####.#.#.###.###.###.#.#.#.#.###.#.#.#####.#.###########.###.#.#.#.###.#.#.#.#.#.###.#.#.###.###.#.#.#####.#.#.#.#.#.#
|
||||
#.#.#.#...#.#.......#...#...#...#.#...#.#.......#...#.#.#...#.....#.#...#.....#.....#.#.#...#.#...#...#...#.#.#.#.#.#.#.#.#.......#.........#
|
||||
#.###.###.#.#.#####.#.#.#.#######.#.#.#.###########.#.#.#####.#####.###.#.#.#####.###.#.###.###.#######.#.#.#.#.#.#.#.#.#.###.###.###.#.###.#
|
||||
#.............#.#...#.#.#.#...#.....#.#...........#.#.#...........#...#...#.#...#.......#.#...#.........#.#...#.#.....#.#.#.................#
|
||||
#.#####.#.###.#.#.###.#.#.#.#.#.###.#.###.#####.###.#.#########.#.###.#####.#.#.#######.#.###.###.#####.#.#.###.#######.#.#.###.###.#####.#.#
|
||||
#.#.....#.....#...#...#.#.#.#.#...#.#...#.#...#.#...#.....#.......#.#...#...#.#...#...#.....#.#.......#.#.#...#.....#...#.#.#...#.......#.#.#
|
||||
#.#.#####.#.###.#######.#.#.#####.#.###.#.#.#.#.#.###.#####.#######.###.#.###.###.#.#.#######.#######.###.###.#####.#.###.#.#.#####.###.#.#.#
|
||||
#.............#.#...#.....#.....#.#.....#.#.#.#.#.#...#.....#.............#...#.#...#...#...#.......#...#.#...#...#.#.#.#...#.....#...#.#.#.#
|
||||
###.#.###.###.#.#.#.#.###.#.#.#.#.#######.#.#.#.#.#.#.#.#####.#############.###.#######.#.#.#######.###.#.#.###.###.#.#.#########.#.###.#.###
|
||||
#...#...#...#.....#.#...#.#.#.#...#.....#...#.#.....#.#...#.#.#...#.....#...#.......#.#...#.#.......#.....#...#...#...#.....#...#.#.....#...#
|
||||
#.###.#.#.###.#####.###.#.###.#.#.#.###.#####.###########.#.#.#.###.#####.#.#.###.#.#.#####.#.#######.#######.###.#######.###.#.#.#.#######.#
|
||||
#...#.#...#...#...#.#...#...#.#.#.#.#.#...#.#.#.....#.....#.#.#.#...#.....#.....#.#...#...#.#.#.....#.........#...........#...#...#.....#...#
|
||||
###.#.###.#.#####.#.#.#####.#.###.#.#.###.#.#.#.###.#.#####.#.#.#.###.###.#######.###.#.#.#.#.#.###.#.###.#.#.#.#######.###.#######.###.#.###
|
||||
#...#...#.#.#...#.#.#.#.#...#...#...#.....#...#.#.#...#.#...#...#.#.#.#.#...#.....#.#.#.#.#.#.#.#...#.#...#.#.#.#.......#...#.#.........#...#
|
||||
#.#####.#.#.#.#.#.#.#.#.#.#####.#####.#####.###.#.#####.#.#.#.###.#.#.#.###.#.#####.#.#.#.#.#.#.###.#.#.###.#.#.#########.###.#.#.#.###.###.#
|
||||
#.#.......#.#.#...#.#.#.#.#.....#...#.....#...#.#.........#...#...#.......#.#...#.......#.#...#.......#...#.#.#...........#...#.#.#...#.#...#
|
||||
#.#.#####.#.#.#####.#.#.#.###.#.#.#######.###.#.#.#####.#######.#.#######.#.###.###############.#########.#.#.###.###########.#.#.#.#.#.#.#.#
|
||||
#.#.#.......#...#...#.#.#.#...#...#...#...#...#.#.......#...#.#.#...#.....#.#...#...............#.#...#...#.#...#.#.........#...#.#.#...#...#
|
||||
#.#.#.#######.#.#.###.#.#.#.###.###.#.#.#######.#.#######.#.#.#.#.#.###.###.#.###.#########.#####.#.#.#.#######.#.#.#.#####.#.###.#.#######.#
|
||||
#.#.#...#.....#.......#...#...#.#...#...#.......#.........#...#...#...#.#...#...............#.....#.#...#...#.......#.#...#.#.#...#...#...#.#
|
||||
#.#.###.#################.###.#.#.#######.#.#######.#################.#.#.###.#######.#####.#.###.#.#####.#.#.#########.#.#.###.###.###.#.#.#
|
||||
#.#.#.#.....#.....#.....#.....#.#.....#.#.#.#.#.....#...#.........#...#.#.#...#...#.#.....#.#...#.#.......#.#.....#.....#.#.#...#...#...#...#
|
||||
#.#.#.#####.#.###.#.###.#####.#######.#.#.#.#.#.#####.#.#.#######.#.###.#.#####.#.#.#.###.#.#.#.###########.#####.#.#####.#.#.###.###.#####.#
|
||||
#.....#...#.......#...#.......#.......#...#.#.....#...#...#.......#.#...#.#.....#.#.#...#.#.#.#.......#...#...#.#...#...#.#...#.....#...#...#
|
||||
#.#####.#.#######.#.###.#######.###########.#.#####.#######.#####.#.#####.#.#####.#.#.###.#.#.#######.#.#.#.#.#.#####.#.#.#########.###.#.#.#
|
||||
#...#...#...#.....#.#...#.....#.....#.......#.#.#...#...#...#.....#.......#...#.#.#...#...#.#...#.....#.#...#...#.....#.#.....#.......#.....#
|
||||
#####.#.###.#.#.###.#.#.#.###.#####.#.#######.#.#.#####.#.###.#############.#.#.#.#.###.#.#.###.#.#.#.#.#######.#.#####.#.###.#.###.#.#.#.#.#
|
||||
#...#.#.....#.#.#...#.#.#.#.#.#.....#...........#.#.....#.#.#.#.............#.#.#.#...#.#.#.#...#.#.#.#.......#.#.#.........#.#.#.......#...#
|
||||
#.#.#.#.#####.###.###.#.#.#.#.#.#####.###.###.#.#.#.###.#.#.#.###.#######.###.#.#.#####.#.#.###.#.#.#.#.#.#.#.#.###.#######.#.#.###.#######.#
|
||||
#.#...#.......#...#...#.#...#.#.....#.#.#.....#...#...#...#.#...#.#...#.......#...#.....#.#...#.#.#.....#...#.#.....#.....#.#.#.........#...#
|
||||
#.#####.#.###.#.###.#.#####.#.#####.#.#.#####.###.###.###.#.###.#.#.#.#.#######.###.#########.###.#####.#####.###########.#.#.#####.###.#.#.#
|
||||
#.#...#.....#.#...#.#.#...#.#.....#.#.#.....#.#...#...#...#.#...#.#.#.#.......#.#...#.......#.#...#.#...#...#.#.........#...#.........#.#...#
|
||||
#.#.#.#.#.###.###.#.#.#.#.#.#.###.#.#.#.###.#.#.###.###.###.#.#####.#.#.#.#.#.#.#.#.#.###.#.#.#.###.#.#.###.#.#.#######.#.#########.#.#.#.#.#
|
||||
#.#.#...#.#.....#.#.....#...#...#.#.#...#...#...#...#...#...#.......#...#.#...#.#.#.#.#...#.#.#...#...#.....#.....#.....#...#.......#...#.#.#
|
||||
#.#.###.#.#.#####.#############.#.#.#######.#####.#.#.###.#############.#.#.###.#.#.#.#.#.###.###.#.###.#.#.#######.#######.###.#.#.#######.#
|
||||
#.#.#...#...#.....#.....#.....#.#.#...#...#.......#.#...#...#.........#...#.....#.#.#...#...#.....#.#...#.#.#.......#.....#...#.#.........#.#
|
||||
#.#.#.###.###.#####.###.###.#.#.#####.#.#.#########.###.###.#.#####.#.#####.#####.#.#.#.###.#######.#####.#.#.#.#####.#######.###.#.###.#.#.#
|
||||
#.#.#.#.#.#.#.#.......#.....#.#.....#...#.#.......#...#...#.#...#...#...#...#.....#.#...#.#...#...#.#...#.#.#.#.#...........#...#.#.....#...#
|
||||
#.#.#.#.#.#.#.#.#####.###.#########.#####.#.###.###.#####.#.#.#.#.#######.###.#####.###.#.###.#.#.#.#.#.#.#.#.#.#.#######.#####.#.#.#######.#
|
||||
#.#.........#.#.....#.#...#.......#.#.....#...#.....#.....#.....#.....#...#...#...#...#...#.#...#.#...#.#.#...#.#.....#...#.....#.#...#.#...#
|
||||
#.#.#.###.#.#.###.###.#.###.###.###.#.#####.#########.#.#####.#######.#.###.###.#.#.#####.#.#####.#####.#.###.#.#####.#.###.#####.###.#.#.###
|
||||
#...#.................#.#...#...#...#.....#.#.......#.#.#...#.....#...#.#.....#.#.#.....#.#.......#...#...#...#.#.....#.#...#...#.#.#.#.....#
|
||||
#.#####.#####.#.###.#####.###.###.#.#####.###.#####.#.###.#.#####.#.#.#.#####.#.#######.#.###.#.#.#.#.#.#######.#######.#.###.#.#.#.#.#######
|
||||
#...#.#.#...#.#...#.........#.....#.....#...#...#...#.....#...#.....#.#...#...#.......#.#.#...#.#...#...#.......#.......#.#...#.#...#.#.....#
|
||||
###.#.#.#.#.#.###.###########.#.#####.#####.###.#.###########.#.#.#######.#.###.#.###.#.#.#.#.#########.#.#######.#####.#.###.#.#####.#.###.#
|
||||
#...#.#...#.#...#.#.........#.#.#...#.#.....#...#.......#...#.#...#...#.........#...#.#...#.#.#...#...#.#.#...#.....#...#.....#...#...#...#.#
|
||||
#.###.#####.###.###.###.#.#.#.#.#.#.#.#.#####.#########.#.#.#.#.###.#.#.#######.###.#######.###.#.#.#.#.#.#.#.#.###.#############.#.###.###.#
|
||||
#.#...#.....#...#...#...#.#...#.#.#...#.......#.....#...#.#...#...#.#...#.....#...#.#.....#.....#.#.#...#.#.#.#.#...#.....#.....#.#.....#...#
|
||||
#.###.#.###.#.###.#####.#.###.#.###############.###.#.###.#####.#.#.#######.#####.#.#.#.#.#######.#.###.#.#.###.#.###.###.#.###.#.#####.#.###
|
||||
#.....#.#...#...#.#...#.#...#.#.#...........#.....#.#.#...#.....#...#.......#...#.....#.#.....#...#...#.#.#.#...#.....#.#.#.#.#.#.....#.#...#
|
||||
#.#.#.#.###.###.#.#.#.#.###.###.#.###.###.#.#######.#.###.#.###.#####.###.###.#.#.#####.#####.#.#.###.#.#.#.#.#########.#.#.#.#.#####.###.#.#
|
||||
#...#.#...#.....#.#.#.#.....#...#.......#.#.........#...#.#...#...#.....#.....#.....#...#.#.....#.#...#...#.#.....#.....#...#.#.....#...#.#.#
|
||||
#####.###.#.#.###.#.#.#######.#########.#.#######.#####.#.###.#.#.#######.#######.#.#.###.#.#.#.#.#.#######.#####.#.###.#####.#.###.###.###.#
|
||||
#.#.....#.#.#...#.#.#.........#.......#.#.#.....#.#...#.#...#...#.#.....#.#.......#...#.#.......#.#.#...#.......#...#...#.....#...#...#...#.#
|
||||
#.#.#.###.#.###.#.#.###.#####.#.#.#####.#.#.###.###.#.#.#.#.#####.#.###.###.#####.###.#.#.#########.#.#.#.###.#######.#.#.###.###.#######.#.#
|
||||
#...#.....#...#...#.....#...#.#.#.......#.#...#.#...#.....#.#.....#...#.....#...#.#.......#...#.....#.#.#...#.......#...#.#.#...#...#...#.#.#
|
||||
#.###.###########.###.#.#.#.#.#.#########.###.#.#.#.#######.#.#######.#######.#.#.#########.#.#.#####.#.###.#.###.#.###.#.#.###.###.#.#.#.#.#
|
||||
#.#.#.....#.......#.#.#.#.#.#.#.......#.....#.#...#...#.....#.#.....#.....#...#.#...........#.#...#...#...#.#...#.#.#...#.#.#...#.#...#.#...#
|
||||
#.#.#####.#.#####.#.#.###.#.#######.#.#.#####.#####.#.###.###.#.###.###.#.#.###.#############.###.#######.#.#.#.#.#.#.###.#.#.###.#####.###.#
|
||||
#...#...#.#...#.....#.....#.......#.........#.#.....#.#...#.#.#...#...#.#.....#.......#.....#...#...........#.#...#.#.#...#.#.#.......#.....#
|
||||
###.#.#.#.###.#.###.#############.#.#######.#.#####.#.#.###.#.###.###.#.#########.###.#.#.#####.#.#####.#.###.#####.#.#.###.#.#.###.#########
|
||||
#...#.#.#.#...#.#...#...........#.#.....#.......#...#...#...#...#.#.#.#...#.#.........#.#.......#...#...#.#.#.....#...#...#...#.#...#.....#.#
|
||||
#####.#.#.#.###.#.###.###.#####.#.#####.#.#####.#.#.#####.#####.#.#.#.###.#.#.###########.###########.###.#.#####.#.#####.###.###.###.#.#.#.#
|
||||
#...#.....#.#...#.....#...#...#.#.....#.#.#.....#.#.....#.....#...#...#.#.#.#...........#.................#...#...#.....#...#...#.....#.#.#.#
|
||||
#.#.#.###.#.#.#.#######.###.#.#######.#.#.#.#####.#.#.#.#.###.#####.###.#.#.#########.#.#######.#.#####.#.###.#.#.#####.#.#.###.#######.#.#.#
|
||||
#.#...#.....#.#.....#...#...#.........#.#...#.....#...#...#...........................#...#...#.#.#...#.....#.#.....#...#.#...#.....#...#.#.#
|
||||
#.###.#.#.###.#.###.#.###.#.#########.#.#.###.#####.#####.#.#.#.###.#.#.###.#.#######.###.#.###.#.#.#.###.#.#.#.###.#.#.#.###.#####.#.###.#.#
|
||||
#...#.#.....#.#...#.#.#...#.#...#...#.#...#.......#...#.#...#.#.#...#.#...#.#.....#...#...#.....#...#...#.....#.#...#.#.....#.....#.#.#.....#
|
||||
#.#.#.###.#.#.#.#.#.###.###.#.#.#.#.#.###.#######.#.#.#.#.#.#.#.#.#######.#.#####.#.#.#.###.#####.#####.#.#####.#.#.#.#.#######.#.#.#.#.###.#
|
||||
#.#.#.....#.#...#.#.....#.#.#.#...#.#...#...#.....#...#...#...#.#.......#.......#.#.#...#...#.........#.....#...#.#...#.#.....#.#.#.#.....#.#
|
||||
#.#.#####.#.#.#.#.#######.#.#.#####.#####.#.#.#####.###.#.#.###.#######.#.#.#####.#.#.###.###########.#####.#.#.###.#.#.#.###.###.#.###.#.#.#
|
||||
#.#.#...#.#.#.#.#...#.......#.....#.......#.#.#.....#...#.#.......#...#...#.#...........................#...#.#.....#...#...#.#...#.......#.#
|
||||
###.#.#.#.#.#.#.###.###########.#.#####.#.#.#.#.#.#.###.#.#.#####.#.#.###.###.#####.###.#.#.###.#.#.###.#.###.#.###.#.#####.#.#.#######.###.#
|
||||
#...#.#.....#.#...#.#...........#.#...#.....#.#.#.#...#.........................#.#.#...#...#...#.#.....#.#.....#...........#.#...#.#...#...#
|
||||
#.#.#.###.#####.#.#.#.#######.###.#.#########.#.###.#.###.#.#####.#.#.###.#.#.#.#.#.#.#######.#########.#.###.###.#.#.#######.###.#.#.#.#.###
|
||||
#.#.#.#...#.....#.#.#.#.....#.#...#...........#...#.........................#.#.#...#.#.#...#.#.............#...#.......#...#.....#...#.....#
|
||||
#.###.#.#.#.#####.#.#.#####.#.#.###########.###.#.#.###.#.#.###.###.#.#.#.#.###.#.###.#.#.#.#.#.#.#.#.#####.###.###.#.#.#.#.#######.###.#.#.#
|
||||
#S......#...#.....#.........#...............#...#.....#.......#.....#...#.......#.....#...#.....#...#.......#...........#.#.................#
|
||||
#############################################################################################################################################
|
15
2024/day16/input.txt.h
Normal file
15
2024/day16/input.txt.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_2024_day16_input_txt_start __asm("_binary_2024_day16_input_txt_start");
|
||||
extern uint32_t _binary_2024_day16_input_txt_end __asm("_binary_2024_day16_input_txt_end");
|
||||
extern uint32_t _binary_2024_day16_input_txt_size __asm("_binary_2024_day16_input_txt_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
17
2024/day16/sample1.txt
Normal file
17
2024/day16/sample1.txt
Normal file
@ -0,0 +1,17 @@
|
||||
#################
|
||||
#...#...#...#..E#
|
||||
#.#.#.#.#.#.#.#.#
|
||||
#.#.#.#...#...#.#
|
||||
#.#.#.#.###.#.#.#
|
||||
#...#.#.#.....#.#
|
||||
#.#.#.#.#.#####.#
|
||||
#.#...#.#.#.....#
|
||||
#.#.#####.#.###.#
|
||||
#.#.#.......#...#
|
||||
#.#.###.#####.###
|
||||
#.#.#...#.....#.#
|
||||
#.#.#.#####.###.#
|
||||
#.#.#.........#.#
|
||||
#.#.#.#########.#
|
||||
#S#.............#
|
||||
#################
|
15
2024/day16/sample1.txt.h
Normal file
15
2024/day16/sample1.txt.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_2024_day16_sample1_txt_start __asm("_binary_2024_day16_sample1_txt_start");
|
||||
extern uint32_t _binary_2024_day16_sample1_txt_end __asm("_binary_2024_day16_sample1_txt_end");
|
||||
extern uint32_t _binary_2024_day16_sample1_txt_size __asm("_binary_2024_day16_sample1_txt_size");
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
109
2024/day16/solution.c
Normal file
109
2024/day16/solution.c
Normal file
@ -0,0 +1,109 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdio.h>
|
||||
//#include "printf.h"
|
||||
#include "dijkstra.h"
|
||||
#include "memory.h"
|
||||
|
||||
static void parse_sewh(const char * input, int length,
|
||||
int * stride,
|
||||
int * width, int * height,
|
||||
int * start_x, int * start_y,
|
||||
int * end_x, int * end_y
|
||||
)
|
||||
{
|
||||
const char * end = input + length;
|
||||
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
|
||||
while (input < end) {
|
||||
char c = *input++;
|
||||
|
||||
switch (c) {
|
||||
case 'S':
|
||||
*start_x = *width;
|
||||
*start_y = *height;
|
||||
break;
|
||||
case 'E':
|
||||
*end_x = *width;
|
||||
*end_y = *height;
|
||||
break;
|
||||
}
|
||||
|
||||
*width += 1;
|
||||
|
||||
if (c == '\n') {
|
||||
*stride = *width;
|
||||
*width = 0;
|
||||
*height += 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
*width = *stride - 1;
|
||||
}
|
||||
|
||||
int64_t _2024_day16_part1(const char * input, int length)
|
||||
{
|
||||
int stride;
|
||||
int width;
|
||||
int height;
|
||||
int start_x;
|
||||
int start_y;
|
||||
int end_x;
|
||||
int end_y;
|
||||
|
||||
parse_sewh(input, length,
|
||||
&stride,
|
||||
&width, &height,
|
||||
&start_x, &start_y,
|
||||
&end_x, &end_y
|
||||
);
|
||||
|
||||
struct dijkstra_xy16 prev[width * height];
|
||||
int dist[width * height];
|
||||
|
||||
dijkstra_cartesian(input,
|
||||
stride,
|
||||
width, height,
|
||||
start_x, start_y,
|
||||
end_x, end_y,
|
||||
'#',
|
||||
prev,
|
||||
dist);
|
||||
|
||||
char map[stride * height + 1];
|
||||
memory_copy_char(input, stride * height, map);
|
||||
|
||||
int x = end_x;
|
||||
int y = end_y;
|
||||
while (!(x == start_x && y == start_y)) {
|
||||
struct dijkstra_xy16 * xy = &prev[y * width + x];
|
||||
map[xy->y * stride + xy->x] = 'x';
|
||||
x = xy->x;
|
||||
y = xy->y;
|
||||
}
|
||||
map[stride * height] = 0;
|
||||
printf("%s", map);
|
||||
|
||||
return dist[end_y * width + end_x];
|
||||
}
|
||||
|
||||
int64_t _2024_day16_part2(const char * input, int length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
FILE * f = fopen("2024/day16/input.txt", "rb");
|
||||
const int length = 20022;
|
||||
char buf[length];
|
||||
size_t len = fread(buf, 1, length, f);
|
||||
assert(len == length);
|
||||
fclose(f);
|
||||
printf("%ld\n", _2024_day16_part1(buf, length));
|
||||
}
|
3
aoc.mk
3
aoc.mk
@ -8,7 +8,8 @@ OBJ = \
|
||||
array.o \
|
||||
memory.o \
|
||||
heap.o \
|
||||
linear_algebra.o
|
||||
linear_algebra.o \
|
||||
dijkstra.o
|
||||
|
||||
DREAMCAST_OBJ = \
|
||||
runner_dreamcast.o \
|
||||
|
75
bfs.c
Normal file
75
bfs.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "memory.h"
|
||||
#include "cartesian.h"
|
||||
#include "bfs.h"
|
||||
|
||||
struct queue_descriptor {
|
||||
int start;
|
||||
int end;
|
||||
};
|
||||
|
||||
struct position {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
};
|
||||
|
||||
static inline void queue_append(struct position * queue,
|
||||
struct queue_descriptor * qd,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
queue[qd->end].x = x;
|
||||
queue[qd->end].y = y;
|
||||
qd->end += 1;
|
||||
}
|
||||
|
||||
static inline struct position * queue_pop(struct position * queue,
|
||||
struct queue_descriptor * qd)
|
||||
{
|
||||
struct position * position = &queue[qd->start];
|
||||
qd->start += 1;
|
||||
return position;
|
||||
}
|
||||
|
||||
void bfs(const char * graph,
|
||||
int stride,
|
||||
int width, int height,
|
||||
int start_x, int start_y,
|
||||
char wall,
|
||||
struct cartesian_link * path)
|
||||
{
|
||||
struct position queue[width * height];
|
||||
struct queue_descriptor qd;
|
||||
qd.start = 0;
|
||||
qd.end = 0;
|
||||
|
||||
memory_set_int((int *)path, -1, width * height);
|
||||
path[start_y * width + start_x].parent_x = start_x;
|
||||
path[start_y * width + start_x].parent_y = start_y;
|
||||
|
||||
queue_append(&queue, &qd, start_x, start_y);
|
||||
|
||||
while (qd.start != qd.end) {
|
||||
struct position * p = queue_pop(&queue, &qd);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int nx = p->x + cartesian_neighbor[i].x;
|
||||
int ny = p->y + cartesian_neighbor[i].y;
|
||||
// ignore all edges that are outside the graph
|
||||
if (!cartesian_inside(width, height, nx, ny))
|
||||
continue;
|
||||
// ignore all edges that are walls
|
||||
if (graph[ny * stride + nx] == wall)
|
||||
continue;
|
||||
// ignore all edges that were previously visited
|
||||
if (path[ny * width + nx].parent_x != -1)
|
||||
continue;
|
||||
|
||||
path[ny * width + nx].parent_x = p->x;
|
||||
path[ny * width + nx].parent_y = p->y;
|
||||
|
||||
queue_append(&queue, &qd, nx, ny);
|
||||
}
|
||||
}
|
||||
}
|
23
bfs.h
Normal file
23
bfs.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bfs(const char * graph,
|
||||
int stride,
|
||||
int width, int height,
|
||||
int start_x, int start_y,
|
||||
char wall,
|
||||
struct cartesian_link * path);
|
||||
|
||||
struct bfs_cartesian_link {
|
||||
int16_t parent_x;
|
||||
int16_t parent_y;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
70
dijkstra.c
Normal file
70
dijkstra.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include "cartesian.h"
|
||||
#include "dijkstra.h"
|
||||
#include "heap.h"
|
||||
#include "memory.h"
|
||||
//#include "printf.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
void dijkstra_cartesian(const char * graph,
|
||||
int stride,
|
||||
int width, int height,
|
||||
int start_x, int start_y,
|
||||
int end_x, int end_y,
|
||||
char wall,
|
||||
struct dijkstra_xy16 * prev,
|
||||
int * dist)
|
||||
{
|
||||
struct heap_entry queue[width * height / 2 + 1];
|
||||
int queue_length = 0;
|
||||
|
||||
// initialize all distances to the maximum distance
|
||||
memory_set_int(dist, 0x7fffffff, width * height);
|
||||
// initialize the distance from the start to the start to zero
|
||||
dist[start_y * width + start_x] = 0;
|
||||
|
||||
// initialize the all node paths to "unknown"
|
||||
memory_set_int((int *)prev, -1, width * height);
|
||||
prev[start_y * width + start_x] =
|
||||
(struct dijkstra_xy16){start_x - 1, start_y}; // west
|
||||
|
||||
// initialize the queue with "start"
|
||||
heap_append_xy(queue, &queue_length, 0, start_x, start_y);
|
||||
|
||||
while (queue_length > 0) {
|
||||
struct heap_entry min = heap_extract_max(queue, &queue_length);
|
||||
//if (min.x == end_x && min.y == end_y)
|
||||
//return;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int nx = min.x + cartesian_neighbor[i].x;
|
||||
int ny = min.y + cartesian_neighbor[i].y;
|
||||
if (!cartesian_inside(width, height, nx, ny))
|
||||
continue;
|
||||
if (graph[ny * stride + nx] == wall)
|
||||
continue;
|
||||
//if (prev[ny * width + nx].x != -1)
|
||||
//continue;
|
||||
int turn = 0;
|
||||
struct dijkstra_xy16 * xy = &prev[min.y * width + min.x];
|
||||
int dx = min.x - xy->x;
|
||||
int dy = min.y - xy->y;
|
||||
if (min.y == 137) {
|
||||
printf("xy % 2d % 2d pxy % 2d % 2d nxy % 2d % 2d dist %d\n",
|
||||
min.x, min.y,
|
||||
xy->x, xy->y,
|
||||
nx, ny,
|
||||
dist[min.y * width + min.x]);
|
||||
}
|
||||
if (cartesian_neighbor[i].x != dx || cartesian_neighbor[i].y != dy)
|
||||
turn = 1000;
|
||||
|
||||
int alt = dist[min.y * width + min.x] + 1 + turn;
|
||||
if (alt < dist[ny * width + nx]) {
|
||||
prev[ny * width + nx] = (struct dijkstra_xy16){min.x, min.y};
|
||||
dist[ny * width + nx] = alt;
|
||||
heap_append_xy(queue, &queue_length, -alt, nx, ny);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
dijkstra.h
Normal file
25
dijkstra.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dijkstra_xy16 {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
};
|
||||
|
||||
void dijkstra_cartesian(const char * graph,
|
||||
int stride,
|
||||
int width, int height,
|
||||
int start_x, int start_y,
|
||||
int end_x, int end_y,
|
||||
char wall,
|
||||
struct dijkstra_xy16 * prev,
|
||||
int * dist);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
48
heap.c
48
heap.c
@ -1,4 +1,5 @@
|
||||
#include "heap.h"
|
||||
#include "memory.h"
|
||||
|
||||
void heap_sift_up(struct heap_entry * e, int ix)
|
||||
{
|
||||
@ -16,6 +17,31 @@ void heap_sift_up(struct heap_entry * e, int ix)
|
||||
}
|
||||
}
|
||||
|
||||
void heap_sift_down(struct heap_entry * e, int heap_length, int ix)
|
||||
{
|
||||
while (true) {
|
||||
int child_l = 2 * ix + 1;
|
||||
int child_r = 2 * ix + 2;
|
||||
if (child_l >= heap_length)
|
||||
break;
|
||||
|
||||
int child = child_l;
|
||||
if (child_r < heap_length && e[child_l].key < e[child_r].key) {
|
||||
child = child_r;
|
||||
}
|
||||
|
||||
if (e[ix].key < e[child].key) {
|
||||
// swap child and ix
|
||||
struct heap_entry tmp = e[child];
|
||||
e[child] = e[ix];
|
||||
e[ix] = tmp;
|
||||
ix = child;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void heap_append(struct heap_entry * e, int * heap_length, int key, int value)
|
||||
{
|
||||
int ix = *heap_length;
|
||||
@ -25,6 +51,16 @@ void heap_append(struct heap_entry * e, int * heap_length, int key, int value)
|
||||
(*heap_length) += 1;
|
||||
}
|
||||
|
||||
void heap_append_xy(struct heap_entry * e, int * heap_length, int key, int x, int y)
|
||||
{
|
||||
int ix = *heap_length;
|
||||
e[ix].key = key;
|
||||
e[ix].x = x;
|
||||
e[ix].y = y;
|
||||
heap_sift_up(e, ix);
|
||||
(*heap_length) += 1;
|
||||
}
|
||||
|
||||
int heap_find(struct heap_entry * e, int length, int ix, int key)
|
||||
{
|
||||
if (e[ix].key == key)
|
||||
@ -47,3 +83,15 @@ int heap_find(struct heap_entry * e, int length, int ix, int key)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define u32_per_heap_entry ((sizeof (struct heap_entry)) / (sizeof (uint32_t)))
|
||||
|
||||
struct heap_entry heap_extract_max(struct heap_entry * e, int * heap_length)
|
||||
{
|
||||
struct heap_entry entry = e[0];
|
||||
(*heap_length)--;
|
||||
e[0] = e[*heap_length];
|
||||
heap_sift_down(e, *heap_length, 0);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
13
heap.h
13
heap.h
@ -1,17 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct heap_entry {
|
||||
int key;
|
||||
int value;
|
||||
union {
|
||||
int value;
|
||||
struct {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
void heap_sift_up(struct heap_entry * e, int ix);
|
||||
void heap_sift_down(struct heap_entry * e, int heap_length, int ix);
|
||||
void heap_append(struct heap_entry * e, int * heap_length, int key, int value);
|
||||
void heap_append_xy(struct heap_entry * e, int * heap_length, int key, int x, int y);
|
||||
int heap_find(struct heap_entry * e, int length, int ix, int key);
|
||||
struct heap_entry heap_extract_max(struct heap_entry * e, int * heap_length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -41,6 +41,8 @@
|
||||
#include "2024/day14/input.txt.h"
|
||||
#include "2024/day15/sample1.txt.h"
|
||||
#include "2024/day15/input.txt.h"
|
||||
#include "2024/day16/sample1.txt.h"
|
||||
#include "2024/day16/input.txt.h"
|
||||
|
||||
static struct start_size sample[][2] = {
|
||||
{
|
||||
@ -163,6 +165,12 @@ static struct start_size sample[][2] = {
|
||||
{ ( char *)&_binary_2024_day15_sample1_txt_start,
|
||||
(uint32_t)&_binary_2024_day15_sample1_txt_size },
|
||||
},
|
||||
{
|
||||
{ ( char *)&_binary_2024_day16_sample1_txt_start,
|
||||
(uint32_t)&_binary_2024_day16_sample1_txt_size },
|
||||
{ ( char *)&_binary_2024_day16_sample1_txt_start,
|
||||
(uint32_t)&_binary_2024_day16_sample1_txt_size },
|
||||
},
|
||||
};
|
||||
|
||||
static struct start_size input[] = {
|
||||
@ -206,4 +214,6 @@ static struct start_size input[] = {
|
||||
(uint32_t)&_binary_2024_day14_input_txt_size },
|
||||
{ ( char *)&_binary_2024_day15_input_txt_start,
|
||||
(uint32_t)&_binary_2024_day15_input_txt_size },
|
||||
{ ( char *)&_binary_2024_day16_input_txt_start,
|
||||
(uint32_t)&_binary_2024_day16_input_txt_size },
|
||||
};
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "linear_algebra.h"
|
||||
|
||||
#include "printf.h"
|
||||
//#include <stdio.h>
|
||||
|
||||
double determinant_2x2(double a, double b,
|
||||
double c, double d)
|
||||
@ -14,32 +13,6 @@ double determinant_2x2(double a, double b,
|
||||
return a * d - b * c;
|
||||
}
|
||||
|
||||
/*
|
||||
5550.00 450000000444000.00 600000000222000.00
|
||||
81081081161.08 108108108148.11
|
||||
|
||||
-3876.00 -460000000548084.00 -400000000524792.00
|
||||
118679050709.00 103199174542.00
|
||||
|
||||
-6595.00 -470000000250610.00 -690000000567170.00
|
||||
71266110727.92 104624715779.71
|
||||
|
||||
4278.00 440000001045978.00 460000000280508.00
|
||||
102851800151.00 107526881786.00
|
||||
*/
|
||||
|
||||
union di {
|
||||
double d;
|
||||
int64_t i;
|
||||
};
|
||||
|
||||
static int64_t raw_double(double n)
|
||||
{
|
||||
union di di;
|
||||
di.d = n;
|
||||
return di.i;
|
||||
}
|
||||
|
||||
struct double2 cramers_rule_2x2(double a1, double b1, double c1,
|
||||
double a2, double b2, double c2)
|
||||
{
|
||||
|
13
memory.c
13
memory.c
@ -16,9 +16,20 @@ void memory_set_int(int * buf, int c, int length)
|
||||
}
|
||||
}
|
||||
|
||||
void memory_copy_char(char * src, int length, char * dst)
|
||||
void memory_copy_char(const char * src, int length, char * dst)
|
||||
{
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
dst[i] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
void memory_copy_u32(const void * _src, int length, void * _dst)
|
||||
{
|
||||
// size given in bytes
|
||||
const uint32_t * src = _src;
|
||||
uint32_t * dst = _dst;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
dst[i] = src[i];
|
||||
}
|
||||
}
|
||||
|
3
memory.h
3
memory.h
@ -6,7 +6,8 @@ extern "C" {
|
||||
|
||||
void memory_set_char(char * buf, char c, int length);
|
||||
void memory_set_int(int * buf, int c, int length);
|
||||
void memory_copy_char(char * src, int length, char * dst);
|
||||
void memory_copy_char(const char * src, int length, char * dst);
|
||||
void memory_copy_u32(const void * _src, int length, void * _dst);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
2
runner.c
2
runner.c
@ -38,7 +38,7 @@ bool runner_tick(struct runner_state * runner_state)
|
||||
int year = solution[ix].year;
|
||||
int day = solution[ix].day;
|
||||
|
||||
if (year != 2024 || day != 15) {
|
||||
if (year != 2024 || day != 16) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,8 @@ void _2024_day14_render(const struct font * font,
|
||||
const void * maple_ft0_data);
|
||||
int64_t _2024_day15_part1(const char * input, int length);
|
||||
int64_t _2024_day15_part2(const char * input, int length);
|
||||
int64_t _2024_day16_part1(const char * input, int length);
|
||||
int64_t _2024_day16_part2(const char * input, int length);
|
||||
|
||||
struct day_funcs solution[] = {
|
||||
{
|
||||
@ -146,4 +148,9 @@ struct day_funcs solution[] = {
|
||||
{_2024_day15_part1, _2024_day15_part2},
|
||||
NULL,
|
||||
},
|
||||
{
|
||||
2024, 16,
|
||||
{_2024_day16_part1, _2024_day16_part2},
|
||||
NULL,
|
||||
},
|
||||
};
|
||||
|
@ -63,4 +63,7 @@ DAY_OBJ = \
|
||||
2024/day14/solution.o \
|
||||
2024/day15/sample1.txt.o \
|
||||
2024/day15/input.txt.o \
|
||||
2024/day15/solution.o
|
||||
2024/day15/solution.o \
|
||||
2024/day16/sample1.txt.o \
|
||||
2024/day16/input.txt.o \
|
||||
2024/day16/solution.o
|
||||
|
20
test/run.sh
Normal file
20
test/run.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!bin/bash
|
||||
|
||||
set -eux
|
||||
|
||||
for i in test/test_heap.c; do
|
||||
name=${i%.c}
|
||||
gcc -Og -g -gdwarf-5 \
|
||||
-std=c2x \
|
||||
-Wall -Werror -Wfatal-errors \
|
||||
-Wno-error=unused-variable \
|
||||
-I. \
|
||||
-o ${name} \
|
||||
${name}.c \
|
||||
memory.c \
|
||||
dijkstra.c \
|
||||
heap.c \
|
||||
cartesian.c
|
||||
|
||||
./${name}
|
||||
done
|
27
test/runner.h
Normal file
27
test/runner.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
typedef bool (*test_t)(const char ** scenario);
|
||||
|
||||
#define ANSI_RED "\x1b[31m"
|
||||
#define ANSI_GREEN "\x1b[32m"
|
||||
#define ANSI_RESET "\x1b[0m"
|
||||
|
||||
#define RUNNER(tests) \
|
||||
int main() \
|
||||
{ \
|
||||
int fail_count = 0; \
|
||||
for (int i = 0; i < (sizeof (tests)) / (sizeof (test_t)); i++) { \
|
||||
const char * scenario = NULL; \
|
||||
bool result = tests[i](&scenario); \
|
||||
const char * result_s = result ? "ok" : ANSI_RED "fail" ANSI_RESET; \
|
||||
fail_count += !result; \
|
||||
fprintf(stderr, "%s: %s\n", scenario, result_s); \
|
||||
} \
|
||||
if (fail_count == 0) { \
|
||||
fprintf(stderr, ANSI_GREEN "failed tests: %d\n\n" ANSI_RESET, fail_count); \
|
||||
} else { \
|
||||
fprintf(stderr, ANSI_RED "failed tests: %d\n\n" ANSI_RESET, fail_count); \
|
||||
} \
|
||||
\
|
||||
return !(fail_count == 0); \
|
||||
}
|
76
test/test_dijkstra.c
Normal file
76
test/test_dijkstra.c
Normal file
@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "runner.h"
|
||||
|
||||
#include "dijkstra.h"
|
||||
#include "memory.h"
|
||||
|
||||
static const char * graph =
|
||||
"###############\n"
|
||||
"#.......#....E#\n"
|
||||
"#.#.###.#.###.#\n"
|
||||
"#.....#.#...#.#\n"
|
||||
"#.###.#####.#.#\n"
|
||||
"#.#.#.......#.#\n"
|
||||
"#.#.#####.###.#\n"
|
||||
"#...........#.#\n"
|
||||
"###.#.#####.#.#\n"
|
||||
"#...#.....#.#.#\n"
|
||||
"#.#.#.###.#.#.#\n"
|
||||
"#.....#...#.#.#\n"
|
||||
"#.###.#.#.#.#.#\n"
|
||||
"#S..#.....#...#\n"
|
||||
"###############\n"
|
||||
;
|
||||
|
||||
static bool dijkstra_test_0(const char ** scenario)
|
||||
{
|
||||
*scenario = "dijkstra";
|
||||
|
||||
int width = 15;
|
||||
int height = 15;
|
||||
int stride = 16;
|
||||
int start_x = 1;
|
||||
int start_y = 13;
|
||||
int end_x = 13;
|
||||
int end_y = 1;
|
||||
|
||||
struct dijkstra_xy16 prev[width * height];
|
||||
int dist[width * height];
|
||||
|
||||
dijkstra_cartesian(graph,
|
||||
stride,
|
||||
width, height,
|
||||
end_x, end_y,
|
||||
start_x, start_y,
|
||||
'#',
|
||||
prev,
|
||||
dist);
|
||||
|
||||
char map[stride * height];
|
||||
memory_copy_char(graph, stride * height, map);
|
||||
|
||||
int x = end_x;
|
||||
int y = end_y;
|
||||
int cost = 0;
|
||||
while (!(x == start_x && y == start_y)) {
|
||||
printf("%2d %2d %d\n", x, y, dist[y * width + x]);
|
||||
struct dijkstra_xy16 xy = prev[y * width + x];
|
||||
map[xy.y * stride + xy.x] = 'x';
|
||||
x = xy.x;
|
||||
y = xy.y;
|
||||
}
|
||||
printf("%2d %2d %d\n", x, y, dist[y * width + x]);
|
||||
|
||||
printf("%d\n", cost);
|
||||
puts(map);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
test_t dijkstra_tests[] = {
|
||||
dijkstra_test_0,
|
||||
};
|
||||
|
||||
RUNNER(dijkstra_tests)
|
35
test/test_heap.c
Normal file
35
test/test_heap.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "runner.h"
|
||||
|
||||
#include "heap.h"
|
||||
|
||||
static bool heap_test_0(const char ** scenario)
|
||||
{
|
||||
*scenario = "heap_extract_max";
|
||||
|
||||
struct heap_entry e[100];
|
||||
int heap_length = 0;
|
||||
int n[] = {-17, -57, -84, -88, -44, -77, -13, -80, -51, -37, -54, -74, -51, -74, -69, -15, -53, -74, -48, -93, -18, -14, -97, -35, -72, -73, -85, -42, -9, -53, -47, -93, -63, -81, -41, -48, -52, -67, -58, -24, -70, -4, -9, -67, -29, -54, -26, -35, -23, -96, -83, -68, -88, -73, -70, -71, -41, -78, -91, -96, -6, -33, -15, -56, -95, -62, -62, -88, -37, -96, -86, -53, -82, -84, -73, -25, -94, -1, -9, -80, -99, -35, -81, -51, -19, -64, -6, -88, -94, -30, -3, -88, -63, -43, -40, -86, -48, -66, -16, -21};
|
||||
for (int i = 0; i < 100; i++) {
|
||||
heap_append(e, &heap_length, n[i], 0);
|
||||
}
|
||||
|
||||
int max = 999;
|
||||
while (heap_length > 0) {
|
||||
struct heap_entry ei = heap_extract_max(e, &heap_length);
|
||||
printf("%d %d\n", ei.key, max);
|
||||
if (ei.key > max)
|
||||
return false;
|
||||
max = ei.key;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
test_t heap_tests[] = {
|
||||
heap_test_0,
|
||||
};
|
||||
|
||||
RUNNER(heap_tests)
|
BIN
test/test_memory
Executable file
BIN
test/test_memory
Executable file
Binary file not shown.
23
test/test_memory.c
Normal file
23
test/test_memory.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "runner.h"
|
||||
|
||||
#include "memory.h"
|
||||
|
||||
static bool memory_test_0(const char ** scenario)
|
||||
{
|
||||
*scenario = "memory_copy_u32 ordering";
|
||||
|
||||
uint32_t l[] = {1, 2, 3, 4};
|
||||
|
||||
memory_copy_u32(&l[1], 3, &l[0]);
|
||||
|
||||
return l[0] == 2 && l[1] == 3 && l[2] == 4;
|
||||
}
|
||||
|
||||
test_t memory_tests[] = {
|
||||
memory_test_0,
|
||||
};
|
||||
|
||||
RUNNER(memory_tests)
|
Loading…
x
Reference in New Issue
Block a user