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/Day05.kt | MisterTeatime | 561,848,263 | false | {"Kotlin": 20300} | fun main() {
val vowels = listOf('a', 'e', 'i', 'o', 'u')
val forbidden = listOf("ab", "cd", "pq", "xy")
fun part1(input: List<String>): Int {
return input
.filterNot { s -> s.windowed(2).any { forbidden.contains(it) } } //Filter "Verbotene Zeichenketten"
.filter { s -> s.c... | 0 | Kotlin | 0 | 0 | d684bd252a9c6e93106bdd8b6f95a45c9924aed6 | 1,125 | AoC2015 | Apache License 2.0 |
2020/src/year2020/day08/Day08.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2020.day08
import util.readAllLines
private data class Instruction(
val command: String,
val arg: Int,
var visited: Boolean = false
)
private fun loadProgram(filename: String): List<Instruction> =
readAllLines(filename).map { line ->
val (command, arg) = line.split(" ")
va... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 1,846 | adventofcode | MIT License |
src/Day03.kt | Flexicon | 576,933,699 | false | {"Kotlin": 5474} | fun main() {
fun String.splitInHalf(): List<String> = (length / 2).let {
listOf(substring(0, it), substring(it))
}
fun Char.priority(): Int = code - if (isLowerCase()) 96 else 38
fun part1(input: List<String>): Int = input
.map { it.splitInHalf() }
.sumOf { (left, right) ->
... | 0 | Kotlin | 0 | 0 | 7109cf333c31999296e1990ce297aa2db3a622f2 | 1,038 | aoc-2022-in-kotlin | Apache License 2.0 |
2020/src/main/kotlin/de/skyrising/aoc2020/day7/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2020.day7
import de.skyrising.aoc.*
private fun readMap(lines: List<String>): Map<String, Set<Pair<String, Int>>> {
val map = mutableMapOf<String, MutableSet<Pair<String, Int>>>()
for (line in lines) {
val (bags, contain) = line.split(" bags contain ")
if (contain.start... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 3,284 | aoc | MIT License |
2015/kotlin/src/main/kotlin/nl/sanderp/aoc/aoc2015/day19/Day19.kt | sanderploegsma | 224,286,922 | false | {"C#": 233770, "Kotlin": 126791, "F#": 110333, "Go": 70654, "Python": 64250, "Scala": 11381, "Swift": 5153, "Elixir": 2770, "Jinja": 1263, "Ruby": 1171} | package nl.sanderp.aoc.aoc2015.day19
import nl.sanderp.aoc.common.readResource
fun parse(input: List<String>): Pair<List<Pair<String, String>>, String> {
val replacements = input.takeWhile { it.isNotBlank() }
.map { it.split(" => ").let { (a, b) -> a to b } }
val molecule = input.drop(replacements.si... | 0 | C# | 0 | 6 | 8e96dff21c23f08dcf665c68e9f3e60db821c1e5 | 1,271 | advent-of-code | MIT License |
src/Day05.kt | khongi | 572,983,386 | false | {"Kotlin": 24901} | import java.util.Stack
fun main() {
operator fun <E> List<E>.component2(): Int = this[1].toString().toInt()
operator fun <E> List<E>.component4(): Int = this[3].toString().toInt()
operator fun <E> List<E>.component6(): Int = this[5].toString().toInt()
fun buildStacks(
input: List<String>,
... | 0 | Kotlin | 0 | 0 | 9cc11bac157959f7934b031a941566d0daccdfbf | 2,651 | adventofcode2022 | Apache License 2.0 |
src/Utils.kt | thpz2210 | 575,577,457 | false | {"Kotlin": 50995} | import java.io.File
/**
* Reads lines from the given input txt file.
*/
fun readInput(name: String) = File("input", "$name.txt").readLines()
/**
* Holds a 2 dimensional grid
*/
class Grid2D<T>(initialItems: List<List<T>>) {
private val itemMap = initialItems.indices.flatMap { y ->
initialItems[y... | 0 | Kotlin | 0 | 0 | 69ed62889ed90692de2f40b42634b74245398633 | 1,515 | aoc-2022 | Apache License 2.0 |
jvm/src/main/kotlin/io/prfxn/aoc2021/day10.kt | prfxn | 435,386,161 | false | {"Kotlin": 72820, "Python": 362} | // Syntax Scoring (https://adventofcode.com/2021/day/10)
package io.prfxn.aoc2021
fun main() {
val lines = textResourceReader("input/10.txt").readLines()
val o2c = "()[]{}<>".chunked(2).associate { it.first() to it.last() }
val c2o = o2c.entries.associate { it.value to it.key }
val seS = ")]}>".asSe... | 0 | Kotlin | 0 | 0 | 148938cab8656d3fbfdfe6c68256fa5ba3b47b90 | 1,512 | aoc2021 | MIT License |
src/main/kotlin/endredeak/aoc2023/Day10.kt | edeak | 725,919,562 | false | {"Kotlin": 26575} | package endredeak.aoc2023
import kotlin.math.absoluteValue
enum class M { N, S, W, E }
operator fun Pair<Int, Int>.plus(move: M): Pair<Int, Int> = when (move) {
M.N -> first - 1 to second
M.S -> first + 1 to second
M.W -> first to second - 1
M.E -> first to second + 1
}
// first I did a BFS for part... | 0 | Kotlin | 0 | 0 | 92c684c42c8934e83ded7881da340222ff11e338 | 2,127 | AdventOfCode2023 | Do What The F*ck You Want To Public License |
src/aoc2023/Day9.kt | RobertMaged | 573,140,924 | false | {"Kotlin": 225650} | package aoc2023
import utils.checkEquals
import utils.readInput
fun main(): Unit = with(Day9) {
part1(testInput).checkEquals(114)
part1(input)
.checkEquals(1980437560)
// .sendAnswer(part = 1, day = "9", year = 2023)
part2(testInput).checkEquals(2)
part2(input)
.checkEquals(97... | 0 | Kotlin | 0 | 0 | e2e012d6760a37cb90d2435e8059789941e038a5 | 1,453 | Kotlin-AOC-2023 | Apache License 2.0 |
src/Day01.kt | vivekpanchal | 572,801,707 | false | {"Kotlin": 11850} | import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
//region using maps
// val elf = mutableMapOf<Int, Int>()
// var elfCount = 1
// var inventory = 0
// var isElf=true
// input.forEach {
// if (it.isNotEmpty()) {
// if (!i... | 0 | Kotlin | 0 | 0 | f21a2dd08be66520e9c9de14611e50c14ea017f0 | 2,416 | Aoc-kotlin | Apache License 2.0 |
src/main/kotlin/com/jacobhyphenated/advent2023/day15/Day15.kt | jacobhyphenated | 725,928,124 | false | {"Kotlin": 121644} | package com.jacobhyphenated.advent2023.day15
import com.jacobhyphenated.advent2023.Day
/**
* Day 15: Lens Library
*
* The puzzle input is a set of instruction for focusing lenses.
* Use a custom ascii hash algorithm as part of the setup process
*/
class Day15: Day<String> {
override fun getInput(): String {
... | 0 | Kotlin | 0 | 0 | 90d8a95bf35cae5a88e8daf2cfc062a104fe08c1 | 2,624 | advent2023 | The Unlicense |
src/twentytwo/Day11.kt | Monkey-Matt | 572,710,626 | false | {"Kotlin": 73188} | package twentytwo
import java.util.*
fun main() {
println("Int max = ${Int.MAX_VALUE}")
println("Long max = ${Long.MAX_VALUE}")
println("Short max = ${Short.MAX_VALUE}")
println("Byte max = ${Byte.MAX_VALUE}")
println()
// test if implementation meets criteria from the description, like:
... | 1 | Kotlin | 0 | 0 | 600237b66b8cd3145f103b5fab1978e407b19e4c | 4,359 | advent-of-code-solutions | Apache License 2.0 |
src/main/kotlin/com/github/michaelbull/advent2021/day15/ChitonCave.kt | michaelbull | 433,565,311 | false | {"Kotlin": 162839} | package com.github.michaelbull.advent2021.day15
import com.github.michaelbull.advent2021.math.Vector2
import com.github.michaelbull.advent2021.math.Vector2.Companion.CARDINAL_DIRECTIONS
import com.github.michaelbull.advent2021.math.Vector2IntMap
import com.github.michaelbull.advent2021.math.rem
import java.util.Priori... | 0 | Kotlin | 0 | 4 | 7cec2ac03705da007f227306ceb0e87f302e2e54 | 3,143 | advent-2021 | ISC License |
src/main/kotlin/io/undefined/AlienDictionary.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.undefined
import io.utils.runTests
import java.util.*
// https://leetcode.com/problems/alien-dictionary/
class AlienDictionary {
fun execute(input: Array<String>): String {
if (input.isEmpty()) return ""
val letters = input.fold(mutableSetOf<Char>()) { acc, word -> acc.apply { word.forEach { ad... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 5,553 | coding | MIT License |
src/main/aoc2018/Day12.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2018
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
class Day12(input: List<String>) {
private val initialState = input.first().substringAfter("initial state: ")
private val rules = parseRules(input.drop(2))
private fun parseRules(input: List<String>): Map<String, Char> {... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 3,810 | aoc | MIT License |
src/Day05.kt | BenHopeITC | 573,352,155 | false | null | fun String.asCreateMove(): Triple<Int, Int, Int> {
val cratesToMove = this.substringAfter("move ").substringBefore(" from ").toInt()
val fromStack = this.substringAfter(" from ").substringBefore(" to ").toInt()
val toStack = this.substringAfter(" to ").toInt()
return Triple(cratesToMove, fromStack, toS... | 0 | Kotlin | 0 | 0 | 851b9522d3a64840494b21ff31d83bf8470c9a03 | 3,272 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/g1601_1700/s1617_count_subtrees_with_max_distance_between_cities/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1601_1700.s1617_count_subtrees_with_max_distance_between_cities
// #Hard #Dynamic_Programming #Tree #Bit_Manipulation #Bitmask #Enumeration
// #2023_06_15_Time_297_ms_(100.00%)_Space_38.6_MB_(100.00%)
import kotlin.math.pow
class Solution {
private var ans = 0
private var vis = 0
fun countSubgr... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,009 | LeetCode-in-Kotlin | MIT License |
kotlin/src/katas/kotlin/leetcode/minimum_path_sum/MinPathSum.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.minimum_path_sum
import datsok.shouldEqual
import org.junit.jupiter.api.Test
//
// Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right,
// which minimizes the sum of all numbers along its path.
// Note: You can only move either down or right at ... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,632 | katas | The Unlicense |
src/main/kotlin/de/jball/aoc2022/day07/Day07.kt | fibsifan | 573,189,295 | false | {"Kotlin": 43681} | package de.jball.aoc2022.day07
import de.jball.aoc2022.Day
class Day07(test: Boolean = false): Day<Long>(test, 95437, 24933642) {
private val rootDir = Directory(mutableMapOf())
private val allDirs = mutableMapOf<String, Directory>()
private val rom = 70000000L
private val needed = 30000000L
init ... | 0 | Kotlin | 0 | 3 | a6d01b73aca9b54add4546664831baf889e064fb | 2,403 | aoc-2022 | Apache License 2.0 |
src/day01/Day01.kt | ivanovmeya | 573,150,306 | false | {"Kotlin": 43768} | package day01
import readInput
fun main() {
fun computeElfCalories(
i: Int,
input: List<String>
): Pair<Int, Int> {
var i1 = i
var currentElfCalories = 0
while (i1 < input.size && input[i1].isNotEmpty() && input[i1].isNotBlank()) {
currentElfCalories += inpu... | 0 | Kotlin | 0 | 0 | 7530367fb453f012249f1dc37869f950bda018e0 | 2,351 | advent-of-code-2022 | Apache License 2.0 |
app/src/main/kotlin/aoc2019/day02/Day02.kt | dbubenheim | 499,817,652 | false | {"Kotlin": 20151} | package aoc2019.day02
import aoc2019.day02.Addresses.NOUN
import aoc2019.day02.Addresses.VERB
import aoc2019.day02.OpcCode.*
import aoc2019.toFile
/*
1,0,0,0,99 becomes 2,0,0,0,99 (1 + 1 = 2).
2,3,0,3,99 becomes 2,3,0,6,99 (3 * 2 = 6).
2,4,4,5,99,0 becomes 2,4,4,5,99,9801 (99 * 99 = 9801).
1,1,1,4,99,5,6,0,99 becomes... | 8 | Kotlin | 0 | 0 | f761d923d8c7c317bd93336163a2d4f86bf16340 | 2,862 | advent-of-code-2019 | MIT License |
src/Day03.kt | bin-wang | 572,801,360 | false | {"Kotlin": 19395} | fun main() {
fun Char.toPriority() = when (this) {
in 'a'..'z' -> this - 'a' + 1
in 'A'..'Z' -> this - 'A' + 27
else -> error("unexpected input: $this")
}
fun part1(input: List<String>): Int {
return input.sumOf {
val item1 = it.slice(0 until it.length / 2)
... | 0 | Kotlin | 0 | 0 | dca2c4915594a4b4ca2791843b53b71fd068fe28 | 915 | aoc22-kt | Apache License 2.0 |
src/Day20.kt | fonglh | 573,269,990 | false | {"Kotlin": 48950, "Ruby": 1701} | fun main() {
data class InputNumber(val originalIndex: Int, val value: Long)
fun numberAt(input: List<InputNumber>, positionFromZero: Int): Long {
// find position of 0
var zeroIndex = 0
for (i in input.indices) {
if (input[i].value == 0.toLong()) {
zeroIndex... | 0 | Kotlin | 0 | 0 | ef41300d53c604fcd0f4d4c1783cc16916ef879b | 2,757 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | cvb941 | 572,639,732 | false | {"Kotlin": 24794} | enum class Response {
ROCK, PAPER, SCISSORS;
fun score(): Int {
return when (this) {
ROCK -> 1
PAPER -> 2
SCISSORS -> 3
}
}
fun matchPointsAgainst(opponent: Response): Int {
return when (this) {
ROCK -> when (opponent) {
... | 0 | Kotlin | 0 | 0 | fe145b3104535e8ce05d08f044cb2c54c8b17136 | 2,930 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day04.kt | slawa4s | 573,050,411 | false | {"Kotlin": 20679} | fun main() {
fun getPairFromInput(arg: String): Pair<Int, Int> {
val splitByTwo = arg.split('-')
return Pair(Integer.parseInt(splitByTwo[0]), Integer.parseInt(splitByTwo[1]))
}
fun checkOneRangeInsideAnother(firstRange: Pair<Int, Int>, secondRange: Pair<Int, Int>): Boolean =
(firstR... | 0 | Kotlin | 0 | 0 | cd8bbbb3a710dc542c2832959a6a03a0d2516866 | 1,312 | aoc-2022-in-kotlin | Apache License 2.0 |
y2020/src/main/kotlin/adventofcode/y2020/Day23.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2020
import adventofcode.io.AdventSolution
fun main() = Day23.solve()
object Day23 : AdventSolution(2020, 23, "Crab Cups")
{
override fun solvePartOne(input: String): Any
{
val nextCup = shuffle(parse(input), 9, 100)
return generateSequence(1) { nextCup[it] }.drop(1).tak... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,535 | advent-of-code | MIT License |
src/Day01.kt | ElenaRgC | 572,898,962 | false | null | fun main() {
fun part1(input: List<String>): Int {
var suma = 0
var sumaMayor = 0
for (i in input) {
if (i == "") {
if (suma > sumaMayor) {
sumaMayor = suma
}
suma = 0
} else {
suma +... | 0 | Kotlin | 0 | 0 | b7505e891429970c377f7b45bfa8b5157f85c457 | 1,466 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/pjozsef/randomtree/RandomTree.kt | pjozsef | 239,387,655 | false | null | package com.github.pjozsef.randomtree
import com.github.pjozsef.WeightedDie
import java.util.*
data class DicePoolNode<T>(
val dicePool: List<Number>,
val branches: List<RandomTree<T>>,
val random: Random = Random()
) : RandomTree<T> {
override val values: List<T>
get() = dicePool.mapIndexed {... | 0 | Kotlin | 0 | 0 | 47a83a62ed1ad4c7e3ebe9d53c49521b8bacabfc | 2,021 | RandomTree | MIT License |
src/Day04.kt | wujingwe | 574,096,169 | false | null | fun main() {
infix fun IntRange.contains(other: IntRange): Boolean {
return this.first <= other.first && this.last >= other.last
}
fun part1(inputs: List<String>): Int {
return inputs.count { s ->
val (a, b) = s.split(",")
val (a1, a2) = a.split("-")
val... | 0 | Kotlin | 0 | 0 | a5777a67d234e33dde43589602dc248bc6411aee | 1,097 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/aoc2022/Day8.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2022
import Grid
import Pos
import kotlin.math.max
class Day8(input: List<String>) {
private val forrest = Grid.parse(input)
/**
* Get a list of 4 lists, one for each direction. Each list contains the positions
* of all the trees in the given direction, starting from closest to the star... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,191 | aoc | MIT License |
src/Day05.kt | arisaksen | 573,116,584 | false | {"Kotlin": 42887} | import org.assertj.core.api.Assertions.assertThat
// https://adventofcode.com/2022/day/5
fun main() {
fun part1(input: String): String {
val (stackData, moves) = input.split("\n\n")
val stacks: List<ArrayDeque<String>> = stackData.toStacks()
moves.lines().forEach {
val number ... | 0 | Kotlin | 0 | 0 | 85da7e06b3355f2aa92847280c6cb334578c2463 | 3,187 | aoc-2022-kotlin | Apache License 2.0 |
src/day09/Day09.kt | tobihein | 569,448,315 | false | {"Kotlin": 58721} | package day09
import readInput
class Day09 {
fun part1(): Int {
val readInput = readInput("day09/input")
return part1(readInput)
}
fun part2(): Int {
val readInput = readInput("day09/input")
return part2(readInput)
}
fun part1(input: List<String>): Int = calculate... | 0 | Kotlin | 0 | 0 | af8d851702e633eb8ff4020011f762156bfc136b | 2,659 | adventofcode-2022 | Apache License 2.0 |
src/main/java/challenges/educative_grokking_coding_interview/k_way_merge/_3/FindKPairs.kt | ShabanKamell | 342,007,920 | false | null | package challenges.educative_grokking_coding_interview.k_way_merge._3
import challenges.util.PrintHyphens
import java.util.Arrays
import java.util.PriorityQueue
import java.util.ArrayList
/**
Given two lists and an integer k, find k
pairs of numbers with the smallest sum so that in each pair, each list contributes... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 3,164 | CodingChallenges | Apache License 2.0 |
src/main/kotlin/at/mpichler/aoc/solutions/year2021/Day08.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2021
import at.mpichler.aoc.lib.Day
import at.mpichler.aoc.lib.PartSolution
open class Part8A : PartSolution() {
lateinit var signalPatterns: List<MutableList<String>>
lateinit var outputs: List<List<String>>
override fun parseInput(text: String) {
val lines ... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 6,944 | advent-of-code-kotlin | MIT License |
src/Day04.kt | MickyOR | 578,726,798 | false | {"Kotlin": 98785} | fun main() {
fun part1(input: List<String>): Int {
var sum = 0;
for (line in input) {
var (s1, s2) = line.split(",");
var (l1, r1) = s1.split("-").map { it.toInt() };
var (l2, r2) = s2.split("-").map { it.toInt() };
if (l1 <= l2 && r2 <= r1 || l2 <= l1... | 0 | Kotlin | 0 | 0 | c24e763a1adaf0a35ed2fad8ccc4c315259827f0 | 920 | advent-of-code-2022-kotlin | Apache License 2.0 |
2023/src/main/kotlin/day11.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Grid
import utils.Parser
import utils.Solution
import utils.Vec2l
import utils.pairs
fun main() {
Day11.run()
}
object Day11 : Solution<Grid<Char>>() {
override val name = "day11"
override val parser = Parser.charGrid
private fun expand(coord: Vec2l, expCols: List<Int>, expRows: List<Int>, times... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,082 | aoc_kotlin | MIT License |
src/Day03.kt | ostersc | 572,991,552 | false | {"Kotlin": 46059} | fun main() {
fun toPriority(c: Char) = if (c.isUpperCase()) c.code - 'A'.code + 26 + 1 else c.code - 'a'.code + 1
fun part1(input: List<String>): Int {
return input.sumOf {
val c = it.toCharArray(0, it.length / 2).intersect(
it.toCharArray(it.length / 2, it.length).toSet()
... | 0 | Kotlin | 0 | 1 | 3eb6b7e3400c2097cf0283f18b2dad84b7d5bcf9 | 972 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g2001_2100/s2025_maximum_number_of_ways_to_partition_an_array/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2025_maximum_number_of_ways_to_partition_an_array
// #Hard #Array #Hash_Table #Prefix_Sum #Counting #Enumeration
// #2023_06_23_Time_1163_ms_(100.00%)_Space_76_MB_(100.00%)
class Solution {
fun waysToPartition(nums: IntArray, k: Int): Int {
val n = nums.size
val ps = LongArray(... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,889 | LeetCode-in-Kotlin | MIT License |
src/day20/Day20.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day20
import readInput
class Number(val value: Long)
fun parseInput(input: List<String>, factor: Long = 1): List<Number> {
var parsed = mutableListOf<Number>()
for (i in input) {
parsed.add(Number(i.toLong() * factor))
}
// There can be only one zero!
check(parsed.count {it.valu... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 2,334 | AdventOfCode2022 | Apache License 2.0 |
src/AoC13.kt | Pi143 | 317,631,443 | false | null | import java.io.File
fun main() {
println("Starting Day 13 A Test 1")
calculateDay13PartA("Input/2020_Day13_A_Test1")
println("Starting Day 13 A Real")
calculateDay13PartA("Input/2020_Day13_A")
println("Starting Day 13 B Test 1")
calculateDay13PartB("Input/2020_Day13_A_Test1")
println("Sta... | 0 | Kotlin | 0 | 1 | fa21b7f0bd284319e60f964a48a60e1611ccd2c3 | 2,596 | AdventOfCode2020 | MIT License |
advent-of-code-2023/src/Day09.kt | osipxd | 572,825,805 | false | {"Kotlin": 141640, "Shell": 4083, "Scala": 693} | private const val DAY = "Day09"
fun main() {
fun testInput() = readInput("${DAY}_test")
fun input() = readInput(DAY)
"Part 1" {
part1(testInput()) shouldBe 114
measureAnswer { part1(input()) }
}
"Part 2" {
part2(testInput()) shouldBe 2
measureAnswer { part2(input()... | 0 | Kotlin | 0 | 5 | 6a67946122abb759fddf33dae408db662213a072 | 972 | advent-of-code | Apache License 2.0 |
src/me/bytebeats/algo/kt/Solution3.kt | bytebeats | 251,234,289 | false | null | package me.bytebeats.algo.kt
import me.bytebeats.algs.ds.ListNode
import me.bytebeats.algs.ds.TreeNode
class Solution3 {
fun removeDuplicates(nums: IntArray): Int {
var size = nums.size
var k = 0
var j = 0
var num = 0
while (k < size) {
num = nums[k]
... | 0 | Kotlin | 0 | 1 | 7cf372d9acb3274003bb782c51d608e5db6fa743 | 35,300 | Algorithms | MIT License |
src/Day07.kt | MwBoesgaard | 572,857,083 | false | {"Kotlin": 40623} | fun main() {
class Folder(val name: String, var parent: Folder?, val children: MutableList<Folder>, var size: Long) {
fun getTotalSize(): Long {
var totalSize: Long = this.size
for (child in children) {
totalSize += child.getTotalSize()
}
retu... | 0 | Kotlin | 0 | 0 | 3bfa51af6e5e2095600bdea74b4b7eba68dc5f83 | 2,580 | advent_of_code_2022 | Apache License 2.0 |
kotlin/change/src/main/kotlin/ChangeCalculator.kt | colintheshots | 117,450,747 | false | null | class ChangeCalculator (list: List<Int>) {
private val sortedList = list.sortedDescending()
fun computeMostEfficientChange(total : Int) : List<Int> {
require(total >= 0) {"Negative totals are not allowed."}
if (total == 0) return emptyList() // no coins make zero change
val trimmed = ... | 0 | Kotlin | 0 | 0 | f284aecd7f017c3fd972c1dcf9d1c4b25866d614 | 2,055 | ExercismKotlin | Apache License 2.0 |
2021/kotlin/src/main/kotlin/com/codelicia/advent2021/Day13.kt | codelicia | 627,407,402 | false | {"Kotlin": 49578, "PHP": 554, "Makefile": 293} | package com.codelicia.advent2021
import kotlin.math.max
class Day13(val input: String) {
fun solve(folds: Int): Int {
val (dots, fold) = input.split("\n\n")
val xs = dots.split("\n").map { it.split(",").map { s -> s.toInt() } }
val xMax = xs.maxOf { it[0] }
val yMax = xs.maxOf { i... | 2 | Kotlin | 0 | 0 | df0cfd5c559d9726663412c0dec52dbfd5fa54b0 | 1,662 | adventofcode | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[128]最长连续序列.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给定一个未排序的整数数组 nums ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。
//
// 请你设计并实现时间复杂度为 O(n) 的算法解决此问题。
//
//
//
// 示例 1:
//
//
//输入:nums = [100,4,200,1,3,2]
//输出:4
//解释:最长数字连续序列是 [1, 2, 3, 4]。它的长度为 4。
//
// 示例 2:
//
//
//输入:nums = [0,3,7,2,5,8,4,6,0,1]
//输出:9
//
//
//
//
// 提示:
//
//
// 0 <= nums.length <= 105
// -109 <=... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,748 | MyLeetCode | Apache License 2.0 |
src/Day01.kt | fasfsfgs | 573,562,215 | false | {"Kotlin": 52546} | fun getElves(input: List<String>):List<Int> {
return input
.joinToString { it.ifBlank { "*" } }
.split('*')
.map { it.split(',') }
.map { getIntList(it) }
.map { it.sum() }
}
fun getIntList(strList: List<String>): List<Int> {
return strList
.map { it.trim() }
... | 0 | Kotlin | 0 | 0 | 17cfd7ff4c1c48295021213e5a53cf09607b7144 | 892 | advent-of-code-2022 | Apache License 2.0 |
src/year2023/day04/Day.kt | tiagoabrito | 573,609,974 | false | {"Kotlin": 73752} | package year2023.day04
import kotlin.math.pow
import year2023.solveIt
fun main() {
val day = "04"
val expectedTest1 = 13L
val expectedTest2 = 30L
fun readCard(it: String): List<Set<String>> = it.substring(it.indexOf(":")).split("|").map { Regex("\\d+").findAll(it).map { it.value }.toSet() }
f... | 0 | Kotlin | 0 | 0 | 1f9becde3cbf5dcb345659a23cf9ff52718bbaf9 | 1,194 | adventOfCode | Apache License 2.0 |
src/array/BestTimeToBuyAStock.kt | develNerd | 456,702,818 | false | {"Kotlin": 37635, "Java": 5892} | package array
/**
*
* You are given an array prices where prices[i] is the price of a given stock on the ith day.
You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.
Return the maximum profit you can achieve from this transaction. ... | 0 | Kotlin | 0 | 0 | 4e6cc8b4bee83361057c8e1bbeb427a43622b511 | 4,229 | Blind75InKotlin | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2022/Day07.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2022
import se.saidaspen.aoc.util.Day
import se.saidaspen.aoc.util.ints
import se.saidaspen.aoc.util.removeFirst
fun main() = Day07.run()
object Day07 : Day(2022, 7) {
data class Dir (
val name: String,
val path : String = "",
val parent: Dir?,
val sub... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,820 | adventofkotlin | MIT License |
src/day05/Day05.kt | pnavais | 574,712,395 | false | {"Kotlin": 54079} | package day05
import readInput
import java.util.*
import kotlin.collections.ArrayDeque
val pattern = Regex("^move (\\d+) from (\\d+) to (\\d+)$")
interface CrateMover {
fun moveCrates(line: String, stacks: MutableList<ArrayDeque<Char>>)
}
private class CrateMover9000 : CrateMover {
override fun moveCrates(l... | 0 | Kotlin | 0 | 0 | ed5f521ef2124f84327d3f6c64fdfa0d35872095 | 3,202 | advent-of-code-2k2 | Apache License 2.0 |
src/Day05.kt | strindberg | 572,685,170 | false | {"Kotlin": 15804} | fun main() {
fun createStacks(input: List<String>): Array<ArrayDeque<Char>> =
Array(9) { ArrayDeque<Char>() }.apply {
input.forEach { line ->
if (line.contains("[")) {
for ((index, char) in line.withIndex()) {
if (ch... | 0 | Kotlin | 0 | 0 | c5d26b5bdc320ca2aeb39eba8c776fcfc50ea6c8 | 2,186 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | ktrom | 573,216,321 | false | {"Kotlin": 19490, "Rich Text Format": 2301} | import java.util.NoSuchElementException
fun main() {
fun part1(matchups: List<List<Shape>>): Int {
// aggregates points earned from all matchups
val score: List<Int> = matchups.map { matchup ->
val opponentShape: Shape = matchup[0]
val myShape: Shape = matchup[1]
// get score earned for using our ... | 0 | Kotlin | 0 | 0 | 6940ff5a3a04a29cfa927d0bbc093cd5df15cbcd | 4,895 | kotlin-advent-of-code | Apache License 2.0 |
src/Day08.kt | stevefranchak | 573,628,312 | false | {"Kotlin": 34220} | class TreeGrid(private val grid: List<List<Int>>) : List<List<Int>> by grid {
private val height
get() = this.size
// Assumption: all rows have the same length
private val width
get() = this[0].size
private fun goUpFrom(rowIndex: Int, columnIndex: Int) =
if (rowIndex == 0) empt... | 0 | Kotlin | 0 | 0 | 22a0b0544773a6c84285d381d6c21b4b1efe6b8d | 4,491 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day05.kt | arosenf | 726,114,493 | false | {"Kotlin": 40487} | import kotlin.math.min
import kotlin.system.exitProcess
fun main(args: Array<String>) {
if (args.isEmpty() or (args.size < 2)) {
println("Almanac not specified")
exitProcess(1)
}
val fileName = args.first()
println("Reading $fileName")
val lines = readLines(fileName)
val result... | 0 | Kotlin | 0 | 0 | d9ce83ee89db7081cf7c14bcad09e1348d9059cb | 3,337 | adventofcode2023 | MIT License |
src/year2023/05/Day05.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2023.`05`
import readInput
import utils.printlnDebug
private const val CURRENT_DAY = "05"
data class RangeMap(
val input: LongRange,
val delta: Long,
)
data class Mapper(
val inputRanges: List<RangeMap>,
)
private fun parseIntoGroups(input: List<String>): List<List<String>> {
val listO... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 4,057 | KotlinAdventOfCode | Apache License 2.0 |
src/day15/Day15.kt | henrikrtfm | 570,719,195 | false | {"Kotlin": 31473} | package day15
import utils.Resources.resourceAsListOfString
import kotlin.math.absoluteValue
typealias Point = Pair<Int,Int>
typealias SensorBeacon = Pair<Point,Point>
private const val MAX = 4000000
private const val MIN = 0
fun main(){
val input = resourceAsListOfString("src/day15/Day15.txt").map { parsePair(i... | 0 | Kotlin | 0 | 0 | 20c5112594141788c9839061cb0de259f242fb1c | 2,862 | aoc2022 | Apache License 2.0 |
src/Day05.kt | Derrick-Mwendwa | 573,947,669 | false | {"Kotlin": 8707} | fun main() {
// NOTE: This will not work for stacks exceeding 9
fun getStacks(input: List<String>): Pair<List<MutableList<Char>>, Int> {
val regex = Regex("""([0-9])+""")
var stacks = 0
var limit = 0
for ((index, line) in input.withIndex()) {
val text = line.filter { ... | 0 | Kotlin | 0 | 1 | 7870800afa54c831c143b5cec84af97e079612a3 | 2,807 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day09.kt | kenyee | 573,186,108 | false | {"Kotlin": 57550} |
import kotlin.math.sign
fun main() { // ktlint-disable filename
val knots = mutableListOf<Position>()
val visited = mutableSetOf<Position>()
fun moveRope(dir: Direction, distance: Int) {
val tailIndex = knots.size - 1
val indexPairs = knots.indices.windowed(size = 2, step = 1)
rep... | 0 | Kotlin | 0 | 0 | 814f08b314ae0cbf8e5ae842a8ba82ca2171809d | 2,265 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/Day07.kt | Soykaa | 576,055,206 | false | {"Kotlin": 14045} | data class Node(var isDir: Boolean, var size: Int, val parent: Node?) {
var children: MutableMap<String, Node> = mutableMapOf()
}
private val root = Node(true, 0, null)
private fun createFileOrDir(parameter: String, parent: Node?): Node = if (parameter == "dir")
Node(true, 0, parent)
else {
Node(false, par... | 0 | Kotlin | 0 | 0 | 1e30571c475da4db99e5643933c5341aa6c72c59 | 2,025 | advent-of-kotlin-2022 | Apache License 2.0 |
aoc/src/main/kotlin/com/bloidonia/aoc2023/day01/Main.kt | timyates | 725,647,758 | false | {"Kotlin": 45518, "Groovy": 202} | package com.bloidonia.aoc2023.day01
import com.bloidonia.aoc2023.lines
private val example = """1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet""".lines()
private val example2 = """two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen""".lines()
private fun firstLast(s: String) = s.f... | 0 | Kotlin | 0 | 0 | 158162b1034e3998445a4f5e3f476f3ebf1dc952 | 1,401 | aoc-2023 | MIT License |
src/cn/leetcode/codes/simple111/Simple111.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple111
import cn.leetcode.codes.common.TreeNode
import cn.leetcode.codes.createTreeNode
import cn.leetcode.codes.out
import java.util.*
import kotlin.math.min
fun main() {
val nums = arrayOf<Int?>(3, 9, 20, 15, 7)
val treeNode = createTreeNode(nums)
val re = minDepth(treeNod... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 2,761 | LeetCodeSimple | Apache License 2.0 |
src/main/java/com/booknara/problem/math/ConsecutiveNumbersSum.kt | booknara | 226,968,158 | false | {"Java": 1128390, "Kotlin": 177761} | package com.booknara.problem.math
/**
* 829. Consecutive Numbers Sum (Hard)
* https://leetcode.com/problems/consecutive-numbers-sum/
*/
class Solution {
// T:O(n), S:(1)
fun consecutiveNumbersSum(N: Int): Int {
var res = 1 // start with 1 because of N itself
for (i in 2..N) {
va... | 0 | Java | 1 | 1 | 04dcf500ee9789cf10c488a25647f25359b37a53 | 847 | playground | MIT License |
src/main/kotlin/de/mbdevelopment/adventofcode/year2021/solvers/day5/Day5Puzzle.kt | Any1s | 433,954,562 | false | {"Kotlin": 96683} | package de.mbdevelopment.adventofcode.year2021.solvers.day5
import de.mbdevelopment.adventofcode.year2021.solvers.PuzzleSolver
abstract class Day5Puzzle : PuzzleSolver {
companion object {
private val INPUT_PATTERN = "(\\d+),(\\d+) -> (\\d+),(\\d+)".toPattern()
}
abstract fun solve(lines: List<L... | 0 | Kotlin | 0 | 0 | 21d3a0e69d39a643ca1fe22771099144e580f30e | 2,049 | AdventOfCode2021 | Apache License 2.0 |
tools/intellij.tools.ide.metrics.collector/src/com/intellij/tools/ide/metrics/collector/metrics/collectionExtension.kt | JetBrains | 2,489,216 | false | null | package com.intellij.tools.ide.metrics.collector.metrics
import kotlin.math.pow
import kotlin.math.sqrt
/** @see medianValue */
fun Iterable<Long>.median(): Long {
val size = this.count()
require(size > 0) { "Cannot calculate median value because collection is empty" }
val sortedList = this.sorted()
// odd ... | 251 | null | 5,079 | 16,158 | 831d1a4524048aebf64173c1f0b26e04b61c6880 | 1,585 | intellij-community | Apache License 2.0 |
src/Day07.kt | MerickBao | 572,842,983 | false | {"Kotlin": 28200} | fun main() {
// build a file tree
fun build(input: List<String>): Node {
val root = Node("/")
var curr: Node = root
val parent = HashMap<Node, Node>()
var i = 0
while (i < input.size) {
var now = input[i].split(" ")
if (now[1] == "cd") { // cd dir
... | 0 | Kotlin | 0 | 0 | 70a4a52aa5164f541a8dd544c2e3231436410f4b | 2,339 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day07.kt | jordan-thirus | 573,476,470 | false | {"Kotlin": 41711} | fun main() {
fun parse(input: List<String>): Directory {
val que : ArrayDeque<Directory> = ArrayDeque()
val root = Directory("/")
que.addLast(root)
for(line in input.subList(1, input.size)){
val instructions = line.split(' ')
when(instructions[0]){
... | 0 | Kotlin | 0 | 0 | 59b0054fe4d3a9aecb1c9ccebd7d5daa7a98362e | 4,495 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/_2022/Day05.kt | novikmisha | 572,840,526 | false | {"Kotlin": 145780} | package _2022
import readGroupedInput
fun main() {
fun processCargo(input: List<List<String>>, itemSort: (items: List<String>) -> List<String>): String {
val (cargo, commands) = input
val numberOfColumns = cargo.last().split(" ")
.filter(String::isNotEmpty)
.maxOf { it.to... | 0 | Kotlin | 0 | 0 | 0c78596d46f3a8bf977bf356019ea9940ee04c88 | 1,730 | advent-of-code | Apache License 2.0 |
src/Day03.kt | JCampbell8 | 572,669,444 | false | {"Kotlin": 10115} | fun main() {
val lowerCaseLettersSet: Set<Char> = "abcdefghijklmnopqrstuvwxyz".toSet()
val upperCaseLettersSet: Set<Char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toSet()
fun convertLetterToNumber(letter: Char): Int {
var number = lowerCaseLettersSet.indexOf(letter)
if (number != -1)
numb... | 0 | Kotlin | 0 | 1 | 0bac6b866e769d0ac6906456aefc58d4dd9688ad | 1,203 | advent-of-code-2022 | Apache License 2.0 |
src/Day13.kt | hrach | 572,585,537 | false | {"Kotlin": 32838} | fun main() {
@Suppress("UNCHECKED_CAST")
fun n(a: Any): List<Any> =
if (a is List<*>) a as List<Any> else listOf(a)
fun inOrder(li: Any, ri: Any): Boolean? {
val ll = n(li).toMutableList()
val rr = n(ri).toMutableList()
while (ll.isNotEmpty() || rr.isNotEmpty()) {
val l = ll.removeFirstOrNull() ?: return... | 0 | Kotlin | 0 | 1 | 40b341a527060c23ff44ebfe9a7e5443f76eadf3 | 2,176 | aoc-2022 | Apache License 2.0 |
src/questions/LongestPalindrome.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
/**
* Given a string s which consists of lowercase or uppercase letters,
* return the length of the longest palindrome that can be built with those letters.
*
* Letters are case sensitive, for example, "Aa" is not considered a palindr... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 1,423 | algorithms | MIT License |
day16/src/main/kotlin/Main.kt | rstockbridge | 159,586,951 | false | null | import java.io.File
fun main() {
val samples = parseInputPartI(readInputFilePartI())
println("Part I: the solution is ${solvePartI(samples)}.")
val instructions = parseInputPartII(readInputFilePartII())
println("Part II: the solution is ${solvePartII(samples, instructions)}.")
}
fun readInputFilePart... | 0 | Kotlin | 0 | 0 | c404f1c47c9dee266b2330ecae98471e19056549 | 4,624 | AdventOfCode2018 | MIT License |
src/Day05.kt | afranken | 572,923,112 | false | {"Kotlin": 15538} | fun main() {
fun part1(input: List<String>, stackSize: Int, moveDrop: Int): String {
val stacks = mutableMapOf<Int, ArrayDeque<Char>>()
for (i in 0 until stackSize) {
stacks[i] = ArrayDeque()
}
input
.take(stackSize)
.filterNot(String::isBlank)
... | 0 | Kotlin | 0 | 0 | f047d34dc2a22286134dc4705b5a7c2558bad9e7 | 2,967 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day01.kt | proggler23 | 573,129,757 | false | {"Kotlin": 27990} | fun List<String>.partitionBy(separator: String): List<List<String>> {
return buildList {
val list = mutableListOf<String>()
for (value in this@partitionBy) {
if (value == separator) {
add(list.toList())
list.clear()
} else {
lis... | 0 | Kotlin | 0 | 0 | 584fa4d73f8589bc17ef56c8e1864d64a23483c8 | 1,045 | advent-of-code-2022 | Apache License 2.0 |
src/Day01.kt | bananer | 434,885,332 | false | {"Kotlin": 36979} | fun main() {
fun part1(input: List<String>): Int {
return input.map { Integer.parseInt(it) }
.fold(Pair(Integer.MAX_VALUE, 0)) { (prev, count), next ->
Pair(
next,
if (next > prev) {
count + 1
} e... | 0 | Kotlin | 0 | 0 | 98f7d6b3dd9eefebef5fa3179ca331fef5ed975b | 1,074 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/y2023/day07/Day07.kt | TimWestmark | 571,510,211 | false | {"Kotlin": 97942, "Shell": 1067} | package y2023.day07
fun main() {
AoCGenerics.printAndMeasureResults(
part1 = { part1() },
part2 = { part2() }
)
}
typealias Hand = String
data class Game(
val bidValue: Int,
val hand: Hand
)
enum class HandType {
FIVE,
FOUR,
FULL_HOUSE,
THREE,
TWO_PAIR,
PAIR,
... | 0 | Kotlin | 0 | 0 | 23b3edf887e31bef5eed3f00c1826261b9a4bd30 | 4,930 | AdventOfCode | MIT License |
src/main/kotlin/com/ginsberg/advent2021/Day16.kt | tginsberg | 432,766,033 | false | {"Kotlin": 92813} | /*
* Copyright (c) 2021 by <NAME>
*/
/**
* Advent of Code 2021, Day 16 - Packet Decoder
* Problem Description: http://adventofcode.com/2021/day/16
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2021/day16/
*/
package com.ginsberg.advent2021
class Day16(input: String) {
private val b... | 0 | Kotlin | 2 | 34 | 8e57e75c4d64005c18ecab96cc54a3b397c89723 | 3,424 | advent-2021-kotlin | Apache License 2.0 |
src/day8/Day8.kt | davidcurrie | 579,636,994 | false | {"Kotlin": 52697} | package day8
import java.io.File
fun main() {
val lines = File("src/day8/input.txt").readLines()
val trees = mutableMapOf<Pair<Int, Int>, Int>()
for (j in lines.indices) {
for (i in 0 until lines[j].length) {
trees[Pair(i, j)] = lines[j][i].toString().toInt()
}
}
val v... | 0 | Kotlin | 0 | 0 | 0e0cae3b9a97c6019c219563621b43b0eb0fc9db | 2,049 | advent-of-code-2022 | MIT License |
src/Day05.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | import kotlin.text.StringBuilder
fun main() {
fun parseCargoLine(line: String): List<Char?> = buildList {
var currentIdx = 0
while (currentIdx < line.length) {
val cargo = line.substring(currentIdx, currentIdx + 3)
val cargoLetter = if (cargo.isNotBlank()) {
... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 3,253 | aoc2022 | Apache License 2.0 |
src/main/kotlin/com/uber/tagir/advent2018/day04/day04.kt | groz | 159,977,575 | false | null | package com.uber.tagir.advent2018.day04
import com.uber.tagir.advent2018.utils.resourceAsString
fun main(args: Array<String>) {
with(Day04()) {
strategy1()
strategy2()
}
}
class Day04 {
private val input = resourceAsString("input.txt").lines().sorted()
private val schedule = parseSche... | 0 | Kotlin | 0 | 0 | 19b5a5b86c9a3d2803192b8c6786a25151b5144f | 2,762 | advent2018 | MIT License |
src/com/ncorti/aoc2023/Day04.kt | cortinico | 723,409,155 | false | {"Kotlin": 76642} | package com.ncorti.aoc2023
data class ScratchCard(val winningNumbers: List<Int>, val playerNumbers: List<Int>, var count: Int = 1) {
companion object {
fun from(input: String) = ScratchCard(
winningNumbers = input.substringAfter(":").substringBefore("|").split(" ").filter(String::isNotBlank)
... | 1 | Kotlin | 0 | 1 | 84e06f0cb0350a1eed17317a762359e9c9543ae5 | 1,555 | adventofcode-2023 | MIT License |
src/main/kotlin/com/groundsfam/advent/y2023/d05/Day05.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2023.d05
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.except
import com.groundsfam.advent.rangeIntersect
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
// Models the mapping specified by a single row of the input.
//
// ... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 3,378 | advent-of-code | MIT License |
src/main/kotlin/nl/dirkgroot/adventofcode/year2021/Day24.kt | dirkgroot | 317,968,017 | false | {"Kotlin": 187862} | package nl.dirkgroot.adventofcode.year2021
import nl.dirkgroot.adventofcode.util.Puzzle
import kotlin.math.pow
class Day24 : Puzzle() {
private val functions = listOf(
1L, 13L, 8L, 1L, 12L, 13L, 1L, 12L, 8L, 1L, 10L, 10L, 26L, -11L, 12L, 26L, -13L, 1L, 1L, 15L, 13L,
1L, 10L, 5L, 26L, -2L, 10L, 26L... | 1 | Kotlin | 1 | 1 | ffdffedc8659aa3deea3216d6a9a1fd4e02ec128 | 4,070 | adventofcode-kotlin | MIT License |
y2023/src/main/kotlin/adventofcode/y2023/Day11.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2023
import adventofcode.io.AdventSolution
import adventofcode.util.collections.combinations
import adventofcode.util.vector.Vec2
fun main() {
Day11.solve()
}
object Day11 : AdventSolution(2023, 11, "Cosmic Expansion") {
override fun solvePartOne(input: String) = solve(input, expansion... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,377 | advent-of-code | MIT License |
src/Day01.kt | roxspring | 573,123,316 | false | {"Kotlin": 9291} | fun main() {
fun part1(input: List<String>): Int = input.chunkedByBlank()
.map { lines -> lines.sumOf { it.toInt() } }
.max()
fun part2(input: List<String>): Int = input.chunkedByBlank()
.map { lines -> lines.sumOf { it.toInt() } }
.sortedDescending()
.take(3)
.... | 0 | Kotlin | 0 | 0 | 535beea93bf84e650d8640f1c635a430b38c169b | 1,006 | advent-of-code-2022 | Apache License 2.0 |
src/aoc2022/Day07.kt | FluxCapacitor2 | 573,641,929 | false | {"Kotlin": 56956} | package aoc2022
import Day
object Day07 : Day(2022, 7) {
data class Node(val name: String, val size: Int) {
var parent: Node? = null
private val children = mutableListOf<Node>()
fun addChild(name: String, size: Int) {
Node(name, size).let {
children.add(it)
... | 0 | Kotlin | 0 | 0 | a48d13763db7684ee9f9129ee84cb2f2f02a6ce4 | 3,845 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day20/Day20.kt | qnox | 575,581,183 | false | {"Kotlin": 66677} | package day20
import readInput
fun main() {
fun mix(numbers: IntArray, decryptionKey: Int = 1, repeatCount: Int = 1): List<Long> {
val actualNumbers = numbers.map { it.toLong() * decryptionKey }.withIndex()
val mixed = actualNumbers.toMutableList()
repeat(repeatCount) {
actua... | 0 | Kotlin | 0 | 0 | 727ca335d32000c3de2b750d23248a1364ba03e4 | 1,463 | aoc2022 | Apache License 2.0 |
app/src/main/kotlin/io/github/andrewfitzy/day04/Task02.kt | andrewfitzy | 747,793,365 | false | {"Kotlin": 60159, "Shell": 1211} | package io.github.andrewfitzy.day04
private const val LETTERS_IN_ALPHABET = 26
private const val LOWER_Z_VALUE = 122
private const val LOWER_A_VALUE = 96
class Task02(puzzleInput: List<String>) {
private val input: List<String> = puzzleInput
fun solve(targetRoom: String): Int {
var targetSectorId =... | 0 | Kotlin | 0 | 0 | 15ac072a14b83666da095b9ed66da2fd912f5e65 | 2,513 | 2016-advent-of-code | Creative Commons Zero v1.0 Universal |
src/pl/shockah/aoc/y2021/Day8.kt | Shockah | 159,919,224 | false | null | package pl.shockah.aoc.y2021
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import pl.shockah.aoc.AdventTask
import java.util.*
class Day8: AdventTask<List<Day8.Input>, Int, Int>(2021, 8) {
companion object {
const val segmentCount = 7
val digits = listOf(
BitSet(segmentCount).appl... | 0 | Kotlin | 0 | 0 | 9abb1e3db1cad329cfe1e3d6deae2d6b7456c785 | 6,179 | Advent-of-Code | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch1/Problem15.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch1
import dev.bogwalk.util.combinatorics.binomialCoefficient
import java.math.BigInteger
/**
* Problem 15: Lattice Paths
*
* https://projecteuler.net/problem=15
*
* Goal: Find the number of routes through an NxM grid, starting at (0,0) & ending at (n,m),
* while only being able to move r... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 3,349 | project-euler-kotlin | MIT License |
advent-of-code-2022/src/Day13.kt | osipxd | 572,825,805 | false | {"Kotlin": 141640, "Shell": 4083, "Scala": 693} | fun main() {
val testInput = readInput("Day13_test")
val input = readInput("Day13")
"Part 1" {
part1(testInput) shouldBe 13
answer(part1(input))
}
"Part 2" {
part2(testInput) shouldBe 140
answer(part2(input))
}
}
private fun part1(packets: List<Packet>): Int {
... | 0 | Kotlin | 0 | 5 | 6a67946122abb759fddf33dae408db662213a072 | 2,962 | advent-of-code | Apache License 2.0 |
year2021/src/main/kotlin/net/olegg/aoc/year2021/day17/Day17.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2021.day17
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.Vector2D
import net.olegg.aoc.year2021.DayOf2021
import kotlin.math.sign
/**
* See [Year 2021, Day 17](https://adventofcode.com/2021/day/17)
*/
object Day17 : DayOf2021(17) {
private val PATTERN = "target area: x=... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,964 | adventofcode | MIT License |
src/Day02.kt | nielsz | 573,185,386 | false | {"Kotlin": 12807} | fun main() {
fun getBasicScore(their: Char, mine: Char): Int {
return if (their != mine) {
when {
their == 'A' && mine == 'B' -> 6
their == 'B' && mine == 'C' -> 6
their == 'C' && mine == 'A' -> 6
else -> 0
}
} e... | 0 | Kotlin | 0 | 0 | 05aa7540a950191a8ee32482d1848674a82a0c71 | 1,445 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/no/chriswk/aoc2019/Day10.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package no.chriswk.aoc2019
import kotlin.math.PI
import kotlin.math.atan2
import kotlin.math.hypot
class Day10 {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day10 = Day10()
report { day10.part1() }
report { day10.part2() }
}
}
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,467 | adventofcode2019 | MIT License |
src/Day08.kt | cerberus97 | 579,910,396 | false | {"Kotlin": 11722} | import kotlin.math.max
fun main() {
class Forest(val grid: List<String>) {
val n = grid.size
val m = grid[0].length
fun inRange(i: Int, j: Int): Boolean =
(i in 0 until n) && (j in 0 until m)
tailrec fun visible(i: Int, j: Int, di: Int, dj: Int, height: Int): Boolean {
val ni = i + di
... | 0 | Kotlin | 0 | 0 | ed7b5bd7ad90bfa85e868fa2a2cdefead087d710 | 1,808 | advent-of-code-2022-kotlin | Apache License 2.0 |
kotlin/Dijkstra.kt | indy256 | 1,493,359 | false | {"Java": 545116, "C++": 266009, "Python": 59511, "Kotlin": 28391, "Rust": 4682, "CMake": 571} | object Dijkstra {
data class Edge(val target: Int, val cost: Int)
data class ShortestPaths(val dist: IntArray, val pred: IntArray)
fun shortestPaths(graph: Array<out List<Edge>>, s: Int): ShortestPaths {
val n = graph.size
val dist = IntArray(n) { Int.MAX_VALUE }
dist[s] = 0
... | 97 | Java | 561 | 1,806 | 405552617ba1cd4a74010da38470d44f1c2e4ae3 | 1,731 | codelibrary | The Unlicense |
src/day14/Day14.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day14
import readInput
data class Point(var x: Int, var y: Int)
enum class Occupier {
ROCK,
SAND
}
class Cave(rockPaths: List<String>) {
var occupiedCells = HashMap<Point, Occupier>()
var maxDepth = 0
init {
for (path in rockPaths) {
val endPoints = path.split(Regex(... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 3,424 | AdventOfCode2022 | Apache License 2.0 |
src/Day04.kt | akunowski | 573,109,101 | false | {"Kotlin": 5413} | fun main() {
fun toRange(s: List<String>): IntRange = s[0].toInt()..s[1].toInt()
fun isOverlapping(first: IntRange, second: IntRange): Boolean {
val union = first union second
return union == first.toSet() || union == second.toSet()
}
fun part1(input: List<String>): Int =
inpu... | 0 | Kotlin | 0 | 0 | b306b779386c793f5bf9d8a86a59a7d0755c6159 | 930 | aoc-2022 | Apache License 2.0 |
src/Day07.kt | sungi55 | 574,867,031 | false | {"Kotlin": 23985} | private const val CD = "$ cd "
private const val LS = "$ ls"
private const val DIR = "dir"
fun main() {
val day = "Day07"
val directorySizes: MutableList<Int> = mutableListOf()
fun getRootNode(input: List<String>): Node {
val root = Node("/", null)
var current = root
input.forEach... | 0 | Kotlin | 0 | 0 | 2a9276b52ed42e0c80e85844c75c1e5e70b383ee | 2,225 | aoc-2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.