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/be/brammeerten/graphs/AStar.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.graphs
import java.util.function.Function
object AStar {
fun <K, V> findShortestPath(graph: Graph<K, V>, start: K, end: K,
h: Function<Pair<K, K>, Double>,
cache: HashMap<Pair<K, K>, List<Node<K, V>>?>? = null): List<Node<K, V>... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 2,411 | Advent-of-Code | MIT License |
atcoder/arc154/c.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package atcoder.arc154
private fun solve(): Boolean {
val (_, a, b) = List(3) { readInts() }
if (a == b) return true
if (b.toSet().size == 1) return b[0] in a
val want = b.filterIndexed { i, it -> it != b.getCycled(i + 1) }
if (want.size == b.size) return false
for (aShifted in a.allShifts()) {
var k = 0
for... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,022 | competitions | The Unlicense |
src/day11/Day11.kt | Ciel-MC | 572,868,010 | false | {"Kotlin": 55885} | package day11
import day11.Monkey.Companion.parseMonkeys
import readInput
import java.util.ArrayDeque
import java.util.Queue
data class Monkey(
val id: MonkeyID,
val holdingItems: Queue<Item>,
val itemOperation: (Item) -> Unit,
val rule: ThrowRule
) {
fun processItems(divideByThree: Boolean, keepI... | 0 | Kotlin | 0 | 0 | 7eb57c9bced945dcad4750a7cc4835e56d20cbc8 | 6,481 | Advent-Of-Code | Apache License 2.0 |
Insert_Interval.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 kotlin.math.max
import kotlin.math.min
class Solution {
fun insert(intervals: Array<IntArray>, newInterval: IntArray): Array<IntArray> {
val result = ArrayList<IntArray>()
var i = 0
while (i < intervals.size && intervals[i][1] < newInterval[0]) {
result.add(intervals[i])
... | 0 | C++ | 0 | 0 | eb5b6814e8ba0847f0b36aec9ab63bcf1bbbc134 | 1,520 | leetcode | MIT License |
kotlin/127.Word Ladder(单词接龙).kt | learningtheory | 141,790,045 | false | {"Python": 4025652, "C++": 1999023, "Java": 1995266, "JavaScript": 1990554, "C": 1979022, "Ruby": 1970980, "Scala": 1925110, "Kotlin": 1917691, "Go": 1898079, "Swift": 1827809, "HTML": 124958, "Shell": 7944} | /**
<p>Given two words (<em>beginWord</em> and <em>endWord</em>), and a dictionary's word list, find the length of shortest transformation sequence from <em>beginWord</em> to <em>endWord</em>, such that:</p>
<ol>
<li>Only one letter can be changed at a time.</li>
<li>Each transformed word must exist in the word ... | 0 | Python | 1 | 3 | 6731e128be0fd3c0bdfe885c1a409ac54b929597 | 4,818 | leetcode | MIT License |
src/main/kotlin/io/undefined/FriendOfAppropriateAges.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.undefined
import io.utils.runTests
// https://leetcode.com/problems/friends-of-appropriate-ages/
class FriendOfAppropriateAges {
fun execute(input: IntArray): Int {
val count = input.fold(IntArray(121)) { acc, value -> acc.apply { this[value]++ } }
var result = 0
count.forEachIndexed { ageA,... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,244 | coding | MIT License |
src/main/kotlin/io/github/t45k/scm/matching/algorithms/rollingHash/RollingHash.kt | T45K | 255,912,849 | false | null | package io.github.t45k.scm.matching.algorithms.rollingHash
import io.github.t45k.scm.entity.TokenSequence
import io.github.t45k.scm.matching.algorithms.StringSearchAlgorithm
class RollingHash(query: TokenSequence) : StringSearchAlgorithm(query) {
private val querySize: Int = query.size
private val memo: Lis... | 0 | Kotlin | 0 | 0 | 37b3ffac9bdf6e24a3fc3ae9282f3f692ec8d12d | 1,663 | SCM | MIT License |
common/geometry/src/main/kotlin/com/curtislb/adventofcode/common/geometry/Ray.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.common.geometry
import com.curtislb.adventofcode.common.number.Fraction
/**
* A unique representation of a ray with a given origin and direction in a 2D grid.
*
* @property source The origin point of the ray.
* @property slope The slope of the ray, or `null` if its slope is infin... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 3,255 | AdventOfCode | MIT License |
src/main/kotlin/at/mpichler/aoc/solutions/year2021/Day13.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2021
import at.mpichler.aoc.lib.*
import org.jetbrains.kotlinx.multik.api.mk
import org.jetbrains.kotlinx.multik.api.zeros
import org.jetbrains.kotlinx.multik.ndarray.data.get
import org.jetbrains.kotlinx.multik.ndarray.operations.toList
open class Part13A : PartSolution() {
... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 3,462 | advent-of-code-kotlin | MIT License |
src/main/kotlin/twentytwenty/DayOne.kt | philspins | 318,606,184 | false | null | package twentytwenty
import java.io.File
import java.nio.file.Paths
class DayOne {
private var inputList: ArrayList<Int> = ArrayList<Int>()
internal var partOneAnswer: Int = 0
internal var partTwoAnswer: Int = 0
fun loadInputFile(filename: String) {
val path = Paths.get("").toAbsolutePath()... | 0 | Kotlin | 0 | 0 | 138eac749657475ff93e82a5a4f667f9c249411f | 2,005 | adventofcode | MIT License |
src/main/kotlin/io/github/clechasseur/adventofcode/y2022/Day20.kt | clechasseur | 567,968,171 | false | {"Kotlin": 493887} | package io.github.clechasseur.adventofcode.y2022
import io.github.clechasseur.adventofcode.y2022.data.Day20Data
object Day20 {
private val input = Day20Data.input
private const val decryptionKey = 811589153L
fun part1(): Long = findGrove(input.lines().map { it.toLong() }, 1)
fun part2(): Long = fin... | 0 | Kotlin | 0 | 0 | 7ead7db6491d6fba2479cd604f684f0f8c1e450f | 3,046 | adventofcode2022 | MIT License |
src/main/kotlin/nl/jackploeg/aoc/_2022/calendar/day19/Day19.kt | jackploeg | 736,755,380 | false | {"Kotlin": 318734} | package nl.jackploeg.aoc._2022.calendar.day19
import nl.jackploeg.aoc._2022.calendar.day19.Day19.Robot.*
import javax.inject.Inject
import nl.jackploeg.aoc.generators.InputGenerator.InputGeneratorFactory
import nl.jackploeg.aoc.utilities.readStringFile
import java.util.*
import kotlin.math.max
class Day19 @Inject co... | 0 | Kotlin | 0 | 0 | f2b873b6cf24bf95a4ba3d0e4f6e007b96423b76 | 13,893 | advent-of-code | MIT License |
src/2022/Day17.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2022`
import common.*
import common.Linearizer
import common.Offset
import java.io.File
import java.math.BigInteger
import java.util.*
import kotlin.collections.List
fun main() {
Day17().solve()
}
class Day17 {
val input1 = """
>>><<><>><<<>><>>><<<>>><<<><<<>><>><<>>
""".trimIndent()
... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 12,132 | advent-of-code | Apache License 2.0 |
src/day05/day05.kt | jimsaidov | 572,881,855 | false | {"Kotlin": 10629} | package day05
class Day05(private val input: List<String>) {
private data class MoveInstruction(val amount: Int, val fromIndex: Int, val toIndex: Int)
private val moveInstructions: List<MoveInstruction> =
input.drop(input.indexOf("") + 1)
.map { row ->
row.split(" ").let {... | 0 | Kotlin | 0 | 0 | d4eb926b57460d4ba4acced14658f211e1ccc12c | 1,740 | aoc2022 | Apache License 2.0 |
src/main/kotlin/Day08.kt | arosenf | 726,114,493 | false | {"Kotlin": 40487} | import kotlin.system.exitProcess
fun main(args: Array<String>) {
if (args.isEmpty() or (args.size < 2)) {
println("Hands not specified")
exitProcess(1)
}
val fileName = args.first()
println("Reading $fileName")
val lines = readLines(fileName)
val result =
if (args[1] ==... | 0 | Kotlin | 0 | 0 | d9ce83ee89db7081cf7c14bcad09e1348d9059cb | 3,992 | adventofcode2023 | MIT License |
src/Day06.kt | ajesh-n | 573,125,760 | false | {"Kotlin": 8882} | fun main() {
fun part1(input: List<String>): Int {
val markerStart = input[0].windowed(4, 1).find {
it.toCharArray().distinct().count() == 4
}
return input[0].indexOf(markerStart!!) + 4
}
fun part2(input: List<String>): Int {
val markerStart = input[0].windowed(1... | 0 | Kotlin | 0 | 0 | 2545773d7118da20abbc4243c4ccbf9330c4a187 | 657 | kotlin-aoc-2022 | Apache License 2.0 |
app/src/main/java/com/themobilecoder/adventofcode/day8/DayEightUtils.kt | themobilecoder | 726,690,255 | false | {"Kotlin": 323477} | package com.themobilecoder.adventofcode.day8
import com.themobilecoder.adventofcode.splitByNewLine
fun String.buildMapDirections(): Map<String, Pair<String, String>> {
val lines = splitByNewLine().filter { it.isNotBlank() }.drop(1)
val map = mutableMapOf<String, Pair<String, String>>()
lines.forEach { lin... | 0 | Kotlin | 0 | 0 | b7770e1f912f52d7a6b0d13871f934096cf8e1aa | 1,468 | Advent-of-Code-2023 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ConsecutiveCharacters.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 | 1,588 | kotlab | Apache License 2.0 |
src/main/kotlin/com/sherepenko/leetcode/data/TreeNode.kt | asherepenko | 264,648,984 | false | null | package com.sherepenko.leetcode.data
import kotlin.math.max
const val TREE_INDENTATION = 10
enum class Traversal {
PRE_ORDER,
IN_ORDER,
POST_ORDER,
LEVEL_ORDER
}
data class TreeNode(
val value: Int,
var left: TreeNode? = null,
var right: TreeNode? = null
) {
override fun toString(): ... | 0 | Kotlin | 0 | 0 | 49e676f13bf58f16ba093f73a52d49f2d6d5ee1c | 3,059 | leetcode | The Unlicense |
AoC2021day10-SintaxScoring/src/main/kotlin/Main.kt | mcrispim | 533,770,397 | false | {"Kotlin": 29888} | import java.io.File
val closeChar = mapOf(')' to '(', ']' to '[', '}' to '{', '>' to '<')
val openChar = mapOf('(' to ')', '[' to ']', '{' to '}', '<' to '>')
val openings = closeChar.values
enum class LineType {
CORRUPTED,
INCOMPLETE,
CORRECT,
}
class Line(val type: LineType, val problemChars: List<Char... | 0 | Kotlin | 0 | 0 | ac4aa71c9b5955fa4077ae40fc7e3fc3d5242523 | 2,479 | AoC2021 | MIT License |
src/day21/Day21.kt | crmitchelmore | 576,065,911 | false | {"Kotlin": 115199} | package day21
import helpers.ReadFile
import java.math.BigDecimal
class Day21 {
val tlines = listOf(
"root: pppw + sjmn",
"dbpl: 5",
"cczh: sllz + lgvd",
"zczc: 2",
"ptdq: humn - dvpt",
"dvpt: 3",
"lfqf: 4",
... | 0 | Kotlin | 0 | 0 | fd644d442b5ff0d2f05fbf6317c61ee9ce7b4470 | 3,104 | adventofcode2022 | MIT License |
src/main/kotlin/test1/task2.kt | IgorFilimonov | 342,322,388 | false | null | package test1
fun displayHints() {
println("What do you want to do?\n" +
"1. Add element\n" +
"2. Find out if there is an element\n" +
"3. Remove element\n" +
"4. Find out the number of elements\n" +
"5. Find out the number of elements starting with a giv... | 1 | Kotlin | 0 | 0 | bb8c6e54e738ac403062e8f62caea846d7efb1f9 | 1,924 | spbu_2020_kotlin_homeworks | Apache License 2.0 |
src/main/kotlin/cloud/dqn/leetcode/PalindromeNumberKt.kt | aviuswen | 112,305,062 | false | null | package cloud.dqn.leetcode
/**
* https://leetcode.com/problems/palindrome-number/description/
*
* Determine whether an integer is a palindrome. Do this without extra space.
*/
class PalindromeNumberKt {
class Solution {
/**
Assumption: "Do this without extra space" =>
no other c... | 0 | Kotlin | 0 | 0 | 23458b98104fa5d32efe811c3d2d4c1578b67f4b | 2,395 | cloud-dqn-leetcode | No Limit Public License |
src/test/kotlin/br/com/colman/kaucasus/DoubleStatisticsTest.kt | LeoColman | 364,760,768 | true | {"Kotlin": 110184} | package br.com.colman.kaucasus
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.maps.shouldContainAll
import io.kotest.matchers.shouldBe
class DoubleStatisticsTest : FunSpec({
val doubleVector = sequenceOf(0.0, 1.0, 3.0, 5.0, 11.0)
val gr... | 3 | Kotlin | 0 | 3 | 08187a786cf34002e2c65022d39e44250db5e253 | 1,821 | Kaucasus | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/KokoEatingBananas.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,390 | kotlab | Apache License 2.0 |
Kotlin/src/SearchInRotatedSortedArrayII.kt | TonnyL | 106,459,115 | false | null | import java.util.Arrays
/**
* Follow up for "Search in Rotated Sorted Array":
* What if duplicates are allowed?
*
* Would this affect the run-time complexity? How and why?
*
* Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
*
* (i.e., 0 1 2 4 5 6 7 might become 4 ... | 1 | Swift | 22 | 189 | 39f85cdedaaf5b85f7ce842ecef975301fc974cf | 1,522 | Windary | MIT License |
src/main/kotlin/g2201_2300/s2212_maximum_points_in_an_archery_competition/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2201_2300.s2212_maximum_points_in_an_archery_competition
// #Medium #Array #Bit_Manipulation #Recursion #Enumeration
// #2023_06_27_Time_210_ms_(100.00%)_Space_34.4_MB_(100.00%)
class Solution {
private val ans = IntArray(12)
private val ans1 = IntArray(12)
private var max = 0
fun maximumBobP... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,083 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/bk65/Problem1.kt | yvelianyk | 405,919,452 | false | {"Kotlin": 147854, "Java": 610} | package bk65
import kotlin.math.abs
fun main() {
// "aaaa"
// "bccb"
val resul = Problem1().checkAlmostEquivalent("aaaa", "bccb")
println(resul)
}
class Problem1 {
fun checkAlmostEquivalent(word1: String, word2: String): Boolean {
val map1 = word1.toCharArray().toList().groupingBy { it }.e... | 0 | Kotlin | 0 | 0 | 780d6597d0f29154b3c2fb7850a8b1b8c7ee4bcd | 1,067 | leetcode-kotlin | MIT License |
advent/src/test/kotlin/org/elwaxoro/advent/y2022/Dec19.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2022
import org.elwaxoro.advent.PuzzleDayTester
/**
* Give up hope looking at this. was refactoring for smarter solvers but didn't keep the original working solver :(
*/
class Dec19 : PuzzleDayTester(19, 2022) {
override fun part1(): Any = "lost"
override fun part2(): Any = "lo... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 7,103 | advent-of-code | MIT License |
src/main/kotlin/day25/Day25.kt | jakubgwozdz | 571,298,326 | false | {"Kotlin": 85100} | package day25
import execute
import readAllText
fun part1(input: String) = input.lineSequence()
.sumOf(::decode)
.let(::encode)
private const val DIGITS = "=-012"
private fun decode(line: String) = line.fold(0L) { acc, c ->
acc * 5 + DIGITS.indexOf(c) - 2
}
private fun encode(number: Long) = buildStri... | 0 | Kotlin | 0 | 0 | 7589942906f9f524018c130b0be8976c824c4c2a | 863 | advent-of-code-2022 | MIT License |
aoc_2023/src/main/kotlin/problems/day25/GroupDividider.kt | Cavitedev | 725,682,393 | false | {"Kotlin": 228779} | package problems.day25
class GroupDividider(val snowMachine: SnowMachine, val disconnectWires: Int) {
fun divideIn2Groups(): List<Set<Component>> {
val group1 = mutableSetOf<Component>()
val group2 = mutableSetOf<Component>()
val visitedPairs = mutableSetOf<ComponentPair>()
val ... | 0 | Kotlin | 0 | 1 | aa7af2d5aa0eb30df4563c513956ed41f18791d5 | 3,104 | advent-of-code-2023 | MIT License |
src/main/kotlin/aoc2019/day22_slam_shuffle/Op.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package aoc2019.day22_slam_shuffle
import util.modularInverse as modInv
import util.modularMultiply as modMult
internal interface Op {
fun forward(card: Long): Long
fun reverse(card: Long): Long
}
internal data class Cut(val deckSize: Long, val n: Long) : Op {
override fun forward(card: Long) =
... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 3,032 | aoc-2021 | MIT License |
src/main/kotlin/g2501_2600/s2573_find_the_string_with_lcp/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2501_2600.s2573_find_the_string_with_lcp
// #Hard #String #Dynamic_Programming #Greedy #Union_Find
// #2023_07_10_Time_853_ms_(100.00%)_Space_147.3_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
fun findTheString(lcp: Array<IntArray>): String {
val n = lcp.size
val parent = Int... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,073 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/utils/utils.kt | corneil | 572,437,852 | false | {"Kotlin": 93311, "Shell": 595} | package utils
import java.io.File
import java.math.BigInteger
/**
* Reads lines from the given input txt file.
* @param name The name of the file to read
*/
fun readFile(name: String) = File("src/main/resources", "$name.txt").readLines()
/**
* Reads whole file into a text string
* @param name The name of the fi... | 0 | Kotlin | 0 | 0 | dd79aed1ecc65654cdaa9bc419d44043aee244b2 | 4,689 | aoc-2022-in-kotlin | Apache License 2.0 |
KVServer/src/main/kotlin/com/arist/Trie.kt | ArisPoz | 354,646,175 | false | null | package com.arist
import java.lang.StringBuilder
/**
* @author arist
*/
data class Trie(val root: TrieNode = TrieNode(), val fin: Boolean = false) {
data class TrieNode
(var fin: Boolean = false, var subNodes: MutableMap<Char, TrieNode> = HashMap())
fun put(key: String) {
var currentNode =... | 0 | Kotlin | 0 | 1 | 0e9b97c35f8bb73cb7e8a4bc1c97f36bc2a08578 | 4,053 | KVStore | MIT License |
src/main/kotlin/d1/d1.kt | LaurentJeanpierre1 | 573,454,829 | false | {"Kotlin": 118105} | package d1
import readInput
fun part1(input: List<String>): Int {
val elves = ArrayList<Int>()
var sum = 0
for (line in input) {
if (line.isBlank()) {
if (sum > 0)
elves += sum
sum = 0
} else {
sum += line.toInt()
}
}
if (... | 0 | Kotlin | 0 | 0 | 5cf6b2142df6082ddd7d94f2dbde037f1fe0508f | 850 | aoc2022 | Creative Commons Zero v1.0 Universal |
src/aoc2022/Day02.kt | nguyen-anthony | 572,781,123 | false | null | package aoc2022
import utils.readInputAsList
fun main() {
val part1results = mapOf(
"A X" to 3+1,
"A Y" to 6+2,
"A Z" to 0+3,
"B X" to 0+1,
"B Y" to 3+2,
"B Z" to 6+3,
"C X" to 6+1,
"C Y" to 0+2,
"C Z" to 3+3
)
val part2results = ma... | 0 | Kotlin | 0 | 0 | 9336088f904e92d801d95abeb53396a2ff01166f | 1,185 | AOC-2022-Kotlin | Apache License 2.0 |
src/day14/Solution.kt | chipnesh | 572,700,723 | false | {"Kotlin": 48016} | package day14
import Coords
import below
import day14.PointType.ABYSS
import day14.PointType.AIR
import day14.PointType.ROCK
import day14.PointType.SAND
import day14.PointType.SOURCE
import get
import leftDown
import readInput
import rightDown
import splitEach
import toPair
fun main() {
fun part1(input: List<Str... | 0 | Kotlin | 0 | 1 | 2d0482102ccc3f0d8ec8e191adffcfe7475874f5 | 5,493 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/day5/day5.kt | lavong | 317,978,236 | false | null | /*
--- Day 5: Binary Boarding ---
You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.
You write a quick program to use your phone's ... | 0 | Kotlin | 0 | 1 | a4ccec64a614d73edb4b9c4d4a72c55f04a4b77f | 4,030 | adventofcode-2020 | MIT License |
src/main/kotlin/de/niemeyer/aoc2022/Day07.kt | stefanniemeyer | 572,897,543 | false | {"Kotlin": 175820, "Shell": 133} | package de.niemeyer.aoc2022
/**
* Advent of Code 2022, Day 7: No Space Left On Device
* Problem Description: https://adventofcode.com/2022/day/7
*/
import de.niemeyer.aoc.utils.Resources.resourceAsList
import de.niemeyer.aoc.utils.getClassName
fun main() {
fun part1(input: List<String>): Long =
Comput... | 0 | Kotlin | 0 | 0 | ed762a391d63d345df5d142aa623bff34b794511 | 4,699 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/days/Day17.kt | TheMrMilchmann | 725,205,189 | false | {"Kotlin": 61669} | /*
* Copyright (c) 2023 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, dis... | 0 | Kotlin | 0 | 1 | f94ff8a4c9fefb71e3ea183dbc3a1d41e6503152 | 3,798 | AdventOfCode2023 | MIT License |
src/day01/Day01.kt | chskela | 574,228,146 | false | {"Kotlin": 9406} | package day01
import java.io.File
import java.util.PriorityQueue
fun main() {
fun parseInput(input: String) = input.split("\n\n").map { str ->
str.lines().map { it.toInt() }
}
fun List<List<Int>>.topNElves(n: Int): Int {
val best = PriorityQueue<Int>()
for (calories in map { it.su... | 0 | Kotlin | 0 | 0 | 951d38a894dcf0109fd0847eef9ff3ed3293fca0 | 1,049 | adventofcode-2022-kotlin | Apache License 2.0 |
src/main/kotlin/recur/WeightedMedian.kt | yx-z | 106,589,674 | false | null | package recur
import util.*
import kotlin.math.floor
// given an unsorted array S[1..n] of (value, weight)
// find weighted median S[i] : total weight of elements that has value < S[i]_1
// is less than half of the total weight of S
// similarly, total weight of elements that has value > S[i]_1 is also less than
// h... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 1,322 | AlgoKt | MIT License |
kotlinx-collections-experimental/src/main/kotlin/kotlinx.collections.experimental/grouping/groupFold.kt | ilya-g | 62,652,856 | false | null | package kotlinx.collections.experimental.grouping
public inline fun <T, K, R> Iterable<T>.groupAggregateBy(keySelector: (T) -> K, operation: (key: K, value: R?, element: T, first: Boolean) -> R): Map<K, R> {
val result = mutableMapOf<K, R>()
for (e in this) {
val key = keySelector(e)
val valu... | 0 | Kotlin | 3 | 1 | 41f2385b3921977329b0216ebcecc81d85ec7cb5 | 3,285 | kotlinx.collections.experimental | Apache License 2.0 |
src/main/kotlin/g2001_2100/s2097_valid_arrangement_of_pairs/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2097_valid_arrangement_of_pairs
// #Hard #Depth_First_Search #Graph #Eulerian_Circuit
// #2023_06_28_Time_2120_ms_(100.00%)_Space_143.1_MB_(100.00%)
import java.util.LinkedList
import java.util.Queue
@Suppress("NAME_SHADOWING")
class Solution {
fun validArrangement(pairs: Array<IntArray>): Ar... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,929 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/Day17.kt | i-redbyte | 433,743,675 | false | {"Kotlin": 49932} | fun main() {
val data = readInputFile("day17")
val (xr, yr) = data.first().removePrefix("target area: ").split(", ")
val (x1, x2) = xr.removePrefix("x=").split("..").map { it.toInt() }
val (y1, y2) = yr.removePrefix("y=").split("..").map { it.toInt() }
fun part1(): Int {
var result = 0
... | 0 | Kotlin | 0 | 0 | 6d4f19df3b7cb1906052b80a4058fa394a12740f | 1,791 | AOC2021 | Apache License 2.0 |
src/main/kotlin/tr/emreone/adventofcode/days/Day7.kt | EmRe-One | 434,793,519 | false | {"Kotlin": 44202} | package tr.emreone.adventofcode.days
@OptIn(ExperimentalUnsignedTypes::class)
object Day7 {
class Instruction(val variable: String, val operation: (vars: UShortArray) -> UShort, vararg val parameter: String) {
var value: UShort? = null
fun execute(vars: UShortArray): UShort {
if (valu... | 0 | Kotlin | 0 | 0 | 57f6dea222f4f3e97b697b3b0c7af58f01fc4f53 | 3,755 | advent-of-code-2015 | Apache License 2.0 |
src/main/kotlin/sschr15/aocsolutions/Day1.kt | sschr15 | 317,887,086 | false | {"Kotlin": 184127, "TeX": 2614, "Python": 446} | package sschr15.aocsolutions
import sschr15.aocsolutions.util.Challenge
import sschr15.aocsolutions.util.ReflectivelyUsed
import sschr15.aocsolutions.util.challenge
import sschr15.aocsolutions.util.ints
import sschr15.aocsolutions.util.watched.sum
/**
* AOC 2023 [Day 1](https://adventofcode.com/2023/day/1)
* Challe... | 0 | Kotlin | 0 | 0 | e483b02037ae5f025fc34367cb477fabe54a6578 | 1,555 | advent-of-code | MIT License |
2022/src/test/kotlin/Day03.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
class Day03 : StringSpec({
"puzzle part 01" {
val sumOfPriorities = getPuzzleInput("day03-input.txt")
.map { it.duplicated() }
.sumOf { it.priority() }
sumOfPriorities shouldBe 7446
}
"p... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 916 | adventofcode | MIT License |
src/main/kotlin/day6/Day6.kt | mortenberg80 | 574,042,993 | false | {"Kotlin": 50107} | package day6
class Day6(val input: String) {
private val listOfWindows = (0..input.length-4).map { input.substring(it, it+4) }
private val messageMarkerWindows = (0..input.length-14).map { input.substring(it, it+14) }
fun startOfPacket(): Int {
return listOfWindows.indexOfFirst { !it.contains... | 0 | Kotlin | 0 | 0 | b21978e145dae120621e54403b14b81663f93cd8 | 1,596 | adventofcode2022 | Apache License 2.0 |
kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/ints.kt | ca-r0-l | 258,232,982 | true | {"Kotlin": 2272378, "HTML": 423, "Java": 153} | package io.kotest.property.arbitrary
import io.kotest.property.Shrinker
import kotlin.math.abs
import kotlin.random.nextInt
import io.kotest.property.Arb
fun Arb.Companion.int(min: Int, max: Int) = int(min..max)
/**
* Returns an [Arb] where each value is a randomly chosen [Int] in the given range.
* The edgecases ... | 1 | null | 0 | 1 | e176cc3e14364d74ee593533b50eb9b08df1f5d1 | 1,766 | kotest | Apache License 2.0 |
hoon/HoonAlgorithm/src/main/kotlin/programmers/lv01/Lv1_12950.kt | boris920308 | 618,428,844 | false | {"Kotlin": 137657, "Swift": 35553, "Java": 1947, "Rich Text Format": 407} | package main.kotlin.programmers.lv01
/**
*
* https://school.programmers.co.kr/learn/courses/30/lessons/12950
*
* 행렬의 덧셈
* 문제 설명
* 행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다.
* 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요.
*
* 제한 조건
* 행렬 arr1, arr2의 행과 열의 길이는 500을 넘지 않습니다.
* 입출력... | 1 | Kotlin | 1 | 2 | 88814681f7ded76e8aa0fa7b85fe472769e760b4 | 1,136 | HoOne | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DeleteAndEarn.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 | 5,995 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/UnequalTriplets.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,337 | kotlab | Apache License 2.0 |
src/Day02.kt | guilherme | 574,434,377 | false | {"Kotlin": 7468} | import java.lang.RuntimeException
enum class RoundResult(val score: Int) {
LOST(0),
DRAW(3),
WIN(6);
companion object {
fun fromString(input: String): RoundResult {
// X means you need to lose,
// Y means you need to end the round in a draw,
// and Z means you need to win.
return w... | 0 | Kotlin | 0 | 3 | dfc0cee1d023be895f265623bec130386ed12f05 | 3,904 | advent-of-code | Apache License 2.0 |
src/day8/subarraySumAlgorithm.kt | minielectron | 332,678,510 | false | {"Java": 127791, "Kotlin": 48336} | package day8
// Problem : Given an datastructure.array of integers, you have find if there are two numbers whose sum is equal to k.
// 2 Sum - k=2
class subarraySumAlgorithm {
fun findTwoSum(a: IntArray, k: Int): Boolean {
var end = a.size - 1
var start = 0
a.sort()
while (start <... | 0 | Java | 0 | 0 | f2aaff0a995071d6e188ee19f72b78d07688a672 | 1,291 | data-structure-and-coding-problems | Apache License 2.0 |
Unprimeable_numbers/Kotlin/src/main/kotlin/UnprimeableNumbers.kt | ncoe | 108,064,933 | false | {"D": 425100, "Java": 399306, "Visual Basic .NET": 343987, "C++": 328611, "C#": 289790, "C": 216950, "Kotlin": 162468, "Modula-2": 148295, "Groovy": 146721, "Lua": 139015, "Ruby": 84703, "LLVM": 58530, "Python": 46744, "Scala": 43213, "F#": 21133, "Perl": 13407, "JavaScript": 6729, "CSS": 453, "HTML": 409} | private const val MAX = 10000000
private val primes = BooleanArray(MAX)
fun main() {
sieve()
println("First 35 unprimeable numbers:")
displayUnprimeableNumbers(35)
val n = 600
println()
println("The ${n}th unprimeable number = ${nthUnprimeableNumber(n)}")
println()
val lowest = genLowes... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 2,088 | rosetta | MIT License |
libraries/gemoji/src/main/kotlin/io/sweers/catchup/gemoji/EmojiMarkdownConverter.kt | pyricau | 224,052,604 | false | null | /*
* Copyright (C) 2019. <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 ... | 2 | Kotlin | 3 | 29 | d5629cf6ebdea64099e0f46e5290328c73b54bef | 3,760 | CatchLeaks | Apache License 2.0 |
src/day04.kts | miedzinski | 434,902,353 | false | {"Kotlin": 22560, "Shell": 113} | data class Board(val rows: List<List<Int>>) {
val columns: List<List<Int>> by lazy {
(0 until rows.size).map { col -> (0 until rows.size).map { row -> rows[row][col] } }
}
}
val boardSize = 5
val allDraws = readLine()!!.split(',').map(String::toInt).toList()
var boards = generateSequence(::readLine).c... | 0 | Kotlin | 0 | 0 | 6f32adaba058460f1a9bb6a866ff424912aece2e | 972 | aoc2021 | The Unlicense |
src/main/kotlin/days/aoc2021/Day14.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2021
import days.Day
class Day14 : Day(2021, 14) {
override fun partOne(): Any {
return findDeltaBetweenMostAndLeastCommonElements2(inputList, 10)
}
override fun partTwo(): Any {
return findDeltaBetweenMostAndLeastCommonElements2(inputList, 40)
}
// idiot version
... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 3,151 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/2020/Day4_2.kts | Ozsie | 318,802,874 | false | {"Kotlin": 99344, "Python": 1723, "Shell": 975} | import java.io.File
import kotlin.collections.ArrayList
import kotlin.text.Regex
val fields = listOf("byr","iyr","eyr","hgt","hcl","ecl","pid")
val eyes = listOf("amb","blu","brn","gry","grn","hzl","oth")
var passportList = ArrayList<String>()
var passport = ""
File("input/2020/day4").forEachLine {
passport = if (!... | 0 | Kotlin | 0 | 0 | d938da57785d35fdaba62269cffc7487de67ac0a | 1,390 | adventofcode | MIT License |
domain/src/main/kotlin/com/seanshubin/kotlin/tryme/domain/schulze/Schulze.kt | SeanShubin | 228,113,855 | false | null | package com.seanshubin.kotlin.tryme.domain.schulze
import kotlin.math.max
import kotlin.math.min
object Schulze {
fun schulzeTally(candidates: List<String>, rows: List<List<Int>>): List<Pair<String, List<String>>> {
val strongestPaths = strongestPaths(rows)
val tallied = tally(strongestPaths, empt... | 0 | Kotlin | 0 | 0 | abc67c5f43c01bdf55c6d4adcf05b77610c0473a | 2,440 | kotlin-tryme | The Unlicense |
src/iii_conventions/MyDate.kt | dgyordanov | 144,988,264 | false | null | package iii_conventions
data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate> {
override fun compareTo(other: MyDate): Int {
return when {
year != other.year -> year - other.year
month != other.month -> month - other.month
else -> day... | 0 | Kotlin | 0 | 0 | 9e1042c8ca3de4a3ee759d89f5fb23930f836b51 | 1,425 | kotlin-koans | MIT License |
src/main/kotlin/novah/data/DAG.kt | stackoverflow | 255,379,925 | false | null | /**
* 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 | 9 | f3f2b12e178c5288197f6c6d591e8d304f5baf5d | 3,864 | novah | Apache License 2.0 |
src/main/kotlin/g1301_1400/s1363_largest_multiple_of_three/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1301_1400.s1363_largest_multiple_of_three
// #Hard #Array #Dynamic_Programming #Greedy
// #2023_06_06_Time_267_ms_(100.00%)_Space_39.5_MB_(100.00%)
class Solution {
fun largestMultipleOfThree(digits: IntArray): String {
var sum = 0
val count = IntArray(10)
// Here we are using the... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,151 | LeetCode-in-Kotlin | MIT License |
src/model/Grid.kt | NOWUM | 358,732,934 | false | {"Kotlin": 245354, "TypeScript": 141516, "CSS": 4266, "HTML": 1721, "Dockerfile": 329} | package de.fhac.ewi.model
import de.fhac.ewi.exceptions.IllegalGridException
import de.fhac.ewi.util.DoubleFunction
import de.fhac.ewi.util.repeatEach
class Grid {
private val _nodes = mutableListOf<Node>()
val nodes: List<Node>
get() = _nodes.toList()
private val _pipes = mutableListOf<Pipe>()
... | 18 | Kotlin | 0 | 4 | 7c65a8c372df6e3e8b1f2e1c4bc5833ba3dda987 | 4,183 | grid-optimizer | MIT License |
src/Day03.kt | becsegal | 573,649,289 | false | {"Kotlin": 9779} | import java.io.File
fun main() {
val letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
fun mispackedCharacter(contents: String): String {
val compartmentAContents: CharArray = contents.substring(0, contents.length/2).toCharArray()
val compartmentBContents: CharArray = contents.... | 0 | Kotlin | 0 | 0 | a4b744a3e3c940c382aaa1d5f5c93ae0df124179 | 1,611 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/sk/set0/78. Subsets.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.set0
import kotlin.math.pow
class Solution78 {
// Backtracking
fun subsets(nums: IntArray): List<List<Int>> {
val ans = mutableListOf<List<Int>>()
fun backtrack(tmpList: MutableList<Int>, start: Int) {
ans.add(tmpList.toList()) // copy it and add it to answer
... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,636 | leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/solved/p289/InPlaceSolution.kt | mr-nothing | 469,475,608 | false | {"Kotlin": 162430} | package solved.p289
/** The idea is that we will store in original array:
* -1 for dead-alive transition
* 0 for dead-dead transition
* 1 for alive-alive transition
* 2 for alive-dead transition
*/
class InPlaceSolution {
class Solution {
fun gameOfLife(board: Array<IntArray>) {
... | 0 | Kotlin | 0 | 0 | 0f7418ecc8675d8361ef31cbc1ee26ea51f7708a | 2,187 | leetcode | Apache License 2.0 |
src/main/kotlin/dev/paulshields/aoc/day14/DockingData.kt | Pkshields | 318,658,287 | false | null | package dev.paulshields.aoc.day14
import dev.paulshields.aoc.common.readFileAsStringList
val valueSetCaptureRegex = Regex("mem\\[(\\d+)] = (\\d+)")
fun main() {
val program = readFileAsStringList("/day14/InitializationProgram.txt")
var memory = runInitializationProgramThroughDecoderChipV1(program)
print... | 0 | Kotlin | 0 | 0 | a7bd42ee17fed44766cfdeb04d41459becd95803 | 1,849 | AdventOfCode2020 | MIT License |
aoc-2023/src/main/kotlin/aoc/util/ListStuff.kt | triathematician | 576,590,518 | false | {"Kotlin": 615974} | package aoc.util
/** get second item in a collection. */
fun <E> Collection<E>.second(): E = drop(1).first()
/** get all pairs of elements from a list. */
fun <E> List<E>.pairwise(): List<Set<E>> = flatMapIndexed { i, e -> drop(i + 1).map { setOf(e, it) } }
/** get all triples of elements from a list. */
fun <E> Lis... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 1,244 | advent-of-code | Apache License 2.0 |
dcp_kotlin/src/main/kotlin/dcp/day288/day288.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day288
// day288.kt
// By <NAME>, 2020.
// Make sure we have four digits by prepending.
private fun Int.to4digits(): Int =
(toString().toList() + List(4 - toString().length){"0"}).joinToString("").toInt()
// At least two digits. Must treat as a string to avoid removing leading 0s.
private fun Int.atLe... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 1,380 | daily-coding-problem | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year21/Day06.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year21
import com.grappenmaker.aoc.PuzzleSet
fun PuzzleSet.day6() = puzzle(day = 6) {
// Part one
val fish = input.split(",").groupingBy { it.trim().toInt() }.eachCount()
.mapValues { it.value.toLong() }
val cyclePopulation = { map: Map<Int, Long>, count: Int ->
... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,055 | advent-of-code | The Unlicense |
src/main/kotlin/g0801_0900/s0894_all_possible_full_binary_trees/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0894_all_possible_full_binary_trees
// #Medium #Dynamic_Programming #Tree #Binary_Tree #Recursion #Memoization
// #2023_04_11_Time_257_ms_(100.00%)_Space_46.5_MB_(90.00%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,575 | LeetCode-in-Kotlin | MIT License |
kotlin/1958-check-if-move-is-legal.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | // recursive solution
class Solution {
fun checkMove(board: Array<CharArray>, rMove: Int, cMove: Int, color: Char): Boolean {
board[rMove][cMove] = color
val rowColumDirections = arrayOf(
intArrayOf(0, 1),
intArrayOf(0, -1),
intArrayOf(1, 0),
intArray... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 3,220 | leetcode | MIT License |
src/day01/Day01.kt | ayukatawago | 572,742,437 | false | {"Kotlin": 58880} | package day01
import readInput
import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
var maxCalories = 0
var calories = 0
input.forEach { calory ->
if (calory.isEmpty()) {
maxCalories = max(maxCalories, calories)
calories = 0... | 0 | Kotlin | 0 | 0 | 923f08f3de3cdd7baae3cb19b5e9cf3e46745b51 | 1,000 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2017/2017-08.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2017
import kotlin.math.max
fun main() {
println("Part1+2:")
println(solve(testInput1))
println(solve(input))
}
private fun solve(input: String): Pair<Int, Int> {
val registers = mutableMapOf<String, Int>()
var max = 0
input.lines().forEach {
... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 26,809 | advent-of-code | MIT License |
30 Days of Code (Kotlin)/day20-sorting.kt | swapnanildutta | 259,629,657 | false | null | /*
Question
Today, we're discussing a simple sorting algorithm called Bubble Sort. Check out the Tutorial tab for learning materials and an instructional video!
Consider the following version of Bubble Sort:
for (int i = 0; i < n; i++) {
// Track number of elements swapped during a single array traversal
int ... | 41 | Python | 202 | 65 | 01b04ee56f1e4b151ff5b98094accfeb09b55a95 | 2,998 | Hackerrank-Codes | MIT License |
src/main/kotlin/days/Day2.kt | wmichaelshirk | 315,495,224 | false | null | package days
class Day2 : Day(2) {
// Each line gives the password policy and then the password. The password policy indicates the
// lowest and highest number of times a given letter must appear for the password to be valid.
// For example, 1-3 a means that the password must contain a at least 1 time and... | 0 | Kotlin | 0 | 0 | b36e5236f81e5368f9f6dbed09a9e4a8d3da8e30 | 1,095 | 2020-Advent-of-Code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/org/hildan/hashcode/Main.kt | joffrey-bion | 341,976,407 | false | null | package org.hildan.hashcode
import kotlinx.coroutines.runBlocking
import org.hildan.hashcode.utils.reader.HCReader
import org.hildan.hashcode.utils.solveHCFilesInParallel
import kotlin.math.ceil
fun main(args: Array<String>) = runBlocking {
solveHCFilesInParallel(*args) {
readProblem().solve()
}
}
@O... | 0 | Kotlin | 0 | 0 | 1c668eecc504eaf019f9fbce36ee78e6bf9bddb8 | 7,523 | hashcode-2021-qualif | MIT License |
src/2020/Day7_2.kts | Ozsie | 318,802,874 | false | {"Kotlin": 99344, "Python": 1723, "Shell": 975} | import java.io.File
import kotlin.collections.ArrayList
/*
shiny gold bag
dark olive bag
faded blue bags
faded blue bags
faded blue bags
dotted black
dotted black
dotted black
dotted black
vibrant plum bag
faded blue
faded blue
faded blue
faded blue
faded blue
do... | 0 | Kotlin | 0 | 0 | d938da57785d35fdaba62269cffc7487de67ac0a | 2,009 | adventofcode | MIT License |
nebulosa-imaging/src/main/kotlin/nebulosa/imaging/algorithms/computation/fwhm/FWHM.kt | tiagohm | 568,578,345 | false | {"Kotlin": 2031289, "TypeScript": 322187, "HTML": 164617, "SCSS": 10191, "Python": 2817, "JavaScript": 1119} | package nebulosa.imaging.algorithms.computation.fwhm
import nebulosa.imaging.Image
import nebulosa.imaging.algorithms.ComputationAlgorithm
import kotlin.math.max
import kotlin.math.min
data class FWHM(
private val x: Int, private val y: Int,
private val mode: Mode = Mode.MIDDLE_ROW,
) : ComputationAlgorithm<F... | 0 | Kotlin | 0 | 1 | de96a26e1a79c5b6f604d9af85311223cc28f264 | 2,134 | nebulosa | MIT License |
src/Day01.kt | erwinw | 572,913,172 | false | {"Kotlin": 87621} | @file:Suppress("MagicNumber")
private const val DAY = "01"
private const val PART1_CHECK = 24000
private const val PART2_CHECK = 45000
fun main() {
fun part1(input: List<String>): Int {
var highestElfCalories = 0
var currentElfCalories = 0
input.forEach {
if (it.isEmpty()) {
... | 0 | Kotlin | 0 | 0 | 57cba37265a3c63dea741c187095eff24d0b5381 | 1,580 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/day12.kt | Gitvert | 725,292,325 | false | {"Kotlin": 97000} | var hits = 0L
val foundSprings = mutableMapOf<String, Long>()
var cacheHits = 0L
fun day12 (lines: List<String>) {
var totalArrangements = 0L
val allPossibilities = mutableListOf<String>()
lines.forEach { line ->
val spring = line.split(" ")[0]
val groups = line.split(" ")[1].split(","... | 0 | Kotlin | 0 | 0 | f204f09c94528f5cd83ce0149a254c4b0ca3bc91 | 4,743 | advent_of_code_2023 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CanPlaceFlowers.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,586 | kotlab | Apache License 2.0 |
src/medium/_43MultiplyStrings.kt | ilinqh | 390,190,883 | false | {"Kotlin": 382147, "Java": 32712} | package medium
class _43MultiplyStrings {
class Solution {
fun multiply(num1: String, num2: String): String {
if (num1 == "0" || num2 == "0") {
return "0"
}
val sb = StringBuffer()
val length1 = num1.length
val length2 = num2.lengt... | 0 | Kotlin | 0 | 0 | 8d2060888123915d2ef2ade293e5b12c66fb3a3f | 1,951 | AlgorithmsProject | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/searching/QuickSelect.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.searching
fun main() {
val arr = mutableListOf(4, 1, 2, 6, 3, 9, 10, 5, 7, 8)
print(quickSelect(arr, 3)) // 4
}
// O(n) time | O(1) space
private fun quickSelect(arr: MutableList<Int>, k: Int): Int {
var low = 0
var high = arr.size - 1
while (low <... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 993 | algs4-leprosorium | MIT License |
src/main/kotlin/days/y2023/day14/Day14.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2023.day14
import util.InputReader
typealias PuzzleLine = String
typealias PuzzleInput = List<PuzzleLine>
class Day14(val input: PuzzleInput) {
private val start = input.toGrid()
fun partOne(): Int {
val rows = start.transpose()
val rolled = rows.roll()
val cols = rolle... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 6,027 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/hj/leetcode/kotlin/problem1396/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1396
/**
* LeetCode page: [1396. Design Underground System](https://leetcode.com/problems/design-underground-system/);
*/
class UndergroundSystem() {
private val activeCheckIn = hashMapOf<CustomerID, CheckInRecord>()
private val tripTimeSummary = hashMapOf<Trip, TimeSum... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,042 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/be/amedee/adventofcode/aoc2015/day02/Day02.kt | amedee | 160,062,642 | false | {"Kotlin": 9459, "Markdown": 7503} | package be.amedee.adventofcode.aoc2015.day02
import java.io.BufferedReader
import java.io.InputStreamReader
fun getSurfaceArea(
length: Int,
width: Int,
height: Int,
) = 2 * ((length * width) + (width * height) + (height * length))
fun getSlack(
length: Int,
width: Int,
height: Int,
) = minOf... | 0 | Kotlin | 0 | 1 | 02e8e0754f2252a2850175fc8b134dd36bc6d042 | 1,834 | adventofcode | MIT License |
src/main/kotlin/at2020/day1/At2020Day1Part1.kt | JeanBarbosa27 | 575,328,729 | false | {"Kotlin": 10872} | package at2020.day1
class At2020Day1Part1 : At2020Day1() {
override var entriesToReachTargetSum = IntArray(2) { 0 }
override val puzzleDescription: String = "Day1 part 1 description:\n" +
"Find the two entries that sum to 2020; what do you get if you multiply them together?\n"
private fun calc... | 0 | Kotlin | 0 | 0 | 62c4e514cd9a306e6a4b5dbd0c146213f08e05f3 | 3,067 | advent-of-code-solving-kotlin | MIT License |
test/leetcode/MaxWordsThatCanBeTyped.kt | andrej-dyck | 340,964,799 | false | null | package leetcode
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
/**
* https://leetcode.com/problems/maximum-number-of-words-you-can-type/
*
* 1935. Maximum Number of Words You Can Type
* [Easy]
*
* There is a... | 0 | Kotlin | 0 | 0 | 3e3baf8454c34793d9771f05f330e2668fda7e9d | 2,090 | coding-challenges | MIT License |
leetcode/src/offer/middle/Offer31.kt | zhangweizhe | 387,808,774 | false | null | package offer.middle
import java.util.*
fun main() {
// 剑指 Offer 31. 栈的压入、弹出序列
// https://leetcode.cn/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/
println(validateStackSequences1(intArrayOf(2,1,0), intArrayOf(1,2,0)))
}
fun validateStackSequences(pushed: IntArray, popped: IntArray): Boolean {
val st... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,874 | kotlin-study | MIT License |
src/main/kotlin/g0901_1000/s0947_most_stones_removed_with_same_row_or_column/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s0947_most_stones_removed_with_same_row_or_column
// #Medium #Depth_First_Search #Graph #Union_Find #Level_2_Day_19_Union_Find
// #2023_04_30_Time_200_ms_(100.00%)_Space_56_MB_(5.88%)
class Solution {
private val roots = IntArray(20002)
fun removeStones(stones: Array<IntArray>): Int {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,178 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/g1401_1500/s1443_minimum_time_to_collect_all_apples_in_a_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1401_1500.s1443_minimum_time_to_collect_all_apples_in_a_tree
// #Medium #Hash_Table #Depth_First_Search #Breadth_First_Search #Tree
// #2023_06_07_Time_793_ms_(85.71%)_Space_104.6_MB_(57.14%)
@Suppress("UNUSED_PARAMETER")
class Solution {
fun minTime(n: Int, edges: Array<IntArray>, hasApple: List<Boolean... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,494 | LeetCode-in-Kotlin | MIT License |
aoc2022/aoc2022-kotlin/src/main/kotlin/de/havox_design/aoc2022/day16/ProboscideaVolcanium.kt | Gentleman1983 | 737,309,232 | false | {"Kotlin": 746488, "Java": 441473, "Scala": 33415, "Groovy": 5725, "Python": 3319} | package de.havox_design.aoc2022.day16
class ProboscideaVolcanium(private var filename: String) {
val valves = readFile()
private val usefulValves = valves.filter { valve -> valve.value.rate > 0 }
private val distances = computeDistances()
fun processPart1(): Int =
traverse(minutes = 30)
... | 4 | Kotlin | 0 | 1 | b94716fbc95f18e68774eb99069c0b703875615c | 2,824 | aoc2022 | Apache License 2.0 |
src/shreckye/coursera/algorithms/IntBits.kt | ShreckYe | 205,871,625 | false | {"Kotlin": 72136} | package shreckye.coursera.algorithms
fun Int.flipSequence(length: Int, hammingDistance: Int, startIndex: Int = 0): Sequence<Int> =
if (hammingDistance == 0)
sequenceOf(this)
else
(startIndex..length - hammingDistance).asSequence().flatMap {
(this xor (1 shl it)).flipSequence(length,... | 0 | Kotlin | 1 | 2 | 1746af789d016a26f3442f9bf47dc5ab10f49611 | 1,146 | coursera-stanford-algorithms-solutions-kotlin | MIT License |
src/main/kotlin/com/github/michaelbull/advent2023/day18/DigPlan.kt | michaelbull | 726,012,340 | false | {"Kotlin": 195941} | package com.github.michaelbull.advent2023.day18
import com.github.michaelbull.advent2023.math.Vector2
import kotlin.math.absoluteValue
fun Sequence<String>.toDigPlan(): DigPlan {
return DigPlan(this.map(String::toInstruction).toList())
}
data class DigPlan(
val instructions: List<Instruction>,
) {
fun l... | 0 | Kotlin | 0 | 1 | ea0b10a9c6528d82ddb481b9cf627841f44184dd | 1,069 | advent-2023 | ISC License |
src/main/kotlin/pl/jpodeszwik/aoc2023/Day06.kt | jpodeszwik | 729,812,099 | false | {"Kotlin": 55101} | package pl.jpodeszwik.aoc2023
import java.lang.Long.parseLong
private fun parseLine(line: String) = line.split(":")[1]
.trim()
.replace("\\s+".toRegex(), " ")
.split(" ")
.map { parseLong(it) }
private fun part1(lines: List<String>) {
val times = parseLine(lines[0])
val distances = parseLine(... | 0 | Kotlin | 0 | 0 | 2b90aa48cafa884fc3e85a1baf7eb2bd5b131a63 | 1,212 | advent-of-code | MIT License |
src/main/kotlin/me/peckb/aoc/_2022/calendar/day20/Day20.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2022.calendar.day20
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import kotlin.math.abs
class Day20 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
fun partOne(filename: String) = generatorFactory.forFile(filena... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 2,356 | advent-of-code | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.