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/com/jacobhyphenated/day15/Day15.kt | jacobhyphenated | 572,119,677 | false | {"Kotlin": 157591} | package com.jacobhyphenated.day15
import com.jacobhyphenated.Day
import com.jacobhyphenated.day9.IntCode
import java.io.File
import java.util.*
import kotlin.random.Random
// Oxygen System
class Day15: Day<List<Long>> {
override fun getInput(): List<Long> {
return this.javaClass.classLoader.getResource("d... | 0 | Kotlin | 0 | 0 | 1a0b9cb6e9a11750c5b3b5a9e6b3d63649bf78e4 | 8,030 | advent2019 | The Unlicense |
solutions/src/solutions/y19/day 12.kt | Kroppeb | 225,582,260 | false | null | @file:Suppress("PackageDirectoryMismatch")
package solutions.solutions.y19.d12
import helpers.*
import kotlinx.coroutines.runBlocking
import kotlin.math.*
data class Moon(var p:Point3D, var v:Point3D)
private fun part1(data: IntLines)= runBlocking {
val moons = data.map{(x,y,z) -> Moon(x toP y toP z, 0 toP 0 toP 0)... | 0 | Kotlin | 0 | 1 | 744b02b4acd5c6799654be998a98c9baeaa25a79 | 1,502 | AdventOfCodeSolutions | MIT License |
src/main/kotlin/Day03.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("Schematic document not specified")
exitProcess(1)
}
val fileName = args.first()
println("Reading $fileName")
val lines = readLines(fileName)
val schematic = lines
... | 0 | Kotlin | 0 | 0 | d9ce83ee89db7081cf7c14bcad09e1348d9059cb | 5,960 | adventofcode2023 | MIT License |
engine/taskpool-collector/src/main/kotlin/io/holunda/camunda/taskpool/enricher/ProcessVariablesTaskCommandEnricherFilter.kt | kgeis | 244,446,791 | true | {"Kotlin": 429712} | package io.holunda.camunda.taskpool.enricher
import org.camunda.bpm.engine.variable.VariableMap
/**
* Groups one or more {@linkplain VariableFilter process variable filters}. Assumes (but does not enforce) that among the given individual filter instances,
* at most one is contained for any specific process, and at ... | 0 | null | 0 | 0 | 6308ef1b3b49c3378c8b9f272c0e7ab28800a384 | 3,512 | camunda-bpm-taskpool | Apache License 2.0 |
kotlin/src/main/kotlin/adventofcode/day11/Day11_2.kt | thelastnode | 160,586,229 | false | null | package adventofcode.day11
object Day11_2 {
data class Coord(val x: Int, val y: Int, val w: Int)
fun powerLevel(coord: Pair<Int, Int>, gridSerial: Int): Int {
val (x, y) = coord
val rackId = x + 10
val t = (rackId * y + gridSerial) * rackId
return (t / 100) % 10 - 5
}
... | 0 | Kotlin | 0 | 0 | 8c9a3e5a9c8b9dd49eedf274075c28d1ebe9f6fa | 1,713 | adventofcode | MIT License |
2023/day04-25/src/main/kotlin/Day08.kt | CakeOrRiot | 317,423,901 | false | {"Kotlin": 62169, "Python": 56994, "C#": 20675, "Rust": 10417} | import java.io.File
import java.math.BigInteger
class Day08 {
fun solve1() {
val input = File("inputs/8.txt").inputStream().bufferedReader().lineSequence().toList()
val turns = input[0]
val map = emptyMap<String, Pair<String, String>>().toMutableMap()
input.drop(2).forEach { line -... | 0 | Kotlin | 0 | 0 | 8fda713192b6278b69816cd413de062bb2d0e400 | 2,452 | AdventOfCode | MIT License |
AdventOfCode/Challenge2023Day10.kt | MartinWie | 702,541,017 | false | {"Kotlin": 90565} | import org.junit.Test
import java.io.File
import kotlin.math.ceil
import kotlin.test.assertEquals
class Challenge2023Day10 {
data class Coord(val row: Int, val col: Int)
private fun solve1(map: List<String>): Int {
val startCoord =
map.withIndex().find { (_, line) -> 'S' in line }
... | 0 | Kotlin | 0 | 0 | 47cdda484fabd0add83848e6000c16d52ab68cb0 | 2,824 | KotlinCodeJourney | MIT License |
klogic-core/src/main/kotlin/org/klogic/core/State.kt | UnitTestBot | 594,002,694 | false | {"Kotlin": 146776} | package org.klogic.core
import kotlinx.collections.immutable.PersistentSet
import kotlinx.collections.immutable.persistentHashSetOf
import kotlinx.collections.immutable.toPersistentHashSet
import org.klogic.unify.toUnificationState
typealias InequalityConstraints = PersistentSet<InequalityConstraint>
/**
* Represen... | 2 | Kotlin | 1 | 1 | c086377208a1482231769779ea702cb823869590 | 3,634 | klogic | MIT License |
Word_Ladder.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} | // https://leetcode.com/problems/word-ladder/solution/
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.set
class Solution {
fun ladderLength(beginWord: String, endWord: String, wordList: List<String>): Int {
val levelMap = HashMap<String, I... | 0 | C++ | 0 | 0 | eb5b6814e8ba0847f0b36aec9ab63bcf1bbbc134 | 1,711 | leetcode | MIT License |
2021/src/day20/day20.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day20
import java.io.File
fun main() {
val file = File("src/day20", "day20input.txt").readLines()
val algorithm = file[0]
val image = Image.parse(file.drop(2))
println(algorithm)
println(image.getBounds())
println(image)
val enhance = image.enhance(algorithm)
//println(enhance... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 3,496 | adventofcode | Apache License 2.0 |
src/Day03.kt | acrab | 573,191,416 | false | {"Kotlin": 52968} | import com.google.common.truth.Truth.assertThat
fun scoreForItem(char: Char): Int =
if (char in 'a'..'z') {
(char.code - 97) + 1
} else {
(char.code - 65) + 27
}
fun main() {
fun part1(input: List<String>): Int = input
//Split into two parts
.map { it.chunked(it.length ... | 0 | Kotlin | 0 | 0 | 0be1409ceea72963f596e702327c5a875aca305c | 1,038 | aoc-2022 | Apache License 2.0 |
complex/src/main/kotlin/net/fwitz/math/binary/complex/functions/Binomial.kt | txshtkckr | 410,419,365 | false | {"Kotlin": 558762} | package net.fwitz.math.binary.complex.functions
import net.fwitz.math.binary.complex.Complex
import net.fwitz.math.binary.complex.functions.Factorial.factorial
object Binomial {
const val BINOMIAL_MAX_N = 33
private val BINOMIAL: List<IntArray> = run {
val table = ArrayList<IntArray>(BINOMIAL_MAX_N +... | 0 | Kotlin | 1 | 0 | c6ee97ab98115e044a46490ef3a26c51752ae6d6 | 1,797 | fractal | Apache License 2.0 |
codeforces/round901/b_slow.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.round901
private fun solve() {
fun encode(a: Int, b: Int) = (a.toLong() shl 32) or b.toLong()
val (a, b, c, d, m) = readIntArray()
val source = encode(a, b)
val dest = encode(c, d)
val queue = mutableListOf<Long>()
val dist = mutableMapOf<Long, Int>()
queue.add(source)
dist[source] = 0
var ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,485 | competitions | The Unlicense |
src/main/adventofcode/Day14Solver.kt | eduardofandrade | 317,942,586 | false | null | package adventofcode
import java.io.InputStream
import java.math.BigInteger
import java.util.*
class Day14Solver(stream: InputStream) : Solver {
private var instructions: ArrayList<Instruction> = arrayListOf()
init {
stream.bufferedReader().readLines().forEach { line: String ->
if (line... | 0 | Kotlin | 0 | 0 | 147553654412ae1da4b803328e9fc13700280c17 | 3,345 | adventofcode2020 | MIT License |
src/main/kotlin/g1301_1400/s1391_check_if_there_is_a_valid_path_in_a_grid/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1301_1400.s1391_check_if_there_is_a_valid_path_in_a_grid
// #Medium #Array #Depth_First_Search #Breadth_First_Search #Matrix #Union_Find
// #2023_06_06_Time_636_ms_(100.00%)_Space_64.1_MB_(100.00%)
import java.util.LinkedList
import java.util.Queue
class Solution {
private val dirs = arrayOf(
ar... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,928 | LeetCode-in-Kotlin | MIT License |
src/2021/Day05.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2021`
import common.Point
import java.io.File
import java.util.*
import kotlin.math.abs
fun main() {
Day05().solve()
}
fun sign(a: Int): Int {
if (a<0) {
return -1
}
if (a>0) {
return 1
}
return 0
}
class Line(p1: Point, p2: Point) {
private val leftTop: Point
... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 1,968 | advent-of-code | Apache License 2.0 |
src/Day21.kt | chasegn | 573,224,944 | false | {"Kotlin": 29978} | import java.lang.IllegalArgumentException
/**
* Day 21 for Advent of Code 2022
* https://adventofcode.com/2022/day/21
*/
class Day21 : Day {
override val inputFileName: String = "Day21"
override val test1Expected: Long = 152
override val test2Expected: Long = 301
/**
* Accepted solution: 11018... | 0 | Kotlin | 0 | 0 | 2b9a91f083a83aa474fad64f73758b363e8a7ad6 | 2,485 | advent-of-code-2022 | Apache License 2.0 |
solver/src/commonMain/kotlin/org/hildan/sudoku/model/Cell.kt | joffrey-bion | 9,559,943 | false | {"Kotlin": 51198, "HTML": 187} | package org.hildan.sudoku.model
import org.hildan.sudoku.solver.techniques.CellIndex
/**
* Represents one cell in a Sudoku [Grid].
*/
class Cell(
val row: Int,
val col: Int,
/** The digit set for this cell, or null if this cell is empty */
var value: Digit?,
) {
/** True if this cell's digit was... | 0 | Kotlin | 0 | 0 | 441fbb345afe89b28df9fe589944f40dbaccaec5 | 2,023 | sudoku-solver | MIT License |
src/algorithmsinanutshell/IntersectionOfLines.kt | realpacific | 234,499,820 | false | null | package algorithmsinanutshell
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.test.assertFalse
import kotlin.test.assertTrue
/**
* ```
* Two lines (P1, P2) and (P3,P4) intersect when orientation of:
* * (P1 wrt P3,P4) and (P2 wrt P3,P4)
* * (P3 wrt P1,P2) and (P4 wrt P1,P2)
*
... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 3,546 | algorithms | MIT License |
src/main/kotlin/Day03.kt | luluvia | 576,815,205 | false | {"Kotlin": 7130} | class Day03 {
fun part1(input: List<String>): Int {
var priorityScore = 0
for (line in input) {
val matchingChar = getMatchingChar(line)
priorityScore += getPriorityScore(matchingChar)
}
return priorityScore
}
fun part2(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | 29ddde3b0d7acbe0ef1295ec743e7d0417cfef53 | 1,550 | advent-of-code-22 | Apache License 2.0 |
src/day12/d12_2.kt | svorcmar | 720,683,913 | false | {"Kotlin": 49110} | fun main() {
val input = ""
val obj = parseObj(input, 1, false)
println(obj.sum())
}
fun parseObj(input: String, from: Int, isArray: Boolean): ObjectFragment {
val sb = StringBuilder()
val arrSb = StringBuilder()
val subObjects = mutableListOf<ObjectFragment>()
var i = from
while(true) {
i += when(... | 0 | Kotlin | 0 | 0 | cb097b59295b2ec76cc0845ee6674f1683c3c91f | 1,523 | aoc2015 | MIT License |
src/nl/davefranken/rosalind/P4FIB.kt | Davio | 105,393,274 | false | null |
import java.io.File
import java.math.BigInteger
import java.util.stream.Stream
/**
* Problem
A sequence is an ordered collection of objects (usually numbers), which are allowed to repeat. Sequences can be finite or infinite. Two examples are the finite sequence (π,−2–√,0,π)(π,−2,0,π) and the infinite sequence of od... | 0 | Kotlin | 0 | 0 | f5350b0bf4a2514044d69ece5420c5cb8f102889 | 2,235 | rosalind | MIT License |
src/main/kotlin/Day3.kt | d1snin | 726,126,205 | false | {"Kotlin": 14602} | /*
* 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 wr... | 0 | Kotlin | 0 | 0 | 8b5b34c4574627bb3c6b1a12664cc6b4c9263e30 | 4,850 | aoc-2023 | Apache License 2.0 |
leetcode2/src/leetcode/remove-nth-node-from-end-of-list.kt | hewking | 68,515,222 | false | null | package leetcode
import leetcode.structure.ListNode
/**
* 19. 删除链表的倒数第N个节点
* https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/
* 给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。
示例:
给定一个链表: 1->2->3->4->5, 和 n = 2.
当删除了倒数第二个节点后,链表变为 1->2->3->5.
说明:
给定的 n 保证是有效的。
进阶:
你能尝试使用一趟扫描实现吗?
来源:力扣(LeetCode)
链接:https:... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,485 | leetcode | MIT License |
src/main/Day20.kt | ssiegler | 572,678,606 | false | {"Kotlin": 76434} | package day20
import utils.readInput
private const val filename = "Day20"
fun part1(filename: String): Long = readEncrypted(filename).mix().grooveCoordinates().sum()
fun readEncrypted(filename: String, key: Long = 1) = readInput(filename).map { it.toLong() * key }
fun part2(filename: String): Long =
readEncryp... | 0 | Kotlin | 0 | 0 | 9133485ca742ec16ee4c7f7f2a78410e66f51d80 | 992 | aoc-2022 | Apache License 2.0 |
hoon/HoonAlgorithm/src/main/kotlin/programmers/lv02/Lv2_12951_JadenCase문자열만들기.kt | boris920308 | 618,428,844 | false | {"Kotlin": 137657, "Swift": 35553, "Java": 1947, "Rich Text Format": 407} | package programmers.lv02
/**
*
* no.12951
* JadenCase 문자열 만들기
* https://school.programmers.co.kr/learn/courses/30/lessons/12951
*
* JadenCase란 모든 단어의 첫 문자가 대문자이고, 그 외의 알파벳은 소문자인 문자열입니다.
* 단, 첫 문자가 알파벳이 아닐 때에는 이어지는 알파벳은 소문자로 쓰면 됩니다. (첫 번째 입출력 예 참고)
* 문자열 s가 주어졌을 때, s를 JadenCase로 바꾼 문자열을 리턴하는 함수, solution을 완성해주세... | 1 | Kotlin | 1 | 2 | 88814681f7ded76e8aa0fa7b85fe472769e760b4 | 1,681 | HoOne | Apache License 2.0 |
sbom-ort/scanner/src/main/kotlin/ScannerCriteria.kt | opensourceways | 521,493,253 | false | {"Kotlin": 4381819, "Go": 1396721, "JavaScript": 291650, "Shell": 163230, "HTML": 118849, "Python": 87335, "Haskell": 30438, "CSS": 25056, "Makefile": 21936, "FreeMarker": 20565, "Ruby": 13496, "Dockerfile": 12965, "Batchfile": 9453, "Roff": 7778, "Java": 6729, "Scala": 6656, "ANTLR": 1883, "Rust": 280, "Emacs Lisp": 1... | /*
* Copyright (C) 2020 Bosch.IO GmbH
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agr... | 63 | Kotlin | 2 | 27 | 3e0f370e5c2d809257e0b8d7aa6b1ac3161c53a2 | 5,697 | sbom-tools | Apache License 2.0 |
src/main/kotlin/days/Day25.kt | julia-kim | 569,976,303 | false | null | package days
import readInput
import kotlin.math.absoluteValue
import kotlin.math.log
import kotlin.math.pow
import kotlin.math.roundToInt
fun main() {
fun Long.toSNAFU(): String {
var snafu = ""
var decimal = this.toDouble()
var currentPlace = log(this.toDouble(), 5.0).roundToInt()
... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 1,882 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/marcdenning/adventofcode/day11/Day11b.kt | marcdenning | 317,730,735 | false | {"Kotlin": 87536} | package com.marcdenning.adventofcode.day11
import java.io.File
private const val FLOOR = '.'
private const val EMPTY = 'L'
private const val OCCUPIED = '#'
fun main(args: Array<String>) {
val floorPlanMatrix = File(args[0]).readLines().map { it.toCharArray() }.toTypedArray()
println("Number of occupied seat... | 0 | Kotlin | 0 | 0 | b227acb3876726e5eed3dcdbf6c73475cc86cbc1 | 3,391 | advent-of-code-2020 | MIT License |
advent2021/src/main/kotlin/year2021/Day07.kt | bulldog98 | 572,838,866 | false | {"Kotlin": 132847} | package year2021
import AdventDay
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
private fun addIfFirstMaxIsZero(a: Int, b: Int): Int =
if (a == Int.MAX_VALUE)
b
else
a + b
private fun Collection<Int>.alignTo(i: Int, cost: (Int) -> Int = ::abs): Int = asSequence()
.m... | 0 | Kotlin | 0 | 0 | 02ce17f15aa78e953a480f1de7aa4821b55b8977 | 999 | advent-of-code | Apache License 2.0 |
kotlin/src/katas/kotlin/algorithms/RabinKarp.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.algorithms
import datsok.shouldEqual
import org.junit.Test
class RollingHash(
val s: CharSequence,
val size: Int,
val startIndex: Int = 0,
val base: Int = 256,
val modulus: Int = 101,
val value: Int = s.subSequence(startIndex, startIndex + size).fold(0) { acc, c ->
... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,296 | katas | The Unlicense |
src/main/kotlin/com/hj/leetcode/kotlin/problem1464/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1464
import kotlin.math.max
import kotlin.math.min
/**
* LeetCode page: [1464. Maximum Product of Two Elements in an Array](https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(1) where ... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,067 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/day21/Day21.kt | TheSench | 572,930,570 | false | {"Kotlin": 128505} | package day21
import runDay
import stackOf
import kotlin.RuntimeException
fun main() {
fun part1(input: List<String>): Long = input.map { it.toMonkey() }
.processMonkeys()
.let {
it["root"]!!.number!!
}
fun part2(input: List<String>) = input.map { it.toMonkey() }
.processMonkeys()
.let... | 0 | Kotlin | 0 | 0 | c3e421d75bc2cd7a4f55979fdfd317f08f6be4eb | 5,900 | advent-of-code-2022 | Apache License 2.0 |
letcode/src/main/java/daily/LeetCode167.kt | chengw315 | 343,265,699 | false | null | package daily
fun main() {
val solution = Solution167()
//4,5
val twoSum4 = solution.twoSum(intArrayOf(1,2,3,4,4,8,9,75), 8)
//2,3
val twoSum3 = solution.twoSum(intArrayOf(5,25,75), 100)
//1,2
val twoSum = solution.twoSum(intArrayOf(2, 7, 11, 15), 9)
//1,5
val twoSum2 = solution.two... | 0 | Java | 0 | 2 | 501b881f56aef2b5d9c35b87b5bcfc5386102967 | 937 | daily-study | Apache License 2.0 |
src/test/kotlin/dev/shtanko/algorithms/leetcode/SortByBitsTest.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 | 2,154 | kotlab | Apache License 2.0 |
src/day04/Day04.kt | shiddarthbista | 572,833,784 | false | {"Kotlin": 9985} | package day04
import readInput
fun main() {
fun addToList(elf: String, roomList: MutableList<Int>) {
for (i in elf.substringBefore("-").toInt()..elf.substringAfter("-").toInt()) {
roomList.add(i)
}
}
fun getElfRoomList(roomInfo: String): Pair<MutableList<Int>, MutableList<Int>... | 0 | Kotlin | 0 | 0 | ed1b6a132e201e98ab46c8df67d4e9dd074801fe | 1,458 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem59/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem59
/**
* LeetCode page: [59. Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii/);
*/
class Solution {
/* Complexity:
* Time O(n^2) and Auxiliary Space O(1);
*/
fun generateMatrix(n: Int): Array<IntArray> {
val result = Array(n) { IntArray... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,535 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day01.kt | marosseleng | 573,498,695 | false | {"Kotlin": 32754} | fun main() {
fun part1(input: List<String>): Long {
var currentMax = 0L
var intermediateMax = 0L
for (line in input) {
if (line.isBlank()) {
if (intermediateMax > currentMax) {
currentMax = intermediateMax
}
in... | 0 | Kotlin | 0 | 0 | f13773d349b65ae2305029017490405ed5111814 | 1,635 | advent-of-code-2022-kotlin | Apache License 2.0 |
leetcode2/src/leetcode/ValidAnagram.kt | hewking | 68,515,222 | false | null | package leetcode
import java.util.*
/**
*242. 有效的字母异位词
* https://leetcode-cn.com/problems/valid-anagram/
* Created by test
* Date 2019/6/4 1:06
* Description
* 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。
示例 1:
输入: s = "anagram", t = "nagaram"
输出: true
示例 2:
输入: s = "rat", t = "car"
输出: false
说明:
你可以假设字符串只包含小写字母... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,134 | leetcode | MIT License |
advent/src/test/kotlin/org/elwaxoro/advent/y2015/Dec03.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2015
import org.elwaxoro.advent.Coord
import org.elwaxoro.advent.Dir
import org.elwaxoro.advent.PuzzleDayTester
/**
* https://adventofcode.com/2015/day/3
* part 1: 2081
* part 2: 2341
*/
class Dec03 : PuzzleDayTester(3, 2015) {
data class Santa(val visits: List<Coord> = listOf(Co... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 1,214 | advent-of-code | MIT License |
src/Day01.kt | JohannesPtaszyk | 573,129,811 | false | {"Kotlin": 20483} | fun main() {
fun getElvesCalories(input: List<String>) =
input.fold(mutableListOf()) { elves: MutableList<Int>, s: String ->
elves.apply {
when {
isEmpty() || s.isBlank() -> add(0)
s.isNotBlank() -> this[lastIndex] += s.toInt()
... | 0 | Kotlin | 0 | 1 | 6f6209cacaf93230bfb55df5d91cf92305e8cd26 | 840 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/prison_cells/PrisonCells.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.prison_cells
import datsok.shouldEqual
import org.junit.Test
class PrisonCellsTests {
@Test fun examples() {
prisonAfterNDays(intArrayOf(0, 1, 0, 1, 1, 0, 0, 1), days = 0) shouldEqual intArrayOf(0, 1, 0, 1, 1, 0, 0, 1)
prisonAfterNDays(intArrayOf(0, 1, 0, 1, 1, 0, 0, ... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 3,955 | katas | The Unlicense |
kotlin_from_scratch_solution/src/main/kotlin/ScheduleEntities.kt | thomasnield | 106,970,692 | false | null |
import java.time.LocalDateTime
/** A discrete, 15-minute chunk of time a class can be scheduled on */
data class Block(val range: ClosedRange<LocalDateTime>) {
val timeRange = range.start.toLocalTime()..range.endInclusive.toLocalTime()
/** indicates if this block is zeroed due to operating day/break constr... | 3 | Kotlin | 7 | 37 | e59e8c5a15fcc7e7baafbd31fc264da7f057b0e5 | 5,348 | classroom-scheduling-demo | Apache License 2.0 |
src/iii_conventions/MyDate.kt | kacperkr90 | 92,478,724 | false | {"Kotlin": 80910, "Java": 4315} | package iii_conventions
data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate> {
override fun compareTo(other: MyDate): Int {
return this.days().compareTo(other.days())
}
}
operator fun MyDate.rangeTo(other: MyDate): DateRange =
DateRange(this, other)
opera... | 0 | Kotlin | 0 | 0 | 1bca2dfb13df09c97d917bfc6e69724f64b24b15 | 1,738 | kotlin-tutorial | MIT License |
src/cn/leetcode/codes/simple628/Simple628.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple628
import cn.leetcode.codes.out
import java.util.*
import kotlin.math.max
fun main() {
// val nums = intArrayOf(1,2,3)
// val nums = intArrayOf(1,2,3,4)
// val nums = intArrayOf(-1,-2,-3)
val nums = intArrayOf(-100,-98,-1,2,3,4)
out(maximumProduct(nums))
}
/*
628... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 965 | LeetCodeSimple | Apache License 2.0 |
src/main/kotlin/year_2023/Day05.kt | krllus | 572,617,904 | false | {"Kotlin": 97314} | package year_2023
import Day
import solve
import year_2022.Command
import year_2022.toCommand
class Day05 : Day(day = 5, year = 2023, "If You Give A Seed A Fertilizer") {
private val groups by lazy { inputAsString.split("\n\n") }
private fun getSeeds(): List<Seed> {
return groups.first()
... | 0 | Kotlin | 0 | 0 | b5280f3592ba3a0fbe04da72d4b77fcc9754597e | 3,872 | advent-of-code | Apache License 2.0 |
app/src/main/kotlin/leetcode/0724_Find-Pivot-Index/FindPivotIndex.kt | chanphy | 527,447,921 | false | {"Kotlin": 13667} | package leetcode.`0724_Find-Pivot-Index`
/**
Given an array of integers nums, calculate the pivot index of this array.
The pivot index is the index where the sum of all the numbers strictly to the
left of the index is equal to the sum of all the numbers strictly to the index's
right.
If the index is on the left edge... | 0 | Kotlin | 0 | 0 | 3c1c49e0e6ab6e703dd123f942870c2c9801ee60 | 1,658 | Algo-Kotlin | MIT License |
utils/src/main/kotlin/de/skyrising/aoc/calc.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc
import org.apache.commons.math3.util.ArithmeticUtils.gcd
import kotlin.math.max
infix fun Long.over(other: Long) = LongFraction(this, other).reduce()
data class LongFraction(val numerator: Long, val denominator: Long) {
init {
require(denominator != 0L)
}
constructor(valu... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 4,857 | aoc | MIT License |
src/main/kotlin/y2023/Day4.kt | juschmitt | 725,529,913 | false | {"Kotlin": 18866} | package y2023
import utils.Day
import kotlin.math.pow
class Day4 : Day(4, 2023, false) {
override fun partOne(): Any {
return inputList.mapToCards().calculatePointsPerCard().sum()
}
override fun partTwo(): Any {
val cards = inputList.mapToCards()
return IntArray(cards.size) { 1 }.... | 0 | Kotlin | 0 | 0 | b1db7b8e9f1037d4c16e6b733145da7ad807b40a | 1,117 | adventofcode | MIT License |
src/Day01.kt | LukasAnda | 572,878,230 | false | {"Kotlin": 3190} | fun main() {
check(getTopNLargestCalorieSum(readInput("Day01_test"), 1) == 24000L)
check(getTopNLargestCalorieSum(readInput("Day01_test"), 3) == 45000L)
println("Top 1 is: " + getTopNLargestCalorieSum(readInput("Day01"), 1))
println("Top 3 are: " + getTopNLargestCalorieSum(readInput("Day01"), 3))
}
f... | 0 | Kotlin | 0 | 0 | 20ccddd7b0517cbaf7590364333201e33bd5c0d6 | 806 | AdventOfCode2022 | Apache License 2.0 |
src/Day05.kt | anilkishore | 573,688,256 | false | {"Kotlin": 27023} | import java.util.*
import java.util.regex.Pattern
import kotlin.streams.toList
fun main() {
fun part1(input: List<String>, together: Boolean = false) {
val (moves, colsExtra) = input.partition { it.startsWith("move") }
val cols = colsExtra.dropLast(2).reversed()
val n = (cols[0].length + 1... | 0 | Kotlin | 0 | 0 | f8f989fa400c2fac42a5eb3b0aa99d0c01bc08a9 | 1,399 | AOC-2022 | Apache License 2.0 |
src/main/math/ModInt.kt | vamsi3 | 504,166,472 | false | {"Kotlin": 10048} | package com.vamsi3.algorithm.math
class ModInt private constructor(
value: Long = 0,
private val mod: Int,
) : Number() {
private var value: Int = 0
init {
this.value = (if (value !in -mod + 1..mod) value % mod else value).toInt()
if (this.value < 0) this.value += mod
}
constr... | 0 | Kotlin | 0 | 0 | 5eda4c454984866e00a5d26c73dfb6f2437017e7 | 2,320 | algorithm-library | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1318/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1318
/**
* LeetCode page: [1318. Minimum Flips to Make a OR b Equal to c](https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/);
*/
class Solution {
/* Complexity:
* Time O(LogN) and Space O(1) where N is the max of a, b and c;
*/
fun minFlips... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,183 | hj-leetcode-kotlin | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/MinWindow.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
/**
* 76. 最小覆盖子串
*
* 给你一个字符串 s 、一个字符串 t 。返回 s 中涵盖 t 所有字符的最小子串。如果 s 中不存在涵盖 t 所有字符的子串,则返回空字符串 "" 。
*
* 注意:如果 s 中存在这样的子串,我们保证它是唯一的答案。
*/
class MinWindow {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println(MinWindow().minWindow... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 1,874 | daily_algorithm | Apache License 2.0 |
src/day02/Code.kt | ldickmanns | 572,675,185 | false | {"Kotlin": 48227} | package day02
import readInput
fun main() {
val input = readInput("day02/input")
println(part1(input))
println(part2(input))
}
// A, X -> Rock, 1
// B, Y -> Paper, 2
// C, Z -> Scissors, 3
fun part1(input: List<String>): Int {
var score = 0
input.forEach {
score += when {
"X... | 0 | Kotlin | 0 | 0 | 2654ca36ee6e5442a4235868db8174a2b0ac2523 | 1,245 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/day9/EncryptedData.kt | lukasz-marek | 317,632,409 | false | {"Kotlin": 172913} | package day9
data class EncryptedData(val numbers: List<Long>, val preambleSize: Int)
interface InvalidNumberFinder {
fun findInvalidNumbers(encryptedData: EncryptedData): List<Long>
}
class InvalidNumberFinderImpl : InvalidNumberFinder {
override fun findInvalidNumbers(encryptedData: EncryptedData): List<Lon... | 0 | Kotlin | 0 | 0 | a16e95841e9b8ff9156b54e74ace9ccf33e6f2a6 | 2,335 | aoc2020 | MIT License |
codeforces/round626/c.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.round626
import java.io.*
private fun solve(): Long {
val (n, m) = readInts()
val c = readLongs()
val nei = List(n) { mutableListOf<Int>() }
repeat(m) {
val (u, v) = readInts().map { it - 1 }
nei[v].add(u)
}
val hashed = nei.map { it.sorted().fold(1L) { acc: Long, x: Int -> acc * 566239L ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 973 | competitions | The Unlicense |
2015/src/main/kotlin/day3_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.Vec2i
import utils.mapItems
fun main() {
Day3Func.run()
}
fun Char.toVec() = when (this) {
'>' -> Vec2i(1, 0)
'<' -> Vec2i(-1, 0)
'^' -> Vec2i(0, -1)
'v' -> Vec2i(0, 1)
else -> throw IllegalArgumentException("Unacceptable input char $this")
}
object ... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 908 | aoc_kotlin | MIT License |
src/main/kotlin/problems/LongestConsecutiveArray.kt | amartya-maveriq | 510,824,460 | false | {"Kotlin": 42296} | package problems
/**
* Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
* You must write an algorithm that runs in O(n) time.
*
* Input: nums = [100,4,200,1,3,2]
* Output: 4
* Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefor... | 0 | Kotlin | 0 | 0 | 2f12e7d7510516de9fbab866a59f7d00e603188b | 1,062 | data-structures | MIT License |
app/src/main/kotlin/compiler/lexer/Lexer.kt | brzeczyk-compiler | 545,707,939 | false | {"Kotlin": 1167879, "C": 4004, "Shell": 3242, "Vim Script": 2238} | package compiler.lexer
import compiler.dfa.AbstractDfa
import compiler.dfa.isAccepting
import compiler.diagnostics.Diagnostic
import compiler.diagnostics.Diagnostics
import compiler.input.Input
import compiler.input.Location
import compiler.input.LocationRange
// Used to turn a sequence of characters into a sequence ... | 7 | Kotlin | 0 | 2 | 5917f4f9d0c13c2c87d02246da8ef8394499d33c | 4,020 | brzeczyk | MIT License |
src/test/kotlin/aoc2018/day7/StepsTest.kt | arnab | 75,525,311 | false | null | package aoc2018.day7
import aoc.util.TestResourceReader
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
internal class StepsTest {
@Test
fun part1_StepOrder_Problem1() {
val steps = parseData(TestResourceReader.readFile("aoc2018/day7/input.txt"))
val stepsInOrder = S... | 0 | Kotlin | 0 | 0 | 1d9f6bc569f361e37ccb461bd564efa3e1fccdbd | 3,226 | adventofcode | MIT License |
src/main/kotlin/kr/co/programmers/P152995.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://github.com/antop-dev/algorithm/issues/486
class P152995 {
fun solution(scores: Array<IntArray>): Int {
var rank = 1
val me = scores[0]
var maxScore = 0
// 근무태도 내림차순 정렬.
// 근무태도 동점인 경우 동료평가 오름차순 정렬
scores.sortWith(Comparator { a, b... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 988 | algorithm | MIT License |
2020/day12/day12.kt | flwyd | 426,866,266 | false | {"Julia": 207516, "Elixir": 120623, "Raku": 119287, "Kotlin": 89230, "Go": 37074, "Shell": 24820, "Makefile": 16393, "sed": 2310, "Jsonnet": 1104, "HTML": 398} | /*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
package day12
import java.lang.Math.floorMod
import java.lang.Math.toDegrees
import java.lang.Math.toRadians
import kotlin.math.a... | 0 | Julia | 1 | 5 | f2d6dbb67d41f8f2898dbbc6a98477d05473888f | 3,703 | adventofcode | MIT License |
Retos/Reto #6 - PIEDRA, PAPEL, TIJERA, LAGARTO, SPOCK [Media]/kotlin/masdos.kt | mouredev | 581,049,695 | false | {"Python": 3866914, "JavaScript": 1514237, "Java": 1272062, "C#": 770734, "Kotlin": 533094, "TypeScript": 457043, "Rust": 356917, "PHP": 281430, "Go": 243918, "Jupyter Notebook": 221090, "Swift": 216751, "C": 210761, "C++": 164758, "Dart": 159755, "Ruby": 70259, "Perl": 52923, "VBScript": 49663, "HTML": 45912, "Raku": ... | /*
* Crea un programa que calcule quien gana más partidas al juego piedra, papel, tijera, lagarto,
* spock.
* - El resultado puede ser: "Player 1", "Player 2", "Tie" (empate)
* - La función recibe un listado que contiene pares, representando cada jugada.
* - El par puede contener combinaciones de "🗿" (piedra), "... | 4 | Python | 2,929 | 4,661 | adcec568ef7944fae3dcbb40c79dbfb8ef1f633c | 3,841 | retos-programacion-2023 | Apache License 2.0 |
src/main/kotlin/shared.kt | reitzig | 318,492,753 | false | null | import kotlin.math.absoluteValue
data class Either<T, U>(val t: T? = null, val u: U? = null) {
init {
assert((t == null) != (u == null)) { "Exactly one parameter must be null" }
}
override fun toString(): String = "${t ?: ""}${u ?: ""}"
}
fun <T> List<T>.split(splitEntry: T): List<List<T>> =
... | 0 | Kotlin | 0 | 0 | f17184fe55dfe06ac8897c2ecfe329a1efbf6a09 | 3,511 | advent-of-code-2020 | The Unlicense |
src/Day14.kt | HylkeB | 573,815,567 | false | {"Kotlin": 83982} | import java.lang.IllegalArgumentException
fun main() {
class Scan(
private val top: Int,
private val left: Int,
private val bottom: Int,
private val right: Int,
) {
private val width = (right - left) + 1
private val height = (bottom - top) + 1
... | 0 | Kotlin | 0 | 0 | 8649209f4b1264f51b07212ef08fa8ca5c7d465b | 6,117 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/day13/Day13.kt | Ciel-MC | 572,868,010 | false | {"Kotlin": 55885} | package day13
import day13.ListNode.Companion.toListNode
import day13.Value.Companion.toValue
import readInput
import java.io.File
val file = File("AAA.txt")
fun log(message: Any?) {
file.appendText("$message\n")
println(message)
}
sealed interface Value {
fun isCorrect(other: Value): Boolean?
comp... | 0 | Kotlin | 0 | 0 | 7eb57c9bced945dcad4750a7cc4835e56d20cbc8 | 8,012 | Advent-Of-Code | Apache License 2.0 |
2022/src/day25/day25.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day25
import GREEN
import RESET
import printTimeMillis
import readInput
fun String.toDecimal() = fold(0L) { acc, c -> acc * 5L + ("=-012".indexOf(c) - 2) }
fun Long.toSNAFU(): String {
val base = listOf('0', '1', '2', '=', '-')
val digits = listOf(0, 1, 2, -2, -1)
val sb = StringBuilder()
va... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 881 | advent-of-code | Apache License 2.0 |
Kotlin/5 kyu Josephus Survivor.kt | MechaArms | 508,384,440 | false | {"Kotlin": 22917, "Python": 18312} | /*
In this kata you have to correctly return who is the "survivor", ie: the last element of a Josephus permutation.
Basically you have to assume that n people are put into a circle and that they are eliminated in steps of k elements, like this:
josephus_survivor(7,3) => means 7 people in a circle;
one every 3 is elim... | 0 | Kotlin | 0 | 1 | b23611677c5e2fe0f7e813ad2cfa21026b8ac6d3 | 1,311 | My-CodeWars-Solutions | MIT License |
Kotlin/src/UniqueBinarySearchTreesII.kt | TonnyL | 106,459,115 | false | null | /**
* Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.
*
* For example,
* Given n = 3, your program should return all 5 unique BST's shown below.
*
* 1 3 3 2 1
* \ / / / \ \
* 3 2 1 1 3 2
* / /... | 1 | Swift | 22 | 189 | 39f85cdedaaf5b85f7ce842ecef975301fc974cf | 1,369 | Windary | MIT License |
src/Day10.kt | msernheim | 573,937,826 | false | {"Kotlin": 32820} | import kotlin.math.sign
fun main() {
fun evalSignalStrengthOrZero(clock: Int, x: Int): Int {
if (clock % 40 == 20) {
return x * clock
}
return 0
}
fun part1(input: List<String>): Int {
var clock = 1
var signalStrength = 0
var x = 1
inpu... | 0 | Kotlin | 0 | 3 | 54cfa08a65cc039a45a51696e11b22e94293cc5b | 1,664 | AoC2022 | Apache License 2.0 |
2023/3/solve-1.kts | gugod | 48,180,404 | false | {"Raku": 170466, "Perl": 121272, "Kotlin": 58674, "Rust": 3189, "C": 2934, "Zig": 850, "Clojure": 734, "Janet": 703, "Go": 595} | import java.io.File
class EngineSchemata(
val engineSchematic: List<String>,
) {
private fun CharSequence.indicesOfNextNumOrNull (
startIndex: Int,
) : IntRange? {
if (startIndex > this.lastIndex)
throw IllegalStateException("Your index is not my index.")
val begin = (s... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 1,934 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ThreeSumMulti.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 5,623 | kotlab | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem347/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem347
/**
* LeetCode page: [347. Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(N) where N is the size of nums;
*/
fun topKFrequent(nums: IntArray, k: Int): IntArray {
... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,501 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/org/flightofstairs/ctci/treesAndGraphs/Heap.kt | FlightOfStairs | 509,587,102 | false | {"Kotlin": 38930} | package org.flightofstairs.ctci.treesAndGraphs
// The main thing I learned from this is that it's way easier to implement a heap using an array or list than a
// classic tree. A lot of effort here is spent on pathing to the last element, which is trivial with array.
class Heap<T : Comparable<T>>(private val comparator... | 0 | Kotlin | 0 | 0 | 5f4636ac342f0ee5e4f3517f7b5771e5aabe5992 | 3,221 | FlightOfStairs-ctci | MIT License |
gcj/y2022/round1b/b.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2022.round1b
import kotlin.math.abs
private fun solve(): Long {
val (n, _) = readInts()
val lists = List(n) { readInts() }
var pLow = 0
var pHigh = 0
var costLow = 0L
var costHigh = 0L
for (list in lists) {
val pLowNew = list.minOrNull()!!
val pHighNew = list.maxOrNull()!!
val costLowNew = m... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 904 | competitions | The Unlicense |
src/deselby/fockSpace/BinomialBasis.kt | deselby-research | 166,023,166 | false | null | package deselby.fockSpace
import deselby.fockSpace.extensions.join
import deselby.std.FallingFactorial
import deselby.std.extensions.fallingFactorial
import org.apache.commons.math3.distribution.BinomialDistribution
import org.apache.commons.math3.special.Gamma
import java.io.Serializable
import kotlin.math.ln
import ... | 0 | Kotlin | 1 | 8 | 6c76a9a18e2caafc1ff00ab970d0df4d703f0119 | 6,971 | ProbabilisticABM | MIT License |
src/Day03.kt | rromanowski-figure | 573,003,468 | false | {"Kotlin": 35951} | object Day03 : Runner<Int, Int>(3, 157, 70) {
override fun part1(input: List<String>): Int {
val priorities = input.map { contents ->
val half = contents.length / 2
val left = contents.substring(0, half)
val right = contents.substring(half, contents.length)
va... | 0 | Kotlin | 0 | 0 | 6ca5f70872f1185429c04dcb8bc3f3651e3c2a84 | 952 | advent-of-code-2022-kotlin | Apache License 2.0 |
solutions/aockt/util/Collections.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.util
/**
* Generate a [Sequence] of permutations of this collection.
* For obvious reasons, will throw if the collection is too large.
*/
fun <T> Collection<T>.generatePermutations(): Sequence<List<T>> = when (size) {
!in 0 .. 9 -> throw Exception("Too many permutations. This is probably not what ... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 998 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CountTheRepetitions.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,616 | kotlab | Apache License 2.0 |
src/main/kotlin/g0301_0400/s0395_longest_substring_with_at_least_k_repeating_characters/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0301_0400.s0395_longest_substring_with_at_least_k_repeating_characters
// #Medium #Top_Interview_Questions #String #Hash_Table #Sliding_Window #Divide_and_Conquer
// #2022_11_28_Time_274_ms_(66.67%)_Space_34_MB_(100.00%)
class Solution {
fun longestSubstring(s: String, k: Int): Int {
return helpe... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 970 | LeetCode-in-Kotlin | MIT License |
code-sample-kotlin/algorithms/src/main/kotlin/com/codesample/leetcode/medium/394_decodeString.kt | aquatir | 76,377,920 | false | {"Java": 674809, "Python": 143889, "Kotlin": 112192, "Haskell": 57852, "Elixir": 33284, "TeX": 20611, "Scala": 17065, "Dockerfile": 6314, "HTML": 4714, "Shell": 387, "Batchfile": 316, "Erlang": 269, "CSS": 97} | package com.codesample.leetcode.medium
fun main() {
val s = Solution1()
println(s.decodeString("3[a]2[bc]")) // "aaabcbc"
println(s.decodeString("3[a2[c]]")) // "accaccacc"
println(s.decodeString("2[abc]3[cd]ef")) // "abcabccdcdcdef"
println(s.decodeString("abc3[cd]xyz")) // "abccdcdcdxyz"
}
/** ... | 1 | Java | 3 | 6 | eac3328ecd1c434b1e9aae2cdbec05a44fad4430 | 3,038 | code-samples | MIT License |
Day2_02/src/main/kotlin/Main.kt | mepants | 574,131,679 | false | {"Kotlin": 17592} | import java.io.File
enum class Move(val value: Int)
{
ROCK(1) {
override fun scoreAgainst(opponentMove: Move): Int {
return when (opponentMove) {
ROCK -> 3
PAPER -> 0
SCISSORS -> 6
}
}
override fun losesAgainst() = PAP... | 0 | Kotlin | 0 | 0 | 3b42381c10f3990b5a92cc6e41af04cb67a4fbd4 | 2,095 | Advent-Of-Code-2022 | Creative Commons Zero v1.0 Universal |
src/main/java/challenges/educative_grokking_coding_interview/two_heaps/_2/MedianOfAStream.kt | ShabanKamell | 342,007,920 | false | null | package challenges.educative_grokking_coding_interview.two_heaps._2
import challenges.util.PrintHyphens
import java.util.*
/**
Our task is to implement a data structure that will store a dynamically growing list of integers and provide
access to their median in O(1).
https://www.educative.io/courses/grokking-coding-... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 2,437 | CodingChallenges | Apache License 2.0 |
src/main/kotlin/com/rtarita/days/Day12.kt | RaphaelTarita | 570,100,357 | false | {"Kotlin": 79822} | package com.rtarita.days
import com.rtarita.structure.AoCDay
import com.rtarita.util.day
import com.rtarita.util.ds.graph.Graph
import com.rtarita.util.ds.graph.MutableGraph
import com.rtarita.util.ds.graph.buildGraph
import kotlinx.datetime.LocalDate
import java.util.LinkedList
import java.util.Queue
object Day12 : ... | 0 | Kotlin | 0 | 9 | 491923041fc7051f289775ac62ceadf50e2f0fbe | 4,012 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/me/giacomozama/adventofcode2023/days/Day03.kt | giacomozama | 725,810,476 | false | {"Kotlin": 12023} | package me.giacomozama.adventofcode2023.days
import java.io.File
class Day03 : Day() {
private lateinit var input: List<String>
override fun parseInput(inputFile: File) {
input = inputFile.readLines()
}
override fun solveFirstPuzzle(): Int {
fun isAdjacentToSymbol(y: Int, startX: In... | 0 | Kotlin | 0 | 0 | a86e9757288c63778e1f8f1f3fa5a2cfdaa6dcdd | 3,753 | aoc2023 | MIT License |
src/Day05.kt | elliaoster | 573,666,162 | false | {"Kotlin": 14556} | fun main() {
fun moveBoxes(input: List<String>, multipleBoxMove: Boolean): String {
var tops = ""
//read the file to figure out how many stacks
var numStacks = 0
for (line in input) {
if (line[1] == '1') {
numStacks = line.split(" ").last().toInt()
... | 0 | Kotlin | 0 | 0 | 27e774b133f9d5013be9a951d15cefa8cb01a984 | 3,102 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day11.kt | Walop | 573,012,840 | false | {"Kotlin": 53630} | import java.io.InputStream
data class Monkey(
val items: MutableList<Long>,
val operation: (Long) -> Long,
val test: Long,
val trueReceiver: Int,
val falseReceiver: Int,
var inspectionCount: Long = 0
)
class Day11 {
companion object {
private fun createOperation(operator: String, o... | 0 | Kotlin | 0 | 0 | 7a13f6500da8cb2240972fbea780c0d8e0fde910 | 3,024 | AdventOfCode2022 | The Unlicense |
y2021/src/main/kotlin/adventofcode/y2021/Day19.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2021
import adventofcode.io.AdventSolution
import adventofcode.util.collections.cartesian
import adventofcode.util.vector.Vec3
object Day19 : AdventSolution(2021, 19, "Beacon Scanner") {
override fun solvePartOne(input: String): Any {
val scanners = parse(input)
val closed = ... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 4,404 | advent-of-code | MIT License |
aoc2022/day10.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2022
import utils.InputRetrieval
fun main() {
Day10.execute()
}
object Day10 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2:")
part2(input)
}
private val CYCLES = listOf(20, 60, 100, 140, 180, 220)
private... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 2,124 | Advent-Of-Code | MIT License |
src/year2022/01/Day01.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2022.`01`
import readInput
fun main() {
fun prepareListOfElfsWithCalories(input: List<String>): List<List<Int>> {
return input
// Null is for empty strings that are separators.
.map { it.toIntOrNull() }
.fold(mutableListOf(mutableListOf<Int>())) { listOfElf... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 1,191 | KotlinAdventOfCode | Apache License 2.0 |
kotlin/src/main/kotlin/AoC_Day6.kt | sviams | 115,921,582 | false | null |
object AoC_Day6 {
data class State(val steps: Int, val work: Array<Byte>, val mem: MutableList<Array<Byte>>) {
fun repeats() : Boolean = mem.count { it contentEquals work } > 1
}
fun solve2(input: Array<Byte>) : State {
val width = input.size
return generateSequence(State(0, input... | 0 | Kotlin | 0 | 0 | 19a665bb469279b1e7138032a183937993021e36 | 1,086 | aoc17 | MIT License |
src/Day01.kt | esteluk | 572,920,449 | false | {"Kotlin": 29185} | fun main() {
fun part1(input: List<String>): Int {
var i = 0
val arr = IntArray(input.size)
input.forEach {
if (it.isEmpty()) {
i += 1
} else {
arr[i] += it.toInt()
}
}
return arr.max()
}
fun part2(i... | 0 | Kotlin | 0 | 0 | 5d1cf6c32b0c76c928e74e8dd69513bd68b8cb73 | 918 | adventofcode-2022 | Apache License 2.0 |
src/main/kotlin/com/kishor/kotlin/algo/algorithms/graph/RemoveIslands.kt | kishorsutar | 276,212,164 | false | null | package com.kishor.kotlin.algo.algorithms.graph
import java.util.*
class RemoveIslands {
fun removeIsland(matrix: List<MutableList<Int>>): List<MutableList<Int>> {
for (row in 0 until matrix.size) {
val rowBorder = row == 0 || row == matrix.size - 1
for (col in 0 until matrix[r... | 0 | Kotlin | 0 | 0 | 6672d7738b035202ece6f148fde05867f6d4d94c | 2,085 | DS_Algo_Kotlin | MIT License |
src/Day04.kt | konclave | 573,548,763 | false | {"Kotlin": 21601} | fun main() {
fun solve1(input: List<String>): Int {
return input.filter {
val (fstStart, fstEnd, sndStart, sndEnd) = it.split(Regex("[-,]")).map{ it.toInt() }
sndStart >= fstStart && sndEnd <= fstEnd || fstStart >= sndStart && fstEnd <= sndEnd
}.size
}
fun solve2(input: List... | 0 | Kotlin | 0 | 0 | 337f8d60ed00007d3ace046eaed407df828dfc22 | 650 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/y23/Day01.kt | kezz | 572,635,766 | false | {"Kotlin": 20772} | package days.y23
import util.Day
import util.debug
import util.mapInner
public fun main() {
Day01().run()
}
public class Day01 : Day(23, 1) {
private val replacements = mapOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"five" to 5,
"six" to 6,
"... | 0 | Kotlin | 0 | 0 | 1cef7fe0f72f77a3a409915baac3c674cc058228 | 1,234 | aoc | Apache License 2.0 |
src/main/kotlin/io/undefined/IntervalListIntersections.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.undefined
import io.utils.runTests
// https://leetcode.com/problems/interval-list-intersections/
class IntervalListIntersections {
fun execute(input0: Array<IntArray>, input1: Array<IntArray>): Array<IntArray> {
var index0 = 0
var index1 = 0
val result = mutableListOf<IntArray>()
while (... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,176 | coding | MIT License |
2023/src/main/kotlin/org/suggs/adventofcode/Day08HauntedWasteland.kt | suggitpe | 321,028,552 | false | {"Kotlin": 156836} | package org.suggs.adventofcode
import org.slf4j.LoggerFactory
object Day08HauntedWasteland {
private val log = LoggerFactory.getLogger(this::class.java)
fun countHopsInDataMap(data: List<String>): Long =
countHopsToFinsh("AAA", data.first(), buildHopsDataMapFrom(data), 0)
.also { log.debu... | 0 | Kotlin | 0 | 0 | 9485010cc0ca6e9dff447006d3414cf1709e279e | 2,103 | advent-of-code | Apache License 2.0 |
src/day04/Day04.kt | gagandeep-io | 573,585,563 | false | {"Kotlin": 9775} | package day04
import readInput
fun main() {
fun List<String>.ranges() = map {
val (firstElf, secondElf) = it.split(",")
Pair(firstElf.toRange(), secondElf.toRange())
}
fun part1(input: List<String>): Int =
input.ranges().count { it.first in it.second || it.second in it... | 0 | Kotlin | 0 | 0 | 952887dd94ccc81c6a8763abade862e2d73ef924 | 954 | aoc-2022-kotlin | Apache License 2.0 |
src/Day21.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | private sealed interface MathMonkey {
fun initLeftRight(information: Map<String, MathMonkey>)
fun isConcrete(): Boolean
fun eval(): Long
}
private class JustYell(val name: String, val value: Long) : MathMonkey {
override fun initLeftRight(information: Map<String, MathMonkey>) {}
override fun isConc... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 5,116 | advent-of-kotlin-2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.