Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use itertools::iproduct;
- use std::collections::HashMap; // 0.8.0
- fn main() {
- let input = "auxwcbzrmdvpsjfgkrthnkioqm
- auxwcbzrmdvpsjfgbltonyijqe
- auxwcbzrmdfpsefgklthnoioqe
- auxwcbzrmdvpsjfgkluhnjisqe
- auxwcbzrmdvesjfgdzthnyioqe
- auxwcbzrmdvhsjfgklthnmijqe
- auxwcbzridvpsjfgkltxeyioqe
- ayxwcbzrgdvpsjfgklthiyioqe
- ajxwcbzrmdvpsjfgklkhnyiode
- auxwcbcrmdvpsjfqelthnyioqe
- auxwcbzrmsvpsjsgklthnyiope
- auxwcbzrmqvpsjzgklghnyioqe
- auxwcbzrmdvpsjtqklthxyioqe
- auxwcbzrmdopsjfdklthncioqe
- auxwcbzrmdvpsjfgkltmhyfoqe
- aixwcbzrmdvpsjfgllthdyeoqe
- vuxicbzrmdepsjfgklthnyioqe
- auxwcbbxmdkpsjfgklthnyioqe
- auxwcbzrgdvpsofaklthnyioqe
- auxycbzrmdvpsjfgklthnyuose
- aujwcbzrmdvprjfgkltcnyioqe
- auxwgbzrmdvpsjfgyzthnyioqe
- auxwcbzrmavpsjfgkltsnyiome
- auxwcbgrmdvpsjfgkdthnrioqe
- kuxwcbzrmdvpsyfgklthnyioue
- auxwcbzomdvpjdfgklthnyioqe
- auxwcbzrmdppsjfgklthvyifqe
- aunwubzrmdvpsjrgklthnyioqe
- auxwcbzrmoipsjfgklbhnyioqe
- auxwdbzrmdvpsjfgmlthnyioce
- auxwcbzjmsvpsjfiklthnyioqe
- auxwcbzrmwcpsjfcklthnyioqe
- auxwcbzfmdvprjfhklthnyioqe
- auxdcbzrgdvpsjfgklthnyxoqe
- wuxwbbzrmdvpsjfgklthnyiote
- auowcbjrmdvpsjfgklthnyfoqe
- auxwsbzrmdvpsjfglltcnyioqe
- quxwcbzrmdvpkjfgklthnyioqt
- vuxwcbzrudvpsjfgklthnyioqi
- puxwcbzrmdvgsjfgklthncioqe
- luxdcbzrmdvpsjfgkothnyioqe
- auxwcbzrmdvpsjfyklthfhioqe
- auxwcbqrmdvpsjfgkldhnyiote
- quxwcbzrmlvpsjfgklthnyioqi
- auxwcbzgmdvpsjfoklthnyiuqe
- auxwcbzrmdvpsbfgkltdjyioqe
- auxwcbzsmdrpsjfgklthpyioqe
- auxwcbzrmfvpsjfwklthnyiote
- auxbkpzrmdvpsjfgklthnyioqe
- auxwcbzrddvpsjfsklthnyroqe
- abxwcbzrmdvpsjfgkltdnyivqe
- awxwcbzrmvvpsjfgklthngioqe
- auxwcbzrmkvgsjfgkltcnyioqe
- auxwcbammdvpsjfgklthpyioqe
- auxwcbhrmdvpsjfgtlthnuioqe
- auxwcpzrmdvpbjogklthnyioqe
- auxwcbzrmdvpslfgklbhkyioqe
- auxwcbsrmdvpjjfgkldhnyioqe
- auxwcbzrmdqpsjfgauthnyioqe
- ydxwcbxrmdvpsjfgklthnyioqe
- auxwcbzrmdvpejfgklthnyyofe
- auxwchzrmxvpsjfgklthnyioqh
- auxwcbzrtdvpsjfgklxhnzioqe
- auxwcbyrmdvpsnfgklnhnyioqe
- auxwcbzrcdvpsjugklihnyioqe
- auxwcbzrddvpsjfgklhhnyiaqe
- aumwtbzrmdvpsjfgklthnyitqe
- auxucbzrmdvpsjfgklthwfioqe
- auxwcbzrmdvpzmfgkllhnyioqe
- auxwcbzrmdvpsjhgklthntiome
- buxwzbzrmdvpszfgklthnyioqe
- ouxwcbzsgdvpsjfgklthnyioqe
- auxwcbzrmdvpsjfskltgnyioqz
- auxwcbbrmdvpsjftklthnyioqu
- quxocbzrmdvpsjfgklthfyioqe
- acxwcbzrmdvpsjfgklfhnrioqe
- auxwcbzrmdnpsjfrkjthnyioqe
- wuxwybzrmdwpsjfgklthnyioqe
- auxwgbxrmdvpsjfghlthnyioqe
- atxwcbzrmdvnsjfgklthnyjoqe
- acxwcbzmmdvpsjfbklthnyioqe
- auxhcbzrmdvbsjbgklthnyioqe
- auxwlbzrfdvpsjfgxlthnyioqe
- auxwmbzrmdfpsjqgklthnyioqe
- auxwcbzrmdvpsgfgklahnyigqe
- auxwgbzrmdvpsjfgzldhnyioqe
- auxwcbzrmdvpydfgklthnyiohe
- auxwxbzrmdvpsjfsklchnyioqe
- auxqcbzrmdvpsjfgqlthnyiwqe
- auxwcozrmdvssbfgklthnyioqe
- auxvcczrmdvpsufgklthnyioqe
- auxwcbzrudvpsjfgklyhnyioxe
- aulwcbzrmdvpsjqgknthnyioqe
- auukcbzrmdvpsjfgklthtyioqe
- auxwcszimdvpsjfgklthnyigqe
- juxwcbzrbdvpsjfgklthnyboqe
- auxwcbzrmdvpjofgklthnyioqj
- auxwcbzrmdvpsjfgplfhnyione
- auxwcbzrmdhpsjfgkltknyeoqe
- luxwcqzrmdvpsjfgklthnbioqe
- uuxwcbzrmdvpsjfgkithnyiiqe
- auxwcbzrmdvpdjfgkrthnyeoqe
- auuwcbnrmdvpsjfgklthnjioqe
- auxwcnzrmdvpsjvgklthnyooqe
- auxwcbzcmdvpsjfcklthnyiose
- auxwcbzrldfpsjfgklthjyioqe
- auxwcizrmdvpsjfjklthnymoqe
- auxwcbtrmdvpsjfgtlphnyioqe
- amxwcbzrmdvksjfgklthnyiove
- auxwcbzrmdvpszfgkpthnyiuqe
- auxwcbzrmdvxdjfgkltqnyioqe
- auxwcbzrudvpsjfgklthnymiqe
- auxwcbirmdvfsjfgklmhnyioqe
- auwwcbzrndvprjfgklthnyioqe
- auxwcbormdgpsjfgklbhnyioqe
- auxwabzrmdupsjfgklthnyioqt
- auxvcbzrmdvpsjfgkltrmyioqe
- auxwcbzrmddpsjfsklthnyizqe
- auxwcczrmuvpyjfgklthnyioqe
- auxwcczrmdvpsnfgkpthnyioqe
- auxkcbzrmdvpsjfhklihnyioqe
- auxwcbzrmdvpsjfgklthnkijje
- auxwcbzcmdvpsjpgkldhnyioqe
- auxwcnzrudvpstfgklthnyioqe
- xuxwcbzrgdvusjfgklthnyioqe
- aaxwcbzrmdvpsjvgklthnyidqe
- auxwcbztmdvpsjfgklthnyhqqe
- auxwcbzrmfvpsjfgklthnyilfe
- auxwcbzrmdvksjfgklthjyioqq
- auxwcbzrmdzksjfgktthnyioqe
- auxwcbzrmfvpszfgklohnyioqe
- auxwckzamdvpsjfgklthnyioqs
- auxwcmzrhdvpsjfaklthnyioqe
- fuxwcbzrmdapsjfgklrhnyioqe
- avxwxbzrmdvpsjfgklthniioqe
- auxwubzrmevpsjfgkltpnyioqe
- fuxwcbzrgdvpsjfgklhhnyioqe
- duxwwbdrmdvpsjfgklthnyioqe
- audwcbzrmdvpnjcgklthnyioqe
- auxtcbzrmdvpsjmgklthnyyoqe
- aucwcbwrmdepsjfgklthnyioqe
- auxwcbzrudvpsjfpklthnyiose
- auxwcbzridvpsjfsklthxyioqe
- auxtcbzrmdvpscfgklyhnyioqe
- auxwcbzrmdvppjfgklthnyivee
- auxwdbzrmuvpskfgklthnyioqe
- auxwubzrmdvosjfgklthnyiope
- auxwcbzrmhnpsjfgklthnyimqe
- auxwcbzrmdqpwjfgkltpnyioqe
- auxwcbormdvpsjljklthnyioqe
- auxwcbzrmdjpsjfgkltjpyioqe
- auxwcbzrmdvpszfgklthkyizqe
- auxwcbzighvpsjfgklthnyioqe
- auxwcbzrmdlpsjfgcythnyioqe
- auxwcbzumdvpsjflklthnyimqe
- pdxwcbzrmdvpsjfgklthnyihqe
- auxwcbzrsdvpsjfgklhhvyioqe
- auxwcfzamdvpsjfgkmthnyioqe
- aexwcdzrmdvpsjogklthnyioqe
- auxxcbkrmavpsjfgklthnyioqe
- auxwcbzredvssjfgklthryioqe
- aupwqbzrmdvpsjfgklthnyioqc
- auxwcbzrmdvpkcagklthnyioqe
- auxwcbzrmdvwsbfgklthnlioqe
- aunwcbzxmdvhsjfgklthnyioqe
- auxwcbzrhddpsjfgklthnnioqe
- ouxwcbzrmdvtsifgklthnyioqe
- auxwcbzrmdqpsjfgklthnyfoqp
- auxwrbzrhdvpsjfgolthnyioqe
- auxwcbcqmdvpsjugklthnyioqe
- auxwcbzrqdvpsjhgklthnjioqe
- auxmcbzrmdvpsjfgmlthnyjoqe
- auxwcbzrmdvpsjfgzlthnycoqv
- auswcbzrmdvpsffgslthnyioqe
- auxwcbzrfdvpsjfrmlthnyioqe
- auxwcbzrmdvpsjngzlthnxioqe
- auxwcbzrmdvpsjfuqlthnyiyqe
- auxwzbzrrdvosjfgklthnyioqe
- auxwcbzdmdvpsjfikxthnyioqe
- guxwcbzrmdvpsjfgmlthnytoqe
- auxwcbzrmdvpspfgkytenyioqe
- auxvcbzrldvpsjfgklthnyhoqe
- auxwcbzrmavpckfgklthnyioqe
- autwcbzrmdvpsafgklthnyirqe
- auxwcbzrxuvpsjfgklthmyioqe
- auxwcbarmdppsjfgklthnywoqe
- anxvcbzrmdvpsjfgklthnyijqe
- auxwcbwrmdapsjngklthnyioqe
- abxwcbzrmdvpsjugkltgnyioqe
- auxwcbtrmdvpsjfgkltunyioue
- aujwcbzrmovpsjfgklthryioqe
- auxwcbzrydvpsjfgklthndikqe
- auxwcbzrmdvpsjfgklmrnyioqo
- auxwcbzrddvpsjfggithnyioqe
- auxwcbzrmdvpfjfaklthlyioqe
- fuxtcbzrmdvpsjfgklwhnyioqe
- tuxwcbzrjdvpsjfgjlthnyioqe
- auxwcbzrmdppsofgklthnyfoqe
- auxvclzamdvpsjfgklthnyioqe
- auxwcbzrmdvpsjfdklhhnzioqe
- auxwcbzrmsvpsvdgklthnyioqe
- arxfcbzrmdvpsvfgklthnyioqe
- auxzcbzrmdvpsjfgklthnhioqj
- auxwcbzrrdvpsjfgpltunyioqe
- auxuibzrmdvpwjfgklthnyioqe
- auxwcbzrwdqpsjfgklthnyooqe
- aujwcbzrmdvpsjvgklthxyioqe
- abxwcbzrmfvpsjfgklthnyxoqe
- aurwcbzrmdvpshfgklthnyhoqe
- auxwcbzjmdvpsjfgknthnycoqe
- auxwcbzrmdvpsjfgklmhxwioqe
- auxwcbzrmfvpsjfgklthnyiorq
- auxwcbormdvpsjfgklwhnlioqe
- auxwctzrmdvpsjfgklcknyioqe
- awxwcbzrmdvpsjfgvlthnyiome
- auxwcbzrmdvpsjfjklthnyixje
- auxwcsxrmdvpsjfgkltsnyioqe
- auxbmbzrmdvpsjfgklthnyioce
- auxwcbzrmdvpsjfukzthnytoqe
- aixwcbzrmdvpsjfgllthdyioqe
- auxwcbzrmdypsjfgklthnlioqy
- auxccbzrmdvpsjfgkltrnnioqe
- auxwcznrmdvpsjfgklthnykoqe
- auxwmqzrmdvpsjfgilthnyioqe
- auxwcbzrmdvpdyfgolthnyioqe
- auxwcbzrmdvpsjfgkmohnqioqe
- auxwcfzrmzvpsjfoklthnyioqe
- auxwjyzrmdvpsjfgulthnyioqe
- auxwcgzredvpsjfgkxthnyioqe
- wuxwcbtrmdvpsjfgklthnyiofe
- auxwcbzrmdopsgfgklthncioqe
- auxmcbzjmdvpsjfgklbhnyioqe
- auxwlbzrmdvpsjffklthgyioqe
- auxwcbzrmrvpsjfgqlthtyioqe
- kuxwhbzrmdvpsjfgklthgyioqe
- auxwcozrmdgpsjfgklthnydoqe
- auxwdbzrmdvpdjfgklthgyioqe
- auxwqbzrmdapsvfgklthnyioqe
- auqwcbzridvjsjfgklthnyioqe
- auxwckzrmdvpsjfoklthnyuoqe
- auxwcbzvmdvpsjfgklghnyiome
- auxtcbzrmdvpsjqgktthnyioqe
- auxwcbzrmdvesjfgkljhnnioqe
- auxwcbzrmpvpsqfgklthnqioqe
- auxwcbzrmdcpsqfgklthnzioqe
- yuxwcbzrmdvpsjggklthnlioqe
- auxwcbzradvpsjftklthoyioqe
- auxwcbzrmdvjujfgklmhnyioqe
- auxwcbzrmdvpsrfgklpinyioqe
- auxwobzrvqvpsjfgklthnyioqe";
- let s: Vec<String> = input.split_whitespace().map(String::from).collect();
- let count_occurrences = |s: String, i: i32| {
- s.chars()
- .fold(HashMap::new(), |mut m, x| {
- m.entry(x).and_modify(|v| *v += 1).or_insert(1);
- m
- })
- .iter()
- .any(|(_, b)| b == &i)
- };
- println!(
- "Part1: {}",
- s.iter()
- .filter(|x| count_occurrences(x.to_string(), 2))
- .count()
- * s.iter()
- .filter(|x| count_occurrences(x.to_string(), 3))
- .count()
- );
- let diff = |a: String, b: String| a.chars().zip(b.chars()).filter(|&(a, b)| a != b).count();
- let common = |(a, b): (String, String)| -> String {
- a.chars()
- .zip(b.chars())
- .filter(|&(a, b)| a == b)
- .fold(String::new(), |mut acc, b| { acc.push(b.0); acc})
- };
- let mut b = iproduct!(&s, &s);
- println!(
- "{:?}",
- common(b.find(|(i, j)| diff(i.to_string(), j.to_string()) == 1)
- .unwrap())
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement