diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2016-12-19 09:53:41 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2016-12-19 09:53:41 +0200 |
commit | 3d6b8afea8dfd397186f0be13d6c064e3e7a8ffe (patch) | |
tree | 0db3b6f1afcc46598c80d0ba323de6453526f6d5 /aoc19 | |
parent | 160dc053dda09b2e42236ff5b1a78c78a701e43a (diff) |
AOC19 part 1
runs fairly fast, but does not translate easily to part 2
Diffstat (limited to 'aoc19')
-rw-r--r-- | aoc19/Cargo.lock | 4 | ||||
-rw-r--r-- | aoc19/Cargo.toml | 6 | ||||
-rw-r--r-- | aoc19/src/main.rs | 18 |
3 files changed, 28 insertions, 0 deletions
diff --git a/aoc19/Cargo.lock b/aoc19/Cargo.lock new file mode 100644 index 0000000..7dc8a26 --- /dev/null +++ b/aoc19/Cargo.lock @@ -0,0 +1,4 @@ +[root] +name = "aoc19" +version = "0.1.0" + diff --git a/aoc19/Cargo.toml b/aoc19/Cargo.toml new file mode 100644 index 0000000..17889e3 --- /dev/null +++ b/aoc19/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "aoc19" +version = "0.1.0" +authors = ["Justin Worthe <justin.worthe@gmail.com>"] + +[dependencies] diff --git a/aoc19/src/main.rs b/aoc19/src/main.rs new file mode 100644 index 0000000..f76fce9 --- /dev/null +++ b/aoc19/src/main.rs @@ -0,0 +1,18 @@ +fn main() { + let mut elves = (0..3017957).map(|i| i+1).collect::<Vec<_>>(); + + let mut eliminate_mod = 1; + + while elves.len() > 1 { + let next_mod = if elves.len() % 2 == eliminate_mod { 0 } else { 1 }; + elves = elves.iter() + .enumerate() + .filter(|&(i, _)| i % 2 != eliminate_mod) + .map(|(_, &e)| e) + .collect(); + eliminate_mod = next_mod; + } + + let elf = elves[0]; + println!("Elf {} gets all the presents", elf); +} |