summaryrefslogtreecommitdiff
path: root/aoc19/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'aoc19/src/main.rs')
-rw-r--r--aoc19/src/main.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/aoc19/src/main.rs b/aoc19/src/main.rs
index f76fce9..1930d8d 100644
--- a/aoc19/src/main.rs
+++ b/aoc19/src/main.rs
@@ -1,4 +1,9 @@
fn main() {
+ part1();
+ part2();
+}
+
+fn part1() {
let mut elves = (0..3017957).map(|i| i+1).collect::<Vec<_>>();
let mut eliminate_mod = 1;
@@ -14,5 +19,24 @@ fn main() {
}
let elf = elves[0];
- println!("Elf {} gets all the presents", elf);
+ println!("Elf {} gets all the presents in part 1", elf);
+}
+
+fn part2() {
+ let mut elves = (0..3017957).map(|i| i+1).collect::<Vec<_>>();
+
+ let mut i = 0;
+ while elves.len() > 1 {
+ i = i % elves.len();
+ let to_eliminate = (i + elves.len() / 2) % elves.len();
+// println!("Elf {} is taking presents from elf {}", elves[i], elves[to_eliminate]);
+ elves.remove(to_eliminate);
+ if to_eliminate > i {
+ i += 1;
+ }
+ }
+
+ let elf = elves[0];
+ println!("Elf {} gets all the presents in part 2", elf);
+
}