|
@@ -0,0 +1,27 @@
|
|
|
+fn total_fuel(mass: f32) -> i32 {
|
|
|
+ let mut req_fuel = get_fuel_cost(mass);
|
|
|
+ let mut fuel = req_fuel;
|
|
|
+ while get_fuel_cost(req_fuel as f32) > 0{
|
|
|
+ req_fuel = get_fuel_cost(req_fuel as f32);
|
|
|
+ fuel += req_fuel;
|
|
|
+ }
|
|
|
+
|
|
|
+ fuel
|
|
|
+}
|
|
|
+
|
|
|
+fn get_fuel_cost(mass: f32) -> i32{
|
|
|
+ ((mass / 3.0).floor() - 2.0) as i32
|
|
|
+}
|
|
|
+
|
|
|
+pub fn main() {
|
|
|
+
|
|
|
+ let contents = std::fs::read_to_string("input_day_1.txt").expect("Scream Internally");
|
|
|
+ let lines = contents.split("\r\n");
|
|
|
+ let mut all_f = 0;
|
|
|
+ for l in lines {
|
|
|
+ let x: f32 = l.parse().unwrap();
|
|
|
+ all_f += total_fuel(x);
|
|
|
+ }
|
|
|
+
|
|
|
+ println!("{}", all_f);
|
|
|
+}
|