File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -63,3 +63,39 @@ const cleanRoom = function(robot) {
63
63
}
64
64
}
65
65
}
66
+
67
+ // another
68
+
69
+ /**
70
+ * @param {Robot } robot
71
+ * @return {void }
72
+ */
73
+ const cleanRoom = function ( robot ) {
74
+ const dirs = [
75
+ [ - 1 , 0 ] ,
76
+ [ 0 , 1 ] ,
77
+ [ 1 , 0 ] ,
78
+ [ 0 , - 1 ]
79
+ ]
80
+ const visited = new Set ( )
81
+ clean ( 0 , 0 , 0 )
82
+ function clean ( x , y , curDirection ) {
83
+ robot . clean ( )
84
+ visited . add ( `${ x } ,${ y } ` )
85
+ for ( let i = curDirection ; i < curDirection + 4 ; i ++ ) {
86
+ const nx = dirs [ i % 4 ] [ 0 ] + x
87
+ const ny = dirs [ i % 4 ] [ 1 ] + y
88
+ if ( ! visited . has ( `${ nx } ,${ ny } ` ) && robot . move ( ) ) {
89
+ clean ( nx , ny , i % 4 )
90
+ }
91
+ robot . turnRight ( )
92
+ }
93
+ robot . turnRight ( )
94
+ robot . turnRight ( )
95
+ robot . move ( )
96
+ robot . turnRight ( )
97
+ robot . turnRight ( )
98
+
99
+ }
100
+ } ;
101
+
You can’t perform that action at this time.
0 commit comments