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/10.kts | reitzig | 318,492,753 | false | null | import java.io.File
data class Joltage(val value: Int) : Comparable<Joltage> {
fun canTake(other: Joltage): Boolean =
value <= other.value + 3
override fun compareTo(other: Joltage): Int =
value.compareTo(other.value)
operator fun plus(difference: Int): Joltage =
Joltage(value + d... | 0 | Kotlin | 0 | 0 | f17184fe55dfe06ac8897c2ecfe329a1efbf6a09 | 1,582 | advent-of-code-2020 | The Unlicense |
src/Day05.kt | mythicaleinhorn | 572,689,424 | false | {"Kotlin": 11494} | import java.util.*
fun main() {
fun parseInput(input: List<String>): List<Deque<Char>> {
val stacks = mutableListOf<Deque<Char>>()
val drawing = input.take(input.indexOf(""))
val n = drawing.last().trim()[drawing.last().trim().lastIndex].digitToInt()
repeat(n) {
stacks.... | 0 | Kotlin | 0 | 0 | 959dc9f82c14f59d8e3f182043c59aa35e059381 | 2,220 | advent-of-code-2022 | Apache License 2.0 |
cz.wrent.advent/Day5.kt | Wrent | 572,992,605 | false | {"Kotlin": 206165} | package cz.wrent.advent
import java.util.*
fun main() {
val result = partOne(input)
println("5a: $result")
val resultTwo = partTwo(input)
println("5b: $resultTwo")
}
private fun partOne(input: String): String {
return moveCrates(input) { x, y, z -> moveCrates9000(x, y, z) }
}
private fun partTwo(input: String)... | 0 | Kotlin | 0 | 0 | 8230fce9a907343f11a2c042ebe0bf204775be3f | 11,968 | advent-of-code-2022 | MIT License |
src/d01/Day01.kt | Ezike | 573,181,935 | false | {"Kotlin": 7967} | package d01
import readInput
fun main() {
fun part1(day: String): Int? {
var calories = mutableListOf<Int>()
var sum = 0
val (input, lastIndex) = readInput(day).let { it to it.lastIndex }
for ((i, s) in input.withIndex()) {
if (s.isEmpty()) {
sum = maxOf... | 0 | Kotlin | 0 | 0 | 07ed8acc2dcee09cc4f5868299a8eb5efefeef6d | 1,476 | advent-of-code | Apache License 2.0 |
src/Day19.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | object Day19 {
const val EXPECTED_PART1_CHECK_ANSWER = 33
const val EXPECTED_PART2_CHECK_ANSWER = 3472
val BLUEPRINT_REGEX =
Regex("Blueprint (\\d+): Each ore robot costs (\\d+) ore. Each clay robot costs (\\d+) ore. Each obsidian robot costs (\\d+) ore and (\\d+) clay. Each geode robot costs (\\d+... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 6,375 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/day17/Day17.kt | qnox | 575,581,183 | false | {"Kotlin": 66677} | package day17
import readInput
fun main() {
val rocks = listOf(
listOf("####"),
listOf(
" # ",
"###",
" # "
),
listOf(
" #",
" #",
"###"
),
listOf(
"#",
"#",
... | 0 | Kotlin | 0 | 0 | 727ca335d32000c3de2b750d23248a1364ba03e4 | 5,193 | aoc2022 | Apache License 2.0 |
src/main/kotlin/se/brainleech/adventofcode/aoc2022/Aoc2022Day01.kt | fwangel | 435,571,075 | false | {"Kotlin": 150622} | package se.brainleech.adventofcode.aoc2022
import se.brainleech.adventofcode.compute
import se.brainleech.adventofcode.readLines
import se.brainleech.adventofcode.verify
import kotlin.math.max
class Aoc2022Day01 {
fun part1(input: List<String>): Long {
var maxCalories = 0L
var currentCalories = 0... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 1,291 | adventofcode | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/GraphValidTree.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <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 | 5,390 | kotlab | Apache License 2.0 |
src/Day03.kt | dyomin-ea | 572,996,238 | false | {"Kotlin": 21309} | fun main() {
fun intersection(input: List<String>): Iterable<Char> =
input.fold(
input.first()
.toSet()
) { acc, s ->
acc.intersect(s.toSet())
}
fun pointsOf(c: Char): Int =
when (c) {
in 'a'..'z' -> c - 'a' + 1
in 'A'..'Z' -> c - 'A' + 27
else -> error("unsupported")
}
fun Str... | 0 | Kotlin | 0 | 0 | 8aaf3f063ce432207dee5f4ad4e597030cfded6d | 918 | advent-of-code-2022 | Apache License 2.0 |
src/Day01/Day01.kt | brhliluk | 572,914,305 | false | {"Kotlin": 16006} | fun main() {
fun part1(input: List<String>) = input.chunkBy { it.isEmpty() }.map {
calloryList -> calloryList.map { it.toInt() }.reduce { acc, meal -> acc + meal }
}.maxOrNull()
fun part2(input: List<String>) = input.chunkBy { it.isEmpty() }.map {
calloryList -> calloryList.map ... | 0 | Kotlin | 0 | 0 | 96ac4fe0c021edaead8595336aad73ef2f1e0d06 | 869 | kotlin-aoc | Apache License 2.0 |
src/main/kotlin/com/scavi/brainsqueeze/adventofcode/Day12RainRisk.kt | Scavi | 68,294,098 | false | {"Java": 1449516, "Kotlin": 59149} | package com.scavi.brainsqueeze.adventofcode
import kotlin.math.abs
class Day12RainRisk(private val wayPoint: WayPoint? = null) {
private enum class CardDirection(val value: Int) {
N(0), E(90), S(180), W(270);
companion object {
fun fromInt(value: Int) = values().first { it.value == va... | 0 | Java | 0 | 1 | 79550cb8ce504295f762e9439e806b1acfa057c9 | 3,387 | BrainSqueeze | Apache License 2.0 |
src/Day03.kt | ditn | 572,953,437 | false | {"Kotlin": 5079} | fun main() {
fun part1(input: List<String>): Int = input
.map {
val left = it.subSequence(0, it.length / 2)
val right = it.subSequence(it.length / 2, it.length)
left.toSet() intersect right.toSet()
}
.map(Set<Char>::first)
.map(Char::toPriority)
... | 0 | Kotlin | 0 | 0 | 4c9a286a911cd79d433075cda5ed01249ecb5994 | 899 | aoc2022 | Apache License 2.0 |
src/main/kotlin/co/csadev/advent2021/Day05.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2021 by <NAME>
* Advent of Code 2021, Day 5
* Problem Description: http://adventofcode.com/2021/day/5
*/
package co.csadev.advent2021
import co.csadev.adventOfCode.BaseDay
import co.csadev.adventOfCode.Resources.resourceAsText
class Day05(override val input: List<String> = resourceAsText("21da... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 1,473 | advent-of-kotlin | Apache License 2.0 |
src/main/kotlin/leetcode/advanceds/DisjointSetDataStructure1.kt | sandeep549 | 251,593,168 | false | null | package leetcode.advanceds
// https://en.wikipedia.org/wiki/Disjoint-set_data_structure
// https://www.techiedelight.com/disjoint-set-data-structure-union-find-algorithm/
/**
* Problem Statement: We have some number of items. We are allowed to merge any two items to consider them equal.
* At any point we should be ... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 2,073 | kotlinmaster | Apache License 2.0 |
string-similarity/src/commonMain/kotlin/com/aallam/similarity/JaroWinkler.kt | aallam | 597,692,521 | false | null | package com.aallam.similarity
import kotlin.math.max
import kotlin.math.min
/**
* The Jaro–Winkler distance metric is designed and best suited for short strings such as person names, and to detect
* typos; it is (roughly) a variation of Damerau-Levenshtein, where the substitution of 2 close characters is considered... | 0 | Kotlin | 0 | 1 | 40cd4eb7543b776c283147e05d12bb840202b6f7 | 6,664 | string-similarity-kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CherryPickup.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,566 | kotlab | Apache License 2.0 |
src/Day24.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | suspend fun main() {
val testInput = readInput("Day24_test")
check(part1(testInput) == 18)
check(part2(testInput) == 54)
val input = readInput("Day24")
measureAndPrintResult {
part1(input)
}
measureAndPrintResult {
part2(input)
}
}
private fun part1(input: List<String>)... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 2,067 | aoc-22 | Apache License 2.0 |
src/main/aoc2021/Day10.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2021
class Day10(val input: List<String>) {
companion object {
private val opposite = mapOf('{' to '}', '[' to ']', '(' to ')', '<' to '>')
private val part1Scores = mapOf(')' to 3, ']' to 57, '}' to 1197, '>' to 25137)
// We have a list of leftover opening characters without an... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,578 | aoc | MIT License |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2023/2023-16.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2023
import com.github.ferinagy.adventOfCode.CharGrid
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.get
import com.github.ferinagy.adventOfCode.isIn
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfC... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 2,638 | advent-of-code | MIT License |
src/main/kotlin/day09/DayNine.kt | Neonader | 572,678,494 | false | {"Kotlin": 19255} | package day09
import java.io.File
data class Knot(var x: Int, var y: Int)
val fileList = File("puzzle_input/day09.txt").readLines()
fun moveHead(head: Knot, direction: Char) = when (direction) {
'U' -> Knot(head.x, head.y + 1)
'L' -> Knot(head.x - 1, head.y)
'R' -> Knot(head.x + 1, head.y)
'D' -... | 0 | Kotlin | 0 | 3 | 4d0cb6fd285c8f5f439cb86cb881b4cd80e248bc | 1,751 | Advent-of-Code-2022 | MIT License |
src/main/kotlin/com/ginsberg/advent2021/Day15.kt | tginsberg | 432,766,033 | false | {"Kotlin": 92813} | /*
* Copyright (c) 2021 by <NAME>
*/
/**
* Advent of Code 2021, Day 15 - Chiton
* Problem Description: http://adventofcode.com/2021/day/15
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2021/day15/
*/
package com.ginsberg.advent2021
import java.util.PriorityQueue
typealias ChitonCave = A... | 0 | Kotlin | 2 | 34 | 8e57e75c4d64005c18ecab96cc54a3b397c89723 | 2,281 | advent-2021-kotlin | Apache License 2.0 |
src/Day03.kt | robotfooder | 573,164,789 | false | {"Kotlin": 25811} | fun main() {
fun part1(input: List<String>): Int = input
.map { it.splitToPair(it.length / 2) }
.flatMap { (c1, c2) -> c1.toSet() intersect c2.toSet() }
.sumOf { it.score() }
fun part2(input: List<String>): Int {
return input
.chunked(3)
.flatMap { it[0... | 0 | Kotlin | 0 | 0 | 9876a52ef9288353d64685f294a899a58b2de9b5 | 993 | aoc2022 | Apache License 2.0 |
src/main/kotlin/solutions/day05/Day5.kt | Dr-Horv | 570,666,285 | false | {"Kotlin": 115643} | package solutions.day05
import solutions.Solver
class Day5 : Solver {
override fun solve(input: List<String>, partTwo: Boolean): String {
val inputList = input.toMutableList()
val stacks = parseStacks(inputList)
performMoves(stacks, inputList, partTwo)
return (1..stacks.keys.max... | 0 | Kotlin | 0 | 2 | 6c9b24de2fe2a36346cb4c311c7a5e80bf505f9e | 2,011 | Advent-of-Code-2022 | MIT License |
2022/src/main/kotlin/day20_attempt2.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.badInput
import utils.mapItems
fun main() {
Day20_2.run()
}
object Day20_2 : Solution<List<Int>>() {
override val name = "day20"
override val parser = Parser.lines.mapItems { it.toInt() }
data class Item(
val origIndex: Int,
val value: Int,
)
... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,192 | aoc_kotlin | MIT License |
src/Day05.kt | ezeferex | 575,216,631 | false | {"Kotlin": 6838} | import java.util.*
fun processCrate(crates: List<String>): Pair<List<Stack<Char>>, List<Triple<Int, Int, Int>>> {
val stacks = mutableListOf<Stack<Char>>()
val lines = crates[0].split("\n")
lines.last().split(" ")
.filter(String::isNotBlank)
.forEach { _ ->
stacks.add(Stack<Char... | 0 | Kotlin | 0 | 0 | f06f8441ad0d7d4efb9ae449c9f7848a50f3f57c | 1,973 | advent-of-code-2022 | Apache License 2.0 |
src/day09/Day09.kt | robin-schoch | 572,718,550 | false | {"Kotlin": 26220} | package day09
import AdventOfCodeSolution
import kotlin.math.abs
fun main() {
Day09.run()
}
sealed class MoveDirection {
companion object {
fun of(direction: Char) = when (direction) {
'R' -> Right
'U' -> Up
'L' -> Left
'D' -> Down
else -> e... | 0 | Kotlin | 0 | 0 | fa993787cbeee21ab103d2ce7a02033561e3fac3 | 3,577 | aoc-2022 | Apache License 2.0 |
server/src/main/kotlin/com/heerkirov/hedge/server/library/compiler/grammar/definintion/SyntaxTable.kt | HeerKirov | 298,201,781 | false | null | package com.heerkirov.hedge.server.library.compiler.grammar.definintion
import kotlin.math.max
//语法分析表的定义,作用是和syntax-table.txt中的定义对应。
class SyntaxTable(internal val actionTable: Array<Array<Action?>>,
internal val gotoTable: Array<Array<Int?>>,
private val actionMap: Map<String, I... | 0 | TypeScript | 0 | 1 | 8140cd693759a371dc5387c4a3c7ffcef6fb14b2 | 4,854 | Hedge-v2 | MIT License |
usvm-util/src/main/kotlin/org/usvm/algorithms/GraphUtils.kt | UnitTestBot | 586,907,774 | false | {"Kotlin": 2547205, "Java": 471958} | package org.usvm.algorithms
import java.util.LinkedList
import java.util.Queue
/**
* Finds minimal distances from one vertex to all other vertices in unweighted graph.
* A map with already calculated minimal distances can be specified to reduce the amount of calculations.
*
* @param startVertex vertex to find dis... | 39 | Kotlin | 0 | 7 | 94c5a49a0812737024dee5be9d642f22baf991a2 | 5,753 | usvm | Apache License 2.0 |
src/main/kotlin/Problem4.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | /**
* Largest palindrome product
*
* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is
* 9009 = 91 × 99.
*
* Find the largest palindrome made from the product of two 3-digit numbers.
*
* https://projecteuler.net/problem=4
*/
fun main() {
... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 1,023 | project-euler | MIT License |
tmp/arrays/youTrackTests/1541.kt | vitekkor | 600,111,569 | true | {"Kotlin": 11752665, "JavaScript": 2761845, "ANTLR": 28803, "Java": 12579} | // Original bug: KT-37416
fun main() = println(solve().joinToString("\n"))
private fun solve() = Array(readLine()!!.toInt()) { tn ->
if (tn > 0) readLine()
val (n, m) = readLine()!!.split(" ").map { it.toInt() }
val c = readLine()!!.split(" ").map { it.toLong() }
val g = Array(n) { ArrayList<Int>(2) ... | 1 | Kotlin | 12 | 0 | f47406356a160ac61ab788f985b37121cc2e2a2a | 788 | bbfgradle | Apache License 2.0 |
HackerRank/BiggerIsGreater/Iteration1.kt | MahdiDavoodi | 434,677,181 | false | {"Kotlin": 57766, "JavaScript": 17002, "Java": 10647, "HTML": 696, "Python": 683} | fun biggerIsGreater(w: String): String {
var str = w.toCharArray().toMutableList()
if (w.length < 2) return "no answer"
for (i in str.size - 2 downTo 0) {
if (str[i] < str[i + 1]) {
val ch = str[i]
val cutFrom = i + 1
val rest = str.subList(cutFrom, str.size)
... | 0 | Kotlin | 0 | 0 | 62a23187efc6299bf921a95c8787d02d5be51742 | 1,462 | ProblemSolving | MIT License |
src/main/kotlin/day07/Day07.kt | dustinconrad | 572,737,903 | false | {"Kotlin": 100547} | package day07
import readResourceAsBufferedReader
import java.util.function.Predicate
fun main() {
println("part 1: ${part1(readResourceAsBufferedReader("7_1.txt").readLines())}")
println("part 2: ${part2(readResourceAsBufferedReader("7_1.txt").readLines())}")
}
fun part1(input: List<String>): Int {
val ... | 0 | Kotlin | 0 | 0 | 1dae6d2790d7605ac3643356b207b36a34ad38be | 4,696 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/net/voldrich/aoc2022/Day07.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2022
import net.voldrich.BaseDay
import java.lang.RuntimeException
// https://adventofcode.com/2022/day/7
fun main() {
Day07().run()
}
class Day07 : BaseDay() {
override fun task1() : Int {
val rootDir = parseDirectoryTree()
return rootDir.filterDirectories { it.dirSi... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 3,073 | advent-of-code | Apache License 2.0 |
src/main/kotlin/day12.kt | tianyu | 574,561,581 | false | {"Kotlin": 49942} | import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEqualTo
private fun main() {
tests {
val example = HeightMap(
"""
Sabqponm
abcryxxl
accszExk
acctuvwj
abdefghi
""".trimIndent().encodeToByteArray()
)
"Re... | 0 | Kotlin | 0 | 0 | 6144cc0ccf1a51ba2e28c9f38ae4e6dd4c0dc1ea | 2,894 | AdventOfCode2022 | MIT License |
2021/src/main/kotlin/de/skyrising/aoc2021/day21/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2021.day21
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap
val test = TestInput("""
Player 1 starting position: 4
Player 2 starting position: 8
""")
@PuzzleName("<NAME>")
fun PuzzleInput.part1(): Any {
var (p1, p2) = parseInput(this)
... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 2,291 | aoc | MIT License |
08/kotlin/src/main/kotlin/se/nyquist/Functions.kt | erinyq712 | 437,223,266 | false | {"Kotlin": 91638, "C#": 10293, "Emacs Lisp": 4331, "Java": 3068, "JavaScript": 2766, "Perl": 1098} | package se.nyquist
import java.math.BigInteger
fun <T> getPermutationsWithDistinctValues(original: List<T>): Set<List<T>> {
if (original.isEmpty())
return emptySet()
val permutationInstructions = original.toSet()
.map { it to original.count { x -> x == it } }
.fold(listOf(setOf<Pair<T,... | 0 | Kotlin | 0 | 0 | b463e53f5cd503fe291df692618ef5a30673ac6f | 2,299 | adventofcode2021 | Apache License 2.0 |
src/main/kotlin/days/y22/Day02.kt | kezz | 572,635,766 | false | {"Kotlin": 20772} | package days.y22
import util.Day
public fun main() {
Day2().run()
}
public class Day2 : Day(22, 2) {
override fun part1(input: List<String>): Any = input
.map { string -> string.filterNot(Char::isWhitespace).toCharArray() }
.map { (opponentCode, playerCode) -> Pair(opponentCode.code - 64, pla... | 0 | Kotlin | 0 | 0 | 1cef7fe0f72f77a3a409915baac3c674cc058228 | 1,399 | aoc | Apache License 2.0 |
src/Day13.kt | mcrispim | 573,449,109 | false | {"Kotlin": 46488} | fun isInt(s: String): Boolean {
return try {
s.toInt()
true
} catch (e: NumberFormatException) {
false
}
}
fun isList(s: String) = s.startsWith('[') && s.endsWith(']')
fun unlist(list: String): MutableList<String> {
val elements = mutableListOf<String>()
var level = 0
v... | 0 | Kotlin | 0 | 0 | 5fcacc6316e1576a172a46ba5fc9f70bcb41f532 | 3,806 | AoC2022 | Apache License 2.0 |
src/main/kotlin/g0601_0700/s0691_stickers_to_spell_word/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0601_0700.s0691_stickers_to_spell_word
// #Hard #Array #String #Dynamic_Programming #Bit_Manipulation #Backtracking #Bitmask
// #2023_02_20_Time_249_ms_(100.00%)_Space_42.6_MB_(100.00%)
class Solution {
// count the characters of every sticker
private lateinit var counts: Array<IntArray>
// For ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,269 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/g0001_0100/s0016_3sum_closest/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0001_0100.s0016_3sum_closest
// #Medium #Array #Sorting #Two_Pointers #Level_2_Day_14_Sliding_Window/Two_Pointer
// #2023_07_03_Time_163_ms_(100.00%)_Space_37.5_MB_(92.24%)
class Solution {
fun threeSumClosest(nums: IntArray, target: Int): Int {
if (nums.size < 3) {
return 0
}... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,495 | LeetCode-in-Kotlin | MIT License |
year2023/src/main/kotlin/net/olegg/aoc/year2023/day19/Day19.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2023.day19
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.toPair
import net.olegg.aoc.year2023.DayOf2023
/**
* See [Year 2023, Day 19](https://adventofcode.com/2023/day/19)
*/
object Day19 : DayOf2023(19) {
override fun first(): Any? {
val (rulesBlock, partsBlock) = ... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 6,643 | adventofcode | MIT License |
src/Day02.kt | iownthegame | 573,926,504 | false | {"Kotlin": 68002} | enum class Shape {
PAPER, SCISSORS, STONE, INVALID
}
enum class Outcome {
WIN, DRAW, LOSE, INVALID
}
class Round(private val shapeOfOpponent: Shape, private var suggestedShape: Shape?, private var outcome: Outcome?) {
private val scoreOfShape = mapOf(
Shape.PAPER to 2,
Shape.SCISSORS to 3,
... | 0 | Kotlin | 0 | 0 | 4e3d0d698669b598c639ca504d43cf8a62e30b5c | 4,906 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/year2021/Day01.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2021
private fun part1(input: List<String>): Int {
val numbers = input.map { it.toInt() }
var count = 0
var previous = numbers[0]
for (number in numbers) {
if (number > previous) {
count++
}
previous = number
}
return count
}
private fun part2(i... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 1,049 | advent-of-code | MIT License |
src/net/sheltem/aoc/y2023/Day04.kt | jtheegarten | 572,901,679 | false | {"Kotlin": 178521} | package net.sheltem.aoc.y2023
import kotlin.math.pow
suspend fun main() {
Day04().run()
}
class Day04 : Day<Long>(13, 30) {
override suspend fun part1(input: List<String>): Long = input.indexWinners()
.sumOf { it.second.score() }
override suspend fun part2(input: List<String>): Long = input.ind... | 0 | Kotlin | 0 | 0 | ac280f156c284c23565fba5810483dd1cd8a931f | 1,598 | aoc | Apache License 2.0 |
src/day18/Parser.kt | g0dzill3r | 576,012,003 | false | {"Kotlin": 172121} | package day18
import readInput
import kotlin.math.absoluteValue
data class Dimensions (val min: Point, val max: Point) {
val cells: Int
get () {
val point = max.add (min.negate ()).add (Point (1, 1, 1))
val (x, y, z) = point
return x * y * z
}
fun contains (... | 0 | Kotlin | 0 | 0 | 6ec11a5120e4eb180ab6aff3463a2563400cc0c3 | 3,557 | advent_of_code_2022 | Apache License 2.0 |
src/Day01.kt | niltsiar | 572,887,970 | false | {"Kotlin": 16548} | fun main() {
fun part1(input: List<String>): Int {
return calculateCaloriesCarriedByElf(input)
.max()
}
fun part2(input: List<String>): Int {
return calculateCaloriesCarriedByElf(input)
.sortedDescending()
.take(3)
.sum()
}
// test if... | 0 | Kotlin | 0 | 0 | 766b3e168fc481e4039fc41a90de4283133d3dd5 | 884 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/filter.kt | knewjade | 382,342,162 | false | null | import common.tetfu.Tetfu
import common.tetfu.TetfuElement
import common.tetfu.TetfuPage
import common.tetfu.common.ColorConverter
import core.mino.MinoFactory
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
import java.io.PrintWriter
import java.util.*
import kotlin.math.pow
data class Lin... | 0 | Kotlin | 0 | 0 | ec7aeb05696abc2c59c4aa27033ea2bc35a5d6fe | 11,186 | path-filter | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2023/Day01.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2023
import se.saidaspen.aoc.util.*
fun main() = Day01.run()
object Day01 : Day(2023, 1) {
fun digits(input: String) = input.filter { it.isDigit() }.map { it.toString().toInt() }.toList()
override fun part1() = input.lines().sumOf { digits(it)[0] * 10 + digits(it)[digits(it).siz... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 904 | adventofkotlin | MIT License |
src/main/kotlin/g1301_1400/s1314_matrix_block_sum/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1301_1400.s1314_matrix_block_sum
// #Medium #Array #Matrix #Prefix_Sum #Dynamic_Programming_I_Day_14
// #2023_06_05_Time_235_ms_(100.00%)_Space_39_MB_(50.00%)
class Solution {
fun matrixBlockSum(mat: Array<IntArray>, k: Int): Array<IntArray> {
val rows = mat.size
val cols = mat[0].size
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,402 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/mantono/lingress/Spread.kt | mantono | 100,183,137 | false | null | package com.mantono.lingress
fun median(c: Collection<Number>): Double = c.asSequence().median()
fun mean(c: Collection<Number>): Double = c.map { it.toDouble() }.average()
fun range(c: Collection<Number>): Double = c.asSequence().range()
fun variance(c: Collection<Number>): Double = c.asSequence().variance()
fun stan... | 0 | Kotlin | 0 | 0 | 0c7cb0ff9b8feb946aea0d57538da8bd0423aada | 1,219 | linear-regression | MIT License |
LeetCode/Kotlin/src/main/kotlin/org/redquark/tutorials/leetcode/LetterCombinationsOfAPhoneNumber.kt | ani03sha | 297,402,125 | false | null | package org.redquark.tutorials.leetcode
fun letterCombinations(digits: String): List<String> {
// Resultant list
val combinations: MutableList<String> = mutableListOf()
// Base condition
if (digits.isEmpty()) {
return combinations
}
// Mappings of letters and numbers
val lettersAndN... | 2 | Java | 40 | 64 | 67b6ebaf56ec1878289f22a0324c28b077bcd59c | 1,516 | RedQuarkTutorials | MIT License |
src/Day17.kt | fasfsfgs | 573,562,215 | false | {"Kotlin": 52546} | const val CHAMBER_WIDTH = 7
fun main() {
fun part1(input: String): Int {
return simulateChamber(input, 2022)
}
fun part2(input: String): Int {
return input.length
}
val testInput = readInputAsString("Day17_test")
check(part1(testInput) == 3068)
// check(part2(testInput) == ... | 0 | Kotlin | 0 | 0 | 17cfd7ff4c1c48295021213e5a53cf09607b7144 | 4,155 | advent-of-code-2022 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions33.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
fun test33() {
printlnResult(5, 7, 6, 9, 11, 10, 8) // true
printlnResult(5, 7, 6, 11, 10, 8) // true
printlnResult(7, 4, 6, 5) // false
printlnResult(5, 6, 11, 10, 8) // true
printlnResult(5, 7, 6, 10, 8) // false
printlnResult(5, 6, 10, 8, 7) // true
}
... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,852 | Algorithm | Apache License 2.0 |
src/main/kotlin/io/github/ajoz/puzzles/Day03.kt | ajoz | 574,043,593 | false | {"Kotlin": 21275} | package io.github.ajoz.puzzles
import io.github.ajoz.utils.firstRepeatingCharFrom
import io.github.ajoz.utils.halfs
import io.github.ajoz.utils.readInput
/**
--- Day 3: Rucksack Reorganization ---
One Elf has the important job of loading all of the rucksacks with supplies for the jungle journey. Unfortunately, that
... | 0 | Kotlin | 0 | 0 | 6ccc37a4078325edbc4ac1faed81fab4427845b8 | 6,051 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/problems/day6/part2/part2.kt | klnusbaum | 733,782,662 | false | {"Kotlin": 43060} | package problems.day6.part2
import java.io.File
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.sqrt
private const val inputFile = "input/day6/input.txt"
//const val testFile = "input/day6/test.txt"
fun main() {
val numberOfBeats = File(inputFile).bufferedReader().useLines { multiplyNumBeats(... | 0 | Kotlin | 0 | 0 | d30db2441acfc5b12b52b4d56f6dee9247a6f3ed | 1,490 | aoc2023 | MIT License |
src/Day11.kt | vladislav-og | 573,326,483 | false | {"Kotlin": 27072} | fun main() {
fun extractNumbers(input: String): MutableList<String> {
val regex = Regex("\\d+")
return regex.findAll(input).map { c -> c.value }.toMutableList()
}
fun extractMonkeysInitialData(input: List<String>): Pair<HashMap<Int, HashMap<String, MutableList<String>>>, MutableList<Int>> {
val monk... | 0 | Kotlin | 0 | 0 | b230ebcb5705786af4c7867ef5f09ab2262297b6 | 4,064 | advent-of-code-2022 | Apache License 2.0 |
src/main/java/Exercise18.kt | cortinico | 317,667,457 | false | null | fun main() {
object {}
.javaClass
.getResource("input-18.txt")
.readText()
.split("\n")
.map { it.replace(" ", "") }
.sumOf { evaluate(it, 0) }
.also(::println)
}
fun evaluate(input: String, partial: Long): Long =
when {
input.isEmpty() -> partial... | 1 | Kotlin | 0 | 4 | a0d980a6253ec210433e2688cfc6df35104aa9df | 1,499 | adventofcode-2020 | MIT License |
src/main/kotlin/com/dkanen/graphmapnav/collections/graphs/Dijkstra.kt | prufrock | 662,847,778 | false | {"Kotlin": 284337} | package com.dkanen.graphmapnav.collections.graphs
import com.dkanen.graphmapnav.collections.queues.ComparatorPriorityQueueImpl
/**
* Finds the shortest paths from a given node.
*/
class Dijkstra<T: Any>(private val graph: AdjacencyList<T>) {
/**
* Follows route from the destination to the start.
*/
... | 0 | Kotlin | 0 | 1 | 55ebc6120b97a9c2c3d86b9d67c4cb97186a30f7 | 4,607 | graphmapnav | MIT License |
year2023/src/main/kotlin/net/olegg/aoc/year2023/day14/Day14.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2023.day14
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2023.DayOf2023
/**
* See [Year 2023, Day 14](https://adventofcode.com/2023/day/14)
*/
object Day14 : DayOf2023(14) {
override fun first(): Any? {
val shifted = matrix.transpose().shiftLeft()
return shifted.... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,862 | adventofcode | MIT License |
src/Day03.kt | buczebar | 572,864,830 | false | {"Kotlin": 39213} | fun main() {
fun Char.getPriority() =
(('a'..'z') + ('A'..'Z')).indexOf(this) + 1
fun part1(input: List<String>) =
input.map { sack -> sack.chunked(sack.length / 2).map { comp -> comp.toList() } }
.map { (comp1, comp2) -> (comp1 intersect comp2.toSet()).single() }
.sumOf... | 0 | Kotlin | 0 | 0 | cdb6fe3996ab8216e7a005e766490a2181cd4101 | 744 | advent-of-code | Apache License 2.0 |
src/main/kotlin/aoc19/Day12.kt | tahlers | 225,198,917 | false | null | package aoc19
import io.vavr.collection.HashSet
import io.vavr.collection.Stream
import io.vavr.collection.Vector
import java.util.Arrays
import kotlin.math.abs
object Day12 {
data class Vec(val x: Int, val y: Int, val z: Int) {
operator fun plus(other: Vec): Vec = Vec(x + other.x, y + other.y, z + other... | 0 | Kotlin | 0 | 0 | dae62345fca42dd9d62faadf78784d230b080c6f | 2,654 | advent-of-code-19 | MIT License |
src/main/kotlin/g1001_1100/s1092_shortest_common_supersequence/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1001_1100.s1092_shortest_common_supersequence
// #Hard #String #Dynamic_Programming #2023_06_02_Time_174_ms_(100.00%)_Space_37.9_MB_(100.00%)
class Solution {
fun shortestCommonSupersequence(str1: String, str2: String): String {
val m = str1.length
val n = str2.length
val dp = Arr... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,641 | LeetCode-in-Kotlin | MIT License |
dataStructuresAndAlgorithms/src/main/java/dev/funkymuse/datastructuresandalgorithms/search/BinarySearch.kt | FunkyMuse | 168,687,007 | false | {"Kotlin": 1728251} | package dev.funkymuse.datastructuresandalgorithms.search
/**
* Binary stringSearch, assumes that the list is sorted.
* Splits the list in half with every single iteration, bringing the worst case running time to O(log n)
*
* Time complexity per case:
* Best - O(1), constant. In case the element is in the ver... | 0 | Kotlin | 92 | 771 | e2afb0cc98c92c80ddf2ec1c073d7ae4ecfcb6e1 | 1,296 | KAHelpers | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[78]子集.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.util.*
import kotlin.collections.ArrayList
//给你一个整数数组 nums ,数组中的元素 互不相同 。返回该数组所有可能的子集(幂集)。
//
// 解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。
//
//
//
// 示例 1:
//
//
//输入:nums = [1,2,3]
//输出:[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
//
//
// 示例 2:
//
//
//输入:nums = [0]
//输出:[[],[0]]
//
//
//
//
// 提示:
//
//
/... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,630 | MyLeetCode | Apache License 2.0 |
08/kotlin/src/main/kotlin/se/nyquist/Decoder.kt | erinyq712 | 437,223,266 | false | {"Kotlin": 91638, "C#": 10293, "Emacs Lisp": 4331, "Java": 3068, "JavaScript": 2766, "Perl": 1098} | package se.nyquist
class Decoder {
private val validCombinations = Digit.values().map { it.representation }
private val value = "abcdefg"
private val valueArray : List<String> = IntRange(0, value.length-1).map{value.substring(it,it+1)}.toList()
private val permutations : List<List<String>> = allPermut... | 0 | Kotlin | 0 | 0 | b463e53f5cd503fe291df692618ef5a30673ac6f | 1,967 | adventofcode2021 | Apache License 2.0 |
src/main/kotlin/days/Day12.kt | jgrgt | 433,952,606 | false | {"Kotlin": 113705} | package days
import util.MutableTree
import util.MutableTree.MutableNode
class Day12 : Day(12) {
companion object {
/**
* Avoid 'lower case' nodes being used twice!
*/
fun paths(current: List<MutableNode<String>>, end: MutableNode<String>): List<List<MutableNode<String>>> {
... | 0 | Kotlin | 0 | 0 | 6231e2092314ece3f993d5acf862965ba67db44f | 3,540 | aoc2021 | Creative Commons Zero v1.0 Universal |
src/Day14.kt | kipwoker | 572,884,607 | false | null | import kotlin.math.max
import kotlin.math.min
enum class CaveCell {
Air,
Rock,
Sand
}
enum class SandFallResult {
Stuck,
Fall
}
val caveSize = 1000
fun main() {
class Cave(val map: Array<Array<CaveCell>>) {
fun getBounds(): Pair<Point, Point> {
var minX = caveSize
... | 0 | Kotlin | 0 | 0 | d8aeea88d1ab3dc4a07b2ff5b071df0715202af2 | 4,287 | aoc2022 | Apache License 2.0 |
src/main/kotlin/base/data/datas.kt | chlesaec | 544,431,960 | false | {"Kotlin": 68026} | package base.data
import base.vectors.RealVector
import base.vectors.Vector
import kotlin.math.exp
fun softMax(values : RealVector): Pair<Double, DoubleArray> {
val exponential = DoubleArray(values.size) {
exp(values[it])
}
val sum: Double = exponential.sum()
return Pair(sum, exponential)
}
f... | 0 | Kotlin | 0 | 0 | 0169f05a15164a56fc61d4e2d25314fdcc64f869 | 3,909 | Neurons | Apache License 2.0 |
src/main/kotlin/nov_challenge2021/UniquePathsIII.kt | yvelianyk | 405,919,452 | false | {"Kotlin": 147854, "Java": 610} | package nov_challenge2021
fun main() {
val grid1 = arrayOf(
intArrayOf(1, 0, 0, 0),
intArrayOf(0, 0, 0, 0),
intArrayOf(0, 0, 2, -1),
)
val res1 = UniquePathsIII().uniquePathsIII(grid1)
assert(res1 == 2)
val grid2 = arrayOf(
intArrayOf(0, 1),
intArrayOf(2, 0)... | 0 | Kotlin | 0 | 0 | 780d6597d0f29154b3c2fb7850a8b1b8c7ee4bcd | 1,931 | leetcode-kotlin | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem808/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem808
/**
* LeetCode page: [808. Soup Servings](https://leetcode.com/problems/soup-servings/);
*/
class Solution {
/* Complexity:
* Time O(1) and Space O(1) because the number of recursions is bounded by O(n0^2),
* where n0 is a constant much smaller than the upper b... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,231 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day11.kt | icoffiel | 572,651,851 | false | {"Kotlin": 29350} | private const val DAY = "Day11"
fun main() {
data class Test(val divisibleBy: Int, val throwToTrue: Int, val throwToFalse: Int)
data class Operation(val operand: String, val value: String) {
fun perform(itemValue: Long): Long {
val parsedValue: Long = when (value) {
"old" -> ... | 0 | Kotlin | 0 | 0 | 515f5681c385f22efab5c711dc983e24157fc84f | 5,419 | advent-of-code-2022 | Apache License 2.0 |
src/Day01.kt | frozbiz | 573,457,870 | false | {"Kotlin": 124645} | fun main() {
fun MutableList<Int>.insert_ordered(value: Int, max_position: Int) {
var ix = kotlin.math.min(this.size, max_position)
while (ix > 0 && value > this[ix-1]) {
ix--
}
if (ix < max_position) {
this.add(ix, value)
}
}
fun part2(input:... | 0 | Kotlin | 0 | 0 | 4feef3fa7cd5f3cea1957bed1d1ab5d1eb2bc388 | 1,625 | 2022-aoc-kotlin | Apache License 2.0 |
src/Day22.kt | schoi80 | 726,076,340 | false | {"Kotlin": 83778} | import java.util.PriorityQueue
import java.util.Stack
import kotlin.math.min
data class Brick(
val name: String,
val xRange: IntRange,
val yRange: IntRange,
var zRange: IntRange,
val supports: MutableList<Brick> = mutableListOf(),
val supportedBy: MutableList<Brick> = mutableListOf(),
var i... | 0 | Kotlin | 0 | 0 | ee9fb20d0ed2471496185b6f5f2ee665803b7393 | 3,722 | aoc-2023 | Apache License 2.0 |
src/main/kotlin/days/Day15.kt | vovarova | 572,952,098 | false | {"Kotlin": 103799} | package days
import days.Util.manhattanDistance
import util.Cell
import kotlin.math.abs
class Day15 : Day(15) {
class Sensor(val coordinates: Cell, val beacon: Cell) {
val beaconDistance: Int = manhattanDistance(coordinates, beacon)
fun distanceTo(cell: Cell): Int = manhattanDistance(coordinates... | 0 | Kotlin | 0 | 0 | e34e353c7733549146653341e4b1a5e9195fece6 | 4,008 | adventofcode_2022 | Creative Commons Zero v1.0 Universal |
day14/Kotlin/day14.kt | Ad0lphus | 353,610,043 | false | {"C++": 195638, "Python": 139359, "Kotlin": 80248} | import java.io.*
fun print_day_14() {
val yellow = "\u001B[33m"
val reset = "\u001b[0m"
val green = "\u001B[32m"
println(yellow + "-".repeat(25) + "Advent of Code - Day 14" + "-".repeat(25) + reset)
println(green)
val process = Runtime.getRuntime().exec("figlet Extended Polymerization -c -f smal... | 0 | C++ | 0 | 0 | 02f219ea278d85c7799d739294c664aa5a47719a | 2,797 | AOC2021 | Apache License 2.0 |
kts/aoc2016/aoc2016_15.kts | miknatr | 576,275,740 | false | {"Kotlin": 413403} | val input15 = """Disc #1 has 13 positions; at time=0, it is at position 1.
Disc #2 has 19 positions; at time=0, it is at position 10.
Disc #3 has 3 positions; at time=0, it is at position 2.
Disc #4 has 7 positions; at time=0, it is at position 1.
Disc #5 has 5 positions; at time=0, it is at position 3.
Disc #6 has 17 ... | 0 | Kotlin | 0 | 0 | 400038ce53ff46dc1ff72c92765ed4afdf860e52 | 1,315 | aoc-in-kotlin | Apache License 2.0 |
src/Day03.kt | zt64 | 572,594,597 | false | null | val priorities = (('a'..'z') + ('A'..'Z'))
.mapIndexed { index, char -> char to index + 1 }
.toMap()
fun main() {
val input = readInput("Day03")
fun part1(input: String): Int {
val rucksacks = input.lines()
val total = rucksacks.sumOf { rucksack ->
val middle = rucksack.le... | 0 | Kotlin | 0 | 0 | 4e4e7ed23d665b33eb10be59670b38d6a5af485d | 963 | aoc-2022 | Apache License 2.0 |
src/Day21.kt | catcutecat | 572,816,768 | false | {"Kotlin": 53001} | import kotlin.system.measureTimeMillis
fun main() {
measureTimeMillis {
Day21.run {
solve1(152L) // 309248622142100L
solve2(301L) // 3757272361782L
}
}.let { println("Total: $it ms") }
}
object Day21 : Day.LineInput<Day21.Monkeys, Long>("21") {
override fun parse(i... | 0 | Kotlin | 0 | 2 | fd771ff0fddeb9dcd1f04611559c7f87ac048721 | 3,149 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LargestDivisibleSubset.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 | 1,775 | kotlab | Apache License 2.0 |
src/Day01.kt | b0n541 | 571,797,079 | false | {"Kotlin": 17810} | fun main() {
fun sumCaloriesPerElf(input: List<String>): List<Int> {
var result = mutableListOf<Int>()
var currentElfCalories = 0
input.forEach { line ->
if (line.isNotEmpty()) {
currentElfCalories += line.toInt()
} else {
result.add(... | 0 | Kotlin | 0 | 0 | d451f1aee157fd4d47958dab8a0928a45beb10cf | 1,063 | advent-of-code-2022 | Apache License 2.0 |
src/day10/Day10.kt | armanaaquib | 572,849,507 | false | {"Kotlin": 34114} | package day10
import readInput
fun main() {
data class Instruction(val command: String, val value: Int? = null)
fun parseInput(input: List<String>) = input.map { line ->
val c = line.split(" ").filter { it.isNotEmpty() }
if(c[0] == "noop") {
Instruction(c[0])
} else {
... | 0 | Kotlin | 0 | 0 | 47c41ceddacb17e28bdbb9449bfde5881fa851b7 | 2,200 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/se/brainleech/adventofcode/aoc2020/Aoc2020Day03.kt | fwangel | 435,571,075 | false | {"Kotlin": 150622} | package se.brainleech.adventofcode.aoc2020
import se.brainleech.adventofcode.compute
import se.brainleech.adventofcode.readLines
import se.brainleech.adventofcode.verify
class Aoc2020Day03 {
companion object {
private const val TREE = '#'
private const val HIT = 'X'
private const val MISS... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 1,809 | adventofcode | MIT License |
y2017/src/main/kotlin/adventofcode/y2017/Day03.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2017
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Vec2
import adventofcode.util.vector.mooreNeighbors
import kotlin.math.roundToInt
import kotlin.math.sqrt
object Day03 : AdventSolution(2017, 3, "Spiral Memory") {
override fun solvePartOne(input: String) = toSpiralCo... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,824 | advent-of-code | MIT License |
hoon/HoonAlgorithm/src/main/kotlin/programmers/lv01/Lv1_12934_square.kt | boris920308 | 618,428,844 | false | {"Kotlin": 137657, "Swift": 35553, "Java": 1947, "Rich Text Format": 407} | package main.kotlin.programmers.lv01
import kotlin.math.pow
import kotlin.math.sqrt
/**
*
* https://school.programmers.co.kr/learn/courses/30/lessons/12934
*
* 문제 설명
* 임의의 양의 정수 n에 대해, n이 어떤 양의 정수 x의 제곱인지 아닌지 판단하려 합니다.
* n이 양의 정수 x의 제곱이라면 x+1의 제곱을 리턴하고, n이 양의 정수 x의 제곱이 아니라면 -1을 리턴하는 함수를 완성하세요.
*
* 제한 사항
* n... | 1 | Kotlin | 1 | 2 | 88814681f7ded76e8aa0fa7b85fe472769e760b4 | 1,291 | HoOne | Apache License 2.0 |
src/Day05.kt | Sagolbah | 573,032,320 | false | {"Kotlin": 14528} | import java.lang.StringBuilder
fun main() {
val cols = 9
data class Movement(val items: Int, val from: Int, val to: Int)
fun parse(line: String): List<Char?> {
val res = mutableListOf<Char?>()
for (i in line.indices step 4) {
res.add(if (line[i + 1].isWhitespace()) null else ... | 0 | Kotlin | 0 | 0 | 893c1797f3995c14e094b3baca66e23014e37d92 | 2,180 | advent-of-code-kt | Apache License 2.0 |
src/test/kotlin/nl/dirkgroot/adventofcode/year2022/Day09Test.kt | dirkgroot | 317,968,017 | false | {"Kotlin": 187862} | package nl.dirkgroot.adventofcode.year2022
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import nl.dirkgroot.adventofcode.util.input
import nl.dirkgroot.adventofcode.util.invokedWith
import kotlin.math.sign
private fun solution1(input: String) = doMotions(input, 2)
private fun solutio... | 1 | Kotlin | 1 | 1 | ffdffedc8659aa3deea3216d6a9a1fd4e02ec128 | 2,259 | adventofcode-kotlin | MIT License |
src/main/kotlin/days/Day14.kt | andilau | 429,557,457 | false | {"Kotlin": 103829} | package days
@AdventOfCodePuzzle(
name = "<NAME>",
url = "https://adventofcode.com/2015/day/14",
date = Date(day = 14, year = 2015)
)
class Day14(input: List<String>) : Puzzle {
private val reindeer = input.map(Reindeer::from)
internal var duration = 2503
override fun partOne(): Int = reindeer... | 0 | Kotlin | 0 | 0 | 55932fb63d6a13a1aa8c8df127593d38b760a34c | 2,276 | advent-of-code-2015 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/shtanko/algorithms/learn/Dijkstra.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <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 | 4,806 | kotlab | Apache License 2.0 |
src/Day14.kt | thomasreader | 573,047,664 | false | {"Kotlin": 59975} | import java.io.Reader
import java.util.SortedMap
import java.util.SortedSet
fun main() {
val testInput = """
498,4 -> 498,6 -> 496,6
503,4 -> 502,4 -> 502,9 -> 494,9
""".trimIndent()
val testRocks = parseInput(testInput.reader())
check(partOne(testRocks) == 24)
val input = reader... | 0 | Kotlin | 0 | 0 | eff121af4aa65f33e05eb5e65c97d2ee464d18a6 | 4,804 | advent-of-code-2022-kotlin | Apache License 2.0 |
2020/src/year2021/day13/code.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2021.day13
import util.readAllLines
import kotlin.math.max
data class Dot(val x: Int, val y: Int)
data class Fold(val x: Int, val y: Int)
fun main() {
val dots = mutableSetOf<Dot>()
val folds = mutableListOf<Fold>()
readAllLines("input.txt").forEach { line ->
if (line.startsWith("fol... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 1,744 | adventofcode | MIT License |
src/main/kotlin/de/tek/adventofcode/y2022/util/algorithms/SetAlgorithms.kt | Thumas | 576,671,911 | false | {"Kotlin": 192328} | package de.tek.adventofcode.y2022.util.algorithms
import de.tek.adventofcode.y2022.util.math.until
import java.math.BigInteger
/**
* Returns a list of all subsets of this set.
*/
fun <T> Set<T>.subsets(): List<Set<T>> {
val elements = this.toList()
val numberOfElements = elements.size
val result = muta... | 0 | Kotlin | 0 | 0 | 551069a21a45690c80c8d96bce3bb095b5982bf0 | 3,065 | advent-of-code-2022 | Apache License 2.0 |
src/day04/Day04.kt | palpfiction | 572,688,778 | false | {"Kotlin": 38770} | package day04
import readInput
fun main() {
fun expand(assignment: String) =
with(assignment.split("-")) {
(this.component1().toInt()..this.component2().toInt()).toSet()
}
fun part1(input: List<String>): Int =
input.map { it.split(",") }
.map { (first, second... | 0 | Kotlin | 0 | 0 | 5b79ec5fa4116e496cd07f0c7cea7dabc8a371e7 | 1,020 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/marcdenning/adventofcode/day16/Day16a.kt | marcdenning | 317,730,735 | false | {"Kotlin": 87536} | package com.marcdenning.adventofcode.day16
import java.io.File
import java.util.regex.Pattern
fun main(args: Array<String>) {
val inputLines = File(args[0]).readLines()
val separatorLineIndex = inputLines.indexOf("")
val rules = inputLines.subList(0, separatorLineIndex).map { line ->
parseRule(lin... | 0 | Kotlin | 0 | 0 | b227acb3876726e5eed3dcdbf6c73475cc86cbc1 | 1,435 | advent-of-code-2020 | MIT License |
src/main/kotlin/endredeak/aoc2022/Day17.kt | edeak | 571,891,076 | false | {"Kotlin": 44975} | package endredeak.aoc2022
import kotlin.math.absoluteValue
fun main() {
/**
* Ported Todd's solution: https://todd.ginsberg.com/post/advent-of-code/2022/day17/
*/
solve("Pyroclastic Flow") {
fun Char.asMove() =
when (this) {
'>' -> 1 to 0
'<' -> -1... | 0 | Kotlin | 0 | 0 | e0b95e35c98b15d2b479b28f8548d8c8ac457e3a | 3,451 | AdventOfCode2022 | Do What The F*ck You Want To Public License |
src/Day05.kt | dyomin-ea | 572,996,238 | false | {"Kotlin": 21309} | fun main() {
fun stacksFrom(input: List<String>): List<MutableList<Char>> =
(1..input.first().length step 4)
.map { c ->
input.map { it[c] }
.filterNot(Char::isWhitespace)
.reversed()
.toMutableList()
}
fun moves9000From(input: List<String>): List<Move9000> {
fun movesFrom(input: String)... | 0 | Kotlin | 0 | 0 | 8aaf3f063ce432207dee5f4ad4e597030cfded6d | 2,552 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/Triangle.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <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,931 | kotlab | Apache License 2.0 |
src/day14/Day14.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day14
import readInput
import java.awt.Point
import java.util.Stack
fun main() {
val rocksPositionSet = hashSetOf<Point>()
val sandPositionSet = hashSetOf<Point>()
var minX = Int.MAX_VALUE
var maxX = Int.MIN_VALUE
var maxY = Int.MIN_VALUE
fun resetGlobalStuff() {
rocksPosit... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 4,641 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/day10/Day10.kt | mortenberg80 | 574,042,993 | false | {"Kotlin": 50107} | package day10
class Day10(private val input: List<String>) {
private val commands = parseCommands(input)
private fun parseCommands(input: List<String>): List<Command> {
return input.flatMap { parseCommand(it) }
}
private fun parseCommand(input: String): List<Command> {
if (input ... | 0 | Kotlin | 0 | 0 | b21978e145dae120621e54403b14b81663f93cd8 | 4,752 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/VerifyPreorderInBinarySearchTree.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <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 | 2,268 | kotlab | Apache License 2.0 |
src/main/kotlin/cloud/dqn/leetcode/TrappingRainWaterKt.kt | aviuswen | 112,305,062 | false | null | package cloud.dqn.leetcode
/**
* https://leetcode.com/problems/trapping-rain-water/description/
Given n non-negative integers representing an elevation map where
the width of each bar is 1, compute how much water it is able to
trap after raining.
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], retu... | 0 | Kotlin | 0 | 0 | 23458b98104fa5d32efe811c3d2d4c1578b67f4b | 4,187 | cloud-dqn-leetcode | No Limit Public License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.