day 2 solution
parent
21d0ccd59a
commit
59c1563ace
|
@ -0,0 +1,14 @@
|
|||
[[package]]
|
||||
name = "day2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"edit-distance 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "edit-distance"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum edit-distance 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3bd26878c3d921f89797a4e1a1711919f999a9f6946bb6f5a4ffda126d297b7e"
|
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "day2"
|
||||
version = "0.1.0"
|
||||
authors = ["Andrew Coleman <penguincoder@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
edit-distance = "2.0.0"
|
|
@ -0,0 +1,250 @@
|
|||
qywzphxoiseldjrbaoagvkmanu
|
||||
qywzphxeisulpjrbtfcgvkmanu
|
||||
qywzxhooiseldjrbtfcgvcmanu
|
||||
qywzphjojseldjubtfcgvkmanu
|
||||
qtwzphxoieeldjrbtfcgvrmanu
|
||||
tywzphzoiseldjritfcgvkmanu
|
||||
qyuzphxoiseldjrbtfcgykbanu
|
||||
qswzmhxoiseldjrbtfcgvkaanu
|
||||
qyczqhxoiseldjrbtfcgvkbanu
|
||||
qybzpqxooseldjrbtfcgvkmanu
|
||||
qywzpoxoxseldjrbtfcgvpmanu
|
||||
qywzphxbipeldjrbtfcgvkmaru
|
||||
qywzpmxoiseldjrutqcgvkmanu
|
||||
qywzphxoisesdjrrtfchvkmanu
|
||||
qywzphxoiseldhrbtfcgukyanu
|
||||
jywzphyoiseldjrbtfclvkmanu
|
||||
qywzvhxoiselrjrbtfcgvkmanl
|
||||
qywzplxojseldjrbtfcgvkmamu
|
||||
qywzphxoiseldjrbtacgvkmvnd
|
||||
qywpphxoiseldjrbtfcgvkvenu
|
||||
qqazphxoiselqjrbtfcgvkmanu
|
||||
qyozvhxoiseldjrbtfcgvkmadu
|
||||
xywzphxliseldjhbtfcgvkmanu
|
||||
qdwzphioiseldqrbtfcgvkmanu
|
||||
qswyphxoiseldjrbtfcgvkmanx
|
||||
qowzshxoiseldjrbtfigvkmanu
|
||||
qywzphxoiseldjjbtfcgvkmawq
|
||||
qyhzphxoiseldjrbtfvgvkmynu
|
||||
qxwzphxoiselmjrbtfcgvqmanu
|
||||
qywzphxoiceldjrbtfcgikmgnu
|
||||
qywephxoiseldjrbthcgvkmane
|
||||
yywzphxoisejdjrotfcgvkmanu
|
||||
qywzxhxoisyldyrbtfcgvkmanu
|
||||
qywzpjxoiseqdjrbtfcgvwmanu
|
||||
qywzphxoqweldprbtfcgvkmanu
|
||||
qywzphnoiseldjrbtfcamkmanu
|
||||
qylgphxoiseldjrbtfcgvkmauu
|
||||
qysdphxomseldjrbtfcgvkmanu
|
||||
lywzpoxoikeldjrbtfcgvkmanu
|
||||
qywzphxgiseldjrbtfeqvkmanu
|
||||
qywzdhxozseldjcbtfcgvkmanu
|
||||
qywzphxeiskedjrbtfcgvkmanu
|
||||
qmwzphxoispldjrbtfcgvkmany
|
||||
qywzphxoiselzcrbtfcgvkmanz
|
||||
qywzphxoisxodjrbtscgvkmanu
|
||||
qywzphxoiseldjrrtfcgmkmaeu
|
||||
aywzphxoiseldjrbtfmjvkmanu
|
||||
qywzthxoiiewdjrbtfcgvkmanu
|
||||
qywzpsxoisrzdjrbtfcgvkmanu
|
||||
qywzphxoiseldjkbtqcgvkmank
|
||||
tywzphxoisewdjkbtfcgvkmanu
|
||||
qywkchxoiseldjrbtfcghkmanu
|
||||
qywzphxoiseldjoftfrgvkmanu
|
||||
qywzpixoisehdjrbtfcgvkmacu
|
||||
qywzchooiseldarbtfcgvkmanu
|
||||
qywyphtoaseldjrbtfcgvkmanu
|
||||
qywyphxotsbldjrbtfcgvkmanu
|
||||
qywzphxoiseldjrbhsggvkmanu
|
||||
dywzphxoiseldjrktfegvkmanu
|
||||
qywzphxoiseldjrmtfcgvkcenu
|
||||
qywcphxjiseldjybtfcgvkmanu
|
||||
qywzphxoiseldhrbsfogvkmanu
|
||||
qmwzpheoiseldjrrtfcgvkmanu
|
||||
qywzrhxoiselpjrbtfcgvemanu
|
||||
qyezphpoiseldjrbtfcgvdmanu
|
||||
qywzphxvisewdjrbtfcgvkmdnu
|
||||
qywzphkoiseldjrbtfcgvkmdnh
|
||||
qywzehxoiseldfrbtpcgvkmanu
|
||||
qywzphxoiseldjrrtfcgvrdanu
|
||||
qpwzphxoizeldjqbtfcgvkmanu
|
||||
qywzphxojseldjrbtmcgvkmvnu
|
||||
vywzphxoiseldjrbtfcgvkmaop
|
||||
sywzphxoiselbjrttfcgvkmanu
|
||||
qywwphkoiseldjrbtfcivkmanu
|
||||
qlwkpcxoiseldjrbtfcgvkmanu
|
||||
qywzphxoiyesdjrbtfcgvkmvnu
|
||||
qywzphxoiseldjrbofcgrkmrnu
|
||||
qywzphxyiseldjrstfcgvkmjnu
|
||||
qywzphaoiseldtrbnfcgvkmanu
|
||||
qywzphxhisuldurbtfcgvkmanu
|
||||
qywzphxdiseldjrbtvugvkmanu
|
||||
qywzpzxbiseldjrbtfcgukmanu
|
||||
qyrzphxoixeldjrbtfcgvumanu
|
||||
qywzphxoiberdjrptfcgvkmanu
|
||||
qywzphxfiskldjrbtfcgvkmdnu
|
||||
qyxzphxoiseldjrdhfcgvkmanu
|
||||
qywzphrqiseldjrbtfcgvbmanu
|
||||
qyezphxviseldjrbtfcgvkmani
|
||||
qywgphxoiseldgkbtfcgvkmanu
|
||||
qywzphxoileldjrbtgcgvkdanu
|
||||
qywzphxoiseldnrbtfcwvkmpnu
|
||||
qywzphxoiseidjrbmfcqvkmanu
|
||||
qywzpkxoiselijrbtfcgvlmanu
|
||||
mywzphxoiveldjrbtfcgvkmunu
|
||||
qywzphxooseddjrbtfcgpkmanu
|
||||
qywzphxokseldjritfcyvkmanu
|
||||
qywzxhxoiseldjrbtfqgvcmanu
|
||||
qywzphxoisfldjrbpfcgvkmaju
|
||||
qywuphxgiseldjrbffcgvkmanu
|
||||
qywzphociseldjrbtfcgvkuanu
|
||||
qywzphxoiseldvrbtftgckmanu
|
||||
qywzpbxoisrldjrbtfngvkmanu
|
||||
qywzphxoiseldjrntfygvdmanu
|
||||
qywzphxviseldkrbtfcgvkianu
|
||||
qywpphxgiseldjrbtfctvkmanu
|
||||
qywzphxoicewdjrbtfcgvsmanu
|
||||
qywzpcxoiseldjmbtfcgvcmanu
|
||||
qrwzphxoiseldjrbtfcgjumanu
|
||||
qywzphxoiselojrbtfcgxkmaau
|
||||
qywzphxojsbldjrbtfcgykmanu
|
||||
oywzphxoiseldjrbtfqgvkmvnu
|
||||
qywfphxpiseldjrbtfckvkmanu
|
||||
qyyzwhxwiseldjrbtfcgvkmanu
|
||||
qywzphxgiseldjrbtfchvkmabu
|
||||
qywzphxfiseldjrbtfcgukoanu
|
||||
qywzpdxoisyldjrbtfcgvkxanu
|
||||
dyuzphxoiseldjrbtfcgvkmamu
|
||||
qywzphxoiseldjrbifcgvkmnnp
|
||||
qywzpyxoiseldjrbtfcgvklano
|
||||
dywzphxoiieldjrbtfcgvwmanu
|
||||
qywzphxoihemdjrbtfcgvdmanu
|
||||
gywzphxoxseldvrbtfcgvkmanu
|
||||
qywzqhxoissldjwbtfcgvkmanu
|
||||
eywzphxoiieldjrbtfcgekmanu
|
||||
qyizprxciseldjrbtfcgvkmanu
|
||||
qywjphxoiseldjrbtfcgckmano
|
||||
qywznhxoiseldjrbrfcgvkmagu
|
||||
qywzphxoisrldjdbvfcgvkmanu
|
||||
qyyxphxoiseldjrbtwcgvkmanu
|
||||
qywzphxoiseldjdbtfcpvkmjnu
|
||||
qywzvhxqiseldjrbofcgvkmanu
|
||||
vywzphxoiseldjrbtfcgckwanu
|
||||
qywzphgbiseldjrbtfcgvkmazu
|
||||
qcwzphxoiseldjrbqfcgvkmdnu
|
||||
qywzphxoismldjrbtfcgkkmznu
|
||||
qywhphxoiseldjrbtccgvkmane
|
||||
qywzphzoiseldjrbtfcgvqmauu
|
||||
hywzphxoiseldjrbtfcuvkmanc
|
||||
qywzphxozsejdgrbtfcgvkmanu
|
||||
qyszphxoiseldjrntfygvdmanu
|
||||
qywzphxoisgldjrbtfcgvklaru
|
||||
qywzhhxoiseldjrbtscgvkmqnu
|
||||
qywjphxpiqeldjrbtfcgvkmanu
|
||||
qywzphxoiseldxrptfclvkmanu
|
||||
qywlphxoisehdjrbtfcgvkmanc
|
||||
qydzpfxoiseldjrwtfcgvkmanu
|
||||
qywzphxoiseldjrbtxcgqkfanu
|
||||
qywophxoiselfjrbtfcgvkmani
|
||||
qywzyhxoiszldtrbtfcgvkmanu
|
||||
qywzphxoxseldfrntfcgvkmanu
|
||||
qywzphloiseldjqbtfcgvkmtnu
|
||||
qywzpuxoiseldorbtfcgvkeanu
|
||||
qywzphxoiueldjrwdfcgvkmanu
|
||||
qgwzphxoiseldjmbtncgvkmanu
|
||||
qywzphtggseldjrbtfcgvkmanu
|
||||
qywzphxoisrldjrbtfmgvhmanu
|
||||
qfszphxoiseldjqbtfcgvkmanu
|
||||
qywzphxpisjldjrbxfcgvkmanu
|
||||
qywznhxoisepdjrbtfqgvkmanu
|
||||
qywzphioiseldjabtfcgxkmanu
|
||||
qyizphxaiseldjrbtfcgvkmaxu
|
||||
xywzphxoiqelvjrbtfcgvkmanu
|
||||
quwzphxoiseldjretfcgvkmaau
|
||||
bywzphxoiseldjrbtucgckmanu
|
||||
jywzphxoiseldjrbofcgvkmani
|
||||
qywzphxoiseltjkbtfcgvkmabu
|
||||
eywzphxoiselgjrbtfkgvkmanu
|
||||
qywzphxoisengjrttfcgvkmanu
|
||||
qywzphzoiseldjrbtfcgvkmknk
|
||||
quwdphxoiseldjrbtfcxvkmanu
|
||||
qcwzzhxoiseldjrgtfcgvkmanu
|
||||
qywgphxdiseldjrbtfcgjkmanu
|
||||
qywzpdxoivefdjrbtfcgvkmanu
|
||||
qywzphxoiseldjrbtfdgvjmpnu
|
||||
qfwzphxoiseydkrbtfcgvkmanu
|
||||
qywzphxdiqelqjrbtfcgvkmanu
|
||||
qywzvhxoiseldjrbtfognkmanu
|
||||
qywzphgoiseldjrbcfcgvtmanu
|
||||
qywophxoiseldjrbtpcgvkmank
|
||||
qywzphxoiszldjretfcgvkmabu
|
||||
qywzphxoiseldjhbtfcgvxmawu
|
||||
qcgzphxoiselejrbtfcgvkmanu
|
||||
qywzphxoisepdjrbtfcfvkcanu
|
||||
qivzphxniseldjrbtfcgvkmanu
|
||||
qywzhhxoiseldjrftxcgvkmanu
|
||||
qyazphxciseldjrbtfcgskmanu
|
||||
qywzphxoisoldgrbtfczvkmanu
|
||||
qywzmhxoiseldurbwfcgvkmanu
|
||||
qywzphxoistldjrbwfcgvkranu
|
||||
qywzphxoistedjrbtfcgokmanu
|
||||
qywzqhxodsecdjrbtfcgvkmanu
|
||||
qywzphxtisxldjrbtfcgvkhanu
|
||||
qywzphxoeseldjrtrfcgvkmanu
|
||||
qdwzphxoioeldjrbtfigvkmanu
|
||||
qjwzphxoisbldjrbtfcgvkmanz
|
||||
qywzphxoiseldbrbtfdgvlmanu
|
||||
qywzphxoiselddrbhvcgvkmanu
|
||||
zywzppxoiseldjrdtfcgvkmanu
|
||||
qywzppxqiselkjrbtfcgvkmanu
|
||||
qywzphxoihelbjrbtfcgvkmabu
|
||||
qywzphxoiseldjreyfcgvknanu
|
||||
qywzphxxrseldjrbtfcgvkmagu
|
||||
qywhpfxoiseldjrbtfdgvkmanu
|
||||
qywzphxoisxldjrdtfagvkmanu
|
||||
oywzphxxiseldjrbtfcgvkmaeu
|
||||
qywzphxoiselqirbtfvgvkmanu
|
||||
qywzphxoqseldhrbtfcgvkhanu
|
||||
qywzphxokseldjrbtfxgvkmaju
|
||||
qywzphtoiseldurbtfcfvkmanu
|
||||
qywzphxoiheudjrrtfcgvkmanu
|
||||
qrwzphxzigeldjrbtfcgvkmanu
|
||||
qywzphxoiseldorbtfcgvxmvnu
|
||||
qywzphxoisaldjpbqfcgvkmanu
|
||||
qywuphxoiselljrbtfchvkmanu
|
||||
qywzphxoisaldjrbefcgvkmsnu
|
||||
qywzphxoiteldjrbnfcgvkmanp
|
||||
qywhphxoiselqjrbtfcgvkmagu
|
||||
qywzjhxoisejdjrbtfcgvkmanr
|
||||
qywephaoiseldjrbtfcavkmanu
|
||||
qywcphxoireldjqbtfcgvkmanu
|
||||
qywzphxoiseldirbuicgvkmanu
|
||||
qywzphxoisecvnrbtfcgvkmanu
|
||||
qcwzphxoiseldjrbtfcgvrmaiu
|
||||
qywnphxoiseldjrntftgvkmanu
|
||||
qywzphxhisyldjrbtfcgvkmafu
|
||||
qyhzphxoiseldjrytfcgvkmanq
|
||||
vjwzbhxoiseldjrbtfcgvkmanu
|
||||
qyvzpsxoisuldjrbtfcgvkmanu
|
||||
qywzphxaiseldcrbefcgvkmanu
|
||||
qywzphxoiseldjgbtfsgvkfanu
|
||||
oiwzphxoiseldjrbtfcgvkmcnu
|
||||
qyezphxoiseldjrbtfcqvkmjnu
|
||||
tywzphxriseldzrbtfcgvkmanu
|
||||
yywzphxoiseldjbbtfugvkmanu
|
||||
qywzpfxviseldjrbttcgvkmanu
|
||||
qywzphxoiceldcrbtfugvkmanu
|
||||
qymzphxoiseldjratfcsvkmanu
|
||||
qywzphxoiselxjrbdfcgvkpanu
|
||||
qywzphxoiselujrbtfkgvimanu
|
||||
qywzshyoiseldjrbtfcgpkmanu
|
||||
qywzphxoiselfjrbtfsgvkmant
|
||||
qywpphxoiseldjxbtfcyvkmanu
|
||||
qywzfhxoiselqjrptfcgvkmanu
|
||||
qewzphxoiseldprbtfcgvkmand
|
||||
qywfphxoiseldlrbtfcgvkmgnu
|
||||
qywzphxoiseldjhbtqcovkmanu
|
||||
fywzphxoiseldlrbtfcgvkjanu
|
||||
sywzphxoiseldjrbhfccvkmanu
|
||||
qywzphxoiseldjfbtfcrvkmpnu
|
||||
sywzphxoisrldjrbtfczvkmanu
|
|
@ -0,0 +1,65 @@
|
|||
extern crate edit_distance;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use edit_distance::edit_distance;
|
||||
|
||||
fn get_char_counts(input: &String) -> (bool, bool) {
|
||||
let mut has_two = false;
|
||||
let mut has_three = false;
|
||||
let mut map = HashMap::new();
|
||||
for char in input.chars() {
|
||||
map.entry(char).and_modify(|x| *x += 1).or_insert(1);
|
||||
}
|
||||
for (_char, count) in map {
|
||||
if has_two && has_three {
|
||||
break;
|
||||
}
|
||||
if count == 2 {
|
||||
has_two = true;
|
||||
} else if count == 3 {
|
||||
has_three = true;
|
||||
}
|
||||
}
|
||||
(has_two, has_three)
|
||||
}
|
||||
|
||||
fn calc_checksum(lines: &Vec<String>) {
|
||||
let mut two_count = 0;
|
||||
let mut three_count = 0;
|
||||
for line in lines.iter() {
|
||||
let (has_two, has_three) = get_char_counts(line);
|
||||
if has_two {
|
||||
two_count += 1;
|
||||
}
|
||||
if has_three {
|
||||
three_count += 1;
|
||||
}
|
||||
}
|
||||
println!("checksum: {}", two_count * three_count);
|
||||
}
|
||||
|
||||
fn find_single_char_difference(lines: &mut Vec<String>) {
|
||||
let line = lines.pop().expect("ran out of lines to find the single char difference!");
|
||||
let mut found = false;
|
||||
for other in lines.iter() {
|
||||
if edit_distance(&line, other) == 1 {
|
||||
found = true;
|
||||
println!("{} and {}", line, other);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
find_single_char_difference(lines);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut lines: Vec<String> = BufReader::new(File::open("input").unwrap())
|
||||
.lines()
|
||||
.map(|line| line.unwrap())
|
||||
.collect();
|
||||
calc_checksum(&lines);
|
||||
find_single_char_difference(&mut lines);
|
||||
}
|
Loading…
Reference in New Issue