-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76c7dcc
commit f177178
Showing
8 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
73617 | ||
104372 | ||
131825 | ||
85022 | ||
105514 | ||
78478 | ||
87420 | ||
118553 | ||
97680 | ||
89479 | ||
146989 | ||
79746 | ||
108085 | ||
117895 | ||
143811 | ||
102509 | ||
102382 | ||
92975 | ||
72978 | ||
94208 | ||
130521 | ||
83042 | ||
138605 | ||
107566 | ||
63374 | ||
71176 | ||
129487 | ||
118408 | ||
115425 | ||
63967 | ||
98282 | ||
121829 | ||
92834 | ||
61084 | ||
70122 | ||
87221 | ||
132773 | ||
141347 | ||
133225 | ||
81199 | ||
94994 | ||
60881 | ||
110074 | ||
63499 | ||
143107 | ||
76618 | ||
86818 | ||
135394 | ||
106908 | ||
96085 | ||
99801 | ||
112903 | ||
51751 | ||
56002 | ||
70924 | ||
62180 | ||
133025 | ||
68025 | ||
122660 | ||
64898 | ||
77339 | ||
62109 | ||
133891 | ||
134460 | ||
84224 | ||
54836 | ||
59748 | ||
125540 | ||
67796 | ||
71845 | ||
92899 | ||
130103 | ||
74612 | ||
136820 | ||
96212 | ||
132002 | ||
97405 | ||
82629 | ||
63717 | ||
62805 | ||
112693 | ||
147810 | ||
139827 | ||
116220 | ||
69711 | ||
50236 | ||
137833 | ||
103743 | ||
147456 | ||
112098 | ||
84867 | ||
75615 | ||
132738 | ||
81072 | ||
89444 | ||
58443 | ||
94465 | ||
112494 | ||
82127 | ||
132533 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! # The Tyranny of the Rocket Equation | ||
//! | ||
//! The title of the problem is a reference to the | ||
//! [real life equation](https://en.wikipedia.org/wiki/Tsiolkovsky_rocket_equation). | ||
use crate::util::parse::*; | ||
|
||
/// The [`iter_unsigned`] utility method extracts and parses numbers from surrounding text. | ||
/// | ||
/// [`iter_unsigned`]: crate::util::parse | ||
pub fn parse(input: &str) -> Vec<u32> { | ||
input.iter_unsigned().collect() | ||
} | ||
|
||
/// Calculate fuel requirements following the formula. | ||
pub fn part1(input: &[u32]) -> u32 { | ||
input.iter().map(|mass| mass / 3 - 2).sum() | ||
} | ||
|
||
/// Calculate the fuel requirements taking into account that fuel needs more fuel to lift it. | ||
/// Mass of 8 or below results in zero or negative fuel so we can stop. | ||
pub fn part2(input: &[u32]) -> u32 { | ||
input | ||
.iter() | ||
.copied() | ||
.map(|mut mass| { | ||
let mut fuel = 0; | ||
while mass > 8 { | ||
mass = mass / 3 - 2; | ||
fuel += mass; | ||
} | ||
fuel | ||
}) | ||
.sum() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use aoc::year2019::day01::*; | ||
|
||
const EXAMPLE: &str = "100756"; | ||
|
||
#[test] | ||
fn part1_test() { | ||
let input = parse(EXAMPLE); | ||
assert_eq!(part1(&input), 33583); | ||
} | ||
|
||
#[test] | ||
fn part2_test() { | ||
let input = parse(EXAMPLE); | ||
assert_eq!(part2(&input), 50346); | ||
} |