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/main/kotlin/y2022/day08/Day08.kt | TimWestmark | 571,510,211 | false | {"Kotlin": 97942, "Shell": 1067} | package y2022.day08
import Matrix
import MatrixUtils
fun main() {
AoCGenerics.printAndMeasureResults(
part1 = { part1() },
part2 = { part2() }
)
}
data class Tree(
val height: Int,
var counted: Boolean,
var scenicScore: Int = 0,
)
fun input(): Matrix<Tree> {
return MatrixUtil... | 0 | Kotlin | 0 | 0 | 23b3edf887e31bef5eed3f00c1826261b9a4bd30 | 2,694 | AdventOfCode | MIT License |
code-sample-kotlin/algorithms/src/main/kotlin/com/codesample/leetcode/easy/1534_CountGoodTriplets.kt | aquatir | 76,377,920 | false | {"Java": 674809, "Python": 143889, "Kotlin": 112192, "Haskell": 57852, "Elixir": 33284, "TeX": 20611, "Scala": 17065, "Dockerfile": 6314, "HTML": 4714, "Shell": 387, "Batchfile": 316, "Erlang": 269, "CSS": 97} | package com.codesample.leetcode.easy
/**
* 1534. Count Good Triplets. https://leetcode.com/problems/count-good-triplets/
*
* Given an array of integers arr, and three integers a, b and c. You need to find the number of good triplets.
*
* A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are t... | 1 | Java | 3 | 6 | eac3328ecd1c434b1e9aae2cdbec05a44fad4430 | 1,449 | code-samples | MIT License |
src/main/kotlin/dev/bogwalk/batch6/Problem66.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch6
import kotlin.math.sqrt
import kotlin.math.truncate
/**
* Problem 66: Diophantine Equation
*
* https://projecteuler.net/problem=66
*
* Goal: Given a quadratic Diophantine equation of the form, x^2 - Dy^2 = 1, find the value of
* D <= N in minimal solutions of x for which the largest v... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 3,195 | project-euler-kotlin | MIT License |
src/AOC2022/Day03/Day03.kt | kfbower | 573,519,224 | false | {"Kotlin": 44562} | package AOC2022.Day03
import AOC2022.readInput
fun main() {
fun part1(input: List<String>): Int {
val priorityValueMap: MutableMap<Char, Int> = buildPriorityList()
val priorityList: MutableList<Int> = mutableListOf()
input.forEachIndexed { i, s ->
val list1: MutableList<Ch... | 0 | Kotlin | 0 | 0 | 48a7c563ebee77e44685569d356a05e8695ae36c | 3,188 | advent-of-code-2022 | Apache License 2.0 |
src/year2021/13/Day13.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2021.`13`
import readInput
private data class Point(
val x: Int,
val y: Int
)
private fun extractPoints(input: List<String>): Set<Point> {
return input.takeWhile { it.isNotBlank() }
.map {
val (x, y) = it.split(",")
.map { it.toInt() }
Point(x,... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 3,430 | KotlinAdventOfCode | Apache License 2.0 |
src/Day05.kt | jwalter | 573,111,342 | false | {"Kotlin": 19975} | fun main() {
data class Cmd(val from: Int, val to: Int, val count: Int)
fun parseInput(input: List<String>): Pair<List<MutableList<String>>, List<Cmd>> {
val stackRows = input.takeWhile { it.contains("[") }.map { it.chunked(4) }
val stackCount = stackRows.maxOf { it.size }
val stacks = ... | 0 | Kotlin | 0 | 0 | 576aeabd297a7d7ee77eca9bb405ec5d2641b441 | 2,029 | adventofcode2022 | Apache License 2.0 |
src/Day05.kt | Olivki | 573,156,936 | false | {"Kotlin": 11297} | import java.util.LinkedList
fun main() {
val excessiveWhitespace = """\s+""".toRegex()
data class CraneData(val cranes: List<LinkedList<Char>>, val instructions: List<List<Int>>)
fun parseInput(input: List<String>): CraneData {
val separatorIndex = input.indexOfFirst { it.isBlank() }
val ... | 0 | Kotlin | 0 | 1 | 51c408f62589eada3d8454740c9f6fc378e2d09b | 2,610 | aoc-2022 | Apache License 2.0 |
src/day15/Day15.kt | xxfast | 572,724,963 | false | {"Kotlin": 32696} | package day15
import geometry.*
import readLines
import kotlin.math.abs
data class Record(val sensor: Point, val beacon: Point, val distance: Long = distance(sensor, beacon) + 1)
val regex = Regex("""-?\d{1,7}""")
fun format(inputs: List<String>): Set<Record> = inputs
.map { line ->
regex.findAll(line).toList... | 0 | Kotlin | 0 | 1 | a8c40224ec25b7f3739da144cbbb25c505eab2e4 | 3,581 | advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/day08/Day08.kt | TheSench | 572,930,570 | false | {"Kotlin": 128505} | package day08
import runDay
fun main() {
fun part1(input: List<String>) =
input.toGrid().visibilityMap.sumOf { row -> row.count { it } }
fun part2(input: List<String>) =
input.toGrid().let { grid ->
grid.mapCellsIndexed { x, y, value ->
grid.scenicScore(x, y, value... | 0 | Kotlin | 0 | 0 | c3e421d75bc2cd7a4f55979fdfd317f08f6be4eb | 3,706 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day05.kt | zychu312 | 573,345,747 | false | {"Kotlin": 15557} | import java.util.Stack
class Day05 {
data class MoveOperation(val howMany: Int, val fromStack: Int, val toStack: Int)
private fun parseStacks(allLines: List<String>): List<Stack<Char>> {
val stacksInput = allLines
.takeWhile { !it.trim().startsWith("1") }
.map { line ->
... | 0 | Kotlin | 0 | 0 | 3e49f2e3aafe53ca32dea5bce4c128d16472fee3 | 2,875 | advent-of-code-kt | Apache License 2.0 |
src/y2023/d01/Day01.kt | AndreaHu3299 | 725,905,780 | false | {"Kotlin": 31452} | package y2023.d01
import println
import readInput
fun main() {
val classPath = "y2023/d01"
fun part1(input: List<String>): Int {
return input.sumOf { line ->
val firstDigit = line.find { it.isDigit() }?.toString() ?: "0"
val lastDigit = line.findLast { it.isDigit() }?.toString... | 0 | Kotlin | 0 | 0 | f883eb8f2f57f3f14b0d65dafffe4fb13a04db0e | 1,704 | aoc | Apache License 2.0 |
app/src/main/kotlin/day02/Day02.kt | StylianosGakis | 434,004,245 | false | {"Kotlin": 56380} | package day02
import common.InputRepo
import common.readSessionCookie
import common.solve
fun main(args: Array<String>) {
val day = 2
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay02Part1, ::solveDay02Part2)
}
enum class SubmarineAction {
Forward,
Dow... | 0 | Kotlin | 0 | 0 | a2dad83d8c17a2e75dcd00651c5c6ae6691e881e | 2,222 | advent-of-code-2021 | Apache License 2.0 |
src/Day03.kt | Redstonecrafter0 | 571,787,306 | false | {"Kotlin": 19087} |
fun main() {
fun prioritize(common: List<Char>): Int {
return common.sumOf {
if (it in 'a'..'z') {
it - 'a' + 1
} else {
it - 'A' + 27
}
}
}
fun part1(input: List<String>): Int {
val rucksacks = input.map { it.subs... | 0 | Kotlin | 0 | 0 | e5dbabe247457aabd6dd0f0eb2eb56f9e4c68858 | 1,283 | Advent-of-Code-2022 | Apache License 2.0 |
src/Day03.kt | akunowski | 573,109,101 | false | {"Kotlin": 5413} | fun main() {
fun compartmentsItems(items: String): Pair<Set<Char>, Set<Char>> {
val leftCompartment = HashSet<Char>()
val rightCompartment = HashSet<Char>()
for (i: Int in 0 until items.length / 2) {
leftCompartment.add(items[i])
rightCompartment.add(items[items.len... | 0 | Kotlin | 0 | 0 | b306b779386c793f5bf9d8a86a59a7d0755c6159 | 1,223 | aoc-2022 | Apache License 2.0 |
src/year2022/day05/Day05.kt | kingdongus | 573,014,376 | false | {"Kotlin": 100767} | package year2022.day05
import partitionBy
import readInputFileByYearAndDay
import readTestFileByYearAndDay
fun main() {
fun moveCrates(input: List<String>, multipleAtOnce: Boolean = false): Array<String> {
val cratesAndInstructions = input.partitionBy { it.isBlank() }
val initialCrates = crate... | 0 | Kotlin | 0 | 0 | aa8da2591310beb4a0d2eef81ad2417ff0341384 | 2,025 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/day11/Day11.kt | jankase | 573,187,696 | false | {"Kotlin": 70242} | package day11
import Day
import extractAllIntegers
import extractAllLongs
import lcm
import product
import solve
typealias WorryLevel = Long
fun String.toWorryLevel(): WorryLevel? = toLongOrNull()
infix fun WorryLevel.divisibleBy(divisor: Int) = this % divisor == 0L
class Day11 : Day(11, 2022, "Monkey in the Middle"... | 0 | Kotlin | 0 | 0 | 0dac4ec92c82a5ebb2179988fb91fccaed8f800a | 3,905 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch6/Problem68.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch6
import dev.bogwalk.util.combinatorics.permutations
/**
* Problem 68: Magic 5-Gon Ring
*
* https://projecteuler.net/problem=68
*
* Goal: Given N, representing a magic N-gon ring, and S, representing the total to which each
* ring's line sums, return all concatenated strings (in lexicog... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 11,230 | project-euler-kotlin | MIT License |
src/Day09.kt | oleksandrbalan | 572,863,834 | false | {"Kotlin": 27338} | import kotlin.math.abs
fun main() {
val input = readInput("Day09")
.filterNot { it.isEmpty() }
.map {
val (direction, count) = it.split(" ")
List(count.toInt()) { direction }
}
.flatten()
val part1Rope = Array(2) { Coordinate(0, 0) }
val part1Positio... | 0 | Kotlin | 0 | 2 | 1493b9752ea4e3db8164edc2dc899f73146eeb50 | 1,588 | advent-of-code-2022 | Apache License 2.0 |
src/Day14.kt | iam-afk | 572,941,009 | false | {"Kotlin": 33272} | import kotlin.math.max
import kotlin.math.min
fun main() {
class Rocks(input: List<String>) {
private val horizontal: Map<Int, List<IntRange>>
private val vertical: Map<Int, List<IntRange>>
val maxY: Int
init {
val h = mutableMapOf<Int, MutableList<IntRange>>()
... | 0 | Kotlin | 0 | 0 | b30c48f7941eedd4a820d8e1ee5f83598789667b | 2,817 | aockt | Apache License 2.0 |
src/main/java/com/ncorti/aoc2021/Exercise05.kt | cortinico | 433,486,684 | false | {"Kotlin": 36975} | package com.ncorti.aoc2021
import kotlin.math.max
import kotlin.math.min
object Exercise05 {
private fun getInput() =
getInputAsTest("05") { split("\n") }.map { it.split(",", " -> ").map(String::toInt) }.map {
(i0, i1, i2, i3) ->
if (i2 < i0) {
listOf(i2, i3, i0, i... | 0 | Kotlin | 0 | 4 | af3df72d31b74857201c85f923a96f563c450996 | 1,846 | adventofcode-2021 | MIT License |
2k23/aoc2k23/src/main/kotlin/05.kt | papey | 225,420,936 | false | {"Rust": 88237, "Kotlin": 63321, "Elixir": 54197, "Crystal": 47654, "Go": 44755, "Ruby": 24620, "Python": 23868, "TypeScript": 5612, "Scheme": 117} | package d05
import input.raw
import java.util.concurrent.atomic.AtomicLong
import kotlin.math.min
import kotlin.streams.asStream
fun main() {
println("Part 1: ${part1(raw("05.txt").trim())}")
println("Part 2: ${part2(raw("05.txt").trim())}")
}
fun part1(input: String): Long {
val (seeds, maps) = parse(in... | 0 | Rust | 0 | 3 | cb0ea2fc043ebef75aff6795bf6ce8a350a21aa5 | 1,620 | aoc | The Unlicense |
src/AoC19.kt | Pi143 | 317,631,443 | false | null | import java.io.File
fun main() {
println("Starting Day 19 A Test 1")
calculateDay19PartA("Input/2020_Day19_Rules_Test1", "Input/2020_Day19_A_Messages_Test1")
println("Starting Day 19 A Real")
calculateDay19PartA("Input/2020_Day19_Rules", "Input/2020_Day19_A_Messages")
println("Starting Day 19 B T... | 0 | Kotlin | 0 | 1 | fa21b7f0bd284319e60f964a48a60e1611ccd2c3 | 2,727 | AdventOfCode2020 | MIT License |
src/main/kotlin/ru/timakden/aoc/year2023/Day03.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2023
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 3: Gear Ratios](https://adventofcode.com/2023/day/3).
*/
object Day03 {
@JvmStatic
fun main(args: Array<String>) {
measure {
val input = readInput("year2023/Day03")
... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 2,213 | advent-of-code | MIT License |
src/year2022/day16/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2022.day16
import io.kotest.matchers.shouldBe
import java.util.LinkedList
import kotlin.math.ceil
import utils.Graph
import utils.Identifiable
import utils.Identifier
import utils.cartesianProduct
import utils.combinations
import utils.findShortestRoute
import utils.readInput
fun main() {
val testInpu... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 5,474 | Advent-of-Code | Apache License 2.0 |
advent2021/src/main/kotlin/year2021/Day04.kt | bulldog98 | 572,838,866 | false | {"Kotlin": 132847} | package year2021
import AdventDay
import year2021.day04.Board
import year2021.day04.toGameInput
private fun Board.isWinning(drawn: Collection<Int>): Boolean {
val rowIsWinning = rows.any { row -> row.cells.count { drawn.contains(it) } == 5 }
val columnIsWinning = columns.any { column -> column.count { drawn.c... | 0 | Kotlin | 0 | 0 | 02ce17f15aa78e953a480f1de7aa4821b55b8977 | 1,671 | advent-of-code | Apache License 2.0 |
2022/src/day02/Day02.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day02
import java.io.File
fun main() {
val input = File("src/day02/day2input.txt").readLines()
println(input.sumOf { calculateScore(it) })
println(input.sumOf { calculateSecretScore(it) })
}
fun getWinTable(): Map<String, Int> {
return mapOf(
"A X" to 0,
"A Y" to 1,
"A... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 1,553 | adventofcode | Apache License 2.0 |
src/Day04.kt | Redstonecrafter0 | 571,787,306 | false | {"Kotlin": 19087} |
fun main() {
fun part1(input: List<String>): Int {
return input
.map { it.split(",").map { i -> i.split("-").map { j -> j.toInt() } } }
.map { it.map { i -> i[0]..i[1] } }
.map { it[0] to it[1] }
.count { (first, second) ->
(first.first in sec... | 0 | Kotlin | 0 | 0 | e5dbabe247457aabd6dd0f0eb2eb56f9e4c68858 | 1,097 | Advent-of-Code-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/year2021/Day06.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2021
private fun solve(input: String, days: Int): Long {
val lanternFishes = lanternFishes(input)
simulateDays(lanternFishes, days)
return lanternFishes.countLanterfishs()
}
private fun part1(input: String): Long {
return solve(input, 80)
}
private fun part2(input: String): Long {
r... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 1,668 | advent-of-code | MIT License |
src/Day02.kt | kipwoker | 572,884,607 | false | null | enum class Figure(val score: Int) {
Rock(1),
Paper(2),
Scissors(3)
}
fun main() {
fun createFigure(value: String): Figure {
return when (value) {
"A" -> Figure.Rock
"B" -> Figure.Paper
"C" -> Figure.Scissors
"X" -> Figure.Rock
"Y" -> F... | 0 | Kotlin | 0 | 0 | d8aeea88d1ab3dc4a07b2ff5b071df0715202af2 | 2,496 | aoc2022 | Apache License 2.0 |
src/main/kotlin/day3.kt | noamfree | 433,962,392 | false | {"Kotlin": 93533} | private val testInput1 = """
00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010
""".trimIndent()
private fun tests() {
assertEquals(gammaRate(parseInput(testInput1)), "10110")
assertEquals(gammaRateDecimal(parseInput(testInput1)), 22)
ass... | 0 | Kotlin | 0 | 0 | 566cbb2ef2caaf77c349822f42153badc36565b7 | 2,656 | AOC-2021 | MIT License |
src/main/kotlin/_2022/Day23.kt | novikmisha | 572,840,526 | false | {"Kotlin": 145780} | package _2022
import readInput
fun main() {
fun parseElves(input: List<String>): Set<MutablePair<Int, Int>> {
val elves = mutableSetOf<MutablePair<Int, Int>>()
input.forEachIndexed { index, str ->
str.forEachIndexed { strIndex, char ->
if (char == '#')
... | 0 | Kotlin | 0 | 0 | 0c78596d46f3a8bf977bf356019ea9940ee04c88 | 3,005 | advent-of-code | Apache License 2.0 |
src/Day10.kt | p357k4 | 573,068,508 | false | {"Kotlin": 59696} | sealed interface Command {
object MicroNoop : Command
data class MicroAddX(val v: Int) : Command
}
fun main() {
fun commands(input: List<String>) = input
.flatMap { line ->
val split = line.split(' ')
when (split[0]) {
"noop" -> sequenceOf(Command.MicroNoop)
... | 0 | Kotlin | 0 | 0 | b9047b77d37de53be4243478749e9ee3af5b0fac | 1,932 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day05.kt | Akhunzaada | 573,119,655 | false | {"Kotlin": 23755} | import java.io.File
import java.util.Stack
data class Cargo(val stacks: List<Stack<Char>>) {
fun peekStacks() = buildString {
stacks.forEach {
append(it.peek())
}
}
}
data class ArrangeCrates(val quantity: Int, private val _fromStack: Int, private val _toStack: Int) {
val fromS... | 0 | Kotlin | 0 | 0 | b2754454080989d9579ab39782fd1d18552394f0 | 2,936 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/com/github/jntakpe/aoc2022/days/Day24.kt | jntakpe | 572,853,785 | false | {"Kotlin": 72329, "Rust": 15876} | import Day24.Direction.*
import com.github.jntakpe.aoc2022.shared.Day
import com.github.jntakpe.aoc2022.shared.readInputLines
import kotlin.math.abs
object Day24 : Day {
override val input = readInputLines(24)
override fun part1(): Int {
return Terrain.from(input).run { optimalPath(this, State(start,... | 1 | Kotlin | 0 | 0 | 63f48d4790f17104311b3873f321368934060e06 | 5,752 | aoc2022 | MIT License |
src/main/kotlin/com/briarshore/aoc2022/day09/RopeBridgePuzzle.kt | steveswing | 579,243,154 | false | {"Kotlin": 47151} | package com.briarshore.aoc2022.day09
import com.briarshore.aoc2022.day09.Direction.*
import println
import readInput
import kotlin.math.abs
enum class Direction(val move: Move) {
UP(Move(0, 1)), DOWN(Move(0, -1)), LEFT(Move(-1, 0)), RIGHT(Move(1, 0))
}
data class Pos(val x: Int, val y: Int)
data class Move(val d... | 0 | Kotlin | 0 | 0 | a0d19d38dae3e0a24bb163f5f98a6a31caae6c05 | 2,550 | 2022-AoC-Kotlin | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem712/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem712
/**
* LeetCode page: [712. Minimum ASCII Delete Sum for Two Strings](https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/);
*/
class Solution {
/* Complexity:
* Time O(MN) and Space O(MN) where M and N are the length of s1 and s2 respectively;
... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,002 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2015/2015-21.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2015
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputText
fun main() {
val input = readInputText(2015, "21-input")
println("Part1:")
part1(input).println()
println()
println("Part2:")
part2(input).pr... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 3,311 | advent-of-code | MIT License |
src/Day04.kt | bjornchaudron | 574,072,387 | false | {"Kotlin": 18699} | fun String.toIntRanges(): Pair<IntRange, IntRange> {
fun String.toIntRange(): IntRange {
val (start, end) = split("-").map { it.toInt() }
return start..end
}
val (first, second) = split(",")
return Pair(first.toIntRange(), second.toIntRange())
}
fun IntRange.contains(other: IntRange) = ... | 0 | Kotlin | 0 | 0 | f714364698966450eff7983fb3fda3a300cfdef8 | 1,124 | advent-of-code-2022 | Apache License 2.0 |
src/leetcodeProblem/leetcode/editor/en/ReplaceWords.kt | faniabdullah | 382,893,751 | false | null | //In English, we have a concept called root, which can be followed by some
//other word to form another longer word - let's call this word successor. For example,
// when the root "an" is followed by the successor word "other", we can form a
//new word "another".
//
// Given a dictionary consisting of many roots and ... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 3,552 | dsa-kotlin | MIT License |
src/day03/Day03.kt | commanderpepper | 574,647,779 | false | {"Kotlin": 44999} | package day03
import readInput
fun main() {
// list of items currently in each rucksack (puzzle input)
val day3Input = readInput("day03")
partOne(day3Input)
partTwo(day3Input)
}
private fun partTwo(day3Input: List<String>) {
val elfGroups = day3Input.chunked(3).map {
ElfGroup(it[0], it[1... | 0 | Kotlin | 0 | 0 | fef291c511408c1a6f34a24ed7070ceabc0894a1 | 1,467 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day07.kt | l8nite | 573,298,097 | false | {"Kotlin": 105683} | class File(
val path: String,
val isDirectory: Boolean = false,
var size: Int = 0,
var parent: File? = null
) {
fun addFile(file: File) {
increaseSize(file)
}
fun increaseSize(file: File) {
size += file.size
this.parent?.increaseSize(file)
}
}
fun pathify(it: Str... | 0 | Kotlin | 0 | 0 | f74331778fdd5a563ee43cf7fff042e69de72272 | 2,999 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/org/deep/quined/algo/quine.kt | RedDocMD | 347,395,585 | false | null | package org.deep.quined.algo
fun partitionCubesByOneCount(cubes: List<Cube>): Map<Int, List<Cube>> {
val partitions = mutableMapOf<Int, MutableList<Cube>>()
for (cube in cubes) {
partitions.getOrPut(cube.oneCount, { mutableListOf() }).add(cube)
}
return partitions
}
data class ReductionStepRes... | 0 | Kotlin | 1 | 3 | 22e0783bcc257ffad15cbf3008ab59b623787920 | 2,910 | QuinedAgain | MIT License |
code-sample-kotlin/algorithms/src/main/kotlin/com/codesample/leetcode/medium/907_subOfSubarrayMinimums.kt | aquatir | 76,377,920 | false | {"Java": 674809, "Python": 143889, "Kotlin": 112192, "Haskell": 57852, "Elixir": 33284, "TeX": 20611, "Scala": 17065, "Dockerfile": 6314, "HTML": 4714, "Shell": 387, "Batchfile": 316, "Erlang": 269, "CSS": 97} | package com.codesample.leetcode.medium
/** 907. Sum of Subarray Minimums Given an array of integers arr, find the sum of min(b), where b ranges over every
* (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 10^9 + 7.
*
* Input: arr = [3,1,2,4]
* Output: 17
* Explanation:
* Sub... | 1 | Java | 3 | 6 | eac3328ecd1c434b1e9aae2cdbec05a44fad4430 | 4,693 | code-samples | MIT License |
src/Day11.kt | rod41732 | 572,917,438 | false | {"Kotlin": 85344} | private typealias Operand = (v: Long) -> Long
// ALL calculations use Long to prevent integer overflow
private enum class Operator { ADD, MUL }
private data class Expression(val left: Operand, val op: Operator, val right: Operand) {
fun evaluate(old: Long): Long {
val lhs = left(old)
val rhs = righ... | 0 | Kotlin | 0 | 0 | 1d2d3d00e90b222085e0989d2b19e6164dfdb1ce | 3,672 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day09.kt | bananer | 434,885,332 | false | {"Kotlin": 36979} | typealias Heightmap = Array<Array<Int>>
fun Heightmap.get(x: Int, y: Int) = this[y][x]
val Heightmap.width: Int
get() = this[0].size
val Heightmap.height: Int
get() = this.size
fun Heightmap.getAdjacentCoordinates(x: Int, y: Int): List<Pair<Int, Int>> {
val result = mutableListOf<Pair<Int, Int>>()
i... | 0 | Kotlin | 0 | 0 | 98f7d6b3dd9eefebef5fa3179ca331fef5ed975b | 3,774 | advent-of-code-2021 | Apache License 2.0 |
src/Day03.kt | sgc109 | 576,491,331 | false | {"Kotlin": 8641} | fun main() {
fun getPriority(ch: Char): Long =
if (ch.isLowerCase()) {
ch - 'a' + 1
} else {
ch - 'A' + 1 + 26
}.toLong()
fun part1(input: List<String>): Long {
return input.sumOf { line ->
val halfLen = line.length / 2
val left = ... | 0 | Kotlin | 0 | 0 | 03e4e85283d486430345c01d4c03419d95bd6daa | 1,246 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2019/Day14.kt | tginsberg | 222,116,116 | false | null | /*
* Copyright (c) 2019 by <NAME>
*/
/**
* Advent of Code 2019, Day 14 - Space Stoichiometry
* Problem Description: http://adventofcode.com/2019/day/14
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2019/day14/
*/
package com.ginsberg.advent2019
import kotlin.math.ceil
import kotlin.math.... | 0 | Kotlin | 2 | 23 | a83e2ecdb6057af509d1704ebd9f86a8e4206a55 | 3,073 | advent-2019-kotlin | Apache License 2.0 |
src/Day02.kt | topr | 572,937,822 | false | {"Kotlin": 9662} | import HandShape.Companion.handShape
enum class HandShape(val shapeScore: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3);
fun defeats(other: HandShape) = when (this) {
ROCK -> other == SCISSORS
PAPER -> other == ROCK
SCISSORS -> other == PAPER
}
companion object {
fun ... | 0 | Kotlin | 0 | 0 | 8c653385c9a325f5efa2895e94830c83427e5d87 | 1,853 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/days/Day13.kt | butnotstupid | 433,717,137 | false | {"Kotlin": 55124} | package days
class Day13 : Day(13) {
override fun partOne(): Any {
val delimiter = inputList.indexOfFirst { it.isEmpty() }
return inputList.withIndex().partition { it.index < delimiter }.let { (coord, directions) ->
val initialPoints = coord.map { it.value.split(",").map { it.toInt() }... | 0 | Kotlin | 0 | 0 | a06eaaff7e7c33df58157d8f29236675f9aa7b64 | 2,367 | aoc-2021 | Creative Commons Zero v1.0 Universal |
src/Day13.kt | ech0matrix | 572,692,409 | false | {"Kotlin": 116274} | fun main() {
fun compareOrder(p1: Packet, p2: Packet): Int {
//println("- Compare $p1 vs $p2")
var i = 0
while(true) {
if (i >= p1.items.size && i >= p2.items.size) {
// Both sides out of items. Go back up a level
return 0
} else if (i ... | 0 | Kotlin | 0 | 0 | 50885e12813002be09fb6186ecdaa3cc83b6a5ea | 4,333 | aoc2022 | Apache License 2.0 |
src/day20/second/Solution.kt | verwoerd | 224,986,977 | false | null | package day20.second
import day20.first.Maze
import day20.first.Portals
import day20.first.parseMaze
import tools.timeSolution
fun main() = timeSolution {
val (maze, portals) = parseMaze()
println(maze.findPath(portals))
}
private fun Maze.findPath(portals: Portals): Int {
val startCoordinate = portals.getValu... | 0 | Kotlin | 0 | 0 | 554377cc4cf56cdb770ba0b49ddcf2c991d5d0b7 | 1,937 | AoC2019 | MIT License |
src/main/kotlin/nl/dirkgroot/adventofcode/year2020/Day21.kt | dirkgroot | 317,968,017 | false | {"Kotlin": 187862} | package nl.dirkgroot.adventofcode.year2020
import nl.dirkgroot.adventofcode.util.Input
import nl.dirkgroot.adventofcode.util.Puzzle
class Day21(input: Input) : Puzzle() {
private val foodRegex = "(.*) \\(contains (.*)\\)".toRegex()
class Food(val ingredients: List<String>, val allergents: List<String>)
... | 1 | Kotlin | 1 | 1 | ffdffedc8659aa3deea3216d6a9a1fd4e02ec128 | 2,424 | adventofcode-kotlin | MIT License |
2022/13/13.kt | LiquidFun | 435,683,748 | false | {"Kotlin": 40554, "Python": 35985, "Julia": 29455, "Rust": 20622, "C++": 1965, "Shell": 1268, "APL": 191} | fun String.parseLists(): Any {
val stack: MutableList<MutableList<Any>> = mutableListOf(mutableListOf())
this.replace("]", ",}").replace("[", "{,").replace(",,", ",").split(",").forEach {
when (it) {
"{" -> { val m: MutableList<Any> = mutableListOf(); stack.last().add(m); stack.add(m) }
... | 0 | Kotlin | 7 | 43 | 7cd5a97d142780b8b33b93ef2bc0d9e54536c99f | 1,436 | adventofcode | Apache License 2.0 |
app/src/main/kotlin/advent/of/code/twentytwenty/Day4.kt | obarcelonap | 320,300,753 | false | null | package advent.of.code.twentytwenty
fun main() {
val input = getResourceAsText("/day4-input")
val part1Count = countValidPassports(input, ::requiredFieldsValidator)
println("Part1: count of valid passwords is $part1Count")
val part2Count = countValidPassports(input, ::fieldsValidator)
println("Pa... | 0 | Kotlin | 0 | 0 | a721c8f26738fe31190911d96896f781afb795e1 | 2,958 | advent-of-code-2020 | MIT License |
src/aoc2022/Day05.kt | miknatr | 576,275,740 | false | {"Kotlin": 413403} | package aoc2022
fun main() {
class Command(val howMany: Int, val from: Int, val to: Int)
class Warehouse(
val initState: List<ArrayDeque<String>>,
val commands: List<Command>,
) {
val topLetters get() = initState.map { it.last() }.joinToString("")
fun execute9000() = comma... | 0 | Kotlin | 0 | 0 | 400038ce53ff46dc1ff72c92765ed4afdf860e52 | 2,607 | aoc-in-kotlin | Apache License 2.0 |
src/Day08.kt | marosseleng | 573,498,695 | false | {"Kotlin": 32754} | fun main() {
fun part1(input: List<String>): Int {
return countVisibleTrees(constructMap(input))
}
fun part2(input: List<String>): Int {
return getMaxScenicScore(constructMap(input))
}
val testInput = readInput("Day08_test")
check(part1(testInput) == 21)
check(part2(testInp... | 0 | Kotlin | 0 | 0 | f13773d349b65ae2305029017490405ed5111814 | 3,848 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day05.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | fun main() {
fun readCrates(input: List<String>): List<MutableList<Char>> {
val crates: List<MutableList<Char>> = List((input.last().length + 2) / 4) { mutableListOf() }
for (line in input) {
line.chunked(4).forEachIndexed { index, part -> if (part[1].isLetter()) crates[index].add(part[1... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 1,857 | advent-of-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/Day10.kt | Ostkontentitan | 434,500,914 | false | {"Kotlin": 73563} | fun puzzleDayTenPartOne() {
val inputs = readInput(10)
val score = inputs.mapNotNull { findFirstIllegalChar(it) }.sumOf { ERROR_SCORE_MAP[it]!! }
println("Syntax error score: $score")
}
fun puzzleDayTenPartTwo() {
val inputs = readInput(10)
val sortedCompleteScores = calculateCompletionScoresAndSor... | 0 | Kotlin | 0 | 0 | e0e5022238747e4b934cac0f6235b92831ca8ac7 | 2,646 | advent-of-kotlin-2021 | Apache License 2.0 |
advent-of-code-2017/src/test/java/Day7RecursiveCircus.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
data class Node(
val name: String,
val ownWeight: Int,
val children: List<String>
)
class Day7RecursiveCircus {
@Test
fun star1Test() {
val nodes = parseInput(testInput)
assertThat(findRoot(nodes).name).isEqua... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 31,323 | advent-of-code | MIT License |
src/main/kotlin/Robots.kt | alebedev | 573,733,821 | false | {"Kotlin": 82424} | fun main() = Robots.solve()
private object Robots {
const val MAX_TURNS = 32
fun solve() {
val blueprints = readInput().take(3)
// println("1st: ${maxGeodes(blueprints.first())}")
val score = blueprints.map { maxGeodes(it) }.reduce { x, y -> x * y }
println("Total score: ${score... | 0 | Kotlin | 0 | 0 | d6ba46bc414c6a55a1093f46a6f97510df399cd1 | 6,778 | aoc2022 | MIT License |
kotlin/src/main/kotlin/com/github/jntakpe/aoc2021/days/day14/Day14.kt | jntakpe | 433,584,164 | false | {"Kotlin": 64657, "Rust": 51491} | package com.github.jntakpe.aoc2021.days.day14
import com.github.jntakpe.aoc2021.shared.Day
import com.github.jntakpe.aoc2021.shared.readInputSplitOnBlank
object Day14 : Day {
override val input = Instructions.from(readInputSplitOnBlank(14).map { it.lines() })
override fun part1() = input.result(10)
ove... | 0 | Kotlin | 1 | 5 | 230b957cd18e44719fd581c7e380b5bcd46ea615 | 1,847 | aoc2021 | MIT License |
src/Day05.kt | Shykial | 572,927,053 | false | {"Kotlin": 29698} | private val DIGIT_REGEX = Regex("""\D+""")
fun main() {
fun part1(input: List<String>): String {
val parsedInput = parseInput(input)
val stacks = parsedInput.initialState.map(::ArrayDeque)
parsedInput.instructions.forEach { instruction ->
repeat(instruction.numberOfCrates) {
... | 0 | Kotlin | 0 | 0 | afa053c1753a58e2437f3fb019ad3532cb83b92e | 2,158 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | benwicks | 572,726,620 | false | {"Kotlin": 29712} | import java.util.*
fun main() {
fun part1(input: List<String>): String {
val (stacks, steps) = parseInput(input)
for (step in steps) {
val (numToMove, stackFromIndex, stackToIndex) = parseStep(step)
for (i in 1..numToMove) {
stacks[stackToIndex].push(stacks[s... | 0 | Kotlin | 0 | 0 | fbec04e056bc0933a906fd1383c191051a17c17b | 2,612 | aoc-2022-kotlin | Apache License 2.0 |
src/Day03.kt | Xacalet | 576,909,107 | false | {"Kotlin": 18486} | /**
* ADVENT OF CODE 2022 (https://adventofcode.com/2022/)
*
* Solution to day 3 (https://adventofcode.com/2022/day/3)
*
*/
private typealias Rucksack = List<Char>
private val charToPriorityMap: Map<Char, Int> =
(('a'..'z') + ('A'..'Z')).withIndex().associate { (index, value) ->
value to index + 1
... | 0 | Kotlin | 0 | 0 | 5c9cb4650335e1852402c9cd1bf6f2ba96e197b2 | 1,037 | advent-of-code-2022 | Apache License 2.0 |
2020/src/main/kotlin/sh/weller/adventofcode/twentytwenty/Day7.kt | Guruth | 328,467,380 | false | {"Kotlin": 188298, "Rust": 13289, "Elixir": 1833} | package sh.weller.adventofcode.twentytwenty
fun List<String>.countBagsThatAreContained(color: String): Long {
val parsedInput = this.parseBaggageInput()
val rootBag = ContainedBag(color).appendLevel(parsedInput)
return rootBag!!.getNumOfContainedBags()
}
private fun ContainedBag.getNumOfContainedBags()... | 0 | Kotlin | 0 | 0 | 69ac07025ce520cdf285b0faa5131ee5962bd69b | 3,316 | AdventOfCode | MIT License |
src/Day13.kt | dakr0013 | 572,861,855 | false | {"Kotlin": 105418} | import kotlin.math.min
import kotlin.test.assertEquals
fun main() {
fun part1(input: List<String>): Int {
return parsePairsOfPackets(input)
.mapIndexedNotNull { index, pair ->
if (pair.isInRightOrder()) {
index + 1
} else {
null
}
}
.s... | 0 | Kotlin | 0 | 0 | 6b3adb09f10f10baae36284ac19c29896d9993d9 | 3,334 | aoc2022 | Apache License 2.0 |
src/day_3/kotlin/Day3.kt | Nxllpointer | 573,051,992 | false | {"Kotlin": 41751} | // AOC Day 3
data class Rucksack(val items: String) {
val firstCompartment = items.drop(items.length / 2)
val secondCompartment = items.dropLast(items.length / 2)
val misorderedItem by lazy {
firstCompartment.first { secondCompartment.contains(it) }
}
}
const val priorities = "abcdefghijklmno... | 0 | Kotlin | 0 | 0 | b6d7ef06de41ad01a8d64ef19ca7ca2610754151 | 1,303 | AdventOfCode2022 | MIT License |
src/year2023/day02/Day.kt | tiagoabrito | 573,609,974 | false | {"Kotlin": 73752} | package year2023.day02
import year2023.solveIt
fun main() {
val day = "02"
fun i(index: Int) = index
val expectedTest1 = 8L
val expectedTest2 = 2286L
val minimum = mapOf("red" to 12, "green" to 13, "blue" to 14)
fun canPlay(s: String): Boolean {
val map = s.substringAfter(":").spl... | 0 | Kotlin | 0 | 0 | 1f9becde3cbf5dcb345659a23cf9ff52718bbaf9 | 1,359 | adventOfCode | Apache License 2.0 |
src/Lesson9MaximumSliceProblem/MaxSliceSum.kt | slobodanantonijevic | 557,942,075 | false | {"Kotlin": 50634} | /**
* 100/100
* Kadane's algorithm
* @param A
* @return
*/
fun solution(A: IntArray): Int {
var maxSlice = A[0]
var maxEnding = A[0]
/**
* For each position, we compute the largest sum that ends in that position
* If we assume that the maximum sum of a slice ending in position i equals maxEnd... | 0 | Kotlin | 0 | 0 | 155cf983b1f06550e99c8e13c5e6015a7e7ffb0f | 1,747 | Codility-Kotlin | Apache License 2.0 |
src/Day03.kt | mvanderblom | 573,009,984 | false | {"Kotlin": 25405} | fun String.inHalf(): List<String> = listOf(
this.substring(0, this.length/2),
this.substring(this.length/2, this.length)
)
fun List<String>.intersection(): Set<Char> = this
.map { it.toSet() }
.reduceIndexed { i, acc, it -> if (i == 0) it else acc.intersect(it) }
val allLetters... | 0 | Kotlin | 0 | 0 | ba36f31112ba3b49a45e080dfd6d1d0a2e2cd690 | 1,157 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/day7.kt | Arch-vile | 572,557,390 | false | {"Kotlin": 132454} | package day7
import aoc.utils.*
data class File(val name: String, val size: Int)
data class Directory(
val name: String,
val parent: Directory?,
val dirs: MutableList<Directory> = mutableListOf(),
val files: MutableList<File> = mutableListOf()
) {
fun cd(dirName: String): Directory {
retur... | 0 | Kotlin | 0 | 0 | e737bf3112e97b2221403fef6f77e994f331b7e9 | 1,932 | adventOfCode2022 | Apache License 2.0 |
src/year2015/day11/Day11.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2015.day11
import check
import readInput
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("2015", "Day11_test")
check(part1(testInput), "abcdffaa")
val input = readInput("2015", "Day11")
println(part1(input))
println(part2... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 1,466 | AdventOfCode | Apache License 2.0 |
src/Day07.kt | makohn | 571,699,522 | false | {"Kotlin": 35992} | fun main() {
class TreeNode<T>(val name: String, val value: T, val parent: TreeNode<T>? = null) {
val children = mutableListOf<TreeNode<T>>()
fun add(child: TreeNode<T>) = children.add(child)
}
fun TreeNode<Int>.getDirSize(): Int {
return children.fold(0) { acc, treeNode ->
... | 0 | Kotlin | 0 | 0 | 2734d9ea429b0099b32c8a4ce3343599b522b321 | 2,005 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/aoc/year2023/Day10.kt | SackCastellon | 573,157,155 | false | {"Kotlin": 62581} | package aoc.year2023
import aoc.Puzzle
/**
* [Day 10 - Advent of Code 2023](https://adventofcode.com/2023/day/10)
*/
object Day10 : Puzzle<Int, Int> {
override fun solvePartOne(input: String): Int {
val (connectionMap, start) = getConnectionMap(input)
return connectionMap.getValue(start)
... | 0 | Kotlin | 0 | 0 | 75b0430f14d62bb99c7251a642db61f3c6874a9e | 4,911 | advent-of-code | Apache License 2.0 |
src/day04/Day04.kt | skempy | 572,602,725 | false | {"Kotlin": 13581} | package day04
import readInputAsPairs
fun main() {
fun part1(input: List<Pair<String, String>>): Int {
val ranges = input.map {
Pair(
it.first.substringBefore('-').toInt()..it.first.substringAfter('-').toInt(),
it.second.substringBefore('-').toInt()..it.second.... | 0 | Kotlin | 0 | 0 | 9b6997b976ea007735898083fdae7d48e0453d7f | 1,551 | AdventOfCode2022 | Apache License 2.0 |
cz.wrent.advent/Day11.kt | Wrent | 572,992,605 | false | {"Kotlin": 206165} | package cz.wrent.advent
fun main() {
val result = partOne(input, 20, 3)
println("10a: $result")
println(result == 51075L)
println("10b: ${partOne(input, 10000, 1)}")
}
private fun partOne(input: String, rounds: Int, divisor: Long): Long {
val monkeys = input.split("\n\n").map { it.parseMonkey() }
val allMod = m... | 0 | Kotlin | 0 | 0 | 8230fce9a907343f11a2c042ebe0bf204775be3f | 3,369 | advent-of-code-2022 | MIT License |
src/main/kotlin/ru/timakden/aoc/year2022/Day13.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2022
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 13: Distress Signal](https://adventofcode.com/2022/day/13).
*/
object Day13 {
@JvmStatic
fun main(args: Array<String>) {
measure {
val input = readInput("year2022/Day13")... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 3,163 | advent-of-code | MIT License |
src/main/kotlin/solutions/CHK/CheckoutSolution.kt | DPNT-Sourcecode | 748,885,607 | false | {"Kotlin": 21624, "Shell": 2184} | package solutions.CHK
object CheckoutSolution {
fun checkout(skus: String): Int {
val skuList = skus.map { it.toString() }
if (containsInvalidSkus(skuList)) {
return -1
}
val checkoutItemsMap = getCheckoutItemsMap(skuList)
val items = setupItems()
return... | 0 | Kotlin | 0 | 0 | 326235b3112d321afbce5aaeb84a60a51cc09b0e | 7,413 | CHK-cvvr01 | Apache License 2.0 |
src/main/kotlin/Day8.kt | cbrentharris | 712,962,396 | false | {"Kotlin": 171464} | import kotlin.String
import kotlin.collections.List
object Day8 {
data class Node(var left: Node?, var right: Node?, val key: String)
data class DesertMap(val directions: CharArray, val root: Node?) {
companion object {
fun parse(input: List<String>): DesertMap {
val directi... | 0 | Kotlin | 0 | 1 | f689f8bbbf1a63fecf66e5e03b382becac5d0025 | 3,243 | kotlin-kringle | Apache License 2.0 |
2017/src/main/kotlin/Day24.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | import utils.splitNewlines
object Day24 {
fun part1(input: String): Int {
return strongestBridge(0, parseComponents(input))
}
fun part2(input: String): Int {
return longestAndStrongestBridge(0, parseComponents(input)).strength
}
private fun strongestBridge(port: Int, components: List<Component>): ... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 1,404 | advent-of-code | MIT License |
src/Day02.kt | ShuffleZZZ | 572,630,279 | false | {"Kotlin": 29686} | private const val RPS_SIZE = 3
private fun String.toInt() = when (this) {
"A", "X" -> 1
"B", "Y" -> 2
"C", "Z" -> 3
else -> error("Incorrect input")
}
private fun Pair<Int, Int>.game1() = second + when {
first % RPS_SIZE + 1 == second -> 6
first == second -> 3
(first + 1) % RPS_SIZE + 1 ==... | 0 | Kotlin | 0 | 0 | 5a3cff1b7cfb1497a65bdfb41a2fe384ae4cf82e | 1,156 | advent-of-code-kotlin | Apache License 2.0 |
src/day14.kt | skuhtic | 572,645,300 | false | {"Kotlin": 36109} | import kotlin.math.max
import kotlin.math.min
fun main() {
day14.execute(onlyTests = false, forceBothParts = true)
}
val day14 = object : Day<Int>(14, 24, 93) { // 93
override val testInput: InputData
get() = """
498,4 -> 498,6 -> 496,6
503,4 -> 502,4 -> 502,9 -> 494,9
... | 0 | Kotlin | 0 | 0 | 8de2933df90259cf53c9cb190624d1fb18566868 | 3,217 | aoc-2022 | Apache License 2.0 |
year2022/src/main/kotlin/net/olegg/aoc/year2022/day8/Day8.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2022.day8
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.Directions.Companion.NEXT_4
import net.olegg.aoc.utils.Vector2D
import net.olegg.aoc.utils.fit
import net.olegg.aoc.utils.get
import net.olegg.aoc.year2022.DayOf2022
/**
* See [Year 2022, Day 8](https://adventofcode.c... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 2,410 | adventofcode | MIT License |
kotlin/src/commonMain/kotlin/y2016/Day1.kt | emmabritton | 358,239,150 | false | {"Rust": 18706, "Kotlin": 13302, "JavaScript": 8960} | package y2016
import kotlin.math.abs
fun runY2016D1(input: String): Pair<String, String> {
val steps = input.split(",")
.map { parse(it.trim()) }
val (distance, firstRepeat) = travel(steps)
return Pair(distance.toString(), firstRepeat.toString())
}
fun parse(input: String): Move {
if (input... | 0 | Rust | 0 | 0 | c041d145c9ac23ce8d7d7f48e419143c73daebda | 2,721 | advent-of-code | MIT License |
src/Day07.kt | HenryCadogan | 574,509,648 | false | {"Kotlin": 12228} | fun main() {
// val input = readInput("Day07")
val input = readInput("Day07")
fun part1(input: List<String>): Int {
val directoryWalker = DirectoryWalker(input)
val rootDirectory = directoryWalker.walkDirectory()
val allDirectories= rootDirectory.getAllSubDirectories()
retur... | 0 | Kotlin | 0 | 0 | 0a0999007cf16c11355fcf32fc8bc1c66828bbd8 | 3,404 | AOC2022 | Apache License 2.0 |
src/main/kotlin/days/y2023/day11_a/Day11.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2023.day11_a
import util.InputReader
import util.timeIt
import kotlin.math.abs
typealias PuzzleLine = String
typealias PuzzleInput = List<PuzzleLine>
class Day11(val input: PuzzleInput) {
private val galaxyPositions = input.galaxyPositions()
private val galaxyYs = galaxyPositions.map { it.y }.... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 3,295 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/days/Day09.kt | julia-kim | 569,976,303 | false | null | package days
import Point
import readInput
import kotlin.math.absoluteValue
fun main() {
fun printTail(visited: List<Point>) {
var rows = visited.maxOf { it.y }
while (rows >= visited.minOf { it.y }) {
var cols = visited.minOf { it.x }
while (cols <= visited.maxOf { it.x })... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 3,663 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day12.kt | hughjdavey | 725,972,063 | false | {"Kotlin": 76988} | package days
import xyz.hughjd.aocutils.Collections.stackOf
import xyz.hughjd.aocutils.Strings.indicesOf
class Day12 : Day(12) {
override fun partOne(): Any {
return inputList.map { ConditionRecord(it) }.sumOf { it.possibleArrangements().size }
}
override fun partTwo(): Any {
return 0
... | 0 | Kotlin | 0 | 0 | 330f13d57ef8108f5c605f54b23d04621ed2b3de | 2,895 | aoc-2023 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/days/Day5Data.kt | yigitozgumus | 572,855,908 | false | {"Kotlin": 26037} | package days
import utils.SolutionData
import java.util.*
fun main() {
Day5Data().solvePart1()
Day5Data().solvePart2()
}
data class Operation(val times: Int, val from: Int, val to: Int)
class Day5Data : SolutionData(inputFile = "inputs/day5.txt") {
private val separation = rawData.indexOf("")
private val data =... | 0 | Kotlin | 0 | 0 | 9a3654b6d1d455aed49d018d9aa02d37c57c8946 | 1,531 | AdventOfCode2022 | MIT License |
2021/src/day07/Day07.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day07
import readInput
import kotlin.math.abs
fun part1(lines: List<String>) : Int {
val crabsPos = lines.first().split(",").map{ it.toInt() }
val min = crabsPos.minOrNull() ?: return -1
val max = crabsPos.maxOrNull() ?: return -1
var minFuel = Integer.MAX_VALUE
for (i in min..max) {
... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 1,563 | advent-of-code | Apache License 2.0 |
2021/src/day17/Day17.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day17
import readInput
data class Point(val x: Int, val y: Int)
data class Area(val start: Int, val end: Int) {
fun contains(pos: Int) = this.start <= pos && this.end >= pos
}
fun List<String>.toAreas() : List<Area> {
val area = first().substringAfter("target area: ").split(" ")
val areaX = area.... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 3,146 | advent-of-code | Apache License 2.0 |
src/main/kotlin/net/navatwo/adventofcode2023/day5/Day5Solution.kt | Nava2 | 726,034,626 | false | {"Kotlin": 100705, "Python": 2640, "Shell": 28} | package net.navatwo.adventofcode2023.day5
import com.github.nava2.interval_tree.Interval
import com.github.nava2.interval_tree.IntervalTree
import net.navatwo.adventofcode2023.framework.ComputedResult
import net.navatwo.adventofcode2023.framework.Solution
import java.util.Objects
sealed class Day5Solution : Solution<... | 0 | Kotlin | 0 | 0 | 4b45e663120ad7beabdd1a0f304023cc0b236255 | 7,206 | advent-of-code-2023 | MIT License |
src/main/kotlin/day7/main.kt | janneri | 572,969,955 | false | {"Kotlin": 99028} | package day7
import util.readTestInput
open class Command
class ListCurrentDir: Command()
class ChangeDir(val arg: String): Command()
class ChangeDirOut: Command()
open class Result
data class MyFile(val size: Int, val name: String): Result()
data class MyDir(val name: String): Result()
fun parseCommand(str: String... | 0 | Kotlin | 0 | 0 | 1de6781b4d48852f4a6c44943cc25f9c864a4906 | 3,006 | advent-of-code-2022 | MIT License |
src/main/kotlin/day03/Problem.kt | xfornesa | 572,983,494 | false | {"Kotlin": 18402} | package day03
fun solveProblem01(input: List<String>): Int {
val commonTypes = mutableListOf<Char>()
input.forEach {
val first = it.substring(0 until it.length/2)
val second = it.substring((it.length / 2) until it.length)
val commonType = commonType(first, second)
commonTypes.ad... | 0 | Kotlin | 0 | 0 | dc142923f8f5bc739564bc93b432616608a8b7cd | 1,578 | aoc2022 | MIT License |
src/Day03.kt | gillyobeast | 574,413,213 | false | {"Kotlin": 27372} | import utils.appliedTo
import utils.readInput
private fun <E> List<E>.toTriple(): Triple<E, E, E> {
assert(this.size == 3)
return Triple(this[0], this[1], this[2])
}
fun main() {
val lowerPriorities =
("abcdefghijklmnopqrstuvwxyz".toCharArray()).zip((1..26).toList()).toMap()
val upperPrioriti... | 0 | Kotlin | 0 | 0 | 8cdbb20c1a544039b0e91101ec3ebd529c2b9062 | 2,277 | aoc-2022-kotlin | Apache License 2.0 |
kotlin/src/main/kotlin/com/github/jntakpe/aoc2022/days/Day22.kt | jntakpe | 572,853,785 | false | {"Kotlin": 72329, "Rust": 15876} | package com.github.jntakpe.aoc2022.days
import com.github.jntakpe.aoc2022.shared.Day
import com.github.jntakpe.aoc2022.shared.readInputLines
object Day22 : Day {
override val input = readInputLines(22).let { it.dropLast(2) to instructions(it.last()) }
operator fun List<String>.get(pos: Position): Char = ge... | 1 | Kotlin | 0 | 0 | 63f48d4790f17104311b3873f321368934060e06 | 4,735 | aoc2022 | MIT License |
src/Day03.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { s: String ->
val leftSet = s.substring(0, s.length / 2).toSet()
val rightSet = s.substring(s.length / 2).toSet()
val intersect = leftSet.intersect(rightSet)
check(intersect.size == 1)
... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 1,147 | aoc22-kotlin | Apache License 2.0 |
src/Day02.kt | Ramo-11 | 573,610,722 | false | {"Kotlin": 21264} | fun main() {
// Part 1
// A and X are rock
// B and Y are paper
// C and Z are scissors
// Part 2
// Y also means draw
// X also means lose
// Z also means win
val opponentChoices: MutableList<String> = ArrayList()
val myChoices: MutableList<String> = ArrayList()
fun cons... | 0 | Kotlin | 0 | 0 | a122cca3423c9849ceea5a4b69b4d96fdeeadd01 | 2,659 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem2244/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2244
/**
* LeetCode page: [2244. Minimum Rounds to Complete All Tasks](https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks/);
*/
class Solution {
/* Complexity:
* Time O(|tasks|) and Space O(|tasks|);
*/
fun minimumRounds(tasks: IntArray): Int {
... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,343 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/day05/day05.kt | andrew-suprun | 725,670,189 | false | {"Kotlin": 18354, "Python": 17857, "Dart": 8224} | package day05
import java.io.File
import kotlin.math.max
import kotlin.math.min
fun main() {
run(::part1)
run(::part2)
}
data class Map(val range: LongRange, val inc: Long)
data class Model(val seeds: List<LongRange>, val allMaps: List<List<Map>>)
fun run(part: (String) -> List<LongRange>) {
val model =... | 0 | Kotlin | 0 | 0 | dd5f53e74e59ab0cab71ce7c53975695518cdbde | 2,585 | AoC-2023 | The Unlicense |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.