R: fix ktLint and Detekt issues
This commit is contained in:
parent
98c91a107a
commit
6585014a1c
4 changed files with 77 additions and 49 deletions
64
src/main/kotlin/org/example/Rover.kt
Normal file
64
src/main/kotlin/org/example/Rover.kt
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package org.example
|
||||
|
||||
class Rover {
|
||||
constructor(p: String) {
|
||||
val s = p.split(' ')
|
||||
if (s.size >= 3) {
|
||||
rs.xx = s[0].toInt()
|
||||
rs.yy = s[1].toInt()
|
||||
rs.dd = s[2][0]
|
||||
}
|
||||
}
|
||||
|
||||
fun go(cms: String) {
|
||||
for (c in cms) {
|
||||
when (c) {
|
||||
'L' -> {
|
||||
when (rs.dd) {
|
||||
'E' -> rs.dd = 'N'
|
||||
'N' -> rs.dd = 'W'
|
||||
'W' -> rs.dd = 'S'
|
||||
'S' -> rs.dd = 'E'
|
||||
}
|
||||
}
|
||||
'R' -> {
|
||||
when (rs.dd) {
|
||||
'E' -> rs.dd = 'S'
|
||||
'S' -> rs.dd = 'W'
|
||||
'W' -> rs.dd = 'N'
|
||||
'N' -> rs.dd = 'E'
|
||||
}
|
||||
}
|
||||
'M' -> {
|
||||
when (rs.dd) {
|
||||
'E' -> rs.xx++
|
||||
'S' -> rs.yy--
|
||||
'W' -> rs.xx--
|
||||
'N' -> rs.yy++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun g(z: Char) {
|
||||
go(z.toString())
|
||||
}
|
||||
|
||||
val xyd: String
|
||||
get() = "${rs.xx} ${rs.yy} ${rs.dd}"
|
||||
|
||||
fun pos(): String {
|
||||
return xyd
|
||||
}
|
||||
|
||||
constructor() : this("")
|
||||
|
||||
private var rs = RoverState()
|
||||
}
|
||||
|
||||
class RoverState {
|
||||
var xx: Int = 0
|
||||
var yy: Int = 0
|
||||
var dd: Char = 'N'
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue