Initial solution
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 = "day01"
|
||||||
|
version = "0.1.0"
|
||||||
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "day01"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
2256
src/input.txt
Normal file
2256
src/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
30
src/main.rs
Normal file
30
src/main.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
use std::io::BufRead;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let path = Path::new("input.txt");
|
||||||
|
let file = File::open(&path).expect("Could not find file");
|
||||||
|
let lines = io::BufReader::new(file).lines();
|
||||||
|
let mut totals = Vec::new();
|
||||||
|
let mut running_tot = 0;
|
||||||
|
|
||||||
|
for line in lines {
|
||||||
|
if let Ok(line) = line {
|
||||||
|
if line.is_empty() {
|
||||||
|
totals.push(running_tot);
|
||||||
|
running_tot = 0;
|
||||||
|
} else if let Ok(i) = line.parse::<i32>() {
|
||||||
|
running_tot += i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
totals.sort_unstable_by(|a, b| b.partial_cmp(a).unwrap());
|
||||||
|
let max = totals[0];
|
||||||
|
let total :i32 = totals.into_iter().take(3).sum();
|
||||||
|
|
||||||
|
println!("first answer {}", max);
|
||||||
|
println!("second answer {}", total);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user