Day 2 part 1
This commit is contained in:
parent
4b4ba0602d
commit
13e3a5202b
250
inputs/2.txt
Normal file
250
inputs/2.txt
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
cnjxpritdzhubeseewfmqagkul
|
||||||
|
cwyxpgitdzhvbosyewfmqagkul
|
||||||
|
cnfxpritdzhebosywwfmqagkul
|
||||||
|
cnjxpritdzgvbosyawfiqagkul
|
||||||
|
cnkxpritdzhvbosyewfmgagkuh
|
||||||
|
gnjxprhtdzhebosyewfmqagkul
|
||||||
|
cnjxpriedzevbosyewfjqagkul
|
||||||
|
cnjxpritdzhpyosyewfsqagkul
|
||||||
|
cnjxprltdzhvbosyewfmhagkzl
|
||||||
|
cnjxfritdjhvbosyewfmiagkul
|
||||||
|
xnjxpritdzhvbosyewfmqagkgn
|
||||||
|
cnjxpritdzmvzosyewfhqagkul
|
||||||
|
cljxxritdzhvbosyewfmragkul
|
||||||
|
cnjxjritdzhvbovyewfmvagkul
|
||||||
|
cnjxprdtdzhpbosyewvmqagkul
|
||||||
|
cojxprdtdzhzbosyewfmqagkul
|
||||||
|
cnjxpritgzhvfgsyewfmqagkul
|
||||||
|
knjxprptdzhvbosyecfmqagkul
|
||||||
|
cnjxpritdzhvbvsyeyfmqagkuc
|
||||||
|
cnjxpritdzhvbosvewfmoagjul
|
||||||
|
cnjxpritdzhvbosyfwfmbagkjl
|
||||||
|
cnjxpjitazhvbosfewfmqagkul
|
||||||
|
cnjtpfitdzhvbosyewfmiagkul
|
||||||
|
ckjxpritdzhvbysyewfmqagoul
|
||||||
|
cnjxvritdzhvbfsyewfmqalkul
|
||||||
|
cnjipqitdzhvbosyewfeqagkul
|
||||||
|
cnjhpritdzhvbosyewymqjgkul
|
||||||
|
cnjxprrtdzhvbosyewfmlkgkul
|
||||||
|
cnjxnritdzhvbopyewfmqaskul
|
||||||
|
cxjxpritdzhvtosyewjmqagkul
|
||||||
|
cnjxpritdzhvbjsyewfrqagkwl
|
||||||
|
cnjxhritdzhubosyewfmqagvul
|
||||||
|
cnjxpritdzhvbosyyyfmeagkul
|
||||||
|
cnjxkritdzhvaoeyewfmqagkul
|
||||||
|
cnjxpritdzhvtotyewfmqazkul
|
||||||
|
cnjxoriadzhvbosyewfmqcgkul
|
||||||
|
cnjxpritdzhcbosyewfmkapkul
|
||||||
|
fnjxprtddzhvbosyewfmqagkul
|
||||||
|
cnjxmvitdzhvbosyewfmqagrul
|
||||||
|
cnjxpyitdzhibosyewfmqagktl
|
||||||
|
cyjxprxtdzhvbosyewbmqagkul
|
||||||
|
onjxpditdzhvbosyeofmqagkul
|
||||||
|
cnjxprixdzhvbosuewftqagkul
|
||||||
|
cnjxpritdrhvaosyewymqagkul
|
||||||
|
cnjxpritdzhhbokyewfvqagkul
|
||||||
|
cnjxpritczhvbosyewfmqwgxul
|
||||||
|
cnjxpribdzqvbnsyewfmqagkul
|
||||||
|
ynpxpritdzhvbvsyewfmqagkul
|
||||||
|
cnjxprirdzhvboerewfmqagkul
|
||||||
|
cnjxpritdxhvbosyewfmgavkul
|
||||||
|
cnwxprntdzhvbosyewfmqagkuk
|
||||||
|
cnjxpritzzhvbosyewfmcagktl
|
||||||
|
bbjxpritdzhvbosyetfmqagkul
|
||||||
|
cnjxpbitdzhvbosyewrmqagkui
|
||||||
|
cnjxwrildzcvbosyewfmqagkul
|
||||||
|
cnqxpoitdzhvbosnewfmqagkul
|
||||||
|
cnzxpritdzhvbosyewfmqazkfl
|
||||||
|
cnjxpriddzhvoosyewfmhagkul
|
||||||
|
znjxpritdzhvbosjewfmqagkur
|
||||||
|
cnjxpritdzhvbosyewcmfagkuk
|
||||||
|
cnjxpritdzhvbomyywnmqagkul
|
||||||
|
cnjxpgitjzhvbosyejfmqagkul
|
||||||
|
cnjxpkitdzjvbosyewfmqcgkul
|
||||||
|
cnjxpritduhvbosyewfmqfkkul
|
||||||
|
cnfxpritdzhvbgsyewfmqwgkul
|
||||||
|
cnjxpritdzhvbosywufmqaskul
|
||||||
|
cnjxprittzhvboryswfmqagkul
|
||||||
|
cndxpritpzrvbosyewfmqagkul
|
||||||
|
cnjxpritdzhvbosyewfwqazkum
|
||||||
|
cccxprmtdzhvbosyewfmqagkul
|
||||||
|
cnjxpzitdzhvlbsyewfmqagkul
|
||||||
|
cnjxdrigdzhvbosyewfmqagsul
|
||||||
|
fhjxpritdzhvbosyewfmqagkcl
|
||||||
|
cnjxpritdzhvdosyewffqagaul
|
||||||
|
cnjxprikdztvbosyekfmqagkul
|
||||||
|
cnjxpritdzhvbohiewfmqagkue
|
||||||
|
cnjxpritdzhvbowyetfmqegkul
|
||||||
|
cnuxpritdzhvbosyewmmqapkul
|
||||||
|
qnjxpritdzhvbosyewfmjakkul
|
||||||
|
cnjxpritdzlvbosyewiaqagkul
|
||||||
|
cnjxpritdzhpoosyewfmvagkul
|
||||||
|
cdjxpritdzhvboryewfbqagkul
|
||||||
|
cnjxppitxzhvbosyewymqagkul
|
||||||
|
cnjxpywtdzhvboiyewfmqagkul
|
||||||
|
cnjxpritdzpvbosyezfmqaqkul
|
||||||
|
cnjppritdghvbosyewfdqagkul
|
||||||
|
cmjxpritdzhvbosvewfmqagkup
|
||||||
|
cnjxoritdzhvbosylffmqagkul
|
||||||
|
cnjxfritdzhvbojyewfmqagkvl
|
||||||
|
cnjxpritdzhvbozyewgmqlgkul
|
||||||
|
cnjxlritdzhvbosyewfmqalkug
|
||||||
|
cnyxprittzhvbosyewfmsagkul
|
||||||
|
cnjxprytdzcvdosyewfmqagkul
|
||||||
|
ctjxpritdzhvbosyedfmqagkil
|
||||||
|
cnjxpvitdzhrbosyewfmqaekul
|
||||||
|
cnyxyritdzhvbospewfmqagkul
|
||||||
|
cnjxoritwzhvbosyewrmqhgkul
|
||||||
|
cnjxpritdzhjbosyqwsmqagkul
|
||||||
|
cnjzprindzhvbosyewfmqabkul
|
||||||
|
cnjspritdzhvbosysffmqagkul
|
||||||
|
cnxxpritdzhvbosyelfmqageul
|
||||||
|
bnjhpritdzhvbosyewfmzagkul
|
||||||
|
cnjxbhitdzhdbosyewfmqagkul
|
||||||
|
cnjxprktdzmvbosyewfmqagkuj
|
||||||
|
cnjxprixdzhvbqsyewfmqmgkul
|
||||||
|
cnjxpkitdzhvbosyewfmqagbum
|
||||||
|
cnjhpritdzhxbosyewfmqagjul
|
||||||
|
cnjxpritdzzvbosyewuqqagkul
|
||||||
|
cnjxprhtdzhvuopyewfmqagkul
|
||||||
|
cnjxpritdzhjqosyewfmqagkgl
|
||||||
|
cnzxpritdzhvbosyejfmuagkul
|
||||||
|
cnvxpritoohvbosyewfmqagkul
|
||||||
|
cnjxpmitdzwvbosyemfmqagkul
|
||||||
|
cnjoprittzzvbosyewfmqagkul
|
||||||
|
cnjxpgitdzhvbosytwfmqsgkul
|
||||||
|
cnjxprrtdehvbosyewfnqagkul
|
||||||
|
onjxpjitdzgvbosyewfmqagkul
|
||||||
|
cnjxpmitdzhvbopaewfmqagkul
|
||||||
|
cnjxpritqzhvbosoewfrqagkul
|
||||||
|
cnjxpnitdzhvbosyewfmqagkjy
|
||||||
|
cnsxpritdzhvbosyewfmqjykul
|
||||||
|
cnjxpriidzhvbosyewfmqxgkut
|
||||||
|
cnjxpyitdzhnbosyewfgqagkul
|
||||||
|
cnjxpritdzhbboyyewfmqagsul
|
||||||
|
cnjxpeitdzsvbosyewfmqabkul
|
||||||
|
cnjxpritdzhzvosyewfmragkul
|
||||||
|
cnjrpritdzhmbosyewfmqrgkul
|
||||||
|
cnjxpritdzhmbosyenfmqaglul
|
||||||
|
cnjxqrntdzhvboswewfmqagkul
|
||||||
|
cnjxprdtpzhvbosyewfmqagkcl
|
||||||
|
cnjxpritdzhvsdsyewfmqagkur
|
||||||
|
cnjxpritdzhvvosyewumqhgkul
|
||||||
|
cnzxpritdznvhosyewfmqagkul
|
||||||
|
ynjypritdzhvbosyewfmqagkuz
|
||||||
|
cnjxpnitdzhvbocyezfmqagkul
|
||||||
|
vnjxpritdzhvbfsyewfmjagkul
|
||||||
|
cnjfpritdzhvbosyewfmqagkzu
|
||||||
|
cnjxpritdzhbbosyewfmlegkul
|
||||||
|
cnjxpnitdzhvbosyesfmbagkul
|
||||||
|
cnjxpritezwvbosyewfmqagkgl
|
||||||
|
cujxpritdzhqbosyawfmqagkul
|
||||||
|
cnjxprindzhrbosyerfmqagkul
|
||||||
|
cntxpritdzhvbosyewfmqauxul
|
||||||
|
cnjxpvitdzhvbosyepfmqagkuy
|
||||||
|
cnjxdrqtdzhvbosdewfmqagkul
|
||||||
|
cnnxpritdzhvvosyenfmqagkul
|
||||||
|
lnjxphitdzhvbosyewfaqagkul
|
||||||
|
cngxpritdzhhbobyewfmqagkul
|
||||||
|
uncxphitdzhvbosyewfmqagkul
|
||||||
|
cnjxpribdehvbosfewfmqagkul
|
||||||
|
cnjxppitdqhvbmsyewfmqagkul
|
||||||
|
gnjxpritkzhvbosyewfbqagkul
|
||||||
|
znjxpritdzhvbowycwfmqagkul
|
||||||
|
cnjxpgitdzhvbosyewidqagkul
|
||||||
|
cnjxhritdzhvbowyswfmqagkul
|
||||||
|
injxkritdzhvbjsyewfmqagkul
|
||||||
|
cmjupritgzhvbosyewfmqagkul
|
||||||
|
cnjxpritdzbvjoeyewfmqagkul
|
||||||
|
cnjxpritdkhvbosyewlmuagkul
|
||||||
|
cnkxpritdzhebvsyewfmqagkul
|
||||||
|
cyjxptitdzhvbosyewfmqagkuv
|
||||||
|
cnjxpritdzhvbodrewflqagkul
|
||||||
|
cnjxpratdzhvbksyewfhqagkul
|
||||||
|
cnjxpoitdzhvbosjewxmqagkul
|
||||||
|
cnjxprhidzhvbasyewfmqagkul
|
||||||
|
cnjxpritdzhvbosqewvmqagmul
|
||||||
|
cnjxoritdzhvbosyzifmqagkul
|
||||||
|
mnjxpritdzhvbcsyeyfmqagkul
|
||||||
|
cnjhpritgzhvbosyewfmqngkul
|
||||||
|
cnjxprijdzevbesyewfmqagkul
|
||||||
|
cnexprqtdzhvbosyewvmqagkul
|
||||||
|
cnjxpxitdzhvbosyawfmqmgkul
|
||||||
|
cnjxpritdzhvbosyirfmqaxkul
|
||||||
|
cqjxpcitdzhvboslewfmqagkul
|
||||||
|
cmjxpqitdztvbosyewfmqagkul
|
||||||
|
cnbxpritdzhvfosyewfmuagkul
|
||||||
|
cnjxprrtdzhvbosumwfmqagkul
|
||||||
|
cnjxprttdvhvbossewfmqagkul
|
||||||
|
cnjxpritdzhvbcsuewfaqagkul
|
||||||
|
cbjxpritdzhvbosyewfhqalkul
|
||||||
|
cnjxprithzhvbosjcwfmqagkul
|
||||||
|
chjxpritdzhvbosyewftcagkul
|
||||||
|
cnjxprirdchvdosyewfmqagkul
|
||||||
|
cnjxpritdxhvbosyewfmqcgkal
|
||||||
|
cnjxpriidchvbosrewfmqagkul
|
||||||
|
cnjhprizdzhvbosyewfmqagvul
|
||||||
|
cnjwpritdzhpbosyewfmqaqkul
|
||||||
|
cnjxpgitfzhvbosyxwfmqagkul
|
||||||
|
cnjxpjiedzhvbosywwfmqagkul
|
||||||
|
cnjxpritdzhvbosyewfpqynkul
|
||||||
|
xnixlritdzhvbosyewfmqagkul
|
||||||
|
cnjxoritdznvbosyehfmqagkul
|
||||||
|
cnjxpritdzhvbjsyewsmqagcul
|
||||||
|
lnjxpritdzhvkosyewjmqagkul
|
||||||
|
cnjxpritdzhvbosyedfiqvgkul
|
||||||
|
cnjxpritdzhqbdsyerfmqagkul
|
||||||
|
cnjxpritdzavbosyywfmqagvul
|
||||||
|
dmjxprithzhvbosyewfmqagkul
|
||||||
|
cnjxpriqdzhvnosyeofmqagkul
|
||||||
|
cnjxpritdxhvboszewfmqkgkul
|
||||||
|
cnjxpritdzxvbosjewymqagkul
|
||||||
|
cnjxpritdzngbosyewfmqugkul
|
||||||
|
cajxpritdnhvbosyerfmqagkul
|
||||||
|
cnsxpritdzhvbosymwfmqagcul
|
||||||
|
cnjxoritdzhvbosyewrmqhgkul
|
||||||
|
cnjxpritdzhvposyewfmqagkwo
|
||||||
|
cnjxpriazzhvbosyeufmqagkul
|
||||||
|
cnjxrritdzhvbosymhfmqagkul
|
||||||
|
cnjxprztdzhvbosyewfmqtgkum
|
||||||
|
cnjxpritdzhvbmsyewfmqatkun
|
||||||
|
cnuxpritdzhvbosyewfmqagvur
|
||||||
|
ctjxxritdzhvbosyewfvqagkul
|
||||||
|
cnjxpritdzlvbosyevfmqagkll
|
||||||
|
cnjxpritdzhlbosyewfmqagasl
|
||||||
|
cnjxpritwzhvbosyewfcxagkul
|
||||||
|
cyjxpritdzhfbosyewfmqagcul
|
||||||
|
cnjxpritxghvkosyewfmqagkul
|
||||||
|
ctjxpritdjhvbosyewfmqkgkul
|
||||||
|
cnjxpritxzhvbosyewjmbagkul
|
||||||
|
unjxpritdzhkbosyewfmqaghul
|
||||||
|
cnjoprqtdzhvbosyewzmqagkul
|
||||||
|
rnjxprgtgzhvbosyewfmqagkul
|
||||||
|
cnjgpqitdzhvbosyewfaqagkul
|
||||||
|
cnjxpritdzuybosyewfmqagful
|
||||||
|
cnjxprqtdahvbosyewfnqagkul
|
||||||
|
cnjxpritdzhmkhsyewfmqagkul
|
||||||
|
wnjxpritdzhvbosiewfmqagkml
|
||||||
|
cnjmpritdzhvbosyjwfmqagkdl
|
||||||
|
cnjopritdzhvbksyewfmqrgkul
|
||||||
|
cnlxpritdzhvbosyewfmomgkul
|
||||||
|
cgjxpritdzhvbbsyewfmxagkul
|
||||||
|
cnaxpritdvhvnosyewfmqagkul
|
||||||
|
cnjxprijdzhvbkmyewfmqagkul
|
||||||
|
cnjxpritdzhvposyewzmqagkuz
|
||||||
|
cnuxpuitdzdvbosyewfmqagkul
|
||||||
|
cnjxprifdzjvbosyewfyqagkul
|
||||||
|
cnhspritdzhvbosyewfmqaghul
|
||||||
|
cnjxprcbdzfvbosyewfmqagkul
|
||||||
|
lnjapritdzhvbosyewfmqegkul
|
||||||
|
cnjxprisszhvbosyewqmqagkul
|
||||||
|
cnjxpritdzhvbosyeifmsagoul
|
||||||
|
cnjxpritrfhvbosyewfmqagkuz
|
||||||
|
cnjxkritdzmvboqyewfmqagkul
|
||||||
|
cnjxpritdzhvbosyedfmqzgkzl
|
||||||
|
cnjxprifdzhvbosyswfmqagksl
|
||||||
|
cnjxoritdzhvbosyxwfmhagkul
|
||||||
|
cnjhpritdzzvbosfewfmqagkul
|
||||||
|
cnjxprityjhvbomyewfmqagkul
|
||||||
|
cnjbpritdzhvbosyywfmqagkuf
|
||||||
|
cnjxprrtdzhvbosyewgmqagtul
|
7
inputs/2_test.txt
Normal file
7
inputs/2_test.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
abcdef
|
||||||
|
bababc
|
||||||
|
abbcde
|
||||||
|
abcccd
|
||||||
|
aabcdd
|
||||||
|
abcdee
|
||||||
|
ababab
|
43
src/day2.rs
Normal file
43
src/day2.rs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
const INPUT: &str = "inputs/2.txt";
|
||||||
|
|
||||||
|
pub fn solve() -> Result<usize, Box<Error>> {
|
||||||
|
calculate_checksum(INPUT)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn calculate_checksum(filename: &str) -> Result<usize, Box<Error>> {
|
||||||
|
let mut two_count = 0;
|
||||||
|
let mut three_count = 0;
|
||||||
|
let file = File::open(filename)?;
|
||||||
|
for line in BufReader::new(file).lines() {
|
||||||
|
let mut char_map: HashMap<char, usize> = HashMap::new();
|
||||||
|
for c in line?.chars() {
|
||||||
|
let current_count = char_map.get(&c).unwrap_or(&0);
|
||||||
|
char_map.insert(c, current_count + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if char_map.values().any(|&count| count == 2) {
|
||||||
|
two_count += 1
|
||||||
|
}
|
||||||
|
if char_map.values().any(|&count| count == 3) {
|
||||||
|
three_count += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(two_count * three_count)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
const TEST_INPUT: &str = "inputs/2_test.txt";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn calculates_correct_checksum() {
|
||||||
|
assert_eq!(calculate_checksum(TEST_INPUT).unwrap(), 12);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,9 @@
|
|||||||
mod day1;
|
mod day1;
|
||||||
|
mod day2;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Day 1:");
|
println!("Day 1:");
|
||||||
println!("{}", day1::solve().unwrap());
|
println!("{}", day1::solve().unwrap());
|
||||||
|
println!("Day 2:");
|
||||||
|
println!("{}", day2::solve().unwrap());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user