mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement day 11 in scala.
This commit is contained in:
@@ -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
1
2017/day-11/input.txt
Normal file
File diff suppressed because one or more lines are too long
39
2017/day-11/solution.scala
Normal file
39
2017/day-11/solution.scala
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user