File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ impl Cave {
123
123
124
124
/// # Panics
125
125
#[ must_use]
126
- pub fn solve ( data : & str ) -> ( usize , usize ) {
126
+ pub fn solve ( data : & str ) -> ( usize , u64 ) {
127
127
let jets: Vec < u8 > = data. trim ( ) . bytes ( ) . collect ( ) ;
128
128
129
129
let mut cave = Cave :: new ( ) ;
@@ -162,13 +162,13 @@ pub fn solve(data: &str) -> (usize, usize) {
162
162
}
163
163
164
164
if start != 0 && end != 0 {
165
- let remaining_rocks = 1_000_000_000_000 - start;
166
- let cycle_length = end - start;
165
+ let remaining_rocks = 1_000_000_000_000 - u64 :: try_from ( start) . unwrap ( ) ;
166
+ let cycle_length = u64 :: try_from ( end - start) . unwrap ( ) ;
167
167
168
168
let q = remaining_rocks / cycle_length;
169
- let r = remaining_rocks % cycle_length;
169
+ let r = usize :: try_from ( remaining_rocks % cycle_length) . unwrap ( ) ;
170
170
171
- part2 = heights[ start + r] + q * ( heights[ end] - heights[ start] ) ;
171
+ part2 = u64 :: try_from ( heights[ start + r] ) . unwrap ( ) + q * u64 :: try_from ( heights[ end] - heights[ start] ) . unwrap ( ) ;
172
172
}
173
173
174
174
( part1, part2)
Original file line number Diff line number Diff line change @@ -43,8 +43,12 @@ impl Puzzle {
43
43
}
44
44
45
45
match shift. 0 {
46
- o if o > 0 => q. rotate_left ( usize:: try_from ( o) . unwrap ( ) % ( nb - 1 ) ) ,
47
- o if o < 0 => q. rotate_right ( usize:: try_from ( -o) . unwrap ( ) % ( nb - 1 ) ) ,
46
+ o if o > 0 => q. rotate_left (
47
+ usize:: try_from ( o % i64:: try_from ( q. len ( ) ) . unwrap ( ) ) . unwrap ( ) % ( nb - 1 ) ,
48
+ ) ,
49
+ o if o < 0 => q. rotate_right (
50
+ usize:: try_from ( ( -o) % i64:: try_from ( q. len ( ) ) . unwrap ( ) ) . unwrap ( ) % ( nb - 1 ) ,
51
+ ) ,
48
52
_ => ( ) ,
49
53
}
50
54
You can’t perform that action at this time.
0 commit comments