day 23 done B)

main
Shoofle 10 months ago
parent 9a217a0202
commit a847e4e73c
  1. 2
      day17/target/.rustc_info.json
  2. 2
      day19/target/.rustc_info.json
  3. 13
      day21/drawings
  4. 8
      day23/.idea/.gitignore
  5. 11
      day23/.idea/day23.iml
  6. 8
      day23/.idea/modules.xml
  7. 6
      day23/.idea/vcs.xml
  8. 7
      day23/Cargo.lock
  9. 8
      day23/Cargo.toml
  10. 257
      day23/src/main.rs
  11. 1
      day23/target/.rustc_info.json
  12. 3
      day23/target/CACHEDIR.TAG
  13. 0
      day23/target/debug/.cargo-lock
  14. 1
      day23/target/debug/.fingerprint/day23-08047b34a1a248d2/invoked.timestamp
  15. 1
      day23/target/debug/.fingerprint/day23-08047b34a1a248d2/test-bin-day23
  16. 1
      day23/target/debug/.fingerprint/day23-08047b34a1a248d2/test-bin-day23.json
  17. 1
      day23/target/debug/.fingerprint/day23-2555db558b3ab0aa/bin-day23
  18. 1
      day23/target/debug/.fingerprint/day23-2555db558b3ab0aa/bin-day23.json
  19. 1
      day23/target/debug/.fingerprint/day23-2555db558b3ab0aa/invoked.timestamp
  20. 1
      day23/target/debug/.fingerprint/day23-42a5522b767f966b/bin-day23
  21. 1
      day23/target/debug/.fingerprint/day23-42a5522b767f966b/bin-day23.json
  22. BIN
      day23/target/debug/.fingerprint/day23-42a5522b767f966b/dep-bin-day23
  23. 1
      day23/target/debug/.fingerprint/day23-42a5522b767f966b/invoked.timestamp
  24. BIN
      day23/target/debug/day23
  25. 1
      day23/target/debug/day23.d
  26. BIN
      day23/target/debug/deps/day23-42a5522b767f966b
  27. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.100et5x6c7ftw9nu.rcgu.o
  28. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.13nuhp38l6ovvb79.rcgu.o
  29. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.13rmsdepg7a8ydzg.rcgu.o
  30. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.13tbm7m6476ov4se.rcgu.o
  31. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.15ih8ng83kz9cnw0.rcgu.o
  32. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.15o7i02ljec9evac.rcgu.o
  33. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.18ldvoavs3vaqd50.rcgu.o
  34. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.19hjksfpplcgsi7j.rcgu.o
  35. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1aqzuj5qagynuahq.rcgu.o
  36. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1bw2193ysdi0etsj.rcgu.o
  37. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1ddbceg5nbmwpi99.rcgu.o
  38. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1dv4u44ajx7bqxoh.rcgu.o
  39. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1h77si5ubqr08j77.rcgu.o
  40. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1jdwuwfjinzbcwtc.rcgu.o
  41. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1jlu7xceoposhkrw.rcgu.o
  42. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1l1ku6qu0rfbmoy5.rcgu.o
  43. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1qbzdsnxzku0e7u6.rcgu.o
  44. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.1sn6ijoz7xbeq1e5.rcgu.o
  45. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.24jqa3u96jv790df.rcgu.o
  46. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.24up7dncu1p2xoy5.rcgu.o
  47. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.26wyv13yo11fg987.rcgu.o
  48. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.27xbmsmtwwuqwxt5.rcgu.o
  49. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2c1gfoghx9c05i5q.rcgu.o
  50. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2cwbe8y9ymhvaf8h.rcgu.o
  51. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2dfopw2jz1nt1xfb.rcgu.o
  52. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2djkq60xvvg93ubr.rcgu.o
  53. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2dm1hmk8vyiiupx9.rcgu.o
  54. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2f1e1kp2nagtjtnn.rcgu.o
  55. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2i5l7l3mefd4ia3v.rcgu.o
  56. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2l9y3rky0nfdn9zy.rcgu.o
  57. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2paq21msmoj8sung.rcgu.o
  58. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.2phvdzhc2mu9tlz3.rcgu.o
  59. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.30742yzwjtyawqdr.rcgu.o
  60. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.33159a32zijdprwc.rcgu.o
  61. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.33zfio7o9f8yb827.rcgu.o
  62. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.34bsjz93hfjy2sse.rcgu.o
  63. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3cm3c40fgk2trudb.rcgu.o
  64. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3iea3btogj0vcoit.rcgu.o
  65. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3jbiilz4pmte42os.rcgu.o
  66. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3kf8q51vebm1t8vx.rcgu.o
  67. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3knzmjz37pqq7vxp.rcgu.o
  68. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3m77qo0vz4feqelf.rcgu.o
  69. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3mjzusugxs2oeutd.rcgu.o
  70. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3nx6stbmzdopbxlz.rcgu.o
  71. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3pqcokpn2v1ball8.rcgu.o
  72. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3rcos3cichkco9eh.rcgu.o
  73. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3rs507qbwvo6thsv.rcgu.o
  74. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.3wr89qitdg28a332.rcgu.o
  75. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.40oxpase1kpijk87.rcgu.o
  76. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.41joyjo6lfxqc9f7.rcgu.o
  77. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.43a9tzhejufjx5zv.rcgu.o
  78. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.448yrh7m47hinqux.rcgu.o
  79. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.44ibnb4lczedx68a.rcgu.o
  80. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.45m3lyh6wx719vgo.rcgu.o
  81. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.47tm270blewx2e3r.rcgu.o
  82. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.4a829mqyomzlybn2.rcgu.o
  83. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.4fz4j98n1it39oko.rcgu.o
  84. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.4gly5ks92h27fn7y.rcgu.o
  85. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.4gyrx5srgj7ue4r9.rcgu.o
  86. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.4h5e4hu67q4s8ca1.rcgu.o
  87. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.4kvvmeepwylqczo6.rcgu.o
  88. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.4ohdw6z8sz10fryo.rcgu.o
  89. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.4zv8n67fahg6kkgn.rcgu.o
  90. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.52fliutovhy2ist0.rcgu.o
  91. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.54c44jvfun1od2fz.rcgu.o
  92. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.55biotzbcpk2aors.rcgu.o
  93. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.574pocsivoxubabu.rcgu.o
  94. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.57sk4get8xzo5mnr.rcgu.o
  95. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.5bnjbw0tp550kov6.rcgu.o
  96. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.5ed4sjiaxu6qqsth.rcgu.o
  97. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.5fzvl6bwnh3nss0e.rcgu.o
  98. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.7m9aw69qqurl6zn.rcgu.o
  99. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.97y5iz632o0zyi4.rcgu.o
  100. BIN
      day23/target/debug/deps/day23-42a5522b767f966b.abllt41l3ea6q8c.rcgu.o
  101. Some files were not shown because too many files have changed in this diff Show More

