Skip to content

Commit 7f82e80

Browse files
committed
Misc
1 parent 2c7daea commit 7f82e80

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

aoc2024/src/bin/14.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,26 @@ pub fn part_two(input: &str) -> Option<u64> {
9797
}
9898

9999
// manually looking at output, see some sort of pattern at 19 and a different one at 70
100+
// pattern @ 19: Horizontal "ribbon"
101+
// pattern @ 70: Vertical "ribbon"
102+
// When the horizontal & vertical "ribbons" line up is where the tree will be.
103+
//
100104
// pattern at 19 repeats every 103 (height)
101-
// x*103 + 19 = res
102-
// pattern at 70 reteats every 101 (width)
103-
// y*101 + 70 = res
105+
// x*103 + 19 = res
106+
// pattern at 70 repeats every 101 (width)
107+
// y*101 + 70 = res
104108
//
105109
// y = (103x - 51)/101
106110

111+
// NOTE: These constants (19 & 70) will differ for different input - use the prints to find
112+
// where your patterns occur
113+
const VERTICAL_PATTERN: f64 = 19.0;
114+
const HORIZONTAL_PATTERN: f64 = 70.0;
115+
107116
let mut x = 0;
108117
for i in 1..101 {
109-
let res = (103.0 * (i as f64) - 51.0) / 101.0;
118+
let res =
119+
(HEIGHT as f64 * (i as f64) - (HORIZONTAL_PATTERN - VERTICAL_PATTERN)) / WIDTH as f64;
110120
// find first whole number - this is our x in x * 103 + 19 = res
111121
if res.fract() == 0.0 {
112122
x = i;
@@ -130,6 +140,7 @@ mod tests {
130140
#[test]
131141
fn test_part_two() {
132142
let result = part_two(&advent_of_code::template::read_file("examples", DAY));
133-
assert_eq!(result, Some(7847));
143+
// doesn't actually make a tree in example input
144+
assert_eq!(result, Some(122));
134145
}
135146
}

aoc2024/src/bin/15.rs

-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ use itertools::Itertools;
55

66
advent_of_code::solution!(15);
77

8-
#[derive(Clone, Copy, Debug)]
9-
enum Dir {
10-
Up,
11-
Down,
12-
Left,
13-
Right,
14-
}
15-
168
fn handle_move(d: Dir, curr: &mut (usize, usize), map: &mut [Vec<char>]) {
179
let mut temp = (curr.0, curr.1);
1810
match d {

0 commit comments

Comments
 (0)