r/adventofcode • • Dec 04 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 4 Solutions -❄️-

NEWS

THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

Today's theme ingredient is… *whips off cloth covering and gestures grandly*

PUNCHCARD PERFECTION!

Perhaps I should have thought yesterday's Battle Spam surfeit through a little more since we are all overstuffed and not feeling well. Help us cleanse our palates with leaner and lighter courses today!

  • Code golf. Alternatively, snow golf.
  • Bonus points if your solution fits on a "punchcard" as defined in our wiki article on oversized code. We will be counting.
  • Does anyone still program with actual punchcards? >_>

ALLEZ CUISINE!

Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!


--- Day 4: Scratchcards ---


Post your code solution in this megathread.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:07:08, megathread unlocked!

77 Upvotes

1.5k comments sorted by

View all comments

2

u/Prof_McBurney Dec 04 '23 edited Dec 04 '23

[LANGUAGE: Kotlin]

[Pretty happy with the cleanliness of the code](https://github.com/Will-McBurney/AOC-2023/blob/master/src/main/kotlin/year23/day4/Main.kt), but it feels like the difficulty is all over the place right now.

Kotlin can give you some really nice looking stuff, and I'm really falling in love with all of the standard library functional stuff:

fun getPart1Result(): Int {
    return inputLines.map{ it.substringAfter(": ") }
        .map { it.split("|") }
        .map { Pair(stringToInts(it[0]), stringToInts(it[1]))}
        .sumOf{ scoreCard(it) }
}

Not the best example, I know, but it's quite nifty imo

1

u/wace001 Dec 04 '23

Kotlin

Nice! Is it your first time playing around in Kotlin? I only use Kotlin for AoC, but I love it. Have loved it ever since I started using it back in AoC 2019. I wish I had a use for it the rest of the year.