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
use std::collections::HashMap; | |
#[derive(Debug,Hash,PartialEq,Eq,Copy,Clone)] | |
struct Pos(i8, i8); | |
type CharMat = Vec<Vec<char>>; | |
type MemoHash = HashMap<String, usize>; | |
struct Maze { | |
mat: CharMat, |
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 move = (a, b) => [a[0]+b[0], a[1]+b[1]] | |
// given data build a maze matrix | |
const buildMaze = (data) => { | |
const maze = data.slice(1).split('\n') | |
.map(r => r.split('')) | |
let startPos = [0, 0], numKeys = 0 | |
for (let i = 0; i < maze.length; i++) { | |
const row = maze[i] |
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-day3-part2.kt | |
fun part2(s: String) = evenOddGroups(s) | |
.flatMap { it.scan(0, nextPos) } | |
.distinct() | |
.count() | |
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-day3-evenOddGroups.kt | |
fun evenOddGroups(s: String) = s | |
.withIndex() | |
.groupBy { it.index % 2 }.values | |
.map { it.map { v -> v.value } | |
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-day3-part1.kt | |
fun part1(s: String) = s | |
.scan(0, nextPos) | |
.distinct() | |
.count() | |
} | |
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-day3-nextPos | |
private val len = 10000 | |
fun nextPos(acc: Int, c: Char) = when(c) { | |
'^' -> acc + len | |
'v' -> acc - len | |
'>' -> acc + 1 | |
'<' -> acc - 1 | |
else -> acc |
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-day2-part.kt | |
fun part( | |
list: List<Box>, | |
fn: (Int, Int, Int) -> Int | |
) = list | |
.map { (l, w, h) -> fn(l, w, h) } | |
.sum() | |
fun part1(list: List<Box>) = part(list, paper) |
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-d2-part2.kt | |
val paper2 = { l: Int, w: Int, h: Int -> | |
val m = maxOf(l, w, h) | |
(l + w + h - m) * 2 + l * w * h | |
} | |
fun part2(list: List<Box>) = list | |
.map { (l, w, h) -> paper2(l, w, h) } | |
.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
// aoc2015-d2-part1.kt | |
val paper = { l: Int, w: Int, h: Int -> | |
(l * w + w * h + h * l) * 2 + | |
l * w * h / maxOf(l, w, h) | |
} | |
fun part1(list: List<Box>) = list | |
.map { (l, w, h) -> paper(l, w, h) } | |
.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
// aoc-2015-day2.kt | |
typealias Box = List<Int> | |
fun extractBox(s: String): Box = "\\d+".toRegex() | |
.findAll(s) | |
.map { it.value.toInt() } | |
.toList() | |
} |
NewerOlder