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/Day07.kt | fasfsfgs | 573,562,215 | false | {"Kotlin": 52546} | data class AoCFile(val name: String, val size: Long, val dir: String)
fun List<AoCFile>.totalSize() = sumOf { it.size }
fun List<AoCFile>.dirSizes() = asSequence()
.flatMap { it.dir.possibleDirs() }
.distinct()
.map { dir -> this.filter { it.dir == dir || it.dir.startsWith("$dir/") } }
.map { files ->... | 0 | Kotlin | 0 | 0 | 17cfd7ff4c1c48295021213e5a53cf09607b7144 | 2,094 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc2023/Day21.kt | Ceridan | 725,711,266 | false | {"Kotlin": 110767, "Shell": 1955} | package aoc2023
class Day21 {
fun part1(input: String, steps: Int): Int {
val (start, grid) = parseInput(input)
val (reachablePointsCount) = getReachablePoints(grid, start, steps)
return reachablePointsCount
}
fun part2(input: String, steps: Int): Long {
val (start, grid) =... | 0 | Kotlin | 0 | 0 | 18b97d650f4a90219bd6a81a8cf4d445d56ea9e8 | 2,939 | advent-of-code-2023 | MIT License |
src/main/kotlin/Day5.kt | Ostkontentitan | 434,500,914 | false | {"Kotlin": 73563} | import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun puzzleDayFivePartOne() {
val inputs = readInput(5).map { it.trim() }
val lines = parseLines(inputs).filter { it.isVertical() || it.isHorizontal() }
val allPoints = lines.fold(emptyList<Point>()) { acc, line ->
acc + line.poi... | 0 | Kotlin | 0 | 0 | e0e5022238747e4b934cac0f6235b92831ca8ac7 | 2,399 | advent-of-kotlin-2021 | Apache License 2.0 |
src/aoc2022/Day25.kt | NoMoor | 571,730,615 | false | {"Kotlin": 101800} | package aoc2022
import utils.*
import kotlin.math.max
private class Day25(val lines: List<String>) {
/** Maps from SNAFU character to decimal digit. */
fun map(c: Char) : Int {
return when (c) {
'-' -> -1
'=' -> -2
else -> c.digitToInt()
}
}
/** Maps from decimal digit to SNAFU cha... | 0 | Kotlin | 1 | 2 | d561db73c98d2d82e7e4bc6ef35b599f98b3e333 | 2,089 | aoc2022 | Apache License 2.0 |
aoc-2023/src/main/kotlin/aoc/aoc12b.kts | triathematician | 576,590,518 | false | {"Kotlin": 615974} | import aoc.AocParser.Companion.parselines
import aoc.*
import aoc.util.getDayInput
val testInput = """
???.### 1,1,3
.??..??...?##. 1,1,3
?#?#?#?#?#?#?#? 1,3,1,6
????.#...#... 4,1,1
????.######..#####. 1,6,5
?###???????? 3,2,1
""".parselines
class Springs(_line: String, val nums: List<Int>) {
val max = nums.maxOr... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 3,468 | advent-of-code | Apache License 2.0 |
src/main/kotlin/day7.kt | Gitvert | 725,292,325 | false | {"Kotlin": 97000} | fun day7 (lines: List<String>) {
day7part1(lines)
day7part2(lines)
}
fun day7part2(lines: List<String>) {
val cards = parseCamelCards(lines)
cards.forEach { it.handStrength = findHandStrength(replaceJokers(it)) }
cards.forEach {
it.cards = it.cards
.replace("A", "Z")
... | 0 | Kotlin | 0 | 0 | f204f09c94528f5cd83ce0149a254c4b0ca3bc91 | 2,817 | advent_of_code_2023 | MIT License |
src/main/kotlin/SevenSegments_8.kt | Flame239 | 433,046,232 | false | {"Kotlin": 64209} | val digitLines: List<DigitLine> by lazy {
readFile("SevenSegments").split("\n").map {
val (signal, output) = it.split(" | ")
DigitLine(signal.split(" ").map { it.sortAlphabetically() }, output.split(" ").map { it.sortAlphabetically() })
}
}
val mapCharsToDigit = mapOf(
Pair("abcefg", "0"),
... | 0 | Kotlin | 0 | 0 | ef4b05d39d70a204be2433d203e11c7ebed04cec | 3,302 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/Day16.kt | Vampire | 572,990,104 | false | {"Kotlin": 57326} | import kotlin.math.max
fun main() {
data class Valve(
val name: String,
val flowRate: Int,
val reachableValveNames: List<String>
) {
val reachableValves = mutableListOf<Valve>()
}
val inputPattern = """Valve (?<valveName>\w++) has flow rate=(?<flowRate>\d++); (?:tunnels... | 0 | Kotlin | 0 | 0 | 16a31a0b353f4b1ce3c6e9cdccbf8f0cadde1f1f | 22,359 | aoc-2022 | Apache License 2.0 |
src/Day16.kt | buczebar | 572,864,830 | false | {"Kotlin": 39213} | fun main() {
lateinit var flowRates: Map<String, Int>
lateinit var connections: Map<String, List<String>>
lateinit var workingValves: List<String>
lateinit var distances: Map<Pair<String, String>, Int>
fun getDistanceToValve(
current: String,
destination: String,
visited: Li... | 0 | Kotlin | 0 | 0 | cdb6fe3996ab8216e7a005e766490a2181cd4101 | 2,961 | advent-of-code | Apache License 2.0 |
src/year2022/day15/Day15.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2022.day15
import check
import readInput
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("2022", "Day15_test")
check(part1(testInput, 10), 26)
check(part2(testIn... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 3,805 | AdventOfCode | Apache License 2.0 |
aoc-2021/src/main/kotlin/nerok/aoc/aoc2021/day04/Day04.kt | nerok | 572,862,875 | false | {"Kotlin": 113337} | package nerok.aoc.aoc2021.day04
import nerok.aoc.utils.Input
import kotlin.time.DurationUnit
import kotlin.time.measureTime
fun main() {
fun calculateScore(bingoBoard: List<MutableList<Int>>, drawing: List<Int>): Pair<Int, Int> {
drawing.forEachIndexed { drawNumber, draw ->
bingoBoard.mapIndex... | 0 | Kotlin | 0 | 0 | 7553c28ac9053a70706c6af98b954fbdda6fb5d2 | 2,866 | AOC | Apache License 2.0 |
src/Day23.kt | azat-ismagilov | 573,217,326 | false | {"Kotlin": 75114} | fun main() {
val day = 23
data class Position(val x: Int, val y: Int) {
fun move(direction: Int) = when (direction.mod(4)) {
0 -> copy(x = x - 1)
1 -> copy(x = x + 1)
2 -> copy(y = y - 1)
else -> copy(y = y + 1)
}
fun needToCheck(directio... | 0 | Kotlin | 0 | 0 | abdd1b8d93b8afb3372cfed23547ec5a8b8298aa | 3,295 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/day18/Day18.kt | qnox | 575,581,183 | false | {"Kotlin": 66677} | package day18
import readInput
import java.util.BitSet
fun main() {
data class Cube(val x: Int, val y: Int, val z: Int)
data class Limits(val minX: Int, val maxX: Int, val minY: Int, val maxY: Int, val minZ: Int, val maxZ: Int) {
val numX = maxX - minX + 1
val numY = maxY - minY + 1
... | 0 | Kotlin | 0 | 0 | 727ca335d32000c3de2b750d23248a1364ba03e4 | 4,268 | aoc2022 | Apache License 2.0 |
src/Day02.kt | cisimon7 | 573,872,773 | false | {"Kotlin": 41406} | fun main() {
fun abcMap(a: String) = when (a) {
"A" -> HandShape.Rock
"B" -> HandShape.Paper
"C" -> HandShape.Scissors
else -> throw Error("$a is not applicable")
}
fun xyzMap(a: String) = when (a) {
"X" -> HandShape.Rock to Outcome.Loose
"Y" -> HandShape.Pap... | 0 | Kotlin | 0 | 0 | 29f9cb46955c0f371908996cc729742dc0387017 | 2,651 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | MarkRunWu | 573,656,261 | false | {"Kotlin": 25971} | fun main() {
fun calculateScore(shape: Pair<Int, Int>): Int {
val diff = shape.second - shape.first
return shape.second + (if (diff == 0) {
3
} else if ((diff == -2) or (diff == 1)) { // -2: rock - scissors, 1: paper - rock / scissors - paper
6
} else {
... | 0 | Kotlin | 0 | 0 | ced885dcd6b32e8d3c89a646dbdcf50b5665ba65 | 1,674 | AOC-2022 | Apache License 2.0 |
src/Day04.kt | dyomin-ea | 572,996,238 | false | {"Kotlin": 21309} | import kotlin.math.max
fun main() {
fun IntRange.length(): Int =
last - first + 1
fun String.asRange(): IntRange =
splitBy("-")
.let { it.first.toInt()..it.second.toInt() }
fun String.intoRangePair(): Pair<IntRange, IntRange> =
splitBy(",")
.let { it.first.asRange() to it.second.asRange() }
fun par... | 0 | Kotlin | 0 | 0 | 8aaf3f063ce432207dee5f4ad4e597030cfded6d | 2,509 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/year2023/Day07.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2023
import year2023.Day07.CardType1
import kotlin.reflect.KClass
class Day07 {
enum class HandType {
HighCard,
OnePair,
TwoPair,
ThreeOfAKind,
FullHouse,
FourOfAKind,
FiveOfAKind
}
interface CardType<T : CardType<T>> : Comparable<T>
... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 3,614 | aoc-2022 | Apache License 2.0 |
src/y2022/Day13.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2022
import util.readInput
import util.split
object Day13 {
private fun parse(input: List<String>): List<List<ListItem>> {
return input.split { it.isEmpty() }
.map {
it.map { ln ->
ListItem.of(ln)
}
}
}
sealed cl... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 4,012 | advent-of-code | Apache License 2.0 |
src/aoc2021/day04/Code.kt | ldickmanns | 572,675,185 | false | {"Kotlin": 48227} | package aoc2021.day04
import readInput
fun main() {
val input = readInput("aoc2021/day04/input")
println(part1(input))
println(part2(input))
}
typealias NumberBoard = Array<IntArray> // IntArrays are the rows
typealias BingoBoard = Array<BooleanArray> // BooleanArrays are the rows
fun part1(input: List... | 0 | Kotlin | 0 | 0 | 2654ca36ee6e5442a4235868db8174a2b0ac2523 | 3,705 | aoc-kotlin-2022 | Apache License 2.0 |
src/day17/Day17.kt | maxmil | 578,287,889 | false | {"Kotlin": 32792} | package day17
import println
import readInputAsText
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.sqrt
data class Target(val minX: Int, val maxX: Int, val minY: Int, val maxY: Int)
private fun String.parseTarget() = "target area: x=([-\\d]+)..([-\\d]+), y=([-\\d]+)..([-\\d]+)"
.toRegex().ma... | 0 | Kotlin | 0 | 0 | 246353788b1259ba11321d2b8079c044af2e211a | 2,244 | advent-of-code-2021 | Apache License 2.0 |
2022/src/test/kotlin/Day12.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import java.util.PriorityQueue
private data class Coord12(val x: Int, val y: Int)
private val directions = listOf(Coord12(1, 0), Coord12(0, 1), Coord12(-1, 0), Coord12(0, -1))
class Day12 : StringSpec({
"puzzle part 01" {
val m... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 2,543 | adventofcode | MIT License |
y2023/src/main/kotlin/adventofcode/y2023/Day03.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2023
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Vec2
fun main() {
Day03.solve()
}
object Day03 : AdventSolution(2023, 3, "Gear Ratios") {
override fun solvePartOne(input: String): Int {
val (numbers, symbols) = parse(input)
return numbers.fil... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,518 | advent-of-code | MIT License |
src/Day08.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | object Day08 {
const val EXPECTED_PART1_CHECK_ANSWER = 21
const val EXPECTED_PART2_CHECK_ANSWER = 8
}
fun main() {
fun List<String>.parseTreeGrid(): List<List<Int>> =
this.map { it.toList() }.map { it.map { chr -> chr.digitToInt() } }
fun List<List<Int>>.isVisible(x: Int, y: Int): Boolean {
... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 3,458 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day08.kt | anilkishore | 573,688,256 | false | {"Kotlin": 27023} | import java.lang.Math.abs
fun main() {
fun part1(trees: List<String>): Int {
val n = trees.size
val mins = Array(n) { CharArray(n) { ':' } }
val scores = Array(n) { IntArray(n) { 1 } }
for (i in 1 until n - 1)
for ((js, jd) in arrayOf(1 to 1, n - 2 to -1)) {
... | 0 | Kotlin | 0 | 0 | f8f989fa400c2fac42a5eb3b0aa99d0c01bc08a9 | 1,972 | AOC-2022 | Apache License 2.0 |
src/day9/Day9.kt | pocmo | 433,766,909 | false | {"Kotlin": 134886} | package day9
import java.io.File
fun readInput(filename: String = "day9.txt"): List<List<Int>>{
return File(filename)
.readLines()
.map { line -> line.toCharArray().map { character -> character.digitToInt() } }
}
fun List<List<Int>>.neighbours(x: Int, y: Int): List<Int> {
val top = get(x).get... | 0 | Kotlin | 1 | 2 | 73bbb6a41229e5863e52388a19108041339a864e | 2,789 | AdventOfCode2021 | Apache License 2.0 |
src/Day05.kt | konclave | 573,548,763 | false | {"Kotlin": 21601} | fun main() {
fun solve1(input: List<String>): String {
val movements = getMovements(input)
val crateStacks = getCrateStacks(input)
return applyMovements9000(movements, crateStacks)
}
fun solve2(input: List<String>): String {
val movements = getMovements(input)
val cr... | 0 | Kotlin | 0 | 0 | 337f8d60ed00007d3ace046eaed407df828dfc22 | 2,644 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | davidkna | 572,439,882 | false | {"Kotlin": 79526} | import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sign
fun main() {
fun parseInput(input: List<String>): List<Pair<Int, Int>> {
return input.map { l ->
val (direction, steps) = l.split(" ")
val stepsInt = steps.toInt()
return@map when (direction) {
... | 0 | Kotlin | 0 | 0 | ccd666cc12312537fec6e0c7ca904f5d9ebf75a3 | 1,883 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | cjosan | 573,106,026 | false | {"Kotlin": 5721} | fun main() {
fun part1(input: List<String>): Int {
// A -> Rock; B -> Paper; C -> Scissors
// X -> Rock; Y -> Paper; Z -> Scissors
val shapeScores = mapOf("X" to 1, "Y" to 2, "Z" to 3)
return input
.stream()
.mapToInt { round ->
val shapes = r... | 0 | Kotlin | 0 | 0 | a81f7fb9597361d45ff73ad2a705524cbc64008b | 1,866 | advent-of-code2022 | Apache License 2.0 |
2023/12/solve-1.kts | gugod | 48,180,404 | false | {"Raku": 170466, "Perl": 121272, "Kotlin": 58674, "Rust": 3189, "C": 2934, "Zig": 850, "Clojure": 734, "Janet": 703, "Go": 595} | import java.io.File
data class SpringProblem (
val observation: String,
val expectation: List<Int>,
)
data class SpringParts (
val c: Char,
val quantity: Int,
)
fun isMatch(problem: SpringProblem, guess: String): Boolean =
problem.expectation == Regex("#+").findAll(guess).map { it.value.length }.... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 1,868 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/Day12.kt | davidkna | 572,439,882 | false | {"Kotlin": 79526} | import java.util.PriorityQueue
fun main() {
fun height(c: Char): Int {
if (('a'..'z').contains(c)) {
return c.code - 'a'.code
}
return when (c) {
'S' -> 0
'E' -> 25
else -> throw Exception("Unknown char")
}
}
fun neighbors(x: ... | 0 | Kotlin | 0 | 0 | ccd666cc12312537fec6e0c7ca904f5d9ebf75a3 | 2,383 | aoc-2022 | Apache License 2.0 |
src/day02/Day02.kt | Harvindsokhal | 572,911,840 | false | {"Kotlin": 11823} | package day02
import readInput
fun main() {
val data = readInput("day02/day02_data")
/*
* L -> Lose
* T -> Tie
* W -> Win
* */
fun totalScore(list:List<String>): Int {
val myMap: HashMap<String, String> = hashMapOf("X" to "Rock", "Y" to "Paper", "Z" to "Scissors")
val opp... | 0 | Kotlin | 0 | 0 | 7ebaee4887ea41aca4663390d4eadff9dc604f69 | 2,210 | aoc-2022-kotlin | Apache License 2.0 |
src/Day07.kt | JanTie | 573,131,468 | false | {"Kotlin": 31854} | fun main() {
fun buildFileTree(input: List<String>): Map<String, Int> {
var currentDir = ""
val map = mutableMapOf<String, Int>()
input.forEach {
when {
it.startsWith("\$ cd") -> {
val param = it.split(" ")[2]
currentDir = w... | 0 | Kotlin | 0 | 0 | 3452e167f7afe291960d41b6fe86d79fd821a545 | 2,015 | advent-of-code-2022 | Apache License 2.0 |
src/Day13.kt | tomoki1207 | 572,815,543 | false | {"Kotlin": 28654} | import DatumType.NumDatumType
import DatumType.PacketDatumType
sealed class DatumType {
class NumDatumType(val value: Int) : DatumType() {
override fun toString(): String {
return value.toString()
}
}
class PacketDatumType(val value: Packet) : DatumType() {
override fun... | 0 | Kotlin | 0 | 0 | 2ecd45f48d9d2504874f7ff40d7c21975bc074ec | 3,163 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/codes/jakob/aoc/solution/Day12.kt | The-Self-Taught-Software-Engineer | 433,875,929 | false | {"Kotlin": 56277} | package codes.jakob.aoc.solution
import codes.jakob.aoc.shared.UndirectedGraph
import codes.jakob.aoc.shared.UndirectedGraph.Vertex
object Day12 : Solution() {
override fun solvePart1(input: String): Any {
val graph: UndirectedGraph<Cave> = UndirectedGraph(parseInput(input))
val paths: Set<List<Ve... | 0 | Kotlin | 0 | 6 | d4cfb3479bf47192b6ddb9a76b0fe8aa10c0e46c | 2,189 | advent-of-code-2021 | MIT License |
src/Day09.kt | bigtlb | 573,081,626 | false | {"Kotlin": 38940} | import kotlin.math.abs
fun main() {
fun distance(head: Pos, tail: Pos): Int = Math.max(abs(head.first - tail.first), abs(head.second - tail.second))
fun follow(head: Pos, tail: Pos): Pos =
tail.copy(tail.first + if (distance(head, tail)>1) head.first.compareTo(tail.first) else 0,
tail.seco... | 0 | Kotlin | 0 | 0 | d8f76d3c75a30ae00c563c997ed2fb54827ea94a | 2,331 | aoc-2022-demo | Apache License 2.0 |
app/src/main/kotlin/codes/jakob/aoc/solution/Day08.kt | loehnertz | 725,944,961 | false | {"Kotlin": 59236} | package codes.jakob.aoc.solution
import codes.jakob.aoc.shared.cyclicIterator
import codes.jakob.aoc.shared.lowestCommonMultiple
import codes.jakob.aoc.shared.splitByCharacter
object Day08 : Solution() {
private val mapPattern = Regex("([A-Z]{3})\\s=\\s\\(([A-Z]{3}),\\s([A-Z]{3})\\)")
override fun solvePart1... | 0 | Kotlin | 0 | 0 | 6f2bd7bdfc9719fda6432dd172bc53dce049730a | 3,633 | advent-of-code-2023 | MIT License |
src/Day04.kt | lukewalker128 | 573,611,809 | false | {"Kotlin": 14077} | fun main() {
val testInput = readInput("Day04_test")
val testAssignmentPairs = testInput.toAssignmentPairs()
checkEquals(2, part1(testAssignmentPairs))
checkEquals(4, part2(testAssignmentPairs))
val input = readInput("Day04")
val assignmentPairs = input.toAssignmentPairs()
println("Part 1: ... | 0 | Kotlin | 0 | 0 | c1aa17de335bd5c2f5f555ecbdf39874c1fb2854 | 1,577 | advent-of-code-2022 | Apache License 2.0 |
day11/src/main/kotlin/Main.kt | joshuabrandes | 726,066,005 | false | {"Kotlin": 47373} | package org.example
import java.io.File
fun main() {
println("------ Advent of Code 2023 - Day 10 -----")
val puzzleInput = getPuzzleInput()
val starMap = puzzleInput
.map { line ->
line.map { Space.fromChar(it) }
}
val spaceGraph = buildSpaceGraph(starMap)
val shorte... | 0 | Kotlin | 0 | 1 | de51fd9222f5438efe9a2c45e5edcb88fd9f2232 | 5,701 | aoc-2023-kotlin | The Unlicense |
src/Day11.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | import kotlin.math.max
import kotlin.math.min
private const val EXPECTED_1 = 374L
private const val EXPECTED_2 = 1030L
private class Day11(isTest: Boolean) : Solver(isTest) {
val field = readAsLines().map { it.toCharArray() }
val Y = field.size
val X = field[0].size
var mul = 2L
fun part1(): Any ... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 1,901 | advent-of-code-2022 | Apache License 2.0 |
src/Day08.kt | wgolyakov | 572,463,468 | false | null | fun main() {
fun parse(input: List<String>): List<List<Int>> {
val grid = mutableListOf<List<Int>>()
for (line in input)
grid.add(line.map { it.digitToInt() })
return grid
}
fun part1(input: List<String>): Int {
val grid = parse(input)
val h = grid.size
val w = grid[0].size
val visible = Array(h) {... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 1,727 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | pavlo-dh | 572,882,309 | false | {"Kotlin": 39999} | import kotlin.math.pow
import kotlin.math.sign
import kotlin.math.sqrt
fun main() {
data class Point(val x: Int, val y: Int)
fun parseMovement(inputLine: String): Triple<Int, Int, Int> {
val (direction, steps) = inputLine.split(' ')
val (headXMovement, headYMovement) = when (direction.first())... | 0 | Kotlin | 0 | 2 | c10b0e1ce2c7c04fbb1ad34cbada104e3b99c992 | 3,319 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day10/Day10.kt | banshay | 572,450,866 | false | {"Kotlin": 33644} | package day10
import readInput
fun main() {
fun part1(input: List<String>): Int {
val program = input.toCycleSignalStrengthMap()
val relevantCycles = 20..220 step 40
return relevantCycles.sumOf {
val x = when (program[it]) {
null -> program[it + 1]!!.during()
... | 0 | Kotlin | 0 | 0 | c3de3641c20c8c2598359e7aae3051d6d7582e7e | 2,316 | advent-of-code-22 | Apache License 2.0 |
src/Day05.kt | zirman | 572,627,598 | false | {"Kotlin": 89030} | fun main() {
fun part1(input: List<String>): String {
val (stacksInput, movesInput) = input.joinToString("\n").split("\n\n")
val stacks = stacksInput.split("\n").map { it.map { it } }
val cs = stacks.last().mapIndexedNotNull { i, c -> if (c.isDigit()) i else null }
fun parseStack(c:... | 0 | Kotlin | 0 | 1 | 2ec1c664f6d6c6e3da2641ff5769faa368fafa0f | 3,284 | aoc2022 | Apache License 2.0 |
src/Day17.kt | Flame239 | 570,094,570 | false | {"Kotlin": 60685} | import kotlin.math.max
private fun pushes(): List<Int> {
return readInput("Day17")[0].map { if (it == '>') 1 else -1 }
}
private val addHeightByTurn = mutableListOf<Long>()
private fun part1(pushes: List<Int>, rounds: Int): Int {
val game = Array(7) { BooleanArray(100000) }
for (i in 0 until 7) game[i][0... | 0 | Kotlin | 0 | 0 | 27f3133e4cd24b33767e18777187f09e1ed3c214 | 2,709 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | esp-er | 573,196,902 | false | {"Kotlin": 29675} | package patriker.day09
import kotlin.math.abs
import patriker.utils.*
data class Pos(val x: Int, val y: Int)
enum class Dir{
RIGHT,LEFT,UP,DOWN;
}
fun main() {
val testInput = readInput("Day09_test")
val test2 = readInput("Day09_test2")
val input = readInput("Day09_input")
// test if implementatio... | 0 | Kotlin | 0 | 0 | f46d09934c33d6e5bbbe27faaf2cdf14c2ba0362 | 3,859 | aoc2022 | Apache License 2.0 |
src/main/kotlin/de/jball/aoc2022/day08/Day08.kt | fibsifan | 573,189,295 | false | {"Kotlin": 43681} | package de.jball.aoc2022.day08
import de.jball.aoc2022.Day
import kotlin.math.max
class Day08(test: Boolean = false) : Day<Int>(test, 21, 8) {
private val grid = input
.mapIndexed { lineNo, line ->
line.chunked(1)
.mapIndexed { colNo, col -> Pair(Pair(lineNo, colNo), col.toInt(... | 0 | Kotlin | 0 | 3 | a6d01b73aca9b54add4546664831baf889e064fb | 3,237 | aoc-2022 | Apache License 2.0 |
src/Day07.kt | zhtk | 579,137,192 | false | {"Kotlin": 9893} | sealed class FileSystem(var size: Int = 0) {
class File(val name: String, size: Int) : FileSystem(size)
data class Directory(
val name: String,
val files: MutableSet<String> = mutableSetOf()
) : FileSystem()
}
fun main() {
val input = readInput("Day07")
val fileSystem = mutableMapOf... | 0 | Kotlin | 0 | 0 | bb498e93f9c1dd2cdd5699faa2736c2b359cc9f1 | 2,184 | aoc2022 | Apache License 2.0 |
src/Day07.kt | Yasenia | 575,276,480 | false | {"Kotlin": 15232} | abstract class FileSystemNode(val name: String) {
abstract val parent: Directory?
abstract fun size(): Int
}
class Directory(
name: String,
override val parent: Directory? = null,
private val content: MutableList<FileSystemNode> = mutableListOf()
) : FileSystemNode(name) {
override fun size(): ... | 0 | Kotlin | 0 | 0 | 9300236fa8697530a3c234e9cb39acfb81f913ba | 3,299 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/g2501_2600/s2572_count_the_number_of_square_free_subsets/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2501_2600.s2572_count_the_number_of_square_free_subsets
// #Medium #Array #Dynamic_Programming #Math #Bit_Manipulation #Bitmask
// #2023_07_09_Time_218_ms_(100.00%)_Space_37.8_MB_(100.00%)
class Solution {
private val primes = intArrayOf(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)
private val badNums = (1..3... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,868 | LeetCode-in-Kotlin | MIT License |
src/year2021/Day4.kt | drademacher | 725,945,859 | false | {"Kotlin": 76037} | package year2021
import readFile
fun main() {
val input = parseInput(readFile("2021", "day4"))
val testInput = parseInput(readFile("2021", "day4_test"))
check(part1(testInput) == 4512)
println("Part 1:" + part1(input))
check(part2(testInput) == 1924)
println("Part 2:" + part2(input))
}
priv... | 0 | Kotlin | 0 | 0 | 4c4cbf677d97cfe96264b922af6ae332b9044ba8 | 3,229 | advent_of_code | MIT License |
src/Day15.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} | import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun ints(input: String): List<Int>{
return """-?\d+""".toRegex().findAll(input).map { it.value.toInt()}.toList()
}
fun String.aints() = ints(this)
private class Day15(val lines: List<String>) {
val sensors = lines.map { it.aints() }.map { ... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 2,837 | aoc-22-kotlin | Apache License 2.0 |
src/Day18.kt | andrikeev | 574,393,673 | false | {"Kotlin": 70541, "Python": 18310, "HTML": 5558} | import kotlin.math.abs
fun main() {
data class Cube(val x: Int, val y: Int, val z: Int)
fun List<String>.parse(): List<Cube> {
return map {
val (x, y, z) = it.split(",").map(String::toInt)
Cube(x, y, z)
}
}
fun part1(input: List<String>): Int {
fun Cub... | 0 | Kotlin | 0 | 1 | 1aedc6c61407a28e0abcad86e2fdfe0b41add139 | 2,472 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day03.kt | NielsSteensma | 572,641,496 | false | {"Kotlin": 11875} | val alphabet = ('a'..'z').toMutableList()
fun main() {
val input = readInput("Day03")
println("Day 03 Part 1 ${calculateDay03Part1(input)}")
println("Day 03 Part 2 ${calculateDay03Part2(input)}")
}
fun calculateDay03Part1(input: List<String>): Int {
val priority = input.map(::getCompartments).map(::co... | 0 | Kotlin | 0 | 0 | 4ef38b03694e4ce68e4bc08c390ce860e4530dbc | 1,849 | aoc22-kotlin | Apache License 2.0 |
src/Day04.kt | MatthiasDruwe | 571,730,990 | false | {"Kotlin": 47864} |
fun main() {
fun part1(input: List<String>): Int {
val output = input.map { it.split(",").map { minmax -> minmax.split("-").map { number-> number.toInt() } } }.map{
(it[0][0]>= it[1][0] && it[0][1]<=it[1][1]) || (it[1][0] >= it[0][0] && it[1][1]<= it[0][1])
}.count { it }
retu... | 0 | Kotlin | 0 | 0 | f35f01cea5075cfe7b4a1ead9b6480ffa57b4989 | 1,059 | Advent-of-code-2022 | Apache License 2.0 |
src/twentytwo/Day04.kt | mihainov | 573,105,304 | false | {"Kotlin": 42574} | package twentytwo
import readInputTwentyTwo
data class Section(val start: Int, val end: Int) {
fun getSize(): Int {
return end - start
}
}
data class ElfSections(val firstSection: Section?, val secondSection: Section?)
fun String.toSections(): ElfSections {
val elvesSection = this.split(",")
... | 0 | Kotlin | 0 | 0 | a9aae753cf97a8909656b6137918ed176a84765e | 1,887 | kotlin-aoc-1 | Apache License 2.0 |
src/Day03.kt | strindberg | 572,685,170 | false | {"Kotlin": 15804} | fun priority(char: Char) =
if (char.isUpperCase()) char - 'A' + 27 else if (char.isLowerCase()) char - 'a' + 1 else throw RuntimeException()
fun String.uniqueChars() = this.toSet().toList()
fun main() {
fun part1(input: List<String>): Int =
input.sumOf { line ->
val first = lin... | 0 | Kotlin | 0 | 0 | c5d26b5bdc320ca2aeb39eba8c776fcfc50ea6c8 | 1,392 | aoc-2022 | Apache License 2.0 |
src/Day16.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | fun main() {
data class Valve(val id: String, val rate: Int, val edges: List<String>)
data class State(val valves: Map<String, Valve>, val shortestPaths: MutableMap<String, MutableMap<String, Int>>, var score: Int = 0)
fun processInput(input: List<String>): State {
val list = mutableListOf<Valve>()... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 2,899 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | davedupplaw | 573,042,501 | false | {"Kotlin": 29190} | fun main() {
fun findCommonItem(rucksackContents: String): Char {
val numberOfItems = rucksackContents.length / 2
val firstCompartmentContents = rucksackContents.substring(0, numberOfItems)
val secondCompartmentContents = rucksackContents.substring(numberOfItems)
return firstCompartm... | 0 | Kotlin | 0 | 0 | 3b3efb1fb45bd7311565bcb284614e2604b75794 | 1,743 | advent-of-code-2022 | Apache License 2.0 |
src/Day24.kt | er453r | 572,440,270 | false | {"Kotlin": 69456} | fun main() {
val directions = mapOf('<' to Vector3d.LEFT, '>' to Vector3d.RIGHT, '^' to Vector3d.UP, 'v' to Vector3d.DOWN)
val neighboursInTime = directions.values.map { it + Vector3d.BACK }.toSet() + Vector3d.BACK
val start = Vector3d(0, -1, 0)
fun isEmpty(positionInTime: Vector3d, width: Int, height:... | 0 | Kotlin | 0 | 0 | 9f98e24485cd7afda383c273ff2479ec4fa9c6dd | 3,773 | aoc2022 | Apache License 2.0 |
src/Day07.kt | peterfortuin | 573,120,586 | false | {"Kotlin": 22151} | fun main() {
fun parseToTree(input: List<String>): TreeNode {
val rootNode = TreeNode("root")
var currentNode = rootNode
input.forEach { line ->
when {
!line.contains("$") && line.contains("dir") -> currentNode.add(TreeNode(line.split(" ")[1]))
!l... | 0 | Kotlin | 0 | 0 | c92a8260e0b124e4da55ac6622d4fe80138c5e64 | 2,765 | advent-of-code-2022 | Apache License 2.0 |
src/Day15.kt | Cryosleeper | 572,977,188 | false | {"Kotlin": 43613} | import kotlin.math.abs
fun main() {
fun part1(input: List<String>, yToUse: Int): Int {
val sensors = input.parseToSensors()
val pointsToIgnore = mutableSetOf<Beacon>()
val minX = sensors.minBy { it.x }.x
val maxX = sensors.maxBy { it.x }.x
val maxDistance = sensors.maxBy { i... | 0 | Kotlin | 0 | 0 | a638356cda864b9e1799d72fa07d3482a5f2128e | 3,059 | aoc-2022 | Apache License 2.0 |
cz.wrent.advent/Day18.kt | Wrent | 572,992,605 | false | {"Kotlin": 206165} | package cz.wrent.advent
import java.util.*
fun main() {
println(partOne(test))
val result = partOne(input)
println("18a: $result")
println(partTwo(test))
val resultTwo = partTwo(input)
println("18b: $resultTwo")
}
private fun partOne(input: String): Int {
val cubes = input.split("\n")
.map { it.parseCube(... | 0 | Kotlin | 0 | 0 | 8230fce9a907343f11a2c042ebe0bf204775be3f | 18,195 | advent-of-code-2022 | MIT License |
src/Day12.kt | askeron | 572,955,924 | false | {"Kotlin": 24616} | class Day12 : Day<Int>(31, 29, 447, 446) {
private fun partCommon(input: List<String>, lookForBestStartPoint: Boolean): Int {
val inputMap = input.charMatrixToPointMap()
val allPoints = inputMap.keys
val start = inputMap.entries.filter { it.value == 'S' }.singleValue().key
val end = ... | 0 | Kotlin | 0 | 1 | 6c7cf9cf12404b8451745c1e5b2f1827264dc3b8 | 1,923 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/AOC2022/Day07/Day07.kt | kfbower | 573,519,224 | false | {"Kotlin": 44562} | package AOC2022.Day07
import AOC2022.readInput
fun main(){
fun treeBuilder(lines: List<String>): Directory {
val root = Directory("/", parent = null)
var current = root
lines.drop(1).forEach {
if (it.startsWith("$ cd ..")) {
current = current.parent!!
... | 0 | Kotlin | 0 | 0 | 48a7c563ebee77e44685569d356a05e8695ae36c | 1,939 | advent-of-code-2022 | Apache License 2.0 |
2021/src/day05/Day05.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day05
import readInput
import kotlin.math.abs
data class Point(val x: Int, val y: Int)
fun part1(lines: List<String>) : Int {
val boardLines = mutableListOf<Point>()
for (line in lines) {
val split = line.filter { !it.isWhitespace() }.split("->")
val fromX = split[0].split(",")[0].to... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 2,538 | advent-of-code | Apache License 2.0 |
src/Day07.kt | Jintin | 573,640,224 | false | {"Kotlin": 30591} | import java.util.*
fun main() {
fun part1(input: List<String>): Int {
val root = buildFileTree(input)
return countSize(root)
}
fun part2(input: List<String>): Int {
val root = buildFileTree(input)
return findMin(root, root.size - 40000000)
}
val input = readInput(... | 0 | Kotlin | 0 | 2 | 4aa00f0d258d55600a623f0118979a25d76b3ecb | 2,321 | AdventCode2022 | Apache License 2.0 |
src/Day03.kt | ktrom | 573,216,321 | false | {"Kotlin": 19490, "Rich Text Format": 2301} | fun main() {
fun part1(input: List<String>): Int {
return input.map {
val charsInFirstHalfOfString: Set<Char> = it.substring(0 until it.length / 2).toSet()
val charsInSecondHalfOfString: Set<Char> = it.substring(it.length / 2).toSet()
val charsInBothHalvesOfString: Set<Char> =
charsInFirstHalfOfStri... | 0 | Kotlin | 0 | 0 | 6940ff5a3a04a29cfa927d0bbc093cd5df15cbcd | 2,057 | kotlin-advent-of-code | Apache License 2.0 |
src/y2022/Day05.kt | a3nv | 574,208,224 | false | {"Kotlin": 34115, "Java": 1914} | package y2022
import utils.readInput
fun main() {
fun part1(columns: MutableList<MutableList<String>>, operations: List<String>): String {
operations.forEachIndexed() { index, it ->
val task = it.split(",")
val qty = task[0].toInt()
val from = task[1].toInt() - 1
... | 0 | Kotlin | 0 | 0 | ab2206ab5030ace967e08c7051becb4ae44aea39 | 3,331 | advent-of-code-kotlin | Apache License 2.0 |
Kotlin101/13-lambda-functions/01_Basics.kt | ge47jaz | 695,323,673 | false | {"Kotlin": 77958} | // val lambdaName: (inputType) -> outputType = { inputVariable: inputType -> body }
// example:
val square: (Int) -> Int = { number: Int -> number * number }
// equivalent to:
fun square2(number: Int): Int {
return number * number
}
// lambda function can be assigned to a variable
val square3 = { number: Int -> ... | 0 | Kotlin | 0 | 0 | 87dba8f8137c32d0ef6912efd5999675a2620ab4 | 5,711 | kotlin-progress | MIT License |
src/Day07.kt | lassebe | 573,423,378 | false | {"Kotlin": 33148} | fun main() {
fun sizeOf(
dirName: String,
fileStructure: Map<String, List<String>>,
dirSize: Map<String, Long>,
): Long {
val subDirs = fileStructure.getOrDefault(dirName, emptyList())
return dirSize.getOrDefault(dirName, 0) + subDirs.sumOf {
sizeOf(
... | 0 | Kotlin | 0 | 0 | c3157c2d66a098598a6b19fd3a2b18a6bae95f0c | 3,299 | advent_of_code_2022 | Apache License 2.0 |
src/Day03.kt | frungl | 573,598,286 | false | {"Kotlin": 86423} | fun main() {
fun cost(ch: Char): Int {
return when(ch) {
in 'a'..'z' -> ch - 'a' + 1
else -> ch - 'A' + 27
}
}
fun part1(input: List<String>): Int {
return input.sumOf { str ->
val (l, r) = str.chunked(str.length / 2)
l.toCharArray().d... | 0 | Kotlin | 0 | 0 | d4cecfd5ee13de95f143407735e00c02baac7d5c | 1,544 | aoc2022 | Apache License 2.0 |
kotlin-practice/src/main/kotlin/exercise/collection/CollectionOperators.kt | nicolegeorgieva | 590,020,790 | false | {"Kotlin": 120359} | package exercise.collection
fun main() {
val students = listOf<Student>(
Student("John", 20, 3.5),
Student("Jane", 21, 3.8),
Student("Jack", 22, 3.2),
Student("J", 20, 6.0),
Student("JC", 20, 4.5)
)
println(studentsInfo(students))
}
data class Student(
val name... | 0 | Kotlin | 0 | 1 | c96a0234cc467dfaee258bdea8ddc743627e2e20 | 2,462 | kotlin-practice | MIT License |
src/Day08.kt | jwklomp | 572,195,432 | false | {"Kotlin": 65103} | fun main() {
fun isVisible(grid: Grid2D<Int>, cell: Cell<Int>): Boolean {
val row = grid.getRow(cell.y) // y fixed, x variable
val isLeftVisible = row.filter { it.x < cell.x }.all { it.value < cell.value }
val isRightVisible = row.filter { it.x > cell.x }.all { it.value < cell.value }
... | 0 | Kotlin | 0 | 0 | 1b1121cfc57bbb73ac84a2f58927ab59bf158888 | 2,127 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day07.kt | erikthered | 572,804,470 | false | {"Kotlin": 36722} | fun main() {
data class File(val name: String, val path: List<String>, val size: Int)
data class Folder(val name: String, val path: List<String>, val files: List<File>)
fun computeFolderSizes(input: List<String>): List<Pair<String, Int>> {
val location = mutableListOf<String>()
val folder... | 0 | Kotlin | 0 | 0 | 3946827754a449cbe2a9e3e249a0db06fdc3995d | 2,967 | aoc-2022-kotlin | Apache License 2.0 |
src/Day07.kt | chasebleyl | 573,058,526 | false | {"Kotlin": 15274} |
data class Directory(
val name: String,
val parent: Directory? = null,
val subDirectories: MutableList<Directory> = mutableListOf<Directory>(),
val files: MutableList<File> = mutableListOf<File>(),
) {
fun allSubDirectories(): List<Directory> = subDirectories + subDirectories.flatMap { it.allSubDir... | 0 | Kotlin | 0 | 1 | f2f5cb5fd50fb3e7fb9deeab2ae637d2e3605ea3 | 1,966 | aoc-2022 | Apache License 2.0 |
src/Day11.kt | maewCP | 579,203,172 | false | {"Kotlin": 59412} | import java.math.BigInteger
fun main() {
fun readMonkeys(strs: List<String>): MutableList<Day11Monkey> {
val monkeys = mutableListOf<Day11Monkey>()
val regex = "Monkey (\\d+):\\n.*Starting items: (.*)\\n.*Operation: new = old (.*)\\n.*Test: divisible by (\\d+)\\n.*If true: throw to monkey (\\d+)\\... | 0 | Kotlin | 0 | 0 | 8924a6d913e2c15876c52acd2e1dc986cd162693 | 4,049 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day07.kt | gsalinaslopez | 572,839,981 | false | {"Kotlin": 21439} | const val TOTAL_DISK_SPACE = 70000000
const val UPDATE_SIZE = 30000000
enum class FileType { FILE, DIR }
data class FileSystemEntry(val size: Long, val name: String, val fileType: FileType)
fun main() {
fun buildFileSystemTree(input: List<String>): Map<FileSystemEntry, List<FileSystemEntry>> {
val dirNav... | 0 | Kotlin | 0 | 0 | 041c7c3716bfdfdf4cc89975937fa297ea061830 | 3,871 | aoc-2022-in-kotlin | Apache License 2.0 |
AdventOfCodeDay19/src/nativeMain/kotlin/Day19.kt | bdlepla | 451,510,571 | false | {"Kotlin": 165771} | class Day19(lines:List<String>) {
private val scanners: List<Set<Point3d>> = parseInput(lines.joinToString("\n"))
private fun parseInput(input: String): List<Set<Point3d>> =
input.split("\n\n").map { singleScanner ->
singleScanner
.lines()
.drop(1)
... | 0 | Kotlin | 0 | 0 | 1d60a1b3d0d60e0b3565263ca8d3bd5c229e2871 | 2,173 | AdventOfCode2021 | The Unlicense |
jvm/src/main/kotlin/io/prfxn/aoc2021/day08.kt | prfxn | 435,386,161 | false | {"Kotlin": 72820, "Python": 362} | // Seven Segment Search (https://adventofcode.com/2021/day/8)
package io.prfxn.aoc2021
fun main() {
val lines =
requireNotNull(object {}.javaClass.classLoader.getResourceAsStream("input/08.txt"))
.reader()
.useLines { lineSeq ->
lineSeq
.map { l... | 0 | Kotlin | 0 | 0 | 148938cab8656d3fbfdfe6c68256fa5ba3b47b90 | 4,121 | aoc2021 | MIT License |
kotlin/src/Day04.kt | ekureina | 433,709,362 | false | {"Kotlin": 65477, "C": 12591, "Rust": 7560, "Makefile": 386} | import java.lang.Long.parseLong
data class BingoSquare(val number: Long, val isPicked:Boolean = false)
data class BingoBoard(val numbers: List<List<BingoSquare>>) {
fun markNumber(number:Long): BingoBoard {
return BingoBoard(numbers.map { row ->
row.map { square ->
if (square.n... | 0 | Kotlin | 0 | 1 | 391d0017ba9c2494092d27d22d5fd9f73d0c8ded | 2,913 | aoc-2021 | MIT License |
src/Day09.kt | mkfsn | 573,042,358 | false | {"Kotlin": 29625} | import kotlin.math.sign
fun main() {
data class Action(val direction: Char, val steps: Int)
data class Point(val x: Int, val y: Int)
class Solution(input: List<String>, size: Int) {
val actions: List<Action>
val rope = MutableList(size) { Point(1, 1) }
init {
this.act... | 0 | Kotlin | 0 | 1 | 8c7bdd66f8550a82030127aa36c2a6a4262592cd | 1,903 | advent-of-code-kotlin-2022 | Apache License 2.0 |
gcj/y2020/round2/a.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2020.round2
import kotlin.math.pow
fun solvePancakes(aIn: Long, bIn: Long): String {
var a = aIn; var b = bIn
var i = 1L
val maxN = (a.toDouble() + b + 100).pow(0.5).toLong() * 2
fun step(): String? {
if (maxOf(a, b) < i) return "${i - 1} $a $b"
if (a >= b) a -= i else b -= i
i++
return null... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,477 | competitions | The Unlicense |
advent-of-code-2021/src/main/kotlin/Day8.kt | jomartigcal | 433,713,130 | false | {"Kotlin": 72459} | //Day 8: Seven Segment Search
//https://adventofcode.com/2021/day/8
import java.io.File
fun main() {
val lines = File("src/main/resources/Day8.txt").readLines()
count1478FromOutput(lines.map { it.substringAfter(" | ").split(" ") })
countAll(lines)
}
fun count1478FromOutput(outputs: List<List<String>>) {
... | 0 | Kotlin | 0 | 0 | 6b0c4e61dc9df388383a894f5942c0b1fe41813f | 1,814 | advent-of-code | Apache License 2.0 |
src/main/kotlin/Day17.kt | clechasseur | 267,632,210 | false | null | import org.clechasseur.adventofcode2016.Direction
import org.clechasseur.adventofcode2016.Pt
import org.clechasseur.adventofcode2016.md5
object Day17 {
private const val input = "awrkjxxr"
fun part1(): String = shortestPath(State(Pt.ZERO, emptyList()))
fun part2(): Int = longestPath(State(Pt.ZERO, emptyL... | 0 | Kotlin | 0 | 0 | 120795d90c47e80bfa2346bd6ab19ab6b7054167 | 2,008 | adventofcode2016 | MIT License |
src/Day02.kt | l8nite | 573,298,097 | false | {"Kotlin": 105683} | fun main() {
val points = mapOf("Rock" to 1, "Paper" to 2, "Scissors" to 3)
val beats = mapOf("Rock" to "Paper", "Paper" to "Scissors", "Scissors" to "Rock")
val beatenBy = beats.entries.associateBy({ it.value }){ it.key }
fun parseGuide(input: List<String>, strategy: Map<String, String>): List<Pair<St... | 0 | Kotlin | 0 | 0 | f74331778fdd5a563ee43cf7fff042e69de72272 | 1,828 | advent-of-code-2022 | Apache License 2.0 |
src/Day08.kt | iartemiev | 573,038,071 | false | {"Kotlin": 21075} | fun generateTreePairSet(matrix: List<List<Int>>): Set<Pair<Int, Int>> {
val minLeft = 1
val minTop = 1
val minRight = matrix[0].size - 2
val minBottom = matrix.size - 2
val treePairSet = mutableSetOf<Pair<Int, Int>>()
// top left -> bottom right
val minTopY = matrix[0].toCollection(mutableListOf())
fo... | 0 | Kotlin | 0 | 0 | 8d2b7a974c2736903a9def65282be91fbb104ffd | 2,812 | advent-of-code | Apache License 2.0 |
src/Day09.kt | jorgecastrejon | 573,097,701 | false | {"Kotlin": 33669} | import kotlin.math.abs
fun main() {
fun part1(input: List<String>): Int {
val moves = input.map { move -> move.split(" ").let { it.first() to it.last().toInt() } }
return moves.resolve(chainLength = 2).size
}
fun part2(input: List<String>): Int {
val moves = input.map { move -> m... | 0 | Kotlin | 0 | 0 | d83b6cea997bd18956141fa10e9188a82c138035 | 1,487 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day15/Day15.kt | joostbaas | 573,096,671 | false | {"Kotlin": 45397} | package day15
import kotlin.math.abs
fun String.parse(): SensorReading {
val regex = """Sensor at x=(-?\d+), y=(-?\d+): closest beacon is at x=(-?\d+), y=(-?\d+)"""
val (x1, y1, x2, y2) = regex.toRegex().matchEntire(this)!!.destructured
return SensorReading(Point(x1.toInt(), y1.toInt()), Point(x2.toInt(),... | 0 | Kotlin | 0 | 0 | 8d4e3c87f6f2e34002b6dbc89c377f5a0860f571 | 3,160 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | WhatDo | 572,393,865 | false | {"Kotlin": 24776} | fun main() {
val input = readInput("Day02")
val rounds = input.map(::mapRound)
val scores = rounds.map(::roundScore)
println("Total score for following guide is ${scores.sum()}")
val outcomeRound = input.map(::mapOutcomeRound)
val outcomeScores = outcomeRound.map(::outcomeRoundScore)
prin... | 0 | Kotlin | 0 | 0 | 94abea885a59d0aa3873645d4c5cefc2d36d27cf | 2,562 | aoc-kotlin-2022 | Apache License 2.0 |
src/Day11.kt | kpilyugin | 572,573,503 | false | {"Kotlin": 60569} | fun main() {
class Monkey(
val operation: (Long) -> Long,
val divisibleBy: Int,
val test: (Long) -> Int) {
val items = mutableListOf<Long>()
var inspected = 0L
fun inspect(monkeys: List<Monkey>, manage: (Long) -> Long = { it / 3 }) {
for (item in items) {... | 0 | Kotlin | 0 | 1 | 7f0cfc410c76b834a15275a7f6a164d887b2c316 | 2,376 | Advent-of-Code-2022 | Apache License 2.0 |
src/year2021/day15/Day15.kt | fadi426 | 433,496,346 | false | {"Kotlin": 44622} | package year2021.day15
import util.read2021DayInput
fun main() {
fun task1(input: List<String>): Int {
val board = MutableList(input.size) { input[it].map { "$it".toInt() }.toMutableList() }
return findShortestDistance(board)
}
fun task2(input: List<String>, expansionNumber: Int): Int {
... | 0 | Kotlin | 0 | 0 | acf8b6db03edd5ff72ee8cbde0372113824833b6 | 2,640 | advent-of-code-kotlin-template | Apache License 2.0 |
src/day9/Day09.kt | MatthewWaanders | 573,356,006 | false | null | package day9
import utils.readInput
typealias PositionState = Pair<Int, Int>
typealias Dimension = String
typealias Direction = Int
const val row: Dimension = "ROW"
const val column: Dimension = "COLUMN"
const val reverse: Direction = -1
const val normal: Direction = 1
fun main() {
val testInput = readInput("D... | 0 | Kotlin | 0 | 0 | f58c9377edbe6fc5d777fba55d07873aa7775f9f | 4,201 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | davedupplaw | 573,042,501 | false | {"Kotlin": 29190} | fun main() {
val yourShapeMap = mapOf(
"X" to "A",
"Y" to "B",
"Z" to "C"
)
val shapeScores = mapOf(
"A" to 1,
"B" to 2,
"C" to 3
)
val beats = mapOf(
"C" to "B",
"B" to "A",
"A" to "C"
)
... | 0 | Kotlin | 0 | 0 | 3b3efb1fb45bd7311565bcb284614e2604b75794 | 1,358 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc/year2023/Day11.kt | SackCastellon | 573,157,155 | false | {"Kotlin": 62581} | package aoc.year2023
import aoc.Puzzle
import kotlin.math.abs
/**
* [Day 11 - Advent of Code 2023](https://adventofcode.com/2023/day/11)
*/
object Day11 : Puzzle<Long, Long> {
override fun solvePartOne(input: String): Long = input.solve(expansionRate = 2)
override fun solvePartTwo(input: String): Long = in... | 0 | Kotlin | 0 | 0 | 75b0430f14d62bb99c7251a642db61f3c6874a9e | 2,334 | advent-of-code | Apache License 2.0 |
src/Day13.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | object Day13 {
const val EXPECTED_PART1_CHECK_ANSWER = 13
const val EXPECTED_PART2_CHECK_ANSWER = 140
const val PACKET_COMBOS_NR_OF_LINES = 3
val NONE_NUMBER_CHARS = listOf('[', ']', ',')
const val DIVIDER_PACKET_ONE = 2
const val DIVIDER_PACKET_TWO = 6
val DIVIDER_PACKETS: List<List<Any>> ... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 3,563 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day02.kt | icoffiel | 572,651,851 | false | {"Kotlin": 29350} | fun main() {
fun winLoseOrDraw(playerOne: ITEM, playerTwo: ITEM) = when (playerOne) {
playerTwo -> OUTCOME.DRAW
playerTwo.beats() -> OUTCOME.WIN
else -> OUTCOME.LOSE
}
fun shouldPlay(playerOne: ITEM, expectedOutcome: OUTCOME): ITEM = when(expectedOutcome) {
OUTCOME.LOSE -> ... | 0 | Kotlin | 0 | 0 | 515f5681c385f22efab5c711dc983e24157fc84f | 2,242 | advent-of-code-2022 | Apache License 2.0 |
src/y2015/Day14.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2015
import util.readInput
import kotlin.math.min
data class Reindeer(
val speed: Int,
val endurance: Int,
val rest: Int
) {
fun distance(testTime: Int): Int {
val cycleLength = endurance + rest
val distancePerCycle = endurance * speed
val numCycles = testTime / cycleL... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 2,023 | advent-of-code | Apache License 2.0 |
src/main/kotlin/g0801_0900/s0891_sum_of_subsequence_widths/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0891_sum_of_subsequence_widths
// #Hard #Array #Math #Sorting #2023_04_10_Time_481_ms_(100.00%)_Space_48.5_MB_(100.00%)
class Solution {
// 1-6 (number of elements in between 1 and 6) = (6-1-1) = 4
// length of sub seq 2 -> 4C0 3 -> 4C1 ; 4 -> 4c2 ; 5 -> 4C3 6 -> 4C4 4c0 + 4c1 + 4c2 + 4c... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,754 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/aoc2021/Day04.kt | davidsheldon | 565,946,579 | false | {"Kotlin": 161960} | package aoc2021
import aoc2022.blocksOfLines
import utils.InputUtils
class Day04(val calls: List<Int>, private val boards: List<Board>) {
fun makeCalls(): Sequence<Pair<Int, Board>> = calls.asSequence().flatMap { n ->
boards.filter { !it.isWinner() }.filter {
it.callNumber(n)
it.... | 0 | Kotlin | 0 | 0 | 5abc9e479bed21ae58c093c8efbe4d343eee7714 | 2,986 | aoc-2022-kotlin | Apache License 2.0 |
2k23/aoc2k23/src/main/kotlin/21.kt | papey | 225,420,936 | false | {"Rust": 88237, "Kotlin": 63321, "Elixir": 54197, "Crystal": 47654, "Go": 44755, "Ruby": 24620, "Python": 23868, "TypeScript": 5612, "Scheme": 117} | package d21
import input.read
import java.math.BigInteger
fun main() {
println("Part 1: ${part1(read("21.txt"))}")
println("Part 2: ${part2(read("21.txt"))}")
}
fun part1(input: List<String>): Int = Maze(input).discover()
fun part2(input: List<String>): BigInteger {
val goal = 26501365
val maze = Ma... | 0 | Rust | 0 | 3 | cb0ea2fc043ebef75aff6795bf6ce8a350a21aa5 | 2,776 | aoc | The Unlicense |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.