Day 2 2018

This commit is contained in:
Wesley Moore 2018-12-02 17:43:52 +11:00
parent 696b90944d
commit f78231443c
No known key found for this signature in database
GPG key ID: BF67766C0BC2D0EE
2 changed files with 309 additions and 0 deletions

250
2018/input/2018/day2.txt Normal file
View file

@ -0,0 +1,250 @@
ybruvapdgixszyckwtfqjonsie
mbruvapxghslyyckwtfqjonsie
mbruvapdghslzyckwtkujonsie
rwruvapdghxlzyckwtfqjcnsie
obruvapdgtxlzyckwtfqionsie
lbruvapdghxqzyckwtfqjfnsie
mbrunapdghxlzyccatfqjonsie
mbruvapdghxlzyokltfqjdnsie
ybruvapdghxlzmckwtfqjmnsie
mbruwaadghxdzyckwtfqjonsie
muruvapdghxlzyckvtfqjonsim
mbruvapdghxlkyckwtxqjonjie
mbruvaqdghxlzyckwtfqjrnnie
mwruvapdghdlzyckttfqjonsie
mbruvapdgtelzyckwxfqjonsie
mbruvapdohxlzvckwtfqjonhie
mbrugapdgbxlzyckwtfqjynsie
mbruvapdghxlzyckwtlqjonjiu
mbruvapwghxlzyckwafqjonbie
wbruvapdghxlhyckwtfqjonsii
mbruvapdghxlzyckwtcqnonsiq
mbyuvapighxlzybkwtfqjonsie
mbrrvapdghxvzyckwtfqjonsio
mhruvapdghrlzyckwtfzjonsie
mtruvapvghxlzyckwtfnjonsie
mmrlhapdghxlzyckwtfqjonsie
mbruvapdgpxlzyjkwtfqjovsie
mbrucapdghxlzymkwtzqjonsie
mbeuvafdghxlzyckwtfqjonwie
mbruvapcghxlayckwtfqjonsii
mbruvabdghxlzyckwtfqyansie
mbruvjpdghxlzyckwtfqgfnsie
lbruvapdghxlzyckwtfqjonriv
mbrupapdghxlzycjwtfqronsie
mbpuvapdthxlzymkwtfqjonsie
mbiuvapdgixlzyckwxfqjonsie
mbruvapdghxyzyckwtfcjonsbe
mbrurapkghxlzyckwtfqjonzie
mbrufapdrhxlzyciwtfqjonsie
mbruvapdghxlzbckwtfqjoisae
ubruhapdghxlzuckwtfqjonsie
mbruvapdjhulzyckwtfqjonshe
mbruwapdgyxlzyckntfqjonsie
mwruvapdghplzyckwtfqjonsme
mbruvapjghtlzyckwtfqgonsie
pbruvapdghhlzyckwtfrjonsie
mbruvgpdihxqzyckwtfqjonsie
mbruvahdohxlzyckwtfijonsie
ibuuvapdghxlzyckwtfqjofsie
mbruvandghxlzyckwtfqjrnxie
mbrjvlpdghxlzyckwgfqjonsie
mbruvapogfxlzyckotfqjonsie
mbruvrpdghxlzyckutfejonsie
mbruvbpdghxlzyhkwtfqjonsip
mbruvapdghxlzyckmnfqjensie
mbruvapdghvlzyckwtfqjowsix
mbruvakdgholzwckwtfqjonsie
mbruvapdghxlzackwtfqconsae
mbruvapdghxlzyqvwtfqjlnsie
mprrvapdgfxlzyckwtfqjonsie
mbrunacdghxlhyckwtfqjonsie
obruvapdgsxlzyckwtfqjonvie
murcvapdghslzyckwtfqjonsie
mbruvapdghxlzyzkwmftjonsie
mbrwvapdgtvlzyckwtfqjonsie
mbxuvapdghxlzqcnwtfqjonsie
mbruvaddghxboyckwtfqjonsie
mhruvwndghxlzyckwtfqjonsie
mbrdvapdghxlzyckwmpqjonsie
mbruvapdgyxlzyckizfqjonsie
mbruvapdghxlzlckwtfqeowsie
mbruvbpdgrxlzyckwtfqjonsxe
mbruqapoghxlzyckwtvqjonsie
mbouhapdghmlzyckwtfqjonsie
mbruvapjghxidyckwtfqjonsie
mbsuvapkghxlkyckwtfqjonsie
mbruvlpdghxlzycrwtfqjonsis
mcrueapdghxlzyckwtfqjynsie
muruvapngbxlzyckwtfqjonsie
mbruvapdghxlzycawtfyjojsie
mbruvbpdghxczyjkwtfqjonsie
ybduvapdghxnzyckwtfqjonsie
mbruvbpdghxlzyckwtfbjousie
mbouvapdghxlzycbwtfqponsie
mbruvaedghplzycgwtfqjonsie
mbrhvapdghxlzyckytfqjgnsie
mbruvapdqbxleyckwtfqjonsie
mbruvapddhhldyckwtfqjonsie
mbruvapdghxlwrckwtfqjondie
mbruvapdmhxlzyckwtfqkonsve
xbbuvapdghxlzyckwtfkjonsie
mbruvapdghxlzyckwcfqjunkie
mbruvapdghxlzyckwtfqxonfib
mbrtvapkghxlzyckwtfqeonsie
mbruvazdghxldymkwtfqjonsie
kbruvapddhxlzfckwtfqjonsie
mbouvapdghxlpyckwtfqjoosie
mbauvapdghxlzyckwtfqjszsie
mbruvapdghtlzyckntfqtonsie
mbruvipdggxlzbckwtfqjonsie
mbruqapdghrlzyckwtfqjznsie
myruvacdghxlzyckwifqjonsie
mbruvapdghxlzuckwtfkjocsie
mwjuvapdghxlzyckwtfqjonsxe
mbruvapxghxlzickwtfqjobsie
mbrupapdghxtlyckwtfqjonsie
meruvapdjjxlzyckwtfqjonsie
mbruvkodghxlzyckwofqjonsie
mbruvapdgexlzyckwtgkjonsie
mbruvapwghxlzyckwtcqjonsiw
mbruvapdghxlzykkwtfqtoxsie
mbruvapdahxlzycgwtfwjonsie
mbruvapdgwxlhyckhtfqjonsie
mbruvapbghxlzycbhmfqjonsie
mbruvapdghxvzyzkwtfqjonsin
mbrcvapdqhxlzyckwyfqjonsie
zbruvaxdghxlzyckwgfqjonsie
mtruvapdghxlilckwtfqjonsie
bbruvapdghxlzyckwtfmjonsxe
mbruvajdghxlzyckwtfqfwnsie
mbruvapdgkxlzyckwtfqionpie
rbruvapdghxlryckwdfqjonsie
mbruvandghxlzyckwmfvjonsie
mbruvahdghxlzeckwtfqjonsme
mbruvnpcghxlzyckwtfqjobsie
mbruvapdghqlzyckwtfbjonsiy
mbruvavdghxlzyckwufqjodsie
mbruvapdghxlzyckwtfzmovsie
mbruvlpdghxuzyckwtfqjoesie
mbruvopdghxlzycwwtfqjansie
obruvapdghglzybkwtfqjonsie
mbpuvlpdghxlcyckwtfqjonsie
mbruvaidghxlzyckwtfmjonoie
mbruvapdihxzzyckwtfqjonsiy
mbquvapdghxlzyckwtfqconsme
mbruvapdghslzyckqtfqjojsie
mbrzdapdghxmzyckwtfqjonsie
mwruvapdghxozyckwtfqjonsxe
muruvapdgfxlzyckwtfqjojsie
wtruvapdghxlzyckvtfqjonsie
mbruvapdghxlzyckysfqjxnsie
mbruvrpdghxczyckktfqjonsie
mbquvapdghxlryckwtfqjonsne
mbruvapdghflzycvwtfqjpnsie
mbruvapughclzyckwtfqjonsin
mbrhvapdghxlpyckwtfqjonsre
mbruvapdgtxlzyckwtfqjoosit
mbrupapnghxhzyckwtfqjonsie
mmvuvapdvhxlzyckwtfqjonsie
mbruvaptghxlzyckwtfqjotsse
mgruvapvghxlzyckwtfqjonsix
mbrupapdghxszyckwtfqjunsie
mbruvkpdghelzyckwtfqjpnsie
mbruvrrdghjlzyckwtfqjonsie
mbruvapdghnlzyckwtfkjonsze
mbruvwpdghxlzyckwtfqhoysie
mbrsvapdfhxlzyckwtfqjobsie
mbruvapdgexezymkwtfqjonsie
ybruvapdghxlzyckwtfqxonsiw
mrruvapdghxdzyckwtfqjossie
mbruvapdghtlzyckwtfqconsiu
mbrpvapdghxlzlckwpfqjonsie
mbruvjpdghslzyckwtfqjjnsie
mhruvapoghxlzyckwtfvjonsie
mbrubqpdghvlzyckwtfqjonsie
mbruvapdghxlzackwtfqconsiw
mbruvapdgnxlzkckwtfqjdnsie
mbrudapgghelzyckwtfqjonsie
mbruvapdghxlzlakwbfqjonsie
mbpuvapdghxlzyckwtuqjonjie
abruvapdghxlzykkwtfqjonzie
mbrupupdghxlsyckwtfqjonsie
mbrsvupdghxlzyckwtfqjonkie
mxruvgpdghxllyckwtfqjonsie
mbrnvapdghxlzycbwtfqfonsie
mbrbxapdghxlzyckttfqjonsie
mbnuvapdghxlzyxkwtmqjonsie
mbrfvapdghjlzickwtfqjonsie
mbhuvupdghxlzyxkwtfqjonsie
mbrcvapdghxluyckwtfqjznsie
mbruvapdghxlzyckwofqjoxsiz
mbrevapdghxloyckwtfqjonnie
mbruvipdghnlzyckwtfqjopsie
mbxxvaptghxlzyckwtfqjonsie
mbruvcpdghxlztckwtjqjonsie
mqruvlpdghxlzyckotfqjonsie
mbruvapdgqxlzyckwtfqjpvsie
mbruvapdgvxlzyjkwtfqjbnsie
mbruvapdghxlgyckwtfqcocsie
mbruvapdghxkwyckwtfqjoqsie
mbrgvavdghxlzyckwxfqjonsie
qbruqapdgvxlzyckwtfqjonsie
mbauvapdghxlzgckwtfqjunsie
mbruvapdgdxluyckwtfqjoosie
mbruvapdghxlzykkwtfqwobsie
mbruvapdghxlzhcnwtfqjonqie
mbruvapdghxlzycbhmfqjonsie
mbruvapdghxluyczwtfqjontie
mbruvapnghxlzyckwnfqjonbie
moruvapdghxlzcckwtfqponsie
mbruvapfgxxlzyckwtfqjunsie
mbruvapdghxlryckvtfejonsie
mbrzvapdghxlzvcbwtfqjonsie
mbruvapdgqxlzyckwcfqjonsce
abruvupdrhxlzyckwtfqjonsie
mbrubaptghxlzyckwtfqjondie
mgruvapdgpxlzyckwtfijonsie
mbruvapdghxczlckwtfujonsie
mbruvapdgmmlzyckwtfqjonsir
mbruvapdhhxltyckwtfdjonsie
mbruvapdghxlzyckwtfdjjnste
mbrdvzpdghxlcyckwtfqjonsie
mbruvapdghxlzyckwtnqbonsim
mbrovapdghxlzyckwtfpjousie
mymuvapdghxlzyjkwtfqjonsie
mbpuvapdghxlzyckwtfljcnsie
mbrxvapdghxlzyclwtfqjonpie
mbrueapdghxlzyckwtfqjopsia
mbruvapdghxlzycdwtfqjbfsie
tbruvavdghxlzyckwtmqjonsie
mbduvapdghxlzyckwrfqjrnsie
mkrsvapughxlzyckwtfqjonsie
mbruvapdghylzyckwtfqtolsie
mgruvapdglxldyckwtfqjonsie
mbrunapdghclzyckwtfqjonsiy
mbruvapdgrxlxyckwtfgjonsie
mbruvapdghxpzbckftfqjonsie
mbruvcpdghxyzyckotfqjonsie
mbruvapdghxlsyckwtfqcqnsie
mbruvapdghxlzzckwtfqjonskf
mbruvppdghxlzfckwtfqjgnsie
mbhuvapdghxlzytkwtfqjonoie
mbruvapdghxlzvrkwtfqjjnsie
mbmuvapdghxuzyckwtfqjonsze
mbruvapdghnlzycnwtfqjonsil
mbruvapdgholzyckitfqjonsia
mbruxapdghxlmyckwtfqbonsie
mbauvapdgholzyckwtfqjolsie
mbruvapdghxlzyckwtfqjotslq
dbrutapdghxlzyckwtfqjonsiv
mbruvapdzhxlyyckwtfbjonsie
mmruaapsghxlzyckwtfqjonsie
mbruvaldgqxqzyckwtfqjonsie
mbruvaodghxdzyjkwtfqjonsie
mbrcmatdghxlzyckwtfqjonsie
mbrqvapdgtxlzycewtfqjonsie
mjruvapdghzlzyckwtfqjonrie
mbruvapdghxopcckwtfqjonsie
mbruvapdghxszycwwtfqjoqsie
mbruvapdgoxezyckwtjqjonsie

