Challenge two
This commit is contained in:
parent
570172f32f
commit
9fcba93cd9
250
input/02.txt
Normal file
250
input/02.txt
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
pnebjqralgdgckzfifvtxywomu
|
||||||
|
pnebjqsalrdgcqzfihotxhwomu
|
||||||
|
pneajqsalrdgckzfihytxywoml
|
||||||
|
pnepjqsalrwgckztihvtxywomu
|
||||||
|
pnhbjqsalrdgckzfimvtxywodu
|
||||||
|
pnwbjqsdlrdgckzfihvnxywomu
|
||||||
|
inebjqnalrdgckzfihvtxzwomu
|
||||||
|
pnebjssalhdgckzfihvtsywomu
|
||||||
|
pnebjqjalrdgckzfiavtxywoku
|
||||||
|
vnebjqsalrdgckzfihvbxmwomu
|
||||||
|
phebjksaurdgckzfihvtxywomu
|
||||||
|
pneojqealrdgckzhihvtxywomu
|
||||||
|
snebjqsalrdgckzqihvtxyzomu
|
||||||
|
pnebjqsalrtackzfihvtxswomu
|
||||||
|
bnebjqlalrdgckzfihvtxywhmu
|
||||||
|
pnebjqfalrdgckzfijvtxywomi
|
||||||
|
fnehjbsalrdgckzfihvtxywomu
|
||||||
|
pnebjasalrdgckzdihvtxqwomu
|
||||||
|
pnebjhsaljdgckzfihvtxywmmu
|
||||||
|
pnebjqsalrdgckzfihvsxykoau
|
||||||
|
pnebjqsalrdgckzbihvtdywomc
|
||||||
|
pnobjqsalrxgckzfihvtxywomh
|
||||||
|
pnebjqstlrdgchzfihvtxywnmu
|
||||||
|
pnebjquaxrdgckzfihvtxywolu
|
||||||
|
pqebjqsalrdgcdzfihvtcywomu
|
||||||
|
xnabjqsalrdgckzfihvtxywmmu
|
||||||
|
rnebjqsalrdgckzfihvtxmwouu
|
||||||
|
vaebjqsalrdgckcfihvtxywomu
|
||||||
|
pnebjqsalrpgcnzfihvbxywomu
|
||||||
|
pcvbjqsalrdjckzfihvtxywomu
|
||||||
|
pneyjqsafrdgckzfihdtxywomu
|
||||||
|
pxedjqsalrdgckzfihvtxyzomu
|
||||||
|
pnebjqsalrdgctzfihnyxywomu
|
||||||
|
pnebjqsalrdgckzfihvtnylsmu
|
||||||
|
pnebjqsalrdyckzfihvbxycomu
|
||||||
|
fnebjqsalrdgckzfihvtxtwomc
|
||||||
|
pnobjqsalrdgckdfihvtxywomh
|
||||||
|
pqebjqsalrdgcqzfihvtxywymu
|
||||||
|
pnebxqsalrdgckzficvtwywomu
|
||||||
|
pnebjqshlragczzfihvtxywomu
|
||||||
|
pnebqqsalrdackzfihttxywomu
|
||||||
|
pnebjqsalrdsckwfbhvtxywomu
|
||||||
|
pnehjqsalrdgcuzfxhvtxywomu
|
||||||
|
pnebjqsavrdgckzfihvexywomn
|
||||||
|
pnebunsalrdgckzfihvtxywomi
|
||||||
|
pnebjxsalrdgckzfmhvtpywomu
|
||||||
|
rnebjqsalrdghkzfihztxywomu
|
||||||
|
pnebjqsalrigcbzfihvfxywomu
|
||||||
|
pnebqqsalrggckzfihvtxyromu
|
||||||
|
pnebjqsalrdgchzfihvtxylmmu
|
||||||
|
pnebeqsalrdgckzdihvtxywoms
|
||||||
|
pnebjqsalrdgckzzihvfxywozu
|
||||||
|
pnzbjgsalrtgckzfihvtxywomu
|
||||||
|
pnebjqsaledgckzjihvtxzwomu
|
||||||
|
pnebjqsalydgckqfihvtxywouu
|
||||||
|
pnebjqsalrdgckufihvqxdwomu
|
||||||
|
pnebjqsylrdgckzfihvdxyjomu
|
||||||
|
pnemjqsalrdgckzeihvtxywoqu
|
||||||
|
plebjasalrdgckzfihvtxywomb
|
||||||
|
pnebjqsadrdgckufihvtxyfomu
|
||||||
|
pbebjqsaardgckzfihvtxmwomu
|
||||||
|
pnebjqsalrdgcmzfihotxywgmu
|
||||||
|
pnebjqsaprdgcizfihvtxywhmu
|
||||||
|
pnebjqsalrkgcuzfihvtlywomu
|
||||||
|
pnebjqsalrdnckzfihvtxysomg
|
||||||
|
pnebjqdafrdgckzfihctxywomu
|
||||||
|
pnebjqsalrdgckzfihutxkwomp
|
||||||
|
pnebvqsalrdgclzfimvtxywomu
|
||||||
|
pnebjqralrdgcktfihvtxiwomu
|
||||||
|
pneujqsalrdsckzfzhvtxywomu
|
||||||
|
pnebfqgalrdgckzfihvtxywjmu
|
||||||
|
pneyjqsalrkgckzfihctxywomu
|
||||||
|
pndbjqsalrdgckzfjhvtxywouu
|
||||||
|
pneljnsalrdgcozfihvtxywomu
|
||||||
|
phebjqsalrdgckzfihxtxdwomu
|
||||||
|
pnlbjqsalrhgckzfzhvtxywomu
|
||||||
|
pnebjqsalrsgckzfiovtxywwmu
|
||||||
|
pncbjqsalrdgfkzfivvtxywomu
|
||||||
|
nnebjqsalrdgckzfthvtxycomu
|
||||||
|
pnebjqwalsdgckzfixvtxywomu
|
||||||
|
pnebjtsalrdgcfzfimvtxywomu
|
||||||
|
pnebjqsvlrdgckzfihutxfwomu
|
||||||
|
pnebjmsalrdgckzkxhvtxywomu
|
||||||
|
pnekjqsllrdgckzfinvtxywomu
|
||||||
|
pneijqsxlrdgckzfihvtxywjmu
|
||||||
|
wnxbjqsafrdgckzfihvtxywomu
|
||||||
|
pnebjqskledgokzfihvtxywomu
|
||||||
|
pnebjqvalrdgckzfihvtxytoju
|
||||||
|
pneqjqsalrdgckzfilvthywomu
|
||||||
|
pnebjqsalrdgckzfihvokywomf
|
||||||
|
bnebjqsalrdgckufihvtxywimu
|
||||||
|
pnebjqsaurdgckzfihvtrywosu
|
||||||
|
pnebjmsaludgckzfihvtxywomn
|
||||||
|
pnebdqsalrdgcktfihvtxywodu
|
||||||
|
pnebjqjylzdgckzfihvtxywomu
|
||||||
|
piebjqsalrdgcrzfihstxywomu
|
||||||
|
pnebjqsaurdgckwfnhvtxywomu
|
||||||
|
pnebxqsajrdgcjzfihvtxywomu
|
||||||
|
pnebjqsalrdghsdfihvtxywomu
|
||||||
|
pnebcqsxlrdgckzfihvtxyaomu
|
||||||
|
pnefjqsalrdgckzfuhvtxyworu
|
||||||
|
pnebjqsalrdlcksfihvteywomu
|
||||||
|
pnebjqlalrgackzfihvtxywomu
|
||||||
|
pnebdqsalrdickzfihvtxdwomu
|
||||||
|
pneujksalrdgctzfihvtxywomu
|
||||||
|
pnebjqsalrduckzfihvsxywomf
|
||||||
|
pnebjqsalrdgckcfihotxywomd
|
||||||
|
envbjqsalsdgckzfihvtxywomu
|
||||||
|
pnebjqsalzdgcvzzihvtxywomu
|
||||||
|
pnebjqsalrdyckzflhvyxywomu
|
||||||
|
pnebjqsalrdglkzfihstxymomu
|
||||||
|
pnebmqsalrdgokzfihvtxywoml
|
||||||
|
pnebjqsylrdnckzfihatxywomu
|
||||||
|
pnebjqaflndgckzfihvtxywomu
|
||||||
|
pneboqsagragckzfihvtxywomu
|
||||||
|
peebjqstlndgckzfihvtxywomu
|
||||||
|
onebjqsklrdgckzfihvtxmwomu
|
||||||
|
pnebjqjnlrdgckrfihvtxywomu
|
||||||
|
pnebjqsalrhgckzfihvqxywomh
|
||||||
|
pnebjqsalrdgckzzihvtxowomw
|
||||||
|
pnebjgsalrdgckffihltxywomu
|
||||||
|
znebaqsalcdgckzfihvtxywomu
|
||||||
|
pnnbjqeasrdgckzfihvtxywomu
|
||||||
|
rnebjqaalrxgckzfihvtxywomu
|
||||||
|
pnebjqsalrdgckaxphvtxywomu
|
||||||
|
pnebjcnalrdgnkzfihvtxywomu
|
||||||
|
pnebjasalbdgckzmihvtxywomu
|
||||||
|
pnebjqsalrdgckefjhvtmywomu
|
||||||
|
pnebjqsalrdgmkzfihvtxyoomb
|
||||||
|
pnebjqsalrkgckogihvtxywomu
|
||||||
|
pnwbjqsalrdgckztihvtxywomt
|
||||||
|
pnebjqsalrdgckzfihotgnwomu
|
||||||
|
pnebjqsdlrrgckzfihvtxyaomu
|
||||||
|
pnebvasalrdgckzfihvtsywomu
|
||||||
|
pnebrqqalrvgckzfihvtxywomu
|
||||||
|
tnebjqsglrdgqkzfihvtxywomu
|
||||||
|
pnebjqsatrsgckifihvtxywomu
|
||||||
|
pneboqsalrdgckzfihvkxywomi
|
||||||
|
pnezaqsalrdgcktfihvtxywomu
|
||||||
|
pnebjqsnlrdgckzfihvfxqwomu
|
||||||
|
pneajqsaxrmgckzfihvtxywomu
|
||||||
|
pnebjosalodgckzfihvxxywomu
|
||||||
|
pnebjqsalndgckmfihvtfywomu
|
||||||
|
pneejqsalidgckzfihgtxywomu
|
||||||
|
pnecjqsalrdgckzfihptxiwomu
|
||||||
|
tnebjqsalrdgckznihvxxywomu
|
||||||
|
ptebjqsalrdgckzfimvtxywomm
|
||||||
|
wnebjqsalndgckzfihvtxywoju
|
||||||
|
fnebmqsplrdgckzfihvtxywomu
|
||||||
|
pnlbjqsalrdghkzficvtxywomu
|
||||||
|
pnebjqsesrdgckzdihvtxywomu
|
||||||
|
pnebjqsalregokzfirvtxywomu
|
||||||
|
pnebjtualrtgckzfihvtxywomu
|
||||||
|
pnebjwsdlrdgckzfihvtxywoml
|
||||||
|
pnlbjqsayrdgckzfqhvtxywomu
|
||||||
|
pnebjwsalpdgckzfihvtxywomc
|
||||||
|
pnqbjqsalcdgckzhihvtxywomu
|
||||||
|
pneujqsalrdgckzfhhvtxrwomu
|
||||||
|
pnebjqsalqdgcizfihvtxywimu
|
||||||
|
pnebjqsacldgckzfihvwxywomu
|
||||||
|
puebjqsalrdgckzfbhvtxyeomu
|
||||||
|
pnebjqsalrdgcyimihvtxywomu
|
||||||
|
pnebjlsalrdgckzfihvtxiwome
|
||||||
|
pnebfusalrdgckzfihvtxywodu
|
||||||
|
pnebjqsalrdgvazfirvtxywomu
|
||||||
|
pnebjqsalrdgckyfohvtxywomz
|
||||||
|
gnenjqsalrdgckzfihvtxynomu
|
||||||
|
mnebjqsalrdgckhfihvtxycomu
|
||||||
|
phebjqsalrdgckzfihvtxtworu
|
||||||
|
pnebjqsalrdgdkzfihvtxywfmj
|
||||||
|
pneveqsairdgckzfihvtxywomu
|
||||||
|
pnebjqsalcdlckzfihvtxywomg
|
||||||
|
pneajqsalrdgckzfihvtxygoxu
|
||||||
|
puebjqdclrdgckzfihvtxywomu
|
||||||
|
tuebjqsalrdgckzfihvtxywoou
|
||||||
|
pwenjqsalrdgckzfihvtxywomg
|
||||||
|
pnebjqsalrdgckzfihhltywomu
|
||||||
|
pnebjqsalrdgchzqievtxywomu
|
||||||
|
pnegjqsalrdgckzfiovtxywdmu
|
||||||
|
pnebjaralrqgckzfihvtxywomu
|
||||||
|
pnebjqsalrdrckzfimvtxywomm
|
||||||
|
pnebjqsalrdgckzfpgvtxewomu
|
||||||
|
pnebjqsalrdhcqzfihitxywomu
|
||||||
|
pnebjqsalrjgckefihmtxywomu
|
||||||
|
pnebjcsalrdgcksfikvtxywomu
|
||||||
|
pnebjqsalrdgckzfihvtxywdjc
|
||||||
|
pnebjqsazrjgckzjihvtxywomu
|
||||||
|
pnfbjqsclrdgckzfihvtxybomu
|
||||||
|
pnebjqsalrdgckuqihvtxyaomu
|
||||||
|
pfpbjzsalrdgckzfihvtxywomu
|
||||||
|
pnevjqsalrdgckwfihytxywomu
|
||||||
|
pnebjqsqlrkgckzfihvtvywomu
|
||||||
|
pneejqsalrdlckzfihvtxywopu
|
||||||
|
pnebjqsalcdgxkzfihvtxywomd
|
||||||
|
pneqjqsalrdgcvzzihvtxywomu
|
||||||
|
pnvbjqsalydgctzfihvtxywomu
|
||||||
|
pnebjqsalrdgckzzihvfxywomn
|
||||||
|
pnybjqsaerdgckzfihstxywomu
|
||||||
|
pnobjqsalrdkckzfihvtxywomv
|
||||||
|
pnebjqsalridckzfihvtxywfmu
|
||||||
|
pnhbjqsaludgckyfihvtxywomu
|
||||||
|
pnetjqsaprdgykzfihvtxywomu
|
||||||
|
wnebjqsalrdvcfzfihvtxywomu
|
||||||
|
pnetjqsalrdmckwfihvtxywomu
|
||||||
|
pnebjysalrdgcszfihvtxnwomu
|
||||||
|
pnebjqsrlrdgckzfihvtxywkhu
|
||||||
|
pnubjqsplrdgcjzfihvtxywomu
|
||||||
|
pnebjqsalrdzckzficjtxywomu
|
||||||
|
pnebjqsalregckzfinvtxywoku
|
||||||
|
pnebjqsalrcgckyfivvtxywomu
|
||||||
|
pyenjqsalrdgckzfihvnxywomu
|
||||||
|
prebjqsalrdnckzfihvtxysomg
|
||||||
|
pnebjnsalrdgchzfihvaxywomu
|
||||||
|
pnebjqsalrdgckzfihxagywomu
|
||||||
|
pnebjqsalrdgckzvihvtoywoml
|
||||||
|
pnebjqsilrdgckzfihvtfywgmu
|
||||||
|
pnebjqmalrdgckzfihvtvawomu
|
||||||
|
pnebqqsalrdgckzfiuvtfywomu
|
||||||
|
pneqjqsalrdgckzfihvqxywomi
|
||||||
|
pnebjesalrsgckzfihvtxywmmu
|
||||||
|
znebjqsblrdgckzfihvlxywomu
|
||||||
|
pnebjqsalrdgckzfuhvtlyworu
|
||||||
|
pnebjqsylrdgckzfihvqxpwomu
|
||||||
|
onebjqsalfdgckifihvtxywomu
|
||||||
|
pnebjusalrdgckzfihvtxywyml
|
||||||
|
pnebjssflrdgckzfigvtxywomu
|
||||||
|
pnebjfsdzrdgckzfihvtxywomu
|
||||||
|
pnebjqsalrdgcktfihvixywocu
|
||||||
|
gnebjqnaqrdgckzfihvtxywomu
|
||||||
|
pnebjqsaqrugckzfihhtxywomu
|
||||||
|
pnebjqsxlrdgckzfihvtxlwosu
|
||||||
|
pnebjzsalrdgckzmihvtxywovu
|
||||||
|
pnebgqsalrdgckzfizvtxyjomu
|
||||||
|
pnebjqsmlrdgckzfihvtxywsmi
|
||||||
|
pnebjqsakmdgckzjihvtxywomu
|
||||||
|
pnebjqdglrdgckvfihvtxywomu
|
||||||
|
pnebmhsalrdgckxfihvtxywomu
|
||||||
|
pneejqsalrdlckzfihvnxywomu
|
||||||
|
bnebjqsalmdgckzfihvfxywomu
|
||||||
|
bnebjnsalrdgcizfihvtxywomu
|
||||||
|
pnebjqsalhdgcdzfihvbxywomu
|
||||||
|
pnebjqsjlrdgckzfihvgiywomu
|
||||||
|
pnebjisalrdgckzfihvtxywqmi
|
||||||
|
pdebjqsalrdickzfihhtxywomu
|
||||||
|
pnebjqsalrdkckzfihvjeywomu
|
||||||
|
pneyjqsalrqgckzfihvtxywohu
|
||||||
|
pnebjqsalrdgckcfihvtxjlomu
|
||||||
|
plebqwsalrdgckzfihvtxywomu
|
||||||
|
pnebjqlalrdgckzfihetxynomu
|
||||||
|
sngbjqsalrdgckzfihvmxywomu
|
@ -1,6 +1,6 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub fn run(input: &[String], part: u8) -> String {
|
pub fn run(input: &[&str], part: u8) -> String {
|
||||||
let encoded: Vec<_> = input.iter().map(|i| i.parse::<i32>().unwrap()).collect();
|
let encoded: Vec<_> = input.iter().map(|i| i.parse::<i32>().unwrap()).collect();
|
||||||
match part {
|
match part {
|
||||||
1 => c_01_1(&encoded),
|
1 => c_01_1(&encoded),
|
||||||
|
118
src/aoc/c02.rs
Normal file
118
src/aoc/c02.rs
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
pub fn run(input: &[&str], part: u8) -> String {
|
||||||
|
match part {
|
||||||
|
1 => c_02_1(input).to_string(),
|
||||||
|
2 => c_02_2(input),
|
||||||
|
_ => panic!("unknown part"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn c_02_1(input: &[&str]) -> i32 {
|
||||||
|
let mut three = 0;
|
||||||
|
let mut two = 0;
|
||||||
|
for val in input {
|
||||||
|
let mut m = HashMap::new();
|
||||||
|
|
||||||
|
for c in val.chars() {
|
||||||
|
let new_val =match m.get(&c) {
|
||||||
|
Some(v) => *v+1,
|
||||||
|
None => 1
|
||||||
|
};
|
||||||
|
|
||||||
|
m.insert(c.clone(), new_val);
|
||||||
|
}
|
||||||
|
|
||||||
|
three += match m.iter().filter(|(_, v)| **v == 3).next() {
|
||||||
|
Some(_) => 1,
|
||||||
|
None => 0
|
||||||
|
};
|
||||||
|
two += match m.iter().filter(|(_, v)| **v == 2).next() {
|
||||||
|
Some(_) => 1,
|
||||||
|
None => 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
three * two
|
||||||
|
}
|
||||||
|
|
||||||
|
fn c_02_2(input: &[&str]) -> String {
|
||||||
|
for val1 in input {
|
||||||
|
for val2 in input {
|
||||||
|
let mut diff = 0;
|
||||||
|
let mut val2char = val2.chars();
|
||||||
|
for val1char in val1.chars() {
|
||||||
|
match val2char.next() {
|
||||||
|
Some(v) => {
|
||||||
|
if v != val1char {
|
||||||
|
diff += 1;
|
||||||
|
if diff > 1 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if diff == 1 {
|
||||||
|
let mut s = String::new();
|
||||||
|
for (i, c) in val1.chars().enumerate() {
|
||||||
|
if c == val2.chars().nth(i).unwrap() {
|
||||||
|
s.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn c_02_1_examples() -> Result<(), String> {
|
||||||
|
let mut examples: HashMap<&[&str], i32> = HashMap::new();
|
||||||
|
examples.insert(
|
||||||
|
&[
|
||||||
|
"abcdef", "bababc", "abbcde", "abcccd", "aabcdd", "abcdee", "ababab",
|
||||||
|
],
|
||||||
|
12,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (input, out) in examples.iter() {
|
||||||
|
let actual = c_02_1(input);
|
||||||
|
if &actual != out {
|
||||||
|
return Err(format!("Got: {}, Want: {}", actual, out));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn c_02_2_examples() -> Result<(), String> {
|
||||||
|
let mut examples: HashMap<&[&str], &str> = HashMap::new();
|
||||||
|
examples.insert(
|
||||||
|
&[
|
||||||
|
"abcde", "fghij", "klmno", "pqrst", "fguij", "axcye", "wvxyz",
|
||||||
|
],
|
||||||
|
"fgij",
|
||||||
|
);
|
||||||
|
|
||||||
|
for (input, out) in examples.iter() {
|
||||||
|
let actual = c_02_2(input);
|
||||||
|
if &actual != out {
|
||||||
|
return Err(format!("Got: {}, Want: {}", actual, out));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
mod c01;
|
mod c01;
|
||||||
|
mod c02;
|
||||||
|
|
||||||
pub fn run(input: &[String], challenge: u8, part: u8) -> String {
|
pub fn run(input: &[&str], challenge: u8, part: u8) -> String {
|
||||||
match challenge {
|
match challenge {
|
||||||
1 => c01::run(input, part),
|
1 => c01::run(input, part),
|
||||||
|
2 => c02::run(input, part),
|
||||||
_ => panic!("challenge not implemented"),
|
_ => panic!("challenge not implemented"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,5 @@ fn main() {
|
|||||||
.map(|v| v.to_string())
|
.map(|v| v.to_string())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
println!("{}", aoc::run(&lines, challenge, part));
|
println!("{}", aoc::run(&(lines.iter().map(|s| s.as_str()).collect::<Vec<&str>>() ), challenge, part));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user