This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const animationRate = 30; // 30 ms | |
let initialTime, elapsedTime; | |
function animate(deltaT) { | |
// calculate object positions based on deltaT | |
} | |
function onFrame() { | |
const currentTime = new Date().getTime(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Aoc 2015 Day 1, Not Quite Lisp, Part 1 | |
fun part1(ops: List<Int>) = ops.sum() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Day 1: Not Quite Lisp, Part 2 | |
fun part2(ops: List<Int>): Int = ops.asSequence() | |
.scan(0) { acc, v -> acc + v } | |
.indexOf(-1) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun part2s(s: String): Int { | |
val all = s.asSequence() | |
scan(0) { acc, c -> acc + charValue(c) } | |
return all.indexOf(-1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
fun parseFile(name: String): List<String> = | |
File("../res/$name.input").readLines() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.extractNumbers(): List<Int> = | |
"""\d+""".toRegex() | |
.findAll(this) | |
.map { it.value.toInt() } | |
.toList() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// aoc2015-d0-part1 | |
fun part1(list: List<Model>) = list. | |
.map {} | |
... | |
.sum() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extract operation list from a string | |
fun extractOps(s: String): List<Int> = s | |
.map { charValue(it) } | |
.toList() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Map char into a int | |
private fun charValue(c: Char): Int = when (c) { | |
'(' -> 1 | |
')' -> -1 | |
else -> 0 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// aoc2015-day0-model | |
fun extractModal(str: String): Model { | |
return ... | |
} | |
OlderNewer