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/Day15.kt | CrazyBene | 573,111,401 | false | {"Kotlin": 50149} | import kotlin.math.abs
fun main() {
data class Position(val xPos: Int, val yPos: Int) {
fun distanceTo(otherPosition: Position): Int = abs(xPos - otherPosition.xPos) + abs(yPos - otherPosition.yPos)
}
data class Sensor(val position: Position, val beaconPosition: Position)
fun part1(input: L... | 0 | Kotlin | 0 | 0 | dfcc5ba09ca3e33b3ec75fe7d6bc3b9d5d0d7d26 | 3,873 | AdventOfCode2022 | Apache License 2.0 |
app/src/main/java/com/betulnecanli/kotlindatastructuresalgorithms/CodingPatterns/01Knapsack.kt | betulnecanli | 568,477,911 | false | {"Kotlin": 167849} | /*
This technique is used to solve optimization problems.
Use this technique to select elements that give maximum profit from a given set with a limitation on capacity
and that each element can only be picked once.
*/
//1. Equal Subset Sum Partition
fun canPartition(nums: IntArray): Boolean {
val totalSum = nums... | 2 | Kotlin | 2 | 40 | 70a4a311f0c57928a32d7b4d795f98db3bdbeb02 | 3,219 | Kotlin-Data-Structures-Algorithms | Apache License 2.0 |
src/main/day8/Day8.kt | Derek52 | 572,850,008 | false | {"Kotlin": 22102} | package main.day8
import main.readInput
fun main() {
val input = readInput("day8/day8")
val firstHalf = true
testAlg(firstHalf)
if (firstHalf) {
//println(part1(input))
} else {
println(part2(input))
}
}
enum class Direction {
LEFT, RIGHT, UP, DOWN, ALL
}
data class Ve... | 0 | Kotlin | 0 | 0 | c11d16f34589117f290e2b9e85f307665952ea76 | 3,422 | 2022AdventOfCodeKotlin | Apache License 2.0 |
aoc2022/day8.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2022
import utils.InputRetrieval
fun main() {
Day8.execute()
}
object Day8 {
fun execute() {
val input = readInput()
val (visibleCount, highestScenicScore) = solve(input)
println("Part 1: $visibleCount")
println("Part 2: $highestScenicScore")
}
private fun ... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 2,289 | Advent-Of-Code | MIT License |
src/day2/Day02.kt | francoisadam | 573,453,961 | false | {"Kotlin": 20236} | package day2
import day2.Outcome.DRAW
import day2.Outcome.LOOSE
import day2.Outcome.WIN
import day2.Shape.PAPER
import day2.Shape.ROCK
import day2.Shape.SCISSOR
import readInput
fun main() {
fun part1(input: List<String>): Int {
val rounds = input.map {
val rawRound = it.split(" ")
... | 0 | Kotlin | 0 | 0 | e400c2410db4a8343c056252e8c8a93ce19564e7 | 2,537 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/com/groundsfam/advent/y2015/d09/Day09.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2015.d09
import com.groundsfam.advent.DATAPATH
import kotlin.io.path.div
import kotlin.io.path.useLines
data class TourPlan(val start: Int, val destinations: Set<Int>)
fun findExtremeTour(distances: Array<IntArray>, minimize: Boolean = true): Int {
// store the minimum achievable t... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 2,562 | advent-of-code | MIT License |
src/Day10.kt | vjgarciag96 | 572,719,091 | false | {"Kotlin": 44399} | private val cyclesToSelect = setOf(20, 60, 100, 140, 180, 220)
private fun part1(input: List<String>): Int {
return input.fold(initial = listOf(1)) { state, instruction ->
when (instruction) {
"noop" -> state + listOf(state.last())
else -> {
val (_, valueToAdd) = ins... | 0 | Kotlin | 0 | 0 | ee53877877b21166b8f7dc63c15cc929c8c20430 | 1,373 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | gillyobeast | 574,413,213 | false | {"Kotlin": 27372} | import utils.appliedTo
import utils.readInput
enum class Shape(val score: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3), ;
}
// X == lose
// Y == draw
// Z == win!
fun String.toTheirShape(): Shape {
return when (this) {
"A" -> Shape.ROCK
"B" -> Shape.PAPER
else -> Shape.SCISSORS
}... | 0 | Kotlin | 0 | 0 | 8cdbb20c1a544039b0e91101ec3ebd529c2b9062 | 2,859 | aoc-2022-kotlin | Apache License 2.0 |
src/Day02.kt | wellithy | 571,903,945 | false | null | package day02
import util.*
import day02.Result.*
import day02.Hand.*
import day02.Symbol.*
enum class Hand(val score: Int, val symbol: String) {
Rock(1, "A"),
Paper(2, "B"),
Scissors(3, "C"),
;
val defeats: Hand
get() = when (this) {
Rock -> Scissors
Paper -> Rock... | 0 | Kotlin | 0 | 0 | 6d5fd4f0d361e4d483f7ddd2c6ef10224f6a9dec | 2,020 | aoc2022 | Apache License 2.0 |
marathons/atcoder/ahc3_shortestPathQueries/shortestPathQueries.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package marathons.atcoder.ahc3_shortestPathQueries
import kotlin.random.Random
private fun solve(queries: Int = 1000, size: Int = 30, averageEdge: Int = 5000) {
val noiseLevel = 0.2
val random = Random(566)
fun vertexId(y: Int, x: Int) = y * size + x
data class Edge(val from: Int, val to: Int, val label: Char, va... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 2,438 | competitions | The Unlicense |
src/twentytwo/Day01.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("Day01_test")
// println(part1(testInput))
check(part1(testInput) == 24_000)
// println(part2(testInput))
check(part2(testInput) == 45_000)
val input = readInput... | 1 | Kotlin | 0 | 0 | 600237b66b8cd3145f103b5fab1978e407b19e4c | 1,906 | advent-of-code-solutions | Apache License 2.0 |
src/jvmMain/kotlin/day02/initial/Day02.kt | liusbl | 726,218,737 | false | {"Kotlin": 109684} | package day02.initial
import java.io.File
fun main() {
// solvePart1() // Solution: 2268, solved at 07:31
solvePart2() // Solution: 63542, solved at 07:46
}
// max amount of: 12 red cubes, 13 green cubes, and 14 blue cubes
fun solvePart1() {
val input = File("src/jvmMain/kotlin/day02/input/input.txt")
// ... | 0 | Kotlin | 0 | 0 | 1a89bcc77ddf9bc503cf2f25fbf9da59494a61e1 | 3,524 | advent-of-code | MIT License |
kotlin-examples/src/main/kotlin/de/rieckpil/learning/fpbook/datatypes/FunctionalTreeDataStructure.kt | rieckpil | 127,932,091 | false | null | package de.rieckpil.learning.fpbook.datatypes
sealed class Tree<out A> {
companion object {
fun <A> size(tree: Tree<A>): Int =
when (tree) {
is Leaf -> 1
is Branch -> 1 + size(tree.left) + size(tree.right)
}
fun maximum(tree: Tree<Int>): Int =
when (tree) {
is Lea... | 23 | Java | 7 | 11 | 33d8f115c81433abca8f4984600a41350a1d831d | 1,869 | learning-samples | MIT License |
src/main/kotlin/icfp2019/Parsers.kt | jzogg | 193,197,477 | true | {"JavaScript": 797354, "Kotlin": 19302, "HTML": 9922, "CSS": 9434} | package icfp2019
import com.google.common.base.CharMatcher
import com.google.common.base.Splitter
import com.google.common.collect.Range
import com.google.common.collect.TreeRangeSet
val matcher = CharMatcher.anyOf("()")
fun parsePoint(mapEdges: String): Point {
return parseEdges(mapEdges)[0]
}
fun parseEdges(m... | 0 | JavaScript | 0 | 0 | 8d637f7feee33d2c7a030f94732bb16c850e047c | 2,951 | icfp-2019 | The Unlicense |
solutions/aockt/y2022/Y2022D15.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2022
import io.github.jadarma.aockt.core.Solution
import kotlin.math.absoluteValue
object Y2022D15 : Solution {
/** Represents a discrete point in 2D space. */
private data class Point(val x: Int, val y: Int)
/** Returns the Manhattan distance between the two points. */
private infix ... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 2,866 | advent-of-code-kotlin-solutions | The Unlicense |
jvm/src/main/kotlin/io/prfxn/aoc2021/day09.kt | prfxn | 435,386,161 | false | {"Kotlin": 72820, "Python": 362} | // Smoke Basin (https://adventofcode.com/2021/day/9)
package io.prfxn.aoc2021
object Day09 {
val lines =
textResourceReader("input/09.txt").useLines { seq ->
seq.map { it.map(Char::digitToInt) }.toList()
}
fun isValidCoords(row: Int, col: Int) =
row in lines.indices && col... | 0 | Kotlin | 0 | 0 | 148938cab8656d3fbfdfe6c68256fa5ba3b47b90 | 1,969 | aoc2021 | MIT License |
src/Day03.kt | krisbrud | 573,455,086 | false | {"Kotlin": 8417} | fun main() {
// TODO: Make prioritization function
fun priority(s: Char): Int {
return when(s.isLowerCase()) {
true -> s.code - "a".toCharArray().first().code
false -> s.code - "A".toCharArray().first().code + 26
} + 1
}
fun compartmentalize(s: String): List<Stri... | 0 | Kotlin | 0 | 0 | 02caf3a30a292d7b8c9e2b7788df74650e54573c | 1,480 | advent-of-code-2022 | Apache License 2.0 |
src/Day13.kt | mikemac42 | 573,071,179 | false | {"Kotlin": 45264} | import java.io.File
fun main() {
val testInput = """[1,1,3,1,1]
[1,1,5,1,1]
[[1],[2,3,4]]
[[1],4]
[9]
[[8,7,6]]
[[4,4],4,4]
[[4,4],4,4,4]
[7,7,7,7]
[7,7,7]
[]
[3]
[[[]]]
[[]]
[1,[2,[3,[4,[5,6,7]]]],8,9]
[1,[2,[3,[4,[5,6,0]]]],8,9]"""
val realInput = File("src/Day13.txt").readText()
val part1TestOutput = ... | 0 | Kotlin | 1 | 0 | 909b245e4a0a440e1e45b4ecdc719c15f77719ab | 4,474 | advent-of-code-2022 | Apache License 2.0 |
src/day05/Day05.kt | andreas-eberle | 573,039,929 | false | {"Kotlin": 90908} | package day05
import readInput
const val day = "05"
fun main() {
fun calculatePart1Score(input: List<String>): String {
val (stacks, moves) = input.parseStacksAndMoves()
val mutableStacks = stacks.map { it.toMutableList() }
moves.forEach { (times, from, to) ->
repeat(times... | 0 | Kotlin | 0 | 0 | e42802d7721ad25d60c4f73d438b5b0d0176f120 | 2,452 | advent-of-code-22-kotlin | Apache License 2.0 |
src/Day12.kt | Shykial | 572,927,053 | false | {"Kotlin": 29698} | fun main() {
fun part1(input: List<String>): Int {
lateinit var start: GeoPoint
lateinit var end: GeoPoint
val geoMap = input.mapIndexed { lineIndex, line ->
line.mapIndexed { charIndex, char ->
when (char) {
'S' -> GeoPoint(y = lineIndex, x =... | 0 | Kotlin | 0 | 0 | afa053c1753a58e2437f3fb019ad3532cb83b92e | 3,116 | advent-of-code-2022 | Apache License 2.0 |
solutions/src/Day04.kt | khouari1 | 573,893,634 | false | {"Kotlin": 132605, "HTML": 175} | fun main() {
fun part1(input: List<String>): Int {
return input.count { line ->
val (one, two) = line.asNumberPairs()
val (oneLowInt, oneHighInt) = one
val (twoLowInt, twoHighInt) = two
(oneLowInt >= twoLowInt && oneHighInt <= twoHighInt) || (twoLowInt >= oneL... | 0 | Kotlin | 0 | 1 | b00ece4a569561eb7c3ca55edee2496505c0e465 | 1,441 | advent-of-code-22 | Apache License 2.0 |
2021/src/Day15.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | import java.util.*
// https://adventofcode.com/2021/day/15
fun main() {
fun <T> List<Pair<T, T>>.getUniqueValuesFromPairs(): Set<T> = this
.map { (a, b) -> listOf(a, b) }
.flatten()
.toSet()
fun <T> List<Pair<T, T>>.getUniqueValuesFromPairs(predicate: (T) -> Boolean): Set<T> = this
.map { (a, b) ... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 4,597 | advent-of-code | Apache License 2.0 |
src/main/kotlin/io/steinh/aoc/day02/CubeConundrum.kt | daincredibleholg | 726,426,347 | false | {"Kotlin": 25396} | package io.steinh.aoc.day02
class CubeConundrum {
fun sumIds(lines: List<String>, bagLimits: List<CubeCount>): Int {
val processed = analyze(lines)
var sum = 0
for (game in processed) {
var match = true
for (entry in game.value) {
for (limit in bag... | 0 | Kotlin | 0 | 0 | 4aa7c684d0e337c257ae55a95b80f1cf388972a9 | 3,894 | AdventOfCode2023 | MIT License |
src/main/kotlin/day3.kt | danielfreer | 297,196,924 | false | null | import kotlin.math.absoluteValue
import kotlin.time.ExperimentalTime
@ExperimentalTime
fun day3(paths: List<String>): List<Solution> {
return listOf(
solve(3, 1) { findIntersection(paths) },
solve(3, 2) { findSteps(paths) }
)
}
data class Point(val x: Int, val y: Int)
fun manhattanDistance(po... | 0 | Kotlin | 0 | 0 | 74371d15f95492dee1ac434f0bfab3f1160c5d3b | 2,817 | advent2019 | The Unlicense |
2023/src/main/kotlin/day19.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Component4
import utils.Parse
import utils.Parser
import utils.Solution
import utils.Vec4i
import utils.cut
import utils.mapItems
fun main() {
Day19.run()
}
object Day19 : Solution<Pair<List<Day19.Workflow>, List<Vec4i>>>() {
override val name = "day19"
override val parser = Parser.compound(
Pa... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 5,174 | aoc_kotlin | MIT License |
src/Day03.kt | mhuerster | 572,728,068 | false | {"Kotlin": 24302} | fun main() {
var lowercase = ('a'..'z')
var uppercase = ('A'..'Z')
class Rucksack(val contents: String ) {
val midpoint: Int
get() = (contents.length / 2)
val firstCompartment: String
get() = contents.substring(0..midpoint)
val secondCompartment: String
get() = contents.substring(mid... | 0 | Kotlin | 0 | 0 | 5f333beaafb8fe17ff7b9d69bac87d368fe6c7b6 | 2,030 | 2022-advent-of-code | Apache License 2.0 |
src/Day12.kt | thpz2210 | 575,577,457 | false | {"Kotlin": 50995} | private class Solution12(input: List<String>) {
var grid = Grid2D(input.map { it.toCharArray().toList() })
fun part1() = distanceFrom('E' to 'S')
fun part2() = distanceFrom('E' to 'a')
private fun distanceFrom(fromTo: Pair<Char, Char>): Int {
val fromChar = fromTo.first
val toChar = ... | 0 | Kotlin | 0 | 0 | 69ed62889ed90692de2f40b42634b74245398633 | 1,407 | aoc-2022 | Apache License 2.0 |
src/aoc2017/kot/Day24.kt | Tandrial | 47,354,790 | false | null | package aoc2017.kot
import java.io.File
object Day24 {
fun solve(input: List<String>): Pair<Int, Int> {
val (pairs, doubles) = input.map { val (l, r) = it.split("/").map { it.toInt() }; l to r }.partition { it.first != it.second }
val (p1, p2) = dfs(listOf(0), pairs, doubles)
return Pair(p1, p2.second)... | 0 | Kotlin | 1 | 1 | 9294b2cbbb13944d586449f6a20d49f03391991e | 1,391 | Advent_of_Code | MIT License |
src/Day07.kt | PascalHonegger | 573,052,507 | false | {"Kotlin": 66208} | private sealed interface SystemNode {
val name: String
val size: Int
}
private data class SystemDirectory(override val name: String, val children: List<SystemNode>) : SystemNode {
override val size = children.sumOf { it.size }
}
private data class SystemFile(override val name: String, override val size: I... | 0 | Kotlin | 0 | 0 | 2215ea22a87912012cf2b3e2da600a65b2ad55fc | 3,925 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | Akaneiro | 572,883,913 | false | null | fun main() {
fun Char.calculatePriority(): Int {
var priority = this.lowercaseChar() - 'a' + 1
if (this.isUpperCase()) priority += 26
return priority
}
fun List<String>.asListOfCharLists() =
this
.asSequence()
.map { it.toCharArray().toList() }
... | 0 | Kotlin | 0 | 0 | f987830a70a2a1d9b88696271ef668ba2445331f | 1,635 | aoc-2022 | Apache License 2.0 |
src/Day23.kt | jstapels | 572,982,488 | false | {"Kotlin": 74335} |
fun main() {
data class Dir(val dir: String, val offset: Pos, val checks: List<Pos>) {
fun valid(pos: Pos, used: Set<Pos>) =
checks.map { pos + it }
.none { it in used }
}
val startDirs = listOf(
Dir("N", 0 by -1, listOf(-1 by -1, 0 by -1, 1 by -1)),
Di... | 0 | Kotlin | 0 | 0 | 0d71521039231c996e2c4e2d410960d34270e876 | 3,299 | aoc22 | Apache License 2.0 |
src/Day07.kt | zuevmaxim | 572,255,617 | false | {"Kotlin": 17901} | private fun part1(input: List<String>): Int {
val root = parse(input)
val dirs = root.toDirList()
return dirs.filter { it.size <= 100000 }.sumOf { it.size }
}
private fun part2(input: List<String>): Int {
val root = parse(input)
val dirs = root.toDirList()
val currentData = root.size
val cu... | 0 | Kotlin | 0 | 0 | 34356dd1f6e27cc45c8b4f0d9849f89604af0dfd | 2,191 | AOC2022 | Apache License 2.0 |
src/main/kotlin/Day05.kt | todynskyi | 573,152,718 | false | {"Kotlin": 47697} | import java.util.*
fun main() {
fun parse(input: List<String>): Pair<MutableMap<Int, LinkedList<String>>, List<MoveCommand>> {
val data = input.takeWhile { it.isNotBlank() }
val numberOfStacks =
data.last().mapIndexedNotNull { index, c -> if (c.isDigit()) c.toString().toInt() to index ... | 0 | Kotlin | 0 | 0 | 5f9d9037544e0ac4d5f900f57458cc4155488f2a | 2,444 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/Day04.kt | allwise | 574,465,192 | false | null | import java.io.File
fun main() {
fun part1(input: List<String>): Int {
val areas= Areas(input)
return areas.process()
}
fun part2(input: List<String>): Int {
val areas= Areas(input)
return areas.processContains()
}
// test if implementation meets criteria from th... | 0 | Kotlin | 0 | 0 | 400fe1b693bc186d6f510236f121167f7cc1ab76 | 2,169 | advent-of-code-2022 | Apache License 2.0 |
aoc-2022/src/main/kotlin/nerok/aoc/aoc2022/day05/Day05.kt | nerok | 572,862,875 | false | {"Kotlin": 113337} | package nerok.aoc.aoc2022.day05
import nerok.aoc.utils.Input
import kotlin.time.DurationUnit
import kotlin.time.measureTime
fun main() {
fun part1(input: String): String {
val (mapInput, instructionInput) = input.split("\n\n")
val parsedMap = mapInput
.lines()
.map { lines ... | 0 | Kotlin | 0 | 0 | 7553c28ac9053a70706c6af98b954fbdda6fb5d2 | 3,442 | AOC | Apache License 2.0 |
src/commonMain/kotlin/search/SimpleTrie.kt | jillesvangurp | 271,782,317 | false | null | package search
private class TrieNode {
val children: MutableMap<Char, TrieNode> = mutableMapOf()
var isLeaf = false
fun strings(): List<String> {
return children.entries.flatMap { entry ->
val n = entry.value
if (n.isLeaf) {
listOf("" + entry.key) +
... | 0 | Kotlin | 1 | 4 | 0f4236bf891faa841c6e32fe37c9ab9d2e6ce7c5 | 3,524 | querylight | MIT License |
aoc21/day_21/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
import kotlin.math.max
enum class Player {
P1, P2;
fun opposite(): Player = if (this == P1) P2 else P1
}
data class Game(
var p1Pos: Int,
var p2Pos: Int,
var p1Score: Int = 0,
var p2Score: Int = 0,
val winningScore: Int,
var playing: Player = Player.P1,
) {
var... | 0 | Rust | 1 | 0 | f47ef85393d395710ce113708117fd33082bab30 | 2,768 | advent-of-code | MIT License |
src/main/kotlin/biz/koziolek/adventofcode/year2022/day03/day3.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2022.day03
import biz.koziolek.adventofcode.findInput
fun main() {
val inputFile = findInput(object {})
val rucksacks = parseRucksacks(inputFile.bufferedReader().readLines())
println("Sum of shared item priorities: ${getSumOfSharedItemPriorities(rucksacks)}")
va... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 1,779 | advent-of-code | MIT License |
src/Day05.kt | emersonf | 572,870,317 | false | {"Kotlin": 17689} | import java.util.*
data class Instruction(val count: Int, val from: Int, val to: Int)
typealias Stack = LinkedList<Char>
fun main() {
fun readStacksAndInstructions(input: List<String>): Pair<Array<Stack>, List<Instruction>> {
val (instructionLines, stackLines) = input.partition { line -> line.startsWith... | 0 | Kotlin | 0 | 0 | 0e97351ec1954364648ec74c557e18ccce058ae6 | 3,016 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/hopkins/aoc/day5/main.kt | edenrox | 726,934,488 | false | {"Kotlin": 88215} | package com.hopkins.aoc.day5
import java.io.File
const val debug = true
const val part = 2
/** Advent of Code 2023: Day 5 */
fun main() {
// Read the input
val lines: List<String> = File("input/input5.txt").readLines()
// Step 1: read the seeds
val (_, seedsPart) = lines[0].split(": ")
val seedN... | 0 | Kotlin | 0 | 0 | 45dce3d76bf3bf140d7336c4767e74971e827c35 | 3,061 | aoc2023 | MIT License |
advent-of-code-2023/src/test/kotlin/Day2Test.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
/** [Day 2: Day 2: Cube Conundrum](https://adventofcode.com/2023/day/2) */
class Day2Test {
data class Game(
val gameId: Int,
val sets: List<CubeSet>,
) {
fun max(color: String): Int {
return sets.maxOf { it.cubes[color] ?:... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 3,100 | advent-of-code | MIT License |
codeforces/globalround16/d.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.globalround16
private fun solve() {
val (hei, wid) = readInts()
val a = readInts()
val places = mutableMapOf<Int, MutableList<Pair<Int, Int>>>()
val aSorted = a.sorted()
for (i in aSorted.indices) {
places.getOrPut(aSorted[i]) { mutableListOf() }.add(i / wid to i % wid)
}
places.forEach { (... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,334 | competitions | The Unlicense |
2023/src/main/kotlin/day18.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parse
import utils.Parser
import utils.SegmentL
import utils.Solution
import utils.Vec2l
import utils.mapItems
fun main() {
Day18.run()
}
object Day18 : Solution<List<Day18.Line>>() {
override val name = "day18"
override val parser = Parser.lines.mapItems { parseLine(it) }
@Parse("{direction} {l... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 3,280 | aoc_kotlin | MIT License |
src/Day08.kt | ajmfulcher | 573,611,837 | false | {"Kotlin": 24722} | fun main() {
fun makeGrid(input: List<String>): List<List<Int>> {
return input.map { line ->
line.toCharArray().map { it.digitToInt() }
}
}
fun List<List<Int>>.row(idx: Int) = this[idx]
fun List<List<Int>>.col(idx: Int) = map { it[idx] }
fun findVisible(row: List<Int>, ... | 0 | Kotlin | 0 | 0 | 981f6014b09e347241e64ba85e0c2c96de78ef8a | 2,810 | advent-of-code-2022-kotlin | Apache License 2.0 |
kata/src/main/kotlin/kata/HowGreenIsMyValley.kt | gualtierotesta | 129,613,223 | false | null | package kata
import java.util.*
import java.util.stream.Collectors.toList
/*
Input : an array of integers.
Output : this array, but sorted in such a way that there are two wings:
the left wing with numbers decreasing,
the right wing with numbers increasing.
the two wings have the sa... | 0 | Kotlin | 0 | 0 | 8366bb3aed765fff7fb5203abce9a20177529a8e | 2,537 | PlayWithKotlin | Apache License 2.0 |
2022/src/main/kotlin/day2_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.badInput
import utils.cut
import utils.mapItems
fun main() {
Day2Func.run()
}
enum class Play(val score: Int) {
Rock(1),
Paper(2),
Scissors(3);
val winsOver: Play get() = when (this) {
Rock -> Scissors
Paper -> Rock
Scissors -> Paper
}
... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,605 | aoc_kotlin | MIT License |
src/Day02.kt | HylkeB | 573,815,567 | false | {"Kotlin": 83982} | import java.lang.IllegalArgumentException
private sealed class Hand(val pickScore: Int) {
protected abstract val winsVersus: Hand
private val losesVersus: Hand get() = winsVersus.winsVersus
fun winsVersus(other: Hand): Boolean {
return winsVersus == other
}
fun getLosingHand(): Hand {
... | 0 | Kotlin | 0 | 0 | 8649209f4b1264f51b07212ef08fa8ca5c7d465b | 2,302 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/day16/Day16.kt | Mee42 | 433,459,856 | false | {"Kotlin": 42703, "Java": 824} | package dev.mee42.day16
import dev.mee42.*
sealed class Packet(val vNumber: Int) {
data class LiteralValue(val value: Long, val vNum: Int): Packet(vNum) {
override fun toString() = "$value"
}
data class Op(val packets: List<Packet>, val vNum: Int, val typeID: Int): Packet(vNum) {
override ... | 0 | Kotlin | 0 | 0 | db64748abc7ae6a92b4efa8ef864e9bb55a3b741 | 3,022 | aoc-2021 | MIT License |
src/Day16.kt | kpilyugin | 572,573,503 | false | {"Kotlin": 60569} | import kotlin.math.max
fun main() {
data class Valve(val id: String, val rate: Int, var tunnels: List<Pair<String, Int>>, val index: Int) {
var opened = false
fun needOpen() = rate > 0 && !opened
}
fun parseValves(input: List<String>): Map<String, Valve> {
var index = 0
re... | 0 | Kotlin | 0 | 1 | 7f0cfc410c76b834a15275a7f6a164d887b2c316 | 4,329 | Advent-of-Code-2022 | Apache License 2.0 |
src/Day05.kt | niltsiar | 572,887,970 | false | {"Kotlin": 16548} | fun main() {
fun part1(input: List<String>): String {
val stacks = processStacks(input[0])
val instructions = processInstructions(input[1])
instructions.forEach { instruction ->
val number = instruction.first
val from = instruction.second - 1
val to = ins... | 0 | Kotlin | 0 | 0 | 766b3e168fc481e4039fc41a90de4283133d3dd5 | 2,392 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day12/Day12.kt | spyroid | 433,555,350 | false | null | package day12
import readInput
import kotlin.system.measureTimeMillis
fun main() {
fun find1(map: Map<String, List<String>>, el: String, target: String, visited: MutableSet<String>, cPath: MutableList<String>, distinctPaths: MutableSet<List<String>>) {
if (el == target) {
val copy = cPath.toM... | 0 | Kotlin | 0 | 0 | 939c77c47e6337138a277b5e6e883a7a3a92f5c7 | 2,875 | Advent-of-Code-2021 | Apache License 2.0 |
src/day02/Day02.kt | palpfiction | 572,688,778 | false | {"Kotlin": 38770} | package day02
import readInput
sealed interface Choice
object Rock : Choice
object Paper : Choice
object Scissors : Choice
sealed interface Outcome
object Win : Outcome
object Lose : Outcome
object Draw : Outcome
fun main() {
fun Choice.score() = when (this) {
Rock -> 1
Paper -> 2
Sci... | 0 | Kotlin | 0 | 0 | 5b79ec5fa4116e496cd07f0c7cea7dabc8a371e7 | 2,808 | advent-of-code | Apache License 2.0 |
src/main/kotlin/days/y2023/day15/Day15.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2023.day15
import util.InputReader
typealias PuzzleInput = String
class Day15(val input: PuzzleInput) {
fun partOne(): Int {
// Determine the ASCII code for the current character of the string.
// Increase the current value by the ASCII code you just determined.
// Set the ... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 3,459 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/Day18.kt | todynskyi | 573,152,718 | false | {"Kotlin": 47697} | fun main() {
fun part1(input: List<Coordinate>): Int = input.sumOf { it.neighbors().count { p -> p !in input } }
fun part2(input: List<Coordinate>): Int {
val minX = input.minBy { it.x }.x
val minY = input.minBy { it.y }.y
val minZ = input.minBy { it.z }.z
val maxX = input.ma... | 0 | Kotlin | 0 | 0 | 5f9d9037544e0ac4d5f900f57458cc4155488f2a | 1,803 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/Day03.kt | sebokopter | 570,715,585 | false | {"Kotlin": 38263} | fun main() {
/**
* a..z => 1..26
* A..Z => 27..52
*/
fun priority(char: Char): Int {
val priority = if (char.isLowerCase()) char - 'a'
else char - 'A' + 26
//priority index starts with 1
return priority + 1
}
fun findCommonItem(rucksacks: List<Set<Char>>)... | 0 | Kotlin | 0 | 0 | bb2b689f48063d7a1b6892fc1807587f7050b9db | 1,308 | advent-of-code-2022 | Apache License 2.0 |
src/day03/Day03.kt | barbulescu | 572,834,428 | false | {"Kotlin": 17042} | package day03
import readInput
import kotlin.streams.toList
fun main() {
val total = readInput("day03/Day03")
.asSequence()
.map(::toPriorities)
.map { it.chunked(it.size / 2) }
.onEach { require(it[0].size == it[1].size) }
.map { it[0].intersect(it[1].toSet()) }
.o... | 0 | Kotlin | 0 | 0 | 89bccafb91b4494bfe4d6563f190d1b789cde7a4 | 1,374 | aoc-2022-in-kotlin | Apache License 2.0 |
aoc-2023/src/main/kotlin/aoc/aoc12d.kts | triathematician | 576,590,518 | false | {"Kotlin": 615974} | import aoc.AocParser.Companion.parselines
import aoc.*
import aoc.util.getDayInput
val testInput = """
???.### 1,1,3
.??..??...?##. 1,1,3
?#?#?#?#?#?#?#? 1,3,1,6
????.#...#... 4,1,1
????.######..#####. 1,6,5
?###???????? 3,2,1
""".parselines
class Springs(_line: String, val nums: List<Int>) {
val max = nums.maxOr... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 2,993 | advent-of-code | Apache License 2.0 |
advent-of-code-2020/src/main/kotlin/eu/janvdb/aoc2020/day17/Day17.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2020.day17
import eu.janvdb.aocutil.kotlin.Combinations
import eu.janvdb.aocutil.kotlin.MinMax
import eu.janvdb.aocutil.kotlin.readLines
fun main() {
run(numberOfDimensions = 3)
run(numberOfDimensions = 4)
}
private fun run(numberOfDimensions: Int) {
println("$numberOfDimensions dimensions")
... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,960 | advent-of-code | Apache License 2.0 |
src/main/kotlin/Day08.kt | akowal | 434,506,777 | false | {"Kotlin": 30540} | import Day08.Segment.*
import java.util.*
fun main() {
println(Day08.solvePart1())
println(Day08.solvePart2())
}
object Day08 {
private val entries = readInput("day08")
.map {
val patterns = it.substringBefore("|").trim().split(' ')
val output = it.substringAfter("|").trim(... | 0 | Kotlin | 0 | 0 | 08d4a07db82d2b6bac90affb52c639d0857dacd7 | 2,766 | advent-of-kode-2021 | Creative Commons Zero v1.0 Universal |
src/day02/Day02.kt | zypus | 573,178,215 | false | {"Kotlin": 33417, "Shell": 3190} | package day02
import AoCTask
// https://adventofcode.com/2022/day/2
enum class RPSMove(val score: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3);
infix fun vs(other: RPSMove) = when (other) {
this -> RPSOutcome.DRAW
this.beats() -> RPSOutcome.WIN
else -> RPSOutcome.LOSS
}
fun... | 0 | Kotlin | 0 | 0 | f37ed8e9ff028e736e4c205aef5ddace4dc73bfc | 2,377 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/days/Day9Solution.kt | yigitozgumus | 434,108,608 | false | {"Kotlin": 17835} | package days
import BaseSolution
class Day9Solution(inputList: List<String>) : BaseSolution(inputList) {
private val grids = inputList.mapTo(mutableListOf()) {
it.split("").filter { it != "" }.mapTo(mutableListOf()) { it.toInt() }
}.also {
it.forEach { grid ->
grid.add(grid.size, ... | 0 | Kotlin | 0 | 0 | c0f6fc83fd4dac8f24dbd0d581563daf88fe166a | 1,939 | AdventOfCode2021 | MIT License |
src/main/kotlin/com/oocode/Almanac.kt | ivanmoore | 725,978,325 | false | {"Kotlin": 42155} | package com.oocode
fun almanacFrom(input: String): Almanac {
val lines = input.split("\n")
val seedNumbers = lines[0].split(" ").drop(1).map { it.toLong() }
val seeds = seedNumbers.chunked(2).map {
val startNumber = it[0]
val rangeSize = it[1]
InputRange(startNumber, (startNumber + ... | 0 | Kotlin | 0 | 0 | 36ab66daf1241a607682e7f7a736411d7faa6277 | 3,672 | advent-of-code-2023 | MIT License |
src/main/kotlin/Day10.kt | todynskyi | 573,152,718 | false | {"Kotlin": 47697} | fun main() {
fun List<Command>.toCycles(): Map<Int, Int> {
var index = 0
var x = 1
val values = mutableMapOf<Int, Int>()
this.forEach { command ->
if (command.instruction == "noop") {
values[++index] = x
} else {
values[++inde... | 0 | Kotlin | 0 | 0 | 5f9d9037544e0ac4d5f900f57458cc4155488f2a | 1,432 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/Day09.kt | mjossdev | 574,439,750 | false | {"Kotlin": 81859} | import kotlin.math.abs
import kotlin.math.sign
private enum class Direction {
LEFT, RIGHT, UP, DOWN
}
fun main() {
data class Point(val x: Int, val y: Int)
data class Knot(var position: Point)
fun Point.move(direction: Direction) = when (direction) {
Direction.LEFT -> copy(x = x - 1)
... | 0 | Kotlin | 0 | 0 | afbcec6a05b8df34ebd8543ac04394baa10216f0 | 2,587 | advent-of-code-22 | Apache License 2.0 |
src/Day12.kt | timhillgit | 572,354,733 | false | {"Kotlin": 69577} | import java.util.PriorityQueue
fun <T> dijkstra(
graph: Map<T, List<Pair<Long, T>>>,
start: Set<T>,
goal: Set<T>,
): Pair<Long, List<T>>? {
val visited = mutableSetOf<T>()
val frontier = PriorityQueue<Pair<Long, List<T>>>(start.size) { a, b ->
compareValuesBy(a, b) { it.first }
}
f... | 0 | Kotlin | 0 | 1 | 76c6e8dc7b206fb8bc07d8b85ff18606f5232039 | 2,540 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/year2023/Day18.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2023
fun main() {
val input = readInput("Day18")
Day18.part1(input).println()
Day18.part2(input).println()
}
object Day18 {
fun part1(input: List<String>): Long {
val holes = input.map { getHole(it) }
return holes.cubicMetersOfLava()
}
fun part2(input: List<String>... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 2,283 | advent-of-code | MIT License |
src/Day02.kt | SebastianHelzer | 573,026,636 | false | {"Kotlin": 27111} | enum class HandShape {
Rock, Paper, Scissors;
fun next(): HandShape = when(this) {
Rock -> Paper
Paper -> Scissors
Scissors -> Rock
}
}
fun main() {
fun Char.toHandShape(): HandShape {
return when(this) {
'A', 'X' -> HandShape.Rock
'B', 'Y' -> Ha... | 0 | Kotlin | 0 | 0 | e48757626eb2fb5286fa1c59960acd4582432700 | 1,998 | advent-of-code-2022 | Apache License 2.0 |
src/Day08.kt | jwalter | 573,111,342 | false | {"Kotlin": 19975} | fun main() {
data class Tree(val height: Int, var visible: Boolean = false, val viewingDistances: MutableList<Int> = mutableListOf<Int>())
fun parse(input: List<String>): List<List<Tree>> {
return input.map { it.map { height -> Tree(height.digitToInt()) } }
}
fun setViewingDistance(tree: Tree,... | 0 | Kotlin | 0 | 0 | 576aeabd297a7d7ee77eca9bb405ec5d2641b441 | 2,492 | adventofcode2022 | Apache License 2.0 |
2022/src/test/kotlin/Day18.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import kotlin.math.absoluteValue
private data class Cube(val x: Int, val y: Int, val z: Int)
private val adjacent = 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)
... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 1,963 | adventofcode | MIT License |
src/main/kotlin/aoc2020/ex14.kt | noamfree | 433,962,392 | false | {"Kotlin": 93533} | fun main() {
tests()
val input = readInputFile("aoc2020/input14")
require(part1(input) == 13727901897109L)
val memory = executeCommands2(parseInput(input))
println(memory.values.sumOf { it })
}
private fun part1(input: String): Long {
val commands = parseInput(input)
val memory = executeCom... | 0 | Kotlin | 0 | 0 | 566cbb2ef2caaf77c349822f42153badc36565b7 | 4,541 | AOC-2021 | MIT License |
src/Day24.kt | sabercon | 648,989,596 | false | null | fun main() {
fun index(moves: List<String>): Pair<Int, Int> {
return moves.fold(0 to 0) { (i, j), c ->
when (c) {
"e" -> i + 2 to j
"w" -> i - 2 to j
"se" -> i + 1 to j - 1
"sw" -> i - 1 to j - 1
"ne" -> i + 1 to j +... | 0 | Kotlin | 0 | 0 | 81b51f3779940dde46f3811b4d8a32a5bb4534c8 | 1,634 | advent-of-code-2020 | MIT License |
src/main/aoc2023/Day5.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2023
import kotlin.math.min
class Day5(input: List<String>) {
data class ElfMap(val source: LongRange, val diff: Long) {
companion object {
// Parse input and add all missing ranges between 0 and max UInt with zero
// transformation to have ranges with complete coverage... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 3,129 | aoc | MIT License |
src/main/kotlin/dev/bogwalk/batch8/Problem81.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch8
import java.util.PriorityQueue
/**
* Problem 81: Path Sum 2 Ways
*
* https://projecteuler.net/problem=81
*
* Goal: Find the minimum path sum for an NxN grid, starting at (0,0) and ending at (n,n), while
* only being able to move to the right or down with each step.
*
* Constraints: ... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 4,145 | project-euler-kotlin | MIT License |
src/main/kotlin/day19/Day19.kt | qnox | 575,581,183 | false | {"Kotlin": 66677} | package day19
import readInput
@JvmInline
value class Resources(val resources: IntArray) {
operator fun plus(other: Resources): Resources {
return Resources(IntArray(resources.size) { resources[it] + other.resources[it] })
}
operator fun minus(other: Resources): Resources {
return Resour... | 0 | Kotlin | 0 | 0 | 727ca335d32000c3de2b750d23248a1364ba03e4 | 4,809 | aoc2022 | Apache License 2.0 |
src/main/kotlin/mkuhn/aoc/Day02.kt | mtkuhn | 572,236,871 | false | {"Kotlin": 53161} | package mkuhn.aoc
import mkuhn.aoc.util.readInput
fun main() {
val input = readInput("Day02")
println(day2part1(input))
println(day2part2(input))
}
fun day2part1(input: List<String>): Int =
input.map { l -> l.first().toRpsShape() to l.last().toRpsShape() }
.sumOf { it.first.scoreAgainst(it.se... | 0 | Kotlin | 0 | 1 | 89138e33bb269f8e0ef99a4be2c029065b69bc5c | 1,450 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | stevennoto | 573,247,572 | false | {"Kotlin": 18058} | fun main() {
fun part1(input: List<String>): Int {
// Clean up input (map A/B/C and X/Y/Z to 0/1/2)
// Then, calculate rock/paper/scissors winner using modulus, and sum chosen moves and victory values
return input.map {
val chars = it.toCharArray()
Pair(chars[0] - 'A'... | 0 | Kotlin | 0 | 0 | 42941fc84d50b75f9e3952bb40d17d4145a3036b | 1,652 | adventofcode2022 | Apache License 2.0 |
archive/2022/Day21.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | import kotlin.math.sign
private const val EXPECTED_1 = 152L
private const val EXPECTED_2 = 301L
private class Day21(isTest: Boolean) : Solver(isTest) {
fun Map<String, String>.solve(key: String): Long {
key.toLongOrNull()?.let { return it }
val parts = (this[key]!! + " XX").split(" ")
retu... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 2,238 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day03.kt | rgawrys | 572,698,359 | false | {"Kotlin": 20855} | import utils.intersectAll
import utils.readInput
import utils.splitIntoParts
fun main() {
fun part1(input: List<String>): Int =
sumOfPrioritiesOfDuplicateItemTypesInBothCompartments(input)
fun part2(input: List<String>): Int =
sumOfPrioritiesOfItemTypesCommonByEveryThreeElvesInEachGroup(input)... | 0 | Kotlin | 0 | 0 | 5102fab140d7194bc73701a6090702f2d46da5b4 | 1,592 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc2021/Day15.kt | j4velin | 572,870,735 | false | {"Kotlin": 285016, "Python": 1446} | package aoc2021
import Point
import modulo
import readInput
/**
* @param inputMap the input risk map, see [getInputMap]
* @return the lowest possible risk of all paths from the upper left corner to the bottom right corner
*/
private fun getLowestRisk(inputMap: Array<IntArray>): Int {
val maxX = (inputMap.first... | 0 | Kotlin | 0 | 0 | f67b4d11ef6a02cba5b206aba340df1e9631b42b | 3,024 | adventOfCode | Apache License 2.0 |
2023/src/day02/day02.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day02
import GREEN
import RESET
import printTimeMillis
import readInput
import kotlin.math.max
val maxes = mapOf(
"red" to 12,
"green" to 13,
"blue" to 14
)
fun part1(input: List<String>): Int {
return input.sumOf {
val gameIdx = it.split(":")[0].split(" ")[1].toInt()
val reve... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 1,551 | advent-of-code | Apache License 2.0 |
src/Day13.kt | anilkishore | 573,688,256 | false | {"Kotlin": 27023} | fun main() {
fun endIndex(str: String, s: Int): Int {
var cnt = 0
var i = s
while (true) {
if (str[i] == '[') ++cnt else {
if (str[i] == ']') --cnt
}
if (cnt == 0) return i;
++i
}
}
fun numIndex(str: String, s:... | 0 | Kotlin | 0 | 0 | f8f989fa400c2fac42a5eb3b0aa99d0c01bc08a9 | 2,458 | AOC-2022 | Apache License 2.0 |
src/Day03.kt | SnyderConsulting | 573,040,913 | false | {"Kotlin": 46459} | fun main() {
fun part1(input: List<String>): Int {
val rucksacks = input.map { line ->
Pair(
line.take(line.length / 2),
line.drop(line.length / 2)
)
}
return rucksacks.sumOf { rucksack ->
rucksack.getDuplicate().getPointVa... | 0 | Kotlin | 0 | 0 | ee8806b1b4916fe0b3d576b37269c7e76712a921 | 2,153 | Advent-Of-Code-2022 | Apache License 2.0 |
src/main/kotlin/aoc2017/ElectromagneticMoat.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2017
import komu.adventofcode.utils.nonEmptyLines
import java.util.Comparator.comparing
fun electromagneticMoat(input: String, longest: Boolean = false): Int {
val components = input.nonEmptyLines().map { Component.parse(it) }.toSet()
val comparator = if (longest) comparing(Resul... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 1,409 | advent-of-code | MIT License |
src/main/kotlin/com/groundsfam/advent/y2022/d15/Day15.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2022.d15
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
import kotlin.math.abs
// (x, y) - position of this sensor
// (bx, by) - position of closest beacon to this sensor
data class Sensor(val x: Int, val... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 2,741 | advent-of-code | MIT License |
src/day12/Day12.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day12
import readLines
fun List<CharArray>.findEndpoints(): Pair<Pair<Int, Int>?, Pair<Int, Int>?> {
var start: Pair<Int, Int>? = null
var end: Pair<Int, Int>? = null
for (i in this.indices) {
for (j in this[i].indices) {
if (this[i][j] == 'E') {
start = Pair(i... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 2,315 | aoc2022 | Apache License 2.0 |
src/day11/Day11.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day11
import readInput
fun main() {
data class Monkey(
val items: ArrayDeque<Long>,
val op: String,
val divBy: Long,
val throwWhenTrue: Int,
val throwWhenFalse: Int,
var inspectCount: Long = 0L
)
fun buildMonkey(input: List<String>): List<Monkey> ... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 2,840 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day12Data.kt | yigitozgumus | 572,855,908 | false | {"Kotlin": 26037} | package days
import utils.SolutionData
import utils.Utils.getNeighbors
fun main() = with(Day12Data()) {
println(" --- Part 1 --- ")
solvePart1()
println(" --- Part 2 --- ")
solvePart2()
}
data class Point(val x: Int, val y: Int, val value: Char) {
fun getFilteredValue(): Char = when(value) {
'S' -> '... | 0 | Kotlin | 0 | 0 | 9a3654b6d1d455aed49d018d9aa02d37c57c8946 | 1,668 | AdventOfCode2022 | MIT License |
src/day09/Day09.kt | xxfast | 572,724,963 | false | {"Kotlin": 32696} | package day09
import day09.Direction.*
import readLines
import kotlin.math.abs
enum class Direction(val dx: Int, val dy: Int) { R(+1, 0), U(0, -1), L(-1, 0), D(0, +1) }
typealias Move = Pair<Direction, Int>
val List<String>.moves: List<Move>
get() = this.map {
it.split(" ").let { (direction, amount) -> valueOf... | 0 | Kotlin | 0 | 1 | a8c40224ec25b7f3739da144cbbb25c505eab2e4 | 2,542 | advent-of-code-22 | Apache License 2.0 |
y2018/src/main/kotlin/adventofcode/y2018/Day10.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2018
import adventofcode.io.AdventSolution
import kotlin.math.abs
object Day10 : AdventSolution(2018, 10, "The Stars Align") {
override fun solvePartOne(input: String) = parse(input).findMessage().value.asMessage()
override fun solvePartTwo(input: String) = parse(input).findMessage().i... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 2,268 | advent-of-code | MIT License |
y2023/src/main/kotlin/adventofcode/y2023/Day14.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2023
import adventofcode.io.AdventSolution
import adventofcode.util.algorithm.transpose
import adventofcode.util.collections.splitAfter
import adventofcode.util.collections.splitBefore
import adventofcode.util.collections.takeWhileDistinct
fun main() {
Day14.solve()
}
object Day14 : AdventS... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,838 | advent-of-code | MIT License |
src/main/kotlin/dev/wilerson/aoc/day2/Day02.kt | wilerson | 572,902,668 | false | {"Kotlin": 8272} | package dev.wilerson.aoc.day2
import dev.wilerson.aoc.utils.readInput
fun main() {
val input = readInput("day2input")
// part 1
val part1Score = input.sumOf { line ->
val (opponentHand, ourHand) = line.split(" ").map { parseHand(it) }
ourHand.score + ourHand.match(opponentHand).score
... | 0 | Kotlin | 0 | 0 | d6121ef600783c18696211d43b62284f4700adeb | 1,781 | kotlin-aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day03.kt | bent-lorentzen | 727,619,283 | false | {"Kotlin": 68153} | import java.lang.Integer.max
import java.time.LocalDateTime
import java.time.ZoneOffset
import kotlin.math.min
fun main() {
fun findNumbers(line: String): List<Pair<String, Int>> {
var startIndex = 0
return line.split(Regex("\\D+"))
.filterNot { it.isEmpty() }
.map {
... | 0 | Kotlin | 0 | 0 | 41f376bd71a8449e05bbd5b9dd03b3019bde040b | 2,847 | aoc-2023-in-kotlin | Apache License 2.0 |
src/Day07.kt | olezhabobrov | 572,687,414 | false | {"Kotlin": 27363} | fun main() {
fun List<String>.toPath(): String = this.joinToString(separator = "/")
fun part1(input: List<String>): Int {
val currentPosition = mutableListOf("")
val sizeMap = mutableMapOf<String, Int>()
input.forEach { line ->
val lineSplited = line.split(" ")
i... | 0 | Kotlin | 0 | 0 | 31f2419230c42f72137c6cd2c9a627492313d8fb | 3,059 | AdventOfCode | Apache License 2.0 |
src/Day07.kt | emmanueljohn1 | 572,809,704 | false | {"Kotlin": 12720} | fun main() {
data class File(
val parentPath: String,
val name: String,
val size: Long? = null
)
fun joinPath(parent: String, path: String): String {
if (parent.endsWith("/")) return parent + path
return "$parent/$path"
}
fun getParentFromPath(path: String):... | 0 | Kotlin | 0 | 0 | 154db2b1648c9d12f82aa00722209741b1de1e1b | 3,584 | advent22 | Apache License 2.0 |
AdventOfCodeDay03/src/nativeMain/kotlin/Day03.kt | bdlepla | 451,523,596 | false | {"Kotlin": 153773} | class Day03(private val lines:List<String>) {
val width = lines[0].length
val height = lines.count()
fun solvePart1() = countTrees(3, 1, lines)
fun solvePart1a() = treesOnSlope(3 to 1)
private fun treesOnSlope(slope:Pair<Int,Int>) = path(slope).count{ it in lines }
private operator fun List<Str... | 0 | Kotlin | 0 | 0 | 043d0cfe3971c83921a489ded3bd45048f02ce83 | 1,545 | AdventOfCode2020 | The Unlicense |
aoc2023/day11.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2023
import utils.InputRetrieval
import kotlin.math.max
import kotlin.math.min
fun main() {
Day11.execute()
}
private object Day11 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
private fun part1(in... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 2,811 | Advent-Of-Code | MIT License |
src/Day13.kt | weberchu | 573,107,187 | false | {"Kotlin": 91366} | private data class Packet(
val list: List<Packet>?,
val integer: Int?
) : Comparable<Packet> {
override fun toString(): String {
return list?.toString() ?: integer.toString()
}
// negative if self is right order, positive if not, 0 if equal
override fun compareTo(other: Packet): Int {
... | 0 | Kotlin | 0 | 0 | 903ff33037e8dd6dd5504638a281cb4813763873 | 2,683 | advent-of-code-2022 | Apache License 2.0 |
archive/2022/Day11.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | private const val EXPECTED_1 = 10605L
private const val EXPECTED_2 = 2713310158L
private class Monkey {
val items = mutableListOf<Long>()
var testDiv = 0L
var trueMonk = 0
var falseMonk = 0
lateinit var operation: (Long) -> Long
var inspectCount = 0L
}
private class Day11(isTest: Boolean) : So... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 3,285 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/se/brainleech/adventofcode/aoc2021/Aoc2021Day09.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
import java.util.stream.Stream
import kotlin.streams.toList
class Aoc2021Day09 {
companion object {
private const val MAX_HEIGHT = '9'
... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 3,770 | adventofcode | MIT License |
src/main/kotlin/com/groundsfam/advent/y2015/d06/Day06.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2015.d06
import com.groundsfam.advent.DATAPATH
import kotlin.io.path.div
import kotlin.io.path.useLines
enum class Action {
TurnOn,
TurnOff,
Toggle,
}
data class Instruction(val action: Action, val fromX: Int, val fromY: Int, val toX: Int, val toY: Int)
fun parseInstruction... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 2,770 | advent-of-code | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.