
commit
a89b15584e
5 changed files with 146 additions and 0 deletions
@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "day1" |
||||
version = "0.1.0" |
||||
|
@ -0,0 +1,9 @@
|
||||
[package] |
||||
name = "day1" |
||||
version = "0.1.0" |
||||
authors = ["Stefan Bühler <stbuehler@web.de>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
@ -0,0 +1,100 @@
|
||||
77680 |
||||
106826 |
||||
120225 |
||||
122031 |
||||
100287 |
||||
70402 |
||||
145496 |
||||
73956 |
||||
148205 |
||||
52065 |
||||
149237 |
||||
116195 |
||||
84309 |
||||
105327 |
||||
134606 |
||||
109489 |
||||
104474 |
||||
69536 |
||||
141469 |
||||
72321 |
||||
75154 |
||||
142565 |
||||
57104 |
||||
111925 |
||||
100109 |
||||
75178 |
||||
115130 |
||||
75586 |
||||
148587 |
||||
116029 |
||||
113969 |
||||
66072 |
||||
90521 |
||||
116324 |
||||
137009 |
||||
92880 |
||||
110895 |
||||
131046 |
||||
83273 |
||||
99576 |
||||
70466 |
||||
93602 |
||||
63435 |
||||
103569 |
||||
56610 |
||||
58392 |
||||
95060 |
||||
59101 |
||||
121838 |
||||
93494 |
||||
52243 |
||||
146982 |
||||
142260 |
||||
107232 |
||||
117600 |
||||
59715 |
||||
80284 |
||||
128223 |
||||
123676 |
||||
81060 |
||||
99425 |
||||
50621 |
||||
101184 |
||||
112136 |
||||
131262 |
||||
53150 |
||||
113522 |
||||
117802 |
||||
120251 |
||||
102322 |
||||
111247 |
||||
117719 |
||||
88873 |
||||
133541 |
||||
92695 |
||||
125445 |
||||
149048 |
||||
146928 |
||||
83909 |
||||
109466 |
||||
94063 |
||||
62338 |
||||
124098 |
||||
64769 |
||||
104722 |
||||
106612 |
||||
53882 |
||||
108847 |
||||
92739 |
||||
88496 |
||||
89773 |
||||
57471 |
||||
140532 |
||||
87308 |
||||
137247 |
||||
62816 |
||||
118893 |
||||
101446 |
||||
149208 |
||||
68267 |
@ -0,0 +1,29 @@
|
||||
fn fuel_for_modules1(input: &str) -> i64 { |
||||
let mut fuel: i64 = 0; |
||||
for module in input.split_whitespace() { |
||||
let module: i64 = module.parse().unwrap(); |
||||
fuel += (module / 3) - 2; |
||||
} |
||||
fuel |
||||
} |
||||
|
||||
fn fuel_for_mass2(mass: u64) -> u64 { |
||||
if mass <= 8 { return 0; } /* wish really hard */ |
||||
let fuel = mass / 3 - 2; |
||||
fuel + fuel_for_mass2(fuel) |
||||
} |
||||
|
||||
fn fuel_for_modules2(input: &str) -> u64 { |
||||
let mut fuel: u64 = 0; |
||||
for module in input.split_whitespace() { |
||||
let module: u64 = module.parse().unwrap(); |
||||
fuel += fuel_for_mass2(module); |
||||
} |
||||
fuel |
||||
} |
||||
|
||||
fn main() { |
||||
let input = include_str!("input.txt"); |
||||
println!("Fuel 1: {}", fuel_for_modules1(input)); |
||||
println!("Fuel 2: {}", fuel_for_modules2(input)); |
||||
} |
Loading…
Reference in new issue