diff --git a/2018/src/day1-input.txt b/2018/src/day1-input.txt deleted file mode 100644 index 6007fec..0000000 --- a/2018/src/day1-input.txt +++ /dev/null @@ -1,994 +0,0 @@ -+5 --11 --1 --16 -+12 -+9 --15 -+20 -+4 -+17 --4 --14 -+6 --17 -+6 --19 --12 -+17 --6 --18 -+1 -+15 --14 -+10 --4 --2 -+5 -+6 -+8 -+3 -+17 --9 -+18 --1 -+17 --15 -+7 --6 --17 --17 -+19 -+19 --13 -+18 --15 -+16 -+7 --10 --5 -+22 -+8 --13 -+4 -+3 -+19 -+17 --19 --1 --11 -+2 -+1 --13 -+1 -+3 --14 -+16 --9 -+19 -+13 --20 -+6 -+22 -+10 -+6 -+15 --13 --13 --8 -+16 -+20 --5 -+1 -+7 -+11 --13 -+5 --16 --2 --4 -+25 --5 --10 --12 --9 -+16 --2 --19 --3 --12 -+5 -+17 -+16 -+11 -+16 -+10 -+4 -+3 -+11 --12 -+19 -+3 -+17 -+15 --6 --6 --4 -+3 -+10 -+8 -+15 --7 -+13 -+3 -+6 -+2 -+16 -+20 -+3 --11 -+3 --11 -+12 -+6 -+3 -+11 -+5 -+2 -+12 --4 --2 -+4 -+3 --4 -+20 -+1 -+19 -+14 -+5 --16 --15 --16 --4 --10 --13 --10 --18 -+10 --6 --7 --3 --2 --14 -+12 --2 --6 --11 --5 --6 -+20 --11 --1 -+9 --1 -+5 -+6 -+11 --19 --9 --14 --4 --6 --1 -+2 --6 --12 -+20 --12 --13 --9 --3 --7 --17 -+14 --9 -+20 --4 --8 --1 --6 -+16 -+6 --18 --12 -+6 --22 --15 -+10 -+6 -+20 --16 -+1 --18 -+4 -+19 -+9 --17 -+1 -+13 -+21 -+23 --4 -+7 --16 -+3 --4 --3 --17 --20 --10 --20 -+16 -+3 -+14 --11 -+3 --29 --1 -+7 --18 -+5 --7 --16 -+6 --7 --15 -+9 -+22 --2 --21 --18 -+1 -+10 -+13 -+13 --24 --6 --22 --10 -+9 -+4 --8 --16 -+3 --5 --19 --6 --11 -+3 --8 --16 --14 --16 --15 --6 -+3 -+13 -+8 --19 --18 --8 -+9 --15 --14 --2 -+18 --17 -+2 -+18 --6 --3 --19 -+16 --4 -+6 -+21 --6 -+7 -+17 --8 --4 -+6 -+19 --2 -+5 -+20 --3 --6 -+5 -+5 --17 --18 -+16 -+4 -+7 -+6 -+8 -+6 --1 -+10 --13 --4 --10 -+8 --14 -+17 -+9 -+2 --7 --22 --16 -+20 --13 -+8 --17 -+1 -+19 -+14 -+19 -+11 --6 -+25 -+18 -+19 -+5 -+20 -+17 -+4 --10 -+47 -+4 --1 -+23 -+24 --8 --10 -+31 -+19 --11 --17 -+8 --24 -+9 -+32 -+18 --1 -+4 --13 -+4 -+17 --2 -+11 -+11 -+4 --3 --3 -+22 -+19 -+14 --21 -+13 -+9 --14 --16 -+20 -+16 --14 -+5 --15 -+12 --11 -+1 -+3 --24 --9 --9 --22 --12 --10 --7 --3 -+12 -+13 -+17 --11 -+35 -+12 --9 -+16 -+22 --18 --18 -+19 --8 -+23 -+19 -+3 -+8 -+15 --2 -+11 -+14 -+10 -+15 -+8 --1 -+13 -+1 -+18 --11 -+4 -+4 -+11 -+9 --18 --9 -+13 --18 -+10 -+3 --6 --5 --10 --11 --14 --2 --9 -+3 --4 --6 -+13 --2 --17 --4 -+7 -+6 --12 --7 -+14 --6 --18 -+19 --18 --2 --13 -+6 --15 -+14 -+7 -+9 --14 -+9 --19 -+1 -+13 --2 --10 --11 -+13 --6 --6 -+19 -+10 -+17 --8 --7 -+19 -+16 --1 -+7 -+16 --15 --17 -+12 -+16 --2 -+14 --3 --16 --17 --5 -+16 -+29 --3 --2 -+13 --18 -+15 --4 --14 --12 --16 --19 -+39 --9 -+19 -+3 --11 -+10 -+12 -+19 --4 -+12 -+13 -+19 -+3 --19 -+9 --16 -+10 -+18 -+12 --6 --2 --11 -+20 -+15 -+15 -+4 -+12 --38 -+9 -+33 -+24 -+6 -+4 --36 --47 --15 --13 --3 -+1 -+12 -+14 -+9 --32 -+7 --16 --5 --29 -+12 --2 -+15 --12 --11 --39 --40 -+3 --34 --5 -+78 -+4 -+52 -+1 -+90 -+112 -+152 --80 -+81800 --18 -+15 --9 -+11 -+2 --5 -+16 --5 -+15 --1 -+2 --14 --7 -+12 --10 --9 -+20 -+14 --9 -+12 -+9 -+13 -+3 -+11 -+14 --3 -+10 -+8 -+12 -+5 -+10 -+1 -+14 --5 -+1 --4 --13 -+9 -+18 -+17 -+16 -+9 --1 --10 -+13 -+13 -+11 --18 -+15 --9 --13 -+3 -+1 -+11 --3 --10 -+19 --11 -+13 -+12 --8 --10 --6 -+13 -+5 --13 --7 --1 -+18 -+7 -+14 --2 -+5 -+1 -+16 --7 -+18 -+13 --6 -+18 --1 -+12 --4 --10 -+7 --15 --9 --7 --7 --6 -+11 --16 -+7 --4 -+11 --4 --6 --14 -+1 -+6 --3 -+2 -+21 -+12 --16 -+18 --5 -+17 -+4 -+19 -+6 --13 -+17 --3 --2 --17 -+7 --3 --7 -+14 -+17 -+8 -+7 --17 -+18 --15 --4 -+7 -+2 -+1 --14 --1 --6 -+9 --10 --4 -+15 --14 --18 --14 --9 --11 -+9 -+3 -+12 -+1 -+3 --10 --15 -+7 -+6 -+13 -+9 -+7 --4 -+9 --14 -+21 --9 -+24 -+10 -+6 -+6 --19 -+22 --10 --18 -+10 -+14 --4 -+3 -+7 -+14 -+11 -+16 --10 -+11 --9 --5 --6 --2 --15 -+3 --16 -+19 -+8 -+2 --17 -+3 -+5 -+14 --16 --4 --5 -+1 --3 -+4 -+6 -+18 -+16 -+4 --18 -+6 -+10 --6 -+1 -+6 -+9 -+17 --8 --15 --12 -+1 --6 -+4 -+12 -+2 -+17 --9 --7 -+10 -+12 -+17 -+8 -+15 -+7 --18 --1 -+4 -+13 --3 -+16 -+4 -+2 --8 --5 -+14 -+10 -+18 --15 -+19 --11 --4 --16 -+13 -+16 --15 -+10 --20 --7 --15 --10 --2 --6 -+19 --3 --9 --18 -+12 --8 -+3 -+13 -+20 -+18 --16 -+15 -+12 -+1 --18 -+10 --14 --17 --7 --9 --20 -+8 --9 -+7 --11 --19 -+7 --14 -+6 -+4 -+14 -+8 --11 -+2 --1 --19 -+16 -+9 --10 -+20 -+12 -+11 -+13 --3 --2 -+3 --20 -+6 --17 -+3 --9 --6 --16 -+7 -+7 --23 --6 -+14 --3 --31 --18 --19 --12 --26 -+23 -+9 --7 --10 -+22 -+17 -+17 --7 --8 -+9 -+28 -+5 -+24 --28 -+36 -+37 -+7 -+12 -+19 -+15 --3 --20 -+17 -+18 -+4 --8 -+9 --4 --2 --19 -+11 --1 -+3 --7 -+8 -+9 --8 -+19 -+9 -+12 --11 --5 --13 -+9 --6 -+7 -+17 --13 -+16 -+10 --5 -+20 -+6 --1 -+17 --14 -+10 -+18 --1 -+3 --10 --4 --10 --10 --16 --2 -+7 -+16 --12 -+6 -+8 -+22 -+7 --6 --13 --14 -+10 --1 --21 --1 -+8 --15 -+9 --17 --2 --21 -+4 --19 --13 --8 -+26 -+4 --27 --8 -+2 -+30 --11 --82484 diff --git a/2018/src/day1.rs b/2018/src/day1.rs new file mode 100644 index 0000000..ee3258c --- /dev/null +++ b/2018/src/day1.rs @@ -0,0 +1,35 @@ +use std::collections; +use std::str; + +const INPUT: &str = include_str!("input/day1.txt"); + +pub fn part1() -> i64 { + let mut freq = 0; + for line in str::lines(INPUT) { + match line.parse::() { + Ok(d) => freq += d, + Err(s) => println!("{}", s), + } + } + freq +} + +pub fn part2() -> i64 { + let mut freqs = collections::HashSet::new(); + let mut freq = 0; + freqs.insert(freq); + loop { + for line in str::lines(INPUT) { + match line.parse::() { + Ok(d) => { + freq += d; + if freqs.contains(&freq) { + return freq; + } + freqs.insert(freq); + } + Err(s) => println!("{}", s), + } + } + } +} diff --git a/2018/src/main.rs b/2018/src/main.rs index b722376..58cda89 100644 --- a/2018/src/main.rs +++ b/2018/src/main.rs @@ -1,40 +1,6 @@ -use std::collections; -use std::str; - -fn day1part1() -> i64 { - let input = include_str!("day1-input.txt"); - let mut freq = 0; - for line in str::lines(input) { - match line.parse::() { - Ok(d) => freq += d, - Err(s) => println!("{}", s), - } - } - freq -} - -fn day1part2() -> i64 { - let input = include_str!("day1-input.txt"); - let mut freqs = collections::HashSet::new(); - let mut freq = 0; - freqs.insert(freq); - loop { - for line in str::lines(input) { - match line.parse::() { - Ok(d) => { - freq += d; - if freqs.contains(&freq) { - return freq; - } - freqs.insert(freq); - } - Err(s) => println!("{}", s), - } - } - } -} +mod day1; fn main() { - println!("{}", day1part1()); - println!("{}", day1part2()); + println!("{}", day1::part1()); + println!("{}", day1::part2()); }