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/Day02.kt | frango9000 | 573,098,370 | false | {"Kotlin": 73317} | fun main() {
val input = readInput("Day02")
println(Day02.part1(input))
println(Day02.part2(input))
}
class Day02 {
companion object {
private fun checkGuessRound(it: String): Int {
val (a, b) = it.split(" ").map { it.toCharArray().first() }
val selectionPoints = b.code ... | 0 | Kotlin | 0 | 0 | 62e91dd429554853564484d93575b607a2d137a3 | 1,928 | advent-of-code-22 | Apache License 2.0 |
src/Day16b.kt | jrmacgill | 573,065,109 | false | {"Kotlin": 76362} | import java.lang.Integer.min
class Day16b {
val inputLineRegex = """Valve ([A-Z]*) has flow rate=(\d+); tunnel[s]? lead[s]? to valve[s]? (.*)""".toRegex()
val data = mutableMapOf<String, Room>()
val compactData = mutableMapOf<String, CompactRoom>()
val maxTicks = 30
var best = 0
class Room(v... | 0 | Kotlin | 0 | 1 | 3dcd590f971b6e9c064b444139d6442df034355b | 3,358 | aoc-2022-kotlin | Apache License 2.0 |
src/main/java/Main.kt | Koallider | 557,760,682 | false | {"Kotlin": 8930} | import kotlin.math.min
fun main() {
val trie = buildTrieForResource("words.txt")
println("Enter letters to solve")
val letters = "SAGNETISD".lowercase().toCharArray()
//val letters = readLine()!!.toCharArray()
println(searchForAllPermutations(trie, letters).subList(0, 10))
}
fun searchForAllPermu... | 0 | Kotlin | 0 | 0 | 9faa2e3e14d1daba1d6a9e4530f03b22ddeace77 | 1,889 | 8OO10CDC | Apache License 2.0 |
y2020/src/main/kotlin/adventofcode/y2020/Day24.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2020
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Vec2
fun main() = Day24.solve()
object Day24 : AdventSolution(2020, 24, "Lobby Layout")
{
override fun solvePartOne(input: String) = blackTiles(input).size
override fun solvePartTwo(input: String) = generateSequ... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 2,054 | advent-of-code | MIT License |
src/main/kotlin/day23.kt | Gitvert | 725,292,325 | false | {"Kotlin": 97000} | import java.util.*
val DIRECTIONS = mutableListOf(Pos(1, 0), Pos(-1, 0), Pos(0, 1), Pos(0, -1))
var longestHike = -1
fun day23 (lines: List<String>) {
val hikes = mutableListOf(Hike(mutableSetOf(Pos(1, 0))))
val maxX = lines[0].indices.last
val maxY = lines.indices.last
while (hikes.isNotEmpty()) {
... | 0 | Kotlin | 0 | 0 | f204f09c94528f5cd83ce0149a254c4b0ca3bc91 | 6,203 | advent_of_code_2023 | MIT License |
kotlin/src/com/leetcode/221_MaximalSquare.kt | programmerr47 | 248,502,040 | false | null | package com.leetcode
import kotlin.math.max
/**
* We use the additional matrix of sides b.
* The b[i][j] representes the max side that is possible for the square,
* which right-down corner is placed in (i,j) coordinate.
*
* For instance, with given:
* 1 1 1 0 0
* 1 1 1 1 0
* 1 1 1 1 1
* 0 1 1 1 0
*
* we wi... | 0 | Kotlin | 0 | 0 | 0b5fbb3143ece02bb60d7c61fea56021fcc0f069 | 1,570 | problemsolving | Apache License 2.0 |
src/main/kotlin/g2901_3000/s2977_minimum_cost_to_convert_string_ii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2901_3000.s2977_minimum_cost_to_convert_string_ii
// #Hard #Array #String #Dynamic_Programming #Graph #Trie #Shortest_Path
// #2024_01_19_Time_697_ms_(100.00%)_Space_51.2_MB_(64.29%)
import kotlin.math.min
class Solution {
fun minimumCost(
source: String,
target: String,
original... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,434 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/day17.kt | tobiasae | 434,034,540 | false | {"Kotlin": 72901} | class Day17 : Solvable("17") {
override fun solveA(input: List<String>): String {
return maxHeight(getYRange(input.first()).first).toString()
}
override fun solveB(input: List<String>): String {
val yStepMap =
HashMap<Int, Set<YStep>>().also {
for (y in ... | 0 | Kotlin | 0 | 0 | 16233aa7c4820db072f35e7b08213d0bd3a5be69 | 3,722 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/day09/Day09.kt | tschens95 | 573,743,557 | false | {"Kotlin": 32775} | package day09
import readInput
import kotlin.math.abs
fun main() {
fun adjacent(h: Pair<Int, Int>, t: Pair<Int, Int>): Boolean {
val xDiff = abs(h.first - t.first)
val yDiff = abs(h.second - t.second)
return (xDiff == 0 && yDiff == 0) || (xDiff == 0 && yDiff == 1) || (xDiff == 1 && yDiff... | 0 | Kotlin | 0 | 2 | 9d78a9bcd69abc9f025a6a0bde923f53c2d8b301 | 2,569 | AdventOfCode2022 | Apache License 2.0 |
advent-of-code-2023/src/main/kotlin/eu/janvdb/aoc2023/day14/day14.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2023.day14
import eu.janvdb.aocutil.kotlin.readLines
//const val FILENAME = "input14-test.txt"
const val FILENAME = "input14.txt"
const val NUMBER_OF_ITERATIONS = 1000000000
fun main() {
val platform = readLines(2023, FILENAME).let { Platform.parse(it) }
part1(platform)
part2(platform)
}
pr... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,543 | advent-of-code | Apache License 2.0 |
src/Day11.kt | ricardorlg-yml | 573,098,872 | false | {"Kotlin": 38331} | data class Monkey(
val id: Int,
private val itemOperation: (Long) -> Long,
private val reliefOperation: (Long) -> Long,
val divisibleBy: Int,
private val nextMonkeyIdOnTrue: Int,
private val nextMonkeyIdOnFalse: Int,
private val items: MutableList<Long>,
) {
private fun addItem(item: Lo... | 0 | Kotlin | 0 | 0 | d7cd903485f41fe8c7023c015e4e606af9e10315 | 5,002 | advent_code_2022 | Apache License 2.0 |
src/Day02.kt | anoniim | 572,264,555 | false | {"Kotlin": 8381} | fun main() {
Day2().run(
15,
12
)
}
private class Day2 : Day(2) {
override fun part1(input: List<String>): Int {
// What would your total score be if everything goes exactly according to your strategy guide?
return input.sumOf { GameRound(it).getScore() }
}
overrid... | 0 | Kotlin | 0 | 0 | 15284441cf14948a5ebdf98179481b34b33e5817 | 2,261 | Advent-of-Code-2022 | Apache License 2.0 |
src/Day19.kt | simonbirt | 574,137,905 | false | {"Kotlin": 45762} | fun main() {
Day19.printSolutionIfTest(33, 56*62)
}
object Day19 : Day<Int, Int>(19) {
override fun part1(lines: List<String>) = solve(lines, 24)
override fun part2Test(lines: List<String>) = solve2(lines, 32)
override fun part2(lines: List<String>) = solve2(lines.take(3), 32)
data class Blueprin... | 0 | Kotlin | 0 | 0 | 962eccac0ab5fc11c86396fc5427e9a30c7cd5fd | 3,597 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day11.kt | goblindegook | 319,372,062 | false | null | package com.goblindegook.adventofcode2020
import com.goblindegook.adventofcode2020.input.load
fun main() {
val seats = load("/day11-input.txt")
println(countSeated(seats))
println(countSeatedRedux(seats))
}
fun countSeated(seats: String): Int = countSeated(seats.toRoom(), emptyMap(), 4, ::neighbours)
fu... | 0 | Kotlin | 0 | 0 | 85a2ff73899dbb0e563029754e336cbac33cb69b | 2,450 | adventofcode2020 | MIT License |
2021/src/day03/day3.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day03
import java.io.File
import kotlin.collections.mutableMapOf
fun main() {
// testDay3Sample()
readInput("day3.txt")
}
fun testDay3Sample() {
val input =
listOf(
"00100",
"11110",
"10110",
"10111",
... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 3,208 | adventofcode | Apache License 2.0 |
src/Day09.kt | RobvanderMost-TomTom | 572,005,233 | false | {"Kotlin": 47682} | import kotlin.math.abs
private data class Day09Instruction(
val direction: Char,
val amount: Int
) {
companion object {
fun fromString(input: String) =
Day09Instruction(input[0], input.substring(2).toInt())
}
}
fun main() {
fun Coordinate.moveUp() = Coordinate(x, y+1)
fun Co... | 5 | Kotlin | 0 | 0 | b7143bceddae5744d24590e2fe330f4e4ba6d81c | 3,431 | advent-of-code-2022 | Apache License 2.0 |
src/day03/Day03.kt | maxmil | 578,287,889 | false | {"Kotlin": 32792} | package day03
import println
import readInput
fun main() {
fun bitCounts(input: List<String>) = input
.asSequence()
.map { line -> line.map { it.toString().toInt() } }
.reduce { acc, it -> acc.zip(it) { a, b -> a + b } }
fun getRatingByCounting(input: List<String>, mostCommon: Boolea... | 0 | Kotlin | 0 | 0 | 246353788b1259ba11321d2b8079c044af2e211a | 1,428 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/_2020/Day7.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2020
import aocRun
private val REGEX_MAIN = Regex("^(\\w+\\s+\\w+) bags contain (.*).$")
private val REGEX_CONTAINED = Regex("(\\d+) (\\w+\\s+\\w+) bags?")
private const val NO_BAGS = "no other bags"
private const val SHINY_GOLD = "shiny gold"
fun main() {
aocRun(puzzleInput) { input ->
val map = mutable... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 46,713 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/year2022/day09/Solution.kt | LewsTherinTelescope | 573,240,975 | false | {"Kotlin": 33565} | package year2022.day09
import utils.runIt
import kotlin.math.absoluteValue
import kotlin.math.sign
fun main() = runIt(
testInput = """
R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2
""".trimIndent(),
part1 = ::part1,
testAnswerPart1 = 13,
testInputPart2 = """
R 5
U 8
L 8
D 3
R 17
D 10
L 25
U 20
... | 0 | Kotlin | 0 | 0 | ee18157a24765cb129f9fe3f2644994f61bb1365 | 1,843 | advent-of-code-kotlin | Do What The F*ck You Want To Public License |
kotlin/2018/src/main/kotlin/2018/Lib02.kt | nathanjent | 48,783,324 | false | {"Rust": 147170, "Go": 52936, "Kotlin": 49570, "Shell": 966} | package aoc.kt.y2018;
/**
* Day 2.
*/
/** Part 1 */
fun processBoxChecksum1(input: String): String {
val (count2s, count3s) = input.lines()
.filter { !it.isEmpty() }
.map {
val charCounts = mutableMapOf<Char, Int>()
it.forEach { c ->
val count = charCounts... | 0 | Rust | 0 | 0 | 7e1d66d2176beeecaac5c3dde94dccdb6cfeddcf | 1,912 | adventofcode | MIT License |
src/Day12/Day12.kt | martin3398 | 436,014,815 | false | {"Kotlin": 63436, "Python": 5921} | import java.util.*
fun main() {
fun preprocess(input: List<String>): Map<String, List<String>> {
val res = mutableMapOf<String, MutableList<String>>()
for (e in input) {
val split = e.split('-')
val l1 = res.getOrDefault(split[0], mutableListOf())
l1.add(split[1]... | 0 | Kotlin | 0 | 0 | 085b1f2995e13233ade9cbde9cd506cafe64e1b5 | 2,036 | advent-of-code-2021 | Apache License 2.0 |
src/problems/day3/part1/part1.kt | klnusbaum | 733,782,662 | false | {"Kotlin": 43060} | package problems.day3.part1
import java.io.File
//private const val testFile = "input/day3/test.txt"
private const val part_numbers = "input/day3/part_numbers.txt"
fun main() {
val partNumberSum = File(part_numbers).bufferedReader().useLines { sumPartNumbers(it) }
println("Part Number Sum: $partNumberSum")
}... | 0 | Kotlin | 0 | 0 | d30db2441acfc5b12b52b4d56f6dee9247a6f3ed | 4,034 | aoc2023 | MIT License |
src/Day08.kt | zhiqiyu | 573,221,845 | false | {"Kotlin": 20644} | import kotlin.math.max
class Grid(input: List<String>) {
var m: Int
var n: Int
private val grid: List<List<Int>>
var visible: MutableList<MutableList<Boolean>>
init {
m = input.size
n = input.get(0).length
grid = input.map { it.toList().map(Char::digitToInt) }
visib... | 0 | Kotlin | 0 | 0 | d3aa03b2ba2a8def927b94c2b7731663041ffd1d | 3,386 | aoc-2022 | Apache License 2.0 |
src/Day20.kt | Tomcat88 | 572,566,485 | false | {"Kotlin": 52372} | import kotlin.math.absoluteValue
object Day20 {
fun mix(input: List<IndexedValue<Long>>): MutableList<IndexedValue<Long>> {
val sorted = input.toMutableList()
input.sortedBy { it.index }.forEach { (index, value) ->
if (value == 0L) return@forEach
val curr = sorted.find { it... | 0 | Kotlin | 0 | 0 | 6d95882887128c322d46cbf975b283e4a985f74f | 1,938 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/2022/Day08_2022.kt | regob | 575,917,627 | false | {"Kotlin": 50757, "Python": 46520, "Shell": 430} | import kotlin.math.max
private typealias Mat = List<List<Int>>
fun Mat.transpose(): Mat {
val res = List<MutableList<Int>>(size) { mutableListOf() }
for (j in indices)
for (i in indices)
res[j].add(this[i][j])
return res
}
fun Mat.hflip(): Mat = map {it.asReversed()}
///////////////... | 0 | Kotlin | 0 | 0 | cf49abe24c1242e23e96719cc71ed471e77b3154 | 2,569 | adventofcode | Apache License 2.0 |
src/main/kotlin/dec19/Main.kt | dladukedev | 318,188,745 | false | null | package dec19
sealed class Rule {
data class Terminator(val character: String): Rule()
data class Step(val paths: List<List<Int>>): Rule()
}
fun parseRule(input: String): Pair<Int, Rule> {
val (ruleId, rule) = input.split(": ")
return if(rule.contains("\"")) {
ruleId.toInt() to Rule.Terminato... | 0 | Kotlin | 0 | 0 | d4591312ddd1586dec6acecd285ac311db176f45 | 3,641 | advent-of-code-2020 | MIT License |
src/Day17.kt | akijowski | 574,262,746 | false | {"Kotlin": 56887, "Shell": 101} | data class RockPos(val x: Int, val y: Int) {
fun move(jet: Int) = this.copy(x = x + jet)
fun fallDown(): RockPos = this.copy(y = y - 1)
}
fun lineRock(xStart: Int, y: Int) = (xStart..xStart + 3).map { x -> RockPos(x, y) }
fun plusRock(xStart: Int, y: Int) = listOf(
RockPos(xStart, y + 1),
RockPos(xSta... | 0 | Kotlin | 1 | 0 | 84d86a4bbaee40de72243c25b57e8eaf1d88e6d1 | 5,510 | advent-of-code-2022 | Apache License 2.0 |
src/Day12.kt | arksap2002 | 576,679,233 | false | {"Kotlin": 31030} | import java.util.*
import kotlin.math.min
fun isCorrect(from: Char, to: Char): Boolean = to - from <= 1
fun main() {
fun part1(input: List<String>): Int {
val board = mutableListOf<MutableList<Int>>()
val used = mutableListOf<MutableList<Boolean>>()
var current = Pair(0, 0)
var fin... | 0 | Kotlin | 0 | 0 | a24a20be5bda37003ef52c84deb8246cdcdb3d07 | 3,389 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/io/github/pshegger/aoc/y2020/Y2020D11.kt | PsHegger | 325,498,299 | false | null | package io.github.pshegger.aoc.y2020
import io.github.pshegger.aoc.common.BaseSolver
import io.github.pshegger.aoc.common.Coordinate
class Y2020D11 : BaseSolver() {
override val year = 2020
override val day = 11
override fun part1(): Int = calculateOccupiedSeats(true, 4)
override fun part2(): Int = c... | 0 | Kotlin | 0 | 0 | 346a8994246775023686c10f3bde90642d681474 | 3,150 | advent-of-code | MIT License |
app/src/main/kotlin/com/bloidonia/advent2020/Day_18.kt | timyates | 317,965,519 | false | null | package com.bloidonia.advent2020
import com.bloidonia.linesFromResource
class Day_18 {
enum class Op {
MUL, DIV, ADD, SUB, OPEN, CLOSE, NUMBER
}
data class Token(val op: Op, val arg: Long? = null)
fun tokenize(input: String) =
"(\\(|\\d+|\\+|-|\\*|/|\\))".toRegex().findAll(input).le... | 0 | Kotlin | 0 | 0 | cab3c65ac33ac61aab63a1081c31a16ac54e4fcd | 2,598 | advent-of-code-2020-kotlin | Apache License 2.0 |
src/day01/Day01.kt | martinhrvn | 724,678,473 | false | {"Kotlin": 27307, "Jupyter Notebook": 1336} | package day01
import println
import readInput
class CalibrationReader(val input: List<String>) {
val digitMapping =
mapOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"five" to 5,
"six" to 6,
"seven" to 7,
"eight" to 8,
... | 0 | Kotlin | 0 | 0 | 59119fba430700e7e2f8379a7f8ecd3d6a975ab8 | 1,904 | advent-of-code-2023-kotlin | Apache License 2.0 |
src/Day01.kt | frungl | 573,598,286 | false | {"Kotlin": 86423} | fun main() {
fun part1(input: List<String>): Int {
return input.fold(mutableListOf(0)) { temp, el ->
if (el.isBlank()) {
temp.add(0)
} else {
temp[temp.size - 1] += el.toInt()
}
temp
}.max()
}
fun part2(input: L... | 0 | Kotlin | 0 | 0 | d4cecfd5ee13de95f143407735e00c02baac7d5c | 1,286 | aoc2022 | Apache License 2.0 |
src/Day02.kt | zhiqiyu | 573,221,845 | false | {"Kotlin": 20644} | import kotlin.math.max
import kotlin.math.abs
class Game(
var abc: Array<String> = arrayOf("A", "B", "C"), // rock, paper, scissor
var xyz: Array<String> = arrayOf("X", "Y", "Z") // lose, draw, win
) {
var pointMap: MutableMap<String, Int>
init {
pointMap = mutableMapOf<String, Int>(... | 0 | Kotlin | 0 | 0 | d3aa03b2ba2a8def927b94c2b7731663041ffd1d | 2,144 | aoc-2022 | Apache License 2.0 |
2019/src/main/kotlin/com/github/jrhenderson1988/adventofcode2019/day12/Jupiter.kt | jrhenderson1988 | 289,786,400 | false | {"Kotlin": 216891, "Java": 166355, "Go": 158613, "Rust": 124111, "Scala": 113820, "Elixir": 112109, "Python": 91752, "Shell": 37} | package com.github.jrhenderson1988.adventofcode2019.day12
import com.github.jrhenderson1988.adventofcode2019.lcm
import kotlin.math.abs
class Jupiter(val moons: List<Moon>) {
fun calculateTotalEnergyAfterSteps(steps: Int) =
(0 until steps).fold(moons) { ms, _ -> applyVelocity(applyGravity(ms)) }.sumBy {... | 0 | Kotlin | 0 | 0 | 7b56f99deccc3790c6c15a6fe98a57892bff9e51 | 2,545 | advent-of-code | Apache License 2.0 |
src/main/kotlin/Day14.kt | SimonMarquis | 434,880,335 | false | {"Kotlin": 38178} | class Day14(raw: String) {
private val input: Pair<String, Set<Rule>> = raw.split("\n\n").let { (polymer, rules) ->
polymer to rules.lines().map { rule ->
rule.split(" -> ").let { (i, o) -> Rule(i, o) }
}.toSet()
}
fun part1(): Long = input.process(10)
fun part2(): Long = ... | 0 | Kotlin | 0 | 0 | 8fd1d7aa27f92ba352e057721af8bbb58b8a40ea | 1,645 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2023/2023-11.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2023
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
import kotlin.time.measureTime
fun main() {
val input = readInputLines(2023, "11-input")
val test1 = readInput... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,493 | advent-of-code | MIT License |
src/test/kotlin/chapter6/solutions/ex10/listing.kt | DavidGomesh | 680,857,367 | false | {"Kotlin": 204685} | package chapter6.solutions.ex10
import chapter3.Cons
import chapter3.List
import chapter3.foldRight
import chapter6.RNG
import chapter6.rng1
import io.kotest.matchers.shouldBe
import io.kotest.core.spec.style.WordSpec
//tag::init[]
data class State<S, out A>(val run: (S) -> Pair<A, S>) {
companion object {
... | 0 | Kotlin | 0 | 0 | 41fd131cd5049cbafce8efff044bc00d8acddebd | 2,680 | fp-kotlin | MIT License |
2021/kotlin/src/main/kotlin/nl/sanderp/aoc/aoc2021/day24/Day24.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.aoc2021.day24
import nl.sanderp.aoc.common.measureDuration
import nl.sanderp.aoc.common.prettyPrint
import nl.sanderp.aoc.common.readResource
fun main() {
val input = readResource("Day24.txt").lines().map { parse(it) }
val (answer1, duration1) = measureDuration<Long> { partOne(input) }... | 0 | C# | 0 | 6 | 8e96dff21c23f08dcf665c68e9f3e60db821c1e5 | 3,424 | advent-of-code | MIT License |
src/Day04.kt | kpilyugin | 572,573,503 | false | {"Kotlin": 60569} | fun main() {
fun List<Int>.includes(other: List<Int>) = this[0] <= other[0] && this[1] >= other[1]
fun intersects(a: List<Int>, b: List<Int>) = a[1] >= b[0] && b[1] >= a[0]
fun countPairs(input: List<String>, predicate: (List<Int>, List<Int>) -> Boolean): Int {
return input.count { line ->
... | 0 | Kotlin | 0 | 1 | 7f0cfc410c76b834a15275a7f6a164d887b2c316 | 853 | Advent-of-Code-2022 | Apache License 2.0 |
day3/src/main/kotlin/Main.kt | joshuabrandes | 726,066,005 | false | {"Kotlin": 47373} | import java.io.File
fun main(args: Array<String>) {
println("------ Advent of Code 2023 - Day 3 -----")
val engineSchematic = if (args.isEmpty()) getPuzzleInput() else args.toList()
val validNumbers = getValidNumbers(engineSchematic)
println("Task 1: Sum of all valid numbers: ${validNumbers.sumOf { ... | 0 | Kotlin | 0 | 1 | de51fd9222f5438efe9a2c45e5edcb88fd9f2232 | 6,905 | aoc-2023-kotlin | The Unlicense |
src/main/kotlin/dev/bogwalk/batch0/Problem8.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch0
/**
* Problem 8: Largest Product in a Series
*
* https://projecteuler.net/problem=8
*
* Goal: Find the largest product of K adjacent digits in an N-digit number.
*
* Constraints: 1 <= K <= 13, K <= N <= 1000
*
* e.g.: N = 10 with input = "3675356291", K = 5
* products LTR = {... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,208 | project-euler-kotlin | MIT License |
advent-of-code-2023/src/main/kotlin/eu/janvdb/aoc2023/day07/part1/day07_1.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2023.day07.part1
import eu.janvdb.aoc2023.day07.TypeOfHand
import eu.janvdb.aocutil.kotlin.readLines
//const val FILENAME = "input07-test.txt"
const val FILENAME = "input07.txt"
fun main() {
val pairs = readLines(2023, FILENAME).map { CardBidPair.parse(it) }
val score = pairs
.sortedBy { it... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,090 | advent-of-code | Apache License 2.0 |
src/Day05.kt | RichardLiba | 572,867,612 | false | {"Kotlin": 16347} | fun main() {
data class Move(val count: Int, val from: Int, val to: Int)
fun readWorld(input: List<String>): Pair<MutableMap<Int, List<Char>>, MutableList<Move>> {
val world: MutableMap<Int, List<Char>> = mutableMapOf()
var worldWidth: Int = -1
val moves: MutableList<Move> = mutableList... | 0 | Kotlin | 0 | 0 | 6a0b6b91b5fb25b8ae9309b8e819320ac70616ed | 2,858 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day13.kt | fasfsfgs | 573,562,215 | false | {"Kotlin": 52546} | fun main() {
fun part1(input: String): Int {
return input
.split("\n\n")
.flatMap { it.lines() }
.map { it.toPacket() }
.chunked(2)
.map { Pair(it.first().list!!, it[1].list!!) }
.map { it.isRightOrder() }
.mapIndexedNotNull... | 0 | Kotlin | 0 | 0 | 17cfd7ff4c1c48295021213e5a53cf09607b7144 | 4,089 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinAbsoluteSumDiff.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,757 | kotlab | Apache License 2.0 |
src/Day09.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | import kotlin.math.abs
import kotlin.math.sign
fun main() {
val testInput = readInput("Day09_test")
check(part1(testInput) == 13)
check(part2(testInput) == 1)
val testInput2 = readInput("Day09_test2")
check(part2(testInput2) == 36)
val input = readInput("Day09")
println(part1(input))
... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 1,958 | aoc-22 | Apache License 2.0 |
src/Day05.kt | iownthegame | 573,926,504 | false | {"Kotlin": 68002} | import java.util.*
class Cargo(val moves: Array<Array<Int>>) {
private var stacks = mutableMapOf<Int, Stack<String>>()
fun putCrate(at: Int, label: String) {
if (!stacks.containsKey(at)) {
stacks[at] = Stack<String>()
}
stacks[at]!!.push(label)
}
fun moveCrate(amou... | 0 | Kotlin | 0 | 0 | 4e3d0d698669b598c639ca504d43cf8a62e30b5c | 3,127 | advent-of-code-2022 | Apache License 2.0 |
src/day03/Day03.kt | MaxBeauchemin | 573,094,480 | false | {"Kotlin": 60619} | package day03
import readInput
import kotlin.math.ceil
fun main() {
fun charPriority(char: Char): Int {
return when (char.code) {
in 97..122 -> {
char.code - 96 // a - z
}
in 65..90 -> {
char.code - 38 // A - Z
}
e... | 0 | Kotlin | 0 | 0 | 38018d252183bd6b64095a8c9f2920e900863a79 | 1,449 | advent-of-code-2022 | Apache License 2.0 |
src/Day17.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | fun main() {
val input = readInput("Day17")
val (n,m) = input.size to input[0].length
val dirs = listOf(0 to 1, 1 to 0, 0 to -1, -1 to 0) // east south west north
fun solve(minSteps: Int, maxSteps: Int): Int {
val loss = Array(n) {
Array(m) {
IntArray(4) { -1 }
... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 1,598 | advent-of-code-kotlin | Apache License 2.0 |
src/Day02.kt | rounakdatta | 540,743,612 | false | {"Kotlin": 19962} | sealed class SubmarineInstruction {
// TODO: understand what default constructor of sealed classes mean
data class Forward(val numberOfUnits: Int) : SubmarineInstruction()
data class Down(val numberOfUnits: Int) : SubmarineInstruction()
data class Up(val numberOfUnits: Int) : SubmarineInstruction()
... | 0 | Kotlin | 0 | 1 | 130d340aa4c6824b7192d533df68fc7e15e7e910 | 3,412 | aoc-2021 | Apache License 2.0 |
year2018/src/main/kotlin/net/olegg/aoc/year2018/day18/Day18.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2018.day18
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.Directions.Companion.NEXT_8
import net.olegg.aoc.utils.Vector2D
import net.olegg.aoc.utils.get
import net.olegg.aoc.year2018.DayOf2018
/**
* See [Year 2018, Day 18](https://adventofcode.com/2018/day/18)
*/
object Da... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,836 | adventofcode | MIT License |
src/Day05.kt | zdenekobornik | 572,882,216 | false | null |
fun main() {
fun getStacksFromSupplies(suppliesString: String): Array<ArrayDeque<Char>> {
val supplies = suppliesString.lines()
.map { it.chunked(4).map { it.filterNot { it == '[' || it == ']' }.trim() } }.dropLast(1)
val columns = supplies.first().size
val stacks = Array<Array... | 0 | Kotlin | 0 | 0 | f73e4a32802fa43b90c9d687d3c3247bf089e0e5 | 2,033 | advent-of-code-2022 | Apache License 2.0 |
src/year2023/day10/Day.kt | tiagoabrito | 573,609,974 | false | {"Kotlin": 73752} | package year2023.day10
import year2023.solveIt
fun main() {
val day = "10"
val expectedTest1 = 8L
val expectedTest2 = 1L
data class Position(val x:Int, val y:Int)
val moveMap = mapOf(
"|01" to (0 to 1),"|0-1" to (0 to -1),
"-10" to (1 to 0),"--10" to (-1 to 0),
"J10" to... | 0 | Kotlin | 0 | 0 | 1f9becde3cbf5dcb345659a23cf9ff52718bbaf9 | 2,923 | adventOfCode | Apache License 2.0 |
src/main/kotlin/Day05.kt | alex859 | 573,174,372 | false | {"Kotlin": 80552} | fun main() {
val testInput = readInput("Day05_test.txt")
check(testInput.moveCrates() == "CMZ")
check(testInput.moveCratesFancy() == "MCD")
val input = readInput("Day05.txt")
println(input.moveCrates())
println(input.moveCratesFancy())
}
internal fun String.moveCrates(): String {
val stac... | 0 | Kotlin | 0 | 0 | fbbd1543b5c5d57885e620ede296b9103477f61d | 4,126 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/day7/Solution.kt | krazyglitch | 573,086,664 | false | {"Kotlin": 31494} | package day7
import util.Utils
import java.time.Duration
import java.time.LocalDateTime
class Solution {
enum class FileType {
FOLDER, FILE
}
class File(input: String, val parent: File?) {
val fileType: FileType
val fileName: String
val fileSize: Int
val children ... | 0 | Kotlin | 0 | 0 | db6b25f7668532f24d2737bc680feffc71342491 | 4,124 | advent-of-code2022 | MIT License |
src/main/kotlin/year2022/Day19.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2022
class Day19 {
data class Blueprint(
val id: Int,
val oreRobotOreCost: Int,
val clayRobotOreCost: Int,
val obsidianRobotOreCost: Int,
val obsidianRobotClayCost: Int,
val geodeRobotOreCost: Int,
val geodeRobotObsidianCost: Int
) {
... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 4,502 | aoc-2022 | Apache License 2.0 |
src/day12/Day12.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day12
import readInput
import java.util.LinkedList
import java.util.Queue
fun main() {
data class RowCol(
val row: Int,
val col: Int
)
var destP: RowCol? = null
val sourceDestinations = mutableListOf<RowCol>()
fun List<String>.initMatrix(matrix: Array<CharArray>, part1: ... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 3,276 | aoc-2022-kotlin | Apache License 2.0 |
2022/src/main/kotlin/com/github/akowal/aoc/Day05.kt | akowal | 573,170,341 | false | {"Kotlin": 36572} | package com.github.akowal.aoc
class Day05 {
fun solvePart1(): String {
val (stacks, moves) = loadData()
moves.forEach { m ->
val from = stacks[m.from]
val to = stacks[m.to]
repeat(m.qty) {
to.add(from.removeLast())
}
}
... | 0 | Kotlin | 0 | 0 | 02e52625c1c8bd00f8251eb9427828fb5c439fb5 | 2,206 | advent-of-kode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/g2001_2100/s2002_maximum_product_of_the_length_of_two_palindromic_subsequences/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2002_maximum_product_of_the_length_of_two_palindromic_subsequences
// #Medium #String #Dynamic_Programming #Bit_Manipulation #Backtracking #Bitmask
// #2023_06_23_Time_389_ms_(100.00%)_Space_43.3_MB_(100.00%)
class Solution {
fun maxProduct(s: String): Int {
if (s.length == 2) {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,529 | LeetCode-in-Kotlin | MIT License |
src/day21/Day21.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day21
import readInput
import java.util.*
enum class Operator {
PLUS,
MINUS,
DIVIDE,
MUL
}
data class Node(
val name: String,
var value: Long? = null,
var operator: Operator? = null,
var left: Node? = null,
var right: Node? = null
) {
override fun toString(): String {... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 3,848 | aoc-2022-kotlin | Apache License 2.0 |
src/Day09.kt | dmstocking | 575,012,721 | false | {"Kotlin": 40350} | import java.lang.Exception
import kotlin.math.abs
data class Position(val x: Int, val y: Int) {
fun follow(other: Position): Position {
return if (!near(other)) {
moveTowards(other)
} else {
this
}
}
fun near(other: Position): Boolean {
return other... | 0 | Kotlin | 0 | 0 | e49d9247340037e4e70f55b0c201b3a39edd0a0f | 3,572 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/day11/Day11.kt | jakubgwozdz | 571,298,326 | false | {"Kotlin": 85100} | package day11
import execute
import readAllText
import splitBy
import wtf
data class Monkey(
val id: Int,
val items: MutableList<Long>,
val divisor: Long,
val op: (Long) -> Long,
val nextMonkeyOp: (Long) -> Int,
)
private fun parseMonkey(lines: List<String>): Monkey {
val id = lines[0].substr... | 0 | Kotlin | 0 | 0 | 7589942906f9f524018c130b0be8976c824c4c2a | 3,443 | advent-of-code-2022 | MIT License |
src/main/kotlin/y2023/day02/Day02.kt | TimWestmark | 571,510,211 | false | {"Kotlin": 97942, "Shell": 1067} | package y2023.day02
fun main() {
AoCGenerics.printAndMeasureResults(
part1 = { part1() },
part2 = { part2() }
)
}
data class Game(
val id: Int,
var red: Int = 0,
var blue: Int = 0,
var green: Int = 0
)
fun input(): List<Game> {
return AoCGenerics.getInputLines("/y2023/day0... | 0 | Kotlin | 0 | 0 | 23b3edf887e31bef5eed3f00c1826261b9a4bd30 | 1,358 | AdventOfCode | MIT License |
kotlin/src/main/kotlin/LongestSubstringFromChanHo.kt | funfunStudy | 93,757,087 | false | null | import kotlin.math.max
fun main(args: Array<String>) {
val problems = listOf("abcabcbb", "bbbbb", "pwwkew", "", "dvdf", "asjrgapa")
val expected = listOf(3, 1, 3, 0, 3, 6)
problems.mapIndexed { index, s -> Pair(solution(s), expected.get(index)) }
.forEach { (result, expected) ->
... | 0 | Kotlin | 3 | 14 | a207e4db320e8126169154aa1a7a96a58c71785f | 1,290 | algorithm | MIT License |
code/other/FastSubsetSum.kt | hakiobo | 397,069,173 | false | null | private fun fastSubsetSum(nums: IntArray, goal: Int, x: Int): Int {
val n = nums.size
val maxPref = IntArray((x shl 1) - 1) { -1 }
val cur = IntArray(x)
var part = 0
var b = 0
while (b < n && part + nums[b] <= goal) {
part += nums[b]
b++
}
if(b == n) return part
maxPr... | 0 | Kotlin | 1 | 2 | f862cc5e7fb6a81715d6ea8ccf7fb08833a58173 | 2,775 | Kotlinaughts | MIT License |
src/main/kotlin/org/sjoblomj/adventofcode/day3/Day3.kt | sjoblomj | 161,537,410 | false | null | package org.sjoblomj.adventofcode.day3
import org.sjoblomj.adventofcode.readFile
import kotlin.system.measureTimeMillis
private const val inputFile = "src/main/resources/inputs/day3.txt"
typealias Claims = MutableList<Claim>
typealias Area = Array<Array<Claims>>
inline fun <reified T> matrix2d(height: Int, width: I... | 0 | Kotlin | 0 | 0 | 80db7e7029dace244a05f7e6327accb212d369cc | 2,067 | adventofcode2018 | MIT License |
src/main/kotlin/Crane.kt | alebedev | 573,733,821 | false | {"Kotlin": 82424} | fun main() {
Crane.solve()
}
object Crane {
fun solve() {
val input = readInput()
val result = runMoves(input.state, input.moves)
println("Top of stacks: ${result.map { it.first() }.joinToString("")}")
}
private fun readInput(): Input {
val stacks = mutableListOf<Pair<I... | 0 | Kotlin | 0 | 0 | d6ba46bc414c6a55a1093f46a6f97510df399cd1 | 2,684 | aoc2022 | MIT License |
src/main/kotlin/Day14.kt | dliszewski | 573,836,961 | false | {"Kotlin": 57757} | class Day14 {
fun part1(input: List<String>): Int {
val rocks = mapToRocks(input)
return Cave(rocks).dropSand()
}
fun part2(input: List<String>): Int {
val rocks = mapToRocks(input)
return Cave(rocks, true).dropSandWithFloor()
}
private fun mapToRocks(input: List<S... | 0 | Kotlin | 0 | 0 | 76d5eea8ff0c96392f49f450660220c07a264671 | 3,640 | advent-of-code-2022 | Apache License 2.0 |
src/year2022/day03/Day03.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2022.day03
import io.kotest.matchers.shouldBe
import utils.readInput
fun main() {
val testInput = readInput("03", "test_input")
val realInput = readInput("03", "input")
testInput.asSequence()
.findDuplicates()
.mapToPriorities()
.sum()
.also(::println) shouldBe... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 1,403 | Advent-of-Code | Apache License 2.0 |
src/Day05.kt | mihansweatpants | 573,733,975 | false | {"Kotlin": 31704} | import java.util.LinkedList
fun main() {
fun part1(input: List<String>): String {
val (stacks, moves) = parseInput(input)
for (move in moves) {
val fromStack = stacks[move.from]!!
val toStack = stacks[move.to]!!
repeat(move.amount) {
toStack += ... | 0 | Kotlin | 0 | 0 | 0de332053f6c8f44e94f857ba7fe2d7c5d0aae91 | 2,349 | aoc-2022 | Apache License 2.0 |
src/Day13.kt | Fenfax | 573,898,130 | false | {"Kotlin": 30582} | import org.apache.commons.collections4.ListUtils
fun main() {
fun parseSingleSignal(s: String): Any {
val signal = mutableListOf<Any>()
if (!s.contains("]") && !s.contains("[") && !s.contains(",")) {
return s.takeIf { it != "" }?.toInt() ?: Unit
}
val currentString = ... | 0 | Kotlin | 0 | 0 | 28af8fc212c802c35264021ff25005c704c45699 | 4,115 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/aoc2023/day3/day3Solver.kt | Advent-of-Code-Netcompany-Unions | 726,531,711 | false | {"Kotlin": 94973} | package aoc2023.day3
import lib.*
suspend fun main() {
setupChallenge().solveChallenge()
}
fun setupChallenge(): Challenge<Array<Array<Char>>> {
return setup {
day(3)
year(2023)
//input("example.txt")
parser {
it.readLines().get2DArrayOfColumns()
}
... | 0 | Kotlin | 0 | 0 | a77584ee012d5b1b0d28501ae42d7b10d28bf070 | 3,553 | AoC-2023-DDJ | MIT License |
AOC-2023/src/main/kotlin/Day05.kt | sagar-viradiya | 117,343,471 | false | {"Kotlin": 72737} | import utils.*
object Day05 {
fun part01(input: String): Long {
val inputParts = input.splitAtNewEmptyLines()
val seeds = inputParts[0].splitAtColon()[1].trim().splitAtWhiteSpace().map { it.toLong() }
val mapList = inputParts.drop(0).map { input ->
sourceToDestinationMap(
... | 0 | Kotlin | 0 | 0 | 7f88418f4eb5bb59a69333595dffa19bee270064 | 2,462 | advent-of-code | MIT License |
src/day02/Day02.kt | daniilsjb | 726,047,752 | false | {"Kotlin": 66638, "Python": 1161} | package day02
import java.io.File
fun main() {
val data = parse("src/day02/Day02.txt")
println("🎄 Day 02 🎄")
println()
println("[Part 1]")
println("Answer: ${part1(data)}")
println()
println("[Part 2]")
println("Answer: ${part2(data)}")
}
private data class CubeSet(
val red... | 0 | Kotlin | 0 | 0 | 46a837603e739b8646a1f2e7966543e552eb0e20 | 1,823 | advent-of-code-2023 | MIT License |
src/main/kotlin/days/Day15.kt | hughjdavey | 725,972,063 | false | {"Kotlin": 76988} | package days
class Day15 : Day(15) {
private val initSequence = inputString.replace("\n", "").split(',')
override fun partOne(): Any {
return initSequence.sumOf(this::hash)
}
override fun partTwo(): Any {
val boxes = (0..255).associateWith { mutableListOf<Lens>() }
val steps ... | 0 | Kotlin | 0 | 0 | 330f13d57ef8108f5c605f54b23d04621ed2b3de | 1,815 | aoc-2023 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/problems/Day15.kt | PedroDiogo | 432,836,814 | false | {"Kotlin": 128203} | package problems
import java.util.*
class Day15(override val input: String) : Problem {
override val number: Int = 15
override fun runPartOne(): String {
val board = Board.fromStr(input)
return board.lowestTotalRisk().toString()
}
override fun runPartTwo(): String {
val board... | 0 | Kotlin | 0 | 0 | 93363faee195d5ef90344a4fb74646d2d26176de | 3,668 | AdventOfCode2021 | MIT License |
src/Day04.kt | mrugacz95 | 572,881,300 | false | {"Kotlin": 102751} | private fun IntRange.contains(other: IntRange): Boolean {
return first <= other.first && last >= other.last
}
private fun IntRange.overlap(other: IntRange): Boolean {
return first <= other.last && other.first <= last
}
fun main() {
fun parse(line: String): List<IntRange> {
return line.split(',').m... | 0 | Kotlin | 0 | 0 | 29aa4f978f6507b182cb6697a0a2896292c83584 | 956 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/ikueb/advent18/Day22.kt | h-j-k | 159,901,179 | false | null | package com.ikueb.advent18
import com.ikueb.advent18.model.Point
import java.util.*
object Day22 {
fun getRiskLevel(depth: Int, target: Point) = HardCave(depth, target).apply {
(0..target.y).forEach { y ->
(0..target.x).forEach { x -> at(Point(x, y)) }
}
}.getTotalRiskRiskLevel()
... | 0 | Kotlin | 0 | 0 | f1d5c58777968e37e81e61a8ed972dc24b30ac76 | 3,344 | advent18 | Apache License 2.0 |
src/main/kotlin/aoc2022/Day07.kt | lukellmann | 574,273,843 | false | {"Kotlin": 175166} | package aoc2022
import AoCDay
import util.illegalInput
import kotlin.math.min
// https://adventofcode.com/2022/day/7
object Day07 : AoCDay<Int>(
title = "No Space Left On Device",
part1ExampleAnswer = 95437,
part1Answer = 1792222,
part2ExampleAnswer = 24933642,
part2Answer = 1112963,
) {
priva... | 0 | Kotlin | 0 | 1 | 344c3d97896575393022c17e216afe86685a9344 | 4,168 | advent-of-code-kotlin | MIT License |
src/Day08.kt | dyomin-ea | 572,996,238 | false | {"Kotlin": 21309} | interface Tree {
val height: Int
val u: Tree
val d: Tree
val l: Tree
val r: Tree
}
fun main() {
operator fun List<String>.get(r: Int, c: Int): Int =
this[r][c] - '0'
operator fun <V> MutableMap<Pair<Int, Int>, V>.set(r: Int, c: Int, value: V) {
set(r to c, value)
}
val plain = object : Tree {
overr... | 0 | Kotlin | 0 | 0 | 8aaf3f063ce432207dee5f4ad4e597030cfded6d | 2,727 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc2018/day11/ChronalCharge.kt | arnab | 75,525,311 | false | null | package aoc2018.day11
data class Grid(val sizeX: Int, val sizeY: Int, val serial: Int) {
private val grid = Array(sizeX + 1) { IntArray(sizeY + 1) }
fun calculateAreaWithHighestPower(sizeOfBox: Int): Pair<Point, Int>? {
for (y in 1 until sizeY + 1 ) {
for (x in 1 until sizeX + 1) {
... | 0 | Kotlin | 0 | 0 | 1d9f6bc569f361e37ccb461bd564efa3e1fccdbd | 1,927 | adventofcode | MIT License |
src/Day05.kt | JCampbell8 | 572,669,444 | false | {"Kotlin": 10115} | import java.util.*
fun main() {
data class CrateMovement(val numCrates: Int, val fromStack: Int, val toStack: Int)
fun parseCrates(input: List<String>): MutableList<Deque<String>> {
val crateChart = input.subList(0, input.indexOf(""))
val numRows = crateChart[crateChart.size - 1].replace("\\s... | 0 | Kotlin | 0 | 1 | 0bac6b866e769d0ac6906456aefc58d4dd9688ad | 2,686 | advent-of-code-2022 | Apache License 2.0 |
src/Day14.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} |
class Day14 {
private fun Point2d.next(map: Set<Point2d>, resting: Set<Point2d>) = listOf(
Point2d(x, y + 1),
Point2d(x - 1, y + 1),
Point2d(x + 1, y + 1)
).firstOrNull { it !in map && it !in resting }
private fun parse(input: List<String>): Set<Point2d>{
val ret = mutable... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 1,812 | aoc-22-kotlin | Apache License 2.0 |
src/main/kotlin/leetcode/problem0018/FourSum.kt | ayukatawago | 456,312,186 | false | {"Kotlin": 266300, "Python": 1842} | package leetcode.problem0018
class FourSum {
fun fourSum(nums: IntArray, target: Int): List<List<Int>> {
val sortedNums = nums.sorted()
return kSum(sortedNums, target, 4)
}
private fun kSum(sortedNums: List<Int>, target: Int, k: Int): List<List<Int>> {
if (sortedNums.isEmpty()) {
... | 0 | Kotlin | 0 | 0 | f9602f2560a6c9102728ccbc5c1ff8fa421341b8 | 1,854 | leetcode-kotlin | MIT License |
src/Day10.kt | jamie23 | 573,156,415 | false | {"Kotlin": 19195} | fun main() {
fun solution(input: List<String>): Int {
val set = setOf(20, 60, 100, 140, 180, 220)
val result = mutableListOf<Int>()
var total = 1
var instructionIndex = 0
val instructions = input
.map { it.split(' ') }
.toInstructions()
var ... | 0 | Kotlin | 0 | 0 | cfd08064654baabea03f8bf31c3133214827289c | 1,553 | Aoc22 | Apache License 2.0 |
src/main/kotlin/com/tonnoz/adventofcode23/day17/Day17.kt | tonnoz | 725,970,505 | false | {"Kotlin": 78395} | package com.tonnoz.adventofcode23.day17
import com.tonnoz.adventofcode23.utils.println
import com.tonnoz.adventofcode23.utils.readInput
import com.tonnoz.adventofcode23.utils.toListOfInts
import java.util.*
import kotlin.system.measureTimeMillis
object Day17 {
@JvmStatic
fun main(args: Array<String>) {
val ci... | 0 | Kotlin | 0 | 0 | d573dfd010e2ffefcdcecc07d94c8225ad3bb38f | 4,219 | adventofcode23 | MIT License |
src/Day04.kt | xabgesagtx | 572,139,500 | false | {"Kotlin": 23192} | fun main() {
fun part1(input: List<String>): Int {
return input.map { it.split(",") }
.map { (first, second) -> first.toIntSet() to second.toIntSet() }
.count { it.first.containsAll(it.second) || it.second.containsAll(it.first) }
}
fun part2(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | 976d56bd723a7fc712074066949e03a770219b10 | 918 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/de/jball/aoc2022/day09/Day09.kt | fibsifan | 573,189,295 | false | {"Kotlin": 43681} | package de.jball.aoc2022.day09
import de.jball.aoc2022.Day
import kotlin.math.abs
import kotlin.math.sign
class Day09(test: Boolean = false) : Day<Int>(test, 88, 36) {
private val directions = input.map { parseDirectionLine(it) }
private fun parseDirectionLine(directionLine: String): Pair<Direction, Int> {
... | 0 | Kotlin | 0 | 3 | a6d01b73aca9b54add4546664831baf889e064fb | 2,350 | aoc-2022 | Apache License 2.0 |
day04/src/main/kotlin/Main.kt | rstockbridge | 159,586,951 | false | null | import Constants.Companion.MINUTES_IN_AN_HOUR
import java.io.File
import java.lang.Double.NEGATIVE_INFINITY
fun main() {
val guardData = extractGuardData(readInputFile())
println("Part I: the solution is ${solvePartI(guardData)}.")
println("Part II: the solution is ${solvePartII(guardData)}.")
}
fun read... | 0 | Kotlin | 0 | 0 | c404f1c47c9dee266b2330ecae98471e19056549 | 5,405 | AdventOfCode2018 | MIT License |
src/day09/Day09.kt | andreas-eberle | 573,039,929 | false | {"Kotlin": 90908} | package day09
import readInput
import kotlin.math.absoluteValue
import kotlin.math.sign
const val day = "09"
fun main() {
fun calculatePart1Score(input: List<String>): Int {
val states = input.executeMoves(2)
return states.countLastKnotPositions()
}
fun calculatePart2Score(input: List<S... | 0 | Kotlin | 0 | 0 | e42802d7721ad25d60c4f73d438b5b0d0176f120 | 2,335 | advent-of-code-22-kotlin | Apache License 2.0 |
src/Day04.kt | derivz | 575,340,267 | false | {"Kotlin": 6141} | fun main() {
fun part1(lines: List<String>): Int {
return lines.map { line ->
val (left, right) = line.split(",")
val (leftStart, leftEnd) = left.split("-").map { it.toInt() }
val (rightStart, rightEnd) = right.split("-").map { it.toInt() }
if ((leftStart <= r... | 0 | Kotlin | 0 | 0 | 24da2ff43dc3878c4e025f5b737dca31913f40a5 | 1,153 | AoC2022.kt | Apache License 2.0 |
src/Day03_RucksackReorganization.kt | raipc | 574,467,742 | false | {"Kotlin": 9511} | fun main() {
checkAndSolve("Day03", 157) { calculateSumOfCommonTypePriorities(it) }
checkAndSolve("Day03", 70) { calculateSumOfCommonAcrossGroupsOfThree(it) }
}
private fun calculateSumOfCommonTypePriorities(lines: List<String>) =
lines.sumOf { calculatePriority(findCommonType(it)) }
private fun uniqueCha... | 0 | Kotlin | 0 | 0 | 9068c21dc0acb5e1009652b4a074432000540d71 | 1,629 | adventofcode22 | Apache License 2.0 |
src/Day05.kt | a2xchip | 573,197,744 | false | {"Kotlin": 37206} | import java.io.File
class Stacks(val stacks: List<ArrayDeque<Char>>) {
fun move(action: Action) {
repeat(action.times) {
val c = stacks[action.from].removeFirst()
stacks[action.to].addFirst(c)
}
}
fun moveBatched(action: Action) {
val batch = mutableListOf<C... | 0 | Kotlin | 0 | 2 | 19a97260db00f9e0c87cd06af515cb872d92f50b | 2,823 | kotlin-advent-of-code-22 | Apache License 2.0 |
src/Day03.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | fun main() {
fun priority(c: Char): Int = if (c in 'A'..'Z') c - 'A' + 27 else c - 'a' + 1
fun countRepetitions(line: String): Int {
val n = line.length
val second = line.subSequence(n / 2, n).toSet()
return line.subSequence(0, n / 2).toSet().filter { it in second }.sumOf { priority(it)... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 897 | advent-of-kotlin-2022 | Apache License 2.0 |
src/Day21.kt | nordberg | 573,769,081 | false | {"Kotlin": 47470} | import kotlin.math.max
fun main() {
fun getOperation(op: Char): (Long, Long) -> Long {
return when (op) {
'/' -> { x: Long, y: Long -> x / y }
'*' -> { x: Long, y: Long -> x * y }
'+' -> { x: Long, y: Long -> x + y }
'-' -> { x: Long, y: Long -> x - y }
... | 0 | Kotlin | 0 | 0 | 3de1e2b0d54dcf34a35279ba47d848319e99ab6b | 2,265 | aoc-2022 | Apache License 2.0 |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day22.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwenty
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
class Day22 : Day<Long> {
private data class Player(val name: String, val deck: List<Int>)
private data class Round(val players: List<Player>)
private data class RoundResult(val round: Roun... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 3,950 | adventofcode | Apache License 2.0 |
src/Day13.kt | phoenixli | 574,035,552 | false | {"Kotlin": 29419} | import kotlin.math.min
fun main() {
fun part1(input: List<String>): Int {
var pairIdx = 0
var idxSum = 0
input.chunked(3).forEach{
pairIdx++
val isInOrder = isInOrder(toList(it[0]), toList(it[1]))
if (isInOrder) {
idxSum += pairIdx
... | 0 | Kotlin | 0 | 0 | 5f993c7b3c3f518d4ea926a792767a1381349d75 | 3,209 | Advent-of-Code-2022 | Apache License 2.0 |
2015/Day05/src/main/kotlin/Main.kt | mcrispim | 658,165,735 | false | null | import java.io.File
fun main() {
fun part1(input: List<String>): Int {
// Rule 1
// It contains at least three vowels (aeiou only), like aei, xazegov, or aeiouaeiouaeiou.
fun String.rule1Nice(): Boolean = this.split(Regex("(a|e|i|o|u)")).size > 3
// Rule 2
// It contains ... | 0 | Kotlin | 0 | 0 | 2f4be35e78a8a56fd1e078858f4965886dfcd7fd | 2,282 | AdventOfCode | MIT License |
src/main/kotlin/com/groundsfam/advent/y2021/d03/Day03.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2021.d03
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
// most common bit of position i of all nums
fun gammaRate(binaryNums: List<String>): String {
val n = binaryNums.size
return binaryNums[0]... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 1,557 | advent-of-code | MIT License |
src/Day05.kt | arnoutvw | 572,860,930 | false | {"Kotlin": 33036} | import java.util.*
import kotlin.collections.ArrayList
fun main() {
fun fillStacks(it: String, buckets: TreeMap<Int, LinkedList<String>>) {
val chunkes = it.chunked(4)
chunkes.forEachIndexed { index, element ->
val letter = element.substring(1..1)
if (letter.isNotBlank() &&... | 0 | Kotlin | 0 | 0 | 0cee3a9249fcfbe358bffdf86756bf9b5c16bfe4 | 2,841 | aoc-2022-in-kotlin | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.