From 793848ed965f962e29064da665a29a2110e25bd3 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Sat, 3 Dec 2022 19:21:46 -0500 Subject: [PATCH] Add aoc 2022 day 3 --- 2022/3/Cargo.lock | 14 +++ 2022/3/Cargo.toml | 9 ++ 2022/3/input | 300 +++++++++++++++++++++++++++++++++++++++++++++ 2022/3/src/main.rs | 50 ++++++++ 4 files changed, 373 insertions(+) create mode 100644 2022/3/Cargo.lock create mode 100644 2022/3/Cargo.toml create mode 100644 2022/3/input create mode 100644 2022/3/src/main.rs diff --git a/2022/3/Cargo.lock b/2022/3/Cargo.lock new file mode 100644 index 0000000..8218e2a --- /dev/null +++ b/2022/3/Cargo.lock @@ -0,0 +1,14 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "common" +version = "0.1.0" + +[[package]] +name = "day3" +version = "0.1.0" +dependencies = [ + "common", +] diff --git a/2022/3/Cargo.toml b/2022/3/Cargo.toml new file mode 100644 index 0000000..647cb07 --- /dev/null +++ b/2022/3/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day3" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +common = { path = "../common" } diff --git a/2022/3/input b/2022/3/input new file mode 100644 index 0000000..d0ad78f --- /dev/null +++ b/2022/3/input @@ -0,0 +1,300 @@ +PcPlnShmrLmBnmcwBhrmcmbHNGFGpwdFFwGNjNbGqNHH +tzQfRJfWZZztWzVtCTfRzFZjpFjNZjGLHbdHLDdjpb +CCQTzRLzvQVVfRzJfMPsnBlglgPmBgPmvSrl +RMfvbbszHTsssFPzDQPggpQJPQ +NSNcqVtLVGgDlpQBClVB +hmStGNNLhjNrpWLGSjWrZssbZTMMvTfMnThbRRTs +fTrTPGTbfftWBBmLjrJL +DqHwVMqVplDslmlZmpHVwNnShWZFdBBdjWBtWtdtWJSSLS +MNslpDvVHlwsmpQRgQgCfTTcvcRQ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cbqFfMMpFDVCDFVFVCDqqfFwD +ZtLnlvLnNtvLndnCmfMVSmVCClfpVp +zTzZtjnZNLNmZvdtznntHHZJbBRGBRQWcJGbGsbsJRPQWT +MLmlMTPtQtMNlhbqbbqhflBB +rcrvjpSvScbRbBvbDBPG +ZZJzSHpzPrJzHFmMVMFmHCLNtV diff --git a/2022/3/src/main.rs b/2022/3/src/main.rs new file mode 100644 index 0000000..2d3122f --- /dev/null +++ b/2022/3/src/main.rs @@ -0,0 +1,50 @@ +use common; + +fn main() { + + let input_file = common::parse_args_input_file(&mut std::env::args()); + let contents = std::fs::read_to_string(input_file).expect("Couldn't read contents of input file"); + let mut score = 0; + let mut badge_score = 0; + let mut sacks = std::vec::Vec::::new(); + for line in contents.lines() { + if line.eq("") { + continue; + } + sacks.push(line.clone().to_string()); + if sacks.len() == 3 { + let a = get_common(&sacks[0], &sacks[1]).iter().cloned().collect::(); + let b = get_common(&sacks[1], &sacks[2]).iter().cloned().collect::(); + let sack_common = get_common(&a, &b); + assert_eq!(sack_common.len(), 1); + badge_score += get_priority(sack_common[0]); + sacks.clear(); + } + let (first, second) = line.split_at(line.len() / 2); + let common = get_common(&first.to_string(), &second.to_string()); + assert_eq!(common.len(), 1); + score += get_priority(common[0]); + } + println!("[PART 1] Score: {}", score); + println!("[PART 2] Score: {}", badge_score); +} + +fn get_common(first: &String, second: &String) -> std::vec::Vec:: { + let mut common = std::vec::Vec::::new(); + for x in first.chars() { + for y in second.chars() { + if x == y && !common.contains(&x) { + common.push(x); + } + } + } + return common; +} + +fn get_priority(value: char) -> u32 { + let priority = u32::from(value); + if priority < 97 { + return priority - 64 + 26; + } + return priority - 96; +}