2022 day 1. Learning rust!
This commit is contained in:
parent
849fc74a15
commit
4bda83476c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
**/target/
|
7
2022/day01/Cargo.lock
generated
Normal file
7
2022/day01/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
2022/day01/Cargo.toml
Normal file
8
2022/day01/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]
|
2252
2022/day01/src/input.txt
Normal file
2252
2022/day01/src/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
26
2022/day01/src/main.rs
Normal file
26
2022/day01/src/main.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
use std::io;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
|
fn read_lines(filename: &str) -> io::Result<io::Lines<io::BufReader<File>>> {
|
||||||
|
let file = File::open(filename)?;
|
||||||
|
Ok(io::BufReader::new(file).lines())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut max = 0;
|
||||||
|
let mut current = 0;
|
||||||
|
|
||||||
|
for line in read_lines("input.txt").unwrap() {
|
||||||
|
let text = line.unwrap();
|
||||||
|
current = match text.parse::<i32>() {
|
||||||
|
Ok(value) => current + value,
|
||||||
|
Err(_) => {
|
||||||
|
if current > max { max = current; }
|
||||||
|
0
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{}", max);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user