init with 2019 - day1 - part 1

This commit is contained in:
genofire 2020-09-07 21:13:03 +02:00
commit d865b87052
4 changed files with 46 additions and 0 deletions

1
2019/day1/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

5
2019/day1/Cargo.lock generated Normal file
View File

@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "day1"
version = "0.1.0"

9
2019/day1/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "day1"
version = "0.1.0"
authors = ["genofire <geno+dev@fireorbit.de>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

31
2019/day1/src/main.rs Normal file
View File

@ -0,0 +1,31 @@
fn main() {
let all_modules: [u32; 100] = [
83568, 132382, 65095, 105082, 138042, 59055, 79113, 123950, 59773, 55031, 56499, 122835,
123608, 82848, 109981, 115633, 126241, 137240, 54983, 129523, 101517, 90879, 82446, 105897,
108653, 130530, 113607, 140338, 125646, 112605, 68080, 105466, 93462, 147116, 127370,
128362, 83129, 146946, 102658, 62824, 52950, 119301, 61671, 92820, 139579, 93816, 148535,
77893, 80523, 69543, 51773, 144074, 100340, 64565, 68404, 88923, 144824, 87836, 51209,
99770, 111044, 144978, 56585, 137236, 73290, 86608, 72415, 57783, 130619, 109599, 59655,
99708, 118488, 104989, 93812, 135899, 110396, 89346, 119482, 67292, 143810, 64085, 104169,
145618, 104035, 75765, 88638, 139325, 89099, 132807, 117255, 98029, 114780, 104708, 100671,
98052, 141263, 149844, 117643, 123410,
];
let mut result = 0;
for i in all_modules.iter() {
result += fuel_calc(*i);
}
println!("I need {} fuel for all modules", result);
}
fn fuel_calc(mass: u32) -> u32 {
mass / 3 - 2
}
#[test]
fn test_it() {
assert_eq!(fuel_calc(12), 2);
assert_eq!(fuel_calc(14), 2);
assert_eq!(fuel_calc(1969), 654);
assert_eq!(fuel_calc(100756), 33583);
}