@ -1 +1 @@
{"rustc_fingerprint":18427324047803895159,"outputs":{"12285253167677315500":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/shoofle/.rustup/toolchains/stable-x86_64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"sse4.1\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.74.1 (a28077b28 2023-12-04)\nbinary: rustc\ncommit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1\ncommit-date: 2023-12-04\nhost: x86_64-apple-darwin\nrelease: 1.74.1\nLLVM version: 17.0.4\n","stderr":""}},"successes":{}} {"rustc_fingerprint":18427324047803895159,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.74.1 (a28077b28 2023-12-04)\nbinary: rustc\ncommit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1\ncommit-date: 2023-12-04\nhost: x86_64-apple-darwin\nrelease: 1.74.1\nLLVM version: 17.0.4\n","stderr":""},"12285253167677315500":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/shoofle/.rustup/toolchains/stable-x86_64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"sse4.1\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"apple\"\nunix\n","stderr":""}},"successes":{}}

@ -1 +1 @@
{"rustc_fingerprint":18427324047803895159,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.74.1 (a28077b28 2023-12-04)\nbinary: rustc\ncommit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1\ncommit-date: 2023-12-04\nhost: x86_64-apple-darwin\nrelease: 1.74.1\nLLVM version: 17.0.4\n","stderr":""},"12285253167677315500":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/shoofle/.rustup/toolchains/stable-x86_64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"sse4.1\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"apple\"\nunix\n","stderr":""}},"successes":{}} {"rustc_fingerprint":18427324047803895159,"outputs":{"12285253167677315500":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/shoofle/.rustup/toolchains/stable-x86_64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"sse4.1\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"128\"\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.74.1 (a28077b28 2023-12-04)\nbinary: rustc\ncommit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1\ncommit-date: 2023-12-04\nhost: x86_64-apple-darwin\nrelease: 1.74.1\nLLVM version: 17.0.4\n","stderr":""}},"successes":{}}

@ -1,13 +1,14 @@
.^. /^\
<#> <#>
.v. \v/
points + # points + #
# = 7596 # = 7577
points + # = 34324 points + angles + # = 34324
..^..
./#\. ./^\.
/@#@\
<#@#> <#@#>
.\#/. .\#/.
..v.. ..v..

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/day23.iml" filepath="$PROJECT_DIR$/.idea/day23.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

