Part 1- way of thinking for the solution is amazing
@WayneBagguley19 күн бұрын
Part 1 in one line: fun calc(input: List): Int = input.flatMapIndexed { y, s -> s.mapIndexed { x, c -> x to c } .filter { it.second == 'X' }.map { it.first to y } }.sumOf { p -> listOf(0 to -1, 1 to -1, 1 to 0, 1 to 1, 0 to 1, -1 to 1, -1 to 0, -1 to -1) .count { o -> "XMAS".indices.map { input.getOrNull(p.second + it * o.second) ?.getOrNull(p.first + it * o.first) ?: "" }.joinToString("") == "XMAS" } } Part 2 in one line: fun calc(input:List): Int = input.flatMapIndexed { y, s -> s.mapIndexed { x, c -> x to c } .filter { it.second == 'A' }.map { it.first to y } }.count { p -> listOf(listOf(-1 to -1, 0 to 0, 1 to 1), listOf(1 to -1, 0 to 0, -1 to 1)).map{ it.map { s -> input.getOrNull(p.second + s.second) ?.getOrNull(p.first + s.first) ?: "" }.joinToString("").let{ it == "MAS" || it == "SAM" } }.all { it } }
@molasaheb608218 күн бұрын
they made their solution so complex that it's just useful for content creations and not any real world usage but they gonna scare away newbees from kotlin 🤣
@donwald343618 күн бұрын
It's nice when CPU and RAM are 100% free you can do whatever you want and everything runs in O(0) time! lol