2018: aoc02 part1

This commit is contained in:
Antoine Martin 2019-11-14 18:19:23 +01:00
parent bcf61577e1
commit b80637585b
5 changed files with 308 additions and 0 deletions

9
2018/aoc02/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "aoc02"
version = "0.1.0"
authors = ["Antoine Martin <antoine97.martin@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

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

@ -0,0 +1,250 @@
tqzvwnogbarflkpcbdewsmjhxi
tqyvunogzarfckpcbdewsmzhci
tqyvunojzarflkpcbdcwsmyhxi
tqyvunogzarclkpcbdewmmjrxi
hqyvunogzarflkpcbczwsmjhxi
tqyvunogzarflppcudewsmjhei
tqrvunogzarflkpcbpewsmjhdi
aqyvunogzarflkpcbdewsjjsxi
tqyvtnogzarflkkcbdewymjhxi
tcyeunogzarfkkpcbdewsmjhxi
tqyvunozzarfvkpcbdewsqjhxi
tkyvuwjgzarflkpcbdewsmjhxi
tqevunogzarflkpnbdkwsmjhxi
tqyvunogqarflkpcppewsmjhxi
tqyvunsgzarflkpcbrewsmjhxk
tqyvunogzarffkpdbnewsmjhxi
tqyvunogvarflkpjbdewsojhxi
tqyvgnogzarflkpfbdswsmjhxi
tqyvunogzarfxkpcbtersmjhxi
tqyvukhgzarflupcbdewsmjhxi
tqyvdnoozyrflkpcbdewsmjhxi
tqyvunogzorflkpcbdewsvjhxd
tqyvunzqzarflkpcbdewxmjhxi
tqykunogzarulkpcbdhwsmjhxi
tqycdnogzarflkpcbdewsmjhxz
eqyvunogzarflkpcbdhwqmjhxi
cqyvunogzaralkpcbdewsmjvxi
vqyvunogzarflklcbeewsmjhxi
tqyvunogzarffkpcqdewlmjhxi
eqyvunogzarflkpcbdejsmahxi
tqyvunogjarflkocsdewsmjhxi
tqzvunogzanflkpcbdewsmjhxg
tqycunogzarflkpabdewsmkhxi
tqyvunogzarnlkpcbdewimjaxi
tqyvunogzarfzkpcbdepsyjhxi
gqykunogzarelkpcbdewsmjhxi
tqyvuwogzarflkpcbdrwsmjmxi
tqdqunogzarflkpcbdewsvjhxi
tqmvunbgzarflkpcbdewsvjhxi
tqyvunogzarflkpcbheesmjhdi
tqxvunogzarfxkpcbdewsmhhxi
tqyvunogzarflkpabdjosmjhxi
tqyvugogztrflkpybdewsmjhxi
tqyvundgzarflkxcbdewsmjhmi
tqyvunogzurfgkpcbdeksmjhxi
tqyvunokzarfckpcbdewsojhxi
tqyvufobzarflkpcldewsmjhxi
tqyvunogznrflkncbdeusmjhxi
tqyvuncgzarfxkpcmdewsmjhxi
oqyvunogzarflkpybdewbmjhxi
tqyvjnogqarfmkpcbdewsmjhxi
tqyvunogzacflkpcidewsmjhwi
tqyvunogzarflkpcbqlwxmjhxi
tqyvunogzarflkpnbhewsvjhxi
vqyiunogzarflkpcbdewsmjhqi
tbyvuncgzarfljpcbdewsmjhxi
tqylunogzarflkpcldexsmjhxi
tqyvulogzarflktcbdewsxjhxi
tqyvmnlgzarflkpcbxewsmjhxi
tqyvunogzartlkpcbdewsmihxp
nqyvunogzarflkpcbdewsmnwxi
tqyvunogzarflkpczdewsmjcxj
tzyvunogzariwkpcbdewsmjhxi
tqyiufogzarflipcbdewsmjhxi
oqyvunogzasflkpcbdewsmjhxv
tqyvunoqmarflkpcwdewsmjhxi
tqrvunogzarflkpqbdewnmjhxi
tqyvunogzarmlkocbdewsmjhri
tqyvunogzakflkpcbveasmjhxi
tqyvunorearflkpcbdewsmfhxi
tqynrnogzarflkpcbdewsmjhxp
tiyvueogzaeflkpcbdewsmjhxi
tqyrunogzarflkpccdewbmjhxi
tqtvunogzarflkpcbdewbnjhxi
tqyvfnogzarflhpcbdewsmjqxi
tqyjunoazarflkpcbdewssjhxi
tqyvunxizarflkpcbdewsmjnxi
tqyvunogzarfhkpobdewsmjhai
tqyaunogzanflkpcbxewsmjhxi
tqyvunogzarflkpsbuewsmjmxi
tqyvunogzarzlkwybdewsmjhxi
tqyvunogzarflkpibdawsmhhxi
tqyvunogzarflkycbdewamjwxi
tqyvunourarflkpcbdewsujhxi
tqyvnnogzirflkpcbdewsdjhxi
tayvunogzauflkpcqdewsmjhxi
tqyvunobzfrflkscbdewsmjhxi
tqygvnogzarflkpcbdewsmjnxi
oqyvunogzarflkpcbdewsmjsgi
tqyvunokzarflkpcbdewshjhii
tqyvunobzarflkvcbdewskjhxi
aqyvunogvarflkpcbdlwsmjhxi
tqyvunogzmrrlbpcbdewsmjhxi
tqyvunggzaqolkpcbdewsmjhxi
tqyvunogqarflkpybdewsmjaxi
tqyvunogzxrflkpcxsewsmjhxi
zqyvunogzarflppcbdewsmjhni
tqvvunogzakslkpcbdewsmjhxi
tqyrunogzarzlkpcbdewsmjtxi
tqyvhnogzarfxkpcbdewqmjhxi
tqyvunogzarflkecbdewgdjhxi
tqyvuwogzerfhkpcbdewsmjhxi
tqmvunogzarflkpcbddwsmdhxi
tqyvunogzarflcqcbdewsmihxi
tqyvunogzarvlkpcbdewsmjmxd
tqyvknogzarfllncbdewsmjhxi
tqyvunogzarflbpcbdrwsajhxi
tqyvunogzarfukpcbddwsmjhii
tqyvuvojzahflkpcbdewsmjhxi
tqyvunogzarfchpcbdeqsmjhxi
wqivueogzarflkpcbdewsmjhxi
tqyvunogzwrflkpcbdewstjhxz
tqyvunogzarfloscbdewsmjhxf
tqfbuiogzarflkpcbdewsmjhxi
tqyvfuogzarflkpcxdewsmjhxi
tqyvunogzarflkpcpdewsmgqxi
tqyvunogzdrflkpcbdewsmqhci
tqyvunogzartlkpcbdewsmjpxj
tqyfunogzarfwkpcbdewsmwhxi
tqyvuntgzarflkjcmdewsmjhxi
tqyvunqfzarflkpckdewsmjhxi
nqyvunogznrflkpcbiewsmjhxi
tqymunobzarflkccbdewsmjhxi
tqyvunogzaoflkprbdewzmjhxi
tqyvunogzaiflkpcvdewbmjhxi
tqwvunogzarfzkpcbdewsmjhxx
txhvunogzarflkpcbdewsijhxi
tqyeunogkarflkicbdewsmjhxi
tqylunogzarylkpcbdewsmkhxi
tqyvriogzarflkpcbdewsmohxi
tqyvunogzsrflkpcbdeasijhxi
tqyvunogzarflkpcbfewcmjhxh
tqyvunoozvrflkpcbdewimjhxi
tqyvunogqayflkpcidewsmjhxi
tqyounogzarflkpccdewsmjhxg
tqgvunogsarflkpcbdewqmjhxi
tqevunogzarflkpcbmewsmjhpi
tqivunogzarflkgcbdewqmjhxi
tqyuunogzlrflkgcbdewsmjhxi
xqyvbnogznrflkpcbdewsmjhxi
tqyvunogzarfjkpebdewsmnhxi
tqyvvnogzarfskpcxdewsmjhxi
thovunogzarflkpcbdewsmjhvi
tqyvunugzarflkpcpdewsmjrxi
tcyvvnogzarflkdcbdewsmjhxi
tqdfunogzarflkpbbdewsmjhxi
tqyvunogzarflkpcbdnwsejzxi
tqyvunivkarflkpcbdewsmjhxi
tqyvunogzawflopcbdewsmjhmi
tqyvunogzarflkpcbdkwsdjqxi
tqyvunodzarflkpcbdewlmjhei
oqyvunoozarflkpcbdemsmjhxi
tiyvunogzarjlkpcbdewfmjhxi
tqrvunogearflkpcbdewsojhxi
tqyvunkgzarflkpcbdcwtmjhxi
tqmvunogzarflkpcbdpwsmjtxi
tqyvunogzarflkpcydeptmjhxi
tqyvunkglarflkpcbdfwsmjhxi
tqyaunogzarflkpcbzeesmjhxi
tqyvunogzarrlkpcbdkwsmjhui
tpyvunogzarflkqcbdewsmjhxd
tvyvunogzarfkkpcbdewsajhxi
gqynunogzarflepcbdewsmjhxi
zqvvunogzarflkpcbdexsmjhxi
tqyyunogzawflkpcbdewsmjhxw
tfyvunogzarflkpcbdewomjrxi
tqyeunogzvrflrpcbdewsmjhxi
nqyvunogzarftkpabdewsmjhxi
tzyvunogzariwkpcbdewmmjhxi
tiyvunogzarflkpcbbewsmjhxa
tqydujoyzarflkpcbdewsmjhxi
tqyvunpgzarflkpcbdeysmjhwi
tqyvunogvarllkpcbdewsmshxi
tqyvunogzbrvlkpcbdewsmjhxp
tcyvueogzarflkacbdewsmjhxi
tqyvunogzrhflkpcbdetsmjhxi
tqavunogzrdflkpcbdewsmjhxi
tqyvunogzjrflkpcbdewstjhki
tqyqunolzarflkpcbdewbmjhxi
tqyvunogzarflkqczdgwsmjhxi
tqyvunogzqrfrkpcbrewsmjhxi
tqyvcnogzhrflkacbdewsmjhxi
tqyvunogzarflkpcbdewsmdhtk
tqyvunoggarftkpcbjewsmjhxi
tvyvunogzarfkkpcpdewsmjhxi
tqyvunogzawflkpcndedsmjhxi
tqyvunogzrrflkpcbdemsmmhxi
tqyvunogzarclkpcbrpwsmjhxi
tryvunogztrflkpcbbewsmjhxi
cqyvundgzarflkpcbdewgmjhxi
tqyvunogzarflktcbkewsmjqxi
tqyvjuogzarflkpcadewsmjhxi
tqyvunogzyrflkpcbbxwsmjhxi
ttyvunogzarflkpcbdewsnmhxi
tqyvunogzarflkpcbdeqsmlhki
fqyvugogzarflapcbdewsmjhxi
tqyvunogzartlkppbdewszjhxi
tqyvunfgztrflzpcbdewsmjhxi
tqyvunogmazflkpcbdewsmjhki
tqyvunzdzarflkpcbdewsmjhvi
tqyvunogzarflkpqbzewsujhxi
tqyvunogzarzlkpcbeewymjhxi
tqyounogzarflkpcbdewsnwhxi
tqysunogsaiflkpcbdewsmjhxi
tqdvunogdarflkpcboewsmjhxi
teyvunogzarflkscbdfwsmjhxi
tqyvunoazarflkpcbdvwsmjhpi
tqyvunooearflkpcbdewrmjhxi
tqyvunoszarflnrcbdewsmjhxi
tqyvunogzalflkpcblewsjjhxi
uqlvunkgzarflkpcbdewsmjhxi
tqyvunobzarflkpcidewsmjhvi
tnyvunogzarflkpcbdnwamjhxi
tqyoudogzarflkpcbdgwsmjhxi
tqyvunoggarflkpcbmewsmwhxi
tqykunogzazflkpcbddwsmjhxi
tfyvunogzarflkpcbdewsmjhgo
tqyvunogztrflkpcbdewoojhxi
tqyvunogzarflkpcbdewbmjoni
tmyvunogzalflkpabdewsmjhxi
tqyvunogzarflkpbbvewqmjhxi
tqyvunofzarflkpcwdexsmjhxi
tayvunogzasflkpcbdewsmhhxi
tqyvlnogzarflkpcbdewsmjwxd
tvyvunogzarflkpcbdewhmjrxi
tqyvunogzarplkpcsdewsmihxi
tqyvunogzarplklcbdewsmjtxi
rqbvunogzarhlkpcbdewsmjhxi
tqyvuxogzarftkpcbdewsmthxi
tqtvunogzarfikpczdewsmjhxi
tqyvunwgzarflkpcbdewsmjxxk
tqygunogzarzlkpnbdewsmjhxi
tqyvunogzarjlkpcbdbwswjhxi
tqyvunogzalfnkpcbdewsmjhxf
tqyucuogzarflkpcbdewsmjhxi
tzyvunogzvrflkpcbdewsmjaxi
tjyvunlgzarflkpcbdewgmjhxi
tqyvcnogzarklkpcbdewsmjhfi
tqyvunogzaaflkpsbaewsmjhxi
tsyvunogzarflkpctdewsmbhxi
tqyeunbgzarflkpcbdewrmjhxi
tqyvunogzcrflqpcbdeismjhxi
eqylunogzarflkpcbdewsmjhxy
tqyvundgzarflkpcbdewmmnhxi
tzyvunogzarflkpcndewsmjhxb
tkyvunogzxrflkpcbdewfmjhxi
tqyvunogzarflkxcbdzwsmjfxi
kqavunogzarflkycbdewsmjhxi
tqyvunogzarjlkpcbdxwkmjhxi
tqyvinogzarfqkpcbdewsmjpxi

44
2018/aoc02/src/main.rs Normal file
View file

@ -0,0 +1,44 @@
use std::collections::HashMap;
use std::env;
use std::fs;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
fn main() -> Result<()> {
let mut args = env::args();
args.next();
let input = fs::read_to_string(
&args
.next()
.expect("Please provide the path to the input file"),
)?;
part1(&input)?;
Ok(())
}
fn part1(input: &str) -> Result<()> {
let mut twice = 0;
let mut thrice = 0;
for line in input.lines() {
let mut seen: HashMap<char, u32> = HashMap::new();
for c in line.chars() {
*seen.entry(c).or_default() += 1;
}
if seen.values().any(|x| *x == 2) {
twice += 1;
}
if seen.values().any(|x| *x == 3) {
thrice += 1;
}
}
println!("{}", twice * thrice);
Ok(())
}

4
Cargo.lock generated
View file

@ -4,3 +4,7 @@
name = "aoc01"
version = "0.1.0"
[[package]]
name = "aoc02"
version = "0.1.0"

View file

@ -1,4 +1,5 @@
[workspace]
members = [
"2018/aoc01",
"2018/aoc02",
]