7
day23/Cargo.lock generated

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day23"
version = "0.1.0"

@ -0,0 +1,8 @@
[package]
name = "day23"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

@ -0,0 +1,257 @@
use std::cmp::{max};
use std::collections::{HashMap, HashSet};
use std::fs;
use std::env;
use crate::Dir::{North, South, East, West};
// nodes are (coord, direction) pairs.
// neighbors are step1+turnleft, step2+turnleft, step3+turnleft, step1+turnright, etc
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
enum Dir { North, South, East, West }
fn step(start: &Coord, d: &Dir, steps: i32) -> Coord {
match d {
North => (start.0, start.1 - steps),
South => (start.0, start.1 + steps),
East => (start.0 + steps, start.1),
West => (start.0 - steps, start.1),
}
}
fn slope_from_char(slope: &char) -> Option<Dir> {
match slope {
'>' => Some(East),
'<' => Some(West),
'v' => Some(South),
'^' => Some(North),
_ => None,
}
}
type Coord = (i32, i32);
type Path = Vec<Coord>;
fn main() {
println!("Hello, AoC day 17!");
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("wrong number of arguments!");
std::process::exit(1);
}
let file_path = &args[1];
let contents = fs::read_to_string(file_path).expect("Should have been able to read the file");
let mut grid: HashMap<Coord, char> = HashMap::new();
let mut start: Coord = (-1, -1);
let mut last: Coord = (-1, -1);
// build our grid!
let mut x = 0;
let mut y = 0;
for line in contents.lines() {
x = 0;
for c in line.chars() {
if y == 0 && c == '.' { start = (x,y); }
if c == '.' { last = (x,y); }
grid.insert((x,y), c);
x += 1;
}
y += 1;
}
// is this even necessary??
let mut walks: HashMap<Coord, char> = grid.clone();
for (key, value) in grid {
if value == '#' {
walks.remove(&key);
}
}
for j in 0..y {
for i in 0..x {
if walks.contains_key(&(i,j)) {
print!("{}", walks.get(&(i,j)).unwrap());
} else {
print!(" ");
}
}
print!("\n");
}
let mut final_paths: HashSet<Path> = HashSet::new();
let mut heads: HashSet<(Coord, Path)> = HashSet::new();
heads.insert((start, Vec::from([start])));
while !heads.is_empty() {
let mut new_heads: HashSet<(Coord, Path)> = HashSet::new();
for (head, history) in &heads {
// take a step as each head.
if head == &last {
final_paths.insert(history.to_vec());
continue;
}
let neighbors = options(head, &walks);
let allowed_neighbors: Vec<&Coord> = neighbors.iter()
.filter(|candidate| !history.contains(candidate))
.collect();
for next_step in allowed_neighbors {
let mut next_history = history.clone();
next_history.push(head.clone());
new_heads.insert((*next_step, next_history));
}
}
heads = new_heads;
}
println!("longest path following slopes is...");
println!("{}", final_paths
.iter()
.fold(0, |a: usize, b: &Path| max(a, b.len()))
);
println!("endopint i s {last:?}");
println!("now let's *not* follow some slopes. so first we want to build a more compact graph.");
let mut graph: HashMap<Coord, HashMap<Dir, (Coord, i32)>> = HashMap::new();
let mut unexplored: HashSet<Coord> = HashSet::from([start]);
while !unexplored.is_empty() {
// as long as we've got unexplored nodes to visit, we'll keep looping
let mut new_unexplored: HashSet<Coord> = HashSet::new();
for head in &unexplored {
if graph.contains_key(&head) {
// if we've already visited that location, skip it.
continue;
}
// otherwise it's new. so we add a record to our graph for it
let mut next_steps = HashMap::new();
for (direction, next) in options_but_free(&head, &walks) {
let (location, distance) = keep_going(&head, &next, &walks);
next_steps.insert(direction, (location, distance));
new_unexplored.insert(location);
}
graph.insert(*head, next_steps.clone());
println!("just explored location {head:?}, with outgoings {next_steps:?}");
}
unexplored = new_unexplored;
}
println!("graph has {} elements", graph.len());
println!("now let's do a breadth-first search, i guess. but it's going to be faster this time.");
let mut heads = HashSet::from([vec![(start, 0)]]);
let goal = last;
let mut full_paths = HashSet::new();
while heads.len() != 0 {
//step each head forward one time.
let mut new_heads = HashSet::new();
for path in &heads {
//println!("trying a path with {} steps", path.len());
let head = path.last().unwrap().0;
// check if we've reached an endpoint!
if goal == head {
full_paths.insert(path.to_vec());
continue;
}
// otherwise, look at each next step in the list:
for (_, (coord, distance)) in graph.get(&head).unwrap() {
if !fresh(coord, path) {
//println!("pruning a path!");
continue;
}
let mut next_step_path = path.to_vec();
next_step_path.push((coord.clone(), distance.clone()));
new_heads.insert(next_step_path);
}
}
heads = new_heads;
println!("heads has {} elements now", heads.len());
println!("maximum is {}", maxlength(&heads));
}
println!("largest distance possible is {}", maxlength(&full_paths));
}
fn maxlength(paths: &HashSet<Vec<(Coord, i32)>>) -> i32 {
let mut max_length = 0;
for full_path in paths {
let mut len = 0;
for (_, distance) in full_path {
len += distance;
}
if len > max_length {
max_length = len;
}
}
return max_length;
}
fn fresh(step: &Coord, path: &Vec<(Coord, i32)>) -> bool {
for (location, _) in path {
if step == location {
return false;
}
}
return true;
}
fn keep_going(from: &Coord, towards: &Coord, grid: &HashMap<Coord, char>) -> (Coord, i32) {
// receives where it comes from and where it's going towards.
// keeps walking towards where it's giong, until it reaches a branch, at which poiont it returns
// that coordinate and the distance it walked.
let mut seen = HashSet::from([from.clone()]);
let mut distance = 1;
let mut next = towards.clone();
loop {
let options = options_but_free(&next, grid);
if options.len() != 2 {
// if there's not two options available, then we're either at an endpoint or an intersection
// either way, we should break out and return (next,distance)
break;
}
for (_direction, step) in options {
//if we've already seen this upcoming spot, ignore it.
if seen.contains(&step) {
continue;
} else {
// otherwise increment distance, note the square we've been on, and step forward.
distance += 1;
seen.insert(next);
next = step;
}
}
// now we've seen another one. register that.
}
return (next, distance);
}
fn options(here: &Coord, grid: &HashMap<Coord, char>) -> Vec<Coord> {
let floor = grid.get(here).unwrap();
if let Some(must_go) = slope_from_char(floor) {
return Vec::from([four_winds(here).get(&must_go).unwrap().clone()]);
}
let steps = four_winds(here);
return steps.values().filter(|x| grid.contains_key(x)).copied().collect();
}
fn options_but_free(here: &Coord, grid: &HashMap<Coord, char>) -> HashMap<Dir, Coord> {
let mut output:HashMap<Dir, Coord> = HashMap::with_capacity(4);
for (dir, next_step) in four_winds(here) {
if grid.contains_key(&next_step) { output.insert(dir, next_step); }
}
return output;
}
fn four_winds(here: &Coord) -> HashMap<Dir, Coord> {
return HashMap::from([
(North, step(here, &North, 1)),
(South, step(here, &South, 1)),
(East, step(here, &East, 1)),
(West, step(here, &West, 1))]);
}

