Help needed for day 14 :bangbang:
# advent-of-code
k
Help needed for day 14 ‼️
For getting all floating masks I tried it with recusion
Copy code
private fun floatingMasksOf(mask: String): List<Mask> = when {
            mask.matches("""[01]+""".toRegex()) -> listOf(Mask(mask))
            else -> mutableListOf(
                floatingMasksOf(mask.replaceFirst('X', '0')),
                floatingMasksOf(mask.replaceFirst('X', '1'))
            ).flatten()
        }
How to avoid
listOf
and
flatten
. I tried using generate sequence but it did not work
t
plus ? As in
Copy code
floatingMasksOf(mask.replaceFirst('X', '0')) +
floatingMasksOf(mask.replaceFirst('X', '1'))
The first listOf is unavoidable I think (or at least I am fine with it)
k
Can
generateSequence
be used here?
t
You can use the
sequence {}
builder (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/sequence.html) with yield instead of listOf and yieldAll for both recursive calls. Not sure about
generateSequence
k
Thanks @Timmy