https://kotlinlang.org logo
#advent-of-code
Title
# advent-of-code
p

Pavlo Liapota

12/16/2018, 12:22 PM
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

Marcin Wisniowski

12/16/2018, 5:44 PM
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

Pavlo Liapota

12/16/2018, 6:22 PM
Makes sense 👍
4 Views