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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
advent-of-code-2023/src/main/kotlin/eu/janvdb/aoc2023/day06/day06.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2023.day06
import eu.janvdb.aocutil.kotlin.readLines
//const val FILENAME = "input06-test.txt"
const val FILENAME = "input06.txt"
fun main() {
val lines = readLines(2023, FILENAME)
part1(lines)
part2(lines)
}
private fun part1(lines: List<String>) {
val times = lines[0].split(":")[1].trim()... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,227 | advent-of-code | Apache License 2.0 |
aoc-2021/src/commonMain/kotlin/fr/outadoc/aoc/twentytwentyone/Day14.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwentyone
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
class Day14 : Day<Long> {
private val input = readDayInput()
.split("\n\n")
.map { block -> block.lines() }
private val template = input.first().first().toList()
private... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 2,568 | adventofcode | Apache License 2.0 |
src/Day08.kt | TheGreatJakester | 573,222,328 | false | {"Kotlin": 47612} | import utils.string.asLines
import utils.readInputAsText
import utils.runSolver
private val dayNumber: String = "08"
private val testSolution1 = 21
private val testSolution2 = null
private typealias Grid = List<List<Int>>
private typealias MutableGrid = MutableList<MutableList<Int>>
fun Grid.print() {
forEach {... | 0 | Kotlin | 0 | 0 | c76c213006eb8dfb44b26822a44324b66600f933 | 3,282 | 2022-AOC-Kotlin | Apache License 2.0 |
src/day12/Day12.kt | maxmil | 578,287,889 | false | {"Kotlin": 32792} | package day12
import println
import readInput
fun List<String>.parse() =
flatMap { line -> line.split("-").let { listOf(Pair(it[0], it[1]), Pair(it[1], it[0])) } }
.groupBy { it.first }
.mapValues { entry -> entry.value.map { it.second }.toSet() }
fun countPaths(input: List<String>, allowOneCaveT... | 0 | Kotlin | 0 | 0 | 246353788b1259ba11321d2b8079c044af2e211a | 1,545 | advent-of-code-2021 | Apache License 2.0 |
kotlin/src/main/kotlin/year2021/Day04.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2021
private class Box(val number: Int) {
var checked = false
private set
fun check() {
this.checked = true
}
}
private class Board(val rows: List<List<Box>>) {
fun checkNumber(number: Int) {
rows.forEach { row ->
row.forEach { box ->
if... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 3,358 | advent-of-code | MIT License |
src/Day07.kt | mikemac42 | 573,071,179 | false | {"Kotlin": 45264} | import java.io.File
fun main() {
val testInput = """${'$'} cd /
${'$'} ls
dir a
14848514 b.txt
8504156 c.dat
dir d
${'$'} cd a
${'$'} ls
dir e
29116 f
2557 g
62596 h.lst
${'$'} cd e
${'$'} ls
584 i
${'$'} cd ..
${'$'} cd ..
${'$'} cd d
${'$'} ls
4060174 j
8033020 d.log
5626152 d.ext
7214296 k"""
val testInput2 = "... | 0 | Kotlin | 1 | 0 | 909b245e4a0a440e1e45b4ecdc719c15f77719ab | 2,922 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2023/2023-01.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, "01-input")
val test1 = readInputLines(2023, "01-test1")
val test2 = readInputLines(2023, "01-test2")
p... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,544 | advent-of-code | MIT License |
src/main/kotlin/aoc23/Day02.kt | tahlers | 725,424,936 | false | {"Kotlin": 65626} | package aoc23
import kotlin.math.max
object Day02 {
data class Drawing(val redCubes: Int = 0, val greenCubes: Int = 0, val blueCubes: Int = 0)
data class Game(val id: Int, val drawings: List<Drawing>)
private val redRegEx = """(\d+) red""".toRegex()
private val greenRegEx = """(\d+) green""".toRegex... | 0 | Kotlin | 0 | 0 | 0cd9676a7d1fec01858ede1ab0adf254d17380b0 | 2,442 | advent-of-code-23 | Apache License 2.0 |
src/main/kotlin/days/Day2.kt | nicopico-dev | 726,255,944 | false | {"Kotlin": 37616} | package days
import kotlin.math.max
class Day2(
inputFileNameOverride: String? = null,
) : Day(2, inputFileNameOverride) {
override fun partOne(): Any {
val hypothesis = Hypothesis(
red = 12,
green = 13,
blue = 14,
)
return inputList
.ma... | 0 | Kotlin | 0 | 0 | 1a13c8bd3b837c1ce5b13f90f326f0277249d23e | 2,803 | aoc-2023 | Creative Commons Zero v1.0 Universal |
Round 1A - B. Ratatouille/src/app.kt | amirkhanyana | 110,548,909 | false | {"Kotlin": 20514} | import java.util.*
fun main(args: Array<String>) {
val input = Scanner(System.`in`)
val T = input.nextInt()
var Ti = 1
while (Ti <= T) {
val N = input.nextInt()
val P = input.nextInt()
val recipe = IntArray(N, { input.nextInt() })
val packages = Array(N, { IntArray(P, { ... | 0 | Kotlin | 0 | 0 | 25a8e6dbd5843e9d4a054d316acc9d726995fffe | 3,015 | Google-Code-Jam-2017-Problem-Kotlin-Solutions | The Unlicense |
src/Day02.kt | ChrisCrisis | 575,611,028 | false | {"Kotlin": 31591} | import java.lang.IllegalStateException
fun main() {
fun part1(input: List<String>): Int {
return input.map {
it.split(" ")
}.map { (opo, pl) ->
val opponentChoice = Choice.fromOpponent(opo)
GameMove(
opponentChoice,
Choice.... | 1 | Kotlin | 0 | 0 | 732b29551d987f246e12b0fa7b26692666bf0e24 | 2,903 | aoc2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/adrielm/aoc2020/solutions/day03/Day03.kt | Adriel-M | 318,860,784 | false | null | package com.adrielm.aoc2020.solutions.day03
import com.adrielm.aoc2020.common.Solution
import org.koin.dsl.module
class Day03 : Solution<List<String>, Long>(3) {
private val mapping = mapOf(
'.' to Tile.OPEN,
'#' to Tile.TREE
)
override fun solveProblem1(input: List<String>): Long {
... | 0 | Kotlin | 0 | 0 | 8984378d0297f7bc75c5e41a80424d091ac08ad0 | 1,584 | advent-of-code-2020 | MIT License |
aoc-2015/src/main/kotlin/aoc/AocDay24.kt | triathematician | 576,590,518 | false | {"Kotlin": 615974} | package aoc
class AocDay24: AocDay(24) {
companion object { @JvmStatic fun main(args: Array<String>) { AocDay24().run() } }
override val testinput = """
1
2
3
4
5
7
8
9
10
11
""".trimIndent().lines()
fun List<String>.pars... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 2,544 | advent-of-code | Apache License 2.0 |
advent-of-code-2023/src/main/kotlin/eu/janvdb/aoc2023/day13/day13.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2023.day13
import eu.janvdb.aocutil.kotlin.readGroupedLines
import kotlin.math.min
//const val FILENAME = "input13-test.txt"
const val FILENAME = "input13.txt"
fun main() {
val matrices = readGroupedLines(2023, FILENAME).map { Matrix.parse(it) }
val sums1 = matrices.map { it.part1() }
printl... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,215 | advent-of-code | Apache License 2.0 |
src/day03/Day03.kt | lpleo | 572,702,403 | false | {"Kotlin": 30960} | package day03
import readInput
fun main() {
fun part1(input: List<String>): Int {
return input
.map { rucksack -> arrayOf(rucksack.substring(0, rucksack.length / 2), rucksack.substring((rucksack.length / 2), rucksack.length)) }
.map { compartments ->
co... | 0 | Kotlin | 0 | 0 | 115aba36c004bf1a759b695445451d8569178269 | 1,434 | advent-of-code-2022 | Apache License 2.0 |
src/year2022/day05/Day05.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2022.day05
import check
import readInput
import java.util.*
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("2022", "Day05_test")
check(part1(testInput), "CMZ")
check(part2(testInput), "MCD")
val input = readInput("2022", "D... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 3,315 | AdventOfCode | Apache License 2.0 |
solutions/round1/B/subtransmutation/src/main/kotlin/subtransmutation/SubtransmutationSolution.kt | Lysoun | 351,224,145 | false | null | import java.lang.Integer.max
data class ProblemInput(val metalTypesNumber: Int, val spells: List<Int>, val unitsRequired: List<Int>)
fun main(args: Array<String>) {
val casesNumber = readLine()!!.toInt()
for (i in 1..casesNumber) {
val line1 = readLine()!!.split(" ").map { it.toInt() }
val li... | 0 | Kotlin | 0 | 0 | 98d39fcab3c8898bfdc2c6875006edcf759feddd | 2,803 | google-code-jam-2021 | MIT License |
2022/src/main/kotlin/day19.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import Day19.Resource.geode
import Day19.Resource.ore
import utils.Component4
import utils.Parser
import utils.Solution
import utils.Vec4i
import utils.cut
import utils.mapItems
fun main() {
Day19.run()
}
object Day19 : Solution<List<Day19.Blueprint>>() {
override val name = "day19"
override val parser = Parser... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 3,898 | aoc_kotlin | MIT License |
src/commonMain/kotlin/com/jwoolston/cluster/RankOrderCluster.kt | jwoolston | 288,544,510 | false | null | package com.jwoolston.cluster
import kotlin.math.min
fun <V : Number> clusterOrderedList(cluster: Cluster<V>, clusters: List<Cluster<V>>): List<Cluster<V>> {
return clusters.sortedBy { cluster.distance(it) }
}
/**
* Calculates the asymmetric rank order distance between two clusters as described in Equation 1
*... | 0 | Kotlin | 0 | 0 | 837da7f2add2c7fb29da1d93029ab4279eacb2e5 | 5,542 | RankOrderCluster | Apache License 2.0 |
src/Day25.kt | MartinsCode | 572,817,581 | false | {"Kotlin": 77324} | import kotlin.math.pow
fun digitValue(sign: Char): Long {
return when (sign) {
'0' -> 0L
'1' -> 1L
'2' -> 2L
'-' -> -1L
'=' -> -2L
else -> 0L
}
}
fun desnafuify(snafu: String): Long {
val snafuDigits = snafu.toCharArray()
var value = 0L
for (i in 0..... | 0 | Kotlin | 0 | 0 | 1aedb69d80ae13553b913635fbf1df49c5ad58bd | 1,900 | AoC-2022-12-01 | Apache License 2.0 |
src/commonMain/kotlin/ai/hypergraph/kaliningraph/types/Types.kt | breandan | 245,074,037 | false | {"Kotlin": 1482924, "Haskell": 744, "OCaml": 200} | package ai.hypergraph.kaliningraph.types
/** Corecursive Fibonacci sequence of [Nat]s **/
tailrec fun <T> Nat<T>.fibonacci(
n: T,
seed: V2<T> = nil cc one,
fib: (V2<T>) -> V2<T> = { (a, b) -> b cc a + b },
i: T = nil,
): T =
if (i == n) fib(seed).first
else fibonacci(n = n, seed = fib(seed), i = i.next())
... | 0 | Kotlin | 8 | 100 | c755dc4858ed2c202c71e12b083ab0518d113714 | 6,161 | galoisenne | Apache License 2.0 |
src/Day09.kt | Akhunzaada | 573,119,655 | false | {"Kotlin": 23755} | import java.lang.Exception
import kotlin.math.abs
data class Point(var x: Int, var y: Int) {
infix fun moveTo(delta: Point) {
x += delta.x
y += delta.y
}
infix fun follow(point: Point) {
if (abs(x-point.x) > 1 || abs(y-point.y) > 1) {
x += if (x < point.x) +1 else if (x... | 0 | Kotlin | 0 | 0 | b2754454080989d9579ab39782fd1d18552394f0 | 1,995 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | peterfortuin | 573,120,586 | false | {"Kotlin": 22151} | fun main() {
fun part1(input: List<String>): Int {
return input.map { rps ->
when (rps) {
"A X" -> 3 + 1// Rock rock
"A Y" -> 6 + 2// Rock paper
"A Z" -> 0 + 3// Rock scissors
"B X" -> 0 + 1// Paper rock
"B Y" -> 3 ... | 0 | Kotlin | 0 | 0 | c92a8260e0b124e4da55ac6622d4fe80138c5e64 | 1,526 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/be/tabs_spaces/advent2021/days/Day15.kt | janvryck | 433,393,768 | false | {"Kotlin": 58803} | package be.tabs_spaces.advent2021.days
import java.util.*
class Day15 : Day(15) {
override fun partOne() = Cave(inputList).lowestRiskPath(Point(0, 0))
override fun partTwo() = Cave(inputList, expand = true).lowestRiskPath(Point(0, 0))
class Cave(rawInput: List<String>, expand: Boolean = false) {
... | 0 | Kotlin | 0 | 0 | f6c8dc0cf28abfa7f610ffb69ffe837ba14bafa9 | 2,829 | advent-2021 | Creative Commons Zero v1.0 Universal |
src/Utils.kt | drademacher | 725,945,859 | false | {"Kotlin": 76037} | import kotlin.io.path.Path
import kotlin.io.path.readLines
import kotlin.io.path.readText
import kotlin.math.abs
import kotlin.math.sqrt
fun readLines(
year: String,
day: String,
) = Path("src/year$year/resources/$day.txt").readLines()
fun readFile(
year: String,
day: String,
) = Path("src/year$year/r... | 0 | Kotlin | 0 | 0 | 4c4cbf677d97cfe96264b922af6ae332b9044ba8 | 1,535 | advent_of_code | MIT License |
src/Day04/Day04.kt | ctlevi | 578,257,705 | false | {"Kotlin": 10889} | fun main() {
fun parseElfPair(row: String): Pair<Set<Int>, Set<Int>> {
val (first, second) = row.split(',')
val (firstOne, firstTwo) = first.split('-')
val firstElfRange = (firstOne.toInt()..firstTwo.toInt()).toSet()
val (secondOne, secondTwo) = second.split('-')
val secondEl... | 0 | Kotlin | 0 | 0 | 0fad8816e22ec0df9b2928983713cd5c1ac2d813 | 1,480 | advent_of_code_2022 | Apache License 2.0 |
src/y2015/Day07.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2015
import util.readInput
data class Signal(
val instruction: String,
var result: UShort? = null
) {
fun update(result: UShort): UShort {
this.result = result
return result
}
}
fun lShift(x: UShort, y: Int) : UShort {
return x.rotateLeft(y) and (UShort.Companion.MAX_VALU... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 3,007 | advent-of-code | Apache License 2.0 |
2022/src/test/kotlin/Day13.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.min
private data class Packet(val integer: Int?, val packets: List<Packet>?) : Comparable<Packet> {
constructor() : this (null, null)
constructor(integer: Int) : this (integer, null)
constructor(packets: List<... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 3,360 | adventofcode | MIT License |
src/main/kotlin/be/swsb/aoc2021/day4/Day4.kt | Sch3lp | 433,542,959 | false | {"Kotlin": 90751} | package be.swsb.aoc2021.day4
import java.util.*
object Day4 {
fun solve1(input: List<String>): Int {
return solve(input).first().let { (board, winningNumber) ->
board.findUnmarked().sum() * winningNumber
}
}
fun solve2(input: List<String>): Int {
return solve(input).la... | 0 | Kotlin | 0 | 0 | 7662b3861ca53214e3e3a77c1af7b7c049f81f44 | 3,372 | Advent-of-Code-2021 | MIT License |
src/main/kotlin/com/github/michaelbull/advent2023/day19/System.kt | michaelbull | 726,012,340 | false | {"Kotlin": 195941} | package com.github.michaelbull.advent2023.day19
fun Sequence<String>.toSystem(): System {
var readingWorkflows = true
val workflows = mutableListOf<Workflow>()
val parts = mutableListOf<Part>()
for (line in this) {
if (line.isEmpty()) {
readingWorkflows = false
} else if (r... | 0 | Kotlin | 0 | 1 | ea0b10a9c6528d82ddb481b9cf627841f44184dd | 4,324 | advent-2023 | ISC License |
src/main/kotlin/g0401_0500/s0480_sliding_window_median/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0401_0500.s0480_sliding_window_median
// #Hard #Array #Hash_Table #Heap_Priority_Queue #Sliding_Window
// #2023_01_01_Time_409_ms_(100.00%)_Space_44.6_MB_(81.48%)
import java.util.TreeSet
class Solution {
fun medianSlidingWindow(nums: IntArray, k: Int): DoubleArray {
require(k >= 1) { "Input is ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,239 | LeetCode-in-Kotlin | MIT License |
2022/src/main/kotlin/day9_imp.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.Vec2i
import utils.badInput
import utils.cut
import kotlin.math.sign
fun main() {
Day9Imp.run()
}
enum class Direction(val delta: Vec2i) {
UP(Vec2i(0, 1)),
RIGHT(Vec2i(1, 0)),
DOWN(Vec2i(0, -1)),
LEFT(Vec2i(-1, 0))
}
object Day9Imp : Solution<List<Dire... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,588 | aoc_kotlin | MIT License |
leetcode/src/sort/Q169.kt | zhangweizhe | 387,808,774 | false | null | package sort
fun main() {
// 169. 多数元素
// https://leetcode-cn.com/problems/majority-element/
println(majorityElement2(intArrayOf(2,2,1,1,1,2,2)))
}
/**
* 排序法,排序后的数组,nums[n/2] 一定是众数
* 时间复杂度由排序算法决定
*/
fun majorityElement1(nums: IntArray): Int {
// 使用快速排序
quickSort(nums, 0, nums.size - 1)
ret... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,494 | kotlin-study | MIT License |
kotlin/src/Day03.kt | ekureina | 433,709,362 | false | {"Kotlin": 65477, "C": 12591, "Rust": 7560, "Makefile": 386} | import java.lang.Long.parseLong
data class BitCount(var ones: Long, var zeros: Long)
fun main() {
fun part1(input: List<String>): Long {
val initialCounts = input.first().map { bit ->
if (bit == '0') {
BitCount(0L, 1L)
} else {
BitCount(1L, 0L)
... | 0 | Kotlin | 0 | 1 | 391d0017ba9c2494092d27d22d5fd9f73d0c8ded | 2,967 | aoc-2021 | MIT License |
src/day4/day4.kt | mrm1st3r | 573,163,888 | false | {"Kotlin": 12713} | package day4
import Puzzle
fun findSubRange(ranges: Pair<IntRange, IntRange>): Boolean {
val left = ranges.first
val right = ranges.second
return (left.first >= right.first && left.last <= right.last)
|| (left.first <= right.first && left.last >= right.last)
}
fun convertToIntRanges(s: Strin... | 0 | Kotlin | 0 | 0 | d8eb5bb8a4ba4223331766530099cc35f6b34e5a | 1,266 | advent-of-code-22 | Apache License 2.0 |
src/Day02.kt | ajesh-n | 573,125,760 | false | {"Kotlin": 8882} | fun main() {
val strategyShapeMap = mapOf(
"A" to Shape.Rock,
"X" to Shape.Rock,
"B" to Shape.Paper,
"Y" to Shape.Paper,
"C" to Shape.Scissors,
"Z" to Shape.Scissors,
)
val strategyResultMap = mapOf(
"X" to Result.LOSE,
"Y" to Result.DRAW,
... | 0 | Kotlin | 0 | 0 | 2545773d7118da20abbc4243c4ccbf9330c4a187 | 2,875 | kotlin-aoc-2022 | Apache License 2.0 |
src/main/kotlin/Map.kt | alebedev | 573,733,821 | false | {"Kotlin": 82424} | import kotlin.math.abs
fun main() = AocMap.solve()
private object AocMap {
fun solve() {
val (board, moves) = readInput()
println("$moves")
// board.print()
// val pos = applyMoves(board, moves)
println("Board size ${board.cells.size}x${board.cells.first().size}")
pri... | 0 | Kotlin | 0 | 0 | d6ba46bc414c6a55a1093f46a6f97510df399cd1 | 6,284 | aoc2022 | MIT License |
app/src/main/kotlin/advent/of/code/twentytwenty/Day1.kt | obarcelonap | 320,300,753 | false | null | package advent.of.code.twentytwenty
fun main(args: Array<String>) {
val result = 2020
val numbers: List<Int> = getResourceAsLines("/day1-input")
.map { it.trim().toIntOrNull() }
.toList()
.filterNotNull()
val pairs = pairsAdding(result, numbers)
println("Part 1: fou... | 0 | Kotlin | 0 | 0 | a721c8f26738fe31190911d96896f781afb795e1 | 2,352 | advent-of-code-2020 | MIT License |
src/day03/Day03.kt | sophiepoole | 573,708,897 | false | null | package day03
import readInput
val priority: Map<Char, Int> = (('a'..'z' zip 1..26) + ('A'..'Z' zip 27..52)).toMap()
fun main() {
fun checkRucksack(rucksack: String): Int {
val items = rucksack.toList()
val n = items.size // get the size of the list
val compartment1 = items.subList(... | 0 | Kotlin | 0 | 0 | 00ad7d82cfcac2cb8a902b310f01a6eedba985eb | 1,291 | advent-of-code-2022 | Apache License 2.0 |
aoc-2015/src/main/kotlin/aoc/AocDay9.kt | triathematician | 576,590,518 | false | {"Kotlin": 615974} | package aoc
import aoc.util.chunk
class AocDay9: AocDay(9) {
companion object { @JvmStatic fun main(args: Array<String>) { AocDay9().run() } }
override val testinput = """
London to Dublin = 464
London to Belfast = 518
Dublin to Belfast = 141
""".trimIndent().lines()
fun List... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 2,098 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2021/2021-23.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2021
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
import com.github.ferinagy.adventOfCode.searchGraph
fun main() {
val input = readInputLines(2021, "23-input")
val test1 = readInputLines(2021, "23-test1")
... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 4,559 | advent-of-code | MIT License |
src/main/kotlin/days/Day12.kt | jgrgt | 575,475,683 | false | {"Kotlin": 94368} | package days
import util.MutableMatrix
import util.Point
class Day12 : Day(12) {
override fun partOne(): Any {
val heights = MutableMatrix.fromSingleDigits(inputList) { c ->
c
}
val shortestPath = heights.map { _ -> heights.height() * heights.width() }
val game = Day12... | 0 | Kotlin | 0 | 0 | 5174262b5a9fc0ee4c1da9f8fca6fb86860188f4 | 3,152 | aoc2022 | Creative Commons Zero v1.0 Universal |
src/day12/Day12.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day12
import readInput
class Node(val id: Int) {
var shortestPath = mutableListOf<Node>()
var distanceToSource = Integer.MAX_VALUE;
var adjacentNodes = mutableMapOf<Node, Int>()
}
fun getLowestDistanceNode(unsettledNodes: Set<Node>): Node {
var lowestDistanceNode = unsettledNodes.first()
... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 6,003 | AdventOfCode2022 | Apache License 2.0 |
src/day07/Day07.kt | gillyobeast | 574,413,213 | false | {"Kotlin": 27372} | package day07
import utils.appliedTo
import utils.readInput
/// strategy:
// add `/` to tree
// dirname = "/"
// split input by lines starting $
// for each of those:
// if `cd ..`, set dirname to 'parent'
// if `cd dirname` set `currentDir` to `dirname`
// if `ls`, iterate over remaining lines:
/... | 0 | Kotlin | 0 | 0 | 8cdbb20c1a544039b0e91101ec3ebd529c2b9062 | 5,265 | aoc-2022-kotlin | Apache License 2.0 |
src/Day03.kt | derkalaender | 433,927,806 | false | {"Kotlin": 4155} | fun main() {
fun List<String>.charsForColumn(n: Int) = groupingBy { it[n] }.eachCount()
fun String.invertBinaryString() = map { if (it == '0') '1' else '0' }.joinToString("")
fun part1(input: List<String>): Int {
val charFreqPerColumn = input[0].indices.map { input.charsForColumn(it) }
val... | 0 | Kotlin | 0 | 0 | bf258ea0cf7cada31288a91d2204d5c7b3492433 | 1,580 | aoc2021 | The Unlicense |
21.kt | pin2t | 725,922,444 | false | {"Kotlin": 48856, "Go": 48364, "Shell": 54} | import kotlin.math.pow
fun main() {
val up = Pair(0, -1); val right = Pair(1, 0); val down = Pair(0, 1); val left = Pair(-1, 0)
val rocks = HashSet<Pair<Int, Int>>()
var rows = 0
fun reachable(from: Pair<Int, Int>, steps: Int): Int {
var reach = HashSet<Pair<Int, Int>>()
reach.add(from... | 0 | Kotlin | 1 | 0 | 7575ab03cdadcd581acabd0b603a6f999119bbb6 | 2,303 | aoc2023 | MIT License |
leetcode2/src/leetcode/top-k-frequent-elements.kt | hewking | 68,515,222 | false | null | package leetcode
import java.util.*
/**
* 347. 前 K 个高频元素
* https://leetcode-cn.com/problems/top-k-frequent-elements/
* @program: leetcode
* @description: ${description}
* @author: hewking
* @create: 2019-10-21 11:32
* 给定一个非空的整数数组,返回其中出现频率前 k 高的元素。
示例 1:
输入: nums = [1,1,1,2,2,3], k = 2
输出: [1,2]
示例 2:
输入: nu... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,807 | leetcode | MIT License |
src/aoc2022/day18/aoC18.kt | Saxintosh | 576,065,000 | false | {"Kotlin": 30013} | package aoc2022.day18
import readLines
private val incList = listOf(
P3(-1, 0, 0), P3(1, 0, 0),
P3(0, -1, 0), P3(0, 1, 0),
P3(0, 0, -1), P3(0, 0, 1),
)
private data class P3(val x: Int, val y: Int, val z: Int) {
fun getAdj(): List<P3> = incList.map { P3(x + it.x, y + it.y, z + it.z) }
fun faces() = listOf(
Fa... | 0 | Kotlin | 0 | 0 | 877d58367018372502f03dcc97a26a6f831fc8d8 | 2,600 | aoc2022 | Apache License 2.0 |
2015/Day02/src/main/kotlin/Main.kt | mcrispim | 658,165,735 | false | null | import java.io.File
fun main() {
fun surface(l: Int, w: Int, h: Int) = 2 * l * w + 2 * w * h + 2 * h * l
fun extraPaper(l: Int, w: Int, h: Int): Int {
val (dim1, dim2) = listOf(l, w, h).sorted().take(2)
return dim1 * dim2
}
fun ribbon(l: Int, w: Int, h: Int): Int {
val (dim1... | 0 | Kotlin | 0 | 0 | 2f4be35e78a8a56fd1e078858f4965886dfcd7fd | 1,380 | AdventOfCode | MIT License |
src/Day09.kt | haraldsperre | 572,671,018 | false | {"Kotlin": 17302} | import kotlin.math.abs
import kotlin.math.sign
fun main() {
fun moveHead(position: Pair<Int, Int>, direction: Char): Pair<Int, Int> = when (direction) {
'U' -> position.copy(first = position.first + 1)
'D' -> position.copy(first = position.first - 1)
'L' -> position.copy(second = position.... | 0 | Kotlin | 0 | 0 | c4224fd73a52a2c9b218556c169c129cf21ea415 | 2,109 | advent-of-code-2022 | Apache License 2.0 |
src/year2021/15/Day15.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2021.`15`
import readInput
import java.util.*
private data class Point(
val x: Int,
val y: Int,
)
private typealias PointsToValues = Map<Point, Int>
private typealias MutablePointsToValues = MutableMap<Point, Int>
private fun infinitePaths(initialPoint: Point, initialValues: PointsToValues): Poi... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 4,018 | KotlinAdventOfCode | Apache License 2.0 |
src/Day04.kt | brunojensen | 572,665,994 | false | {"Kotlin": 13161} | private fun String.toRange(): Pair<IntRange, IntRange> {
val splitted = this.split(",")
return splitted[0].substringBefore("-").toInt()..splitted[0].substringAfter("-").toInt() to
splitted[1].substringBefore("-").toInt()..splitted[1].substringAfter("-").toInt()
}
private infix fun IntRange.fullyContains(other... | 0 | Kotlin | 0 | 0 | 2707e76f5abd96c9d59c782e7122427fc6fdaad1 | 1,143 | advent-of-code-kotlin-1 | Apache License 2.0 |
app/src/y2021/day10/Day10SyntaxScoring.kt | henningBunk | 432,858,990 | false | {"Kotlin": 124495} | package y2021.day10
import common.Answers
import common.AocSolution
import common.annotations.AoCPuzzle
fun main(args: Array<String>) {
Day10SyntaxScoring().solveThem()
}
@AoCPuzzle(2021, 10)
class Day10SyntaxScoring : AocSolution {
override val answers = Answers(samplePart1 = 26397, samplePart2 = 288957, p... | 0 | Kotlin | 0 | 0 | 94235f97c436f434561a09272642911c5588560d | 2,612 | advent-of-code-2021 | Apache License 2.0 |
src/main/day11/Day11.kt | rolf-rosenbaum | 543,501,223 | false | {"Kotlin": 17211} | package day11
import kotlin.math.min
const val serial = 5177
const val gridSize = 300
val gridMap = (1..gridSize).flatMap { y ->
(1..gridSize).map { x ->
Point(x, y).let {
it to it.power()
}
}
}.associate { it.first to it.second }
fun part1(): Point {
return gridMap.maxByOr... | 0 | Kotlin | 0 | 0 | dfd7c57afa91dac42362683291c20e0c2784e38e | 1,620 | aoc-2018 | Apache License 2.0 |
kotlin/src/main/kotlin/com/pbh/soft/day3/Day3Solver.kt | phansen314 | 579,463,173 | false | {"Kotlin": 105902} | package com.pbh.soft.day3
import cc.ekblad.konbini.*
import com.pbh.soft.common.Solver
import com.pbh.soft.common.grid.Col
import com.pbh.soft.common.grid.HasColumn
import com.pbh.soft.common.grid.Loc
import com.pbh.soft.common.grid.Row
import com.pbh.soft.common.parsing.ParsingUtils.onSuccess
import com.pbh.soft.comm... | 0 | Kotlin | 0 | 0 | 7fcc18f453145d10aa2603c64ace18df25e0bb1a | 3,318 | advent-of-code | MIT License |
src/main/kotlin/day17.kt | gautemo | 725,273,259 | false | {"Kotlin": 79259} | import shared.*
/* I'ts slow, but it both A and B completes in 30 minutes */
fun main() {
val input = Input.day(17)
println(day17A(input))
println(day17B(input))
}
fun day17A(input: Input): Int {
val map = XYMap(input) { it.digitToInt() }
return aStarIsh(map)
}
fun day17B(input: Input): Int {
... | 0 | Kotlin | 0 | 0 | 6862b6d7429b09f2a1d29aaf3c0cd544b779ed25 | 2,743 | AdventOfCode2023 | MIT License |
src/Day05.kt | Excape | 572,551,865 | false | {"Kotlin": 36421} | data class Instruction(val amount: Int, val source: Int, val dest: Int)
class CrateMover(private val stacks: List<ArrayDeque<String>>) {
fun moveSingleStacks(instruction: Instruction) {
val source = stacks[instruction.source]
val dest = stacks[instruction.dest]
repeat(instruction.amount) ... | 0 | Kotlin | 0 | 0 | a9d7fa1e463306ad9ea211f9c037c6637c168e2f | 2,774 | advent-of-code-2022 | Apache License 2.0 |
codeforces/codeton6/f.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.codeton6
val toBaseArray = LongArray(Long.SIZE_BITS)
private fun solve(): Long {
val (n, k) = readLongs()
val threshold = (n + 1) / k
fun timesK(m: Long) = if (m <= threshold) m * k else n + 1
fun toBase(m: Long): Int {
var i = 0
var mm = m
do {
toBaseArray[i++] = mm % k
mm /= k
... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,395 | competitions | The Unlicense |
src/Day04.kt | dmstocking | 575,012,721 | false | {"Kotlin": 40350} | fun main() {
fun part1(input: List<String>): Int {
return input
.filter { line ->
val (first, second) = line.split(",")
.map {
val (a, b) = it.split("-").map(String::toInt)
a..b
}
... | 0 | Kotlin | 0 | 0 | e49d9247340037e4e70f55b0c201b3a39edd0a0f | 1,258 | advent-of-code-kotlin-2022 | Apache License 2.0 |
app/src/main/kotlin/day03/Day03.kt | tobiasbexelius | 437,250,135 | false | {"Kotlin": 33606} | package day03
import common.InputRepo
import common.readSessionCookie
import common.solve
fun main(args: Array<String>) {
val day = 3
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay03Part1, ::solveDay03Part2)
}
fun solveDay03Part1(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | 3f9783e78e7507eeddde869cf24d34ec6e7e3078 | 1,806 | advent-of-code-21 | Apache License 2.0 |
src/main/kotlin/net/voldrich/aoc2021/Day14.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2021
import net.voldrich.BaseDay
import net.voldrich.minMax
// https://adventofcode.com/2021/day/14
fun main() {
Day14().run()
}
class Day14 : BaseDay() {
override fun task1() : Long {
val polymer = Polymer()
for (i in (1 .. 10)) polymer.multiply()
val (min, ma... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 2,949 | advent-of-code | Apache License 2.0 |
src/Day16.kt | frozbiz | 573,457,870 | false | {"Kotlin": 124645} | fun <E> Collection<E>.choose(n: Int): List<List<E>> {
if (n == 0) return emptyList()
if (n == 1) return this.map { listOf(it) }
val remaining = ArrayDeque(this)
val output = mutableListOf<List<E>>()
while (remaining.isNotEmpty()) {
val item = remaining.removeFirst()
for (list in rema... | 0 | Kotlin | 0 | 0 | 4feef3fa7cd5f3cea1957bed1d1ab5d1eb2bc388 | 11,096 | 2022-aoc-kotlin | Apache License 2.0 |
src/main/kotlin/aoc2021/day4/Bingo.kt | arnab | 75,525,311 | false | null | package aoc2021.day4
object Bingo {
data class Slot(val num: Int, val marked: Boolean = false)
data class Board(
val id: Int,
val slots: List<List<Slot>>
) {
companion object {
fun from(id: Int, data: String): Board {
val numbers = data.split("\n").map ... | 0 | Kotlin | 0 | 0 | 1d9f6bc569f361e37ccb461bd564efa3e1fccdbd | 3,180 | adventofcode | MIT License |
src/Day10.kt | fasfsfgs | 573,562,215 | false | {"Kotlin": 52546} | fun main() {
fun part1(input: List<String>): Int {
val registerValues = input.toRegisterValues()
return listOf(20, 60, 100, 140, 180, 220)
.sumOf { registerValues.signalStrength(it) }
}
fun part2(input: List<String>) {
input.toRegisterValues()
.chunked(40)
... | 0 | Kotlin | 0 | 0 | 17cfd7ff4c1c48295021213e5a53cf09607b7144 | 1,545 | advent-of-code-2022 | Apache License 2.0 |
src/main/java/Exercise16-part2.kt | cortinico | 317,667,457 | false | null | fun main() {
val input = object {}.javaClass.getResource("input-16.txt").readText().split("\n\n")
val ranges =
input[0]
.split("\n")
.associateBy(
{ it.substring(0, it.indexOf(":")) },
{
it.substring(it.indexOf(":") + 1).replac... | 1 | Kotlin | 0 | 4 | a0d980a6253ec210433e2688cfc6df35104aa9df | 2,065 | adventofcode-2020 | MIT License |
src/Day02.kt | BrianEstrada | 572,700,177 | false | {"Kotlin": 22757} | fun main() {
// Test Case
val testInput = readInput("Day02_test")
val part1TestResult = Day02.part1(testInput)
println(part1TestResult)
check(part1TestResult == 15)
val part2TestResult = Day02.part2(testInput)
println(part2TestResult)
check(part2TestResult == 12)
// Actual Case
... | 1 | Kotlin | 0 | 1 | 032a4693aff514c9b30e979e63560dc48917411d | 3,190 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/io/github/clechasseur/adventofcode2021/Day9.kt | clechasseur | 435,726,930 | false | {"Kotlin": 315943} | package io.github.clechasseur.adventofcode2021
import io.github.clechasseur.adventofcode2021.data.Day9Data
import io.github.clechasseur.adventofcode2021.dij.Dijkstra
import io.github.clechasseur.adventofcode2021.dij.Graph
import io.github.clechasseur.adventofcode2021.util.Direction
import io.github.clechasseur.advento... | 0 | Kotlin | 0 | 0 | 4b893c001efec7d11a326888a9a98ec03241d331 | 2,216 | adventofcode2021 | MIT License |
src/main/kotlin/day12/Solution.kt | TestaDiRapa | 573,066,811 | false | {"Kotlin": 50405} | package day12
import java.io.File
fun Char.distance(other: Char) =
if (this == 'E') other - 'z'
else if (this == 'S') other - 'a'
else if (other == 'E') 'z' - this
else if (other == 'S') 'a' - this
else other - this
data class DijkstraParams(
val dist: MutableMap<Pair<Int, Int>, Distance> = m... | 0 | Kotlin | 0 | 0 | b5b7ebff71cf55fcc26192628738862b6918c879 | 4,614 | advent-of-code-2022 | MIT License |
src/main/kotlin/day07/cards.kt | cdome | 726,684,118 | false | {"Kotlin": 17211} | package day07
import java.io.File
fun main() {
val file = File("src/main/resources/day07-cards").readLines()
file
.map { line ->
val (cards, bid) = line.split(" ")
Hand(cards.trim(), bid.trim().toInt())
}
.sorted()
.mapIndexed { order, hand -> (order + 1... | 0 | Kotlin | 0 | 0 | 459a6541af5839ce4437dba20019b7d75b626ecd | 3,260 | aoc23 | The Unlicense |
cz.wrent.advent/Day15.kt | Wrent | 572,992,605 | false | {"Kotlin": 206165} | package cz.wrent.advent
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun main() {
println(partOne(test, 10))
val result = partOne(input, 2000000)
println("15a: $result")
println(partTwo(test, 20))
println("15b: ${partTwo(input, 4000000)}")
}
private fun partOne(input: String, row: Int): ... | 0 | Kotlin | 0 | 0 | 8230fce9a907343f11a2c042ebe0bf204775be3f | 6,617 | advent-of-code-2022 | MIT License |
src/main/kotlin/day11/Code.kt | fcolasuonno | 317,324,330 | false | null | package day11
import isDebug
import java.io.File
import kotlin.system.measureTimeMillis
fun main() {
val name = if (isDebug()) "test.txt" else "input.txt"
System.err.println(name)
val dir = ::main::class.java.`package`.name
val input = File("src/main/kotlin/$dir/$name").readLines()
val (parsed, si... | 0 | Kotlin | 0 | 0 | e7408e9d513315ea3b48dbcd31209d3dc068462d | 3,125 | AOC2020 | MIT License |
src/Day19.kt | thpz2210 | 575,577,457 | false | {"Kotlin": 50995} | private class Solution19(input: List<String>) {
val blueprints = input.map { Blueprint.of(it) }
fun part1() = blueprints.sumOf { nextMinute(24, State.getInitialState(), it) * it.id }
fun part2() = blueprints.take(3).map { nextMinute(32, State.getInitialState(), it) }.reduce(Int::times)
fun nextMinut... | 0 | Kotlin | 0 | 0 | 69ed62889ed90692de2f40b42634b74245398633 | 4,480 | aoc-2022 | Apache License 2.0 |
src/Day09.kt | rifkinni | 573,123,064 | false | {"Kotlin": 33155, "Shell": 125} | import kotlin.math.abs
data class Coordinate9(var x: Int, var y: Int) {
private fun isTouching(other: Coordinate9): Boolean {
if (abs(this.x - other.x) <= 1 && abs(this.y - other.y) <= 1) {
return true
}
return false
}
fun follow(lead: Coordinate9) {
if (isTouch... | 0 | Kotlin | 0 | 0 | c2f8ca8447c9663c0ce3efbec8e57070d90a8996 | 2,961 | 2022-advent | Apache License 2.0 |
src/main/kotlin/com/colinodell/advent2023/Day12.kt | colinodell | 726,073,391 | false | {"Kotlin": 114923} | package com.colinodell.advent2023
class Day12(input: List<String>) {
private val records = input.map {
Record(
conditions = it.split(" ").first(),
expected = it.split(" ").last().split(",").map { it.toInt() }
)
}
private data class Record(val conditions: String, val... | 0 | Kotlin | 0 | 0 | 97e36330a24b30ef750b16f3887d30c92f3a0e83 | 1,962 | advent-2023 | MIT License |
src/Day09.kt | arnoutvw | 572,860,930 | false | {"Kotlin": 33036} | import java.util.LinkedList
import kotlin.math.abs
fun main() {
data class Point(var x: Int, var y: Int)
fun isTouching(head: Point, tail: Point) :Boolean {
if (abs(head.x - tail.x) <= 1 && abs(head.y - tail.y) <= 1) {
return true
}
return false
}
fun part1(input:... | 0 | Kotlin | 0 | 0 | 0cee3a9249fcfbe358bffdf86756bf9b5c16bfe4 | 3,416 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/dec21/Main.kt | dladukedev | 318,188,745 | false | null | package dec21
data class Recipe(
val ingredients: List<String>,
val allergens: List<Allergen>
)
enum class Allergen {
DAIRY,
FISH,
SOY,
NUTS,
SESAME,
PEANUTS,
WHEAT,
EGGS
}
fun parseInput(input: String): List<Recipe> {
return input.lines()
.map {
val (i... | 0 | Kotlin | 0 | 0 | d4591312ddd1586dec6acecd285ac311db176f45 | 3,664 | advent-of-code-2020 | MIT License |
src/Day03.kt | freszu | 573,122,040 | false | {"Kotlin": 32507} | fun main() {
fun priorityForChar(duplicate: Char) = when {
duplicate in 'a'..'z' -> duplicate.code - 'a'.code + 1
duplicate in 'A'..'Z' -> duplicate.code - 'A'.code + 27
else -> throw IllegalArgumentException("Invalid character")
}
fun part1(input: List<String>) = input.map { rucksa... | 0 | Kotlin | 0 | 0 | 2f50262ce2dc5024c6da5e470c0214c584992ddb | 1,192 | aoc2022 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem2492/Solution2.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2492
/**
* LeetCode page: [2492. Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/);
*/
class Solution2 {
/* Complexity:
* Time O(n+E) and Space O(n) where E is the size of roads;
*/
fun minSco... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,055 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/Day24.kt | Avataw | 572,709,044 | false | {"Kotlin": 99761} | package aoc
import aoc.Direction.*
fun solve24A(input: List<String>): Int {
val village = input.toVillage()
val start = village.start
return village.findShortestPathToEnd(Mover(start, 0)).moves
}
fun solve24B(input: List<String>): Int {
val village = input.toVillage()
val start = village.sta... | 0 | Kotlin | 2 | 0 | 769c4bf06ee5b9ad3220e92067d617f07519d2b7 | 4,313 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day19.kt | butnotstupid | 571,247,661 | false | {"Kotlin": 90768} | package days
class Day19 : Day(19) {
override fun partOne(): Any {
val timeLeft = 24
val blueprints = parseInput()
return blueprints.sumOf { blueprint ->
blueprint.id * maxGeodes(blueprint, State.start(timeLeft))
}
}
override fun partTwo(): Any {
val ti... | 0 | Kotlin | 0 | 0 | 4760289e11d322b341141c1cde34cfbc7d0ed59b | 5,689 | aoc-2022 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2022/2022-24.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2022
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.lcm
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
import com.github.ferinagy.adventOfCode.searchGraph
import com.github.ferin... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 2,961 | advent-of-code | MIT License |
kotlin/0135-candy.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | // O(n) linear sweep solution
class Solution {
fun candy(ratings: IntArray): Int {
val n = ratings.size
val candies = IntArray (n) { 1 }
for (i in 1 until n) {
if (ratings[i] > ratings[i - 1])
candies[i] = candies[i - 1] + 1
}
for (i in n - 2 dow... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,828 | leetcode | MIT License |
src/questions/UniquePaths.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
import java.math.BigInteger
import java.util.*
/**
* A robot is located in the top-left corner of a `m x n` grid (marked 'Start' in the diagram below).
* The robot can only move either down or right at any point in time.
* The robot is... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 5,627 | algorithms | MIT License |
src/aoc2023/Day13.kt | anitakar | 576,901,981 | false | {"Kotlin": 124382} | package aoc2023
import readInput
import kotlin.math.min
fun main() {
fun check(terrain: List<String>, split: Int): Boolean {
for (i in 1..min(split, terrain.size - split - 2)) {
val before = terrain[split - i]
val after = terrain[split + 1 + i]
if (after != before) retu... | 0 | Kotlin | 0 | 1 | 50998a75d9582d4f5a77b829a9e5d4b88f4f2fcf | 3,392 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day11.kt | andilau | 726,429,411 | false | {"Kotlin": 37060} | package days
@AdventOfCodePuzzle(
name = "Cosmic Expansion",
url = "https://adventofcode.com/2023/day/11",
date = Date(day = 11, year = 2023)
)
class Day11(input: List<String>) : Puzzle {
private val galaxies = input.extractOnly('#').toList()
override fun partOne(): Int {
return galaxies
... | 3 | Kotlin | 0 | 0 | 9a1f13a9815ab42d7fd1d9e6048085038d26da90 | 1,294 | advent-of-code-2023 | Creative Commons Zero v1.0 Universal |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day16.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwenty
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
class Day16 : Day<Long> {
companion object {
private val ruleRegex = Regex("^([a-z ]+): ([0-9]+)-([0-9]+) or ([0-9]+)-([0-9]+)$")
}
private data class Rule(val fieldName: String, va... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 3,918 | adventofcode | Apache License 2.0 |
src/Lesson3TimeComplexity/TapeEquilibrium.kt | slobodanantonijevic | 557,942,075 | false | {"Kotlin": 50634} | /**
* 100/100
* @param A
* @return
*/
fun solution(A: IntArray): Int {
var left = 0
var right = A.sum()
var min = 0
for (i in 1 until A.size) {
left += A[i - 1]
right -= A[i - 1]
val diff: Int = Math.abs(left - right)
min = getMin(i, diff, min)
}
return min
}
... | 0 | Kotlin | 0 | 0 | 155cf983b1f06550e99c8e13c5e6015a7e7ffb0f | 1,798 | Codility-Kotlin | Apache License 2.0 |
src/days/Day02/Day02.kt | SimaoMata | 573,172,347 | false | {"Kotlin": 3659} | package days.Day02
import readInput
//Part1
//A - Rock - X : 1 Point
//B - Paper - Y : 2 Points
//C - Scissors - Z : 3 Points
//W = 6
//D = 3
//L = 0
//Part2
//W = 6 Z
//D = 3 Y
//L = 0 X
fun main() {
// test if implementation meets criteria from the description, like:
val inputPart1 = readInput("Da... | 0 | Kotlin | 0 | 0 | bc3ba76e725b02c893aacc033c99169d7a022614 | 2,066 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/de/mbdevelopment/adventofcode/year2021/solvers/day9/Day9Puzzle2.kt | Any1s | 433,954,562 | false | {"Kotlin": 96683} | package de.mbdevelopment.adventofcode.year2021.solvers.day9
import de.mbdevelopment.adventofcode.year2021.solvers.PuzzleSolver
class Day9Puzzle2 : PuzzleSolver {
override fun solve(inputLines: Sequence<String>) = sizeSumOfThreeLargestBasins(inputLines).toString()
private fun sizeSumOfThreeLargestBasins(rawH... | 0 | Kotlin | 0 | 0 | 21d3a0e69d39a643ca1fe22771099144e580f30e | 2,806 | AdventOfCode2021 | Apache License 2.0 |
kotlin/problems/src/solution/SimulatedProgram.kt | lunabox | 86,097,633 | false | {"Kotlin": 146671, "Python": 38767, "JavaScript": 19188, "Java": 13966} | package solution
import data.structure.Employee
import java.util.*
import kotlin.collections.HashMap
import kotlin.collections.HashSet
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
class SimulatedProgram {
/**
* https://leetcode-cn.com/problems/robot-return-to-origin/
*/
fun ... | 0 | Kotlin | 0 | 0 | cbb2e3ad8f2d05d7cc54a865265561a0e391a9b9 | 21,253 | leetcode | Apache License 2.0 |
src/Day04.kt | cisimon7 | 573,872,773 | false | {"Kotlin": 41406} | fun main() {
fun part1(pairs: List<Pair<IntRange, IntRange>>): Int {
return pairs.count { (section1, section2) ->
val inter = section1 intersect section2
inter.containsAll(section1.toSet()) || inter.containsAll(section2.toSet())
}
}
fun part2(pairs: List<Pair<IntRang... | 0 | Kotlin | 0 | 0 | 29f9cb46955c0f371908996cc729742dc0387017 | 1,029 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/d5/D5_2.kt | MTender | 734,007,442 | false | {"Kotlin": 108628} | package d5
import input.Input
fun findRangeDestination(sourceRange: Pair<Long, Long>, mappings: List<Mapping>): List<Pair<Long, Long>> {
val sourceStart = sourceRange.first
val sourceLength = sourceRange.second
val mappedRanges = mutableListOf<Pair<Long, Long>>()
val destinations = mutableListOf<Pair... | 0 | Kotlin | 0 | 0 | a6eec4168b4a98b73d4496c9d610854a0165dbeb | 2,663 | aoc2023-kotlin | MIT License |
Array/austenYang/Leetcode/JavaKotlin/src/algorithms4/chapter_2/Sort/sort.kt | JessonYue | 268,215,243 | false | null | package algorithms4.chapter_2.Sort
fun selectSort(array: IntArray) {
for (i in array.indices) {
var minIndex = i
for (j in i until array.size) {
if (array[minIndex] > array[j]) {
minIndex = j
}
}
swap(array, i, minIndex)
}
}
/**
* 1. 将第一... | 0 | C | 19 | 39 | 3c22a4fcdfe8b47f9f64b939c8b27742c4e30b79 | 2,494 | LeetCodeLearning | MIT License |
src/Day02.kt | Qdelix | 574,590,362 | false | null | fun main() {
fun part1(input: List<String>): Int {
var score = 0
input.forEach { line ->
val lineWithoutWhiteSpaces = line.filter { !it.isWhitespace() }
val opponent = lineWithoutWhiteSpaces[0].toString()
val you = lineWithoutWhiteSpaces[1].toString()
... | 0 | Kotlin | 0 | 0 | 8e5c599d5071d9363c8f33b800b008875eb0b5f5 | 2,960 | aoc22 | Apache License 2.0 |
src/main/kotlin/wtf/log/xmas2021/day/day14/Day14.kt | damianw | 434,043,459 | false | {"Kotlin": 62890} | package wtf.log.xmas2021.day.day14
import com.google.common.collect.HashMultiset
import wtf.log.xmas2021.Day
import java.io.BufferedReader
object Day14 : Day<Input, Int, Long> {
override fun parseInput(reader: BufferedReader): Input {
val template = reader.readLine()
require(reader.readLine().isE... | 0 | Kotlin | 0 | 0 | 1c4c12546ea3de0e7298c2771dc93e578f11a9c6 | 4,042 | AdventOfKotlin2021 | BSD Source Code Attribution |
src/main/kotlin/Day4.kt | Ostkontentitan | 434,500,914 | false | {"Kotlin": 73563} | import java.lang.IllegalStateException
fun puzzleDayFourPartOne() {
val inputs = readInput(4).filter { it.isNotEmpty() }
val drawnNumbers = inputs[0].split(",")
val boards: List<BingoBoard> = constructBoards(inputs)
var finished = false
drawnNumbers.forEach { number ->
if (finished) {
... | 0 | Kotlin | 0 | 0 | e0e5022238747e4b934cac0f6235b92831ca8ac7 | 3,114 | advent-of-kotlin-2021 | Apache License 2.0 |
src/Day04.kt | phamobic | 572,925,492 | false | {"Kotlin": 12697} | private const val RANGES_DELIMITER = ","
private const val START_END_DELIMITER = "-"
private fun getParsedRanges(rangesText: String): List<IntRange> =
rangesText.split(RANGES_DELIMITER)
.map { it.split(START_END_DELIMITER) }
.map { it.first().toInt()..it.last().toInt() }
private fun IntRange.conta... | 1 | Kotlin | 0 | 0 | 34b2603470c8325d7cdf80cd5182378a4e822616 | 1,455 | aoc-2022 | Apache License 2.0 |
src/leetcode_problems/hard/MedianOfTwoSortedArrays.kt | MhmoudAlim | 451,633,139 | false | {"Kotlin": 31257, "Java": 586} | package leetcode_problems.hard
/*
https://leetcode.com/problems/median-of-two-sorted-arrays/
*/
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
val maxNumSize = 1000 ; val maxAllNumsSize = 2000
// Lengths of two arrays
val m = nums1.size
val n = nums2.size
val allNums = ... | 0 | Kotlin | 0 | 0 | 31f0b84ebb6e3947e971285c8c641173c2a60b68 | 2,646 | Coding-challanges | MIT License |
src/Day05.kt | VadimB95 | 574,449,732 | false | {"Kotlin": 19743} | import java.util.*
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day05_test")
check(part1(testInput) == "CMZ")
check(part2(testInput) == "MCD")
val input = readInput("Day05")
println(part1(input))
println(part2(input))
}
priva... | 0 | Kotlin | 0 | 0 | 3634d1d95acd62b8688b20a74d0b19d516336629 | 2,440 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day11.kt | uipko | 572,710,263 | false | {"Kotlin": 25828} | data class Monkey(val items: MutableList<Long> = mutableListOf(),
var operator: String, var first: String, var second: String,
var test: Long, var t: Int, var f: Int,
var inspected: Long = 0L)
fun main() {
val monkeys = monkeyBusiness("Day11.txt", 20, 3)
p... | 0 | Kotlin | 0 | 0 | b2604043f387914b7f043e43dbcde574b7173462 | 2,253 | aoc2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.