Day 1, part 1
commit
3442af1c78
|
@ -0,0 +1 @@
|
|||
/target
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aoc2021"
|
||||
version = "0.1.0"
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "aoc2021"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,25 @@
|
|||
use std::io;
|
||||
use std::io::prelude::*;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let f = File::open(&args[1])?;
|
||||
let buf = io::BufReader::new(f);
|
||||
let mut last = -1;
|
||||
let mut count_incr = 0;
|
||||
for line in buf.lines() {
|
||||
if let Ok(l) = line {
|
||||
if let Ok(value) = i32::from_str_radix(&l, 10) {
|
||||
if last > 0 && value > last {
|
||||
count_incr += 1;
|
||||
}
|
||||
last = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("number of increases: {}", count_incr);
|
||||
Ok(())
|
||||
}
|
Reference in New Issue