@@ -11,20 +11,32 @@ struct Point {
11
11
fn main ( ) {
12
12
let stdin = io:: stdin ( ) ;
13
13
for line in stdin. lock ( ) . lines ( ) {
14
- let mut position = Point { x : 0 , y : 0 } ;
14
+ let mut santa_position = Point { x : 0 , y : 0 } ;
15
+ let mut robot_position = Point { x : 0 , y : 0 } ;
15
16
let mut visits = HashMap :: new ( ) ;
16
17
17
- * visits. entry ( position ) . or_insert ( 0 ) += 1 ;
18
+ * visits. entry ( santa_position ) . or_insert ( 0 ) += 1 ;
18
19
19
- for c in line. unwrap ( ) . chars ( ) {
20
- match c {
21
- '>' => position. x += 1 ,
22
- 'v' => position. y -= 1 ,
23
- '<' => position. x -= 1 ,
24
- '^' => position. y += 1 ,
25
- _ => { }
26
- } ;
27
- * visits. entry ( position) . or_insert ( 0 ) += 1
20
+ for ( i, c) in line. unwrap ( ) . chars ( ) . enumerate ( ) {
21
+ if i%2 == 0 {
22
+ match c {
23
+ '>' => santa_position. x += 1 ,
24
+ 'v' => santa_position. y -= 1 ,
25
+ '<' => santa_position. x -= 1 ,
26
+ '^' => santa_position. y += 1 ,
27
+ _ => { }
28
+ } ;
29
+ * visits. entry ( santa_position) . or_insert ( 0 ) += 1
30
+ } else {
31
+ match c {
32
+ '>' => robot_position. x += 1 ,
33
+ 'v' => robot_position. y -= 1 ,
34
+ '<' => robot_position. x -= 1 ,
35
+ '^' => robot_position. y += 1 ,
36
+ _ => { }
37
+ } ;
38
+ * visits. entry ( robot_position) . or_insert ( 0 ) += 1
39
+ }
28
40
}
29
41
30
42
println ! ( "{:?}" , visits. len( ) ) ;
0 commit comments