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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
gcj/y2020/round2/b.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2020.round2
private fun solve(): String {
val (n, m) = readInts()
val data = (listOf(0) + readInts()).toIntArray()
val edges = List(m) { readInts().map { it - 1 } }
val added = IntArray(n)
data.withIndex().filter { it.value < 0 }.forEach { entry ->
added[(-entry.value until n).first { added[it] == ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,133 | competitions | The Unlicense |
src/Day13.kt | StephenVinouze | 572,377,941 | false | {"Kotlin": 55719} | import java.lang.Integer.min
sealed interface PacketData : Comparable<PacketData> {
data class Single(val value: Int) : PacketData {
override fun compareTo(other: PacketData): Int =
when (other) {
is Single -> this.value - other.value
is Multiple -> Multiple(list... | 0 | Kotlin | 0 | 0 | 11b9c8816ded366aed1a5282a0eb30af20fff0c5 | 3,181 | AdventOfCode2022 | Apache License 2.0 |
advent-of-code-2023/src/Day17.kt | osipxd | 572,825,805 | false | {"Kotlin": 141640, "Shell": 4083, "Scala": 693} | import lib.matrix.*
import lib.matrix.Direction.Companion.nextInDirection
import lib.matrix.Direction.DOWN
import lib.matrix.Direction.RIGHT
import kotlin.math.min
private const val DAY = "Day17"
fun main() {
fun testInput(id: Int) = readInput("${DAY}_test$id")
fun input() = readInput(DAY)
"Part 1" {
... | 0 | Kotlin | 0 | 5 | 6a67946122abb759fddf33dae408db662213a072 | 2,818 | advent-of-code | Apache License 2.0 |
src/y2023/d05/Day05.kt | AndreaHu3299 | 725,905,780 | false | {"Kotlin": 31452} | package y2023.d05
import println
import readInput
class Seed(val min: Long, val max: Long)
class Range(
private val fromMin: Long,
private val fromMax: Long,
private val toMin: Long,
private val toMax: Long
) {
constructor(domainMin: Long, codomainMin: Long, length: Long) :
this(domainMin... | 0 | Kotlin | 0 | 0 | f883eb8f2f57f3f14b0d65dafffe4fb13a04db0e | 4,909 | aoc | Apache License 2.0 |
app/src/main/kotlin/day02/Day02.kt | KingOfDog | 433,706,881 | false | {"Kotlin": 76907} | package day02
import common.InputRepo
import common.readSessionCookie
import common.solve
fun main(args: Array<String>) {
val day = 2
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay02Part1, ::solveDay02Part2)
}
fun solveDay02Part1(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | 576e5599ada224e5cf21ccf20757673ca6f8310a | 1,820 | advent-of-code-kt | Apache License 2.0 |
aoc2023/day15.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2023
import utils.InputRetrieval
fun main() {
Day15.execute()
}
private object Day15 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
private fun part1(input: List<Operation>): Long = input.sumOf { i... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 3,061 | Advent-Of-Code | MIT License |
src/year2023/day11/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2023.day11
import arrow.core.nonEmptyListOf
import io.kotest.matchers.shouldBe
import kotlin.math.max
import kotlin.math.min
import utils.Point
import utils.ProblemPart
import utils.combinations
import utils.manhattanDistanceTo
import utils.permutations
import utils.readInputs
import utils.runAlgorithm
fu... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 2,405 | Advent-of-Code | Apache License 2.0 |
src/main/kotlin/tr/emreone/adventofcode/days/Day08.kt | EmRe-One | 568,569,073 | false | {"Kotlin": 166986} | package tr.emreone.adventofcode.days
import tr.emreone.kotlin_utils.Logger.logger
import tr.emreone.kotlin_utils.math.Coords
object Day08 {
private fun generateTreeMap(input: List<String>): Map<Coords, List<List<Int>>> {
val trees = mutableMapOf<Coords, List<List<Int>>>()
input.forEachIndexed { ... | 0 | Kotlin | 0 | 0 | a951d2660145d3bf52db5cd6d6a07998dbfcb316 | 2,409 | advent-of-code-2022 | Apache License 2.0 |
advent-of-code-2023/src/Day06.kt | osipxd | 572,825,805 | false | {"Kotlin": 141640, "Shell": 4083, "Scala": 693} | private const val DAY = "Day06"
fun main() {
fun testInput() = readInput("${DAY}_test")
fun testInput2() = readInput2("${DAY}_test")
fun input() = readInput(DAY)
fun input2() = readInput2(DAY)
"Part 1" {
part1(testInput()) shouldBe 288
measureAnswer { part1(input()) }
}
"P... | 0 | Kotlin | 0 | 5 | 6a67946122abb759fddf33dae408db662213a072 | 1,516 | advent-of-code | Apache License 2.0 |
src/twentytwo/Day13.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("Day13_test")
val part1 = part1(testInput)
println(part1)
check(part1 == 13)
val part2 = part2(testInput)
println(part2)
check(part2 == 140)
println("-... | 1 | Kotlin | 0 | 0 | 600237b66b8cd3145f103b5fab1978e407b19e4c | 3,717 | advent-of-code-solutions | Apache License 2.0 |
src/Day08.kt | sebokopter | 570,715,585 | false | {"Kotlin": 38263} | fun main() {
fun forest(input: List<String>): List<List<Int>> =
input.map { row -> row.map { tree -> tree.digitToInt() } }
fun isVisible(view: List<Int>): Boolean {
val treeSize = view.last()
return view.dropLast(1).all { it < treeSize }
}
fun countVisible(view: List<Int>, cur... | 0 | Kotlin | 0 | 0 | bb2b689f48063d7a1b6892fc1807587f7050b9db | 4,164 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | rifkinni | 573,123,064 | false | {"Kotlin": 33155, "Shell": 125} | abstract class CharacterPriority {
abstract fun intersection(): Char
fun calculate(): Int {
return getItemPriority(intersection())
}
private fun getItemPriority(c: Char): Int {
return priorityString.indexOf(c) + 1
}
companion object {
private const val priorityString =... | 0 | Kotlin | 0 | 0 | c2f8ca8447c9663c0ce3efbec8e57070d90a8996 | 1,602 | 2022-advent | Apache License 2.0 |
src/Day07.kt | RusticFlare | 574,508,778 | false | {"Kotlin": 78496} | import Filesystem.Directory
private sealed interface Filesystem {
val size: Int
data class Directory(
val name: String,
val parent: Directory?,
val files: MutableList<Filesystem> = mutableListOf(),
) : Filesystem {
override val size: Int
get() = files.sumOf { ... | 0 | Kotlin | 0 | 1 | 10df3955c4008261737f02a041fdd357756aa37f | 2,524 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day19.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | import java.util.*
import kotlin.math.max
import kotlin.math.min
private data class Blueprint(val totalCosts: List<List<Int>>)
private data class State(val robotBuilt: List<Int>, var resources: List<Int>)
private const val SHIFT_1: Long = 25
private const val SHIFT_2: Long = 340
private const val BASE: Long = SHIFT_1... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 4,036 | advent-of-kotlin-2022 | Apache License 2.0 |
src/Day13.kt | dmarcato | 576,511,169 | false | {"Kotlin": 36664} | import kotlin.math.min
interface PacketEntry : Comparable<PacketEntry> {
companion object
}
fun PacketEntry.Companion.from(content: String): PacketEntry {
return when {
content.isEmpty() -> PacketList(emptyList())
content.startsWith("[") -> PacketList.from(content)
else -> PacketNumber... | 0 | Kotlin | 0 | 0 | 6abd8ca89a1acce49ecc0ca8a51acd3969979464 | 3,413 | aoc2022 | Apache License 2.0 |
src/Day03.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 = 4361
private const val EXPECTED_2 = 467835
private class Day03(isTest: Boolean) : Solver(isTest) {
fun part1(): Any {
val field = readAsLines()
var sum = 0
for (y in field.indices) {
var x = 0
... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 3,364 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | anoniim | 572,264,555 | false | {"Kotlin": 8381} | fun main() {
Day3().run(
157,
70
)
}
private class Day3 : Day(3) {
override fun part1(input: List<String>): Int {
// What is the sum of the priorities of those item types?
val sharedItemTypes = mutableListOf<ItemType>()
input.forEach { rucksack ->
val co... | 0 | Kotlin | 0 | 0 | 15284441cf14948a5ebdf98179481b34b33e5817 | 1,825 | Advent-of-Code-2022 | Apache License 2.0 |
src/Day11.kt | D000L | 575,350,411 | false | {"Kotlin": 23716} | data class Monkey(
val number: Int,
var items: MutableList<Long> = mutableListOf(),
var operation: String = "",
var divisible: Int = 0,
var trueTarget: Int = 0,
var falseTarget: Int = 0
) {
var inspectedCount = 0L
fun getOperatedItems(): List<Long> {
return items.map {
... | 0 | Kotlin | 0 | 0 | b733a4f16ebc7b71af5b08b947ae46afb62df05e | 3,070 | adventOfCode | Apache License 2.0 |
src/main/kotlin/Day6.kt | Ostkontentitan | 434,500,914 | false | {"Kotlin": 73563} | fun puzzleDaySixPartOne() {
val input = readInput(6).first()
val fishes = inputToPopulation(input)
val fishPrediction = predictPopulation(fishes, 80)
println("Fish prediction after 80 days: ${fishPrediction.size}")
}
fun puzzleDaySixPartTwo() {
val input = readInput(6).first()
val model = inpu... | 0 | Kotlin | 0 | 0 | e0e5022238747e4b934cac0f6235b92831ca8ac7 | 1,608 | advent-of-kotlin-2021 | Apache License 2.0 |
src/main/kotlin/day21/Allergens.kt | lukasz-marek | 317,632,409 | false | {"Kotlin": 172913} | package day21
sealed class AbstractAllergen
object NoAllergen : AbstractAllergen()
data class Allergen(val name: String) : AbstractAllergen()
inline class Ingredient(val name: String)
data class Food(val ingredients: Set<Ingredient>, val allergens: Set<AbstractAllergen>)
private val foodPattern = Regex("^(.+) \\(cont... | 0 | Kotlin | 0 | 0 | a16e95841e9b8ff9156b54e74ace9ccf33e6f2a6 | 4,379 | aoc2020 | MIT License |
src/Day07.kt | azat-ismagilov | 573,217,326 | false | {"Kotlin": 75114} | fun main() {
abstract class FileSystemUnit() {
abstract val size: Int
}
class Directory(val parent: Directory? = null) : FileSystemUnit() {
private var realSize: Int? = null
override val size: Int
get() {
if (realSize == null)
realSiz... | 0 | Kotlin | 0 | 0 | abdd1b8d93b8afb3372cfed23547ec5a8b8298aa | 3,019 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day04.kt | Sagolbah | 573,032,320 | false | {"Kotlin": 14528} | import kotlin.math.max
import kotlin.math.min
fun main() {
data class Segment(val start: Int, val end: Int)
fun parse(line: String): Pair<Segment, Segment> {
val (fst, snd) = line.split(',')
val (fst1, fst2) = fst.split('-').map { x -> x.toInt() }
val (snd1, snd2) = snd.split('-').map... | 0 | Kotlin | 0 | 0 | 893c1797f3995c14e094b3baca66e23014e37d92 | 1,837 | advent-of-code-kt | Apache License 2.0 |
src/main/kotlin/Day7.kt | vw-anton | 574,945,231 | false | {"Kotlin": 33295} | fun main() {
val parsed = readFile("input/7.txt")
.drop(1)
.map { line ->
when {
line == "\$ cd /" -> Directory(name = "/")
line.startsWith("$") -> Command.from(line)
line.first().isDigit() -> File.from(line)
else -> Directo... | 0 | Kotlin | 0 | 0 | a823cb9e1677b6285bc47fcf44f523e1483a0143 | 2,986 | aoc2022 | The Unlicense |
src/Day09.kt | buczebar | 572,864,830 | false | {"Kotlin": 39213} | import java.lang.IllegalArgumentException
import kotlin.math.abs
typealias Point = Pair<Int, Int>
private fun Point.isTouching(point: Point) = abs(first - point.first) < 2 && abs(second - point.second) < 2
fun main() {
fun parseInput(name: String) = readInput(name).map { it.splitWords() }
.map { (directio... | 0 | Kotlin | 0 | 0 | cdb6fe3996ab8216e7a005e766490a2181cd4101 | 2,739 | advent-of-code | Apache License 2.0 |
src/poyea/aoc/mmxxii/day22/Day22.kt | poyea | 572,895,010 | false | {"Kotlin": 68491} | package poyea.aoc.mmxxii.day22
import poyea.aoc.utils.readInput
data class Point(val x: Int, val y: Int) {
operator fun plus(other: Point) = Point(x + other.x, y + other.y)
}
sealed class Instruction {
object Left : Instruction()
object Right : Instruction()
data class Move(val steps: Int) : Instru... | 0 | Kotlin | 0 | 1 | fd3c96e99e3e786d358d807368c2a4a6085edb2e | 6,976 | aoc-mmxxii | MIT License |
2022/src/test/kotlin/Day16.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
private data class Valve(val name: String, val flowRate: Int, val leadsTo: List<String>, var open: Boolean = false)
private val re = "rate=(\\d+);".toRegex()
class Day16 : StringSpec({
"puzzle part 01" {
val valves = getValves(... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 4,046 | adventofcode | MIT License |
src/day4/puzzle04.kt | brendencapps | 572,821,792 | false | {"Kotlin": 70597} | package day4
import Puzzle
import PuzzleInput
import java.io.File
fun day4Puzzle() {
val inputDir = "inputs/day4"
Day4Puzzle1Solution().solve(Day4PuzzleInput("$inputDir/example.txt", 2))
Day4Puzzle1Solution().solve(Day4PuzzleInput("$inputDir/input.txt", 305))
Day4Puzzle2Solution().solve(Day4PuzzleInpu... | 0 | Kotlin | 0 | 0 | 00e9bd960f8bcf6d4ca1c87cb6e8807707fa28f3 | 2,113 | aoc_2022 | Apache License 2.0 |
src/Day02.kt | stevefranchak | 573,628,312 | false | {"Kotlin": 34220} | class StrategyGuideParser(private val scorer: Scorer) {
fun sumScores(input: List<String>) =
input.asSequence().map(::scoreLine).sum()
private fun scoreLine(line: String): Int {
if (line.isBlank()) {
return 0
}
return scorer.score(line.split(" "))
}
}
interface ... | 0 | Kotlin | 0 | 0 | 22a0b0544773a6c84285d381d6c21b4b1efe6b8d | 3,569 | advent-of-code-2022 | Apache License 2.0 |
src/Day13.kt | proggler23 | 573,129,757 | false | {"Kotlin": 27990} | import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
return input.parse13().withIndex().sumOf {
val (left, right) = it.value
if (left < right) it.index + 1
else 0
}
}
fun part2(input: List<String>): Int {
val dividerPackets =... | 0 | Kotlin | 0 | 0 | 584fa4d73f8589bc17ef56c8e1864d64a23483c8 | 2,701 | advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | jpereyrol | 573,074,843 | false | {"Kotlin": 9016} | import kotlin.math.max
import kotlin.math.min
fun main() {
fun part1(input: List<String>): Int {
val firstSplit = input.map { it.split(",") }
val secondSplit = firstSplit.map { it.map { it.split("-") } }.map { it.map { it.map { it.toInt() } } }
val ranges = secondSplit.map { it.map { Int... | 0 | Kotlin | 0 | 0 | e17165afe973392a0cbbac227eb31d215bc8e07c | 1,403 | advent-of-code | Apache License 2.0 |
src/Day13.kt | achugr | 573,234,224 | false | null | import kotlinx.serialization.json.*
val packetDataComparator = PacketDataComparator()
data class Packet(private val rawData: String, private val data: JsonElement) : Comparable<Packet> {
companion object PacketParser {
fun parse(input: String): Packet {
return Packet(input, Json.parseToJsonEle... | 0 | Kotlin | 0 | 0 | d91bda244d7025488bff9fc51ca2653eb6a467ee | 2,541 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day15.kt | ShuffleZZZ | 572,630,279 | false | {"Kotlin": 29686} | import kotlin.math.absoluteValue
private const val TEST_LINE = 10
private const val LINE = 2_000_000
private const val TEST_SIZE = 20
private const val SIZE = 4_000_000
private val template = "Sensor at x=(-?\\d+), y=(-?\\d+): closest beacon is at x=(-?\\d+), y=(-?\\d+)".toRegex()
private fun getCoordinates(input: ... | 0 | Kotlin | 0 | 0 | 5a3cff1b7cfb1497a65bdfb41a2fe384ae4cf82e | 2,891 | advent-of-code-kotlin | Apache License 2.0 |
src/Day07.kt | bendh | 573,833,833 | false | {"Kotlin": 11618} | fun main() {
data class File(val name: String, val size: Int)
class Directory(val name: String, var parent: Directory? = null) {
val files = mutableListOf<File>()
val childDirectories = mutableListOf<Directory>()
var dirSize = 0
}
fun diskSizeData(input: List<String>): List<Dir... | 0 | Kotlin | 0 | 0 | e3ef574441b63a99a99a095086a0bf025b8fc475 | 2,596 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/year2022/Day11.kt | Maetthu24 | 572,844,320 | false | {"Kotlin": 41016} | package year2022
fun main() {
data class Monkey(val items: MutableList<Long>, val operation: (Long) -> Long, val divisibleBy: Long, val ifTrue: Int, val ifFalse: Int) {
fun test(nr: Long): Int {
return if(nr % divisibleBy == 0.toLong()) ifTrue else ifFalse
}
}
fun createMonkey(... | 0 | Kotlin | 0 | 1 | 3b3b2984ab718899fbba591c14c991d76c34f28c | 3,963 | adventofcode-kotlin | Apache License 2.0 |
2021/kotlin/src/main/kotlin/nl/sanderp/aoc/aoc2021/day05/Day05.kt | sanderploegsma | 224,286,922 | false | {"C#": 233770, "Kotlin": 126791, "F#": 110333, "Go": 70654, "Python": 64250, "Scala": 11381, "Swift": 5153, "Elixir": 2770, "Jinja": 1263, "Ruby": 1171} | package nl.sanderp.aoc.aoc2021.day05
import nl.sanderp.aoc.common.*
fun main() {
val input = readResource("Day05.txt").lines().map { parse(it) }
val (answer1, duration1) = measureDuration<Int> { countOverlappingPoints(input.filter { it.type != LineType.Diagonal }) }
println("Part one: $answer1 (took ${du... | 0 | C# | 0 | 6 | 8e96dff21c23f08dcf665c68e9f3e60db821c1e5 | 1,516 | advent-of-code | MIT License |
src/main/kotlin/be/tabs_spaces/advent2021/days/Day09.kt | janvryck | 433,393,768 | false | {"Kotlin": 58803} | package be.tabs_spaces.advent2021.days
class Day09 : Day(9) {
private val heightMap = HeightMap(inputList)
override fun partOne() = heightMap
.findLowPoints()
.map { heightMap.heightAt(it) }
.sumOf { it.toRiskLevel() }
override fun partTwo() = heightMap.largestThreeBasins().produ... | 0 | Kotlin | 0 | 0 | f6c8dc0cf28abfa7f610ffb69ffe837ba14bafa9 | 2,242 | advent-2021 | Creative Commons Zero v1.0 Universal |
src/Day01.kt | dyomin-ea | 572,996,238 | false | {"Kotlin": 21309} | fun main() {
fun List<String>.sumsBetweenEmpty(): MutableList<Int> =
fold(mutableListOf(0)) { acc, s ->
acc += if (s.isEmpty()) {
0
} else {
acc.pop() + s.toInt()
}
acc
}
fun part1(input: List<String>): Int =
input.sumsBetweenEmpty()
.max()
fun part2(input: List<String>): Int =
inpu... | 0 | Kotlin | 0 | 0 | 8aaf3f063ce432207dee5f4ad4e597030cfded6d | 1,998 | advent-of-code-2022 | Apache License 2.0 |
y2015/src/main/kotlin/adventofcode/y2015/Day13.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2015
import adventofcode.io.AdventSolution
import adventofcode.util.collections.permutations
object Day13 : AdventSolution(2015, 13, "Knights of the Dinner Table") {
override fun solvePartOne(input: String) = tryAllRoutes(input).maxOrNull().toString()
override fun solvePartTwo(input: ... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,985 | advent-of-code | MIT License |
src/Day08.kt | freszu | 573,122,040 | false | {"Kotlin": 32507} | enum class Direction { LEFT, TOP, RIGHT, BOTTOM }
fun <T> Sequence<T>.takeWhileInclusive(predicate: (T) -> Boolean): Sequence<T> {
var shouldContinue = true
return takeWhile {
val result = shouldContinue
shouldContinue = predicate(it)
result
}
}
fun <T> Matrix<T>.walkToEdge(fromX: ... | 0 | Kotlin | 0 | 0 | 2f50262ce2dc5024c6da5e470c0214c584992ddb | 1,864 | aoc2022 | Apache License 2.0 |
src/main/java/com/barneyb/aoc/aoc2022/day12/HillClimbingAlgorithm.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2022.day12
import com.barneyb.aoc.util.Slice
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toSlice
import com.barneyb.util.Dir
import com.barneyb.util.HashSet
import com.barneyb.util.Queue
import com.barneyb.util.Vec2
fun main() {
Solver.benchmark(
::parse,
... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 2,549 | aoc-2022 | MIT License |
problems/knights-on-chessboard/knight.kt | mre | 14,571,395 | false | {"Python": 149850, "JavaScript": 52163, "Rust": 22731, "Java": 18047, "Kotlin": 17919, "C++": 16563, "CoffeeScript": 16079, "PHP": 14313, "C#": 14295, "Shell": 11341, "Go": 8067, "Ruby": 5883, "C": 4745, "F#": 4418, "Swift": 1811, "Haskell": 1585, "TypeScript": 1405, "Scala": 1394, "Dart": 1025, "LOLCODE": 647, "Julia"... | import java.io.File
import java.util.stream.Collectors
fun main() {
KnightProblem().solve()
}
data class BoardField(val char: Char, val index: Pair<Int, Int>)
internal class KnightProblem {
companion object {
val board = File("problems/knights-on-chessboard/board.txt").readBoard()
}
data cl... | 8 | Python | 413 | 1,636 | e879e0949a24da5ebc80e9319683baabf8bb0a37 | 2,565 | the-coding-interview | MIT License |
src/main/kotlin/graph/core/ShortestPathWeighted.kt | yx-z | 106,589,674 | false | null | package graph.core
import util.INF
import util.Tuple2
import util.min
import util.tu
import java.util.*
import kotlin.collections.HashMap
// given a weighted graph, a starting vertex s
// find the shortest path with min weight from s to all other vertices
// assume the weights are all positive ints
fun <V> WeightedG... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 4,566 | AlgoKt | MIT License |
src/main/kotlin/dev/bogwalk/batch9/Problem99.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch9
import kotlin.math.log10
import kotlin.math.pow
/**
* Problem 99: Largest Exponential
*
* https://projecteuler.net/problem=99
*
* Goal: Compare 2 base (B) /exponent (E) pairs whose numbers contain a very large amount of
* digits, then use this comparison to either find the Kth smalles... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 4,326 | project-euler-kotlin | MIT License |
src/main/kotlin/cc/stevenyin/leetcode/_0075_SortColors.kt | StevenYinKop | 269,945,740 | false | {"Kotlin": 107894, "Java": 9565} | package cc.stevenyin.leetcode
/**
* Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.
* We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.
... | 0 | Kotlin | 0 | 1 | 748812d291e5c2df64c8620c96189403b19e12dd | 1,842 | kotlin-demo-code | MIT License |
src/year2021/04/Day04.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2021.`04`
import readInput
import transpose
private data class Bingos<T>(
val items: List<List<T>>
)
private data class Marked<T>(
val item: T,
var marked: Boolean
)
fun main() {
fun extractListOfNumbers(input: List<String>): List<Int> {
val filteredItems = input.filter { it.is... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 3,452 | KotlinAdventOfCode | Apache License 2.0 |
src/Day02.kt | gomercin | 572,911,270 | false | {"Kotlin": 25313} | import java.util.*
/*
* searches I needed to make:
* kotlin enum
* kotlin switch
* kotlin dictionary
* kotlin enum ordinal
* kotlin init array
* kotlin init list
* kotlin permutation
* */
enum class Move {
ROCK, PAPER, SCISSOR
}
enum class Winner {
OPPONENT, DRAW, PLAYER
}
fun main() {
val opponentMoveM... | 0 | Kotlin | 0 | 0 | 30f75c4103ab9e971c7c668f03f279f96dbd72ab | 4,430 | adventofcode-2022 | Apache License 2.0 |
src/Day02.kt | hottendo | 572,708,982 | false | {"Kotlin": 41152} |
enum class Score (val score: Int) {
WIN(6),
LOSS(0),
DRAW(3)
}
fun main() {
fun part1(input: List<String>): Int {
val winningMoves = mapOf<String, Int>("C X" to 1, "B Z" to 3, "A Y" to 2)
val loosingMoves = mapOf<String, Int>("B X" to 1, "A Z" to 3, "C Y" to 2)
val drawMoves =... | 0 | Kotlin | 0 | 0 | a166014be8bf379dcb4012e1904e25610617c550 | 3,170 | advent-of-code-2022 | Apache License 2.0 |
src/day21/Day21.kt | bartoszm | 572,719,007 | false | {"Kotlin": 39186} | package day21
import readInput
import toPair
fun main() {
println(solve1(parse(readInput("day21/test"))))
println(solve1(parse(readInput("day21/input"))))
println(solve2(parse(readInput("day21/test"))))
println(solve2(parse(readInput("day21/input"))))
}
fun String.isIdentifier() = !this[0].isDigi... | 0 | Kotlin | 0 | 0 | f1ac6838de23beb71a5636976d6c157a5be344ac | 4,247 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day18.kt | N-Silbernagel | 573,145,327 | false | {"Kotlin": 118156} | import kotlin.math.absoluteValue
fun main() {
val input = readFileAsList("Day18")
println(Day18.part1(input))
println(Day18.part2(input))
}
object Day18 {
fun part1(input: List<String>): Long {
val vectors = parseLava(input)
var uncoveredSidesTotal = 0
for ((index, vector) in ... | 0 | Kotlin | 0 | 0 | b0d61ba950a4278a69ac1751d33bdc1263233d81 | 2,375 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day9.kt | vw-anton | 574,945,231 | false | {"Kotlin": 33295} | import kotlin.math.sign
fun main() {
val commands = readFile("input/9.txt")
.map {
MoveCommand(it.first(), it.substringAfter(" ").toInt())
}
val rope1 = Rope(knots = 2)
val rope2 = Rope(knots = 10)
commands.forEach { command ->
rope1.move(command)
rope2.mov... | 0 | Kotlin | 0 | 0 | a823cb9e1677b6285bc47fcf44f523e1483a0143 | 3,526 | aoc2022 | The Unlicense |
src/y2021/Day02.kt | Yg0R2 | 433,731,745 | false | null | package y2021
import y2021.Directions.DOWN
import y2021.Directions.FORWARD
import y2021.Directions.UP
fun main() {
fun part1(input: List<String>): Int {
return input.toDirectionAmountPairList()
.fold(Submarine(0, 0, 0)) { acc, (direction, amount) ->
when (direction) {
... | 0 | Kotlin | 0 | 0 | d88df7529665b65617334d84b87762bd3ead1323 | 2,126 | advent-of-code | Apache License 2.0 |
src/Day19.kt | catcutecat | 572,816,768 | false | {"Kotlin": 53001} | import kotlin.system.measureTimeMillis
fun main() {
measureTimeMillis {
Day19.run {
solve1(33) // 1199
solve2(3348) // 3510
}
}.let { println("Total: $it ms") }
}
object Day19 : Day.LineInput<List<Day19.Blueprint>, Int>("19") {
class Blueprint(val id: Int, private ... | 0 | Kotlin | 0 | 2 | fd771ff0fddeb9dcd1f04611559c7f87ac048721 | 2,904 | AdventOfCode2022 | Apache License 2.0 |
src/Day02.kt | anisch | 573,147,806 | false | {"Kotlin": 38951} | enum class Shape(val score: Int) { ROCK(1), PAPER(2), SCISSORS(3)}
enum class OutCome(val result: Int) { LOST(0), DRAW(3), WIN(6)}
fun parseShapes(line: String): Pair<Shape, Shape> {
val s = line
.split(" ")
.map { s -> parseShape(s) }
return Pair(s[0], s[1])
}
fun parseShapeOutCome(line: Stri... | 0 | Kotlin | 0 | 0 | 4f45d264d578661957800cb01d63b6c7c00f97b1 | 2,919 | Advent-of-Code-2022 | Apache License 2.0 |
src/Day08.kt | timmiller17 | 577,546,596 | false | {"Kotlin": 44667} | fun main() {
fun part1(input: List<String>): Int {
var visibleTreeCount = 0
val rows = input.map { it.chunked(1) }
val outerTreeCount = rows[0].size * 2 + (rows.size - 2) * 2
visibleTreeCount += outerTreeCount
outerLoop@ for (column in 1..rows[0].size - 2) {
fo... | 0 | Kotlin | 0 | 0 | b6d6b647c7bb0e6d9e5697c28d20e15bfa14406c | 4,248 | advent-of-code-2022 | Apache License 2.0 |
src/Day12.kt | dakr0013 | 572,861,855 | false | {"Kotlin": 105418} | import java.lang.Integer.min
import kotlin.test.assertEquals
fun main() {
fun part1(input: List<String>): Int {
lateinit var start: Node
lateinit var target: Node
val map =
input.mapIndexed { y, line ->
line.toCharArray().mapIndexed { x, height ->
Node(x, y, height.value()).... | 0 | Kotlin | 0 | 0 | 6b3adb09f10f10baae36284ac19c29896d9993d9 | 3,780 | aoc2022 | Apache License 2.0 |
day10/kotlin/corneil/src/main/kotlin/solution.kt | timgrossmann | 224,991,491 | true | {"HTML": 2739009, "Python": 169603, "Java": 157274, "Jupyter Notebook": 116902, "TypeScript": 113866, "Kotlin": 89503, "Groovy": 73664, "Dart": 47763, "C++": 43677, "CSS": 34994, "Ruby": 27091, "Haskell": 26727, "Scala": 11409, "Dockerfile": 10370, "JavaScript": 6496, "PHP": 4152, "Go": 2838, "Shell": 2493, "Rust": 208... | package com.github.corneil.aoc2019.day10
import java.io.File
import java.math.BigDecimal
import java.math.RoundingMode.HALF_EVEN
import kotlin.math.atan2
import kotlin.math.max
import kotlin.math.sqrt
data class Coord(val x: Int, val y: Int)
data class AsteroidMap(val width: Int, val height: Int, val asteroidLocatio... | 0 | HTML | 0 | 1 | bb19fda33ac6e91a27dfaea27f9c77c7f1745b9b | 3,212 | aoc-2019 | MIT License |
src/main/kotlin/tr/emreone/adventofcode/days/Day9.kt | EmRe-One | 434,793,519 | false | {"Kotlin": 44202} | package tr.emreone.adventofcode.days
import tr.emreone.kotlin_utils.Logger.logger
object Day9 {
class Navigation(input: List<String>) {
private val cities = mutableSetOf<String>()
private val pattern = """^(\w+) to (\w+) = (\d+)$""".toRegex()
private val distanceMatrix = input.map { line ... | 0 | Kotlin | 0 | 0 | 57f6dea222f4f3e97b697b3b0c7af58f01fc4f53 | 4,342 | advent-of-code-2015 | Apache License 2.0 |
aoc21/day_18/main.kt | viktormalik | 436,281,279 | false | {"Rust": 227300, "Go": 86273, "OCaml": 82410, "Kotlin": 78968, "Makefile": 13967, "Roff": 9981, "Shell": 2796} | import java.io.File
data class Num(var num: Int, var depth: Int)
typealias Snailfish = MutableList<Num>
fun parseNum(str: String): Snailfish {
val result = mutableListOf<Num>()
var i = 0
var depth = 0
while (i < str.length) {
when (str[i]) {
'[' -> depth += 1
']' -> dep... | 0 | Rust | 1 | 0 | f47ef85393d395710ce113708117fd33082bab30 | 2,256 | advent-of-code | MIT License |
src/year2015/day09/Day09.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2015.day09
import check
import readInput
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("2015", "Day09_test")
check(part1(testInput), 605)
check(part2(testInput), 982)
val input = readInput("2015", "Day09")
println(part1... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 1,627 | AdventOfCode | Apache License 2.0 |
src/Day23.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} | class Day23(input: List<String>) {
private val startingPositions = parseInput(input)
private val nextTurnOffsets: List<List<Point2d>> = createOffsets()
fun solvePart1(): Int {
val locations = (0 until 10).fold(startingPositions) { carry, round -> carry.playRound(round) }
val gridSize =
... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 2,657 | aoc-22-kotlin | Apache License 2.0 |
kotlin/src/com/leetcode/47_PermutationsII.kt | programmerr47 | 248,502,040 | false | null | package com.leetcode
import kotlin.math.pow
/**
* This is the enhancement of 47 supporting recurrent numbers
* The approach is similar except the creation of Set in each
* depth level of recursive `permute` call.
*
* We need that Set to check that this number was already used
* in all previous combinations, so ... | 0 | Kotlin | 0 | 0 | 0b5fbb3143ece02bb60d7c61fea56021fcc0f069 | 3,811 | problemsolving | Apache License 2.0 |
app/src/main/kotlin/day03/Day03.kt | W3D3 | 433,748,408 | false | {"Kotlin": 72893} | package day03
import common.InputRepo
import common.readSessionCookie
import common.solve
import kotlin.math.ceil
fun main(args: Array<String>) {
val day = 3
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay03Part1, ::solveDay03Part2)
}
fun solveDay03Part1(input... | 0 | Kotlin | 0 | 0 | df4f21cd99838150e703bcd0ffa4f8b5532c7b8c | 2,696 | AdventOfCode2021 | Apache License 2.0 |
src/Day11.kt | ked4ma | 573,017,240 | false | {"Kotlin": 51348} | /**
* [Day11](https://adventofcode.com/2022/day/11)
*/
private class Day11 {
class Monkey private constructor(
val id: Int,
items: List<Long>,
val inspect: (Long) -> Long,
val divisible: Int,
private val destTrue: Int,
private val destFalse:... | 1 | Kotlin | 0 | 0 | 6d4794d75b33c4ca7e83e45a85823e828c833c62 | 3,596 | aoc-in-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/Day13.kt | dliszewski | 573,836,961 | false | {"Kotlin": 57757} | class Day13 {
fun part1(input: String): Int {
return input.split("\n\n").map { it.lines() }
.map { (packet, other) -> packet.mapToPacketData() to other.mapToPacketData() }
.mapIndexed { index, pair -> if (pair.first.compareTo(pair.second) < 1) index + 1 else 0 }
.sum()
... | 0 | Kotlin | 0 | 0 | 76d5eea8ff0c96392f49f450660220c07a264671 | 2,469 | advent-of-code-2022 | Apache License 2.0 |
advent-of-code-2022/src/Day09.kt | osipxd | 572,825,805 | false | {"Kotlin": 141640, "Shell": 4083, "Scala": 693} | import kotlin.math.absoluteValue
import kotlin.math.sign
fun main() {
val input = readInput("Day09")
"Part 1" {
val testInput = readInput("Day09_test1")
part1(testInput) shouldBe 13
answer(part1(input))
}
"Part 2" {
val testInput = readInput("Day09_test2")
part... | 0 | Kotlin | 0 | 5 | 6a67946122abb759fddf33dae408db662213a072 | 2,415 | advent-of-code | Apache License 2.0 |
src/day05/Day05.kt | Mini-Stren | 573,128,699 | false | null | package day05
import readInputLines
import java.util.*
fun main() {
val day = 5
fun part1(input: List<String>): String {
val cratesStacks = input.cratesStacks
val cratesMoves = input.cratesMoves
cratesMoves.forEach { (count, from, to) ->
repeat(count) {
v... | 0 | Kotlin | 0 | 0 | 40cb18c29089783c9b475ba23c0e4861d040e25a | 2,789 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/dvdmunckhof/aoc/event2022/Day16.kt | dvdmunckhof | 318,829,531 | false | {"Kotlin": 195848, "PowerShell": 1266} | package com.dvdmunckhof.aoc.event2022
import com.dvdmunckhof.aoc.common.BitSet
class Day16(private val input: List<String>) {
private val valves = parseInput()
private val possibleValves = valves.filter { it.flowRate != 0 }
private val distances = calculateDistances(valves)
fun solvePart1(): Int {
... | 0 | Kotlin | 0 | 0 | 025090211886c8520faa44b33460015b96578159 | 3,292 | advent-of-code | Apache License 2.0 |
src/y2021/Day04.kt | Yg0R2 | 433,731,745 | false | null | package y2021
import java.util.concurrent.atomic.AtomicBoolean
fun main() {
fun initializeBoards(input: List<String>) = input
.drop(2)
.windowed(5, 6)
.map { BingoBoard(it) }
fun part1(input: List<String>): Int {
val boards: List<BingoBoard> = initializeBoards(input)
... | 0 | Kotlin | 0 | 0 | d88df7529665b65617334d84b87762bd3ead1323 | 2,988 | advent-of-code | Apache License 2.0 |
codeforces/kotlinheroes2/g.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.kotlinheroes2
private fun solve() {
val n = readInt()
val flag = readInts()
val want = readInts()
val changed = flag.zip(want) { a, b -> a != b }
val nei = List(n) { mutableListOf<Int>() }
repeat(n - 1) {
val (a, b) = readInts().map { it - 1 }
nei[a].add(b)
nei[b].add(a)
}
val w = chan... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,544 | competitions | The Unlicense |
src/Day09.kt | armandmgt | 573,595,523 | false | {"Kotlin": 47774} | import kotlin.math.abs
import kotlin.math.sign
fun main() {
data class State(val headPos: Pair<Int, Int>, val tailNodes: List<Pair<Int, Int>>)
fun follow(head: Int, tail: Int, headOther: Int, tailOther: Int): Pair<Int, Int> {
// If tail is 2 squares away from head, move in direction of head
if... | 0 | Kotlin | 0 | 1 | 0d63a5974dd65a88e99a70e04243512a8f286145 | 3,527 | advent_of_code_2022 | Apache License 2.0 |
src/Day07.kt | Tomcat88 | 572,566,485 | false | {"Kotlin": 52372} | import java.util.Stack
import java.util.function.Predicate
fun main() {
val root = Dir("/")
val ditStack = Stack<Dir>().apply { add(root) }
fun part1() {
root.filterSize {
it <= 100000
}.sum().log("part1")
}
fun part2() {
val spaceLeft = 70000000 - root.size
... | 0 | Kotlin | 0 | 0 | 6d95882887128c322d46cbf975b283e4a985f74f | 1,989 | advent-of-code-2022 | Apache License 2.0 |
src/Day12.kt | ked4ma | 573,017,240 | false | {"Kotlin": 51348} | import java.util.ArrayDeque
/**
* [Day12](https://adventofcode.com/2022/day/12)
*/
fun main() {
fun toGrid(input: List<String>): Array<Array<Char>> = input.map {
it.toCharArray().toTypedArray()
}.toTypedArray()
fun bfs(
grid: Array<Array<Char>>,
start: Pair<Int, Int>,
... | 1 | Kotlin | 0 | 0 | 6d4794d75b33c4ca7e83e45a85823e828c833c62 | 3,542 | aoc-in-kotlin-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/year2021/Day03.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2021
private const val ONE = '1'
private const val ZERO = '0'
private fun part1(input: List<String>): Int {
val mostCommonBit = findMostCommonBit(input)
val gammaRate = Integer.valueOf(mostCommonBit, 2)
val leastCommonBit = reverse(mostCommonBit)
val epsilonRate = Integer.valueOf(leastCom... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 2,927 | advent-of-code | MIT License |
src/Day02.kt | ralstonba | 573,072,217 | false | {"Kotlin": 4128} | fun main() {
val mapping = mapOf(
"A" to RPSMove.ROCK,
"B" to RPSMove.PAPER,
"C" to RPSMove.SCISSORS,
"X" to RPSMove.ROCK,
"Y" to RPSMove.PAPER,
"Z" to RPSMove.SCISSORS
)
val beats = mapOf(
RPSMove.ROCK to RPSMove.SCISSORS,
RPSMove.PAPER to R... | 0 | Kotlin | 0 | 0 | 93a8ba96db519f4f3d42e2b4148614969faa79b1 | 1,489 | aoc-2022 | Apache License 2.0 |
src/Day11.kt | jordan-thirus | 573,476,470 | false | {"Kotlin": 41711} | fun main() {
fun processRound(monkeys: List<Monkey>, reduceWorryLevel: (Long) -> Long) {
for (monkey in monkeys) {
while (monkey.items.any()) {
monkey.throughput += monkey.items.size
for(item in monkey.items) {
val newWorryLevel = reduceWorryLe... | 0 | Kotlin | 0 | 0 | 59b0054fe4d3a9aecb1c9ccebd7d5daa7a98362e | 3,385 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | eps90 | 574,098,235 | false | {"Kotlin": 9738} | import java.security.InvalidParameterException
enum class FigureType(val score: Int) {
Rock(1),
Paper(2),
Scissors(3),
}
enum class MatchResult(val score: Int) {
Loss(0),
Draw(3),
Win(6);
fun opposite(): MatchResult {
return when (this) {
Loss -> Win
Win ->... | 0 | Kotlin | 0 | 0 | bbf58c512fddc0ef1112c3bee5e5c6d43f5aabc0 | 3,242 | advent-of-code-2022 | Apache License 2.0 |
src/Day12.kt | greg-burgoon | 573,074,283 | false | {"Kotlin": 120556} | fun main() {
class Node(elevation: Char) {
val elevation = elevation
var distance = Int.MAX_VALUE
var adjacentNodes = ArrayList<Node>()
fun canTraverseTo(other: Node): Boolean {
var currentElevation = this.elevation
if (this.elevation == 'S') {
... | 0 | Kotlin | 0 | 1 | 74f10b93d3bad72fa0fc276b503bfa9f01ac0e35 | 3,671 | aoc-kotlin | Apache License 2.0 |
src/Day19.kt | mikrise2 | 573,939,318 | false | {"Kotlin": 62406} | import java.util.*
import kotlin.math.ceil
data class Robot(
val oreGet: Int,
val clayGet: Int,
val obsidianGet: Int,
val geodeGet: Int,
val ore: Int,
val clay: Int,
val obsidian: Int
)
data class Plan(
val id: Int,
val robots: List<Robot>
)
data class State(
val remaining: In... | 0 | Kotlin | 0 | 0 | d5d180eaf367a93bc038abbc4dc3920c8cbbd3b8 | 4,369 | Advent-of-code | Apache License 2.0 |
src/Day01.kt | GreyWolf2020 | 573,580,087 | false | {"Kotlin": 32400} | import java.lang.Integer.max
fun main() {
fun part1(input: List<String>): Int {
val sumIndex = 0
val maxSumIndex = 1
val zeroCalorie = 0
return input.map {
it.toIntOrNull()
}.foldRight(intArrayOf(0, 0)) { calorieOrNull, acc ->
calorieOrNull ?.let { ca... | 0 | Kotlin | 0 | 0 | 498da8861d88f588bfef0831c26c458467564c59 | 2,097 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day02.kt | gsalinaslopez | 572,839,981 | false | {"Kotlin": 21439} | enum class Moves(val points: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3)
}
enum class Results(val points: Int) {
WIN(6),
DRAW(3),
LOSE(0)
}
val modesMap = mapOf(
"A" to Moves.ROCK, "X" to Moves.ROCK,
"B" to Moves.PAPER, "Y" to Moves.PAPER,
"C" to Moves.SCISSORS, "Z" to Moves.SCISSORS,
)
... | 0 | Kotlin | 0 | 0 | 041c7c3716bfdfdf4cc89975937fa297ea061830 | 2,457 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/day07/day07.kt | rolf-rosenbaum | 572,864,107 | false | {"Kotlin": 80772} | package day07
import readInput
private const val THRESHOLD_PART1 = 100000
private const val TOTAL_DISC_SIZE = 70000000
private const val SIZE_FOR_UPDATE = 30000000
data class Directory(
val name: String,
val files: MutableSet<Int>,
val dirs: MutableMap<String, Directory>,
val parent: Directory? = nul... | 0 | Kotlin | 0 | 2 | 59cd4265646e1a011d2a1b744c7b8b2afe482265 | 2,211 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | Loahrs | 574,175,046 | false | {"Kotlin": 7516} | fun main() {
fun part1(input: List<String>): Int {
return input.asSequence().map {
val (opponentMove, playerMove) = it.split(" ")
val opponentShape = getShape(opponentMove)
val playerShape = getShape(playerMove)
val outcome = calculateOutcome(opponentShape, p... | 0 | Kotlin | 0 | 0 | b1ff8a704695fc6ba8c32a227eafbada6ddc0d62 | 2,436 | aoc-2022-in-kotlin | Apache License 2.0 |
src/aoc2022/Day13.kt | Playacem | 573,606,418 | false | {"Kotlin": 44779} | package aoc2022
import utils.readInputText
object Day13 {
fun parseInput(text: String): List<List<String>> = text.split("\n\n").map { it.trim().split("\n") }
sealed class Structure : Comparable<Structure> {
data class AList(val list: List<Structure>) : Structure() {
override fun compareT... | 0 | Kotlin | 0 | 0 | 4ec3831b3d4f576e905076ff80aca035307ed522 | 3,968 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day11/Day11.kt | Avataw | 572,709,044 | false | {"Kotlin": 99761} | package day11
// 36:12
fun solveA(input: List<String>) = parseMonkeys(input).also {
repeat(20) { _ ->
it.forEach { m -> m.takeTurn(it) }
}
}.calcMonkeyBusiness()
//13:32
fun solveB(input: List<String>) = parseMonkeys(input).also {
val superModulo = it.map { monkey -> monkey.test.divisibleBy }.redu... | 0 | Kotlin | 2 | 0 | 769c4bf06ee5b9ad3220e92067d617f07519d2b7 | 4,933 | advent-of-code-2022 | Apache License 2.0 |
src/Day11.kt | dragere | 440,914,403 | false | {"Kotlin": 62581} | import kotlin.streams.toList
fun main() {
fun flash(field: MutableList<MutableList<Int>>, flashed: Array<Array<Boolean>>, pos: Pair<Int, Int>) {
val i = pos.first
val j = pos.second
if (field[i][j] <= 9 || flashed[i][j]) return
flashed[i][j] = true
for (m in -1..1) {
... | 0 | Kotlin | 0 | 0 | 3e33ab078f8f5413fa659ec6c169cd2f99d0b374 | 2,968 | advent_of_code21_kotlin | Apache License 2.0 |
src/main/kotlin/day5/main.kt | janneri | 572,969,955 | false | {"Kotlin": 99028} | package day5
import util.readTestInput
data class Crate(val symbol: Char, val stackNumber: Int)
data class Move(val count: Int, val fromStack: Int, val toStack: Int)
data class GameInput(val moves: List<Move>, val crates: List<Crate>, val stackCount: Int) {
companion object {
/*
Input looks s... | 0 | Kotlin | 0 | 0 | 1de6781b4d48852f4a6c44943cc25f9c864a4906 | 2,881 | advent-of-code-2022 | MIT License |
y2018/src/main/kotlin/adventofcode/y2018/Day22.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2018
import adventofcode.io.AdventSolution
import java.util.*
object Day22 : AdventSolution(2018, 22, "Mode Maze") {
override fun solvePartOne(input: String): Int {
val (depth, tx, ty) = parse(input)
val cave = buildMaze(depth, tx, ty)
cave[ty][tx] = 0
retu... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 3,638 | advent-of-code | MIT License |
src/Day03.kt | Reivax47 | 572,984,467 | false | {"Kotlin": 32685} | fun main() {
fun trouvelecommun(gauche: List<Char>, droite: List<Char>): MutableList<Char> {
val reponse = mutableListOf<Char>()
var index_gauche = 0
var index_droite = 0
while (index_gauche < gauche.size && index_droite < droite.size) {
if (gauche[index_gauche] == dr... | 0 | Kotlin | 0 | 0 | 0affd02997046d72f15d493a148f99f58f3b2fb9 | 2,156 | AD2022-01 | Apache License 2.0 |
src/Day12.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | fun main() {
data class Cell(var value: Char, val edges: MutableList<Int> = mutableListOf())
data class CellToVisit(val index: Int, val distance: Int)
data class Heightmap(var startIndex: Int, var endIndex: Int, val cells: MutableList<Cell> = mutableListOf())
fun buildHeightmap(input: List<String>): He... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 2,546 | aoc-2022 | Apache License 2.0 |
src/Day11.kt | ZiomaleQ | 573,349,910 | false | {"Kotlin": 49609} | import java.math.BigInteger
fun main() {
fun part1(input: List<String>): Long {
val monkeys = mutableListOf<Monkey>()
val num = magicNumber(input)
for (i in 0..input.size / 7) {
monkeys.add(Monkey.parse(input.subList(i * 7, ((i + 1) * 7) - 1)))
}
repeat(20) {
... | 0 | Kotlin | 0 | 0 | b8811a6a9c03e80224e4655013879ac8a90e69b5 | 3,964 | aoc-2022 | Apache License 2.0 |
src/day9/day9.kt | kacperhreniak | 572,835,614 | false | {"Kotlin": 85244} | package day9
import readInput
import kotlin.math.abs
private fun helper(input: List<String>, points: Array<Pair<Int, Int>>): Int {
fun createKey(point: Pair<Int, Int>): String = "${point.first},${point.second}"
val visited: MutableSet<String> = hashSetOf<String>().apply {
add(createKey(points.last()))... | 0 | Kotlin | 1 | 0 | 03368ffeffa7690677c3099ec84f1c512e2f96eb | 1,992 | aoc-2022 | Apache License 2.0 |
src/Day09.kt | Redstonecrafter0 | 571,787,306 | false | {"Kotlin": 19087} |
data class Knot(var x: Int = 1000, var y: Int = 1000)
fun main() {
val pullMap = buildList<List<Pair<Int, Int>>> {
this += listOf(1 to 1, 1 to 1, 0 to 1, -1 to 1, -1 to 1)
this += listOf(1 to 1, 0 to 0, 0 to 0, 0 to 0, -1 to 1)
this += listOf(1 to 0, 0 to 0, 0 to 0, 0 to 0, -1 to 0)
... | 0 | Kotlin | 0 | 0 | e5dbabe247457aabd6dd0f0eb2eb56f9e4c68858 | 2,512 | Advent-of-Code-2022 | Apache License 2.0 |
src/Day07.kt | xabgesagtx | 572,139,500 | false | {"Kotlin": 23192} | fun main() {
fun readDirectoryContent(input: List<String>): FSDir {
return input.fold(listOf<FSDir>()) { stack, line ->
when {
line.isLeaveCommand -> stack.dropLast(1)
line.isChangeDir -> {
val newDir = line.toDir()
stack.l... | 0 | Kotlin | 0 | 0 | 976d56bd723a7fc712074066949e03a770219b10 | 2,783 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day14/Day14.kt | alxgarcia | 435,549,527 | false | {"Kotlin": 91398} | package day14
import java.io.File
fun parseInput(lines: List<String>): Pair<String, Map<String, Char>> {
val initial = lines.first()
val insertions =
lines.drop(2).associate {
val (pattern, addition) = it.split(" -> ")
pattern to addition.first()
}
return initial to insertions
}
private fun... | 0 | Kotlin | 0 | 0 | d6b10093dc6f4a5fc21254f42146af04709f6e30 | 2,432 | advent-of-code-2021 | MIT License |
src/main/kotlin/aoc2021/Day04.kt | j4velin | 572,870,735 | false | {"Kotlin": 285016, "Python": 1446} | package aoc2021
import readInput
private const val BOARD_SIZE = 5
/**
* A bingo board.
* @see [createBoards]
*/
private class Board private constructor(data: List<String>) {
// speed up bingo checking by keeping the data twice: organized by rows & by columns
private val rows: Array<MutableSet<Int>> = (0 ... | 0 | Kotlin | 0 | 0 | f67b4d11ef6a02cba5b206aba340df1e9631b42b | 3,111 | adventOfCode | Apache License 2.0 |
src/main/kotlin/days/y2023/day06/Day06.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2023.day06
import util.InputReader
typealias PuzzleLine = String
typealias PuzzleInput = List<PuzzleLine>
class Day06(val input: PuzzleInput) {
val races = raceDurations(input).zip(raceDistances(input))
val longRace = parseLongRace(input)
fun partOne() = races.map { waysToWin(it.first, it.... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 1,885 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Day11.kt | makohn | 571,699,522 | false | {"Kotlin": 35992} |
fun main() {
val day = "11"
fun toOperation(input: String): (Long) -> Long {
val (x, op, y) = input.split(" ")
return { old ->
val a = if (x == "old") old else x.toLong()
val b = if (y == "old") old else y.toLong()
when (op) {
"+" -> a + b
... | 0 | Kotlin | 0 | 0 | 2734d9ea429b0099b32c8a4ce3343599b522b321 | 3,264 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/github/brpeterman/advent2022/ForestSurvey.kt | brpeterman | 573,059,778 | false | {"Kotlin": 53108} | package com.github.brpeterman.advent2022
class ForestSurvey(input: String) {
data class Coords(val row: Int, val column: Int)
data class TreeMap(val width: Int, val height: Int, val trees: Map<Coords, Int>)
enum class Offset(val rowOffset: Int, val colOffset: Int) {
NORTH(-1, 0),
SOUTH(1, 0... | 0 | Kotlin | 0 | 0 | 1407ca85490366645ae3ec86cfeeab25cbb4c585 | 2,747 | advent2022 | MIT License |
src/main/kotlin/Day13.kt | Ostkontentitan | 434,500,914 | false | {"Kotlin": 73563} | fun puzzleDayThirteenPartOne() {
val inputs = readInput(13)
val coordinates = extractCoordinates(inputs)
val instructions = extractInstructions(inputs)
val instruction = instructions.first() as Fold.X
val folded = foldLeft(coordinates, instruction.value)
println("Dots after first fold: ${folded... | 0 | Kotlin | 0 | 0 | e0e5022238747e4b934cac0f6235b92831ca8ac7 | 2,990 | advent-of-kotlin-2021 | Apache License 2.0 |
src/Day02.kt | andrikeev | 574,393,673 | false | {"Kotlin": 70541, "Python": 18310, "HTML": 5558} | fun main() {
fun part1(input: List<String>): Int {
val shapeScores = mapOf(
'X' to 1,
'Y' to 2,
'Z' to 3,
)
val roundScores = mapOf(
"A X" to 3,
"A Y" to 6,
"A Z" to 0,
"B X" to 0,
"B Y" to 3,
... | 0 | Kotlin | 0 | 1 | 1aedc6c61407a28e0abcad86e2fdfe0b41add139 | 1,466 | aoc-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.