path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/Day12.kt | jstapels | 572,982,488 | false | {"Kotlin": 74335} |
fun main() {
data class Coord(val row: Int, val col: Int)
fun List<List<Char>>.get(pos: Coord) = this[pos.row][pos.col]
fun List<List<Char>>.height(pos: Coord) =
this[pos.row][pos.col]
.let { when (it) {
'S' -> 'a'
'E' -> 'z'
else -> it
... | 0 | Kotlin | 0 | 0 | 0d71521039231c996e2c4e2d410960d34270e876 | 2,969 | aoc22 | Apache License 2.0 |
src/Day02.kt | BenHopeITC | 573,352,155 | false | null | fun main() {
fun part3(input: List<String>) = input
.map { (it[0] - 'A') to (it[2] - 'X') }
.sumOf { (a, b) -> 3 * (4 + b - a).rem(3) + b + 1 }
fun part1(input: List<String>): Int {
val games = input.map {
val actions = it.split(" ")
actions[0] to actions[1]
... | 0 | Kotlin | 0 | 0 | 851b9522d3a64840494b21ff31d83bf8470c9a03 | 2,541 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/year2015/day18/Day18.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2015.day18
import check
import readInput
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("2015", "Day18_test")
check(part1(testInput, 4), 4)
check(part2(testInput, 5), 17)
val input = readInput("2015", "Day18")
println(pa... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 2,416 | AdventOfCode | Apache License 2.0 |
src/Day12.kt | AxelUser | 572,845,434 | false | {"Kotlin": 29744} | import java.util.*
private data class Day12Point(val coords: Pair<Int, Int>, val elevation: Int)
fun main() {
fun List<String>.find(c: Char): List<Pair<Int, Int>> {
val points = mutableListOf<Pair<Int, Int>>()
for (y in indices) {
for(x in this[y].indices) {
if (this[... | 0 | Kotlin | 0 | 1 | 042e559f80b33694afba08b8de320a7072e18c4e | 2,507 | aoc-2022 | Apache License 2.0 |
src/y2022/Day16.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2022
import util.readInput
import java.lang.Integer.max
object Day16 {
class Valve(
val id: String,
val rate: Int,
var neighbors: List<Valve>,
private val neighborIds: List<String>,
) {
companion object {
fun of(line: String): Valve {
... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 9,616 | advent-of-code | Apache License 2.0 |
src/Day05.kt | djleeds | 572,720,298 | false | {"Kotlin": 43505} | import java.util.*
typealias Stacks = List<Stack<Crate>>
typealias CrateMover = (src: Stack<Crate>, dst: Stack<Crate>, count: Int) -> Unit
private object Parser {
private const val FIELD_SIZE = 4
private val newline = System.lineSeparator()
private val movementRegex = Regex("move (\\d+) from (\\d+) to (\\... | 0 | Kotlin | 0 | 4 | 98946a517c5ab8cbb337439565f9eb35e0ce1c72 | 2,509 | advent-of-code-in-kotlin-2022 | Apache License 2.0 |
src/Day9.kt | sitamshrijal | 574,036,004 | false | {"Kotlin": 34366} | import kotlin.math.abs
import kotlin.math.sign
fun main() {
fun parse(input: List<String>): List<Pair<Direction, Int>> = input.map {
val (direction, count) = it.split(" ")
Direction.parse(direction) to count.toInt()
}
fun part1(input: List<String>): Int {
val movements = parse(inpu... | 0 | Kotlin | 0 | 0 | fd55a6aa31ba5e3340be3ea0c9ef57d3fe9fd72d | 2,385 | advent-of-code-2022 | Apache License 2.0 |
src/day08/Day08.kt | robin-schoch | 572,718,550 | false | {"Kotlin": 26220} | package day08
import AdventOfCodeSolution
fun main() {
Day08.run()
}
class Forest(private val trees: Array<IntArray>) {
operator fun Forest.get(coord: Pair<Int, Int>): Int = trees[coord.second][coord.first]
fun searchFromLeft() = searchForVisibleTrees(trees.indices, trees[0].indices) { x, y -> x to y }... | 0 | Kotlin | 0 | 0 | fa993787cbeee21ab103d2ce7a02033561e3fac3 | 3,124 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2023/2023-12.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2023
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
fun main() {
val input = readInputLines(2023, "12-input")
val test1 = readInputLines(2023, "12-test1")
println("Part1:")
part1(test1).println()
p... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 2,200 | advent-of-code | MIT License |
src/Day11.kt | oleksandrbalan | 572,863,834 | false | {"Kotlin": 27338} | import java.util.Deque
import java.util.LinkedList
fun main() {
val part1Monkeys = parseMonkeys()
part1Monkeys.playWithItems(PART1_ROUNDS) { this / 3 }
val part1 = part1Monkeys.calculateMonkeyBusiness()
println("Part2: $part1")
val part2Monkeys = parseMonkeys()
val commonTestBy = part2Monkeys... | 0 | Kotlin | 0 | 2 | 1493b9752ea4e3db8164edc2dc899f73146eeb50 | 2,915 | advent-of-code-2022 | Apache License 2.0 |
y2018/src/main/kotlin/adventofcode/y2018/Day15.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2018
import adventofcode.io.AdventSolution
import kotlin.math.abs
object Day15 : AdventSolution(2018, 15, "Beverage Bandits") {
override fun solvePartOne(input: String): Int {
val map = parse(input)
val combatants = mutableListOf<Combatant>()
for (y in map.indices) {... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 5,622 | advent-of-code | MIT License |
src/Day07.kt | mkfsn | 573,042,358 | false | {"Kotlin": 29625} | fun main() {
data class File(val name: String, val size: Int)
class Dir {
var parentDirectory: Dir? = null
val files: MutableList<File> = mutableListOf<File>()
val subDirectories: MutableMap<String, Dir> = mutableMapOf<String, Dir>()
fun traverseSize(recorder: (Int) -> Unit): I... | 0 | Kotlin | 0 | 1 | 8c7bdd66f8550a82030127aa36c2a6a4262592cd | 2,878 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day13/Day13.kt | xxfast | 572,724,963 | false | {"Kotlin": 32696} | package day13
import readText
// Parsing like an animal 🤯
fun format(line: String): List<Any> =
buildList {
var index = 0
var number = ""
while (true) {
if (index > line.lastIndex) break
var char = line[index++]
when {
char == ',' && number.isNotBlank() -> {
add(numb... | 0 | Kotlin | 0 | 1 | a8c40224ec25b7f3739da144cbbb25c505eab2e4 | 2,894 | advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/day15/Day15.kt | jakubgwozdz | 571,298,326 | false | {"Kotlin": 85100} | package day15
import execute
import parseRecords
import readAllText
import kotlin.math.absoluteValue
private fun Pair<Long, Long>.rotate45ish() = let { (x0, y0) ->
val x1 = x0 - y0
val y1 = x0 + y0
x1 to y1
}
private fun Pair<Long, Long>.rotateBack45ish() = let { (x1, y1) ->
val x0 = (x1 + y1) / 2
... | 0 | Kotlin | 0 | 0 | 7589942906f9f524018c130b0be8976c824c4c2a | 5,255 | advent-of-code-2022 | MIT License |
src/Day02/Day02.kt | Nathan-Molby | 572,771,729 | false | {"Kotlin": 95872, "Python": 13537, "Java": 3671} | package Day02
import readInput
enum class RPS {
ROCK, PAPER, SCISSORS;
fun kryptonite(inputRPS: RPS): RPS {
return when(inputRPS) {
RPS.ROCK -> RPS.PAPER
RPS.PAPER -> RPS.SCISSORS
RPS.SCISSORS -> RPS.ROCK
}
}
fun archNemesis(inputRPS: RPS): RPS {
... | 0 | Kotlin | 0 | 0 | 750bde9b51b425cda232d99d11ce3d6a9dd8f801 | 2,605 | advent-of-code-2022 | Apache License 2.0 |
src/year_2023/day_06/Day06.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2023.day_06
import readInput
fun List<Long>.product(): Long {
var product = 0L
this.forEach { value ->
if (product == 0L) {
product = value
} else {
product *= value
}
}
return product
}
object Day06 {
/**
*
*/
fun solution... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 1,675 | advent_of_code | Apache License 2.0 |
src/day11/Day11.kt | martin3398 | 572,166,179 | false | {"Kotlin": 76153} | package day11
import readInput
class Monkey(
private val items: MutableList<Long>,
private val operation: String,
private val testDivisor: Long,
private val trueTargetMonkey: Int,
private val falseTargetMonkey: Int,
private val modulo: Int
) {
private var inspectionCount = 0
fun inspe... | 0 | Kotlin | 0 | 0 | 4277dfc11212a997877329ac6df387c64be9529e | 2,901 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | mandoway | 573,027,658 | false | {"Kotlin": 22353} | import kotlin.math.pow
import kotlin.math.sqrt
fun Pair<Int, Int>.distanceTo(other: Pair<Int, Int>) =
sqrt(
(first - other.first).toDouble().pow(2)
+ (second - other.second).toDouble().pow(2)
)
operator fun Pair<Int, Int>.minus(other: Pair<Int, Int>) = first - other.first to second - o... | 0 | Kotlin | 0 | 0 | 0393a4a25ae4bbdb3a2e968e2b1a13795a31bfe2 | 2,313 | advent-of-code-22 | Apache License 2.0 |
src/main/day06/Day06.kt | rolf-rosenbaum | 543,501,223 | false | {"Kotlin": 17211} | package day06
import readInput
import second
import kotlin.math.abs
fun part1(input: List<String>): Int {
val points = input.mapIndexed { index, line ->
line.toPoint(index.toString())
}
val map = mutableSetOf<Point>()
(points.minOf { it.x }..points.maxOf { it.x }).forEach { x ->
(poin... | 0 | Kotlin | 0 | 0 | dfd7c57afa91dac42362683291c20e0c2784e38e | 1,722 | aoc-2018 | Apache License 2.0 |
src/day03.kts | miedzinski | 434,902,353 | false | {"Kotlin": 22560, "Shell": 113} | val line = readLine()!!
val nBits = line.length
val input = (sequenceOf(line) + generateSequence(::readLine)).map { it.toInt(2) }.toList()
fun mostCommon(numbers: List<Int>, nthBit: Int): Int? =
numbers.count { it and (1 shl nthBit) != 0 }.let {
when {
2 * it > numbers.size -> 1 shl nthBit
... | 0 | Kotlin | 0 | 0 | 6f32adaba058460f1a9bb6a866ff424912aece2e | 1,255 | aoc2021 | The Unlicense |
src/day09.kts | miedzinski | 434,902,353 | false | {"Kotlin": 22560, "Shell": 113} | val map = generateSequence(::readLine).map {
it.map(Char::digitToInt)
}.toList()
typealias HeightMap = List<List<Int>>
data class Point(val x: Int, val y: Int)
operator fun HeightMap.get(point: Point): Int = this[point.x][point.y]
fun HeightMap.points(): Sequence<Point> =
(0 until size)
.asSequence(... | 0 | Kotlin | 0 | 0 | 6f32adaba058460f1a9bb6a866ff424912aece2e | 1,548 | aoc2021 | The Unlicense |
y2019/src/main/kotlin/adventofcode/y2019/Day14.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2019
import adventofcode.io.AdventSolution
import kotlin.math.ceil
fun main() = Day14.solve()
object Day14 : AdventSolution(2019, 14, "Space Stoichiometry") {
override fun solvePartOne(input: String) = calculateOre(1L, parse(input))
override fun solvePartTwo(input: String): Long {
... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 2,200 | advent-of-code | MIT License |
src/Day02.kt | VadimB95 | 574,449,732 | false | {"Kotlin": 19743} | import java.lang.IllegalArgumentException
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day02_test")
check(part1(testInput) == 15)
val input = readInput("Day02")
println(part1(input))
println(part2(input))
}
private fun part1(inpu... | 0 | Kotlin | 0 | 0 | 3634d1d95acd62b8688b20a74d0b19d516336629 | 2,261 | aoc-2022 | Apache License 2.0 |
src/Day24.kt | timhillgit | 572,354,733 | false | {"Kotlin": 69577} | import java.util.PriorityQueue
data class BlizzardNode(val location: Point, val minutes: Int)
fun Point.orthogonal() = listOf(
Point(1, 0),
Point(0, 1),
Point(-1, 0),
Point(0, -1),
).map(::plus)
class BlizzardBasin(
val initialConditions: List<List<Char>>,
val entrance: Point,
val exit: P... | 0 | Kotlin | 0 | 1 | 76c6e8dc7b206fb8bc07d8b85ff18606f5232039 | 3,637 | advent-of-code-2022 | Apache License 2.0 |
13/kotlin/src/main/kotlin/se/nyquist/Main.kt | erinyq712 | 437,223,266 | false | {"Kotlin": 91638, "C#": 10293, "Emacs Lisp": 4331, "Java": 3068, "JavaScript": 2766, "Perl": 1098} | package se.nyquist
import java.io.File
fun main() {
val lines = File("input.txt").readLines()
val coordinates = lines.filter{ it.contains(',')}.map { getPair(it) }.toList()
val instructionsLines = lines.filter{ it.contains('=')}.map { it.split(" ")[2].split("=") }.map { Pair(it[0], it[1]) }
exercise1(... | 0 | Kotlin | 0 | 0 | b463e53f5cd503fe291df692618ef5a30673ac6f | 2,818 | adventofcode2021 | Apache License 2.0 |
src/Day07.kt | davedupplaw | 573,042,501 | false | {"Kotlin": 29190} | interface Item {
val name: String
fun size(): Int
}
data class File(override val name: String, private val size: Int) : Item {
override fun size() = size
}
class Directory(
override val name: String,
val parent: Directory? = null,
private val files: MutableList<Item> = mutableListOf()
) : Item... | 0 | Kotlin | 0 | 0 | 3b3efb1fb45bd7311565bcb284614e2604b75794 | 2,733 | advent-of-code-2022 | Apache License 2.0 |
Advent-of-Code-2023/src/Day04.kt | Radnar9 | 726,180,837 | false | {"Kotlin": 93593} | import kotlin.math.pow
private const val AOC_DAY = "Day04"
private const val PART1_TEST_FILE = "${AOC_DAY}_test_part1"
private const val PART2_TEST_FILE = "${AOC_DAY}_test_part2"
private const val INPUT_FILE = AOC_DAY
private const val DOUBLE_POINTS = 2.0
/**
* Finds and counts the points of the numbers that match... | 0 | Kotlin | 0 | 0 | e6b1caa25bcab4cb5eded12c35231c7c795c5506 | 3,751 | Advent-of-Code-2023 | Apache License 2.0 |
src/day7/Day7.kt | gautemo | 317,316,447 | false | null | package day7
import shared.getLines
fun nrCanContainGoldBag(bagRules: List<String>): Int {
val bags = mapToBags(bagRules)
return bags.count { containGold(it, bags) }
}
fun containGold(bag: Bag, bags: List<Bag>): Boolean{
return bag.contain.any { inside ->
inside.color == "shiny gold" || containGo... | 0 | Kotlin | 0 | 0 | ce25b091366574a130fa3d6abd3e538a414cdc3b | 1,521 | AdventOfCode2020 | MIT License |
src/twentytwo/Day02.kt | Monkey-Matt | 572,710,626 | false | {"Kotlin": 73188} | package twentytwo
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInputLines("Day02_test")
println(part1(testInput))
check(part1(testInput) == 15)
println(part2(testInput))
check(part2(testInput) == 12)
println("---")
val input = re... | 1 | Kotlin | 0 | 0 | 600237b66b8cd3145f103b5fab1978e407b19e4c | 4,093 | advent-of-code-solutions | Apache License 2.0 |
src/year_2023/day_08/Day08.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2023.day_08
import readInput
import util.lcm
data class Node(
val name: String,
val left: String,
val right: String
)
object Day08 {
/**
*
*/
fun solutionOne(text: List<String>): Long {
val pattern = text[0]
val nodes = text.drop(2).map { parseNode(it) }
... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 2,393 | advent_of_code | Apache License 2.0 |
src/main/kotlin/day22.kt | tobiasae | 434,034,540 | false | {"Kotlin": 72901} | class Day22 : Solvable("22") {
override fun solveA(input: List<String>): String {
val cuboids = input.map { Cuboid.getFromString(it) }
val grid = Array(101) { Array(101) { Array(101) { false } } }
cuboids.forEach {
for (x in it.xMin..it.xMax) {
if (x < -50) cont... | 0 | Kotlin | 0 | 0 | 16233aa7c4820db072f35e7b08213d0bd3a5be69 | 2,967 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/oocode/EngineSchematic.kt | ivanmoore | 725,978,325 | false | {"Kotlin": 42155} | package com.oocode
fun engineSchematicFrom(input: String): EngineSchematic {
val lines = input.split("\n")
val numbers = lines.flatMapIndexed { index, line -> numbersFrom(line, index) }.toSet()
val symbols = lines.flatMapIndexed { index, line -> symbolsFrom(line, index) }.toSet()
val gearIndicators = l... | 0 | Kotlin | 0 | 0 | 36ab66daf1241a607682e7f7a736411d7faa6277 | 2,397 | advent-of-code-2023 | MIT License |
src/Day18.kt | shepard8 | 573,449,602 | false | {"Kotlin": 73637} | import kotlin.math.abs
import kotlin.math.max
fun main() {
open class Lava(val x: Int, val y: Int, val z: Int): Comparable<Lava> {
override fun toString(): String {
return "Lava($x, $y, $z)"
}
fun touches(other: Lava): Boolean {
val dx = abs(x - other.x)
... | 0 | Kotlin | 0 | 1 | 81382d722718efcffdda9b76df1a4ea4e1491b3c | 2,240 | aoc2022-kotlin | Apache License 2.0 |
src/y2021/Day05.kt | Yg0R2 | 433,731,745 | false | null | package y2021
import kotlin.math.abs
import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
return input
.toOceanFloor { x1, y1, x2, y2, oceanFloor ->
if (x1 == x2) {
val yDelta = y2.compareTo(y1)
for (y in 0..abs(y1 -... | 0 | Kotlin | 0 | 0 | d88df7529665b65617334d84b87762bd3ead1323 | 2,084 | advent-of-code | Apache License 2.0 |
src/Day07.kt | khongi | 572,983,386 | false | {"Kotlin": 24901} | sealed class Node(
val name: String,
val parent: Dir?,
val level: Int,
) {
abstract fun calculateSize(): Int
abstract fun print()
}
class File(
name: String,
parent: Dir,
level: Int,
val size: Int,
) : Node(name, parent, level) {
override fun calculateSize() = size
override ... | 0 | Kotlin | 0 | 0 | 9cc11bac157959f7934b031a941566d0daccdfbf | 3,769 | adventofcode2022 | Apache License 2.0 |
src/Day04.kt | icoffiel | 572,651,851 | false | {"Kotlin": 29350} | fun main() {
fun part1(input: List<String>): Int {
return input
.map { it.toRangeList() }
.count { (first, second) -> first.toSet() fullyContains second.toSet() }
}
fun part2(input: List<String>): Int {
return input
.map { it.toRangeList() }
.co... | 0 | Kotlin | 0 | 0 | 515f5681c385f22efab5c711dc983e24157fc84f | 1,460 | advent-of-code-2022 | Apache License 2.0 |
src/Day16.kt | Fedannie | 572,872,414 | false | {"Kotlin": 64631} | import java.util.PriorityQueue
import kotlin.math.max
class Valve(val name: String, val flowRate: Int, val index: Int) {
val next = MutableList(0) { "" to 1 }
}
const val startValve = "AA"
class DFSState(val last: Valve, val time: Int, val open: Set<String>): Comparable<DFSState> {
override fun compareTo(other: ... | 0 | Kotlin | 0 | 0 | 1d5ac01d3d2f4be58c3d199bf15b1637fd6bcd6f | 5,036 | Advent-of-Code-2022-in-Kotlin | Apache License 2.0 |
src/Day03.kt | thpz2210 | 575,577,457 | false | {"Kotlin": 50995} | private class Solution03(input: List<String>) {
private val rucksacks = input.map { Rucksack(it) }
private fun getGroupItem(chunk: List<Rucksack>): Set<Char> {
return chunk[0].items.toSet().intersect(
chunk[1].items.toSet().intersect(
chunk[2].items.toSet()
)
... | 0 | Kotlin | 0 | 0 | 69ed62889ed90692de2f40b42634b74245398633 | 1,228 | aoc-2022 | Apache License 2.0 |
src/Day08.kt | cisimon7 | 573,872,773 | false | {"Kotlin": 41406} | fun main() {
fun part1(trees: List<List<Int>>): Int {
val treesVisibility = with(trees) {
mapIndexed { rIdx, row ->
row.mapIndexed { cIdx, height ->
when {
rIdx == 0 || cIdx == size - 1 -> true
rIdx == row.size -... | 0 | Kotlin | 0 | 0 | 29f9cb46955c0f371908996cc729742dc0387017 | 2,011 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day14/Day14.kt | Avataw | 572,709,044 | false | {"Kotlin": 99761} | package day14
import kotlin.math.max
import kotlin.math.min
fun solveA(input: List<String>): Int {
val occupiedPositions = input.parseToCave().toMutableSet()
val lowestRockHeight = occupiedPositions.maxBy { it.y }.y
return occupiedPositions.pourSandWithoutFloor(lowestRockHeight)
}
fun solveB(input: Li... | 0 | Kotlin | 2 | 0 | 769c4bf06ee5b9ad3220e92067d617f07519d2b7 | 2,661 | advent-of-code-2022 | Apache License 2.0 |
src/main/aoc2023/Day7.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2023
class Day7(val input: List<String>) {
private data class Hand2(val cards: String, val bid: Int, private val useJokers: Boolean) {
// The type of the hand, higher number means better hand
val type: Int
// The strength of the hand, used for comparisons when the type of two h... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,350 | aoc | MIT License |
src/Day07.kt | emersonf | 572,870,317 | false | {"Kotlin": 17689} | fun main() {
data class PathSizeEntry(val path: String, val size: Int)
fun List<String>.parseInput(): List<PathSizeEntry> {
val path = ArrayDeque<String>(50)
path.add("root")
return flatMap { line ->
if (line.first() !in '0'..'9') {
when {
... | 0 | Kotlin | 0 | 0 | 0e97351ec1954364648ec74c557e18ccce058ae6 | 2,173 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/github/lernejo/korekto/toolkit/misc/Distances.kt | lernejo | 315,255,600 | false | {"Kotlin": 83210, "HTML": 3592, "Java": 220} | package com.github.lernejo.korekto.toolkit.misc
import java.util.*
import java.util.stream.Collectors
import java.util.stream.Stream
import kotlin.math.min
object Distances {
private fun minimum(a: Int, b: Int, c: Int): Int {
return min(min(a, b), c)
}
fun levenshteinDistance(lhs: CharSequence?, ... | 4 | Kotlin | 0 | 0 | df998e7098b20454f35cdc05ab3b7b3632fc3ac1 | 3,447 | korekto-toolkit | Apache License 2.0 |
2021/src/main/kotlin/day14_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.mapItems
import utils.mergeToMap
import utils.withLCounts
fun main() {
Day14Func.run()
}
object Day14Func : Solution<Pair<Day14Func.Polymer, List<Pair<String, String>>>>() {
override val name = "day14"
override val parser = Parser { input ->
val (polyme... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,329 | aoc_kotlin | MIT License |
src/Day15.kt | inssein | 573,116,957 | false | {"Kotlin": 47333} | import kotlin.math.abs
fun main() {
data class Sensor(val position: Pair<Int, Int>, val distance: Int)
data class Beacon(val position: Pair<Int, Int>, val sensors: MutableList<Sensor> = mutableListOf())
fun List<String>.toBeaconMap() = this.fold(mutableMapOf<Pair<Int, Int>, Beacon>()) { map, it ->
... | 0 | Kotlin | 0 | 0 | 095d8f8e06230ab713d9ffba4cd13b87469f5cd5 | 3,001 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day25.kt | gautemo | 725,273,259 | false | {"Kotlin": 79259} | import shared.*
fun main() {
val input = Input.day(25)
println(day25A(input))
}
fun day25A(input: Input): Int {
val pairs = sortedBasedOnConnections(toPairs(input.lines))
for (cut1 in 0..10) {
for (cut2 in cut1..<10) {
for (cut3 in cut2..<10) {
if (cut1 == cut3 || c... | 0 | Kotlin | 0 | 0 | 6862b6d7429b09f2a1d29aaf3c0cd544b779ed25 | 3,653 | AdventOfCode2023 | MIT License |
src/Day03.kt | vladislav-og | 573,326,483 | false | {"Kotlin": 27072} | fun main() {
fun calculatePriority(elementInBothRucksacks: Char) =
if (elementInBothRucksacks.code > 96) elementInBothRucksacks.code - 96 else elementInBothRucksacks.code - 64 + 26
fun part1(input: List<String>): Int {
val items = arrayListOf<Int>()
for (row in input) {
... | 0 | Kotlin | 0 | 0 | b230ebcb5705786af4c7867ef5f09ab2262297b6 | 1,875 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | hubikz | 573,170,763 | false | {"Kotlin": 8506} | enum class Shape {
ROCK, PAPER, SCISSORS
}
enum class Result {
LOSE, DRAW, WIN
}
const val LOST_POINTS = 0
const val DRAW_POINTS = 3
const val WON_POINTS = 6
fun main() {
// A for Rock, B for Paper, and C for Scissors
// X for Rock, Y for Paper, and Z for Scissors
// 1 for Rock, 2 for Paper, and 3 ... | 0 | Kotlin | 0 | 0 | 902c6c3e664ad947c38c8edcb7ffd612b10e58fe | 2,438 | AoC2022 | Apache License 2.0 |
2022/src/day07/day07.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day07
import GREEN
import RESET
import printTimeMillis
import readInput
data class File(
val name: String,
val isDir: Boolean = false,
val size: Long = 0
)
fun List<String>.toPath() = "/" + drop(1).joinToString("/")
// construct a map of "/some/file" -> List<File>
fun parseFileSystem(input: List... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 2,698 | advent-of-code | Apache License 2.0 |
src/Day02.kt | Oli2861 | 572,895,182 | false | {"Kotlin": 16729} | enum class Result(val score: Int) {
WIN(6), Draw(3), Lose(0)
}
enum class Choice(val score: Int) {
ROCK(1), PAPER(2), SCISSORS(3);
companion object {
val winsAgainstMap = mapOf(
ROCK to PAPER,
PAPER to SCISSORS,
SCISSORS to ROCK
)
}
private val ... | 0 | Kotlin | 0 | 0 | 138b79001245ec221d8df2a6db0aaeb131725af2 | 3,381 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/kotlin/day12.kt | gautemo | 725,273,259 | false | {"Kotlin": 79259} | import shared.Input
import shared.toInts
fun main() {
val input = Input.day(12)
println(day12A(input))
println(day12B(input))
}
fun day12A(input: Input): Long {
return input.lines.sumOf {
countPermutes(it)
}
}
fun day12B(input: Input): Long {
return input.lines.sumOf {
val (fi... | 0 | Kotlin | 0 | 0 | 6862b6d7429b09f2a1d29aaf3c0cd544b779ed25 | 2,200 | AdventOfCode2023 | MIT License |
src/day08/Code.kt | fcolasuonno | 572,734,674 | false | {"Kotlin": 63451, "Dockerfile": 1340} | package day08
import Coord
import day06.main
import readInput
typealias IntGrid = Array<Array<Int>>
class Forest(private val trees: IntGrid) : Iterable<Coord> {
val maxX = trees[0].size
val maxY = trees.size
fun isVisible(x: Int, y: Int) = (0 until x).all { trees[it][y] < trees[x][y] }
|| (0 ... | 0 | Kotlin | 0 | 0 | 9cb653bd6a5abb214a9310f7cac3d0a5a478a71a | 1,732 | AOC2022 | Apache License 2.0 |
app/src/main/kotlin/day04/Day04.kt | KingOfDog | 433,706,881 | false | {"Kotlin": 76907} | package day04
import common.InputRepo
import common.readSessionCookie
import common.solve
fun main(args: Array<String>) {
val day = 4
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay04Part1, ::solveDay04Part2)
}
fun solveDay04Part1(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | 576e5599ada224e5cf21ccf20757673ca6f8310a | 3,277 | advent-of-code-kt | Apache License 2.0 |
leetcode/src/daily/hard/Q940.kt | zhangweizhe | 387,808,774 | false | null | package daily.hard
fun main() {
// 940. 不同的子序列 II
// https://leetcode.cn/problems/distinct-subsequences-ii/
println(distinctSubseqII("blljuffdyfrkqtwfyfztpdiyktrhftgtabxxoibcclbjvirnqyynkyaqlxgyybkgyzvcahmytjdqqtctirnxfjpktxmjkojlvvrr"))
}
fun distinctSubseqII(s: String): Int {
val mod = (Math.pow(10.... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,694 | kotlin-study | MIT License |
src/Day18.kt | PascalHonegger | 573,052,507 | false | {"Kotlin": 66208} | fun main() {
data class Cube(val x: Int, val y: Int, val z: Int)
fun String.toCube() = split(",").map { it.toInt() }.let { (x, y, z) -> Cube(x, y, z) }
fun Cube.neighbors() =
listOf(copy(x = x + 1), copy(y = y + 1), copy(z = z + 1), copy(x = x - 1), copy(y = y - 1), copy(z = z - 1))
fun part1(... | 0 | Kotlin | 0 | 0 | 2215ea22a87912012cf2b3e2da600a65b2ad55fc | 1,864 | advent-of-code-2022 | Apache License 2.0 |
src/day2/Day02.kt | mrm1st3r | 573,163,888 | false | {"Kotlin": 12713} | package day2
import Puzzle
enum class Shape(val score: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3)
}
val elfCodes = mapOf(
Pair('A', Shape.ROCK),
Pair('B', Shape.PAPER),
Pair('C', Shape.SCISSORS)
)
val humanCodes = mapOf(
Pair('X', Shape.ROCK),
Pair('Y', Shape.PAPER),
... | 0 | Kotlin | 0 | 0 | d8eb5bb8a4ba4223331766530099cc35f6b34e5a | 1,706 | advent-of-code-22 | Apache License 2.0 |
src/Day07.kt | mvanderblom | 573,009,984 | false | {"Kotlin": 25405} | import java.util.*
data class File(val name: String, val size: Int)
data class Dir(val name: String, val subDirs: MutableList<Dir>, val files: MutableList<File>) {
fun size(): Int {
return files.sumOf { it.size } + subDirs.sumOf { it.size() }
}
companion object {
fun withName(name: String):... | 0 | Kotlin | 0 | 0 | ba36f31112ba3b49a45e080dfd6d1d0a2e2cd690 | 2,997 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day02/Day02.kt | marcBrochu | 573,884,748 | false | {"Kotlin": 12896} | package day02
import readInput
enum class Shape(val score: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3),
DEFAULT(0);
fun getOutcome(opponentShape: Shape) =
when {
opponentShape == ROCK && this == PAPER -> RoundOutcome.WIN
opponentShape == PAPER && this == SCISSORS -> Roun... | 0 | Kotlin | 0 | 2 | 8d4796227dace8b012622c071a25385a9c7909d2 | 2,847 | advent-of-code-kotlin | Apache License 2.0 |
src/day13/Day13.kt | PoisonedYouth | 571,927,632 | false | {"Kotlin": 27144} | package day13
import readInput
sealed interface Element : Comparable<Element>
class ElementList(val elements: List<Element>) : Element {
constructor(element: Element) : this(listOf(element))
override fun compareTo(other: Element): Int = when (other) {
is ValueElement -> compareTo(ElementList(other))... | 0 | Kotlin | 1 | 0 | dbcb627e693339170ba344847b610f32429f93d1 | 2,053 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day08.kt | Totwart123 | 573,119,178 | false | null | import kotlin.math.sign
fun main() {
fun part1(input: List<String>): Int {
var treeCount = input.size * 2 + 2 * (input.first().length - 2)
(1 until input.size - 1).forEach { i ->
(1 until input[i].length - 1).forEach { j ->
val currentTree = input[i][j].toString().toInt... | 0 | Kotlin | 0 | 0 | 33e912156d3dd4244c0a3dc9c328c26f1455b6fb | 2,742 | AoC | Apache License 2.0 |
src/main/kotlin/days/Day16.kt | nuudles | 316,314,995 | false | null | package days
class Day16 : Day(16) {
private data class Field(
val name: String,
val ranges: Set<IntRange>
)
private fun parseInput(): Triple<Set<Field>, List<Int>, List<List<Int>>> {
val components = inputString.split("\n\n")
val fields = components[0]
.split("... | 0 | Kotlin | 0 | 0 | 5ac4aac0b6c1e79392701b588b07f57079af4b03 | 3,533 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/com/kingsleyadio/adventofcode/y2021/day11/Solution.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2021.day11
import com.kingsleyadio.adventofcode.util.readInput
fun solution(steps: Int, isPart2: Boolean): Int {
// NOTE: isPart2=false returns number of glows and isPart2=true returns number of steps
val input = readInput(2021, 11).useLines { lines ->
lines.map ... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 1,799 | adventofcode | Apache License 2.0 |
src/adventofcode/day04/Day04.kt | bstoney | 574,187,310 | false | {"Kotlin": 27851} | package adventofcode.day04
import adventofcode.AdventOfCodeSolution
fun main() {
Solution.solve()
}
typealias Section = Int
object Solution : AdventOfCodeSolution<Int>() {
override fun solve() {
solve(4, 2, 4)
}
override fun part1(input: List<String>): Int {
return getCleanUpPairs(i... | 0 | Kotlin | 0 | 0 | 81ac98b533f5057fdf59f08940add73c8d5df190 | 1,913 | fantastic-chainsaw | Apache License 2.0 |
src/main/kotlin/Day12.kt | todynskyi | 573,152,718 | false | {"Kotlin": 47697} | fun main() {
fun Char.getHeight(): Int =
when (this) {
'S' -> 'a'.code
'E' -> 'z'.code
else -> this.code
}
fun Point.toValid(input: Map<Point, Char>): List<Point> {
val data = arrayOf((-1 to 0), (1 to 0), (0 to -1), (0 to 1))
.map { (dx, ... | 0 | Kotlin | 0 | 0 | 5f9d9037544e0ac4d5f900f57458cc4155488f2a | 1,917 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/day12/main.kt | janneri | 572,969,955 | false | {"Kotlin": 99028} | package day12
import util.readTestInput
enum class Direction(val dx: Int, val dy: Int) {
LEFT(-1, 0), RIGHT(1, 0), UP(0, -1), DOWN(0, 1)
}
data class Position(val x: Int, val y: Int) {
fun move(direction: Direction, amount: Int = 1) =
Position(x + amount * direction.dx, y + amount * direction.dy)
... | 0 | Kotlin | 0 | 0 | 1de6781b4d48852f4a6c44943cc25f9c864a4906 | 3,517 | advent-of-code-2022 | MIT License |
src/aoc2022/Day12.kt | anitakar | 576,901,981 | false | {"Kotlin": 124382} | package aoc2022
import println
import readInput
import java.util.*
fun main() {
data class Position(val x: Int, val y: Int) : Comparable<Position> {
public var distance: Int = Int.MAX_VALUE
override fun compareTo(other: Position): Int {
return distance - other.distance
}
... | 0 | Kotlin | 0 | 1 | 50998a75d9582d4f5a77b829a9e5d4b88f4f2fcf | 3,176 | advent-of-code-kotlin | Apache License 2.0 |
src/Day09.kt | tsschmidt | 572,649,729 | false | {"Kotlin": 24089} | import kotlin.math.abs
fun main() {
fun moveTail(head: Pair<Int, Int>, tail: Pair<Int, Int>): Pair<Int, Int>? {
if (head.first == tail.first) {
if (abs((head.second) - (tail.second)) > 1) {
return if (head.second < tail.second) {
tail.first to tail.second - ... | 0 | Kotlin | 0 | 0 | 7bb637364667d075509c1759858a4611c6fbb0c2 | 3,231 | aoc-2022 | Apache License 2.0 |
src/Day14.kt | chbirmes | 572,675,727 | false | {"Kotlin": 32114} | import kotlin.math.max
import kotlin.math.min
fun main() {
fun part1(input: List<String>): Int {
val cave = Cave.parse(input, withFloor = false)
return generateSequence { Sand() }
.map { it.restPosition(cave) }
.indexOfFirst { it == null }
}
fun part2(input: List<S... | 0 | Kotlin | 0 | 0 | db82954ee965238e19c9c917d5c278a274975f26 | 2,814 | aoc-2022 | Apache License 2.0 |
src/Day15.kt | shepard8 | 573,449,602 | false | {"Kotlin": 73637} | import kotlin.math.abs
fun main() {
class Sensor(val x: Int, val y: Int, val closestX: Int, val closestY: Int) {
fun radius(): Int = abs(x - closestX) + abs(y - closestY)
fun frontier(): Sequence<Pair<Int, Int>> {
return sequence {
for (a in 0..radius()) {
... | 0 | Kotlin | 0 | 1 | 81382d722718efcffdda9b76df1a4ea4e1491b3c | 3,224 | aoc2022-kotlin | Apache License 2.0 |
src/year2023/06/Day06.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2023.`06`
import readInput
import utils.printlnDebug
private const val CURRENT_DAY = "06"
data class Race(
val time: Long,
val distance: Long,
)
data class Combination(
val initTime: Long,
val leftTime: Long,
val travelDistance: Long,
)
private fun parseInputIntoRaces(input: List<... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 2,547 | KotlinAdventOfCode | Apache License 2.0 |
src/day03/Day03.kt | banshay | 572,450,866 | false | {"Kotlin": 33644} | package day03
import readInput
fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { rucksackInput ->
val priority = priorityMap[rucksackInput.toRucksack().getMisplacedType()]
priority ?: 0
}
}
fun part2(input: List<String>): Int {
return ... | 0 | Kotlin | 0 | 0 | c3de3641c20c8c2598359e7aae3051d6d7582e7e | 2,063 | advent-of-code-22 | Apache License 2.0 |
src/Day18.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | import kotlin.math.abs
fun main() {
data class MinMax(var min: Int = Int.MAX_VALUE, var max: Int = Int.MIN_VALUE): Iterable<Int> {
fun update(value: Int) {
min = minOf(min, value)
max = maxOf(max, value)
}
override fun iterator(): Iterator<Int> {
return ... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 3,207 | aoc-2022 | Apache License 2.0 |
src/Day08.kt | arhor | 572,349,244 | false | {"Kotlin": 36845} | fun main() {
val input = readInput {}
val (visibleTrees, bestScenicScore) = solvePuzzle(input)
println("Part 1: $visibleTrees")
println("Part 2: $bestScenicScore")
}
private fun solvePuzzle(input: List<String>): Pair<Int, Int> {
val data = input.map { it.map(Char::digitToInt) }
val rows = dat... | 0 | Kotlin | 0 | 0 | 047d4bdac687fd6719796eb69eab2dd8ebb5ba2f | 1,465 | aoc-2022-in-kotlin | Apache License 2.0 |
src/App.kt | tonicsoft | 230,460,897 | false | null | import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import kotlin.streams.toList
val words = Files.readAllLines(Paths.get("words.txt")).asSequence().map { it.toLowerCase() }
.filter { !it.contains("-") }
.filter { !it.contains("'") }
.filter { !it.equals("hutukhtu") }
.filter { !it... | 0 | Kotlin | 0 | 0 | 47e62249cf73c8489be0d777782d36324f67d97c | 4,670 | alphapuzzle-solver | Apache License 2.0 |
src/Day11.kt | davedupplaw | 573,042,501 | false | {"Kotlin": 29190} | import java.math.BigInteger
fun main() {
var lowestCommonModulus: Long
data class Item(var worryLevel: Long)
data class Monkey(
val number: Int,
val items: MutableList<Item> = mutableListOf(),
val operation: String,
val operationOperand: String,
val testDivisibleBy:... | 0 | Kotlin | 0 | 0 | 3b3efb1fb45bd7311565bcb284614e2604b75794 | 3,545 | advent-of-code-2022 | Apache License 2.0 |
src/day03/day03.kt | tmikulsk1 | 573,165,106 | false | {"Kotlin": 25281} | package day03
import readInput
/**
* Advent of Code 2022 - Day 3
* @author tmikulsk1
*/
fun main() {
val inputRucksacks = readInput("day03/input.txt").readLines()
getPuzzle1PriorityRucksacks(inputRucksacks)
getPuzzle2PriorityRucksacks(inputRucksacks)
}
/**
* Puzzle 1: show priority from half groupe... | 0 | Kotlin | 0 | 1 | f5ad4e601776de24f9a118a0549ac38c63876dbe | 2,576 | AoC-22 | Apache License 2.0 |
src/main/kotlin/de/nilsdruyen/aoc/Day07.kt | nilsjr | 571,758,796 | false | {"Kotlin": 15971} | package de.nilsdruyen.aoc
fun main() {
fun part1(input: List<String>): Int {
val tree: MutableList<Entry.Directory> = mutableListOf()
val currentDir = mutableSetOf<String>()
val dirTree = mutableListOf<String>()
input.forEachIndexed { index, line ->
if (line.startsWith... | 0 | Kotlin | 0 | 0 | 1b71664d18076210e54b60bab1afda92e975d9ff | 3,567 | advent-of-code-2022 | Apache License 2.0 |
src/aoc2022/Day08.kt | dayanruben | 433,250,590 | false | {"Kotlin": 79134} | package aoc2022
import readInput
fun main() {
val (year, day) = "2022" to "Day08"
fun List<String>.parseTrees(): Map<Pair<Int, Int>, Char> {
val trees = mutableMapOf<Pair<Int, Int>, Char>()
this.forEachIndexed { y, line ->
line.forEachIndexed { x, c ->
trees[x to y... | 1 | Kotlin | 2 | 30 | df1f04b90e81fbb9078a30f528d52295689f7de7 | 2,121 | aoc-kotlin | Apache License 2.0 |
src/day18/Day18.kt | davidcurrie | 579,636,994 | false | {"Kotlin": 52697} | package day18
import java.io.File
import kotlin.math.max
import kotlin.math.min
fun main() {
val lavas = File("src/day18/input.txt").readLines().map { it.split(',') }.map { Triple(it[0].toInt(), it[1].toInt(), it[2].toInt()) }
val deltas = listOf(
Triple(1, 0, 0), Triple(-1, 0, 0),
Triple(0, 1... | 0 | Kotlin | 0 | 0 | 0e0cae3b9a97c6019c219563621b43b0eb0fc9db | 2,430 | advent-of-code-2022 | MIT License |
src/Day07.kt | aaronbush | 571,776,335 | false | {"Kotlin": 34359} | sealed class FileSystemObject
data class FileSystemDirectory(
val name: String,
val children: MutableMap<String, FileSystemObject>,
val parent: FileSystemDirectory?, // todo: squash nullable parent.
var size: Long = 0
) : FileSystemObject() {
override fun toString() =
"FileSystemDirectory(na... | 0 | Kotlin | 0 | 0 | d76106244dc7894967cb8ded52387bc4fcadbcde | 4,046 | aoc-2022-kotlin | Apache License 2.0 |
src/Day20.kt | sabercon | 648,989,596 | false | null | fun main() {
data class Tile(val id: Int, val data: List<String>) {
val top = data.first()
val bottom = data.last()
val left = data.map { it.first() }.joinToString("")
val right = data.map { it.last() }.joinToString("")
fun flip() = copy(data = data.reversed())
fun ... | 0 | Kotlin | 0 | 0 | 81b51f3779940dde46f3811b4d8a32a5bb4534c8 | 3,505 | advent-of-code-2020 | MIT License |
src/Day05.kt | Fedannie | 572,872,414 | false | {"Kotlin": 64631} | fun main() {
fun String.extractNumbers(): List<Int> {
return split(' ').filter { word -> !word.any { char: Char -> !char.isDigit() } }.map { it.toInt() }
}
fun rotate(n: Int, input: List<List<Char>>): MutableList<MutableList<Char>> {
val stacks = MutableList(n) { MutableList(0) { ' ' } }
input.forEac... | 0 | Kotlin | 0 | 0 | 1d5ac01d3d2f4be58c3d199bf15b1637fd6bcd6f | 2,043 | Advent-of-Code-2022-in-Kotlin | Apache License 2.0 |
solutions/aockt/y2022/Y2022D08.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2022
import io.github.jadarma.aockt.core.Solution
object Y2022D08 : Solution {
/** Parse the input and return the 2D [ForestMap]. */
private fun parseInput(input: String): ForestMap =
input
.lines()
.map { line -> IntArray(line.length) { i -> line[i].digitToInt(... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,613 | advent-of-code-kotlin-solutions | The Unlicense |
2021/src/Day08.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | import kotlin.math.abs
// https://adventofcode.com/2021/day/8
fun main() {
fun part1() {
var result = 0
for (line in readInput("Day08")) {
val data = line.split(" | ")
result += data[1].split(" ").filter { it.length == 2 || it.length == 3 || it.length == 4 || it.length == 7 }.size
}
pr... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 2,069 | advent-of-code | Apache License 2.0 |
src/Day07.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | import kotlin.math.min
private class Node(private val parent: Node?, var size: Int, private val type: TYPE) {
enum class TYPE {
FILE, DIR
}
var children: MutableMap<String, Node> = mutableMapOf()
fun getRealParent(): Node {
return parent ?: this
}
fun recalculateSize(): Int {... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 2,636 | advent-of-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/day12/Day12.kt | alxgarcia | 435,549,527 | false | {"Kotlin": 91398} | package day12
import java.io.File
fun parseInput(lines: List<String>): Map<String, List<String>> =
lines.flatMap {
val (cave1, cave2) = it.split("-")
listOf(cave1 to cave2, cave2 to cave1)
}.groupBy({ it.first }, { it.second })
private fun String.isCaveSmall(): Boolean = this.first().isLowerCase()
fun ... | 0 | Kotlin | 0 | 0 | d6b10093dc6f4a5fc21254f42146af04709f6e30 | 1,582 | advent-of-code-2021 | MIT License |
src/day12/Day12.kt | davidcurrie | 579,636,994 | false | {"Kotlin": 52697} | package day12
import java.io.File
fun main() {
val grid = File("src/day12/input.txt").readLines().mapIndexed {
y, line -> line.mapIndexed {
x, c -> Pair(x, y) to c
}
}.flatten().toMap()
val start = grid.filter { it.value == 'S' }.map { it.key }.first()
val end = grid.filte... | 0 | Kotlin | 0 | 0 | 0e0cae3b9a97c6019c219563621b43b0eb0fc9db | 1,777 | advent-of-code-2022 | MIT License |
src/main/kotlin/codes/jakob/aoc/solution/Day03.kt | The-Self-Taught-Software-Engineer | 433,875,929 | false | {"Kotlin": 56277} | package codes.jakob.aoc.solution
object Day03 : Solution() {
override fun solvePart1(input: String): Any {
val rows: List<List<Int>> = convertToBitString(input)
val mostCommonBits: List<Int> = rows.first().indices.map { findMostCommonBit(rows, it) }
val leastCommonBits: List<Int> = mostCom... | 0 | Kotlin | 0 | 6 | d4cfb3479bf47192b6ddb9a76b0fe8aa10c0e46c | 2,292 | advent-of-code-2021 | MIT License |
src/year2023/day13/Day13.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2023.day13
import check
import readInput
import splitByEmptyLines
fun main() {
val testInput = readInput("2023", "Day13_test")
check(part1(testInput), 405)
check(part2(testInput), 400)
val input = readInput("2023", "Day13")
println(part1(input))
println(part2(input))
}
private fu... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 1,495 | AdventOfCode | Apache License 2.0 |
src/Day09.kt | akijowski | 574,262,746 | false | {"Kotlin": 56887, "Shell": 101} | import kotlin.math.abs
import kotlin.math.sign
data class Knot(var x: Int, var y: Int) {
fun isAboveOrBelow(other: Knot): Boolean {
// if more than 1 away in y
return (x == other.x) && abs(y - other.y) > 1
}
fun isLeftOrRightOf(other: Knot): Boolean {
// if more than 1 away in x
... | 0 | Kotlin | 1 | 0 | 84d86a4bbaee40de72243c25b57e8eaf1d88e6d1 | 2,725 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2021/2021-12.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2021
import com.github.ferinagy.adventOfCode.readInputLines
fun main() {
val input = readInputLines(2021, "12-input")
val test1 = readInputLines(2021, "12-test1")
val test2 = readInputLines(2021, "12-test2")
val test3 = readInputLines(2021, "12-test3")
... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 3,287 | advent-of-code | MIT License |
src/main/kotlin/adventofcode2023/day5/day5.kt | dzkoirn | 725,682,258 | false | {"Kotlin": 133478} | package adventofcode2023.day5
import adventofcode2023.readInput
import java.util.stream.LongStream
import kotlin.time.measureTime
fun main() {
val input = readInput("day5")
println("Day 5")
val duration1 = measureTime {
println("Puzzle 1: ${puzzle1(input)}")
}
println(duration1)
print... | 0 | Kotlin | 0 | 0 | 8f248fcdcd84176ab0875969822b3f2b02d8dea6 | 3,472 | adventofcode2023 | MIT License |
src/main/kotlin/day15/main.kt | janneri | 572,969,955 | false | {"Kotlin": 99028} | package day15
import util.readTestInput
import kotlin.math.abs
import kotlin.math.max
private data class Coord(val x: Int, val y: Int) {
fun distanceTo(coord: Coord) = abs(x - coord.x) + abs(y - coord.y)
}
private data class Sensor(val sensorCoord: Coord, val beaconCoord: Coord) {
val range = sensorCoord.dis... | 0 | Kotlin | 0 | 0 | 1de6781b4d48852f4a6c44943cc25f9c864a4906 | 3,691 | advent-of-code-2022 | MIT License |
dsalgo/src/commonMain/kotlin/com/nalin/datastructurealgorithm/problems/DynamicProgramming.kt | nalinchhajer1 | 534,780,196 | false | {"Kotlin": 86359, "Ruby": 1605} | package com.nalin.datastructurealgorithm.problems
import kotlin.math.max
/**
* Some problem solved using dynamic programming or Advance DS
*/
/**
* Return longest comming subsequence possible between 2 strings
*/
fun longestCommonSubsequence(str1: String, str2: String): String {
// 1. Prepare a DP table with... | 0 | Kotlin | 0 | 0 | eca60301dab981d0139788f61149d091c2c557fd | 2,595 | kotlin-ds-algo | MIT License |
2020/src/year2021/day08/code.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2021.day08
import util.readAllLines
fun main() {
part1()
part2()
}
val DIGITS = mutableMapOf<Int, String>().apply {
put(1, "cf")
put(4, "bcdf")
put(7, "acf")
put(8, "abcdefg")
put(2, "acdeg") // common with 1: c, 4: cd, 7: ac
put(3, "acdfg") // common with 1: cf, 4: cdf, ... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 3,485 | adventofcode | MIT License |
src/Day25.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | fun globalMinCut(mat: Array<IntArray>): Pair<Int, List<Int>> {
var best = Int.MAX_VALUE to emptyList<Int>()
val n = mat.size
val co = Array(n) { mutableListOf(it) }
for (ph in 1 until n) {
val w = mat[0].copyOf()
var (s, t) = 0 to 0
for (it in 0 until n - ph) {
w[t] ... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 1,902 | advent-of-code-kotlin | Apache License 2.0 |
src/Day03.kt | paul-matthews | 433,857,586 | false | {"Kotlin": 18652} |
fun String.binToDec() = Integer.parseInt(this, 2)
fun Pair<String, String>.total() = first.binToDec() * second.binToDec()
typealias PowerConsumption = Pair</* Gamma rate */ String, /* Epsilon Rate */ String>
typealias LifeSupportRating = Pair</* Oxygen Generator */ String, /* C02 Scrubber */ String>
/**
* Partiti... | 0 | Kotlin | 0 | 0 | 2f90856b9b03294bc279db81c00b4801cce08e0e | 2,223 | advent-of-code-kotlin-template | Apache License 2.0 |
app/src/main/kotlin/codes/jakob/aoc/solution/Day09.kt | loehnertz | 725,944,961 | false | {"Kotlin": 59236} | package codes.jakob.aoc.solution
import codes.jakob.aoc.shared.splitByLines
import codes.jakob.aoc.shared.splitBySpace
object Day09 : Solution() {
override fun solvePart1(input: String): Any {
return parseHistories(input)
.map { HistoryTree.resolveFromHistory(it) }
.map { it.resolv... | 0 | Kotlin | 0 | 0 | 6f2bd7bdfc9719fda6432dd172bc53dce049730a | 3,740 | advent-of-code-2023 | MIT License |
src/Day09.kt | wujingwe | 574,096,169 | false | null | import kotlin.math.sign
object Day09 {
private val ADJACENTS = listOf(
0 to 0,
-1 to 0, 1 to 0, 0 to -1, 0 to 1,
-1 to -1, -1 to 1, 1 to -1, 1 to 1
)
private val STEPS = mapOf(
"U" to (-1 to 0),
"D" to (1 to 0),
"R" to (0 to 1),
"L" to (0 to -1)
... | 0 | Kotlin | 0 | 0 | a5777a67d234e33dde43589602dc248bc6411aee | 2,495 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day12.kt | sbaumeister | 572,855,566 | false | {"Kotlin": 38905} | data class Graph(
val nodes: MutableList<Pair<Int, Int>>,
var endNode: Pair<Int, Int>,
var startNode: Pair<Int, Int>,
val heights: MutableList<MutableList<Int>>,
val distances: MutableList<MutableList<Int>>,
val predecessors: MutableList<MutableList<Pair<Int, Int>?>>,
)
fun charToHeight(item: C... | 0 | Kotlin | 0 | 0 | e3afbe3f4c2dc9ece1da7cf176ae0f8dce872a84 | 4,186 | advent-of-code-2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.