Skip to content

Instantly share code, notes, and snippets.

@spikecurtis
Created December 2, 2021 05:20
Show Gist options
  • Save spikecurtis/d2133e199a05fd5476693e0b7c1b12ca to your computer and use it in GitHub Desktop.
Save spikecurtis/d2133e199a05fd5476693e0b7c1b12ca to your computer and use it in GitHub Desktop.
AoC Day 1
use std::io;
fn main() -> io::Result<()> {
let mut buffer = String::new();
let mut old0: i64 = 0;
let mut old1: i64 = 0;
let mut old_total: i64 = 0;
let mut increases = 0;
let mut i = 0;
loop {
buffer.clear();
let r = io::stdin().read_line(&mut buffer)?;
if r == 0 {
break;
}
buffer.pop();
let cur = buffer.parse::<i64>().unwrap();
let sum = cur + old0 + old1;
println!("cur: {}, sum: {}", cur, sum);
if sum > old_total && i > 2 {
println!{"inc."};
increases = increases + 1;
}
old_total = sum;
old0 = old1;
old1 = cur;
i = i + 1;
}
println!("{}", increases);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment