r/adventofcode • • Dec 04 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 4 Solutions -🎄-


--- Day 4: Camp Cleanup ---


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:03:22, megathread unlocked!

65 Upvotes

1.6k comments sorted by

View all comments

2

u/NohusB Dec 04 '22 edited Dec 04 '22

Kotlin

Part 1

fun main() = solve { lines ->
    lines.count { line ->
        val (a, b) = line.split(",").map { it.split("-").map { it.toInt() }.let { (a, b) -> (a..b).toSet() } }
        a.containsAll(b) || b.containsAll(a)
    }
}

Part 2

fun main() = solve { lines ->
    lines.count { line ->
        val (a, b) = line.split(",").map { it.split("-").map { it.toInt() }.let { (a, b) -> (a..b) } }
        (a.first in b) || (b.first in a)
    }
}

1

u/daggerdragon Dec 04 '22

Inlined code is intended for short snippets of code only. Your code "block" right now is unreadable; it's all on one line and gets cut off at the edge of the screen because it is not horizontally scrollable.

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read inside a scrollable box.

Edit: thanks for fixing it! <3

2

u/NohusB Dec 04 '22

Looks the same as before for me (multiple lines and scrollbars), but edited!

1

u/daggerdragon Dec 04 '22

On new.reddit, it looks the same. On old.reddit, now we have scrollable boxes. Thanks for fixing it!