Day 1, part 1
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal 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
8
Cargo.toml
Normal 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
2000
day1-input.txt
Normal file
File diff suppressed because it is too large
Load Diff
25
src/main.rs
Normal file
25
src/main.rs
Normal 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(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user