re: AoC Day 2: Inventory Management System VIEW POST

re: Enjoyed this one. My Kotlin solution: package adventofcode2018.day2 import fun repeatCounts(s: String): Set<Int> =

Were you also annoyed that Kotlin has .groupBy but not .frequencies?

Have you thought about looking into Sequence? You could make your pairs function lazily? Using List means you're materializing the entirety of your double for-loop right away.


The lack of frequencies didn't bother me - it's easy to add. And yes, I've been thinking for the rest of the day that I should use lazy sequences. In this case the execution time remains O(NĀ²) but as you say the memory footprint becomes more like constant. Definitely a good practice when you can't find a better algorithm.

code of conduct - report abuse