aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/06/solver.rs
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022/06/solver.rs')
-rw-r--r--AoC2022/06/solver.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/AoC2022/06/solver.rs b/AoC2022/06/solver.rs
new file mode 100644
index 0000000..0d59479
--- /dev/null
+++ b/AoC2022/06/solver.rs
@@ -0,0 +1,27 @@
+use std::fs;
+use std::io::{self, Read};
+
+fn solver(bytes: &Vec<u8>, marker_len: u32) -> u32 {
+ let mut count = marker_len;
+ for view in bytes.windows(marker_len as usize) {
+ let mut acc: u32 = 0;
+ for elt in view {
+ acc |= 1 << (elt - 96);
+ }
+ if u32::count_ones(acc) >= marker_len {
+ break;
+ }
+ count += 1;
+ }
+ count
+}
+
+fn main() -> io::Result<()> {
+ let mut file = fs::File::open("input").unwrap();
+ let mut bytes: Vec<u8> = Vec::new();
+ file.read_to_end(&mut bytes)?;
+ println!("All test passed. {}", solver(&bytes, 4));
+ println!("All test passed. {}", solver(&bytes, 14));
+
+ Ok(())
+}