Skip to content

Commit a0063c9

Browse files
committed
Year 2016 Day 25
1 parent ca8de76 commit a0063c9

File tree

8 files changed

+85
-0
lines changed

8 files changed

+85
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ pie
267267
| 22 | [Grid Computing](https://adventofcode.com/2016/day/22) | [Source](src/year2016/day22.rs) | 31 |
268268
| 23 | [Safe Cracking](https://adventofcode.com/2016/day/23) | [Source](src/year2016/day23.rs) | 1 |
269269
| 24 | [Air Duct Spelunking](https://adventofcode.com/2016/day/24) | [Source](src/year2016/day24.rs) | 335 |
270+
| 25 | [Clock Signal](https://adventofcode.com/2016/day/25) | [Source](src/year2016/day25.rs) | 1 |
270271

271272
## 2015
272273

benches/benchmark.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ mod year2016 {
8888
benchmark!(year2016, day22);
8989
benchmark!(year2016, day23);
9090
benchmark!(year2016, day24);
91+
benchmark!(year2016, day25);
9192
}
9293

9394
mod year2019 {

input/year2016/day25.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cpy a d
2+
cpy 4 c
3+
cpy 633 b
4+
inc d
5+
dec b
6+
jnz b -2
7+
dec c
8+
jnz c -5
9+
cpy d a
10+
jnz 0 0
11+
cpy a b
12+
cpy 0 a
13+
cpy 2 c
14+
jnz b 2
15+
jnz 1 6
16+
dec b
17+
dec c
18+
jnz c -4
19+
inc a
20+
jnz 1 -7
21+
cpy 2 b
22+
jnz c 2
23+
jnz 1 4
24+
dec b
25+
dec c
26+
jnz 1 -4
27+
jnz 0 0
28+
out b
29+
jnz a -19
30+
jnz 1 -21

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub mod year2016 {
215215
pub mod day22;
216216
pub mod day23;
217217
pub mod day24;
218+
pub mod day25;
218219
}
219220

220221
/// # Rescue Santa from deep space with a solar system adventure.

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ fn all_solutions() -> Vec<Solution> {
126126
solution!(year2016, day22),
127127
solution!(year2016, day23),
128128
solution!(year2016, day24),
129+
solution!(year2016, day25),
129130
// 2019
130131
solution!(year2019, day01),
131132
solution!(year2019, day02),

src/year2016/day25.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! # Clock Signal
2+
//!
3+
//! Like [`Day 12`] and [`Day 23`] this problem is all about *reading* code not writing code.
4+
//!
5+
//! Reverse engineering the code shows that it takes the initial value of `a` then adds
6+
//! two constants multiplied by each other to create a seed.
7+
//!
8+
//! This seed is then repeatedly bit shifted right by dividing by 2 using an inefficient linear
9+
//! time loop. The remainder (the bit that drops off) is the output. This means that output
10+
//! sequence is simply the binary digits of `a + offset` in reverse repeated over and over.
11+
//!
12+
//! To obtain the desired pattern we need the next highest binary number that has the
13+
//! pattern `101010..`.
14+
//!
15+
//! [`Day 12`]: crate::year2016::day12
16+
//! [`Day 23`]: crate::year2016::day23
17+
use crate::util::parse::*;
18+
19+
/// Extract the constant offset from the assembunny code.
20+
pub fn parse(input: &str) -> u32 {
21+
let lines: Vec<_> = input.lines().collect();
22+
let first: u32 = lines[1].unsigned();
23+
let second: u32 = lines[2].unsigned();
24+
first * second
25+
}
26+
27+
pub fn part1(input: &u32) -> u32 {
28+
let offset = *input;
29+
let mut result = 0;
30+
31+
// Find the next number with binary pattern `101010..` greater than the input.
32+
while result < offset {
33+
result = (result << 2) | 2;
34+
}
35+
36+
result - offset
37+
}
38+
39+
pub fn part2(_input: &u32) -> &'static str {
40+
"n/a"
41+
}

tests/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ mod year2016 {
8181
mod day22_test;
8282
mod day23_test;
8383
mod day24_test;
84+
mod day25_test;
8485
}
8586

8687
mod year2019 {

tests/year2016/day25_test.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[test]
2+
fn part1_test() {
3+
// No example data
4+
}
5+
6+
#[test]
7+
fn part2_test() {
8+
// No example data
9+
}

0 commit comments

Comments
 (0)