Implement day 11 in scala.

This commit is contained in:
2017-12-11 11:52:48 +01:00
parent b368355201
commit 07cc38a493
3 changed files with 41 additions and 1 deletions

View File

@@ -26,7 +26,7 @@ The current plan, in no particular order:
- [ ] Python - [ ] Python
- [x] Ruby - [Day 08](./day-08/solution.rb) - [x] Ruby - [Day 08](./day-08/solution.rb)
- [ ] Rust - [ ] Rust
- [ ] Scala - [x] Scala - [Day 11](./day-11/solution.scala)
- [ ] Scheme - [ ] Scheme
- [ ] SQL - [ ] SQL

1
2017/day-11/input.txt Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,39 @@
import scala.io.StdIn
object solution {
def main(args: Array[String]) {
println("Hello, world!")
val input = StdIn.readLine()
val dirs = input.trim.split(",")
follow(dirs)
}
def follow(dirs: Array[String]): Unit = {
var x = 0
var y = 0
var maxDist = 0
for (dir <- dirs) {
dir match {
case "s" => y -= 1
case "n" => y += 1
case "nw" => x -= 1
case "se" => x += 1
case "ne" => y += 1; x += 1
case "sw" => y -= 1; x -= 1
}
maxDist = Math.max(maxDist, dist(x, y))
}
println(dist(x, y))
println(maxDist)
}
def dist(x: Int, y: Int): Int = {
return Math.max(x, y);
}
}