Advent of Code 2024 in Kotlin. Day 4.

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ธ.ค. 2024

ความคิดเห็น • 3

  • @PushkarAgnihotri-ll4vv
    @PushkarAgnihotri-ll4vv 3 ชั่วโมงที่ผ่านมา

    Part 1- way of thinking for the solution is amazing

  • @WayneBagguley
    @WayneBagguley 5 ชั่วโมงที่ผ่านมา +1

    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 } }

    • @molasaheb6082
      @molasaheb6082 3 ชั่วโมงที่ผ่านมา

      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 🤣