dustin
/
aoc2021
Archived
1
0
Fork 0

Day 1, part 1

master
Dustin 2021-12-01 20:07:56 -06:00
commit 3442af1c78
5 changed files with 2041 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View File

@ -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"

8
Cargo.toml Normal file
View File

@ -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]

2000
day1-input.txt Normal file

File diff suppressed because it is too large Load Diff

25
src/main.rs Normal file
View File

@ -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(())
}