Made fist day by myself :3
This commit is contained in:
parent
435f0a2ffe
commit
4538a035c6
|
@ -2,6 +2,10 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day1"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tiesto"
|
name = "tiesto"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
members = [
|
members = [
|
||||||
"tiesto",
|
"tiesto",
|
||||||
|
"day1",
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "day1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,47 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
const FILE_PATH: &str = "input.txt";
|
||||||
|
println!("Hi this is the fist day of AOC2022, first we will read the file {}", FILE_PATH);
|
||||||
|
let contents = fs::read_to_string(FILE_PATH)
|
||||||
|
.expect("Should have been able to read the file");
|
||||||
|
println!("The elf with the biggest calories is: {}", get_max_elf(&contents));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_max_elf(input: &str) -> u32{
|
||||||
|
let binding = input.to_owned();
|
||||||
|
let input: Vec<&str> = binding.lines().collect();
|
||||||
|
let mut elfs = Vec::new();
|
||||||
|
let mut ptr: usize = 0;
|
||||||
|
elfs.push(0);
|
||||||
|
for line in input{
|
||||||
|
if line == "" {ptr+=1; elfs.push(0); continue;}
|
||||||
|
elfs[ptr] += u32::from_str(line).expect("all content must be numbers");
|
||||||
|
}
|
||||||
|
*elfs.iter().max().expect("there must be a maximum lol")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
let input = r#"1000
|
||||||
|
2000
|
||||||
|
3000
|
||||||
|
|
||||||
|
4000
|
||||||
|
|
||||||
|
5000
|
||||||
|
6000
|
||||||
|
|
||||||
|
7000
|
||||||
|
8000
|
||||||
|
9000
|
||||||
|
|
||||||
|
10000"#;
|
||||||
|
|
||||||
|
assert_eq!(get_max_elf(input), 24000);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue