Marketing Pitch and Impressions#

Kotlin

Concise. Multiplatform. Fun.

kotlinlang.org

Kotlin is a great language. It’s the language of choice for Android development, and for folks working in the JVM space, it has access to all of the vast array of Java frameworks and libraries. The standard library is large and well thought out.

Visual Studio Code support is meh. Most folks use IntelliJ IDEA.

The Code#

I first “solved” this using a spreadsheet. I figured there would be a bunch of cases that could be trivially excluded, and a bunch of cases that could be trivially included, and I would just have to work out how to address what was left over. It turns out that the “difficult” problem set was quite small…

1
2
3
4
5
6
7
import java.io.File

val result1 = File("y25d12.txt").readText().split("\n\n").last().lines()
    .map { it.split(Regex("\\D+")).map(String::toInt) }
    .count { l -> l.take(2).map { it / 3 }.reduce(Int::times) >= l.drop(2).sum() }

println("Part1: $result1")

Install Kotlin and run#

The recommended way to install Kotlin is by installing IntelliJ IDEA. If you only want to run this script, it might be easier to just install the kotlin package if your package manager has it.

# I installed from Homebrew
brew install kotlin

# kotlinlang.org recommends installing IntelliJ IDEA or Android Studio
# https://kotlinlang.org/docs/getting-started.html#install-kotlin

# Execute the code (or launch from the IDE)
kotlin d12.kts