Reorganizing for day2
This commit is contained in:
parent
b6d882c8a7
commit
26567460a1
3 changed files with 38 additions and 1031 deletions
|
|
@ -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::<i64>() {
|
||||
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::<i64>() {
|
||||
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());
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue