summaryrefslogtreecommitdiffstats
path: root/day06b/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'day06b/src/main.rs')
-rw-r--r--day06b/src/main.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/day06b/src/main.rs b/day06b/src/main.rs
new file mode 100644
index 0000000..7e98082
--- /dev/null
+++ b/day06b/src/main.rs
@@ -0,0 +1,51 @@
+/// --- Part Two ---
+///
+/// Your device's communication system is correctly detecting packets, but still isn't working. It
+/// looks like it also needs to look for messages.
+///
+/// A start-of-message marker is just like a start-of-packet marker, except it consists of 14
+/// distinct characters rather than 4.
+///
+/// Here are the first positions of start-of-message markers for all of the above examples:
+///
+/// mjqjpqmgbljsphdztnvjfqwrcgsmlb: first marker after character 19
+/// bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 23
+/// nppdvjthqldpwncqszvftbrmjlhg: first marker after character 23
+/// nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 29
+/// zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 26
+///
+/// How many characters need to be processed before the first start-of-message marker is detected?
+use clap::Parser;
+use itertools::Itertools;
+
+use std::fs::File;
+use std::io::prelude::*;
+use std::io::BufReader;
+use std::iter::*;
+use std::path::PathBuf;
+
+const FILEPATH: &'static str = "examples/input.txt";
+const CONS_CHARS: usize = 14;
+
+#[derive(Parser, Debug)]
+#[clap(author, version, about, long_about = None)]
+struct Cli {
+ #[clap(short, long, default_value = FILEPATH)]
+ file: PathBuf,
+}
+
+fn main() {
+ let args = Cli::parse();
+
+ let file = File::open(&args.file).unwrap();
+ let reader = BufReader::new(file);
+ let line = reader.lines().next().unwrap().unwrap();
+ let res = line
+ .into_bytes()
+ .windows(CONS_CHARS)
+ .position(|b| b.iter().all_unique())
+ .unwrap()
+ + CONS_CHARS;
+
+ println!("{:?}", res);
+}