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 | vjgarciag96 | 572,719,091 | false | {"Kotlin": 44399} | private data class DirectoryNode(
val name: String,
val parent: DirectoryNode?,
)
fun main() {
fun part1(input: List<String>): Int {
val visitedFiles = HashSet<String>()
val sizeOfDirectories = HashMap<DirectoryNode, Int>()
var currentDirectory: DirectoryNode? = null
input... | 0 | Kotlin | 0 | 0 | ee53877877b21166b8f7dc63c15cc929c8c20430 | 3,941 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | Olivki | 573,156,936 | false | {"Kotlin": 11297} | fun main() {
val charToPriority = (('a'..'z') + ('A'..'Z')).withIndex().associateBy({ it.value }, { it.index + 1 })
data class Item(val char: Char, val priority: Int = charToPriority.getValue(char))
data class Compartment(val text: String, val items: List<Item> = text.map(::Item))
data class Rucksack... | 0 | Kotlin | 0 | 1 | 51c408f62589eada3d8454740c9f6fc378e2d09b | 2,771 | aoc-2022 | Apache License 2.0 |
src/day15/Day15.kt | ayukatawago | 572,742,437 | false | {"Kotlin": 58880} | package day15
import readInput
import kotlin.math.abs
fun main() {
val testInput = readInput("day15/test")
val regex = """Sensor at x=(-*\d+), y=(-*\d+): closest beacon is at x=(-*\d+), y=(-*\d+)""".toRegex()
val inputs = testInput.mapNotNull {
val result = regex.matchEntire(it) ?: return@mapNotN... | 0 | Kotlin | 0 | 0 | 923f08f3de3cdd7baae3cb19b5e9cf3e46745b51 | 3,756 | advent-of-code-2022 | Apache License 2.0 |
aoc-2023/src/main/kotlin/aoc/aoc7.kts | triathematician | 576,590,518 | false | {"Kotlin": 615974} | import aoc.AocParser.Companion.parselines
import aoc.*
import aoc.util.getDayInput
import kotlin.math.pow
val testInput = """
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483
""".parselines
class Hand(val str: String) : Comparable<Hand> {
override fun toString() = str
val counts = str.toList().groupBy { it }... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 3,841 | advent-of-code | Apache License 2.0 |
advent-of-code-2023/src/main/kotlin/eu/janvdb/aoc2023/day25/day25.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2023.day25
import eu.janvdb.aocutil.kotlin.readLines
import java.util.*
//const val FILENAME = "input25-test.txt"
const val FILENAME = "input25.txt"
fun main() {
val diagram = Diagram.parse(readLines(2023, FILENAME))
val firstConnection = diagram.getMostUsedConnection()
val diagram2 = diagra... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 3,938 | advent-of-code | Apache License 2.0 |
src/Day21_2.kt | michaelYuenAE | 573,094,416 | false | {"Kotlin": 74685} |
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
class Day21_2() {
private val monkeys = readInput("day21_input").map { Monkey.from(it) }.associateBy { it.id }.toMutableMap()
fun solve1(): Long = monkeys[Monkey.ROOT]?.yell(monkeys)!!.toLong()
fun solve2(): Long {
var max... | 0 | Kotlin | 0 | 0 | ee521263dee60dd3462bea9302476c456bfebdf8 | 2,747 | advent22 | Apache License 2.0 |
src/day05/Day05.kt | lpleo | 572,702,403 | false | {"Kotlin": 30960} | package day05
import readInput
class Command constructor(val quantity: Int, val source: Int, val destination: Int) {
}
fun main() {
fun move1(piles: MutableList<ArrayDeque<Char>>, command: Command): MutableList<ArrayDeque<Char>> {
val pileFrom = piles[command.source - 1]
val pileTo = piles[comm... | 0 | Kotlin | 0 | 0 | 115aba36c004bf1a759b695445451d8569178269 | 3,082 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | azarovalex | 573,931,704 | false | {"Kotlin": 4391} | enum class Move {
ROCK, PAPER, SCISSORS;
val points: Int
get() = when (this) {
ROCK -> 1
PAPER -> 2
SCISSORS -> 3
}
companion object {
fun fromCharacter(char: String): Move {
return when (char) {
"A", "X" -> ROCK
... | 0 | Kotlin | 0 | 0 | 48578aeed4250987d4ee339d801f8d5e6577b55b | 2,166 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/codes/jakob/aoc/solution/Day05.kt | The-Self-Taught-Software-Engineer | 433,875,929 | false | {"Kotlin": 56277} | package codes.jakob.aoc.solution
import codes.jakob.aoc.solution.Day05.Point.Companion.fromCommaSeparated
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.math.sqrt
object Day05 : Solution() {
private const val CONNECTOR_ARROW = " -> "
override fun solvePart1(input: S... | 0 | Kotlin | 0 | 6 | d4cfb3479bf47192b6ddb9a76b0fe8aa10c0e46c | 2,577 | advent-of-code-2021 | MIT License |
src/Day02.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} | fun main(){
// X, A = Rock
// Y, B = Paper
// Z, C = Scissors
val points = mapOf("A" to 1, "X" to 1, "B" to 2, "Y" to 2, "C" to 3, "Z" to 3)
fun part2(input: List<String>): Int{
val results = mapOf(
"X" to mapOf("A" to 3,"B" to 1,"C" to 2),
"Z" to mapOf("A" to 2,"B"... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 1,357 | aoc-22-kotlin | Apache License 2.0 |
src/aoc2018/kot/Day12.kt | Tandrial | 47,354,790 | false | null | package aoc2018.kot
import java.io.File
object Day12 {
fun partOne(input: List<String>): Int {
val (state, rules) = parse(input)
return (0 until 20).fold(state) { s, _ -> nextGen(s, rules) }.sum()
}
fun partTwo(input: List<String>): Long {
val (state, rules) = parse(input)
var currentSum = stat... | 0 | Kotlin | 1 | 1 | 9294b2cbbb13944d586449f6a20d49f03391991e | 1,787 | Advent_of_Code | MIT License |
src/main/kotlin/com/nibado/projects/advent/y2020/Day20.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2020
import com.nibado.projects.advent.*
object Day20 : Day {
private val values = resourceStrings(2020, 20).map { tile ->
tile.split("\n")
.let { Tile(it.first().replace("[^0-9]".toRegex(), "").toInt(), Grid(it.drop(1))) }
}
private val solutio... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 4,957 | adventofcode | MIT License |
src/day23/Day23.kt | Volifter | 572,720,551 | false | {"Kotlin": 65483} | package day23
import utils.*
val DIRECTIONS = listOf(
(-1..1).map { Coords(it, -1) },
(-1..1).map { Coords(it, 1) },
(-1..1).map { Coords(-1, it) },
(-1..1).map { Coords(1, it) }
)
data class Coords(var x: Int, var y: Int) {
operator fun plus(other: Coords): Coords = Coords(x + other.x, y + other... | 0 | Kotlin | 0 | 0 | c2c386844c09087c3eac4b66ee675d0a95bc8ccc | 3,141 | AOC-2022-Kotlin | Apache License 2.0 |
src/Day07.kt | xNakero | 572,621,673 | false | {"Kotlin": 23869} | object Day07 {
private const val MAX_SIZE = 100_000
private const val HARD_DRIVE_SIZE = 70_000_000
private const val SPACE_NEEDED = 30_000_000
fun part1() = getRoot()
.getChildrenSizes()
.filter { it <= MAX_SIZE }
.sum()
fun part2() = getRoot()
.getChildrenSizes()
... | 0 | Kotlin | 0 | 0 | c3eff4f4c52ded907f2af6352dd7b3532a2da8c5 | 2,955 | advent-of-code-2022 | Apache License 2.0 |
src/Day07.kt | andrewgadion | 572,927,267 | false | {"Kotlin": 16973} | abstract class Entry(val name: String) { abstract val size: Long }
class File(name: String, override val size: Long) : Entry(name)
class Dir(name: String, val parent: Dir?) : Entry(name) {
private val entries = mutableListOf<Entry>()
override val size: Long get() = entries.sumOf(Entry::size)
fun addEntry(en... | 0 | Kotlin | 0 | 0 | 4d091e2da5d45a786aee4721624ddcae681664c9 | 2,220 | advent-of-code-2022 | Apache License 2.0 |
src/Day08.kt | Tomcat88 | 572,566,485 | false | {"Kotlin": 52372} |
fun main() {
fun part1(input: List<List<Int>>) {
input.withIndex().sumOf { (rowIdx, row) ->
row.withIndex().count { (colIdx, col) ->
row.splitOnIndex(colIdx).any { it.all { col > it } } ||
input.column(colIdx).splitOnIndex(rowIdx).any { it.all { col > it } }
... | 0 | Kotlin | 0 | 0 | 6d95882887128c322d46cbf975b283e4a985f74f | 1,226 | advent-of-code-2022 | Apache License 2.0 |
src/Day07.kt | FuKe | 433,722,611 | false | {"Kotlin": 19825} | import kotlin.math.abs
fun main() {
test()
val puzzleInput: List<Int> = readInput("Day07.txt")[0]
.split(",")
.map { it.toInt() }
val aResult: Int = aSolver(puzzleInput)
println("Part one result: $aResult")
val bResult: Int = bSolver(puzzleInput)
println("Part two result: $bR... | 0 | Kotlin | 0 | 0 | 1cfe66aedd83ea7df8a2bc26c453df257f349b0e | 1,599 | advent-of-code-2021 | Apache License 2.0 |
src/year2023/day21/Day21.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2023.day21
import check
import readInput
fun main() {
val testInput = readInput("2023", "Day21_test")
check(part1(testInput, 6), 16)
val input = readInput("2023", "Day21")
println(part1(input, 64))
println(part2(input))
}
private fun part1(input: List<String>, steps: Int) = input.par... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 3,128 | AdventOfCode | Apache License 2.0 |
src/day05/Day05.kt | RegBl | 573,086,350 | false | {"Kotlin": 11359} | package day05
import readInput
import splitByEmptyLine
fun main() {
val (stacksRaw, instructionsRaw) =
readInput("\\day05\\Day05")
.splitByEmptyLine()
val stacks = stacksRaw.map { it.chunked(4) }
.transpose()
.map { it.dropLast(1) }
.map { stack ->
stac... | 0 | Kotlin | 0 | 0 | bd45eb4378d057267823dcc72ad958492f7056ff | 2,467 | aoc-2022 | Apache License 2.0 |
src/day11/Day11.kt | iulianpopescu | 572,832,973 | false | {"Kotlin": 30777} | package day11
import readInput
private const val DAY = "11"
private const val DAY_TEST = "day${DAY}/Day${DAY}_test"
private const val DAY_INPUT = "day${DAY}/Day${DAY}"
fun main() {
fun List<String>.parseMonkeys() = this
.chunked(7)
.map { it.parseMonkey() }
fun List<Monkey>.computeMostActive... | 0 | Kotlin | 0 | 0 | 4ff5afb730d8bc074eb57650521a03961f86bc95 | 2,934 | AOC2022 | Apache License 2.0 |
src/questions/TotalHammingDistance.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
/**
* The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
* Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.
... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,903 | algorithms | MIT License |
src/main/kotlin/Day05.kt | rgawrys | 572,698,359 | false | {"Kotlin": 20855} | import utils.readInput
fun main() {
fun part1(input: List<String>): String = input
.executeRearrangementProcedure(canPickUpMultipleCrates = false)
.lastValuesAsString()
fun part2(input: List<String>): String = input
.executeRearrangementProcedure(canPickUpMultipleCrates = true)
... | 0 | Kotlin | 0 | 0 | 5102fab140d7194bc73701a6090702f2d46da5b4 | 3,037 | advent-of-code-2022 | Apache License 2.0 |
src/year2023/02/Day02.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2023.`02`
import readInput
import utils.printlnDebug
private const val CURRENT_DAY = "02"
private val initialGameCount = Round(
red = 12,
green = 13,
blue = 14,
)
private data class Game(
val index: Int,
val listOfGames: List<Round>,
)
private data class Round(
val blue: Int,
... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 2,787 | KotlinAdventOfCode | Apache License 2.0 |
src/Day08.kt | SeanDijk | 575,314,390 | false | {"Kotlin": 29164} | enum class Visible {
YES, NO, UNKNOWN
}
fun main() {
// top left is (0,0)
data class Coordinate(val x: Int, val y: Int)
data class Tree(val height: Int, var visible: Visible = Visible.UNKNOWN) {
override fun toString() = "$height${visible.toString().first()}"
}
data class Field(val t... | 0 | Kotlin | 0 | 0 | 363747c25efb002fe118e362fb0c7fecb02e3708 | 4,107 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/adventofcode2023/day8/day8.kt | dzkoirn | 725,682,258 | false | {"Kotlin": 133478} | package adventofcode2023.day8
import adventofcode2023.readInput
import kotlin.math.abs
import kotlin.time.measureTime
fun main() {
println("Day 8")
val input = readInput("day8")
val puzzle1Time = measureTime {
val (commands, graph) = parseInput(input)
println("Puzzle 1: ${puzzle1(commands.... | 0 | Kotlin | 0 | 0 | 8f248fcdcd84176ab0875969822b3f2b02d8dea6 | 2,858 | adventofcode2023 | MIT License |
src/Day02.kt | ds411 | 573,543,582 | false | {"Kotlin": 16415} | fun main() {
val moveValue = mapOf(
"X" to 1,
"Y" to 2,
"Z" to 3,
"A" to 1,
"B" to 2,
"C" to 3
)
val comboValue = mapOf(
Pair("A", "X") to 3,
Pair("A", "Y") to 6,
Pair("A", "Z") to 0,
Pair("B", "X") to 0,
Pair("B", "Y"... | 0 | Kotlin | 0 | 0 | 6f60b8e23ee80b46e7e1262723960af14670d482 | 1,999 | advent-of-code-2022 | Apache License 2.0 |
advent-of-code/src/main/kotlin/com/akikanellis/adventofcode/year2022/Day12.kt | akikanellis | 600,872,090 | false | {"Kotlin": 142932, "Just": 977} | package com.akikanellis.adventofcode.year2022
import com.akikanellis.adventofcode.year2022.utils.Point
object Day12 {
fun shortestPathSteps(input: String, ascending: Boolean): Int {
val squares = squares(input)
val startSquare = squares.single { if (ascending) it.startSquare else it.endSquare }
... | 8 | Kotlin | 0 | 0 | 036cbcb79d4dac96df2e478938de862a20549dce | 3,888 | advent-of-code | MIT License |
src/year2021/day03/Day03.kt | kingdongus | 573,014,376 | false | {"Kotlin": 100767} | package year2021.day03
import readInputFileByYearAndDay
import readTestFileByYearAndDay
fun main() {
/**
* Treats the input as list of binary numbers of equal length l, and returns a map that, for each position
* 0...l-1, records how many bits are set (== '1') across all those numbers
*/
fun c... | 0 | Kotlin | 0 | 0 | aa8da2591310beb4a0d2eef81ad2417ff0341384 | 2,437 | advent-of-code-kotlin | Apache License 2.0 |
aoc-2023/src/main/kotlin/aoc/aoc4.kts | triathematician | 576,590,518 | false | {"Kotlin": 615974} | import aoc.AocParser.Companion.parselines
import aoc.*
import aoc.util.getDayInput
import kotlin.math.pow
val testInput = """
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 ... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 1,881 | advent-of-code | Apache License 2.0 |
src/Day03.kt | patrickwilmes | 572,922,721 | false | {"Kotlin": 6337} | data class Rucksack(
val firstCompartment: Set<Char>,
val secondCompartment: Set<Char>,
) {
fun getItemsLocatedInBothCompartments(): Set<Char> =
firstCompartment.intersect(secondCompartment).toSet()
}
val encodedLowerCaseLetters = run {
var i = 0
(97..122).associate {
i += 1
... | 0 | Kotlin | 0 | 0 | 162c8f1b814805285e10ea4e3ab944c21e8be4c5 | 1,643 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/anahoret/pathfinding/MarkingWayOnMap.kt | mikhalchenko-alexander | 159,798,469 | false | null | package com.anahoret.pathfinding
import java.lang.IllegalArgumentException
import java.util.*
fun addPath(map: String): String = Graph.getMapWithPath(map)
object Graph {
private const val STRAIGHT_LENGTH = 2
private const val DIAGONAL_LENGTH = 3
fun getMapWithPath(map: String): String {
val (no... | 0 | Kotlin | 0 | 0 | c483adee6e1d0e2e3f2d7b50a1cab89eff2f5cd0 | 4,094 | advent-of-kotlin-2018-week1 | Apache License 2.0 |
advent-of-code-2023/src/main/kotlin/eu/janvdb/aoc2023/day22/day22.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2023.day22
import eu.janvdb.aocutil.kotlin.point3d.Point3D
import eu.janvdb.aocutil.kotlin.readLines
import kotlin.math.max
import kotlin.math.min
//const val FILENAME = "input22-test.txt"
const val FILENAME = "input22.txt"
fun main() {
val bricks = readLines(2023, FILENAME).mapIndexed { index,... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 3,250 | advent-of-code | Apache License 2.0 |
src/Day13.kt | cypressious | 572,898,685 | false | {"Kotlin": 77610} | sealed class PacketData : Comparable<PacketData> {
override fun compareTo(other: PacketData): Int {
if (this is PacketInt && other is PacketInt) {
return this.value.compareTo(other.value)
}
if (this is PacketList && other is PacketList) {
for ((l, r) in this.values.z... | 0 | Kotlin | 0 | 1 | 7b4c3ee33efdb5850cca24f1baa7e7df887b019a | 2,841 | AdventOfCode2022 | Apache License 2.0 |
2015/Day14/src/main/kotlin/Main.kt | mcrispim | 658,165,735 | false | null | import java.io.File
data class Reindeer(val name: String, val speed: Int, val flyTime: Int, val restTime: Int)
fun parseReindeers(input: List<String>): List<Reindeer> {
//
// Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds.
//
val reinders = mutableListOf<Reindeer>()
val p... | 0 | Kotlin | 0 | 0 | 2f4be35e78a8a56fd1e078858f4965886dfcd7fd | 3,336 | AdventOfCode | MIT License |
src/day05/Day05.kt | pnavais | 727,416,570 | false | {"Kotlin": 17859} | package day05
import readInput
import kotlin.math.min
class MapType {
private val ranges = mutableListOf<MapRange>()
fun addRange(mapRange: MapRange) = ranges.add(mapRange)
fun translate(sourceIndex: Long) : Long {
var targetIndex: Long? = sourceIndex
for (r in ranges) {
val ... | 0 | Kotlin | 0 | 0 | f5b1f7ac50d5c0c896d00af83e94a423e984a6b1 | 2,666 | advent-of-code-2k3 | Apache License 2.0 |
src/main/kotlin/day15.kt | tobiasae | 434,034,540 | false | {"Kotlin": 72901} | import kotlin.comparisons.compareBy
import java.util.PriorityQueue
class Day15 : Solvable("15") {
override fun solveA(input: List<String>): String {
val grid = mutableListOf<List<Int>>()
input.forEach { grid.add(it.map(Char::toInt).map { it - 48 }) }
return dijkstra(grid).toString()
}
... | 0 | Kotlin | 0 | 0 | 16233aa7c4820db072f35e7b08213d0bd3a5be69 | 1,997 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/be/seppevolkaerts/day3/Day3.kt | Cybermaxke | 727,453,020 | false | {"Kotlin": 35118} | package be.seppevolkaerts.day3
class Row(
val partNumbers: List<PartNumber>,
val symbols: List<Symbol>,
)
class PartNumber(
val number: Int,
val range: IntRange,
var adjacentSymbols: MutableList<Symbol> = mutableListOf(),
)
class Symbol(
val pos: Int,
val symbol: Char,
var adjacentNumbers: MutableLis... | 0 | Kotlin | 0 | 1 | 56ed086f8493b9f5ff1b688e2f128c69e3e1962c | 2,267 | advent-2023 | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2021/Day08.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2021
import se.saidaspen.aoc.util.*
fun main() = Day08.run()
object Day08 : Day(2021, 8) {
private var normalDigits = mapOf(
"abcefg" to 0,
"cf" to 1,
"acdeg" to 2,
"acdfg" to 3,
"bcdf" to 4,
"abdfg" to 5,
"abdefg" to 6,
... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,705 | adventofkotlin | MIT License |
src/Day11.kt | dustinlewis | 572,792,391 | false | {"Kotlin": 29162} | fun main() {
fun part1(input: List<String>): Long {
return parseMonkeys(input)
.executeRounds(20) { value -> value / 3L }
.getMonkeyBusinessLevel()
}
fun part2(input: List<String>): Long {
val monkeys = parseMonkeys(input)
val commonMultiple: Int = monkeys
... | 0 | Kotlin | 0 | 0 | c8d1c9f374c2013c49b449f41c7ee60c64ef6cff | 3,610 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day09/Day09.kt | gr4cza | 572,863,297 | false | {"Kotlin": 93944} | package day09
import Direction
import Position
import readInput
import kotlin.math.abs
fun main() {
fun parseMoves(input: List<String>) = input.map {
val (dir, dist) = it.split(" ")
Move(Direction.valueOf(dir), dist.toInt())
}
fun distY(tail: Position, head: Position): Int {
retur... | 0 | Kotlin | 0 | 0 | ceca4b99e562b4d8d3179c0a4b3856800fc6fe27 | 2,937 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day11.kt | MarkRunWu | 573,656,261 | false | {"Kotlin": 25971} | data class Monkey(
val items: ArrayList<UInt>,
val operation: (UInt) -> UInt,
val test: (UInt) -> Int,
var inspectItemCount: UInt = 0u
) {
companion object {
fun parse(texts: List<String>): Monkey {
if (texts[0].startsWith("Monkey")) {
val items = ArrayList<UInt>(... | 0 | Kotlin | 0 | 0 | ced885dcd6b32e8d3c89a646dbdcf50b5665ba65 | 3,165 | AOC-2022 | Apache License 2.0 |
src/Day03.kt | MartinsCode | 572,817,581 | false | {"Kotlin": 77324} | fun main() {
fun prioritize(a: Char): Int {
return when (a) {
in 'a'..'z' -> a.code - 'a'.code + 1
in 'A'..'Z' -> a.code - 'A'.code + 27
else -> 0
}
}
fun part1(input: List<String>): Int {
var sum = 0
input.forEach {
val compar... | 0 | Kotlin | 0 | 0 | 1aedb69d80ae13553b913635fbf1df49c5ad58bd | 1,447 | AoC-2022-12-01 | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2021/day14/day14.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2021.day14
import biz.koziolek.adventofcode.*
import java.util.*
fun main() {
val inputFile = findInput(object {})
val lines = inputFile.bufferedReader().readLines()
val polymerTemplate = parsePolymerTemplate(lines)
val insertionRules = parsePolymerInsertionRules... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 3,632 | advent-of-code | MIT License |
src/Day03.kt | makobernal | 573,037,099 | false | {"Kotlin": 16467} | fun main() {
val ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
data class Compartment(val content:String)
data class Rucksack(val left:Compartment, val right:Compartment)
fun mapToRucksacks(input: List<String>) =
input.map { it.chunked(it.length / 2) }.map { Rucksack(Compar... | 0 | Kotlin | 0 | 0 | 63841809f7932901e97465b2dcceb7cec10773b9 | 1,609 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day8/main.kt | janneri | 572,969,955 | false | {"Kotlin": 99028} | package day8
import day8.Direction.*
import util.readTestInput
import java.lang.Integer.max
enum class Direction(val dx: Int, val dy: Int) {
LEFT(-1, 0), RIGHT(1, 0), UP(0, -1), DOWN(0, 1)
}
data class Coord(val x: Int, val y: Int) {
fun move(direction: Direction, amount: Int = 1) =
Coord(x + amount ... | 0 | Kotlin | 0 | 0 | 1de6781b4d48852f4a6c44943cc25f9c864a4906 | 3,042 | advent-of-code-2022 | MIT License |
src/main/kotlin/adventofcode2023/day11/day11.kt | dzkoirn | 725,682,258 | false | {"Kotlin": 133478} | package adventofcode2023.day11
import adventofcode2023.Point
import adventofcode2023.readInput
import kotlin.math.abs
import kotlin.time.measureTime
fun main() {
println("Day 11")
val input = readInput("day11")
val puzzle1Duration = measureTime {
println("Puzzle 1 ${puzzle1(input)}")
}
pri... | 0 | Kotlin | 0 | 0 | 8f248fcdcd84176ab0875969822b3f2b02d8dea6 | 2,980 | adventofcode2023 | MIT License |
src/main/kotlin/Day13.kt | N-Silbernagel | 573,145,327 | false | {"Kotlin": 118156} | import java.util.TreeSet
fun main() {
val input = readFileAsList("Day13")
println(Day13.part1(input))
println(Day13.part2(input))
}
object Day13 {
private fun makePairs(input: List<String>): List<Pair<Packet, Packet>> {
return input.chunked(3)
.map { (left, right) -> Packet.from(le... | 0 | Kotlin | 0 | 0 | b0d61ba950a4278a69ac1751d33bdc1263233d81 | 3,281 | advent-of-code-2022 | Apache License 2.0 |
src/Day13.kt | AxelUser | 572,845,434 | false | {"Kotlin": 29744} | sealed interface Day13Node : Comparable<Day13Node> {
override operator fun compareTo(other: Day13Node): Int
@JvmInline
value class NumberNode(val value: Int) : Day13Node {
override fun compareTo(other: Day13Node): Int {
return when (other) {
is NumberNode -> value.compa... | 0 | Kotlin | 0 | 1 | 042e559f80b33694afba08b8de320a7072e18c4e | 2,830 | aoc-2022 | Apache License 2.0 |
src/Day07.kt | RogozhinRoman | 572,915,906 | false | {"Kotlin": 28985} | import java.lang.Long.min
fun main() {
fun getNewDirectory(target: String, currentNode: Node?, root: Node): Node {
return when (target) {
".." -> currentNode!!.parent!!
"/" -> root
else -> currentNode!!.children.single { it.name == target }
}
}
fun fillT... | 0 | Kotlin | 0 | 1 | 6375cf6275f6d78661e9d4baed84d1db8c1025de | 3,427 | AoC2022 | Apache License 2.0 |
day7/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 6 -----")
val puzzleInput = getPuzzleInput()
val games = parseGames(puzzleInput, withJokers = false)
val rankedGames = rankGames(games)
println("Task 1: Total winnings: ${getTotalWinnings(rankedGames)}... | 0 | Kotlin | 0 | 1 | de51fd9222f5438efe9a2c45e5edcb88fd9f2232 | 4,843 | aoc-2023-kotlin | The Unlicense |
src/year_2021/day_03/Day03.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2021.day_03
import readInput
object Day03 {
/**
* @return gamma * epsilon
*/
fun solutionOne(reports: List<String>): Int {
val gammaText = calculateGammaBinary(reports)
val epsilonText = calculateEpsilonBinary(reports)
val gamma = Integer.parseInt(gammaText, 2)... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 2,971 | advent_of_code | Apache License 2.0 |
src/Day12.kt | MatthiasDruwe | 571,730,990 | false | {"Kotlin": 47864} | import kotlin.math.min
fun main() {
fun shortestPath(nodesArray: List<List<Node>>, startpoint: Char): Long {
val nodes = nodesArray.flatten().toMutableList()
val nodesDone = MutableList(0) { Node(0, 0, '0') }
val nodeS = nodes.first { it.value == startpoint }
nodeS.cost = 0
... | 0 | Kotlin | 0 | 0 | f35f01cea5075cfe7b4a1ead9b6480ffa57b4989 | 4,210 | Advent-of-code-2022 | Apache License 2.0 |
gcj/y2020/kickstart_d/d.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2020.kickstart_d
private fun solve(): String {
val (n, q) = readInts()
val d = readInts().toIntArray()
val maxD = d.maxOrNull()!!
val st = SparseTable(d)
fun canWalk(s: Int, t: Int): Pair<Int, Int> {
var low = s
var high = n
while (low + 1 < high) {
val mid = (low + high) / 2
val maxDoor... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 2,196 | competitions | The Unlicense |
advent-of-code-2023/src/main/kotlin/eu/janvdb/aoc2023/day17/day17.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2023.day17
import eu.janvdb.aocutil.kotlin.ShortestPathMove
import eu.janvdb.aocutil.kotlin.findShortestPath
import eu.janvdb.aocutil.kotlin.point2d.Direction
import eu.janvdb.aocutil.kotlin.point2d.Point2D
import eu.janvdb.aocutil.kotlin.readLines
import kotlin.math.max
import kotlin.math.min
//... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 3,375 | advent-of-code | Apache License 2.0 |
src/day02/Day02_elaborate.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day02
import day02.Outcome.*
import day02.Gesture.*
import readLines
enum class Gesture(val points: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3)
}
fun Gesture.beats(): Gesture {
return when (this) {
ROCK -> SCISSORS
PAPER -> ROCK
SCISSORS -> PAPER
}
}
fun Gesture.beatenB... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 2,212 | aoc2022 | Apache License 2.0 |
src/Day03.kt | ajmfulcher | 573,611,837 | false | {"Kotlin": 24722} | fun main() {
val alphabetMap by lazy {
val alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray()
val asMap = hashMapOf<Char, Int>()
alphabet.forEachIndexed { idx, item ->
asMap.put(item, idx + 1)
}
asMap
}
fun commonItems(sack: String): Set<Char> {
... | 0 | Kotlin | 0 | 0 | 981f6014b09e347241e64ba85e0c2c96de78ef8a | 1,649 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day24.kt | catcutecat | 572,816,768 | false | {"Kotlin": 53001} | import kotlin.system.measureTimeMillis
fun main() {
measureTimeMillis {
Day24.run {
solve1(18) // 277
solve2(54) // 877
}
}.let { println("Total: $it ms") }
}
object Day24 : Day.LineInput<Day24.Data, Int>("24") {
class Data(val blizzards: Array<Array<Direction?>>, ... | 0 | Kotlin | 0 | 2 | fd771ff0fddeb9dcd1f04611559c7f87ac048721 | 3,078 | AdventOfCode2022 | Apache License 2.0 |
2022/src/main/kotlin/day11_imp.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.cut
fun main() {
Day11Imp.run()
}
object Day11Imp : Solution<List<Day11Imp.Monkey>>() {
override val name = "day11"
override val parser = Parser { input ->
input.split("\n\n").map { monkeyStr ->
val monkeyLines = monkeyStr.split("\n")
val i... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,980 | aoc_kotlin | MIT License |
src/Day02.kt | rafael-ribeiro1 | 572,657,838 | false | {"Kotlin": 15675} | fun main() {
fun part1(input: List<String>): Int {
return input.gameRounds { GameRound.StrategyGuide1(it[0], it[1]) }
.sumOf { it.calculateScore() }
}
fun part2(input: List<String>): Int {
return input.gameRounds { GameRound.StrategyGuide2(it[0], it[1]) }
.sumOf { it... | 0 | Kotlin | 0 | 0 | 5cae94a637567e8a1e911316e2adcc1b2a1ee4af | 2,499 | aoc-kotlin-2022 | Apache License 2.0 |
src/Day02.kt | jvmusin | 572,685,421 | false | {"Kotlin": 86453} | import kotlin.math.abs
fun main() {
val cost = mapOf(
"X" to 1,
"Y" to 2,
"Z" to 3,
"A" to 1,
"B" to 2,
"C" to 3
)
fun outcome(me: Int, he: Int): Int {
return when {
me == he -> 3
abs(me - he) == 1 -> {
if (me... | 1 | Kotlin | 0 | 0 | 4dd83724103617aa0e77eb145744bc3e8c988959 | 1,685 | advent-of-code-2022 | Apache License 2.0 |
src/year2022/day08/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2022.day08
import utils.Point
import utils.coordinates
import utils.get
import io.kotest.matchers.shouldBe
import utils.readInput
fun main() {
val testInput = readInput("08", "test_input").map { it.toList() }
val realInput = readInput("08", "input").map { it.toList() }
allVisibilityPathSequen... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 2,663 | Advent-of-Code | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2022/2022-02.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2022
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
fun main() {
val input = readInputLines(2022, "02-input")
val testInput1 = readInputLines(2022, "02-test1")
println("Part1:")
part1(testInput1).print... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,480 | advent-of-code | MIT License |
code-sample-kotlin/algorithms/src/main/kotlin/com/codesample/leetcode/medium/621_taskScheduler.kt | aquatir | 76,377,920 | false | {"Java": 674809, "Python": 143889, "Kotlin": 112192, "Haskell": 57852, "Elixir": 33284, "TeX": 20611, "Scala": 17065, "Dockerfile": 6314, "HTML": 4714, "Shell": 387, "Batchfile": 316, "Erlang": 269, "CSS": 97} | package com.codesample.leetcode.medium
import java.util.*
/**
* 621. Task Scheduler https://leetcode.com/problems/task-scheduler/
*
* Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one u... | 1 | Java | 3 | 6 | eac3328ecd1c434b1e9aae2cdbec05a44fad4430 | 3,501 | code-samples | MIT License |
src/Day15/Day15.kt | martin3398 | 436,014,815 | false | {"Kotlin": 63436, "Python": 5921} | import java.util.*
class Node(val x: Int, val y: Int, val dist: Int) : Comparable<Node> {
override fun compareTo(other: Node): Int {
return this.dist - other.dist
}
override fun toString(): String {
return "($x, $y, $dist)"
}
}
fun main() {
fun pad(input: Array<Array<Int>>): Array... | 0 | Kotlin | 0 | 0 | 085b1f2995e13233ade9cbde9cd506cafe64e1b5 | 2,730 | advent-of-code-2021 | Apache License 2.0 |
src/Day02.kt | peterphmikkelsen | 573,069,935 | false | {"Kotlin": 7834} | fun main() {
fun part1(input: List<String>): Int {
var sum = 0
for (round in input) {
val (opponent, us) = round.split(" ")
sum += when(whoWins(opponent, us)) {
true -> if (us == "X") 7 else if (us == "Y") 8 else 9
false -> if (us == "X") 1 els... | 0 | Kotlin | 0 | 0 | 374c421ff8d867a0bdb7e8da2980217c3455ecfd | 1,634 | aoc-2022 | Apache License 2.0 |
src/Day25.kt | schoi80 | 726,076,340 | false | {"Kotlin": 83778} | import Day25.part1
import Day25.part2
import java.util.LinkedList
typealias Edge = Pair<String, String>
object Day25 {
class Graph {
val adjacencyList: MutableMap<String, MutableList<String>> = mutableMapOf()
fun addEdge(e: Edge) {
adjacencyList.getOrPut(e.first) { mutableListOf() }.a... | 0 | Kotlin | 0 | 0 | ee9fb20d0ed2471496185b6f5f2ee665803b7393 | 3,623 | aoc-2023 | Apache License 2.0 |
src/Day07.kt | jamie23 | 573,156,415 | false | {"Kotlin": 19195} | import kotlin.IllegalArgumentException
import kotlin.math.min
fun main() {
var current = 0
var p1Results = 0
var dirToDelete = Integer.MAX_VALUE
fun generateFileSystem(node: Node, commands: List<Command>) {
while (current < commands.size) {
val command = commands[current]
... | 0 | Kotlin | 0 | 0 | cfd08064654baabea03f8bf31c3133214827289c | 2,344 | Aoc22 | Apache License 2.0 |
src/Day07.kt | pimtegelaar | 572,939,409 | false | {"Kotlin": 24985} | fun main() {
open class Node(val name: String, open val size: Int = 0)
class Dir(name: String, val parent: Dir? = null, val nodes: MutableList<Node> = mutableListOf()) : Node(name, 0) {
override val size get() = nodes.sumOf { it.size }
val dirs get() = nodes.filterIsInstance<Dir>()
v... | 0 | Kotlin | 0 | 0 | 16ac3580cafa74140530667413900640b80dcf35 | 1,710 | aoc-2022 | Apache License 2.0 |
src/days/Day02.kt | nicole-terc | 574,130,441 | false | {"Kotlin": 29131} | package days
import days.Shape.*
import readInput
enum class Shape(val symbols: List<Char>, val value: Int) {
ROCK(listOf('A', 'X'), 1),
PAPER(listOf('B', 'Y'), 2),
SCISSORS(listOf('C', 'Z'), 3);
companion object {
fun parseChar(char: Char): Shape = values().first { it.symbols.contains(char) ... | 0 | Kotlin | 0 | 2 | 9b0eb9b20e308e5fbfcb2eb7878ba21b45e7e815 | 2,231 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2018/Day11.kt | tginsberg | 155,878,142 | false | null | /*
* Copyright (c) 2018 by <NAME>
*/
/**
* Advent of Code 2018, Day 11 - Chronal Charge
*
* Problem Description: http://adventofcode.com/2018/day/11
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2018/day11/
*/
package com.ginsberg.advent2018
class Day11(private val serialNumber: Int, pr... | 0 | Kotlin | 1 | 18 | f33ff59cff3d5895ee8c4de8b9e2f470647af714 | 2,423 | advent-2018-kotlin | MIT License |
2022/src/day18/day18.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day18
import GREEN
import RESET
import printTimeMillis
import readInput
import java.lang.Math.abs
data class Point(val x: Int, val y: Int, val z: Int) {
fun neighbors() = listOf(
Point(x - 1, y, z), Point(x + 1, y, z),
Point(x, y - 1, z), Point(x, y + 1, z),
Point(x, y,z - 1), Poin... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 2,344 | advent-of-code | Apache License 2.0 |
src/main/kotlin/day25/main.kt | janneri | 572,969,955 | false | {"Kotlin": 99028} | package day25
import util.equals
import util.readTestInput
import kotlin.math.pow
data class SnafuDigit(val value: Long, val symbol: Char) {
companion object {
fun of(symbol: Char): SnafuDigit = when (symbol) {
'-' -> SnafuDigit(-1, '-')
'=' -> SnafuDigit(-2, '=')
else ... | 0 | Kotlin | 0 | 0 | 1de6781b4d48852f4a6c44943cc25f9c864a4906 | 3,096 | advent-of-code-2022 | MIT License |
src/Day05.kt | jstapels | 572,982,488 | false | {"Kotlin": 74335} |
fun main() {
val OP_REGEX = Regex("""move (\d+) from (\d+) to (\d+)""")
fun parseCrates(input: List<String>) =
input.takeWhile { it.contains('[') }
.flatMap { l ->
l.chunked(4) { it.trim('[', ']', ' ') }
.mapIndexed { i, v -> i + 1 to v }
}
... | 0 | Kotlin | 0 | 0 | 0d71521039231c996e2c4e2d410960d34270e876 | 1,944 | aoc22 | Apache License 2.0 |
src/Day18.kt | ked4ma | 573,017,240 | false | {"Kotlin": 51348} | /**
* [Day18](https://adventofcode.com/2022/day/18)
*/
private class Day18 {
data class Point(val x: Int, val y: Int, val z: Int) {
operator fun get(index: Int) = when (index) {
0 -> x
1 -> y
2 -> z
else -> throw RuntimeException()
}
}
}
fun ma... | 1 | Kotlin | 0 | 0 | 6d4794d75b33c4ca7e83e45a85823e828c833c62 | 3,535 | aoc-in-kotlin-2022 | Apache License 2.0 |
src/Day04.kt | maxonof | 572,454,805 | false | {"Kotlin": 5967} | fun main() {
val input = readInput("input4")
val splits = input.map { it.split(",") }
val pairs = splits.map { Pair(toPair(it[0]), toPair(it[1])) }
val part1 = { a: Pair<Int, Int>, b: Pair<Int, Int> ->
(a.first <= b.first && b.second <= a.second) || (b.first <= a.first && a.second <= b.second)
... | 0 | Kotlin | 0 | 0 | ef03fc65dcd429d919eb12d054ce7c052780d7d7 | 1,045 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/Day14.kt | i-redbyte | 433,743,675 | false | {"Kotlin": 49932} | fun main() {
val data = readInputFile("day14")
val rules = data.drop(2)
.map { it.split(" -> ") }
.associateBy({ it[0] }, { it[1] })
fun part1(): Int {
var polymerTemplate = data.first()
repeat(10) {
polymerTemplate = buildString {
for (i in 0 un... | 0 | Kotlin | 0 | 0 | 6d4f19df3b7cb1906052b80a4058fa394a12740f | 1,953 | AOC2021 | Apache License 2.0 |
src/Day13.kt | buczebar | 572,864,830 | false | {"Kotlin": 39213} | fun main() {
fun parseArray(arrayText: String): List<Any> {
fun nodeToList(node: Node): List<Any> {
return node.children.map { child ->
if (child is Leaf) {
child.value ?: emptyList<Any>()
} else {
nodeToList(child)
... | 0 | Kotlin | 0 | 0 | cdb6fe3996ab8216e7a005e766490a2181cd4101 | 3,469 | advent-of-code | Apache License 2.0 |
src/Day13.kt | er453r | 572,440,270 | false | {"Kotlin": 69456} | fun main() {
data class ListOrValue(val value: Int? = null, val list: List<ListOrValue>? = null)
fun parseLine(line: String): ListOrValue = when {
line.startsWith("[") -> { // find the end
val list = mutableListOf<ListOrValue>()
var stackSize = 0
var accumulator = ""... | 0 | Kotlin | 0 | 0 | 9f98e24485cd7afda383c273ff2479ec4fa9c6dd | 2,725 | aoc2022 | Apache License 2.0 |
kotlin-examples/src/main/kotlin/de/rieckpil/learning/fpbook/fpBook.kt | rieckpil | 127,932,091 | false | null | package de.rieckpil.learning.fpbook
fun main() {
println(fib(10))
println(fib(2))
println(fib(1))
println(fib(0))
println(factorial(7))
println(findFirst(arrayOf("Duke", "Foo", "Mike", "Phil", "Tom")) { it == "Phil" })
println(findFirst(arrayOf(true, false, true, false)) { !it })
println(isSorted(listO... | 23 | Java | 7 | 11 | 33d8f115c81433abca8f4984600a41350a1d831d | 1,850 | learning-samples | MIT License |
src/Day16.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | import java.util.*
object Day16 {
const val EXPECTED_PART1_CHECK_ANSWER = 1651
const val EXPECTED_PART2_CHECK_ANSWER = 1707
const val START_VALVE_NAME = "AA"
const val RUNTIME_MINS_PART1 = 30
const val RUNTIME_MINS_PART2 = 26
}
data class Valve(val name: String, val flowRate: Int) {
private ... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 5,100 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day15.kt | max-zhilin | 573,066,300 | false | {"Kotlin": 114003} | import java.util.*
import kotlin.math.abs
data class Sensor(val x: Int, val y: Int, val radius: Int) {
companion object {
fun parse(s: String): Sensor {
val scanner = Scanner(s)
scanner.useDelimiter("[,:]")
//scanner.useDelimiter(":")
val x = scanner.skip("Se... | 0 | Kotlin | 0 | 0 | d9dd7a33b404dc0d43576dfddbc9d066036f7326 | 4,209 | AoC-2022 | Apache License 2.0 |
src/Day07.kt | rod41732 | 728,131,475 | false | {"Kotlin": 26028} | /**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
fun List<Int>.handTypeStrength(): Int = when (this) {
listOf(5) -> 6
listOf(4, 1) -> 5
listOf(3, 2) -> 4
listOf(3, 1, 1) -> 3
listOf(2, 2, 1) -> 2
listOf(2, 1, 1, 1) -> 1
li... | 0 | Kotlin | 0 | 0 | 05a308a539c8a3f2683b11a3a0d97a7a78c4ffac | 3,933 | aoc-23 | Apache License 2.0 |
src/aoc_2022/Day03.kt | jakob-lj | 573,335,157 | false | {"Kotlin": 38689} | package aoc_2022
data class Compartment(val items: List<Char>)
data class Rucksack(val first: Compartment, val second: Compartment) {
val items get() = first.items + second.items
}
data class Group(val first: Rucksack, val second: Rucksack, val third: Rucksack)
fun main() {
val testInput = """
vJr... | 0 | Kotlin | 0 | 0 | 3a7212dff9ef0644d9dce178e7cc9c3b4992c1ab | 2,461 | advent_of_code | Apache License 2.0 |
src/main/kotlin/se/brainleech/adventofcode/aoc2021/Aoc2021Day12.kt | fwangel | 435,571,075 | false | {"Kotlin": 150622} | package se.brainleech.adventofcode.aoc2021
import se.brainleech.adventofcode.compute
import se.brainleech.adventofcode.readLines
import se.brainleech.adventofcode.verify
class Aoc2021Day12 {
companion object {
private const val CAVE_SEPARATOR = "-"
private val CAVE_START = Cave("start")
... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 3,175 | adventofcode | MIT License |
src/Day05.kt | nguyendanv | 573,066,311 | false | {"Kotlin": 18026} | fun main() {
fun toCrateStacks(input: List<String>, splitIdx: Int): List<ArrayDeque<Char>> {
val crates = input.subList(0, splitIdx - 1)
.map { (1 until it.length step 4).toList().map { i -> it[i] } }
val numStacks = crates.maxOfOrNull { it.size }!!
return (0 until numStacks)
... | 0 | Kotlin | 0 | 0 | 376512583af723b4035b170db1fa890eb32f2f0f | 2,620 | advent2022 | Apache License 2.0 |
src/day9/Solution.kt | chipnesh | 572,700,723 | false | {"Kotlin": 48016} | package day9
import day9.Step.Down
import day9.Step.Left
import day9.Step.Right
import day9.Step.Up
import readInput
import kotlin.math.absoluteValue
fun main() {
fun part1(input: List<String>): Int {
val tail = Pos()
return walkRopes(input, tail::follow)
}
fun part2(input: List<String>)... | 0 | Kotlin | 0 | 1 | 2d0482102ccc3f0d8ec8e191adffcfe7475874f5 | 2,531 | AoC-2022 | Apache License 2.0 |
src/Day04.kt | monsterbrain | 572,819,542 | false | {"Kotlin": 42040} | fun main() {
fun String.isInside(range: String): Boolean {
val start1 = this.split("-")[0].toInt() //6
val end1 = this.split("-")[1].toInt() //6
val start2 = range.split("-")[0].toInt() //4
val end2 = range.split("-")[1].toInt() //6
return start1 >= start2 && end1 <= end2
... | 0 | Kotlin | 0 | 0 | 3a1e8615453dd54ca7c4312417afaa45379ecf6b | 1,727 | advent-of-code-kotlin-2022-Solutions | Apache License 2.0 |
src/day15/Code.kt | fcolasuonno | 572,734,674 | false | {"Kotlin": 63451, "Dockerfile": 1340} | package day15
import Coord
import day06.main
import readInput
import kotlin.math.abs
fun main() {
fun Coord.distanceTo(b: Coord) = abs(first - b.first) + abs(second - b.second)
val format = """Sensor at x=(-?\d+), y=(-?\d+): closest beacon is at x=(-?\d+), y=(-?\d+)""".toRegex()
fun parse(input: List<St... | 0 | Kotlin | 0 | 0 | 9cb653bd6a5abb214a9310f7cac3d0a5a478a71a | 1,876 | AOC2022 | Apache License 2.0 |
app/src/main/kotlin/advent/of/code/twentytwenty/Day3.kt | obarcelonap | 320,300,753 | false | null | package advent.of.code.twentytwenty
fun main() {
val input = getResourceAsText("/day3-input")
val slope = Pair(3, 1)
val part1Count = countTrees(input, slope)
println("Part1: count of trees is $part1Count")
val slopes = listOf(Pair(1, 1), Pair(3, 1), Pair(5, 1), Pair(7, 1), Pair(1, 2))
val pa... | 0 | Kotlin | 0 | 0 | a721c8f26738fe31190911d96896f781afb795e1 | 2,086 | advent-of-code-2020 | MIT License |
2023/src/main/kotlin/day23.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Grid
import utils.Parser
import utils.Solution
import utils.Vec2i
import java.util.ArrayDeque
fun main() {
Day23.run()
}
object Day23 : Solution<Grid<Char>>() {
override val name = "day23"
override val parser = Parser.charGrid
private val dir = mapOf(
'>' to Vec2i(1, 0),
'<' to Vec2i(-1,... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,476 | aoc_kotlin | MIT License |
src/main/kotlin/adventofcode2023/day3/day3.kt | dzkoirn | 725,682,258 | false | {"Kotlin": 133478} | package adventofcode2023.day3
import adventofcode2023.readInput
fun main() {
val input = readInput("day3")
println("Day 3")
println("Puzzle 1: ${puzzle1(input)}")
println("Puzzle 2: ${puzzle2(input)}")
}
fun puzzle1(list: List<CharSequence>): Int {
return findAllIntersections(list).sumOf { it.toI... | 0 | Kotlin | 0 | 0 | 8f248fcdcd84176ab0875969822b3f2b02d8dea6 | 3,187 | adventofcode2023 | MIT License |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2023/2023-02.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2023
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
fun main() {
val input = readInputLines(2023, "02-input")
val test1 = readInputLines(2023, "02-test1")
println("Part1:")
part1(test1).println()
p... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,599 | advent-of-code | MIT License |
src/year_2023/day_09/Day09.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2023.day_09
import readInput
object Day09 {
/**
*
*/
fun solutionOne(text: List<String>): Int {
return text.map { line ->
val differences = mutableListOf<List<Int>>()
differences.add(parseHistory(line))
while (true) {
val dif... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 2,089 | advent_of_code | Apache License 2.0 |
src/main/kotlin/day18/Day18.kt | jakubgwozdz | 571,298,326 | false | {"Kotlin": 85100} | package day18
import execute
import readAllText
private typealias Cube = Triple<Int, Int, Int>
private val adj = listOf(
Cube(-1, 0, 0),
Cube(1, 0, 0),
Cube(0, -1, 0),
Cube(0, 1, 0),
Cube(0, 0, -1),
Cube(0, 0, 1),
)
private operator fun Cube.plus(other: Cube): Cube =
Triple(first + other... | 0 | Kotlin | 0 | 0 | 7589942906f9f524018c130b0be8976c824c4c2a | 2,628 | advent-of-code-2022 | MIT License |
src/Day08.kt | strindberg | 572,685,170 | false | {"Kotlin": 15804} | import kotlin.math.max
fun main() {
fun parse(input: List<String>) = input.map { line -> line.toList().map { it.digitToInt() } }
fun outerVisible(map: List<List<Int>>, row: List<Int>, rowIndex: Int, colIndex: Int) =
rowIndex == 0 || colIndex == 0 || rowIndex == map.lastIndex || colIndex == row.lastIn... | 0 | Kotlin | 0 | 0 | c5d26b5bdc320ca2aeb39eba8c776fcfc50ea6c8 | 3,533 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/days/y2023/day07/Day07.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2023.day07
import days.y2023.PuzzleInput
import days.y2023.PuzzleLine
import util.InputReader
typealias PuzzleLine = String
typealias PuzzleInput = List<PuzzleLine>
class Day07(val input: PuzzleInput) {
val hands = input.map { it.toHand() }.sortedWith(::sortFn).reversed()
fun partOne() = hand... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 6,425 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Day02.kt | proggler23 | 573,129,757 | false | {"Kotlin": 27990} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
it.split(" ").map { dec -> Decision.parseFrom(dec) }.let { (opp, self) -> self.scoreAgainst(opp) }
}
}
fun part2(input: List<String>): Int {
return input.sumOf {
it.split(" ").let { (opp,... | 0 | Kotlin | 0 | 0 | 584fa4d73f8589bc17ef56c8e1864d64a23483c8 | 1,940 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2023/2023-23.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2023
import com.github.ferinagy.adventOfCode.CharGrid
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.contains
import com.github.ferinagy.adventOfCode.get
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adven... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 3,936 | advent-of-code | MIT License |
src/Day16.kt | RusticFlare | 574,508,778 | false | {"Kotlin": 78496} | private data class Valve(
val name: String,
val flowRate: Int,
val adjacentValves: List<String>,
)
private data class OneState(
val currentValve: Valve,
val openValves: Set<Valve> = emptySet(),
val pressureReleased: Int = 0,
)
private data class TwoState(
val myValve: Valve,
val elepha... | 0 | Kotlin | 0 | 1 | 10df3955c4008261737f02a041fdd357756aa37f | 6,067 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day18.kt | asm0dey | 572,860,747 | false | {"Kotlin": 61384} | import VoxelWorld18.Voxel
fun main() {
fun generateWorld(input: List<String>): VoxelWorld18 {
val w = input
.map {
val (x, y, z) = it.split(',').map { it.toInt() }
Voxel(x, y, z)
}
.associateWith { true }
.let { VoxelWorld18()... | 1 | Kotlin | 0 | 1 | f49aea1755c8b2d479d730d9653603421c355b60 | 3,775 | 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.