commit d865b87052d4f8429b8962186a6d0e274439d252 Author: genofire Date: Mon Sep 7 21:13:03 2020 +0200 init with 2019 - day1 - part 1 diff --git a/2019/day1/.gitignore b/2019/day1/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/2019/day1/.gitignore @@ -0,0 +1 @@ +/target diff --git a/2019/day1/Cargo.lock b/2019/day1/Cargo.lock new file mode 100644 index 0000000..464d0c4 --- /dev/null +++ b/2019/day1/Cargo.lock @@ -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" diff --git a/2019/day1/Cargo.toml b/2019/day1/Cargo.toml new file mode 100644 index 0000000..731470e --- /dev/null +++ b/2019/day1/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day1" +version = "0.1.0" +authors = ["genofire "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/day1/src/main.rs b/2019/day1/src/main.rs new file mode 100644 index 0000000..8785e06 --- /dev/null +++ b/2019/day1/src/main.rs @@ -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); +}