Found a nice usage of `generateSequence` for secon...
# advent-of-code
p
Found a nice usage of
generateSequence
for second part of Day 15:
Copy code
return generateSequence(4) { it + 1 }
    .map { elfAttack -> fight(inputs, elfAttack) }
    .first { result -> result.beings.none { it.kind == BeingKind.ELF && !it.alive } }
    .score
👍 1
m
The solution becomes a lot faster if you cancel a battle right away with the first elf death, instead of letting them all finish and looking afterwards.
p
Makes sense 👍