summaryrefslogtreecommitdiffstats
path: root/day06b/src/main.rs
diff options
context:
space:
mode:
authorShivesh Mandalia <mail@shivesh.org>2022-12-21 21:20:05 +0000
committerShivesh Mandalia <mail@shivesh.org>2022-12-21 21:20:05 +0000
commit8f85eafcf28ecc77607ad2b54b4bde3bd07885bb (patch)
treeff0ae03dd95beb1bc8c6020c87190aae7fb171cb /day06b/src/main.rs
parent666b11bc77f17d6d2b5a466c56ea7710bb9134fd (diff)
downloadadvent_of_code_2022-8f85eafcf28ecc77607ad2b54b4bde3bd07885bb.tar.gz
advent_of_code_2022-8f85eafcf28ecc77607ad2b54b4bde3bd07885bb.zip
complete day 6
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);
+}