@ -0,0 +1 @@
{"rustc_fingerprint":14318102787793507742,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.74.1 (a28077b28 2023-12-04)\nbinary: rustc\ncommit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1\ncommit-date: 2023-12-04\nhost: x86_64-apple-darwin\nrelease: 1.74.1\nLLVM version: 17.0.4\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/shoofle/.rustup/toolchains/stable-x86_64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"sse4.1\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""}},"successes":{}}

@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/

@ -0,0 +1 @@
This file has an mtime of when this was started.

@ -0,0 +1 @@
{"rustc":4443399816165520464,"features":"[]","target":12078389660814236502,"profile":13053956386274884697,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day23-08047b34a1a248d2/dep-test-bin-day23"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

@ -0,0 +1 @@
{"rustc":4443399816165520464,"features":"[]","target":12078389660814236502,"profile":13396965805329499462,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day23-2555db558b3ab0aa/dep-bin-day23"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

@ -0,0 +1 @@
This file has an mtime of when this was started.

@ -0,0 +1 @@
{"rustc":4443399816165520464,"features":"[]","target":12078389660814236502,"profile":237655285757591511,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/day23-42a5522b767f966b/dep-bin-day23"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

@ -0,0 +1 @@
This file has an mtime of when this was started.

Binary file not shown.

@ -0,0 +1 @@
/Users/shoofle/Projects/aoc_2023/day23/target/debug/day23: /Users/shoofle/Projects/aoc_2023/day23/src/main.rs

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save