File tree Expand file tree Collapse file tree 1 file changed +8
-29
lines changed
Expand file tree Collapse file tree 1 file changed +8
-29
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,10 @@ fn part_a(input: &str) -> Answer {
66 let mut pos = 50 ;
77 let mut out = 0 ;
88
9- for line in input. trim ( ) . lines ( ) {
9+ for line in input. lines ( ) {
1010 let num = line[ 1 ..] . parse :: < u32 > ( ) . unwrap ( ) ;
1111 match line. as_bytes ( ) [ 0 ] {
12- b'L' => {
13- if num % 100 > pos {
14- pos = 100 - ( num % 100 - pos) ;
15- } else {
16- pos -= num;
17- }
18- }
12+ b'L' => pos = ( 100 + pos - num % 100 ) % 100 ,
1913 b'R' => pos = ( pos + num) % 100 ,
2014 _ => unreachable ! ( ) ,
2115 }
@@ -30,30 +24,16 @@ fn part_b(input: &str) -> Answer {
3024 let mut pos = 50 ;
3125 let mut out = 0 ;
3226
33- for line in input. trim ( ) . lines ( ) {
34- let num = line[ 1 ..] . parse :: < u32 > ( ) . unwrap ( ) ;
27+ for line in input. lines ( ) {
28+ let num = line[ 1 ..] . parse :: < u64 > ( ) . unwrap ( ) ;
3529 match line. as_bytes ( ) [ 0 ] {
3630 b'L' => {
37- for _ in 0 ..num {
38- if pos == 0 {
39- pos = 99 ;
40- } else {
41- pos -= 1 ;
42- }
43-
44- out += ( pos == 0 ) as u64 ;
45- }
31+ out += ( 99 - ( pos + 99 ) % 100 + num) / 100 ;
32+ pos = ( 100 + pos - num % 100 ) % 100 ;
4633 }
4734 b'R' => {
48- for _ in 0 ..num {
49- if pos == 99 {
50- pos = 0 ;
51- } else {
52- pos += 1 ;
53- }
54-
55- out += ( pos == 0 ) as u64 ;
56- }
35+ out += ( pos + num) / 100 ;
36+ pos = ( pos + num) % 100 ;
5737 }
5838 _ => unreachable ! ( ) ,
5939 }
@@ -77,7 +57,6 @@ mod test {
7757 L99
7858 R14
7959 L82
80-
8160 " } ;
8261
8362 #[ test]
You can’t perform that action at this time.
0 commit comments