diff --git a/2018/aoc02/Cargo.toml b/2018/aoc02/Cargo.toml new file mode 100644 index 0000000..58c8f72 --- /dev/null +++ b/2018/aoc02/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc02" +version = "0.1.0" +authors = ["Antoine Martin "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2018/aoc02/input/input.txt b/2018/aoc02/input/input.txt new file mode 100644 index 0000000..1a334bf --- /dev/null +++ b/2018/aoc02/input/input.txt @@ -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 diff --git a/2018/aoc02/src/main.rs b/2018/aoc02/src/main.rs new file mode 100644 index 0000000..802f59a --- /dev/null +++ b/2018/aoc02/src/main.rs @@ -0,0 +1,44 @@ +use std::collections::HashMap; +use std::env; +use std::fs; + +type Result = std::result::Result>; + +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 = 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(()) +} diff --git a/Cargo.lock b/Cargo.lock index fa1c669..5fc2e56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,3 +4,7 @@ name = "aoc01" version = "0.1.0" +[[package]] +name = "aoc02" +version = "0.1.0" + diff --git a/Cargo.toml b/Cargo.toml index e583ea6..91cf50d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] members = [ "2018/aoc01", + "2018/aoc02", ]