Added day 1 pt 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 = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
2003
inputs/day1.txt
Normal file
2003
inputs/day1.txt
Normal file
File diff suppressed because it is too large
Load Diff
22
src/main.rs
Normal file
22
src/main.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
const INPUT: &'static str = include_str!("../inputs/day1.txt");
|
||||
|
||||
fn depths() -> Vec<u64> {
|
||||
INPUT
|
||||
.lines()
|
||||
.filter(|&x| !x.is_empty())
|
||||
.map(|x| x.parse::<u64>().unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let days = depths();
|
||||
let mut count = 0;
|
||||
|
||||
for set in days.windows(2) {
|
||||
if set[1] > set[0] {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
println!("increased {} times", count);
|
||||
}
|
||||
Reference in New Issue
Block a user