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/Day2.kt | aisanu | 112,855,402 | false | {"Kotlin": 15773} | object Day2 {
fun part1Solution(input: String): Long = splitRows(input)
.map { splitColumns(it) }
.map { minMaxDiff(it) }
.sum()
fun part2Solution(input: String): Long = splitRows(input)
.map { splitColumns(it) }
.map { wholeDivider(it) }
... | 0 | Kotlin | 0 | 0 | 25dfe70e2bbb9b83a6ece694648a9271d1e21ddd | 1,024 | advent-of-code | The Unlicense |
src/main/kotlin/io/github/pshegger/aoc/y2020/Y2020D7.kt | PsHegger | 325,498,299 | false | null | package io.github.pshegger.aoc.y2020
import io.github.pshegger.aoc.common.BaseSolver
class Y2020D7 : BaseSolver() {
override val year = 2020
override val day = 7
override fun part1(): Int = parseInput().let { rules ->
rules.keys.count { color -> color.canContain(rules, "shiny gold") }
}
... | 0 | Kotlin | 0 | 0 | 346a8994246775023686c10f3bde90642d681474 | 1,710 | advent-of-code | MIT License |
leetcode2/src/leetcode/minimum-distance-between-bst-nodes.kt | hewking | 68,515,222 | false | null | package leetcode
import leetcode.structure.TreeNode
/**
* 783. 二叉搜索树结点最小距离
* https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/
* @program: leetcode
* @description: ${description}
* @author: hewking
* @create: 2019-10-23 09:18
* 给定一个二叉搜索树的根结点 root, 返回树中任意两节点的差的最小值。
示例:
输入: root = [4,2,6,1,3... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,161 | leetcode | MIT License |
src/main/kotlin/us/jwf/aoc2015/Day19Medicine.kt | jasonwyatt | 318,073,137 | false | null | package us.jwf.aoc2015
import java.io.Reader
import java.util.LinkedList
import java.util.PriorityQueue
import us.jwf.aoc.Day
/**
* AoC 2015 - Day 19
*/
class Day19Medicine : Day<Int, Int> {
override suspend fun executePart1(input: Reader): Int {
val rules = mutableMapOf<Atom, List<Rule>>()
var doneWithRu... | 0 | Kotlin | 0 | 0 | 0c92a62ba324aaa1f21d70b0f9f5d1a2c52e6868 | 3,554 | AdventOfCode-Kotlin | Apache License 2.0 |
src/Day08.kt | i-tatsenko | 575,595,840 | false | {"Kotlin": 90644} | import kotlin.math.max
import kotlin.math.min
class VisibilityUpdater(val field: Array<Array<Int>>, val visibility: Array<Array<Boolean>>, var max: Int) {
fun update(row: Int, column: Int) {
if (field[row][column] > max) {
max = field[row][column]
visibility[row][column] = true
... | 0 | Kotlin | 0 | 0 | 0a9b360a5fb8052565728e03a665656d1e68c687 | 5,326 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/dmc/advent2022/Day01.kt | dorienmc | 576,916,728 | false | {"Kotlin": 86239} | // --- Day 1: Calorie Counting ---
package com.dmc.advent2022
class Day01 : Day<Int> {
override val index = 1
override fun part1(input: List<String>): Int {
val calories = determineCalories(input)
return calories.max()
}
override fun part2(input: List<String>): Int {
val calor... | 0 | Kotlin | 0 | 0 | 207c47b47e743ec7849aea38ac6aab6c4a7d4e79 | 1,250 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/day11/Day11.kt | afTrolle | 572,960,379 | false | {"Kotlin": 33530} | package day11
import Day
import java.math.BigInteger
fun main() {
Day11("Day11").solve()
}
class Day11(input: String) : Day<List<Day11.Monkey>>(input) {
operator fun List<String>.component6(): String = get(5)
data class Monkey(
val name: Int,
val items: MutableList<BigInteger> = mutable... | 0 | Kotlin | 0 | 0 | 4ddfb8f7427b8037dca78cbf7c6b57e2a9e50545 | 3,786 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day03/Code.kt | fcolasuonno | 317,324,330 | false | null | package day03
import day01.multiplyTogether
import isDebug
import java.io.File
fun main() {
val name = if (isDebug()) "test.txt" else "input.txt"
System.err.println(name)
val dir = ::main::class.java.`package`.name
val input = File("src/main/kotlin/$dir/$name").readLines()
val parsed = parse(input... | 0 | Kotlin | 0 | 0 | e7408e9d513315ea3b48dbcd31209d3dc068462d | 1,266 | AOC2020 | MIT License |
src/test/kotlin/be/brammeerten/y2022/Day15Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2022
import be.brammeerten.C
import be.brammeerten.extractRegexGroupsI
import be.brammeerten.readFile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
class Day15Test {
@Test
fun `part 1a`() ... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 7,912 | Advent-of-Code | MIT License |
src/y2022/Day21.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2022
import util.readInput
object Day21 {
sealed class Monkey(val name: String) {
//abstract val name: String
companion object {
val allMonkeys: MutableMap<String, Monkey> = mutableMapOf()
val allDependents: MutableMap<String, List<String>> = mutableMapOf()
... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 5,046 | advent-of-code | Apache License 2.0 |
src/main/kotlin/days/Day7.kt | andilau | 544,512,578 | false | {"Kotlin": 29165} | package days
@AdventOfCodePuzzle(
name = "Internet Protocol Version 7",
url = "https://adventofcode.com/2016/day/7",
date = Date(day = 7, year = 2016)
)
class Day7(private val input: List<String>) : Puzzle {
override fun partOne(): Int = input.count { address -> IP7.from(address).supportsTLS() }
... | 3 | Kotlin | 0 | 0 | b2a836bd3f1c5eaec32b89a6ab5fcccc91b665dc | 1,850 | advent-of-code-2016 | Creative Commons Zero v1.0 Universal |
lib/src/main/kotlin/aoc/day09/Day09.kt | Denaun | 636,769,784 | false | null | package aoc.day09
import kotlin.math.abs
fun part1(input: String): Int = simulate(parse(input), 2).size
fun part2(input: String): Int = simulate(parse(input), 10).size
fun simulate(motions: List<Motion>, numKnots: Int): Set<Coordinate> {
require(numKnots >= 1)
var knots = List(numKnots) { Coordinate(0, 0) }... | 0 | Kotlin | 0 | 0 | 560f6e33f8ca46e631879297fadc0bc884ac5620 | 2,075 | aoc-2022 | Apache License 2.0 |
src/Day10.kt | HylkeB | 573,815,567 | false | {"Kotlin": 83982} | private sealed class Instruction {
object Noop : Instruction()
object StartAddX : Instruction()
class FinishAddX(val amount: Int): Instruction()
}
fun main() {
fun List<String>.toInstructions(): List<Instruction> {
return flatMap {
if (it == "noop") {
listOf(Instruc... | 0 | Kotlin | 0 | 0 | 8649209f4b1264f51b07212ef08fa8ca5c7d465b | 3,558 | advent-of-code-2022-kotlin | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year15/Day07.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year15
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.year15.Wiring.*
import com.grappenmaker.aoc.year15.Operator.*
fun PuzzleSet.day7() = puzzle {
val insns = inputLines.associate { l ->
val (operation, target) = l.split(" -> ")
val parts = operatio... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 2,624 | advent-of-code | The Unlicense |
src/Day11.kt | lmoustak | 573,003,221 | false | {"Kotlin": 25890} | import java.util.*
enum class Operation(val value: String) { ADDITION("+"), MULTIPLICATION("*") }
data class Monkey(
val items: MutableList<Long>,
val operation: Operation,
val value: Int?,
val divisibleBy: Int,
val targetIfTrue: Int,
val targetIfFalse: Int,
var inspections: Long = 0L
)
f... | 0 | Kotlin | 0 | 0 | bd259af405b557ab7e6c27e55d3c419c54d9d867 | 4,865 | aoc-2022-kotlin | Apache License 2.0 |
2020/src/main/kotlin/de/skyrising/aoc2020/day9/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2020.day9
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.HashCommon
import it.unimi.dsi.fastutil.longs.LongOpenHashSet
val test = TestInput("""
35
20
15
25
47
40
62
55
65
95
102
117
150
182
127
219
299
277
309
... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 2,958 | aoc | MIT License |
src/main/kotlin/day12/Code.kt | fcolasuonno | 317,324,330 | false | null | package day12
import isDebug
import java.io.File
import kotlin.math.abs
fun main() {
val name = if (isDebug()) "test.txt" else "input.txt"
System.err.println(name)
val dir = ::main::class.java.`package`.name
val input = File("src/main/kotlin/$dir/$name").readLines()
val parsed = parse(input)
p... | 0 | Kotlin | 0 | 0 | e7408e9d513315ea3b48dbcd31209d3dc068462d | 2,319 | AOC2020 | MIT License |
src/Day01.kt | remidu | 573,452,090 | false | {"Kotlin": 22113} | fun main() {
fun part1(input: List<String>): Int {
var best = 0
var total = 0
for (line in input) {
if (line.isBlank()) {
if (total > best) best = total
total = 0
} else {
total += line.toInt()
}
}
... | 0 | Kotlin | 0 | 0 | ecda4e162ab8f1d46be1ce4b1b9a75bb901bc106 | 984 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/cloud/dqn/leetcode/TwoSum4Kt.kt | aviuswen | 112,305,062 | false | null | package cloud.dqn.leetcode
/**
* https://leetcode.com/problems/two-sum-iv-input-is-a-bst/description/
Given a Binary Search Tree and a target number,
return true if there exist two elements in the BST
such that their sum is equal to the given target.
Example 1:
Input:
5
... | 0 | Kotlin | 0 | 0 | 23458b98104fa5d32efe811c3d2d4c1578b67f4b | 2,875 | cloud-dqn-leetcode | No Limit Public License |
src/Day09.kt | esteluk | 572,920,449 | false | {"Kotlin": 29185} | import kotlin.math.absoluteValue
fun main() {
fun printPositions(head: Pair<Int, Int>, tail: Array<Pair<Int, Int>>, size: Pair<Int, Int> = Pair(6, 5)) {
for (i in size.second-1 downTo 0) {
val builder = StringBuilder(size.first)
for (j in 0 until size.first) {
if (h... | 0 | Kotlin | 0 | 0 | 5d1cf6c32b0c76c928e74e8dd69513bd68b8cb73 | 5,421 | adventofcode-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimizeDeviationInArray.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 | 1,719 | kotlab | Apache License 2.0 |
src/test/kotlin/Day13.kt | christof-vollrath | 317,635,262 | false | null | import io.kotest.core.spec.style.FunSpec
import io.kotest.data.forAll
import io.kotest.data.headers
import io.kotest.data.row
import io.kotest.data.table
import io.kotest.matchers.shouldBe
/*
--- Day 13: Shuttle Search ---
See https://adventofcode.com/2020/day/13
*/
fun List<Int?>.findNextBus(earliest: Int): Pair<... | 1 | Kotlin | 0 | 0 | 8ad08350aa4bd1a29b7e18765fc7a2d6de8021e8 | 4,392 | advent_of_code_2020 | Apache License 2.0 |
src/main/kotlin/Day02.kt | nmx | 572,850,616 | false | {"Kotlin": 18806} | fun main(args: Array<String>) {
class Shape(
val draw: Char,
val defeats: Char,
val score: Int
)
val shapes = buildMap<Char, Shape> {
put('X', Shape('A', 'C', 1)) // Rock smashes Scissors
put('Y', Shape('B', 'A', 2)) // Paper covers Rock
put('Z', Shape('C', '... | 0 | Kotlin | 0 | 0 | 33da2136649d08c32728fa7583ecb82cb1a39049 | 1,859 | aoc2022 | MIT License |
src/Day05.kt | ExpiredMinotaur | 572,572,449 | false | {"Kotlin": 11216} | fun main() {
var crateDataOriginal: List<List<Char>> =emptyList()
var moveData: List<List<Int>> = emptyList()
fun loadData(input: List<String>){
val data = input.chunkedByBlank()
//Parse Crate Data
val lineLength = data[0].maxOf { it.length }
crateDataOriginal = data[0].dr... | 0 | Kotlin | 0 | 0 | 7ded818577737b0d6aa93cccf28f07bcf60a9e8f | 1,950 | AOC2022 | Apache License 2.0 |
src/Day24.kt | MickyOR | 578,726,798 | false | {"Kotlin": 98785} | fun main() {
var dR = listOf<Int>(-1, 0, 1, 0, 0)
var dC = listOf<Int>(0, 1, 0, -1, 0)
fun part1(input: List<String>): Int {
var blizzards = arrayListOf<ArrayList<ArrayList<Boolean>>>()
var oldPositions = mutableSetOf<Pair<Pair<Int, Int>, Int>>()
var blizzard = arrayListOf<ArrayList... | 0 | Kotlin | 0 | 0 | c24e763a1adaf0a35ed2fad8ccc4c315259827f0 | 6,456 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaxScore.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 | 3,727 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/OptimalDivision.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,741 | kotlab | Apache License 2.0 |
src/aoc2022/Day05.kt | Playacem | 573,606,418 | false | {"Kotlin": 44779} | package aoc2022
import utils.readInput
object Day05 {
override fun toString(): String {
return this.javaClass.simpleName
}
data class Instruction(val numOfItems: Int, val fromRaw: Int, val toRaw: Int) {
val fromIndex: Int get() = fromRaw - 1
val toIndex: Int get() = toRaw - 1
... | 0 | Kotlin | 0 | 0 | 4ec3831b3d4f576e905076ff80aca035307ed522 | 3,743 | advent-of-code-2022 | Apache License 2.0 |
src/day16/Day16.kt | JoeSkedulo | 573,328,678 | false | {"Kotlin": 69788} | package day16
import Runner
fun main() {
Day16Runner().solve()
}
class Day16Runner : Runner<Int>(
day = 16,
expectedPartOneTestAnswer = 1651,
expectedPartTwoTestAnswer = 1707
) {
override fun partOne(input: List<String>, test: Boolean): Int {
val valveInput = valves(input)
return... | 0 | Kotlin | 0 | 0 | bd8f4058cef195804c7a057473998bf80b88b781 | 5,790 | advent-of-code | Apache License 2.0 |
src/main/kotlin/solutions/day15/Day15.kt | Dr-Horv | 112,381,975 | false | null | package solutions.day15
import solutions.Solver
import utils.splitAtWhitespace
class Generator(private var value: Long, private val factor: Int, private val divisableBy: Int) {
fun next(): Long {
while(true) {
value = (value * factor) % 2147483647
if(value % divisableBy == 0L) {
... | 0 | Kotlin | 0 | 2 | 975695cc49f19a42c0407f41355abbfe0cb3cc59 | 1,952 | Advent-of-Code-2017 | MIT License |
2021/src/main/kotlin/com/trikzon/aoc2021/Day2.kt | Trikzon | 317,622,840 | false | {"Kotlin": 43720, "Rust": 21648, "C#": 12576, "C++": 4114, "CMake": 397} | package com.trikzon.aoc2021
fun main() {
val input = getInputStringFromFile("/day2.txt")
benchmark(Part.One, ::dayTwoPartOne, input, 2039912, 50000)
benchmark(Part.Two, ::dayTwoPartTwo, input, 1942068080, 50000)
}
fun dayTwoPartOne(input: String): Int {
val commands = input.lines().map { line ->
... | 0 | Kotlin | 1 | 0 | d4dea9f0c1b56dc698b716bb03fc2ad62619ca08 | 1,315 | advent-of-code | MIT License |
src/main/kotlin/CitiesAndDistances.kt | thomasnield | 136,809,665 | false | {"Kotlin": 25034} | import java.util.concurrent.ThreadLocalRandom
data class CityPair(val city1: Int, val city2: Int)
class City(val id: Int, val name: String, val x: Double, val y: Double) {
override fun toString() = name
fun distanceTo(other: City) =CitiesAndDistances.distances[CityPair(id, other.id)]?:0.0
}
object CitiesAndD... | 2 | Kotlin | 25 | 60 | f6d20984b311f59fe3221f170bc55cfc9eb3097e | 1,575 | traveling_salesman_demo | Apache License 2.0 |
dsalgo/src/commonMain/kotlin/com/nalin/datastructurealgorithm/ds/BTree.kt | nalinchhajer1 | 534,780,196 | false | {"Kotlin": 86359, "Ruby": 1605} | package com.nalin.datastructurealgorithm.ds
import kotlin.math.abs
import kotlin.math.max
interface BTree<out T> {
fun root(): BTreeNode<T>?
}
interface BTreeNode<out T> {
fun value(): T
fun leftNode(): BTreeNode<T>?
fun rightNode(): BTreeNode<T>?
}
interface BSTTree<T : Comparable<T>> : BTree<T> {
... | 0 | Kotlin | 0 | 0 | eca60301dab981d0139788f61149d091c2c557fd | 5,016 | kotlin-ds-algo | MIT License |
04 - Kotlin/4.kt | Ciremun | 318,207,178 | false | {"C": 9212, "C++": 7831, "Crystal": 5319, "Python": 4909, "Kotlin": 3585, "Ruby": 3297, "TypeScript": 2631, "Rust": 2560, "Nim": 2134, "Scala": 1408, "C#": 980, "Haskell": 596} | import java.io.File
fun is_valid_hex_char(c: String): Boolean {
val c_int: Int? = c.toIntOrNull()
if (c_int is Int)
return 0 <= c_int && c_int <= 9
return listOf("a", "b", "c", "d", "e", "f").contains(c)
}
fun is_valid_field_hair(pd_value: String): Boolean {
val pd_hash: String = pd_value.subs... | 0 | C | 0 | 1 | 05789c51a3c05040b93e5d943c5eb68c9b3d989b | 3,585 | AOC-2020 | MIT License |
src/exercises/Day07.kt | Njko | 572,917,534 | false | {"Kotlin": 53729} | // ktlint-disable filename
package exercises
import readInput
// https://www.kodeco.com/books/data-structures-algorithms-in-kotlin/v1.0/chapters/6-trees
sealed class Node {
data class Folder(val name: String, val children: MutableList<Node> = mutableListOf()) : Node()
data class File(val name: String, val si... | 0 | Kotlin | 0 | 2 | 68d0c8d0bcfb81c183786dfd7e02e6745024e396 | 2,606 | advent-of-code-2022 | Apache License 2.0 |
advent-of-code/src/main/kotlin/com/akikanellis/adventofcode/year2022/Day15.kt | akikanellis | 600,872,090 | false | {"Kotlin": 142932, "Just": 977} | package com.akikanellis.adventofcode.year2022
import com.akikanellis.adventofcode.year2022.utils.Point
import kotlin.math.abs
object Day15 {
private val SENSORS_TO_BEACONS_REGEX =
"Sensor at x=(.+), y=(.+): closest beacon is at x=(.+), y=(.+)".toRegex()
private const val DISTRESS_BEACON_MIN_COORDINATE... | 8 | Kotlin | 0 | 0 | 036cbcb79d4dac96df2e478938de862a20549dce | 3,160 | advent-of-code | MIT License |
src/aoc2022/Day06.kt | anitakar | 576,901,981 | false | {"Kotlin": 124382} | package aoc2022
import println
import readInput
fun main() {
fun part1(input: List<String>): Int {
val seq = input[0]
val occur = mutableMapOf<Char, Int>()
for (i in 0 until seq.length) {
if (i > 3) {
val char = seq.get(i - 4)
val count = occur.... | 0 | Kotlin | 0 | 1 | 50998a75d9582d4f5a77b829a9e5d4b88f4f2fcf | 1,428 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NearestExit.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 | 2,865 | kotlab | Apache License 2.0 |
src/Day01.kt | rosyish | 573,297,490 | false | {"Kotlin": 51693} | fun main() {
fun part1(input: List<Int>): Int {
return input.max()
}
fun part2(input: List<Int>): Int {
return input.sortedDescending().subList(0, 3).sum()
}
fun computeCaloriesForElves(input: List<String>): List<Int> {
var curVal = 0
val output = mutableListOf<Int>... | 0 | Kotlin | 0 | 2 | 43560f3e6a814bfd52ebadb939594290cd43549f | 1,052 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem2391/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2391
/**
* LeetCode page: [2391. Minimum Amount of Time to Collect Garbage](https://leetcode.com/problems/minimum-amount-of-time-to-collect-garbage/);
*/
class Solution {
/* Complexity:
* Time O(L) and Space O(1) where L id the flattened length of garbage;
*/
f... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,322 | hj-leetcode-kotlin | Apache License 2.0 |
src/commonMain/kotlin/io/github/alexandrepiveteau/graphs/algorithms/ParentsMap.kt | alexandrepiveteau | 630,931,403 | false | {"Kotlin": 132267} | package io.github.alexandrepiveteau.graphs.algorithms
import io.github.alexandrepiveteau.graphs.*
import io.github.alexandrepiveteau.graphs.builder.buildDirectedNetwork
import io.github.alexandrepiveteau.graphs.internal.collections.IntDequeue
/**
* Returns the [VertexArray] containing all the vertices traversed to g... | 9 | Kotlin | 0 | 6 | a4fd159f094aed5b6b8920d0ceaa6a9c5fc7679f | 1,921 | kotlin-graphs | MIT License |
src/main/kotlin/com/groundsfam/advent/y2015/d03/Day03.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2015.d03
import com.groundsfam.advent.DATAPATH
import kotlin.io.path.div
import kotlin.io.path.useLines
enum class Direction {
UP,
DOWN,
LEFT,
RIGHT
}
fun partOne(directions: List<Direction>): Int {
var position = 0 to 0
val visited = mutableSetOf(position)
... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 1,883 | advent-of-code | MIT License |
src/main/kotlin/com/jaspervanmerle/aoc2020/day/Day12.kt | jmerle | 317,518,472 | false | null | package com.jaspervanmerle.aoc2020.day
import kotlin.math.abs
class Day12 : Day("1589", "23960") {
private data class Instruction(val action: Char, val value: Int)
private enum class Direction(val xModifier: Int, val yModifier: Int) {
NORTH(0, 1),
EAST(1, 0),
SOUTH(0, -1),
WES... | 0 | Kotlin | 0 | 0 | 81765a46df89533842162f3bfc90f25511b4913e | 3,457 | advent-of-code-2020 | MIT License |
src/main/kotlin/week5/TicTacToe.kt | doertscho | 305,730,136 | false | null | package week5
import week5.players.ValidMovePlayer
fun winner(state: State): Symbol? {
val field = state.field
val triples = listOf(
// rows
listOf(field[0][0], field[0][1], field[0][2]),
listOf(field[1][0], field[1][1], field[1][2]),
listOf(field[2][0], field[2... | 0 | Kotlin | 0 | 0 | c84e8b0341fae1b5384fce52fcedf660e54b11f5 | 2,137 | software-ag-kks | MIT License |
src/Day03.kt | cerberus97 | 579,910,396 | false | {"Kotlin": 11722} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { items ->
val sz = items.length
val firstHalf = items.substring(0, sz / 2).toSet()
val secondHalf = items.substring(sz / 2, sz).toSet()
val common = firstHalf.intersect(secondHalf).single()
if (common.isLowerCase(... | 0 | Kotlin | 0 | 0 | ed7b5bd7ad90bfa85e868fa2a2cdefead087d710 | 783 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/boj_2206/Kotlin.kt | devetude | 70,114,524 | false | {"Java": 564034, "Kotlin": 80457} | package boj_2206
import java.util.LinkedList
import java.util.StringTokenizer
val DIRECTIONS = arrayOf(arrayOf(0, 1), arrayOf(0, -1), arrayOf(1, 0), arrayOf(-1, 0))
fun main() {
val st = StringTokenizer(readln())
val n = st.nextToken().toInt()
val m = st.nextToken().toInt()
val map = Array(size = n +... | 0 | Java | 7 | 20 | 4c6acff4654c49d15827ef87c8e41f972ff47222 | 2,205 | BOJ-PSJ | Apache License 2.0 |
src/main/kotlin/net/voldrich/aoc2022/Day05.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2022
import net.voldrich.BaseDay
import java.util.*
import kotlin.collections.ArrayList
// https://adventofcode.com/2022/day/5
fun main() {
Day05().run()
}
class Day05 : BaseDay() {
val instructionRegex = Regex("move ([0-9]+) from ([0-9]+) to ([0-9]+)")
override fun task1() : S... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 2,414 | advent-of-code | Apache License 2.0 |
src/day2/Code.kt | fcolasuonno | 162,470,286 | false | null | package day2
import java.io.File
fun main(args: Array<String>) {
val name = if (false) "test.txt" else "input.txt"
val dir = ::main::class.java.`package`.name
val input = File("src/$dir/$name").readLines()
val parsed = parse(input)
println("Part 1 = ${part1(parsed)}")
println("Part 2 = ${part2... | 0 | Kotlin | 0 | 0 | 24f54bf7be4b5d2a91a82a6998f633f353b2afb6 | 1,099 | AOC2015 | MIT License |
src/main/kotlin/y2023/Day03.kt | jforatier | 432,712,749 | false | {"Kotlin": 44692} | package y2023
import common.Resources.splitOnEmpty
class Day03(private val data: List<String>) {
fun part1(): Int {
val digits = "\\d+".toRegex()
val partNumbers = mutableListOf<Int>()
data.forEachIndexed { row, s ->
val numbers = digits.findAll(s)
.map { it.ra... | 0 | Kotlin | 0 | 0 | 2a8c0b4ccb38c40034c6aefae2b0f7d4c486ffae | 1,841 | advent-of-code-kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ThreeEqualParts.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 | 4,802 | kotlab | Apache License 2.0 |
leetcode/src/tree/Q101.kt | zhangweizhe | 387,808,774 | false | null | package tree
import linkedlist.TreeNode
import java.util.*
fun main() {
// 101. 对称二叉树
// https://leetcode-cn.com/problems/symmetric-tree/
val root = TreeNode(1)
root.left = TreeNode(2)
root.right = TreeNode(2)
root.left?.left = TreeNode(3)
// root.left?.right = TreeNode(3)
// root.right?... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,645 | kotlin-study | MIT License |
2021/kotlin/src/main/kotlin/com/pietromaggi/aoc2021/day02/Day02.kt | pfmaggi | 438,378,048 | false | {"Kotlin": 113883, "Zig": 18220, "C": 7779, "Go": 4059, "CMake": 386, "Awk": 184} | /*
* 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 wr... | 0 | Kotlin | 0 | 0 | 7c4946b6a161fb08a02e10e99055a7168a3a795e | 2,430 | AdventOfCode | Apache License 2.0 |
src/Lesson2Arrays/OddOccurrencesInArray.kt | slobodanantonijevic | 557,942,075 | false | {"Kotlin": 50634} |
import java.util.Arrays
/**
* 100/100
* @param A
* @return
*/
fun solution(A: IntArray): Int {
Arrays.sort(A)
var i = 0
while (i < A.size - 1) {
if (A[i] != A[i + 1]) {
return A[i]
}
i += 2
}
return A[A.size - 1]
}
/**
* A non-empty array A consisting of ... | 0 | Kotlin | 0 | 0 | 155cf983b1f06550e99c8e13c5e6015a7e7ffb0f | 1,525 | Codility-Kotlin | Apache License 2.0 |
src/org/aoc2021/Day23.kt | jsgroth | 439,763,933 | false | {"Kotlin": 86732} | package org.aoc2021
import java.nio.file.Files
import java.nio.file.Path
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
object Day23 {
private const val hallwayLength = 11
private val amphipodChars = setOf('A', 'B', 'C', 'D')
private val roomIndices = setOf(2, 4, ... | 0 | Kotlin | 0 | 0 | ba81fadf2a8106fae3e16ed825cc25bbb7a95409 | 9,627 | advent-of-code-2021 | The Unlicense |
src/y2022/Day02.kt | a3nv | 574,208,224 | false | {"Kotlin": 34115, "Java": 1914} | package y2022
import utils.readInput
fun main() {
fun getGame(choice: String): Choice {
return when (choice) {
"A", "X" -> Rock(choice)
"B", "Y" -> Paper(choice)
"C", "Z" -> Scissors(choice)
else -> throw IllegalArgumentException()
}
}
fun ... | 0 | Kotlin | 0 | 0 | ab2206ab5030ace967e08c7051becb4ae44aea39 | 3,638 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/aoc2016/Day01.kt | lukellmann | 574,273,843 | false | {"Kotlin": 175166} | package aoc2016
import AoCDay
import aoc2016.Day01.Dir.*
import util.Vec2
import util.illegalInput
import util.plus
import util.times
import kotlin.math.abs
// https://adventofcode.com/2016/day/1
object Day01 : AoCDay<Int>(
title = "No Time for a Taxicab",
part1ExampleAnswer = 8,
part1Answer = 252,
pa... | 0 | Kotlin | 0 | 1 | 344c3d97896575393022c17e216afe86685a9344 | 1,882 | advent-of-code-kotlin | MIT License |
kotlin/src/main/kotlin/adventofcode/y2018/Day6.kt | 3ygun | 115,948,057 | false | null | package adventofcode.y2018
import adventofcode.DataLoader
import adventofcode.Day
import kotlin.math.abs
object Day6 : Day {
val STAR1_DATA = DataLoader.readLinesFromFor("/y2018/Day6Star1.txt")
val STAR2_DATA = STAR1_DATA
const val STAR2_MAX_DISTANCE = 10_000
override val day: Int = 6
override f... | 0 | Kotlin | 0 | 0 | 69f95bca3d22032fba6ee7d9d6ec307d4d2163cf | 6,827 | adventofcode | MIT License |
advent-of-code-2022/src/main/kotlin/eu/janvdb/aoc2022/day16/Valve.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2022.day16
import eu.janvdb.aocutil.kotlin.ShortestPathMove
import eu.janvdb.aocutil.kotlin.findShortestPath
const val START_VALVE = "AA"
val PATTERN = Regex("Valve ([A-Z]+) has flow rate=(\\d+); tunnels? leads? to valves? ([A-Z, ]+)")
val SPLIT = Regex(", ")
data class Valve(val name: String, ... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,708 | advent-of-code | Apache License 2.0 |
kotlin/dp/MatrixChainMultiply.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package dp
object MatrixChainMultiply {
fun solveIterative(s: IntArray): Int {
val n = s.size - 1
val p = Array(n) { IntArray(n) }
val m = Array(n) { IntArray(n) }
for (len in 2..n) {
var a = 0
while (a + len <= n) {
val b = a + len - 1
... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,932 | codelibrary | The Unlicense |
src/aoc2023/Day3.kt | RobertMaged | 573,140,924 | false | {"Kotlin": 225650} | package aoc2023
import utils.Vertex
import utils.alsoPrintln
import utils.checkEquals
import utils.readInput
import kotlin.collections.List
import kotlin.collections.contains
import kotlin.collections.filter
import kotlin.collections.flatten
import kotlin.collections.getOrNull
import kotlin.collections.listOf
import k... | 0 | Kotlin | 0 | 0 | e2e012d6760a37cb90d2435e8059789941e038a5 | 4,378 | Kotlin-AOC-2023 | Apache License 2.0 |
leetcode-75-kotlin/src/main/kotlin/MergeStringsAlternately.kt | Codextor | 751,507,040 | false | {"Kotlin": 49566} | /**
* You are given two strings word1 and word2.
* Merge the strings by adding letters in alternating order, starting with word1.
* If a string is longer than the other, append the additional letters onto the end of the merged string.
*
* Return the merged string.
*
*
*
* Example 1:
*
* Input: word1 = "abc",... | 0 | Kotlin | 0 | 0 | 0511a831aeee96e1bed3b18550be87a9110c36cb | 1,626 | leetcode-75 | Apache License 2.0 |
src/Day04.kt | ostersc | 572,991,552 | false | {"Kotlin": 46059} | fun main() {
class Assignment() {
var range1 = IntRange(0, 0)
var range2 = IntRange(0, 0)
constructor(line: String) : this() {
val (a, b, c, d) = """(\d+)-(\d+),(\d+)-(\d+)""".toRegex().find(line)!!.destructured.toList()
.map { it.toInt() }
range1 = I... | 0 | Kotlin | 0 | 1 | 3eb6b7e3400c2097cf0283f18b2dad84b7d5bcf9 | 1,236 | advent-of-code-2022 | Apache License 2.0 |
src/Day16.kt | wgolyakov | 572,463,468 | false | null | import kotlin.random.Random
fun main() {
fun parse(input: List<String>): Pair<List<List<Int>>, IntArray> {
val valves = mutableMapOf("AA" to 0)
val adj = MutableList(input.size) { emptyList<Int>() }
val rates = IntArray(input.size)
var count = 1
for (line in input) {
val (valve, rate, exits) =
Regex(... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 3,803 | advent-of-code-2022 | Apache License 2.0 |
advent-of-code2015/src/main/kotlin/day7/Advent7.kt | REDNBLACK | 128,669,137 | false | null | package day7
import parseInput
import splitToLines
/**
--- Day 7: Some Assembly Required ---
This year, Santa brought little Bobby Tables a set of wires and bitwise logic gates! Unfortunately, little Bobby is a little under the recommended age range, and he needs help assembling the circuit.
Each wire has an identif... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 4,607 | courses | MIT License |
src/Day05.kt | samframpton | 572,917,565 | false | {"Kotlin": 6980} | import java.io.File
fun main() {
fun part1(): String {
val stacks = getStacks()
val instructions = getInstructions()
for (instruction in instructions) {
for (i in 0 until instruction.first) {
val crate = stacks[instruction.second - 1].removeLast()
... | 0 | Kotlin | 0 | 0 | e7f5220b6bd6f3c5a54396fa95f199ff3a8a24be | 2,046 | advent-of-code-2022 | Apache License 2.0 |
src/Day2/Day2.kt | mhlavac | 574,023,170 | false | {"Kotlin": 11179, "Makefile": 612} | package Day2
import java.io.File
fun main() {
val lines = File("src", "Day2/input.txt").readLines()
var totalScore = 0
lines.forEach {
val (theirs, mine) = it.split(" ")
val score = score(map(theirs), map(mine))
totalScore += score
println("$theirs $mine: $score")
}
... | 0 | Kotlin | 0 | 0 | 240dbd396c0a9d72959a0b0ed31f77c356c0c0bd | 1,210 | advent-of-code-2022 | Apache License 2.0 |
2016/main/day_01/Main.kt | Bluesy1 | 572,214,020 | false | {"Rust": 280861, "Kotlin": 94178, "Shell": 996} | package day_01_2016
import java.io.File
import kotlin.math.abs
enum class Facing {
NORTH, EAST, SOUTH, WEST
}
fun part1(input: List<String>) {
var horizontalPos =0
var verticalPos = 0
var facing = Facing.NORTH
for ((direction, distance) in input.map { Pair(it[0], it.substring(1).toInt()) }) {
... | 0 | Rust | 0 | 0 | 537497bdb2fc0c75f7281186abe52985b600cbfb | 3,871 | AdventofCode | MIT License |
MaximumSubArray.kt | akshaybhongale | 481,316,050 | false | {"Kotlin": 1611} | /**
* Array Data Structure Problem
* Largest Sum Contiguous Sub-array
* Kotlin solution :
* 1- Simple approach = time complexity O(n*n) where n is size of array
* 2- kadane approach = time complexity O(n) where n is size of array
*/
class MaximumSubArray {
companion object {
@JvmStatic
fun ma... | 0 | Kotlin | 0 | 0 | e2de2c99096dcf0345979492e40f21a0a16b6d55 | 1,611 | Largest-Sum-Contiguous-Subarray-Kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DivideTwoIntegers.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 | 2,105 | kotlab | Apache License 2.0 |
advent-of-code2016/src/main/kotlin/day06/Advent6.kt | REDNBLACK | 128,669,137 | false | null | package day06
import array2d
import parseInput
import splitToLines
/**
--- Day 6: Signals and Noise ---
Something is jamming your communications with Santa. Fortunately, your signal is only partially jammed, and protocol in situations like this is to switch to a simple repetition code to get the message through.
In... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 3,597 | courses | MIT License |
src/day21/Day21.kt | easchner | 572,762,654 | false | {"Kotlin": 104604} | package day21
import readInputString
import java.lang.Exception
import java.lang.Long.max
import kotlin.system.measureNanoTime
data class Monkey(val name: String, val monkey1: String, val monkey2: String, val operation: Char, var output: Long = Long.MIN_VALUE)
fun main() {
fun recurseMonkeys(monkeys: MutableList... | 0 | Kotlin | 0 | 0 | 5966e1a1f385c77958de383f61209ff67ffaf6bf | 5,940 | Advent-Of-Code-2022 | Apache License 2.0 |
year2020/src/main/kotlin/net/olegg/aoc/year2020/day18/Day18.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2020.day18
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2020.DayOf2020
/**
* See [Year 2020, Day 18](https://adventofcode.com/2020/day/18)
*/
object Day18 : DayOf2020(18) {
override fun first(): Any? {
return solve {
when (it) {
'*' -> 1
'+' -> ... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,762 | adventofcode | MIT License |
src/main/kotlin/biodivine/algebra/params/SemiAlgTree.kt | daemontus | 160,796,526 | false | null | package biodivine.algebra.params
import biodivine.algebra.MPoly
import biodivine.algebra.NumQ
import biodivine.algebra.ia.Interval
import biodivine.algebra.ia.div
import biodivine.algebra.ia.minus
import biodivine.algebra.ia.plus
import biodivine.algebra.rootisolation.AdaptiveRootIsolation
import biodivine.algebra.roo... | 0 | Kotlin | 0 | 0 | ed4fd35015b73ea3ac36aecb1c5a568f6be7f14c | 9,569 | biodivine-algebraic-toolkit | MIT License |
src/adventofcode/Day08.kt | Timo-Noordzee | 573,147,284 | false | {"Kotlin": 80936} | package adventofcode
import org.openjdk.jmh.annotations.*
import java.util.concurrent.TimeUnit
import kotlin.math.absoluteValue
/**
* @param si the starting value for i
* @param sj the starting value for j
* @param di the delta value for i
* @param dj the delta value for j
*/
fun Array<IntArray>.vd(si: Int, sj: ... | 0 | Kotlin | 0 | 2 | 10c3ab966f9520a2c453a2160b143e50c4c4581f | 3,237 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day01.kt | szymon-kaczorowski | 572,839,642 | false | {"Kotlin": 45324} | fun main() {
fun part1(input: List<String>): Int {
var max = 0;
var current = 0;
for (line in input) {
if (line.isEmpty()) current = 0 else
current += line.toInt()
if (current > max) max = current
}
return max
}
fun part2(inpu... | 0 | Kotlin | 0 | 0 | 1d7ab334f38a9e260c72725d3f583228acb6aa0e | 1,061 | advent-2022 | Apache License 2.0 |
src/main/kotlin/g0701_0800/s0773_sliding_puzzle/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0701_0800.s0773_sliding_puzzle
// #Hard #Array #Breadth_First_Search #Matrix
// #2023_03_10_Time_166_ms_(100.00%)_Space_35_MB_(100.00%)
import java.util.LinkedList
import java.util.Queue
class Solution {
private class Node(var board: String, var depth: Int, var y: Int, var x: Int)
fun slidingPuzzle(... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,015 | LeetCode-in-Kotlin | MIT License |
src/y2016/Day15.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2016
import util.readInput
object Day15 {
private fun parse(input: List<String>): List<Pair<Int, Int>> {
return input.map {
val els = it.split(' ')
els[3].toInt() to els.last().dropLast(1).toInt()
}
}
fun part1(input: List<String>): Int {
val initi... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 1,614 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/jaspervanmerle/aoc2020/day/Day14.kt | jmerle | 317,518,472 | false | null | package com.jaspervanmerle.aoc2020.day
class Day14 : Day("17765746710228", "4401465949086") {
private abstract class Program {
protected val memory = mutableMapOf<Long, Long>()
protected var mask = ""
protected abstract fun writeValue(address: Long, value: Long)
fun processInstru... | 0 | Kotlin | 0 | 0 | 81765a46df89533842162f3bfc90f25511b4913e | 3,327 | advent-of-code-2020 | MIT License |
src/main/kotlin/kt/kotlinalgs/app/graph/ConnectedComponents.ws.kts | sjaindl | 384,471,324 | false | null | package kt.kotlinalgs.app.graph
println("Test")
Solution().test()
data class Vertice<T>(
val value: T
)
class UndirectedGraphWithAdjList<T>(val vertices: List<Vertice<T>> = emptyList()) {
private val adjList: MutableMap<Vertice<T>, MutableList<Vertice<T>>> = mutableMapOf()
fun addEdge(from: Vertice<T>,... | 0 | Java | 0 | 0 | e7ae2fcd1ce8dffabecfedb893cb04ccd9bf8ba0 | 2,238 | KotlinAlgs | MIT License |
src/Day03.kt | NatoNathan | 572,672,396 | false | {"Kotlin": 6460} | fun Char.getPriority(): Int = when {
this.isLowerCase() -> this.code -96
this.isUpperCase() -> this.code - 38
else -> throw Exception("Not a Letter")
}
fun getHalfs(items: String): List<String> = items.chunked(items.length/2)
fun getErrorItem(items: List<String>): Char {
val (one, two... | 0 | Kotlin | 0 | 0 | c0c9e2a2d0ca2503afe33684a3fbba1f9eefb2b0 | 1,109 | advent-of-code-kt | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2020/Day14.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2020
import com.s13g.aoc.*
/**
* --- Day 14: Docking Data ---
* https://adventofcode.com/2020/day/14
*/
val memRegex = """mem\[(\d+)\] = (\d+)$""".toRegex()
class Day14 : Solver {
override fun solve(lines: List<String>): Result {
val input = parseInput(lines)
// Part A: Use Mas... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 2,671 | euler | Apache License 2.0 |
src/Day05.kt | arturradiuk | 571,954,377 | false | {"Kotlin": 6340} | import java.util.stream.Collectors.*
fun main() {
fun method(input: List<String>, stackFlow: Boolean): String {
val chunkedStacks = input.takeWhile { it != "" }.map { it.chunked(4) }
val indexToElement = chunkedStacks.dropLast(1).flatMap {
it.mapIndexedNotNull { index, string ->
... | 0 | Kotlin | 0 | 0 | 85ef357643e5e4bd2ba0d9a09f4a2d45653a8e28 | 1,881 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/Day3.kt | ueneid | 575,213,613 | false | null | class Day3(val inputs: List<String>) {
private fun getPriority(c: Char): Int {
return if (c.isUpperCase()) {
c.lowercaseChar() - 'a' + 1 + 26
} else {
c - 'a' + 1
}
}
fun solve1(): Int {
return inputs.asSequence()
.map { line -> line.chunk... | 0 | Kotlin | 0 | 0 | 743c0a7adadf2d4cae13a0e873a7df16ddd1577c | 858 | adventcode2022 | MIT License |
runner/src/main/kotlin/com/grappenmaker/aoc/Benchmark.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc
import kotlin.io.path.exists
import kotlin.io.path.readLines
import kotlin.system.measureTimeMillis
fun main(args: Array<String>) {
fun Puzzle.input() = defaultInput(year, day)
fun Puzzle.format() = "Year $year Day $day"
fun Puzzle.run() = SolveContext(this, input().readLines(... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 2,432 | advent-of-code | The Unlicense |
src/Day11.kt | arisaksen | 573,116,584 | false | {"Kotlin": 42887} | import org.assertj.core.api.Assertions.assertThat
// https://adventofcode.com/2022/day/11
fun main() {
data class Test(
var divisible: Long,
val ifTestTrue: Int,
val ifTestFalse: Int
)
data class Monkey(
val startingItems: MutableList<Long>,
val operation: List<Str... | 0 | Kotlin | 0 | 0 | 85da7e06b3355f2aa92847280c6cb334578c2463 | 5,152 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/jaspervanmerle/aoc2020/day/Day19.kt | jmerle | 317,518,472 | false | null | package com.jaspervanmerle.aoc2020.day
class Day19 : Day("285", "412") {
private val inputParts = getInput().split("\n\n")
private val rules = inputParts[0]
.lines()
.map {
val parts = it.split(": ")
parts[0].toInt() to parts[1]
}
.toMap()
.toMut... | 0 | Kotlin | 0 | 0 | 81765a46df89533842162f3bfc90f25511b4913e | 1,870 | advent-of-code-2020 | MIT License |
src/main/kotlin/com/github/dangerground/aoc2020/Day4.kt | dangerground | 317,439,198 | false | null | package com.github.dangerground.aoc2020
import com.github.dangerground.aoc2020.util.DayInput
import java.lang.Exception
class Day4(batches: List<List<String>>) {
var passports = batches.map { Passport(it) }
fun countPassportsWithRequiredField() = passports.filter { it.hasRequiredFields() }.count()
fun co... | 0 | Kotlin | 0 | 0 | c3667a2a8126d903d09176848b0e1d511d90fa79 | 3,118 | adventofcode-2020 | MIT License |
src/main/kotlin/com/github/amolkov/kotlin/algorithms/sorting/MergeSort.kt | amolkov | 122,844,991 | false | null | package com.github.amolkov.kotlin.algorithms.sorting
class MergeSort {
companion object {
/**
* Sorts the specified array into ascending order, according to the natural ordering of its elements,
* using the merge sort algorithm.
*
* @param arr the array to be sorted... | 0 | Kotlin | 0 | 0 | acb6bc2e397087fec8432b3307d0c0ea0c6ba75b | 1,363 | kotlin-algorithms | Apache License 2.0 |
src/main/kotlin/d17_TrickShot/TrickShot.kt | aormsby | 425,644,961 | false | {"Kotlin": 68415} | package d17_TrickShot
import util.Input
import util.Output
fun main() {
Output.day(17, "Trick Shot")
val startTime = Output.startTime()
val targetArea = Input.parseAllText(filename = "/input/d17_target_area.txt")
.split(',')
.map { it.substringAfter("=").split("..").map { n -> n.toInt() }... | 0 | Kotlin | 1 | 1 | 193d7b47085c3e84a1f24b11177206e82110bfad | 1,625 | advent-of-code-2021 | MIT License |
src/main/kotlin/com/leetcode/P959.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package com.leetcode
// https://github.com/antop-dev/algorithm/issues/286
class P959 {
fun regionsBySlashes(grid: Array<String>): Int {
val n = grid.size
val arr = Array(n * 3) { IntArray(n * 3) }
for (i in 0 until (n * n)) {
val p = intArrayOf(i / n * 3, i % n * 3)
... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,334 | algorithm | MIT License |
src/leetcodeProblem/leetcode/editor/en/RotateArray.kt | faniabdullah | 382,893,751 | false | null | //Given an array, rotate the array to the right by k steps, where k is non-
//negative.
//
//
// Example 1:
//
//
//Input: nums = [1,2,3,4,5,6,7], k = 3
//Output: [5,6,7,1,2,3,4]
//Explanation:
//rotate 1 steps to the right: [7,1,2,3,4,5,6]
//rotate 2 steps to the right: [6,7,1,2,3,4,5]
//rotate 3 steps to the righ... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 1,943 | dsa-kotlin | MIT License |
12.kts | pin2t | 725,922,444 | false | {"Kotlin": 48856, "Go": 48364, "Shell": 54} | import java.util.*
var springs: String = ""
var sizes: ArrayList<Int> = ArrayList<Int>()
val cache = HashMap<Pair<Int, Int>, Long>()
fun matched(prefix: String): Boolean {
return prefix.filterIndexed { index, c -> c == springs[index] || springs[index] == '?' }.count() == prefix.length
}
fun matches(prefix: String ... | 0 | Kotlin | 1 | 0 | 7575ab03cdadcd581acabd0b603a6f999119bbb6 | 1,508 | aoc2023 | MIT License |
src/main/kotlin/search/BinarySearch.kt | TheAlgorithms | 177,334,737 | false | {"Kotlin": 41212} | package search
/**
* Binary search is an algorithm which finds the position of a target value within an array (Sorted)
*
* Worst-case performance O(log(n))
* Best-case performance O(1)
* Average performance O(log(n))
* Worst-case space complexity O(1)
*/
/**
* @param array is an array where the element should... | 62 | Kotlin | 369 | 1,221 | e57a8888dec4454d39414082bbe6a672a9d27ad1 | 1,116 | Kotlin | MIT License |
src/Day04.kt | zt64 | 572,594,597 | false | null | fun main() {
val input = readInput("Day04")
fun part1(input: String): Int {
var fullyContaining = 0
input.lines().forEach { pair ->
val (elf1, elf2) = pair.split(",")
val (min1, max1) = elf1.split("-").map(String::toInt)
val (min2, max2) = elf2.split("-").m... | 0 | Kotlin | 0 | 0 | 4e4e7ed23d665b33eb10be59670b38d6a5af485d | 1,242 | aoc-2022 | Apache License 2.0 |
src/Day25.kt | MickyOR | 578,726,798 | false | {"Kotlin": 98785} | fun main() {
fun toDec(s: String): Long {
var ans: Long = 0
var pot: Long = 1
for (i in s.length - 1 downTo 0) {
if (s[i] == '=') {
ans -= 2*pot
}
else if (s[i] == '-') {
ans -= pot
}
else {
... | 0 | Kotlin | 0 | 0 | c24e763a1adaf0a35ed2fad8ccc4c315259827f0 | 1,663 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/year2015/day17/Day17.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2015.day17
import readInput
fun main() {
val input = readInput("2015", "Day17")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>) = getCombinations(input.toContainers(), 150).size
private fun part2(input: List<String>) = getCombinations(input.toContainers()... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 1,434 | AdventOfCode | Apache License 2.0 |
src/main/kotlin/days/Day4.kt | andilau | 726,429,411 | false | {"Kotlin": 37060} | package days
import kotlin.math.pow
@AdventOfCodePuzzle(
name = "Scratchcards",
url = "https://adventofcode.com/2023/day/4",
date = Date(day = 4, year = 2023)
)
class Day4(input: List<String>) : Puzzle {
private val scratchcards = input.map { Scratchcard.from(it) }
override fun partOne(): Int = ... | 3 | Kotlin | 0 | 0 | 9a1f13a9815ab42d7fd1d9e6048085038d26da90 | 1,498 | advent-of-code-2023 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/aoc2020/ex17.kt | noamfree | 433,962,392 | false | {"Kotlin": 93533} | fun main() {
val input = readInputFile("aoc2020/input17")
// val input = """
// .#.
// ..#
// ###
// """.trimIndent()
val cubes = input.lines().flatMapIndexed { r, rowString ->
rowString.mapIndexed { c, char ->
if (char == '#') {
Vector4(c,r,0, 0)
... | 0 | Kotlin | 0 | 0 | 566cbb2ef2caaf77c349822f42153badc36565b7 | 3,730 | AOC-2021 | MIT License |
src/Day07.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | sealed interface FSEntry {
val name: String
val parent: FSEntry?
}
data class FSFile(override val name: String, val size: Int, override val parent: FSEntry?) : FSEntry
class FSDir(override val name: String, override val parent: FSDir?) : FSEntry {
private val entries = mutableMapOf<String, FSEntry>()
... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 4,197 | aoc2022 | Apache License 2.0 |
src/main/kotlin/g0801_0900/s0839_similar_string_groups/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0839_similar_string_groups
// #Hard #Array #String #Depth_First_Search #Breadth_First_Search #Union_Find
// #2023_03_28_Time_205_ms_(100.00%)_Space_35.9_MB_(100.00%)
import java.util.LinkedList
import java.util.Queue
class Solution {
fun numSimilarGroups(strs: Array<String>): Int {
va... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,644 | LeetCode-in-Kotlin | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.