I made a silly mistake, and lost about an hour trying to figure out where I went wrong. I should set up my test runners ahead of day 2 so I don't end up with this same kind of typo.
funanswer2(input:List<String>):Int{valns=input.map(String::parseN).scan(Int::plus)valending=ns.lastreturn(sequenceOf(listOf(0))+generateSequence(ns){it.map(ending::plus)}).findFirstDupe(emptySet())}tailrecfunSequence<List<Int>>.findFirstDupe(seen:Set<Int>):Int{val(head,tail)=thisvalintersections=headintersectseenreturnwhen{intersections.isNotEmpty()->head.find{itinintersections}!!else->tail.findFirstDupe(seen+head)}}/**
* My prewritten `scan` function... it's just a `fold` that keeps every step.
*/fun<A,B>Sequence<A>.scan(initial:B,operation:(B,A)->B)=fold(sequenceOf(initial)){scanList,curr->scanList+operation(scanList.last(),curr)}
Part 2 is "slow", but it's still under a minute 5 seconds to brute force through 150 iterations (or so) of the cycle.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Kotlin Solution!
Part 1
Please exuse my tricked out kotlin, I've added some personal extension functions to let me think about list comprehensions more simply.
Part 2
I made a silly mistake, and lost about an hour trying to figure out where I went wrong. I should set up my test runners ahead of day 2 so I don't end up with this same kind of typo.
Part 2 is "slow", but it's still under
a minute5 seconds to brute force through 150 iterations (or so) of the cycle.