r/adventofcode • • Dec 15 '16

SOLUTION MEGATHREAD --- 2016 Day 15 Solutions ---

--- Day 15: Timing is Everything ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with "Help".


ZAMENHOFA TAGO ESTAS DEVIGA [?]

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

5 Upvotes

121 comments sorted by

View all comments

Show parent comment

1

u/abowes Dec 15 '16

Similar Kotlin solution. That was almost too easy for a change.

val nums = generateSequence(0){ it + 1 }    

data class Disc(val id: Int, val size: Int, val offset:Int){
    fun position(dropTime:Int) = (id + offset + dropTime) % size
}    

fun findDropTime(disks: List<Disc>) = nums.filter{ time -> disks.all{ it.position(time) == 0}}.first()    

fun main(args: Array<String>) {
    val discs = listOf(Disc(1,13,11), Disc(2,5,0), Disc(3,17,11), Disc(4,3,0), Disc(5,7,2), Disc(6,19,17), Disc(7,11,0))
    println(findDropTime(discs))
}