Compare commits
1 Commits
hackerrank
...
day23
| Author | SHA1 | Date | |
|---|---|---|---|
|
0dc039f032
|
@@ -1,6 +0,0 @@
|
|||||||
-----BEGIN SSH SIGNATURE-----
|
|
||||||
U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgZ+OuJYdd3UiUbyBuO1RlsQR20a
|
|
||||||
Qm5mKneuMxRjGo3zkAAAAEZmlsZQAAAAAAAAAGc2hhNTEyAAAAUwAAAAtzc2gtZWQyNTUx
|
|
||||||
OQAAAED8T4C6WILXYZ1KxqDIlVhlrAEjr1Vc+tn8ypcVM3bN7iOexVvuUuvm90nr8eEwKU
|
|
||||||
acrdDxmq2S+oysQbK+pMUE
|
|
||||||
-----END SSH SIGNATURE-----
|
|
||||||
23
day23/example.txt
Normal file
23
day23/example.txt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#.#####################
|
||||||
|
#.......#########...###
|
||||||
|
#######.#########.#.###
|
||||||
|
###.....#.>.>.###.#.###
|
||||||
|
###v#####.#v#.###.#.###
|
||||||
|
###.>...#.#.#.....#...#
|
||||||
|
###v###.#.#.#########.#
|
||||||
|
###...#.#.#.......#...#
|
||||||
|
#####.#.#.#######.#.###
|
||||||
|
#.....#.#.#.......#...#
|
||||||
|
#.#####.#.#.#########v#
|
||||||
|
#.#...#...#...###...>.#
|
||||||
|
#.#.#v#######v###.###v#
|
||||||
|
#...#.>.#...>.>.#.###.#
|
||||||
|
#####v#.#.###v#.#.###.#
|
||||||
|
#.....#...#...#.#.#...#
|
||||||
|
#.#########.###.#.#.###
|
||||||
|
#...###...#...#...#.###
|
||||||
|
###.###.#.###v#####v###
|
||||||
|
#...#...#.#.>.>.#.>.###
|
||||||
|
#.###.###.#.###.#.#v###
|
||||||
|
#.....###...###...#...#
|
||||||
|
#####################.#
|
||||||
141
day23/input.txt
Normal file
141
day23/input.txt
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
#.###########################################################################################################################################
|
||||||
|
#.#...#.......#...#.....#...#...#######...###...#...#.......#...#...#...#...#...#...#...###...###...###...............#.....#...#######...###
|
||||||
|
#.#.#.#.#####.#.#.#.###.#.#.#.#.#######.#.###.#.#.#.#.#####.#.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.###.#.###.#############.#.###.#.#.#######.#.###
|
||||||
|
#.#.#.#.#.....#.#.#...#.#.#...#...#.....#...#.#.#.#.#.....#...#.#.#.#.#.#.#.#.#...#...#.....#.#...#...#.............#.#...#...#.......#.#...#
|
||||||
|
#.#.#.#.#.#####.#.###.#.#.#######.#.#######.#.#.#.#.#####.#####.#.#.#.#.#.#.#.###############.#.#####.#############.#.###.###########.#.###.#
|
||||||
|
#...#...#.....#.#.###.#.#.#.......#.....#...#.#.#.#.#.>.>.#.....#.#.#.#.#.#.#...#.............#.#.....#...#.......#.#.....#...........#.#...#
|
||||||
|
#############.#.#v###.#.#.#.###########.#.###.#.#.#.#.#v###.#####.#.#.#.#.#.###.#.#############.#.#####.#.#.#####.#.#######.###########.#.###
|
||||||
|
#...###...###...#.>.#.#.#.#.#...###.....#.....#.#.#...#...#.#...#.#.#.#.#.#.###.#.#####...###...#...#...#.#...#...#.....#...#...###...#.#.###
|
||||||
|
#.#.###.#.#######v#.#.#.#.#.#.#.###.###########.#.#######.#.#.#.#.#.#.#.#.#.###.#.#####.#.###.#####.#.###.###.#.#######.#.###.#.###.#.#.#.###
|
||||||
|
#.#.#...#.#.....#.#.#.#.#.#...#...#.........#...#.###.....#.#.#.#.#.#.#.#.#.>.>.#.......#.#...#.....#...#.#...#.#.......#...#.#.....#.#.#.###
|
||||||
|
#.#.#.###.#.###.#.#.#.#.#.#######.#########.#.###.###.#####.#.#.#.#.#.#.#.###v###########.#.###.#######.#.#.###.#.#########.#.#######.#.#.###
|
||||||
|
#.#.#...#.#...#.#.#.#.#.#...#.....#...#...#.#...#...#.....#.#.#.#.#.#.#...###.#...........#...#.....#...#.#...#.#.........#.#.#.......#.#.###
|
||||||
|
#.#.###.#.###.#.#.#.#.#.###.#.#####.#.#.#.#.###.###.#####.#.#.#.#.#.#.#######.#.#############.#####.#.###.###.#.#########.#.#.#.#######.#.###
|
||||||
|
#.#.....#.#...#.#.#.#.#.#...#.....#.#...#.#...#.#...#.....#...#...#.#.#.......#.#.....#.....#.#.....#...#.###.#.#...#.....#...#.#...###.#.###
|
||||||
|
#.#######.#.###.#.#.#.#.#.#######.#.#####.###.#.#.###.#############.#.#.#######.#.###.#.###.#.#.#######.#.###.#.#.#.#.#########.#.#.###.#.###
|
||||||
|
#.#...###...###.#.#...#.#...#.....#.#...#...#.#.#...#...........###...#.......#.#.#...#...#.#.#.#...###.#.###.#.#.#.#.....#.....#.#.#...#...#
|
||||||
|
#.#.#.#########.#.#####.###.#.#####.#.#.###.#.#.###.###########.#############.#.#.#.#####.#.#.#.#.#.###.#.###.#.#.#.#####.#.#####.#.#.#####.#
|
||||||
|
#.#.#.........#...#.....#...#.#...#...#...#...#.....#####.......#...###.......#.#.#.#.....#.#.#.#.#.#...#.>.>.#.#.#.#.....#...#...#...###...#
|
||||||
|
#.#.#########.#####.#####.###.#.#.#######.###############.#######.#.###.#######.#.#.#.#####.#.#.#.#.#.#####v###.#.#.#.#######.#.#########.###
|
||||||
|
#...#.......#.#...#...#...###.#.#.>.>...#...#...#...###...###...#.#...#.......#.#.#...###...#.#.#.#.#...#...###...#...###.....#.###.......###
|
||||||
|
#####.#####.#.#.#.###.#.#####.#.###v###.###.#.#.#.#.###.#####.#.#.###.#######.#.#.#######.###.#.#.#.###.#.###############.#####.###.#########
|
||||||
|
#...#.....#...#.#.###...#####...#...###.....#.#.#.#.#...#...#.#...#...#.......#.#.#.....#.....#.#.#.....#...#...........#.#...#...#...#.....#
|
||||||
|
#.#.#####.#####.#.###############.###########.#.#.#.#.###.#.#.#####.###.#######.#.#.###.#######.#.#########.#.#########.#.#.#.###.###.#.###.#
|
||||||
|
#.#.......#...#.#.#...#...###...#.....#.......#.#.#...#...#...#.....###.......#...#...#.#.....#.#...#...###...#.........#...#.#...###...#...#
|
||||||
|
#.#########.#.#.#.#.#.#.#.###.#.#####.#.#######.#.#####.#######.#############.#######.#.#.###.#.###.#.#.#######.#############.#.#########.###
|
||||||
|
#.........#.#.#.#.#.#.#.#...#.#.......#.#.......#.......###.....#...#.........###...#.#.#.#...#.....#.#.#...###.............#...#...#...#...#
|
||||||
|
#########.#.#.#.#.#.#.#.###.#.#########.#.#################.#####.#.#.###########.#.#.#.#.#.#########.#.#.#.###############.#####.#.#.#.###.#
|
||||||
|
#.........#.#.#.#.#.#.#...#.#.......###.#.#...#...#...#...#.....#.#.#.......#...#.#...#.#.#...#.......#.#.#...#.............#...#.#...#.....#
|
||||||
|
#.#########.#.#.#.#.#.###.#.#######v###.#.#.#.#.#.#.#.#.#.#####v#.#.#######.#.#.#.#####.#.###.#.#######.#.###.#.#############.#.#.###########
|
||||||
|
#...........#.#.#...#.#...#...#...>.>.#.#...#.#.#...#.#.#...#.>.>.#.#...###.#.#.#.....#.#.#...#.......#.#...#.#...#...#...###.#.#...........#
|
||||||
|
#############.#.#####.#.#####.#.###v#.#.#####.#.#####.#.###.#.#v###.#.#.###v#.#.#####.#.#.#.#########.#.###.#.###v#.#.#.#.###.#.###########.#
|
||||||
|
#...#...#.....#.....#.#.#.....#.#...#.#.....#.#...###...#...#.#...#.#.#.#.>.>.#.#...#.#.#.#...#.......#...#.#.#.>.>.#...#...#.#...#.........#
|
||||||
|
#.#.#.#.#.#########.#.#.#.#####.#.###.#####.#.###.#######.###.###.#.#.#.#.#v###.#.#.#.#.#.###.#.#########.#.#.#.#v#########.#.###.#.#########
|
||||||
|
#.#...#.#.#####...#.#.#.#.#.....#...#...#...#.#...#.....#...#...#.#...#...#.###...#...#...#...#.......###...#...#.#...#...#.#.#...#...#...###
|
||||||
|
#.#####.#.#####.#.#.#.#.#.#.#######.###.#.###.#.###.###.###.###.#.#########.###############.#########.###########.#.#.#.#.#.#.#.#####.#.#.###
|
||||||
|
#.....#...###...#.#.#...#...#.....#...#.#.#...#.....#...###.....#.....#.....#...#...#...###...#.......#...#...###.#.#...#...#.#...###...#...#
|
||||||
|
#####.#######.###.#.#########.###.###.#.#.#.#########.###############.#.#####.#.#.#.#.#.#####.#.#######.#.#.#.###.#.#########.###.#########.#
|
||||||
|
#.....#...#...###...#...#.....###...#.#.#.#.#...#...#...#.............#...#...#...#...#.....#.#.....#...#...#...#.#.###...###...#.#...#.....#
|
||||||
|
#.#####.#.#.#########.#.#.#########.#.#.#.#.#.#.#.#.###.#.###############.#.###############.#.#####.#.#########.#.#.###.#.#####.#.#.#.#.#####
|
||||||
|
#.....#.#...#####.....#.#.........#...#.#.#.#.#...#.#...#...............#...#...............#.#.....#.#.....#...#.#.#...#.#...#.#.#.#.#...###
|
||||||
|
#####.#.#########.#####.#########.#####.#.#.#.#####.#.#################.#####.###############.#.#####.#.###.#.###.#.#.###.#.#.#.#.#.#.###v###
|
||||||
|
#...#.#.........#.#...#...........#...#...#.#.....#.#.#.................#.....#.....#.......#.#.....#...#...#.....#.#.###.#.#.#.#.#.#.#.>.###
|
||||||
|
#.#.#v#########.#.#.#.#############.#.#####.#####.#.#.#.#################.#####.###.#.#####.#.#####.#####.#########.#.###.#.#.#.#.#.#.#.#v###
|
||||||
|
#.#.#.>...#.....#...#...............#.....#.#...#.#...#.#...#...........#.#.....###...#.....#.......#...#.........#.#...#.#.#...#.#.#...#...#
|
||||||
|
#.#.#v###.#.#############################.#.#.#.#.#####.#.#.#.#########.#.#.###########.#############.#.#########.#.###.#.#.#####.#.#######.#
|
||||||
|
#.#.#...#.#.......#.......................#...#...#...#...#...#...#.....#.#.#...........#...#...###...#...........#.#...#.#.#.....#.#.......#
|
||||||
|
#.#.###.#.#######.#.###############################.#.#########.#.#.#####.#.#.###########.#.#.#.###.###############.#.###.#.#.#####.#.#######
|
||||||
|
#.#.....#.........#...#...#.........###...#...#...#.#.#.........#...#...#...#.#...........#.#.#...#.........#.....#...###.#.#.#.....#.#.....#
|
||||||
|
#.###################.#.#.#.#######.###.#.#.#.#.#.#.#.#.#############.#.#####.#.###########.#.###.#########.#.###.#######.#.#.#.#####.#.###.#
|
||||||
|
#...#...###.....#...#...#.#.#.......#...#...#.#.#.#.#.#.............#.#.....#...#...........#.#...#.........#...#.....###...#...#...#...#...#
|
||||||
|
###.#.#.###.###.#.#.#####.#.#.#######.#######.#.#.#.#.#############.#.#####.#####.###########.#.###.###########.#####.###########.#.#####.###
|
||||||
|
#...#.#...#...#.#.#.#.....#.#.....###.#.......#.#...#...#...#...###...#.....#...#.......#...#.#.###.......###...#.....#...#.....#.#...###...#
|
||||||
|
#.###.###.###.#.#.#.#.#####.#####.###.#.#######.#######.#.#.#.#.#######.#####.#.#######.#.#.#.#.#########v###.###.#####.#.#.###.#.###.#####.#
|
||||||
|
#.....###.....#.#.#.#.......#...#...#.#.....###.......#.#.#...#.#.......#####.#.........#.#.#.#...#.....>.>.#...#.#...#.#.#.#...#...#.###...#
|
||||||
|
###############.#.#.#########.#.###.#.#####.#########.#.#.#####.#.###########.###########.#.#.###.#.#####v#.###.#.#.#.#.#.#.#.#####.#.###v###
|
||||||
|
#...............#.#.#.......#.#.....#.#.....#...#...#.#.#.....#.#...........#...#...#...#.#.#.#...#.....#.#.....#.#.#.#.#.#.#...#...#...>.###
|
||||||
|
#.###############.#.#.#####.#.#######.#.#####.#.#.#.#.#.#####.#.###########.###.#.#.#.#.#.#.#.#.#######.#.#######.#.#.#.#.#.###.#.#######v###
|
||||||
|
#...#.....#...###.#.#.....#.#.#...###.#.#...#.#.#.#.#.#.#...#.#.###.........###...#...#.#.#...#...#.....#.....#...#.#...#.#...#.#.#.....#.###
|
||||||
|
###.#.###.#.#.###.#.#####.#.#.#.#.###.#.#.#.#.#.#.#.#.#.#.#.#.#.###v###################.#.#######.#.#########.#.###.#####.###.#.#.#.###.#.###
|
||||||
|
###...###.#.#.#...#.#.....#...#.#.#...#.#.#.#.#.#.#.#.#.#.#...#...>.>.........#...#.....#.....#...#...#.......#.....#.....#...#...#...#...###
|
||||||
|
#########v#.#.#.###.#.#########.#.#.###.#.#.#.#.#.#.#.#.#.#########v#########.#.#.#.#########.#.#####.#.#############.#####.#########.#######
|
||||||
|
#...#...#.>.#.#...#.#.........#.#.#.#...#.#.#.#.#.#.#.#.#.#.........###.......#.#.#.....#.....#.....#.#...#.........#...#...#.........#...###
|
||||||
|
#.#.#.#.#v###.###.#.#########.#.#.#.#.###.#.#.#.#.#.#.#.#.#.###########.#######.#.#####.#.#########.#.###.#.#######.###.#.###.#########.#.###
|
||||||
|
#.#...#...###.....#.#...#.....#.#...#...#.#.#.#.#.#...#...#...#.....#...#.....#.#.#.....#.......###.#.###...#...#...#...#...#.#...#.....#...#
|
||||||
|
#.#################.#.#.#.#####.#######.#.#.#.#.#.###########.#.###.#.###.###.#.#.#.###########.###.#.#######.#.#.###.#####.#.#.#.#.#######.#
|
||||||
|
#.............#.....#.#.#.....#.....###...#.#.#.#.###...#...#...#...#...#.#...#.#.#.#.....#...#...#.#.#.......#...###...#...#...#...#.......#
|
||||||
|
#############.#.#####.#.#####v#####.#######.#.#.#.###.#.#.#.#####.#####.#.#.###.#.#v#.###.#.#.###.#.#.#.###############.#.###########.#######
|
||||||
|
#.............#.#...#.#...#.>.>.....#.....#.#.#.#.#...#...#.......#####.#.#.....#.>.>.###.#.#.....#.#.#.......#.....###.#...#.......#.......#
|
||||||
|
#.#############.#.#.#.###.#.#v#######.###.#.#.#.#.#.###################.#.#########v#####.#.#######.#.#######.#.###.###.###.#.#####.#######.#
|
||||||
|
#.........#...#...#.#.###.#.#.........#...#...#...#.......#.........#...#...#.......#...#...#...###.#.#.....#...#...#...#...#.....#.........#
|
||||||
|
#########.#.#.#####.#.###.#.###########.#################.#.#######.#.#####.#.#######.#.#####.#.###.#.#.###.#####.###.###.#######.###########
|
||||||
|
#.........#.#.#...#...###...#.........#.#...#...#.......#...#...#...#.#.....#.......#.#.......#...#...#...#.#...#...#.....#...###...........#
|
||||||
|
#.#########.#.#.#.###########.#######.#.#.#.#.#.#.#####.#####.#.#.###.#.###########.#.###########.#######.#.#.#.###.#######.#.#############.#
|
||||||
|
#...#...#...#.#.#.#...#.......#...###...#.#.#.#.#.....#...#...#...###...#...###...#.#.#...........#...#...#...#.....#...###.#.#...#.......#.#
|
||||||
|
###.#.#.#.###.#.#v#.#.#.#######.#.#######.#.#.#.#####.###.#.#############.#.###.#.#.#.#.###########.#.#.#############.#.###.#.#.#.#.#####.#.#
|
||||||
|
#...#.#.#.#...#.#.>.#.#.....#...#...#...#.#.#.#.#...#.#...#.......#...#...#.#...#.#...#.....#.....#.#...#.....###...#.#.#...#.#.#.#...###...#
|
||||||
|
#.###.#.#.#.###.#v###.#####.#.#####.#.#.#.#.#.#.#.#.#.#.#########.#.#.#.###.#.###.#########.#.###.#.#####.###.###.#.#.#.#.###.#.#.###v#######
|
||||||
|
#.....#.#.#...#.#.#...#...#...###...#.#.#.#.#.#.#.#...#.#.......#.#.#.#...#.#...#.###...#...#.#...#...#...###...#.#...#.#...#.#.#...>.###...#
|
||||||
|
#######.#.###.#.#.#.###.#.#######.###.#.#.#.#.#.#.#####.#.#####.#.#.#.###.#.###.#.###.#.#v###.#.#####.#.#######.#.#####.###.#.#.#####v###.#.#
|
||||||
|
#...###...###...#.#...#.#...#...#.###.#.#.#.#.#.#.....#.#.#.....#.#.#.#...#...#.#.#...#.>.>.#.#.....#...#.......#.#.....#...#.#...#...###.#.#
|
||||||
|
#.#.#############.###.#.###.#.#.#v###.#.#.#.#.#.#####.#.#.#.#####v#.#.#.#####.#.#.#.#####v#.#.#####.#####.#######.#.#####.###.###.#.#####.#.#
|
||||||
|
#.#.#...#.....#...###.#.#...#.#.>.>.#.#.#.#.#.#...#...#.#.#.#...>.>.#.#.....#.#.#.#.#.....#...#.....#...#.....#...#.....#...#.#...#.......#.#
|
||||||
|
#.#.#.#.#.###.#.#####.#.#.###.###v#.#.#.#.#.#.###.#.###.#.#.#.###v###.#####.#.#.#.#.#.#########.#####.#.#####.#.#######.###.#.#.###########.#
|
||||||
|
#.#.#.#.#...#.#...#...#.#...#.#...#...#.#.#.#.###...#...#.#.#.#...###...#...#.#.#.#.#.......#...###...#...###.#.......#.#...#.#.#.....#...#.#
|
||||||
|
#.#.#.#.###.#.###.#.###.###.#.#.#######.#.#.#.#######.###.#.#.#.#######.#.###.#.#.#.#######.#.#####.#####.###.#######.#.#.###.#.#.###.#.#.#.#
|
||||||
|
#.#...#.#...#.#...#...#...#...#.......#.#.#.#...#.....#...#...#.......#.#...#...#...#...#...#.......#.....#...#...#...#.#.###...#...#...#...#
|
||||||
|
#.#####.#.###.#.#####.###.###########.#.#.#.###.#.#####.#############.#.###.#########.#.#.###########.#####.###.#.#.###.#.#########.#########
|
||||||
|
#.#...#...###...#.....#...#...........#...#.....#...#...#...#...#...#.#.#...#...#...#.#.#...#.........#...#...#.#.#...#...#####...#.........#
|
||||||
|
#.#.#.###########.#####.###.#######################.#.###.#.#.#.#.#.#.#.#.###.#.#.#.#.#.###.#.#########.#.###v#.#.###.#########.#.#########.#
|
||||||
|
#...#.........###.....#...#.......###...#.........#...#...#...#...#.#.#...#...#...#...#.....#.....#...#.#.#.>.>.#...#.#.........#...........#
|
||||||
|
#############.#######.###.#######.###.#.#.#######.#####.###########.#.#####.#####################.#.#.#.#.#.#v#####.#.#.#####################
|
||||||
|
#.............#...###.....#.....#.....#...#...#...#.....#.......#...#.#...#.................#.....#.#...#...#...###...#.#...#...#.......#...#
|
||||||
|
#.#############.#.#########.###.###########.#.#.###.#####.#####.#.###.#.#.#################.#.#####.###########.#######.#.#.#.#.#.#####.#.#.#
|
||||||
|
#.#.....#...###.#.....#...#...#...........#.#...###.......#...#.#...#.#.#.#.........#...#...#...#...#.......#...#...###...#...#...#...#...#.#
|
||||||
|
#.#.###.#.#.###.#####.#.#.###.###########.#.###############.#.#.###.#.#.#.#.#######.#.#.#.#####.#.###.#####.#.###.#.###############.#.#####.#
|
||||||
|
#...###...#...#...#...#.#.###.........#...#.......#.........#.#.#...#.#.#.#.......#.#.#.#.#...#...###.....#.#.....#...#.............#.....#.#
|
||||||
|
#############.###.#.###.#.###########.#.#########.#.#########.#.#.###.#.#.#######.#.#.#.#.#.#.###########.#.#########.#.#################.#.#
|
||||||
|
#...###.......#...#...#.#.#...........#.....#.....#.........#...#.....#.#.........#.#.#.#.#.#.............#...#.......#.................#.#.#
|
||||||
|
#.#.###v#######.#####.#.#.#.###############.#.#############.###########.###########.#.#.#.#.#################.#.#######################.#.#.#
|
||||||
|
#.#...#.>.#.....#.....#.#.#...............#.#...#...#######.....#...###...........#.#.#.#.#.#.......#...#####...###.....#...#...###.....#.#.#
|
||||||
|
#.###.#v#.#.#####.#####.#.###############.#.###.#.#.###########.#.#.#############.#.#.#.#.#.#.#####.#.#.###########.###.#.#.#.#.###.#####.#.#
|
||||||
|
#...#...#...#.....#...#.#...#.............#.#...#.#.###.........#.#.#...###.......#...#...#...###...#.#...#...#...#...#.#.#.#.#...#.....#...#
|
||||||
|
###.#########.#####.#.#.###.#.#############.#.###.#.###.#########.#.#.#.###.#####################.###.###.#.#.#.#.###.#.#.#.#.###.#####.#####
|
||||||
|
#...#.......#.....#.#.#.#...#.....#...#...#...###.#...#.......#...#...#...#.........#...#...#...#.....#...#.#.#.#.###.#.#.#.#.#...#.....#...#
|
||||||
|
#.###.#####.#####.#.#.#.#.#######.#.#.#.#.#######.###.#######.#.#########.#########.#.#.#.#.#.#.#######.###.#.#.#.###.#.#.#.#.#.###v#####.#.#
|
||||||
|
#.....#.....#...#...#...#...#.....#.#...#.#.......#...#.......#...#.......#.........#.#.#.#.#.#.#...###.###.#.#.#.#...#.#.#.#.#.#.>.###...#.#
|
||||||
|
#######.#####.#.###########.#.#####.#####.#.#######.###.#########.#.#######.#########.#.#.#.#.#.#.#.###v###.#.#.#.#.###.#.#.#.#.#.#v###.###.#
|
||||||
|
#.......#.....#.#...#.......#.......#.....#.......#.###.....#...#.#...#...#.....###...#.#.#.#.#.#.#.#.>.>...#.#.#...###.#.#.#.#...#...#.#...#
|
||||||
|
#.#######.#####.#.#.#.###############.###########.#.#######.#.#.#.###.#.#.#####.###.###.#.#.#.#.#.#.#.#v#####.#.#######.#.#.#.#######.#.#.###
|
||||||
|
#.......#.#.....#.#.#.....#.....#.....#...#...#...#...#...#.#.#.#.#...#.#.#...#.#...###.#.#...#.#.#...#.....#.#.......#.#.#.#...#.....#.#...#
|
||||||
|
#######.#.#.#####.#.#####.#.###.#.#####.#.#.#.#.#####.#.#.#.#.#.#.#.###.#.#.#.#v#.#####.#.#####.#.#########.#.#######.#.#.#.###.#.#####.###.#
|
||||||
|
#.......#.#...#...#...#...#...#.#.#...#.#.#.#.#...#...#.#.#.#.#.#.#...#.#.#.#.>.>.###...#.....#.#.###.......#.#.......#.#.#.#...#.......#...#
|
||||||
|
#.#######.###.#.#####.#.#####.#.#v#.#.#.#.#.#.###.#.###.#.#v#.#.#.###.#.#.#.###v#####.#######.#.#.###.#######.#.#######.#.#.#.###########.###
|
||||||
|
#...#...#...#.#.#.....#.#...#.#.>.>.#.#.#...#.#...#...#.#.>.>.#.#.#...#.#...###.....#...#...#.#.#.#...#.....#.#.....###...#.#...#.........###
|
||||||
|
###.#.#.###.#.#.#.#####.#.#.#.###v###.#.#####.#.#####.#.###v###.#.#.###.###########.###.#.#.#.#.#.#.###.###.#.#####.#######.###.#.###########
|
||||||
|
###.#.#.#...#...#.....#...#...###.#...#.....#...#.....#.###...#...#.....#...#...#...#...#.#.#.#.#.#...#.#...#...#...#...###.....#...........#
|
||||||
|
###.#.#.#.###########.###########.#.#######.#####.#####.#####.###########.#.#.#.#.###.###.#.#.#.#.###.#.#.#####.#.###.#.###################.#
|
||||||
|
#...#.#.#.#...........###...#.....#...#...#.....#.#.....#####.......#.....#...#.#...#.#...#...#...###...#.....#.#.###.#.#...#...#...........#
|
||||||
|
#.###.#.#.#.#############.#.#.#######.#.#.#####.#.#.###############.#.#########.###.#.#.#####################.#.#.###.#.#.#.#.#.#.###########
|
||||||
|
#...#.#.#.#.#...........#.#.#.#.....#.#.#.#.....#...#...............#...#...###.....#.#...#.................#.#.#.#...#...#.#.#.#.........###
|
||||||
|
###.#.#.#.#.#.#########.#.#.#.#.###.#.#.#.#.#########.#################.#.#.#########.###.#.###############.#.#.#.#.#######.#.#.#########.###
|
||||||
|
###.#.#.#.#.#.#.......#...#.#...#...#.#.#.#...#...#...#...#.......#...#...#.........#.....#...............#...#...#...#.....#.#.#...#...#...#
|
||||||
|
###.#.#.#.#.#.#.#####.#####.#####.###.#.#.###.#.#.#.###.#.#.#####.#.#.#############.#####################.###########.#.#####.#.#.#.#v#.###.#
|
||||||
|
###.#.#.#.#...#.....#.#...#.#...#.###...#.....#.#.#...#.#...#.....#.#.#.............###...#...#.....#...#.#.......#...#...#...#.#.#.>.#.....#
|
||||||
|
###.#.#.#.#########.#.#.#.#.#.#.#.#############.#.###.#.#####.#####.#.#.###############.#.#.#.#.###.#.#.#.#.#####.#.#####.#.###.#.###v#######
|
||||||
|
###...#...#.....#...#...#...#.#.#...........###.#.###...#.....###...#.#.......#.......#.#.#.#.#...#...#.#.#.....#...###...#...#...#...#...###
|
||||||
|
###########.###.#.###########.#.###########.###.#.#######.#######.###.#######.#.#####.#.#.#.#.###.#####.#.#####.#######.#####.#####.###.#.###
|
||||||
|
#.......###...#...#...###.....#.............#...#.......#.......#.#...#...#...#.#.....#.#.#.#.###.....#...#...#.......#.......#...#.....#...#
|
||||||
|
#.#####.#####.#####.#.###.###################.#########.#######.#.#.###.#.#.###.#.#####.#.#.#.#######.#####.#.#######.#########.#.#########.#
|
||||||
|
#.....#.......#...#.#...#.........#...###...#...#.......#...#...#.#...#.#...#...#.#...#.#.#.#.#...#...#...#.#.###...#...###.....#...........#
|
||||||
|
#####.#########.#.#.###.#########v#.#.###.#.###.#.#######.#.#.###.###.#.#####.###.#.#.#.#.#.#.#.#.#.###.#.#.#.###.#.###.###.#################
|
||||||
|
#.....#.......#.#.#.###...#...#.>.>.#...#.#.#...#...#.....#...###...#.#.....#.#...#.#.#.#.#.#.#.#.#...#.#.#.#.#...#.....#...#.....#.....#####
|
||||||
|
#.#####.#####.#.#.#.#####.#.#.#.#######.#.#.#.#####.#.#############.#.#####v#.#.###.#.#.#.#.#.#.#.###v#.#.#.#.#.#########.###.###.#.###.#####
|
||||||
|
#.....#.#.....#.#.#.#####.#.#...#.......#.#.#...#...#.........###...#.#...>.>.#.#...#.#.#...#.#.#...>.>.#.#.#.#.........#...#.#...#.###...###
|
||||||
|
#####.#.#.#####.#.#.#####.#.#####.#######.#.###.#.###########v###.###.#.#######.#.###.#.#####.#.#########.#.#.#########.###.#.#.###.#####.###
|
||||||
|
#####...#.....#.#...#.....#.....#.......#.#...#.#...#...#...>.>.#.###.#.....###.#.###.#.###...#.......#...#.#.#.......#.#...#.#.....#...#...#
|
||||||
|
#############.#.#####.#########.#######.#.###.#.###.#.#.#.#####.#.###.#####.###.#.###.#.###.#########.#.###.#.#.#####.#.#.###.#######.#.###.#
|
||||||
|
#.............#...#...#...#.....#.......#.#...#...#.#.#.#.....#.#.#...#.....#...#...#.#...#.....#.....#...#.#.#.....#.#.#...#.#.......#.....#
|
||||||
|
#.###############.#.###.#.#.#####.#######.#.#####.#.#.#.#####.#.#.#.###.#####.#####.#.###.#####.#.#######.#.#.#####.#.#.###.#.#.#############
|
||||||
|
#.................#.....#...#####.........#.......#...#.......#...#.....#####.......#.....#####...#######...#.......#...###...#.............#
|
||||||
|
###########################################################################################################################################.#
|
||||||
236
day23/main.go
Normal file
236
day23/main.go
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
aoc "go.sour.is/advent-of-code"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = aoc.Log
|
||||||
|
|
||||||
|
func main() { aoc.MustResult(aoc.Runner(run)) }
|
||||||
|
|
||||||
|
type result struct {
|
||||||
|
valuePT1 int
|
||||||
|
valuePT2 int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r result) String() string { return fmt.Sprintf("%#v", r) }
|
||||||
|
|
||||||
|
func run(scan *bufio.Scanner) (*result, error) {
|
||||||
|
var m aoc.Map[int16, rune]
|
||||||
|
|
||||||
|
start := Point{0, 0}
|
||||||
|
target := Point{0, 0}
|
||||||
|
var text string
|
||||||
|
for scan.Scan() {
|
||||||
|
text = scan.Text()
|
||||||
|
if start == target {
|
||||||
|
start[1] = int16(strings.IndexRune(text, '.'))
|
||||||
|
}
|
||||||
|
m = append(m, []rune(text))
|
||||||
|
}
|
||||||
|
target[0] = int16(len(m) - 1)
|
||||||
|
target[1] = int16(strings.IndexRune(text, '.'))
|
||||||
|
|
||||||
|
result := &result{}
|
||||||
|
|
||||||
|
result.valuePT1 = search(&graph{m: m, start: start, target: target, neighbors: part1nbs})
|
||||||
|
result.valuePT2 = search(&graph{m: m, start: start, target: target, neighbors: part2nbs})
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Point = aoc.Point[int16]
|
||||||
|
type Map = aoc.Map[int16, rune]
|
||||||
|
|
||||||
|
// diretion of path steps
|
||||||
|
type direction int8
|
||||||
|
|
||||||
|
var (
|
||||||
|
U = Point{-1, 0}
|
||||||
|
R = Point{0, 1}
|
||||||
|
D = Point{1, 0}
|
||||||
|
L = Point{0, -1}
|
||||||
|
)
|
||||||
|
|
||||||
|
var directions = []Point{U, R, D, L}
|
||||||
|
|
||||||
|
var dirIDX = func() map[Point]direction {
|
||||||
|
m := make(map[Point]direction, len(directions))
|
||||||
|
for k, v := range directions {
|
||||||
|
m[v] = direction(k)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}()
|
||||||
|
|
||||||
|
var arrows = []rune{'^', '>', 'v', '<'}
|
||||||
|
|
||||||
|
var arrowIDX = func() map[rune]Point {
|
||||||
|
m := make(map[rune]Point, len(arrows))
|
||||||
|
for k, v := range arrows {
|
||||||
|
m[v] = directions[k]
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}()
|
||||||
|
|
||||||
|
// position on the map
|
||||||
|
type position struct {
|
||||||
|
loc Point
|
||||||
|
direction Point
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p position) step(to Point) position {
|
||||||
|
return position{p.loc.Add(to), to}
|
||||||
|
}
|
||||||
|
|
||||||
|
// implements FindPath graph interface
|
||||||
|
type graph struct {
|
||||||
|
m Map
|
||||||
|
start Point
|
||||||
|
target Point
|
||||||
|
|
||||||
|
neighbors func(g *graph, current position) []position
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neighbors returns valid steps from given position. if at target returns none.
|
||||||
|
func (g *graph) Neighbors(current position) []position {
|
||||||
|
return g.neighbors(g, current)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cost calculates heat cost to neighbor from map
|
||||||
|
func (g *graph) Cost(a, b position) int16 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *graph) Target(a position, c int16) bool {
|
||||||
|
return a.loc == g.target
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *graph) Seen(a position) position {
|
||||||
|
a.direction = Point{}
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
func match[T comparable](match T, lis ...T) bool {
|
||||||
|
for _, b := range lis {
|
||||||
|
if b == match {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func search(g *graph) int {
|
||||||
|
costs, paths := aoc.FindPaths[int16, position](g, position{loc: g.start}, position{loc: g.target})
|
||||||
|
|
||||||
|
for i, path := range paths {
|
||||||
|
log("path length = ", costs[i])
|
||||||
|
printGraph(g.m, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(aoc.Max(0, costs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// printGraph with the path overlay
|
||||||
|
func printGraph(m Map, path []position) {
|
||||||
|
pts := make(map[Point]position, len(path))
|
||||||
|
for _, pt := range path {
|
||||||
|
pts[pt.loc] = pt
|
||||||
|
}
|
||||||
|
|
||||||
|
for r, row := range m {
|
||||||
|
for c, x := range row {
|
||||||
|
if _, ok := pts[Point{int16(r), int16(c)}]; ok {
|
||||||
|
if x == '.' {
|
||||||
|
fmt.Print("*")
|
||||||
|
} else {
|
||||||
|
fmt.Print(string(x))
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Print(".")
|
||||||
|
_ = x
|
||||||
|
// fmt.Print(string(x))
|
||||||
|
}
|
||||||
|
fmt.Println("")
|
||||||
|
}
|
||||||
|
fmt.Println("")
|
||||||
|
}
|
||||||
|
|
||||||
|
func opposite(d Point) Point {
|
||||||
|
return directions[(dirIDX[d]+2)%4]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func part1nbs(g *graph, current position) []position {
|
||||||
|
var nbs []position
|
||||||
|
|
||||||
|
if current.loc == g.start {
|
||||||
|
return []position{
|
||||||
|
{current.loc.Add(D), D},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if current.loc == g.target {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// only one direction on arrow.
|
||||||
|
_, r, _ := g.m.Get(current.loc)
|
||||||
|
if match(r, arrows...) {
|
||||||
|
to := arrowIDX[r]
|
||||||
|
if next := current.step(to); g.m.Valid(next.loc) {
|
||||||
|
_, r, _ := g.m.Get(next.loc)
|
||||||
|
d := arrows[(dirIDX[to]+2)%4] // flow from opposite direction
|
||||||
|
if !match(r, rune(d), '#') {
|
||||||
|
nbs = append(nbs, next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nbs
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, to := range directions {
|
||||||
|
if next := current.step(to); g.m.Valid(next.loc) {
|
||||||
|
_, r, _ := g.m.Get(next.loc)
|
||||||
|
d := arrows[(dirIDX[to]+2)%4] // flow from opposite direction
|
||||||
|
if !match(r, rune(d), '#') {
|
||||||
|
nbs = append(nbs, next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nbs
|
||||||
|
}
|
||||||
|
|
||||||
|
func part2nbs(g *graph, current position) []position {
|
||||||
|
var nbs []position
|
||||||
|
|
||||||
|
if current.loc == g.start {
|
||||||
|
return []position{
|
||||||
|
{current.loc.Add(D), D},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if current.loc == g.target {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, to := range directions {
|
||||||
|
if next := current.step(to); g.m.Valid(next.loc) {
|
||||||
|
if next.direction == opposite(current.direction) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_, r, _ := g.m.Get(next.loc)
|
||||||
|
if r == '#' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
nbs = append(nbs, next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nbs
|
||||||
|
}
|
||||||
42
day23/main_test.go
Normal file
42
day23/main_test.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
_ "embed"
|
||||||
|
|
||||||
|
"github.com/matryer/is"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed example.txt
|
||||||
|
var example []byte
|
||||||
|
|
||||||
|
//go:embed input.txt
|
||||||
|
var input []byte
|
||||||
|
|
||||||
|
func TestExample(t *testing.T) {
|
||||||
|
is := is.New(t)
|
||||||
|
scan := bufio.NewScanner(bytes.NewReader(example))
|
||||||
|
|
||||||
|
result, err := run(scan)
|
||||||
|
is.NoErr(err)
|
||||||
|
|
||||||
|
t.Log(result)
|
||||||
|
// is.Equal(result.valuePT1, 94)
|
||||||
|
is.Equal(result.valuePT2, 154)
|
||||||
|
}
|
||||||
|
|
||||||
|
// func TestSolution(t *testing.T) {
|
||||||
|
// is := is.New(t)
|
||||||
|
// scan := bufio.NewScanner(bytes.NewReader(input))
|
||||||
|
|
||||||
|
// result, err := run(scan)
|
||||||
|
// is.NoErr(err)
|
||||||
|
|
||||||
|
// t.Log(result)
|
||||||
|
// is.True(result.valuePT1 > 1918)
|
||||||
|
// is.Equal(result.valuePT1, 2074)
|
||||||
|
// is.Equal(result.valuePT2, 0)
|
||||||
|
// }
|
||||||
4
go.mod
4
go.mod
@@ -1,6 +1,8 @@
|
|||||||
module go.sour.is/advent-of-code
|
module go.sour.is/advent-of-code
|
||||||
|
|
||||||
go 1.22.0
|
go 1.21.4
|
||||||
|
|
||||||
|
toolchain go1.21.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/matryer/is v1.4.1
|
github.com/matryer/is v1.4.1
|
||||||
|
|||||||
9
grids.go
9
grids.go
@@ -111,8 +111,8 @@ func (m *cmap[C, N]) String() string {
|
|||||||
|
|
||||||
for k, nbs := range m.neighbors {
|
for k, nbs := range m.neighbors {
|
||||||
fmt.Fprintln(b, k)
|
fmt.Fprintln(b, k)
|
||||||
for to, c := range nbs {
|
for to, v := range nbs {
|
||||||
fmt.Fprintln(b, " ", to, c)
|
fmt.Fprintln(b, " ", to, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,18 +132,19 @@ func CompressMap[C number, N comparable](p pather[C, N], start N) pather[C, N] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nbs := p.Neighbors(n)
|
nbs := p.Neighbors(n)
|
||||||
if len(nbs) == 2 {
|
if len(nbs) == 2{
|
||||||
a, b := nbs[0], nbs[1]
|
a, b := nbs[0], nbs[1]
|
||||||
if to, ok := visited[a]; ok {
|
if to, ok := visited[a]; ok {
|
||||||
to[b] = to[n] + p.Cost(n, b)
|
to[b] = to[n] + p.Cost(n, b)
|
||||||
delete(to, n)
|
delete(to, n)
|
||||||
visited[a] = to
|
visited[a] = to
|
||||||
|
continue
|
||||||
} else if to, ok := visited[b]; ok {
|
} else if to, ok := visited[b]; ok {
|
||||||
to[a] = to[n] + p.Cost(n, a)
|
to[a] = to[n] + p.Cost(n, a)
|
||||||
delete(to, n)
|
delete(to, n)
|
||||||
visited[b] = to
|
visited[b] = to
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visited[n] = make(map[N]C)
|
visited[n] = make(map[N]C)
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
import "os"
|
|
||||||
import "bufio"
|
|
||||||
import "strconv"
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
|
|
||||||
var input1 = strings.NewReader(`
|
|
||||||
6
|
|
||||||
1 2 5 3 6 4
|
|
||||||
`)
|
|
||||||
|
|
||||||
var input2 = strings.NewReader(`
|
|
||||||
15
|
|
||||||
1 14 3 7 4 5 15 6 13 10 11 2 12 8 9
|
|
||||||
`)
|
|
||||||
|
|
||||||
var input3 = os.Stdin
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
var length int
|
|
||||||
var tree *node
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(input1)
|
|
||||||
for scanner.Scan() {
|
|
||||||
if length == 0 {
|
|
||||||
length, _ = strconv.Atoi(scanner.Text())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, txt := range strings.Fields(scanner.Text()) {
|
|
||||||
if v, err := strconv.Atoi(txt); err == nil {
|
|
||||||
tree = insert(tree, &node{value: v})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foo(input{1, "hi"})
|
|
||||||
|
|
||||||
fmt.Println(tree)
|
|
||||||
}
|
|
||||||
|
|
||||||
type node struct {
|
|
||||||
value int
|
|
||||||
left *node
|
|
||||||
right *node
|
|
||||||
}
|
|
||||||
|
|
||||||
func insert(root, n *node) *node {
|
|
||||||
if root == nil {
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
if root.value > n.value {
|
|
||||||
root.left = insert(root.left, n)
|
|
||||||
return root
|
|
||||||
}
|
|
||||||
root.right = insert(root.right, n)
|
|
||||||
return root
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *node) String() string {
|
|
||||||
if n == nil { return "" }
|
|
||||||
return fmt.Sprintf("%v %v%v", n.value, n.left.String(), n.right.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
type input struct{a int; b string}
|
|
||||||
func foo (in input) {}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
aoc "go.sour.is/advent-of-code"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Complete the 'cookies' function below.
|
|
||||||
*
|
|
||||||
* The function is expected to return an INTEGER.
|
|
||||||
* The function accepts following parameters:
|
|
||||||
* 1. INTEGER k
|
|
||||||
* 2. INTEGER_ARRAY A
|
|
||||||
*/
|
|
||||||
|
|
||||||
func cookies(k int32, A []int32) int32 {
|
|
||||||
var i int32
|
|
||||||
// fmt.Println(" ", A)
|
|
||||||
// sort.Slice(A, func(i, j int) bool { return A[j] < A[i]})
|
|
||||||
// for A[len(A)-1] < k {
|
|
||||||
// if len(A) < 2 {
|
|
||||||
// return -1
|
|
||||||
// }
|
|
||||||
// // fmt.Println(" ", A[len(A)-1], " + 2x", A[len(A)-2], 2*A[len(A)-2] + A[len(A)-1])
|
|
||||||
// A[len(A)-2] = 2*A[len(A)-2] + A[len(A)-1]
|
|
||||||
// A = A[:len(A)-1]
|
|
||||||
|
|
||||||
// for j:=len(A)-1; j>0 && A[j] > A[j-1]; j-- {
|
|
||||||
// A[j], A[j-1] = A[j-1], A[j]
|
|
||||||
// }
|
|
||||||
// i++
|
|
||||||
// fmt.Println("A", len(A), i)
|
|
||||||
// }
|
|
||||||
|
|
||||||
pq := aoc.FibHeap(func(a, b *int32) bool { return *a < *b })
|
|
||||||
for i := range A {
|
|
||||||
pq.Insert(&A[i])
|
|
||||||
}
|
|
||||||
for !pq.IsEmpty() && *pq.GetMin() < k {
|
|
||||||
first := *pq.ExtractMin()
|
|
||||||
second := *pq.ExtractMin()
|
|
||||||
third := first + 2*second
|
|
||||||
|
|
||||||
pq.Insert(&third)
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
reader := bufio.NewReaderSize(os.Stdin, 16*1024*1024)
|
|
||||||
|
|
||||||
stdout, err := os.Create("/dev/stderr")
|
|
||||||
checkError(err)
|
|
||||||
|
|
||||||
defer stdout.Close()
|
|
||||||
|
|
||||||
writer := bufio.NewWriterSize(stdout, 16*1024*1024)
|
|
||||||
|
|
||||||
firstMultipleInput := strings.Split(strings.TrimSpace(readLine(reader)), " ")
|
|
||||||
|
|
||||||
nTemp, err := strconv.ParseInt(firstMultipleInput[0], 10, 64)
|
|
||||||
checkError(err)
|
|
||||||
n := int32(nTemp)
|
|
||||||
|
|
||||||
kTemp, err := strconv.ParseInt(firstMultipleInput[1], 10, 64)
|
|
||||||
checkError(err)
|
|
||||||
k := int32(kTemp)
|
|
||||||
|
|
||||||
ATemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
|
|
||||||
|
|
||||||
var A []int32
|
|
||||||
|
|
||||||
for i := 0; i < int(n); i++ {
|
|
||||||
AItemTemp, err := strconv.ParseInt(ATemp[i], 10, 64)
|
|
||||||
checkError(err)
|
|
||||||
AItem := int32(AItemTemp)
|
|
||||||
A = append(A, AItem)
|
|
||||||
}
|
|
||||||
|
|
||||||
result := cookies(k, A)
|
|
||||||
|
|
||||||
fmt.Fprintf(writer, "%d\n", result)
|
|
||||||
|
|
||||||
writer.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
func readLine(reader *bufio.Reader) string {
|
|
||||||
str, _, err := reader.ReadLine()
|
|
||||||
if err == io.EOF {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.TrimRight(string(str), "\r\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkError(err error) {
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,2 +0,0 @@
|
|||||||
8 90
|
|
||||||
13 47 74 12 89 74 18 38
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
|
|
||||||
func countChan(n int) <-chan int {
|
|
||||||
ch := make(chan int)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for i := range n {
|
|
||||||
ch <- i
|
|
||||||
}
|
|
||||||
close(ch)
|
|
||||||
}()
|
|
||||||
|
|
||||||
return ch
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
// export GOEXPERIMENT=rangefunc
|
|
||||||
import "iter"
|
|
||||||
|
|
||||||
func Step(start, stop, step int) iter.Seq[int] {
|
|
||||||
if step < 0 {
|
|
||||||
return func(yield func(int) bool) {
|
|
||||||
for i := start; i <= start && i > stop; i += step {
|
|
||||||
next := yield(i)
|
|
||||||
if !next {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if step > 0 {
|
|
||||||
return func(yield func(int) bool) {
|
|
||||||
for i := start; i >= start && i < stop; i += step {
|
|
||||||
next := yield(i)
|
|
||||||
if !next {
|
|
||||||
println("stopped!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return func(yield func(int) bool) { yield(start) }
|
|
||||||
}
|
|
||||||
|
|
||||||
func Fib() iter.Seq[uint] {
|
|
||||||
return func(yield func(uint) bool) {
|
|
||||||
previous, value := uint(1), uint(1)
|
|
||||||
next := yield(value)
|
|
||||||
for next {
|
|
||||||
next = yield(value)
|
|
||||||
value, previous = value+previous, value
|
|
||||||
if value < previous {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Fizzbuzzed[T int | uint](from iter.Seq[T]) iter.Seq2[T, string] {
|
|
||||||
pull, stop := iter.Pull(from)
|
|
||||||
return func(yield func(T, string) bool) {
|
|
||||||
defer stop()
|
|
||||||
for {
|
|
||||||
var fizzbuzz string
|
|
||||||
p, ok := pull()
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if p%3 == 0 {
|
|
||||||
fizzbuzz = "fizz"
|
|
||||||
}
|
|
||||||
if p%5 == 0 {
|
|
||||||
fizzbuzz += "buzz"
|
|
||||||
}
|
|
||||||
if !yield(p, fizzbuzz) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// func main() {
|
|
||||||
// for i, v := range Fizzbuzzed(Fib()) {
|
|
||||||
// println(i, v)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
func countScan(n int) (func() bool, func() int) {
|
|
||||||
pos := -1
|
|
||||||
return func() bool {
|
|
||||||
pos++
|
|
||||||
return pos < n
|
|
||||||
}, func() int {
|
|
||||||
return pos
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,193 +0,0 @@
|
|||||||
package main_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/matryer/is"
|
|
||||||
)
|
|
||||||
|
|
||||||
// func BenchmarkChan(b *testing.B) {
|
|
||||||
// sum := 0
|
|
||||||
|
|
||||||
// for n := range countChan(b.N) {
|
|
||||||
// sum += n
|
|
||||||
// }
|
|
||||||
// b.StopTimer()
|
|
||||||
// b.Log(sum)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func BenchmarkScan(b *testing.B) {
|
|
||||||
// sum := 0
|
|
||||||
// scan, value := countScan(b.N)
|
|
||||||
// for scan() {
|
|
||||||
// sum += value()
|
|
||||||
// }
|
|
||||||
// b.StopTimer()
|
|
||||||
// b.Log(sum)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func BenchmarkRange(b *testing.B) {
|
|
||||||
// sum := 0
|
|
||||||
// for n := range countRF(b.N) {
|
|
||||||
// sum += n
|
|
||||||
// }
|
|
||||||
// b.StopTimer()
|
|
||||||
// b.Log(sum)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestRangeS(t *testing.T) {
|
|
||||||
// for i := range Step(0, 10, 3) {
|
|
||||||
// t.Log(i)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// for i := range Step(10, 0, -3) {
|
|
||||||
// t.Log(i)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
func TestSelect(t *testing.T) {
|
|
||||||
done1 := make(chan struct{})
|
|
||||||
done2 := make(chan struct{})
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
close(done1)
|
|
||||||
close(done2)
|
|
||||||
}()
|
|
||||||
|
|
||||||
for i, ch := range []chan struct{}{done1, done2} {
|
|
||||||
<-ch
|
|
||||||
println("closed", i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGCD(t *testing.T) {
|
|
||||||
is := is.New(t)
|
|
||||||
is.Equal(gcdOfStrings("ABAB", "ABABAB"), "AB")
|
|
||||||
is.Equal(gcdOfStrings("ABAB", "ABABABAB"), "ABAB")
|
|
||||||
is.Equal(gcdOfStrings("ABC", "ABCABC"), "ABC")
|
|
||||||
is.Equal(gcdOfStrings("ABC", "ABCDEF"), "")
|
|
||||||
is.Equal(gcdOfStrings("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
|
||||||
}
|
|
||||||
func gcdOfStrings(str1 string, str2 string) string {
|
|
||||||
if len(str1) == 0 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
runes1 := []rune(str1)
|
|
||||||
runes2 := []rune(str2)
|
|
||||||
|
|
||||||
n := max(len(runes1), len(runes2))
|
|
||||||
m := min(len(runes1), len(runes2))
|
|
||||||
|
|
||||||
if len(runes2) == m {
|
|
||||||
runes1, runes2 = runes2, runes1
|
|
||||||
}
|
|
||||||
|
|
||||||
if isRepeating(runes1, runes2) {
|
|
||||||
return string(runes1)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := n; i > 0; i-- {
|
|
||||||
if runes1[i%len(runes1)] != runes2[i%len(runes2)] {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
gcd := runes2[:i]
|
|
||||||
if isRepeating(gcd, runes1) && isRepeating(gcd, runes2) {
|
|
||||||
return string(gcd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
func isRepeating(str1, str2 []rune) bool {
|
|
||||||
if len(str1) > len(str2) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if len(str2)%len(str1) != 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for i := range str2 {
|
|
||||||
if str1[i%len(str1)] != str2[i] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func canPlaceFlowers(flowerbed []int, n int) bool {
|
|
||||||
var c int
|
|
||||||
|
|
||||||
for i := 0; i < len(flowerbed); i++ {
|
|
||||||
if (i == 0 || flowerbed[i-1] == 0) &&
|
|
||||||
flowerbed[i] == 0 &&
|
|
||||||
(i == len(flowerbed)-1 || flowerbed[i+1] == 0) {
|
|
||||||
c++
|
|
||||||
flowerbed[i] = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c >= n
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFlowers(t *testing.T) {
|
|
||||||
is := is.New(t)
|
|
||||||
is.Equal(canPlaceFlowers([]int{1, 0, 0, 0, 1}, 1), true)
|
|
||||||
is.Equal(canPlaceFlowers([]int{0, 0, 1, 0, 1}, 1), true)
|
|
||||||
is.Equal(canPlaceFlowers([]int{1, 0, 1, 0, 0}, 1), true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func dailyTemperatures(temperatures []int) []int {
|
|
||||||
answers := make([]int, len(temperatures))
|
|
||||||
var stack [][2]int
|
|
||||||
push := func(v int) {
|
|
||||||
if len(stack) == 0 {
|
|
||||||
stack = append(stack, [2]int{v, 1})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
end := len(stack)-1
|
|
||||||
if v < stack[end][0]{
|
|
||||||
stack = append(stack, [2]int{v, 1})
|
|
||||||
return
|
|
||||||
|
|
||||||
}
|
|
||||||
if v == stack[end][0] {
|
|
||||||
stack[len(stack)-1][1]++
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var vs = [2]int{v, 1}
|
|
||||||
// for ; end>0; end-- {
|
|
||||||
// if stack[end][0]<vs[0] {
|
|
||||||
// vs[1]+=stack[end][1]
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
stack = append(stack, vs)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := len(temperatures) - 2; i >= 0; i-- {
|
|
||||||
push(temperatures[i+1])
|
|
||||||
currentTemp := temperatures[i]
|
|
||||||
days := 1
|
|
||||||
end := len(stack)-1
|
|
||||||
for j := range stack {
|
|
||||||
nextTemp := stack[end-j]
|
|
||||||
if currentTemp < nextTemp[0] {
|
|
||||||
answers[i] = days
|
|
||||||
break
|
|
||||||
}
|
|
||||||
days+=nextTemp[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return answers
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTemps(t *testing.T) {
|
|
||||||
is := is.New(t)
|
|
||||||
is.Equal(dailyTemperatures(
|
|
||||||
[]int{73, 74, 75, 71, 69, 72, 76, 73}),
|
|
||||||
[]int{1, 1, 4, 2, 1, 1, 0, 0})
|
|
||||||
is.Equal(dailyTemperatures(
|
|
||||||
[]int{99,99,99,99,100}), []int{4,3,2,1,0})
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
|
|
||||||
func countRF(n int) func(yield func(int) bool) {
|
|
||||||
return func(yield func(int) bool) {
|
|
||||||
for i := range n {
|
|
||||||
if !yield(i) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
103
search.go
103
search.go
@@ -1,6 +1,7 @@
|
|||||||
package aoc
|
package aoc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"maps"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
@@ -322,3 +323,105 @@ func (h *fibHeap[T]) cascadingCut(y *fibTree[T]) {
|
|||||||
h.cascadingCut(y.parent)
|
h.cascadingCut(y.parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindPath uses the A* path finding algorithem.
|
||||||
|
// g is the graph source that implements the pather interface.
|
||||||
|
//
|
||||||
|
// C is an numeric type for calculating cost/potential
|
||||||
|
// N is the node values. is comparable for storing in visited table for pruning.
|
||||||
|
//
|
||||||
|
// start, end are nodes that dileniate the start and end of the search path.
|
||||||
|
// The returned values are the calculated cost and the path taken from start to end.
|
||||||
|
func FindPaths[C integer, N comparable](g pather[C, N], start, end N) ([]C, [][]N) {
|
||||||
|
var zero C
|
||||||
|
// closed := make(map[N]bool)
|
||||||
|
|
||||||
|
var potentialFn = func(N) C { var zero C; return zero }
|
||||||
|
if p, ok := g.(interface{ Potential(N) C }); ok {
|
||||||
|
potentialFn = p.Potential
|
||||||
|
}
|
||||||
|
|
||||||
|
type node struct {
|
||||||
|
cost C
|
||||||
|
potential C
|
||||||
|
parent *node
|
||||||
|
position N
|
||||||
|
closed map[N]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
NewPath := func(n *node) []N {
|
||||||
|
var path []N
|
||||||
|
for n.parent != nil {
|
||||||
|
path = append(path, n.position)
|
||||||
|
n = n.parent
|
||||||
|
}
|
||||||
|
path = append(path, n.position)
|
||||||
|
|
||||||
|
Reverse(path)
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
less := func(b, a *node) bool {
|
||||||
|
return b.cost+b.potential < a.cost+a.potential
|
||||||
|
}
|
||||||
|
|
||||||
|
pq := PriorityQueue(less)
|
||||||
|
pq.Insert(&node{position: start, closed: make(map[N]bool)})
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
Log("queue max depth = ", pq.maxDepth, "total enqueue = ", pq.totalEnqueue, "total dequeue = ", pq.totalDequeue)
|
||||||
|
}()
|
||||||
|
|
||||||
|
var seenFn = func(a N) N { return a }
|
||||||
|
if s, ok := g.(interface{ Seen(N) N }); ok {
|
||||||
|
seenFn = s.Seen
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetFn = func(n N, c C) bool { return true }
|
||||||
|
if s, ok := g.(interface{ Target(N, C) bool }); ok {
|
||||||
|
targetFn = s.Target
|
||||||
|
}
|
||||||
|
|
||||||
|
var paths [][]N
|
||||||
|
var costs []C
|
||||||
|
|
||||||
|
for !pq.IsEmpty() {
|
||||||
|
current := pq.ExtractMin()
|
||||||
|
cost, potential, n := current.cost, current.potential, current.position
|
||||||
|
|
||||||
|
seen := seenFn(n)
|
||||||
|
if current.closed[seen] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
current.closed[seen] = true
|
||||||
|
|
||||||
|
if cost > 0 && potential == zero && cost > Max(0, costs...) && targetFn(current.position, cost) {
|
||||||
|
paths = append([][]N(nil), NewPath(current))
|
||||||
|
costs = append([]C(nil), cost)
|
||||||
|
Log("new record = ", cost)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, nb := range g.Neighbors(n) {
|
||||||
|
seen := seenFn(nb)
|
||||||
|
if current.closed[seen] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
cost := g.Cost(n, nb) + current.cost
|
||||||
|
next := &node{
|
||||||
|
position: nb,
|
||||||
|
parent: current,
|
||||||
|
cost: cost,
|
||||||
|
potential: potentialFn(nb),
|
||||||
|
closed: maps.Clone(current.closed),
|
||||||
|
}
|
||||||
|
// check if path is in open list
|
||||||
|
if _, open := current.closed[seen]; !open {
|
||||||
|
next.closed[seen] = false // add to open list
|
||||||
|
pq.Insert(next)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return costs, paths
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user