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/year2022/10/Day10.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2022.`10`
import readInput
sealed class Command {
object NOP : Command()
data class Addx(val amount: Int) : Command()
companion object {
fun from(string: String): Command {
val items = string.split(" ")
return when (items[0]) {
"addx" -> Addx(ite... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 2,920 | KotlinAdventOfCode | Apache License 2.0 |
src/main/java/com/booknara/problem/union/GraphValidTreeKt.kt | booknara | 226,968,158 | false | {"Java": 1128390, "Kotlin": 177761} | package com.booknara.problem.union
/**
* 261. Graph Valid Tree (Medium)
* https://leetcode.com/problems/graph-valid-tree/
*/
class GraphValidTreeKt {
// T:O(n), S:O(n)
fun validTree(n: Int, edges: Array<IntArray>): Boolean {
var edge = n - 1
val root = IntArray(n) {i -> i}
val rank = IntArray(n) { 1... | 0 | Java | 1 | 1 | 04dcf500ee9789cf10c488a25647f25359b37a53 | 1,018 | playground | MIT License |
LeetCode/0448. Find All Numbers Disappeared in an Array/Solution.kt | InnoFang | 86,413,001 | false | {"C++": 501928, "Kotlin": 291271, "Python": 280936, "Java": 78746, "Go": 43858, "JavaScript": 27490, "Rust": 6410} | class Solution {
fun findDisappearedNumbers(nums: IntArray): List<Int> {
var i = 0
while (i < nums.size) {
if (nums[i] != nums[nums[i] - 1]) {
swap(nums, i, nums[i] - 1)
--i
}
i++
}
return (1..nums.size).filter { num... | 0 | C++ | 8 | 20 | 2419a7d720bea1fd6ff3b75c38342a0ace18b205 | 953 | algo-set | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem953/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem953
/**
* LeetCode page: [953. Verifying an Alien Dictionary](https://leetcode.com/problems/verifying-an-alien-dictionary/);
*/
class Solution {
/* Complexity:
* Time O(M) and Space O(1) where M is the flat length of words;
*/
fun isAlienSorted(words: Array<Str... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,495 | hj-leetcode-kotlin | Apache License 2.0 |
codeforces/round633/b.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.round633
fun main() {
val n = readInt()
val nei = List(n) { mutableListOf<Int>() }
repeat(n - 1) {
val (u, v) = readInts().map { it - 1 }
nei[u].add(v); nei[v].add(u)
}
val mark = BooleanArray(n)
val dist = IntArray(n)
fun dfs(v: Int) {
mark[v] = true
for (u in nei[v]) if (!mark[u]) {... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 886 | competitions | The Unlicense |
2015/src/main/kotlin/day23.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.cut
import utils.mapItems
import kotlin.reflect.KMutableProperty1
fun main() {
Day23.run()
}
object Day23 : Solution<List<Day23.Insn>>() {
override val name = "day23"
override val parser = Parser.lines.mapItems { Insn.parse(it) }
enum class Opcode {
... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,531 | aoc_kotlin | MIT License |
src/main/kotlin/fr/pturpin/coursera/divconquer/QuickSort.kt | TurpIF | 159,055,822 | false | null | package fr.pturpin.coursera.divconquer
import java.util.*
class QuickSort(private val elements: IntArray) {
private val random = Random(42)
fun sortInPlace(): IntArray {
sortInPlace(0, elements.size)
return elements
}
private fun sortInPlace(from: Int, untilExcluded: Int) {
... | 0 | Kotlin | 0 | 0 | 86860f8214f9d4ced7e052e008b91a5232830ea0 | 2,149 | coursera-algo-toolbox | MIT License |
src/Day05.kt | BrianEstrada | 572,700,177 | false | {"Kotlin": 22757} | fun main() {
// Test Case
val testInput = readInput("Day05_test")
val part1TestResult = Day05.part1(testInput)
println(part1TestResult)
check(part1TestResult == "CMZ")
val part2TestResult = Day05.part2(testInput)
println(part2TestResult)
check(part2TestResult == "MCD")
// Actual C... | 1 | Kotlin | 0 | 1 | 032a4693aff514c9b30e979e63560dc48917411d | 4,331 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/exercises/mergetwosortedlists/MergeTwoSortedLists.kt | amykv | 538,632,477 | false | {"Kotlin": 169929} | package exercises.mergetwosortedlists
/*You are given the heads of two sorted linked lists list1 and list2.
Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.
Return the head of the merged linked list.
Example 1:
Input: list1 = [1,2,4], list2 = ... | 0 | Kotlin | 0 | 2 | 93365cddc95a2f5c8f2c136e5c18b438b38d915f | 3,240 | dsa-kotlin | MIT License |
src/day22/Day22.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day22
import readInput
import java.util.regex.Pattern
enum class Facing(val weight: Int) {
EAST(0) {
override fun delta(): Point = Point(1, 0)
override fun left(): Facing = NORTH
override fun right(): Facing = SOUTH
},
SOUTH(1) {
override fun delta(): Point ... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 7,165 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/pj/saari/map/Graph.kt | piizei | 202,340,455 | false | null | package pj.saari.map
import pj.saari.Island
import pj.saari.Tile
import pj.saari.TileCoord
import pj.saari.TileType
fun createMatrix(tiles: List<Tile>): Array<IntArray> {
fun getDimensions(tiles: List<Tile>): List<Int> {
var x = 0
var y = 0
tiles.forEach {
if (it.x > x) x = i... | 0 | Kotlin | 0 | 0 | befda8a460d27fe9d39bb7e7e5286e136bcf3c40 | 2,933 | saari | MIT License |
aoc-2021/src/main/kotlin/nerok/aoc/aoc2021/day02/Day02.kt | nerok | 572,862,875 | false | {"Kotlin": 113337} | package nerok.aoc.aoc2021.day02
import nerok.aoc.utils.Input
import kotlin.time.DurationUnit
import kotlin.time.measureTime
fun main() {
fun part1(input: List<String>): Long {
var depth = 0
var horizontal = 0
input.forEach {
val (command, value) = it.split(" ")
when... | 0 | Kotlin | 0 | 0 | 7553c28ac9053a70706c6af98b954fbdda6fb5d2 | 1,829 | AOC | Apache License 2.0 |
day14/src/main/kotlin/com/lillicoder/adventofcode2023/day14/Day14.kt | lillicoder | 731,776,788 | false | {"Kotlin": 98872} | package com.lillicoder.adventofcode2023.day14
import com.lillicoder.adventofcode2023.grids.Direction
import com.lillicoder.adventofcode2023.grids.Grid
import com.lillicoder.adventofcode2023.grids.GridParser
import com.lillicoder.adventofcode2023.grids.Node
fun main() {
val day14 = Day14()
val grid = GridParse... | 0 | Kotlin | 0 | 0 | 390f804a3da7e9d2e5747ef29299a6ad42c8d877 | 6,770 | advent-of-code-2023 | Apache License 2.0 |
year2021/day02/part2/src/main/kotlin/com/curtislb/adventofcode/year2021/day02/part2/Year2021Day02Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Part Two ---
Based on your calculations, the planned course doesn't seem to make any sense. You find the
submarine manual and discover that the process is actually slightly more complicated.
In addition to horizontal position and depth, you'll also need to track a third value, aim, which
also starts at 0. The ... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,667 | AdventOfCode | MIT License |
src/Day02.kt | ditn | 572,953,437 | false | {"Kotlin": 5079} | import java.lang.IllegalArgumentException
fun main() {
fun part1(input: List<String>): Int = input
.toRounds()
.sumOf { round ->
val outcomeComponent = round.toOutcome().score
val handComponent = round.second.score
outcomeComponent + handComponent
}
... | 0 | Kotlin | 0 | 0 | 4c9a286a911cd79d433075cda5ed01249ecb5994 | 2,753 | aoc2022 | Apache License 2.0 |
src/pl/shockah/aoc/y2015/Day21.kt | Shockah | 159,919,224 | false | null | package pl.shockah.aoc.y2015
import pl.shockah.aoc.AdventTask
import kotlin.math.max
class Day21: AdventTask<Day21.Stats, Int, Int>(2015, 21) {
private val playerHealth = 100
data class Stats(
val health: Int,
val damage: Int,
val armor: Int
) {
constructor(
health: Int,
equipment: Set<Item>
): th... | 0 | Kotlin | 0 | 0 | 9abb1e3db1cad329cfe1e3d6deae2d6b7456c785 | 4,856 | Advent-of-Code | Apache License 2.0 |
src/Day02.kt | DevHexs | 573,262,501 | false | {"Kotlin": 11452} | fun main(){
fun part1(): Int {
var pointsPlayer1 = 0
var pointsPlayer2 = 0
// A | X = Rock, B | Y = Paper, C | Z = Scissors
val pointSelection = mapOf(
"A" to 1,
"B" to 2,
"C" to 3,
"X" to 1,
"Y" to 2,
"Z" to ... | 0 | Kotlin | 0 | 0 | df0ff2ed7c1ebde9327cd1a102499ac5467b73be | 3,354 | AdventOfCode-2022-Kotlin | Apache License 2.0 |
src/main/kotlin/days/Geometry.kt | andilau | 726,429,411 | false | {"Kotlin": 37060} | package days
import kotlin.math.absoluteValue
import kotlin.math.sign
data class Point(val x: Int, val y: Int) {
val north: Point get() = this.copy(y = y - 1)
val northwest: Point get() = this + Point(-1, -1)
val northeast: Point get() = this + Point(1, -1)
val south: Point get() = this + Point(0, 1)... | 3 | Kotlin | 0 | 0 | 9a1f13a9815ab42d7fd1d9e6048085038d26da90 | 3,026 | advent-of-code-2023 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/Puzzle17.kt | namyxc | 317,466,668 | false | null | object Puzzle17 {
@JvmStatic
fun main(args: Array<String>) {
val input = Puzzle17::class.java.getResource("puzzle17.txt").readText()
val calculatedActiveCountIn3D = calculateActiveCountIn3D(input)
println(calculatedActiveCountIn3D)
val calculatedActiveCountIn4D = calculateActive... | 0 | Kotlin | 0 | 0 | 60fa6991ac204de6a756456406e1f87c3784f0af | 6,867 | adventOfCode2020 | MIT License |
src/main/kotlin/dev/siller/aoc2022/Day04.kt | chearius | 575,352,798 | false | {"Kotlin": 41999} | package dev.siller.aoc2022
private val example = """
2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8
""".trimIndent()
private fun part1(input: List<String>): Int = getRanges(input)
.count { (r1, r2) ->
r1.first <= r2.first && r1.last >= r2.last || r2.first <= r1.first && r2.last >=... | 0 | Kotlin | 0 | 0 | e070c0254a658e36566cc9389831b60d9e811cc5 | 1,040 | advent-of-code-2022 | MIT License |
src/Day06.kt | AndreiShilov | 572,661,317 | false | {"Kotlin": 25181} | import java.io.File
import java.util.Stack
fun main() {
fun solve(input: String, msgSize: Int): Int {
var marker = 0
val windowed = input.toCharArray().toList().asSequence().windowed(msgSize)
for (window in windowed) {
marker++
if (window.toSet().size == msgSize) br... | 0 | Kotlin | 0 | 0 | 852b38ab236ddf0b40a531f7e0cdb402450ffb9a | 1,202 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | petoS6 | 573,018,212 | false | {"Kotlin": 14258} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { it.split(" ").let { Game(it[0], it[1]) }.score1 }
}
fun part2(input: List<String>): Int {
return input.sumOf { it.split(" ").let { Game(it[0], it[1]) }.score2 }
}
val testInput = readInput("Day02.txt")
println(part1(testInput)... | 0 | Kotlin | 0 | 0 | 40bd094155e664a89892400aaf8ba8505fdd1986 | 1,521 | kotlin-aoc-2022 | Apache License 2.0 |
src/main/kotlin/advent/of/code/day12/Solution.kt | brunorene | 160,263,437 | false | null | package advent.of.code.day12
import java.io.File
// STILL WRONG :(
data class PlantsInPots(val data: MutableSet<Long> = mutableSetOf()) {
companion object {
fun build(init: String): PlantsInPots {
val instance = PlantsInPots()
init.forEachIndexed { index, c -> instance[index.toLo... | 0 | Kotlin | 0 | 0 | 0cb6814b91038a1ab99c276a33bf248157a88939 | 2,434 | advent_of_code_2018 | The Unlicense |
kotlin/graphs/flows/MaxFlowDinic.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package graphs.flows
import java.util.stream.Stream
// https://en.wikipedia.org/wiki/Dinic%27s_algorithm in O(V^2 * E)
class MaxFlowDinic(nodes: Int) {
var graph: Array<List<Edge>>
var dist: IntArray
inner class Edge(var t: Int, var rev: Int, var cap: Int) {
var f = 0
}
fun addBidiEdge(s... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 2,558 | codelibrary | The Unlicense |
solutions/src/SmallestStringFromLeaf.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | import kotlin.math.min
//https://leetcode.com/problems/smallest-string-starting-from-leaf/
/**
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree node.
* class TreeNode(var `val`: Int) {
* var left: TreeNode? = null
* var right: TreeNode? = null
* }
*/
class SmallestS... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 1,399 | leetcode-solutions | MIT License |
src/Day10.kt | JohannesPtaszyk | 573,129,811 | false | {"Kotlin": 20483} | fun main() {
fun getCycles(input: List<String>) = input.flatMap {
val instruction = it.split(" ")
if (instruction.first() == "noop") {
listOf(null)
} else {
listOf(null, instruction[1].toInt())
}
}
fun part1(input: List<String>): Int {
var x ... | 0 | Kotlin | 0 | 1 | 6f6209cacaf93230bfb55df5d91cf92305e8cd26 | 1,770 | advent-of-code-2022 | Apache License 2.0 |
src/Day20.kt | greg-burgoon | 573,074,283 | false | {"Kotlin": 120556} | fun main() {
data class Node(val value: Long, var visited: Boolean, var leftNode: Node? = null, var rightNode: Node? = null) {
fun printLeft(): String {
var trackNode = leftNode
var s = this.value.toString() + ", "
while (trackNode != this) {
s = s + track... | 0 | Kotlin | 0 | 1 | 74f10b93d3bad72fa0fc276b503bfa9f01ac0e35 | 4,228 | aoc-kotlin | Apache License 2.0 |
src/Day02.kt | casslabath | 573,177,204 | false | {"Kotlin": 27085} | fun main() {
/**
* Rock = A or X 1pt
* Paper = B or Y 2pt
* Scissors = C or Z 3pt
*
* AX beats CZ
* BY beats AX
* CZ beats BY
*/
val leftResults = listOf("A","B","C")
val rightResults = listOf("X","Y","Z")
fun calculateWinningPoints(leftIndex: Int, ... | 0 | Kotlin | 0 | 0 | 5f7305e45f41a6893b6e12c8d92db7607723425e | 1,935 | KotlinAdvent2022 | Apache License 2.0 |
src/main/kotlin/io/queue/FindNearestZero.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.queue
import java.util.*
//https://leetcode.com/explore/learn/card/queue-stack/239/conclusion/1388/
class FindNearestZero {
private val defaultValue = Int.MAX_VALUE
fun execute(input: Array<IntArray>): Array<IntArray> = Array(input.size) { IntArray(input[0].size) }.apply {
for (row in this) Array... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 3,129 | coding | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year19/Day20.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year19
import com.grappenmaker.aoc.*
import com.grappenmaker.aoc.Direction.*
fun PuzzleSet.day20() = puzzle(day = 20) {
val grid = inputLines.asCharGrid()
val valid = grid.findPointsValued('.').toSet()
data class Portal(val name: String, val at: Point)
val portals = with... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,932 | advent-of-code | The Unlicense |
2021/src/main/kotlin/com/trikzon/aoc2021/Day7.kt | Trikzon | 317,622,840 | false | {"Kotlin": 43720, "Rust": 21648, "C#": 12576, "C++": 4114, "CMake": 397} | package com.trikzon.aoc2021
import kotlin.math.absoluteValue
fun main() {
val input = getInputStringFromFile("/day7.txt")
benchmark(Part.One, ::day7Part1, input, 328262, 5000)
benchmark(Part.Two, ::day7Part2, input, 90040997, 500)
}
fun day7Part1(input: String): Int {
val horizPositions = input.split... | 0 | Kotlin | 1 | 0 | d4dea9f0c1b56dc698b716bb03fc2ad62619ca08 | 1,184 | advent-of-code | MIT License |
src/Day14.kt | Aldas25 | 572,846,570 | false | {"Kotlin": 106964} | fun main() {
fun dropSand(grid: Array<Array<Boolean>>): Pair<Int, Int> {
var x = 500
var y = 0
while (true) {
if (y >= 1000-1) break
if (!grid[x][y+1])
y++
else if (!grid[x-1][y+1]) {
x--
y++
}... | 0 | Kotlin | 0 | 0 | 80785e323369b204c1057f49f5162b8017adb55a | 3,040 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/kotlin/io/array/KthLargestElementInArray.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.array
import io.utils.runTests
// https://leetcode.com/problems/kth-largest-element-in-an-array/
class KthLargestElementInArray {
// https://leetcode.com/problems/kth-largest-element-in-an-array/discuss/60312/AC-Clean-QuickSelect-Java-solution-avg.-O(n)-time
fun execute(input: IntArray,
... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,431 | coding | MIT License |
src/main/kotlin/y2022/day10/Day10.kt | TimWestmark | 571,510,211 | false | {"Kotlin": 97942, "Shell": 1067} | package y2022.day10
import kotlin.math.abs
fun main() {
AoCGenerics.printAndMeasureResults(
part1 = { part1() },
part2 = { part2() }
)
}
fun input(): List<String> {
return AoCGenerics.getInputLines("/y2022/day10/input.txt")
}
fun getCycleValues(commands: List<String>): Map<Int, Int> {
... | 0 | Kotlin | 0 | 0 | 23b3edf887e31bef5eed3f00c1826261b9a4bd30 | 2,063 | AdventOfCode | MIT License |
src/main/kotlin/days/Day8.kt | andilau | 544,512,578 | false | {"Kotlin": 29165} | package days
import java.lang.IllegalArgumentException
@AdventOfCodePuzzle(
name = "Two-Factor Authentication",
url = "https://adventofcode.com/2016/day/8",
date = Date(day = 8, year = 2016)
)
class Day8(private val input: List<String>) : Puzzle {
override fun partOne(): Int = with(Display(50, 6)) {
... | 3 | Kotlin | 0 | 0 | b2a836bd3f1c5eaec32b89a6ab5fcccc91b665dc | 2,947 | advent-of-code-2016 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/ginsberg/advent2020/Day13.kt | tginsberg | 315,060,137 | false | null | /*
* Copyright (c) 2020 by <NAME>
*/
/**
* Advent of Code 2020, Day 13 - Shuttle Search
* Problem Description: http://adventofcode.com/2020/day/13
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2020/day13/
*/
package com.ginsberg.advent2020
class Day13(input: List<String>) {
private ... | 0 | Kotlin | 2 | 38 | 75766e961f3c18c5e392b4c32bc9a935c3e6862b | 1,425 | advent-2020-kotlin | Apache License 2.0 |
src/main/java/com/ncorti/aoc2021/Exercise17.kt | cortinico | 433,486,684 | false | {"Kotlin": 36975} | package com.ncorti.aoc2021
import kotlin.math.abs
import kotlin.math.max
object Exercise17 {
private fun getInput() =
getInputAsTest("17") {
removePrefix("target area: x=").split(", y=").flatMap {
it.split("..").map(String::toInt)
}
}
private val steps... | 0 | Kotlin | 0 | 4 | af3df72d31b74857201c85f923a96f563c450996 | 2,972 | adventofcode-2021 | MIT License |
src/Day10.kt | calindumitru | 574,154,951 | false | {"Kotlin": 20625} | import java.util.*
fun main() {
val part1 = Implementation("Find the signal strength during the 20th, 60th, 100th, 140th, 180th, and 220th cycles. What is the sum of these six signal strengths?",
13140) { lines ->
val instructions = mapInstructions(lines)
val process = Process(instructions)... | 0 | Kotlin | 0 | 0 | d3cd7ff5badd1dca2fe4db293da33856832e7e83 | 2,964 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/katas/kotlin/skiena/graphs/Graph.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.skiena.graphs
import katas.kotlin.skiena.graphs.UnweightedGraphs.meshGraph
import katas.kotlin.skiena.graphs.UnweightedGraphs.diamondGraph
import nonstdlib.join
import datsok.shouldEqual
import org.junit.Test
data class Edge<T>(val from: T, val to: T, val weight: Int? = null) {
override fun t... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 4,241 | katas | The Unlicense |
src/main/kotlin/days/Day3Solution.kt | yigitozgumus | 434,108,608 | false | {"Kotlin": 17835} | package days
import BaseSolution
import java.io.File
import kotlin.math.ceil
const val zeroCode = '0'.code
class Day3Solution(inputList: List<String>) : BaseSolution(inputList) {
val formattedInput by lazy { inputList.map { it.toCharArray().map { it.code - zeroCode } } }
private fun List<Boolean>.mapToRate... | 0 | Kotlin | 0 | 0 | c0f6fc83fd4dac8f24dbd0d581563daf88fe166a | 1,916 | AdventOfCode2021 | MIT License |
src/questions/MinLengthAfterDeletingSimilarEnds.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
/**
* Given a string s consisting only of characters 'a', 'b', and 'c'.
* You are asked to apply the following algorithm on the string any number of times:
*
* * Pick a non-empty prefix from the string s where all the characters in th... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 3,230 | algorithms | MIT License |
src/Day01.kt | MwBoesgaard | 572,857,083 | false | {"Kotlin": 40623} | fun main() {
fun part1(input: List<String>): Int {
var totalKcal = 0
var highestKcal = 0
for (kcal in input) {
if (kcal == "") {
if (totalKcal > highestKcal) {
highestKcal = totalKcal
}
totalKcal = 0
... | 0 | Kotlin | 0 | 0 | 3bfa51af6e5e2095600bdea74b4b7eba68dc5f83 | 910 | advent_of_code_2022 | Apache License 2.0 |
src/main/kotlin/aoc2022/Day14.kt | lukellmann | 574,273,843 | false | {"Kotlin": 175166} | package aoc2022
import AoCDay
// https://adventofcode.com/2022/day/14
object Day14 : AoCDay<Int>(
title = "Regolith Reservoir",
part1ExampleAnswer = 24,
part1Answer = 817,
part2ExampleAnswer = 93,
part2Answer = 23416,
) {
private data class Point(val x: Int, val y: Int)
private val SAND_S... | 0 | Kotlin | 0 | 1 | 344c3d97896575393022c17e216afe86685a9344 | 3,167 | advent-of-code-kotlin | MIT License |
y2016/src/main/kotlin/adventofcode/y2016/Day04.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2016
import adventofcode.io.AdventSolution
object Day04 : AdventSolution(2016, 4, "Security Through Obscurity") {
override fun solvePartOne(input: String) = parseRooms(input)
.sumOf { it.id }
.toString()
override fun solvePartTwo(input: String) = parseRooms(input... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,600 | advent-of-code | MIT License |
src/main/kotlin/tr/emreone/adventofcode/days/Day05.kt | EmRe-One | 726,902,443 | false | {"Kotlin": 95869, "Python": 18319} | package tr.emreone.adventofcode.days
import tr.emreone.kotlin_utils.Logger.logger
import tr.emreone.kotlin_utils.automation.Day
class Day05 : Day(5, 2023, "If You Give A Seed A Fertilizer") {
class Process {
private var steps =
arrayOf("seed", "soil", "fertilizer", "water", "light", "temperat... | 0 | Kotlin | 0 | 0 | c75d17635baffea50b6401dc653cc24f5c594a2b | 4,342 | advent-of-code-2023 | Apache License 2.0 |
src/day-4.kt | drademacher | 160,820,401 | false | null | import java.io.File
import java.time.LocalDateTime
fun main(args: Array<String>) {
println("part 1: " + partOne())
println("part 2: " + partTwo())
}
private fun partOne(): Int {
val rawFile = File("res/day-4.txt").readText()
val datetimeAndActions = rawFile
.split("\n")
.filter... | 0 | Kotlin | 0 | 0 | a7f04450406a08a5d9320271148e0ae226f34ac3 | 3,041 | advent-of-code-2018 | MIT License |
src/Day03.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | import java.lang.Exception
fun main() {
fun findCommonItem(sack: String): Char {
val midPoint = sack.length/2
for (itemIndex in IntRange(0, midPoint-1)) {
var item = sack[itemIndex]
if (item in sack.slice(IntRange(midPoint, sack.length - 1))) {
return item
... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 1,645 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/org/hydev/lcci/lcci_03.kt | VergeDX | 334,298,924 | false | null | import java.util.*
import kotlin.collections.ArrayList
// https://leetcode-cn.com/problems/three-in-one-lcci/
class TripleInOne(val stackSize: Int) {
val stackOne = Stack<Int>()
val stackTwo = Stack<Int>()
val stackThree = Stack<Int>()
private fun whichStack(stackNum: Int): Stack<Int> {
return... | 0 | Kotlin | 0 | 0 | 9a26ac2e24b0a0bdf4ec5c491523fe9721c6c406 | 4,863 | LeetCode_Practice | MIT License |
src/Day02.kt | ChristianNavolskyi | 573,154,881 | false | {"Kotlin": 29804} | import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
@ExperimentalTime
fun main() {
val pointMap: Map<String, Int> = mapOf(
Pair("A X", 4),
Pair("A Y", 8),
Pair("A Z", 3),
Pair("B X", 1),
Pair("B Y", 5),
Pair("B Z", 9),
Pair("C X", 7),
P... | 0 | Kotlin | 0 | 0 | 222e25771039bdc5b447bf90583214bf26ced417 | 1,333 | advent-of-code-2022 | Apache License 2.0 |
src/Day14.kt | ambrosil | 572,667,754 | false | {"Kotlin": 70967} | import Type.*
enum class Type { NONE, SAND, WALL }
fun main() {
fun parse(input: List<String>): MutableMap<Point, Type> {
val terrain = mutableMapOf<Point, Type>()
val walls = input.map { it.split(" -> ")
.map { it.split(",") }
.map { (x, y) -> Point(x.toInt(), y.... | 0 | Kotlin | 0 | 0 | ebaacfc65877bb5387ba6b43e748898c15b1b80a | 4,130 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | leeturner | 572,659,397 | false | {"Kotlin": 13839} | fun priority(c: Char) = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(c) + 1
fun main() {
fun part1(rucksacks: List<String>) =
rucksacks
.map { it.chunked(it.length / 2) }
.map { it[0].toSet() intersect it[1].toSet() }
.sumOf { priority(it.first()) }
fun part2(... | 0 | Kotlin | 0 | 0 | 8da94b6a0de98c984b2302b2565e696257fbb464 | 771 | advent-of-code-2022 | Apache License 2.0 |
src/Day16.kt | max-zhilin | 573,066,300 | false | {"Kotlin": 114003} | import java.util.*
val solutions = mutableMapOf<Int, Int>()
data class Link(val valve: Valve, val dist: Int)
data class Valve(val name: String, val rate: Int, var opened: Boolean = false, var lastRateA: Int = -1, var lastRateB: Int = -1) {
lateinit var names: List<String>
val links: MutableList<Link> = mutabl... | 0 | Kotlin | 0 | 0 | d9dd7a33b404dc0d43576dfddbc9d066036f7326 | 14,175 | AoC-2022 | Apache License 2.0 |
src/intervals/Interval.kt | hopshackle | 225,904,074 | false | null | package intervals
import java.lang.AssertionError
import kotlin.random.Random
import kotlin.reflect.KFunction
interface Interval {
fun sampleFrom(): Number
fun sampleFrom(rnd: Random): Number
fun sampleGrid(n: Int): List<Number>
}
fun interval(from: Number, to: Number): Interval {
return when (from) ... | 0 | Kotlin | 0 | 0 | e5992d6b535b3f4a6552bf6f2351865a33d56248 | 4,037 | SmarterSims | MIT License |
src/Day01.kt | matusekma | 572,617,724 | false | {"Kotlin": 119912, "JavaScript": 2024} | class Day01 {
fun part1MostCalories(input: List<String>): Int {
var max = 0
var current = 0
for (calorie in input) {
if (calorie == "") {
if (current > max) {
max = current
}
current = 0
} else {
... | 0 | Kotlin | 0 | 0 | 744392a4d262112fe2d7819ffb6d5bde70b6d16a | 1,307 | advent-of-code | Apache License 2.0 |
src/day03/Day03.kt | pnavais | 727,416,570 | false | {"Kotlin": 17859} | package day03
import readInput
class EngineSchematic {
val rows: MutableList<List<Char>> = mutableListOf()
}
private fun readMatrix(input: List<String>) : EngineSchematic {
val engineSchematic = EngineSchematic()
input.forEach { s ->
engineSchematic.rows.add(s.toList())
}
return engineS... | 0 | Kotlin | 0 | 0 | f5b1f7ac50d5c0c896d00af83e94a423e984a6b1 | 3,931 | advent-of-code-2k3 | Apache License 2.0 |
src/main/kotlin/com/github/shmvanhouten/adventofcode/day13/Maze.kt | SHMvanHouten | 109,886,692 | false | {"Kotlin": 616528} | package com.github.shmvanhouten.adventofcode.day13
import com.github.shmvanhouten.adventofcode.day13.MazeComponent.*
import com.github.shmvanhouten.adventofcode.day22gridcomputing.Coordinate
class Maze(val height: Int = 50, val width: Int = 50) {
private var mazeGrid: Map<Int, Map<Int, MazeComponent>> = initiali... | 0 | Kotlin | 0 | 0 | a8abc74816edf7cd63aae81cb856feb776452786 | 2,316 | adventOfCode2016 | MIT License |
src/Day09.kt | felldo | 572,233,925 | false | {"Kotlin": 76496} | fun main() {
data class Position(var x: Int, var y: Int)
fun moveHead(head: Position, direction: String) {
when (direction) {
"U" -> head.y++
"D" -> head.y--
"L" -> head.x--
"R" -> head.x++
}
}
fun moveKnot(head: Position, tail: Position):... | 0 | Kotlin | 0 | 0 | 0ef7ac4f160f484106b19632cd87ee7594cf3d38 | 2,856 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day10.kt | MartinsCode | 572,817,581 | false | {"Kotlin": 77324} | class Machine {
private var cycle = 0
private var strength = 1
var addedSignal = 0
var display = mutableListOf("........................................",
"........................................",
"........................................",
"....................................... | 0 | Kotlin | 0 | 0 | 1aedb69d80ae13553b913635fbf1df49c5ad58bd | 2,524 | AoC-2022-12-01 | Apache License 2.0 |
src/main/kotlin/year2023/Day08.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2023
import utils.lcm
class Day08 {
fun part1(input: String) = solve(input, { it == "AAA" }, { it == "ZZZ" })
fun part2(input: String) = solve(input, { it.endsWith('A') }, { it.endsWith('Z') })
data class Node(val left: String, val right: String, val terminal: Boolean)
fun solve(input: ... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 1,173 | aoc-2022 | Apache License 2.0 |
src/Day01.kt | brunojensen | 572,665,994 | false | {"Kotlin": 13161} | import java.util.PriorityQueue
import kotlin.math.max
private fun PriorityQueue<Int>.offerAndPollIfMaxSize(input: Int, maxSizw: Int) {
this.offer(input)
if (this.size > maxSizw) {
this.poll()
}
}
fun main() {
fun part1(input: List<String>): Int {
var sum = 0
var max = 0
for (i in input) {
... | 0 | Kotlin | 0 | 0 | 2707e76f5abd96c9d59c782e7122427fc6fdaad1 | 1,063 | advent-of-code-kotlin-1 | Apache License 2.0 |
src/main/kotlin/g1701_1800/s1782_count_pairs_of_nodes/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1701_1800.s1782_count_pairs_of_nodes
// #Hard #Binary_Search #Two_Pointers #Graph
// #2023_06_18_Time_1441_ms_(100.00%)_Space_116_MB_(100.00%)
class Solution {
fun countPairs(n: Int, edges: Array<IntArray>, queries: IntArray): IntArray {
val edgeCount: MutableMap<Int, Int> = HashMap()
val... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,672 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/colinodell/advent2021/Day22.kt | colinodell | 433,864,377 | true | {"Kotlin": 111114} | package com.colinodell.advent2021
class Day22(input: List<String>) {
private val initializationProcedureRegion = Cuboid(Vector3(-50, -50, -50), Vector3(50, 50, 50))
private val procedure = parseInput(input)
private val initializationProcedure = procedure.mapKeys { it.key.intersect(initializationProcedureR... | 0 | Kotlin | 0 | 1 | a1e04207c53adfcc194c85894765195bf147be7a | 1,808 | advent-2021 | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year21/Day23.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year21
import com.grappenmaker.aoc.*
import com.grappenmaker.aoc.Direction.*
import java.util.*
fun PuzzleSet.day23() = puzzle(day = 23) {
fun List<String>.parse() = map { it.padEnd(inputLines.first().length, ' ') }.asCharGrid()
fun solve(grid: Grid<Char>): String {
fun P... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 5,925 | advent-of-code | The Unlicense |
src/main/kotlin/se/saidaspen/aoc/aoc2016/Day21.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2016
import se.saidaspen.aoc.util.Day
import se.saidaspen.aoc.util.e
import se.saidaspen.aoc.util.ints
import se.saidaspen.aoc.util.permutations
import java.lang.RuntimeException
import kotlin.math.absoluteValue
fun main() = Day21.run()
object Day21 : Day(2016, 21) {
override fun par... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 3,021 | adventofkotlin | MIT License |
src/Day06.kt | cornz | 572,867,092 | false | {"Kotlin": 35639} | fun main() {
fun getSequence(input: String, lengthOfMarker: Int): String {
// mjqjpqmgbljsphdztnvjfqwrcgsmlb
val arr = input.toCharArray().map { c -> c.code }
val windows = arr.windowed(size = lengthOfMarker, step = 1)
for (window in windows) {
if (window.size == window.t... | 0 | Kotlin | 0 | 0 | 2800416ddccabc45ba8940fbff998ec777168551 | 1,221 | aoc2022 | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/swype_lock/SwypeLock.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.swype_lock
import datsok.*
import org.junit.*
import kotlin.math.*
/**
* By <NAME>.
*/
class SwypeLock {
@Test fun `some examples`() {
// 1 2 3
// 4 5 6
// 7 8 9
validate(emptyList()) shouldEqual false
validate((1..10).toList()) shouldEqual ... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,658 | katas | The Unlicense |
src/main/kotlin/day24/part2/Part2.kt | bagguley | 329,976,670 | false | null | package day24.part2
import day24.data
import day24.testData
var x: Int = 0
var y: Int = 0
var hexMap = mutableMapOf<String, String>()
var nextMap = mutableMapOf<String, String>()
fun main() {
load(data)
}
fun load(input: List<String>) {
for (line in input) {
x = 0
y = 0
val t = Rege... | 0 | Kotlin | 0 | 0 | 6afa1b890924e9459f37c604b4b67a8f2e95c6f2 | 3,046 | adventofcode2020 | MIT License |
src/main/kotlin/com/chriswk/aoc/advent2018/Day11.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2018
object Day11 {
fun part1(squareSize: Int, gridSerial: Int): Cell {
return (1..squareSize - 3).flatMap { y ->
(1..squareSize - 3).map { x ->
val cell = Cell(x, y)
Pair(cell, squarePower(cell, gridSerial, 3))
}
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 1,535 | adventofcode | MIT License |
src/main/kotlin/problems/Day16.kt | PedroDiogo | 432,836,814 | false | {"Kotlin": 128203} | package problems
class Day16(override val input: String) : Problem {
override val number: Int = 16
private val packets = BITS.fromString(input).packets
override fun runPartOne(): String {
return packets
.first()
.packetVersion()
.toString()
}
override f... | 0 | Kotlin | 0 | 0 | 93363faee195d5ef90344a4fb74646d2d26176de | 5,872 | AdventOfCode2021 | MIT License |
2017-kotlin/src/main/kotlin/com/morninghacks/aoc2017/Day02.kt | whaley | 116,508,747 | false | null | package com.morninghacks.aoc2017
import kotlin.math.abs
/*
Part One:
The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's checksum. For each row, determine the difference between the largest value and the ... | 0 | Kotlin | 0 | 0 | 16ce3c9d6310b5faec06ff580bccabc7270c53a8 | 3,788 | advent-of-code | MIT License |
src/Day05.kt | buongarzoni | 572,991,996 | false | {"Kotlin": 26251} | fun solveDay05() {
val input = readInput("Day05")
println(makeHardcodedMap())
solvePart1(input)
solvePart2(input)
}
private fun solvePart1(input: List<String>) {
val hardcodedMap = makeHardcodedMap()
input.map { line ->
val strings = line.split(" ")
val quantity = strings[1].toI... | 0 | Kotlin | 0 | 0 | 96aadef37d79bcd9880dbc540e36984fb0f83ce0 | 2,268 | AoC-2022 | Apache License 2.0 |
Lab 1/lab1_3/src/main/kotlin/part1/main.kt | katlaang | 461,564,362 | false | null | fun main(args: Array<String>) {
println("Hello World...!")
val num = 256656
val a:IntArray = intArrayOf(1,3,5,8,6,4,9)//1+9+81+25
println(firstDigit(num))
println(lastDigit(num))
println(SumOfOddsinArray(a))
println(weightOnPlanentsFunction(180.00, "Mars"))
}
fun firstDigit(n: Int): Int {... | 0 | Kotlin | 0 | 0 | 8efb8e9f4170189656d47dc5ffeedb1cd59eb30e | 1,034 | Mobile_Device_Programing | MIT License |
lib/src/main/kotlin/de/linkel/aoc/utils/graph/Graph.kt | norganos | 726,350,504 | false | {"Kotlin": 162220} | package de.linkel.aoc.utils.graph
data class Node<K>(
val id: K,
val edges: Map<K, Int>
)
class Graph<K>(
val nodes: Set<Node<K>>
) {
private val network = nodes.associateBy { it.id }
fun dijkstra(start: K, isDest: (id: K) -> Boolean): List<K>? {
val max = this.network.size + 1
va... | 0 | Kotlin | 0 | 0 | 3a1ea4b967d2d0774944c2ed4d96111259c26d01 | 4,304 | aoc-utils | Apache License 2.0 |
src/main/kotlin/adventofcode2022/solution/day_4.kt | dangerground | 579,293,233 | false | {"Kotlin": 51472} | package adventofcode2022.solution
import adventofcode2022.util.readDay
private const val DAY_NUM = 4
fun main() {
Day4(DAY_NUM.toString()).solve()
}
class Day4(private val num: String) {
private val inputText = readDay(num)
fun solve() {
println("Day $num Solution")
println("* Part 1: ... | 0 | Kotlin | 0 | 0 | f1094ba3ead165adaadce6cffd5f3e78d6505724 | 1,324 | adventofcode-2022 | MIT License |
2023/src/main/kotlin/Day01.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | object Day01 {
private val NUMBER_REGEX = Regex("\\d")
private val NUMBER_AND_TEXT_REGEX = Regex("(?=(one|two|three|four|five|six|seven|eight|nine|\\d))")
fun part1(input: String): Int {
return input.splitNewlines()
.map { line -> NUMBER_REGEX.findAll(line).map { it.value.toInt() } }
.sumCalibra... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 947 | advent-of-code | MIT License |
src/Day03.kt | JonahBreslow | 578,314,149 | false | {"Kotlin": 6978} | import java.io.File
val Char.priority: Int
get(): Int {
return when (this){
in 'a'..'z' -> this -'a' + 1
in 'A'..'Z' -> this - 'A' + 27
else -> error("Check your input! $this")
}
}
fun main () {
fun parseInput(input: String)... | 0 | Kotlin | 0 | 1 | c307ff29616f613473768168cc831a7a3fa346c2 | 1,884 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/aoc2020/HandheldHalting.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2020
import komu.adventofcode.utils.nonEmptyLines
fun handheldHalting1(input: String): Int {
val vm = VM(Instruction.parseProgram(input))
vm.run()
return vm.accumulator
}
fun handheldHalting2(input: String): Int {
for (instructions in Instruction.parseProgram(input).modif... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 2,451 | advent-of-code | MIT License |
src/day2/Day02.kt | Johnett | 572,834,907 | false | {"Kotlin": 9781} | package day2
import readInput
fun main() {
fun part1(input: List<String>): Int {
var total = 0
input.forEach { round ->
val opponentChoice = round.first()
val yourChoice = round.last()
total += when (yourChoice) {
'X' -> when (opponentChoice) {... | 0 | Kotlin | 0 | 1 | c8b0ac2184bdad65db7d2f185806b9bb2071f159 | 1,863 | AOC-2022-in-Kotlin | Apache License 2.0 |
kotlin/aoc2018/src/main/kotlin/Day02.kt | aochsner | 160,386,044 | false | null | class Day02 {
fun solvePart1(rawValues : List<String>): Int {
val (twos, threes) = rawValues.fold(Pair(0,0)) { sum, element ->
val counts = element.asSequence().groupingBy { it }.eachCount()
Pair(sum.first + if (counts.values.contains(2)) 1 else 0, sum.second + if(counts.valu... | 0 | Kotlin | 0 | 1 | 7c42ec9c20147c4be056d03e5a1492c137e63615 | 1,106 | adventofcode2018 | MIT License |
codeforces/polynomial2022/e_slow.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.polynomial2022
fun main() {
val (n, d) = readInts()
val nei = List(n) { mutableListOf<Int>() }
repeat(n - 1) {
val (u, v) = readInts().map { it - 1 }
nei[u].add(v)
nei[v].add(u)
}
val arrays = List(2) { readInts().drop(1).map { it - 1 } }
val needed = List(2) { BooleanArray(n).also { it[... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,081 | competitions | The Unlicense |
app/src/main/kotlin/ai/flowstorm/core/dialogue/BasicExtensions.kt | flowstorm | 327,536,541 | false | null | package ai.flowstorm.core.dialogue
import ai.flowstorm.core.language.English
import kotlin.math.absoluteValue
enum class Article { None, Indefinite, Definite }
fun BasicDialogue.article(subj: String, article: Article = Article.Indefinite) =
when (language) {
"en" -> when (article) {
... | 1 | Kotlin | 5 | 9 | 53dae04fa113963d632ea4d44e184885271b0322 | 2,307 | core | Apache License 2.0 |
src/main/kotlin/org/sjoblomj/adventofcode/day4/Day4.kt | sjoblomj | 225,241,573 | false | null | package org.sjoblomj.adventofcode.day4
import kotlin.streams.toList
private const val START = 245182
private const val STOP = 790572
fun day4(): Pair<Int, Int> {
val numberOfPasswordsFulfillingFirstCriteria = countPasswordsFulfillingFirstCriteria(START, STOP)
val numberOfPasswordsFulfillingSecondCriteria = countPa... | 0 | Kotlin | 0 | 0 | f8d03f7ef831bc7e26041bfe7b1feaaadcb40e68 | 1,758 | adventofcode2019 | MIT License |
14/src/main/kotlin/Reindeers.kt | kopernic-pl | 109,750,709 | false | null | import com.google.common.io.Resources
const val TIMER_INPUT = 2503
@Suppress("UnstableApiUsage")
fun main() {
val reindeers = Resources.getResource("input.txt")
.readText().lineSequence()
.map { ReindeerReader.read(it) }
val winningReindeerBySpeed = reindeers
.map { (name, r) -> name ... | 0 | Kotlin | 0 | 0 | 06367f7e16c0db340c7bda8bc2ff991756e80e5b | 2,815 | aoc-2015-kotlin | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ValidPartition.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <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,344 | kotlab | Apache License 2.0 |
Kotlin for Java Developers. Week 5/Games/Task/src/board/BoardImpl.kt | obarcelonap | 374,972,699 | false | null | package board
fun createSquareBoard(width: Int): SquareBoard = CellSquareBoard(width)
fun <T> createGameBoard(width: Int): GameBoard<T> = CellGameBoard(createSquareBoard(width))
class CellSquareBoard(override val width: Int) : SquareBoard {
private val cells = generateSequence(1) { it + 1 }
.take(width)
... | 0 | Kotlin | 0 | 0 | d79103eeebcb4f1a7b345d29c0883b1eebe1d241 | 2,457 | coursera-kotlin-for-java-developers | MIT License |
Word_Ladder_II.kt | xiekch | 166,329,519 | false | {"C++": 165148, "Java": 103273, "Kotlin": 97031, "Go": 40017, "Python": 22302, "TypeScript": 17514, "Swift": 6748, "Rust": 6579, "JavaScript": 4244, "Makefile": 349} | import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
class Solution {
fun findLadders(
beginWord: String,
endWord: String,
wordList: List<String>
): List<List<String>> {
val res = ArrayList<List<String>>()
val levelMap = HashMap<String... | 0 | C++ | 0 | 0 | eb5b6814e8ba0847f0b36aec9ab63bcf1bbbc134 | 3,481 | leetcode | MIT License |
src/Day06.kt | hoppjan | 573,053,610 | false | {"Kotlin": 9256} | fun main() {
val testLines = readInput("Day06_test")
val testResult1 = part1(testLines)
println("test part 1: $testResult1")
check(testResult1 == 7)
val testResult2 = part2(testLines)
println("test part 2: $testResult2")
check(testResult2 == 19)
val lines = readInput("Day06")
pr... | 0 | Kotlin | 0 | 0 | f83564f50ced1658b811139498d7d64ae8a44f7e | 1,032 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2016/Day10.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2016
import se.saidaspen.aoc.util.*
import java.lang.StringBuilder
fun main() = Day10.run()
object Day10 : Day(2016, 10) {
data class Bot(val nr: Int, var low: Bot?, var high: Bot?) {
val chips: MutableList<Int> = mutableListOf()
fun receive(value: Int) {
... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 4,038 | adventofkotlin | MIT License |
src/Day06/Day06.kt | suttonle24 | 573,260,518 | false | {"Kotlin": 26321} | package Day06
import readInput
fun main() {
fun getFirstPacketMarker(input: CharArray): Int {
for ((i, char) in input.withIndex()) {
if (i > 3) {
if (input[i] != input[i-1] && // i
input[i] != input[i-2] && // i
input[i] != input[i-3]... | 0 | Kotlin | 0 | 0 | 039903c7019413d13368a224fd402625023d6f54 | 2,037 | AoC-2022-Kotlin | Apache License 2.0 |
main/src/main/kotlin/siliconsloth/miniruler/planner/Planner.kt | SiliconSloth | 229,996,790 | false | null | package siliconsloth.miniruler.planner
import siliconsloth.miniruler.*
/**
* Simple action planner that uses a backtracking breadth-first search to find the shortest action sequence
* from arbitrary states to a fixed goal.
*
* @param goal the goal state
* @param actions all actions that can be taken by the agent... | 0 | Kotlin | 0 | 0 | 2c30a2a9d92385f2015b63f1fadb683e3edcddfc | 3,545 | MiniRuler | MIT License |
src/day-9/part-2/solution-day-9-part-2.kts | d3ns0n | 572,960,768 | false | {"Kotlin": 31665} | import java.io.File
import kotlin.math.abs
class Coordinate(val x: Int = 0, val y: Int = 0) {
fun moveRight() = Coordinate(x + 1, y)
fun moveLeft() = Coordinate(x - 1, y)
fun moveUp() = Coordinate(x, y + 1)
fun moveDown() = Coordinate(x, y - 1)
fun isTouching(other: Coordinate) = abs(x - other.x) <... | 0 | Kotlin | 0 | 0 | 8e8851403a44af233d00a53b03cf45c72f252045 | 2,095 | advent-of-code-22 | MIT License |
src/medium/_8StringToInteger.kt | ilinqh | 390,190,883 | false | {"Kotlin": 382147, "Java": 32712} | package medium
class _8StringToInteger {
class Solution {
fun myAtoi(str: String): Int {
val automaton = Automaton()
for (item in str) {
automaton[item]
}
return (automaton.sign * automaton.ans).toInt()
}
class Automaton {
... | 0 | Kotlin | 0 | 0 | 8d2060888123915d2ef2ade293e5b12c66fb3a3f | 3,397 | AlgorithmsProject | Apache License 2.0 |
baparker/08/main.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File
fun brokenTrash1() {
var counter = 0
File("input.txt").forEachLine {
it.split(" | ")[1]
.split(" ")
.forEach({
when (it.length) {
2, 3, 4, 7 -> counter++
}
})
}
pr... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 2,805 | advent-of-code-2021 | MIT License |
src/main/kotlin/g1001_1100/s1044_longest_duplicate_substring/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1001_1100.s1044_longest_duplicate_substring
// #Hard #String #Binary_Search #Sliding_Window #Hash_Function #Rolling_Hash #Suffix_Array
// #2023_05_27_Time_592_ms_(100.00%)_Space_106.4_MB_(100.00%)
class Solution {
private lateinit var hsh: LongArray
private lateinit var pw: LongArray
private val ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,160 | LeetCode-in-Kotlin | MIT License |
project-euler/kotlin/src/test/kotlin/dev/mikeburgess/euler/problems/Problems00x.kt | mddburgess | 469,258,868 | false | {"Kotlin": 47737} | package dev.mikeburgess.euler.problems
import dev.mikeburgess.euler.extensions.*
import dev.mikeburgess.euler.math.lcm
import dev.mikeburgess.euler.sequences.fibonacciSequence
import dev.mikeburgess.euler.sequences.primeSequence
import org.assertj.core.api.Assertions.assertThat
import kotlin.test.Test
class Problems0... | 0 | Kotlin | 0 | 0 | 9ad8f26583b204e875b07782c8d09d9d8b404b00 | 6,811 | code-kata | MIT License |
src/main/kotlin/2021/Day6.kt | mstar95 | 317,305,289 | false | null | package `2021`
import days.Day
class Day6 : Day(6) {
override fun partOne(): Any {
val input = inputString.split(",").map { it.toInt() }
val grouped = input.groupBy { it }.mapValues { it.value.size.toLong() }
var fishes = Fishes(grouped.toMutableMap(), mutableMapOf())
repeat(256) ... | 0 | Kotlin | 0 | 0 | ca0bdd7f3c5aba282a7aa55a4f6cc76078253c81 | 2,008 | aoc-2020 | Creative Commons Zero v1.0 Universal |
games-dsl/common/src/main/kotlin/net/zomis/games/components/grids/GridTransformations.kt | Zomis | 125,767,793 | false | {"Kotlin": 1346310, "Vue": 212095, "JavaScript": 43020, "CSS": 4513, "HTML": 1459, "Shell": 801, "Dockerfile": 348} | package net.zomis.games.components.grids
import net.zomis.Best
data class Position(val x: Int, val y: Int, val sizeX: Int, val sizeY: Int) {
fun next(): Position? {
if (x == sizeX - 1) {
return if (y == sizeY - 1) null else Position(0, y + 1, sizeX, sizeY)
}
return Position(thi... | 89 | Kotlin | 5 | 17 | dd9f0e6c87f6e1b59b31c1bc609323dbca7b5df0 | 5,525 | Games | MIT License |
kotlin/src/katas/kotlin/leetcode/optimal_utilisation/OptimalUtilisation.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.optimal_utilisation
import datsok.shouldEqual
import org.junit.Test
class OptimalUtilisationTests {
@Test fun examples() {
findOptimalPairs(
a = listOf(Item(1, 2), Item(2, 4), Item(3, 6)),
b = listOf(Item(1, 2)),
target = 7
) should... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,610 | katas | The Unlicense |
src/Day09.kt | i-tatsenko | 575,595,840 | false | {"Kotlin": 90644} | import kotlin.math.abs
data class Point(val x: Int, val y: Int) {
fun move(direction: String): Point {
return when (direction) {
"R", ">" -> Point(x, y + 1)
"L", "<" -> Point(x, y - 1)
"U", "^" -> Point(x + 1, y)
else -> Point(x - 1, y)
}
}
... | 0 | Kotlin | 0 | 0 | 0a9b360a5fb8052565728e03a665656d1e68c687 | 3,867 | advent-of-code-2022 | Apache License 2.0 |
kt/factor.main.kts | dfings | 31,622,045 | false | {"Go": 12328, "Kotlin": 12241, "Clojure": 11585, "Python": 9457, "Haskell": 8314, "Dart": 5990, "Rust": 5389, "TypeScript": 4158, "Elixir": 3093, "F#": 2745, "C++": 1608} | fun primeFactors(value: Long): Sequence<Long> {
fun recur(n: Long, i: Long): Sequence<Long> = when {
n == 1L -> sequenceOf<Long>()
n % i == 0L -> sequence { yield(i); yieldAll(recur(n / i, i)) }
else -> recur(n, i + 1)
}
return recur(value, 2)
}
fun factors(value: Long): Sequence<Long> {
fun recur(... | 0 | Go | 0 | 0 | f66389dcd8ff4e4d64fbd245cfdaebac7b9bd4ef | 570 | project-euler | The Unlicense |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.