diff options
author | Martin Ashby <martin@ashbysoft.com> | 2022-12-06 09:25:51 +0000 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2022-12-06 09:25:51 +0000 |
commit | 745b6bfd5730a926a32c34d0b6e50a5685cbcddc (patch) | |
tree | 8f7b0286954407c7d7e94401289b4daf8cefb123 /src/day6.rs | |
parent | 3397b97987abac3b1d84d5fa8c7b6185a20bf409 (diff) | |
download | aoc2022-745b6bfd5730a926a32c34d0b6e50a5685cbcddc.tar.gz aoc2022-745b6bfd5730a926a32c34d0b6e50a5685cbcddc.tar.bz2 aoc2022-745b6bfd5730a926a32c34d0b6e50a5685cbcddc.tar.xz aoc2022-745b6bfd5730a926a32c34d0b6e50a5685cbcddc.zip |
Day 6
Reasonably simple this one :)
Diffstat (limited to 'src/day6.rs')
-rw-r--r-- | src/day6.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/day6.rs b/src/day6.rs new file mode 100644 index 0000000..1e2dcfd --- /dev/null +++ b/src/day6.rs @@ -0,0 +1,17 @@ +pub fn run(input: String) { + //let wlen = 4; + let wlen = 14; + let (wix, _) = input.chars().collect::<Vec<char>>().windows(wlen).enumerate().find(|(_, win)| { + //println!("checking window {:?}", win.into_iter().map(|ch|{ch.to_owned()}).collect::<Vec<char>>()); + let n = win.len(); + for i in 0..n { + for j in i..n { + if i != j && win[i]==win[j] { + return false; + } + } + } + return true; + }).expect("no unique sequence!"); + println!("Day 6: {}", wix + wlen); +}
\ No newline at end of file |