File tree 2 files changed +16
-13
lines changed
2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -97,16 +97,26 @@ pub fn part_two(input: &str) -> Option<u64> {
97
97
}
98
98
99
99
// 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
+ //
100
104
// 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
104
108
//
105
109
// y = (103x - 51)/101
106
110
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
+
107
116
let mut x = 0 ;
108
117
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 ;
110
120
// find first whole number - this is our x in x * 103 + 19 = res
111
121
if res. fract ( ) == 0.0 {
112
122
x = i;
@@ -130,6 +140,7 @@ mod tests {
130
140
#[ test]
131
141
fn test_part_two ( ) {
132
142
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 ) ) ;
134
145
}
135
146
}
Original file line number Diff line number Diff line change @@ -5,14 +5,6 @@ use itertools::Itertools;
5
5
6
6
advent_of_code:: solution!( 15 ) ;
7
7
8
- #[ derive( Clone , Copy , Debug ) ]
9
- enum Dir {
10
- Up ,
11
- Down ,
12
- Left ,
13
- Right ,
14
- }
15
-
16
8
fn handle_move ( d : Dir , curr : & mut ( usize , usize ) , map : & mut [ Vec < char > ] ) {
17
9
let mut temp = ( curr. 0 , curr. 1 ) ;
18
10
match d {
You can’t perform that action at this time.
0 commit comments