/** * A Dyslectic worst nightmare. It looks pretty easy, but to write down what you can do easily in your head not so * trivial. It turned out a bit more spaghetti if code statements then I liked, but I think this covers all cases. */ import kotlin.math.pow fun main() { val (x, y) = readln().split(" ", limit = 2).map { it.toDegrees() } when (x) { in 0.0..y -> y - x else -> x - y }.let { println(when(it) { in 0.0 .. 180.0 -> it else -> 360.0 - it }) } } fun String.toDegrees(): Double { if(length == 1) { return when(first()) { 'N' -> 0.0 'E' -> 90.0 'S' -> 180.0 'W' -> 270.0 else -> error("invalid") } } val first = first() val last = last() return foldRightIndexed(0.0) { index, c, acc -> if (index == 0) { acc + when { c == 'N' && last == 'E' -> 0.0 c == 'N' && last == 'W' -> 270.0 c == 'S' && last == 'E' -> 90.0 c == 'S' && last == 'W' -> 180.0 else -> error("Invalid") } } else { val diff = (90.0 / (2.0.pow(length - index))) acc + when { diff == 45.0 -> diff c == 'N' && first == 'N' && last == 'E' -> -diff c == 'S' && first == 'E' && last == 'E' -> -diff c == 'S' && first == 'S' && last == 'W' -> -diff c == 'N' && first == 'W' && last == 'W' -> -diff else -> diff } } } }