59
2018/src/bin/day2.rs Normal file
View file

@ -0,0 +1,59 @@
use std::collections::HashMap;
use std::fs;
fn main() {
let input = fs::read_to_string("input/2018/day2.txt").expect("input");
part1(&input);
part2(&input);
}
fn part1(input: &str) {
let mut twos = 0;
let mut threes = 0;
for line in input.lines() {
let char_counts = count_chars(line);
if char_counts.iter().any(|(_k, &v)| v == 2) {
twos += 1;
}
if char_counts.iter().any(|(_k, &v)| v == 3) {
threes += 1;
}
}
println!("{}", twos * threes);
}
fn count_chars(line: &str) -> HashMap<char, u32> {
let mut counts = HashMap::new();
line.chars()
.for_each(|chr| *counts.entry(chr).or_insert(0) += 1);
counts
}
fn part2(input: &str) {
for (i, line) in input.lines().enumerate() {
for (j, other) in input.lines().enumerate() {
if i == j {
continue;
}
let number_differing =
line.chars().zip(other.chars()).fold(
0,
|acc, (chr1, chr2)| if chr1 != chr2 { acc + 1 } else { acc },
);
if (number_differing == 1) {
println!("{} and {} differ by 1 char", line, other);
let common: String = line
.chars()
.zip(other.chars())
.filter_map(|(chr1, chr2)| if chr1 != chr2 { None } else { Some(chr1) })
.collect();
println!("Common: {}", common);
return;
}
}
}
}