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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
common/src/main/kotlin/me/haydencheers/nscpdt/Sequences.kt | hjc851 | 247,242,039 | false | null | package me.haydencheers.nscpdt
import java.util.function.BiPredicate
object Sequences {
// fun findLCS(X: String, Y: String, m: Int = X.length, n: Int = Y.length): String {
// // Create a table to store lengths findLCS longest common
// // suffixes findLCS substrings. Note that LCSuff[i][j]
// ... | 0 | Kotlin | 0 | 0 | b697648f04710a58722dfc1b764a3e43e56b4c4a | 7,799 | NaiveSCPDTools | MIT License |
api/src/main/kotlin/glimpse/SquareMatrix.kt | glimpse-graphics | 44,015,157 | false | null | package glimpse
internal class SquareMatrix(val size: Int, private val elements: (Int, Int) -> Float) {
companion object {
fun nullMatrix(size: Int) = SquareMatrix(size) { row, col -> 0f }
fun identity(size: Int) = SquareMatrix(size) { row, col ->
if (row == col) 1f else 0f
}
}
operator fun get(row: In... | 0 | Kotlin | 0 | 16 | 5069cc1c3f2d8cb344740f3d33bcf11848f94583 | 1,800 | glimpse-framework | Apache License 2.0 |
src/main/kotlin/days/day6/Day6.kt | Stenz123 | 725,707,248 | false | {"Kotlin": 123279, "Shell": 862} | package days.day6
import days.Day
class Day6 : Day(false) {
override fun partOne(): Any {
val times = readInput()[0].substringAfter(":").trim().split(" ").filter { it.isNotBlank() }.map { it.toInt() }
val distances = readInput()[1].substringAfter(":").trim().split(" ").filter { it.isNotBlank() }.m... | 0 | Kotlin | 1 | 0 | 3de47ec31c5241947d38400d0a4d40c681c197be | 1,295 | advent-of-code_2023 | The Unlicense |
src/main/kotlin/g2901_3000/s2925_maximum_score_after_applying_operations_on_a_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2901_3000.s2925_maximum_score_after_applying_operations_on_a_tree
// #Medium #Dynamic_Programming #Depth_First_Search #Tree
// #2024_01_16_Time_706_ms_(81.82%)_Space_84.7_MB_(27.27%)
import kotlin.math.min
class Solution {
fun maximumScoreAfterOperations(edges: Array<IntArray>, values: IntArray): Long {... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,198 | LeetCode-in-Kotlin | MIT License |
Kotlin/RadixSort.kt | argonautica | 212,698,136 | false | {"Java": 42011, "C++": 24846, "C#": 15801, "Python": 14547, "Kotlin": 11794, "C": 10528, "JavaScript": 9054, "Assembly": 5049, "Go": 3662, "Ruby": 1949, "Lua": 687, "Elixir": 589, "Rust": 447} | fun main(args : Array<String>) {
val sorted = radixSort(intArrayOf(4, 4, 4, 1, 7, 9, 5, 37564, 54, 0, 100))
sorted.forEach {
print("$it, ")
}
}
/**
* Sorts positive numbers only using Radix Sort
*/
fun radixSort(input:IntArray):IntArray {
var out = input
val max = input.max()
var ex... | 4 | Java | 138 | 45 | b9ebd2aadc6b59e5feba7d1fe9e0c6a036d33dba | 1,294 | sorting-algorithms | MIT License |
solutions/src/AlmostSorted.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | class AlmostSorted {
fun almostSorted(arr: Array<Int>) {
var sorted = false;
//Swap
var swapIndicies = mutableSetOf<Int>()
for (i in arr.indices) {
if (i < arr.lastIndex && arr[i] > arr[i+1]) {
swapIndicies.add(i)
}
if (i > 0 && ... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 2,896 | leetcode-solutions | MIT License |
2023/4/solve-2.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
import kotlin.math.pow
import kotlin.text.Regex
class Card (
val id: Int,
val winners: Set<Int>,
val numbers: Set<Int>,
) {
fun matchingNumbers () : Set<Int> = numbers.intersect(winners)
}
private fun String.findAllNumbers() = Regex("[0-9]+").findAll(this).map { it.value.toInt() }
... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 1,068 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/Day05.kt | rifkinni | 573,123,064 | false | {"Kotlin": 33155, "Shell": 125} | class LoadingDock(input: String) {
val stacks: MutableList<Stack>
init {
val columnIndexes = regex.getMatchUnsafe(input, "columnIndex")
val stacksString = regex.getMatchUnsafe(input, "stacks")
val numColumns = maxColumn(columnIndexes)
stacks = initializeStacks(numColumns)
... | 0 | Kotlin | 0 | 0 | c2f8ca8447c9663c0ce3efbec8e57070d90a8996 | 4,599 | 2022-advent | Apache License 2.0 |
leetcode/src/offer/middle/Offer34.kt | zhangweizhe | 387,808,774 | false | null | package offer.middle
import linkedlist.TreeNode
import java.util.*
import kotlin.collections.ArrayList
fun main() {
// 剑指 Offer 34. 二叉树中和为某一值的路径
// https://leetcode.cn/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/
}
private fun pathSum(root: TreeNode?, target: Int): List<List<Int>> {
val r... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,016 | kotlin-study | MIT License |
src/main/kotlin/aoc2015/day03_spherical_houses/SphericalHouses.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package aoc2015.day03_spherical_houses
import geom2d.Point
import geom2d.toDir
import kotlin.streams.toList
fun main() {
util.solve(2565, ::partOne)
util.solve(2639, ::partTwo)
}
private fun String.toDirList() = this
.chars()
.mapToObj { it.toChar().toDir() }
.toList()
fun partOne(input: String)... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 1,064 | aoc-2021 | MIT License |
src/leetcodeProblem/leetcode/editor/en/ReverseWordsInAStringIii.kt | faniabdullah | 382,893,751 | false | null | //Given a string s, reverse the order of characters in each word within a
//sentence while still preserving whitespace and initial word order.
//
//
// Example 1:
// Input: s = "Let's take LeetCode contest"
//Output: "s'teL ekat edoCteeL tsetnoc"
// Example 2:
// Input: s = "<NAME>"
//Output: "doG gniD"
//
//
// ... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,096 | dsa-kotlin | MIT License |
common/src/commonMain/kotlin/data/Ratings.kt | DennisTsar | 555,073,105 | false | {"Kotlin": 31172} | package data
typealias Ratings = List<List<Int>>
class RatingStats(
val ratings: List<Double>,
val numResponses: Int,
)
// returns list of (# of 1s, # of 2s, ... # of 5s) for each question
// note that entries must have scores.size>=100 - maybe throw error?
// ***IMPORTANT NOTE*** By default, don't give rati... | 0 | Kotlin | 0 | 4 | 8ed0afdf5f1024bb8c56398fad049eb512dc8398 | 1,647 | RU-SIRS | MIT License |
src/main/kotlin/com/sk/set29/2975. Maximum Square Area by Removing Fences From a Field.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.set29
import kotlin.math.abs
class Solution2975 {
fun maximizeSquareArea(
m: Int, n: Int, hFences: IntArray, vFences: IntArray
): Int {
vFences.sort()
hFences.sort()
val X = mutableListOf<Int>()
X.add(0)
for(x in vFences) X.add(x-1)
X.add... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 2,385 | leetcode-kotlin | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2021/Day9.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2021
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import com.s13g.aoc.mul
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
/**
* --- Day 9: Smoke Basin ---
* https://adventofcode.com/2021/day/9
*/
class Day9 : Solver {
ov... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 3,140 | euler | Apache License 2.0 |
solutions/aockt/y2015/Y2015D11.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2015
import io.github.jadarma.aockt.core.Solution
object Y2015D11 : Solution {
// Predicates for a valid password
private val illegalCharacterRule = Regex("""[iol]""")
private val doublePairRule = Regex("""(.)\1(?!.*\1.*$).*(.)\2""")
private val passwordValidationRules: List<(String) ... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 1,378 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/com/nibado/projects/advent/y2017/Day14.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2017
import com.nibado.projects.advent.*
import com.nibado.projects.advent.Point
object Day14 : Day {
private val rows = (0..127).map { "amgozmfv-$it" }
private val square : List<String> by lazy { rows.map { hash(it) }.map { toBinary(it) } }
override fun part1() = squa... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 1,301 | adventofcode | MIT License |
Hangman/getRoundResultsFunction/src/main/kotlin/jetbrains/kotlin/course/hangman/Main.kt | jetbrains-academy | 504,249,857 | false | {"Kotlin": 1108971} | package jetbrains.kotlin.course.hangman
// You will use this function later
fun getGameRules(wordLength: Int, maxAttemptsCount: Int) = "Welcome to the game!$newLineSymbol$newLineSymbol" +
"In this game, you need to guess the word made by the computer.$newLineSymbol" +
"The hidden word will appear as a ... | 14 | Kotlin | 1 | 6 | bc82aaa180fbd589b98779009ca7d4439a72d5e5 | 3,270 | kotlin-onboarding-introduction | MIT License |
src/main/kotlin/days/Day12.kt | hughjdavey | 225,440,374 | false | null | package days
import kotlin.math.abs
class Day12 : Day(12) {
private fun moonPositions() = inputList.map { it.replace(Regex("[<>=xyz ]"), "") }.map {
val (x, y, z) = it.split(",").map { it.toInt() }
Coord3D(x, y, z)
}
override fun partOne(): Any {
val moonTracker = MoonTracker(moo... | 0 | Kotlin | 0 | 1 | 84db818b023668c2bf701cebe7c07f30bc08def0 | 4,166 | aoc-2019 | Creative Commons Zero v1.0 Universal |
common/search/src/main/kotlin/com/curtislb/adventofcode/common/search/FindSum.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.common.search
/**
* Returns a list of [minSize] or more contiguous values in the iterable that sum to [targetSum],
* or `null` if are no such values.
*
* @throws IllegalArgumentException If [targetSum] or [minSize] is negative, or a negative value is
* encountered during iterati... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 4,658 | AdventOfCode | MIT License |
src/Day10.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | object Day10 {
const val EXPECTED_PART1_CHECK_ANSWER = 13140
const val EXPECTED_PART2_CHECK_ANSWER = 1
val CYCLE_PROBE_POINTS = listOf(20, 60, 100, 140, 180, 220)
const val CRT_LINE_WIDTH = 40
}
sealed class CpuInstruction(val cycles: Int)
class Noop : CpuInstruction(1)
class AddX(val arg: Int) : Cpu... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 3,374 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/Day11.kt | clechasseur | 267,632,210 | false | null | object Day11 {
private val input = IsolatedArea(listOf(
Floor(setOf(
InterestingObject("thulium", ObjectType.GENERATOR),
InterestingObject("thulium", ObjectType.MICROCHIP),
InterestingObject("plutonium", ObjectType.GENERATOR),
InterestingObject("strontium", Ob... | 0 | Kotlin | 0 | 0 | 120795d90c47e80bfa2346bd6ab19ab6b7054167 | 5,033 | adventofcode2016 | MIT License |
src/main/kotlin/me/grison/aoc/Graphs.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc
import util.CYAN
import java.util.*
import java.util.function.Predicate
import kotlin.collections.ArrayDeque
import kotlin.collections.set
import kotlin.math.pow
typealias Graph<T> = MutableMap<T, MutableList<T>>
fun <T> List<Pair<T, T>>.toGraph() = graph(this)
fun <T> graph(edges: List<Pair<T,... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 16,196 | advent-of-code | Creative Commons Zero v1.0 Universal |
test-case-factory/src/main/java/com/barteklipinski/testcasefactory/CombinationsBuilder.kt | blipinsk | 439,698,827 | false | {"Kotlin": 159143} | package com.barteklipinski.testcasefactory
interface CombinationsBuilder<X, I : Combination> {
val acceptedValues: List<X>
val combinations: List<I>
}
// "Next" builder holds previous combinations.
internal interface NextCombinationsBuilder<T : Combination> {
val previousCombinations: List<T>
}
private f... | 0 | Kotlin | 0 | 2 | 9820d6ed81cfa9cd595a45cd0c600afe89d2d6e1 | 4,875 | test-case-factory | Apache License 2.0 |
src/main/kotlin/nl/hannahsten/utensils/math/matrix/MatrixFunctions.kt | Hannah-Sten | 115,186,492 | false | {"Kotlin": 239636, "Java": 25985} | package nl.hannahsten.utensils.math.matrix
import kotlin.math.sqrt
/**
* Returns a new matrix where each element is mapped to another element.
* The transformation function also contains the row and column index of the elements.
*
* The resulting matrix carries over the major of the original matrix.
*
* @param ... | 0 | Kotlin | 0 | 4 | f8aab17e5107272c0e7b6fa3ddc67df4281b6cf6 | 3,649 | Utensils | MIT License |
src/Day09.kt | acunap | 573,116,784 | false | {"Kotlin": 23918} | import kotlin.math.abs
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
@OptIn(ExperimentalTime::class)
fun main() {
fun part1(input: List<String>) : Int {
var head = Pair(0,0)
var tail = Pair(0, 0)
val tailHistory = mutableSetOf(tail)
fun moveTail() {
... | 0 | Kotlin | 0 | 0 | f06f9b409885dd0df78f16dcc1e9a3e90151abe1 | 5,515 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/io/github/lawseff/aoc2023/substring/NumberBuilder.kt | lawseff | 573,226,851 | false | {"Kotlin": 37196} | package io.github.lawseff.aoc2023.substring
/**
* Class for building numbers from digits, that are contained in a string input
*/
class NumberBuilder {
companion object {
private val DIGITS_BY_WORDS = mapOf(
"zero" to 0,
"one" to 1,
"two" to 2,
"three" to ... | 0 | Kotlin | 0 | 0 | b60ab611aec7bb332b8aa918aa7c23a43a3e61c8 | 2,760 | advent-of-code-2023 | MIT License |
src/Day06.kt | ThijsBoehme | 572,628,902 | false | {"Kotlin": 16547} | fun main() {
fun findMarker(input: String, markerSize: Int): Int {
val marker = input.windowed(markerSize)
.first { chunk ->
chunk.toSet().size == markerSize
}
return input.indexOf(marker) + markerSize
}
fun part1(input: String): Int {
return ... | 0 | Kotlin | 0 | 0 | 707e96ec77972145fd050f5c6de352cb92c55937 | 1,168 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/java/dev/haenara/mailprogramming/solution/y2019/m12/d08/Solution191208.kt | HaenaraShin | 226,032,186 | false | null | import dev.haenara.mailprogramming.solution.Solution
/**
* 매일프로그래밍 2019. 12. 08
* 피보나치 배열은 0과 1로 시작하며, 다음 피보나치 수는 바로 앞의 두 피보나치 수의 합이 된다.
* 정수 N이 주어지면, N보다 작은 모든 짝수 피보나치 수의 합을 구하여라.
* Fibonacci sequence starts with 0 and 1 where each fibonacci number is a sum of two previous fibonacci numbers.
* Given an integer ... | 0 | Kotlin | 0 | 7 | b5e50907b8a7af5db2055a99461bff9cc0268293 | 1,273 | MailProgramming | MIT License |
src/main/kotlin/me/peckb/aoc/_2022/calendar/day18/Day18.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2022.calendar.day18
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import me.peckb.aoc.pathing.GenericIntDijkstra
class Day18 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
fun partOne(filename: String) = generat... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 3,178 | advent-of-code | MIT License |
src/main/App.kt | neelkamath | 187,355,278 | false | null | package com.neelkamath.seeds
private fun prompt(message: String) = print(message).run { readLine()!! }
private fun promptSize(type: String): Int {
val input = prompt("Enter the number of $type (\"r\" for random): ")
if (input == "r") return 100
val num = input.toIntOrNull() ?: promptSize(type)
return ... | 0 | Kotlin | 1 | 0 | c01db90c48be43173084ba5b29d6f3470179ff7d | 1,639 | seeds | MIT License |
src/Day06b.kt | mlidal | 572,869,919 | false | {"Kotlin": 20582} |
fun main() {
fun part1(input: String): Int {
var chars = mutableListOf<Char>()
input.forEachIndexed { index, char ->
if (!chars.contains(char)) {
chars.add(char)
if (chars.size == 4) {
return index + 1
}
}... | 0 | Kotlin | 0 | 0 | bea7801ed5398dcf86a82b633a011397a154a53d | 1,348 | AdventOfCode2022 | Apache License 2.0 |
y2015/src/main/kotlin/adventofcode/y2015/Day07.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2015
import adventofcode.io.AdventSolution
object Day07 : AdventSolution(2015, 7, "Some Assembly Required") {
override fun solvePartOne(input: String) = WireMap(input.lines()).evaluate("a").toString()
override fun solvePartTwo(input: String): String {
val result = WireMap(input.lines()).ev... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,237 | advent-of-code | MIT License |
src/Day06.kt | hiteshchalise | 572,795,242 | false | {"Kotlin": 10694} | fun main() {
fun part1(input: List<String>): Int {
val windowSize = 4
val signal = input[0]
val windowsOfFourSignals = signal.windowed(windowSize, 1, false)
val indexOfFirst = windowsOfFourSignals.indexOfFirst {
val setOfCharacter = it.toCharArray().toSet()
s... | 0 | Kotlin | 0 | 0 | e4d66d8d1f686570355b63fce29c0ecae7a3e915 | 1,084 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NextPermutation.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,655 | kotlab | Apache License 2.0 |
ahp-base/src/test/kotlin/PMIgenerator.kt | sbigaret | 164,424,298 | true | {"Kotlin": 93061, "R": 67629, "Shell": 24899, "Groovy": 24559} | import org.xmcda.*
import org.xmcda.converters.v2_v3.XMCDAConverter
import org.xmcda.parsers.xml.xmcda_v3.XMCDAParser
import org.xmcda.utils.Coord
import org.xmcda.utils.Matrix
import java.io.File
fun crt(id: String, name: String) = Criterion(id, name)
fun alt(id: String, name: String) = Alternative(id).also {
it... | 0 | Kotlin | 0 | 0 | 96c182d7e37b41207dc2da6eac9f9b82bd62d6d7 | 15,519 | DecisionDeck | MIT License |
src/main/java/ReplaceCharactersWithBiggerAscii.kt | ShabanKamell | 342,007,920 | false | null | /*
Given a string str consisting of lowercase letters only and an integer k,
the task is to replace every character of the given string by character whose ASCII value is k times more than it.
If ASCII value exceeds ‘z’, then start checking from ‘a’ in a cyclic manner.
Examples:
Input: str = “abc”, k = 2
Output: cde
a... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 1,813 | CodingChallenges | Apache License 2.0 |
src/aoc2022/day01/Day01.kt | svilen-ivanov | 572,637,864 | false | {"Kotlin": 53827} | @file:Suppress("UnstableApiUsage")
package aoc2022.day01
import com.google.common.collect.MinMaxPriorityQueue
import readInput
import java.util.*
import kotlin.Comparator
fun main() {
fun part1(input: List<String>): Int {
var max = Int.MIN_VALUE
var elf = 1
var i = 1
var sum = 0
... | 0 | Kotlin | 0 | 0 | 456bedb4d1082890d78490d3b730b2bb45913fe9 | 1,784 | aoc-2022 | Apache License 2.0 |
src/problems/61-RotateRight.kt | w1374720640 | 352,006,409 | false | null | package problems
import base.ListNode
import base.createListNode
import base.toIntArray
/**
* 61. 旋转链表 https://leetcode-cn.com/problems/rotate-list/
* 给你一个链表的头节点head,旋转链表,将链表每个节点向右移动k个位置。
*
* 解:旋转链表操作等价于将链表最后k个元素删除,并拼接到链表头部,
* 对于长度小于k的链表,k等于k除以size的余数
* 从头节点开始遍历,记录节点总数、倒数第k+1个节点和最后一个节点,
* 到链表结尾时,若节点总数大于k,使用临时变... | 0 | Kotlin | 0 | 0 | 21c96a75d13030009943474e2495f1fc5a7716ad | 2,517 | LeetCode | MIT License |
aoc21/day_03/main.kt | viktormalik | 436,281,279 | false | {"Rust": 227300, "Go": 86273, "OCaml": 82410, "Kotlin": 78968, "Makefile": 13967, "Roff": 9981, "Shell": 2796} | import java.io.File
fun List<String>.mcb(i: Int) =
if (this.filter { it[i] == '1' }.count() >= this.size / 2) '1' else '0'
fun main() {
val nums = File("input").readLines()
val gamma = nums[0].withIndex().map { (i, _) -> nums.mcb(i) }.joinToString("")
val epsilon = gamma.map { if (it == '1') '0' else... | 0 | Rust | 1 | 0 | f47ef85393d395710ce113708117fd33082bab30 | 763 | advent-of-code | MIT License |
src/Day13.kt | vitind | 578,020,578 | false | {"Kotlin": 60987} |
fun main() {
fun removeOuterSquareBrackets(line: String) : String {
val sb = StringBuilder(line)
val openSquareBracketIndex = sb.indexOfFirst { it.equals('[') }
sb.replace(openSquareBracketIndex, openSquareBracketIndex + 1, "")
val closeSquareBracketIndex = sb.indexOfLast { it.equal... | 0 | Kotlin | 0 | 0 | 2698c65af0acd1fce51525737ab50f225d6502d1 | 5,293 | aoc2022 | Apache License 2.0 |
src/main/kotlin/days/y2019/Day04/day05.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2019.Day04
import days.Day
public class Day04 : Day(2019, 4) {
override fun partOne(input: String): Any {
val (start, end) = input.split("-").map { it.toInt() }
return (start..end).count { it.isValid() }
}
override fun partTwo(input: String): Any {
val (start, end)... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 1,058 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/d13_TransparentOrigami/TransparentOrigami.kt | aormsby | 425,644,961 | false | {"Kotlin": 68415} | package d13_TransparentOrigami
import util.Coord
import util.Input
import util.Output
import kotlin.math.abs
fun main() {
Output.day(13, "Transparent Origami")
val startTime = Output.startTime()
val input = Input.parseLines(filename = "/input/d13_fold_instructions.txt")
var page = input.dropLastWhil... | 0 | Kotlin | 1 | 1 | 193d7b47085c3e84a1f24b11177206e82110bfad | 1,789 | advent-of-code-2021 | MIT License |
src/Day14.kt | HaydenMeloche | 572,788,925 | false | {"Kotlin": 25699} | import java.lang.Integer.max
import java.lang.Integer.min
fun main() {
val input = readInput("Day14test")
infix fun Int.range(i: Int) = min(this, i)..max(this, i)
val rock = input.flatMap { row ->
row.split(" -> ", ",").map(String::toInt).windowed(4, 2).flatMap { (x1, y1, x2, y2) ->
if... | 0 | Kotlin | 0 | 1 | 1a7e13cb525bb19cc9ff4eba40d03669dc301fb9 | 1,056 | advent-of-code-kotlin-2022 | Apache License 2.0 |
2016/src/main/kotlin/com/koenv/adventofcode/Day1.kt | koesie10 | 47,333,954 | false | null | package com.koenv.adventofcode
object Day1 {
fun getBlocksAway(input: String): Int {
var heading: Int = 0 // heading North, positive is clockwise
// store our coordinates
var x: Int = 0
var y: Int = 0
input.split(",").map(String::trim).forEach {
heading = getNew... | 0 | Kotlin | 0 | 0 | 29f3d426cfceaa131371df09785fa6598405a55f | 2,996 | AdventOfCode-Solutions-Kotlin | MIT License |
src/main/kotlin/org/kotrix/matrix/MatrixExponentialPrototype.kt | JarnaChao09 | 285,169,397 | false | {"Kotlin": 446442, "Jupyter Notebook": 26378} | package org.kotrix.matrix
import org.kotrix.utils.by
import kotlin.math.abs
/**
* @param current the current resultant matrix in the series
* @param previous the previous resultant matrix in the series
*
* @return true if the matrices have converged based on a tolerance
*/
private fun checkForConvergence(current... | 0 | Kotlin | 1 | 5 | c5bb19457142ce1f3260e8fed5041a4d0c77fb14 | 2,165 | Kotrix | MIT License |
src/main/kotlin/com/colinodell/advent2016/Day15.kt | colinodell | 495,627,767 | false | {"Kotlin": 80872} | package com.colinodell.advent2016
class Day15(input: List<String>) {
private val discs = input.map { Disc.fromString(it) }
fun solvePart1() = solve(false)
fun solvePart2() = solve(true)
private fun solve(withExtraDisc: Boolean): Int {
val discs = if (withExtraDisc) this.discs.plus(Disc(this.d... | 0 | Kotlin | 0 | 0 | 8a387ddc60025a74ace8d4bc874310f4fbee1b65 | 1,061 | advent-2016 | Apache License 2.0 |
src/Day17.kt | Kvest | 573,621,595 | false | {"Kotlin": 87988} | import java.util.*
fun main() {
val testInput = readInput("Day17_test")[0]
check(part1(testInput) == 3068)
check(part2(testInput) == 1514285714288L)
val input = readInput("Day17")[0]
println(part1(input))
println(part2(input))
}
private const val PART1_ROCKS_COUNT = 2022
private const val PAR... | 0 | Kotlin | 0 | 0 | 6409e65c452edd9dd20145766d1e0ea6f07b569a | 5,143 | AOC2022 | Apache License 2.0 |
src/main/kotlin/Main.kt | Trilgon | 484,536,097 | false | {"Kotlin": 2146} | import java.util.*
fun main(args: Array<String>) {
val input: StringBuilder = StringBuilder("10.3 + -2")
val queueNumbers: Queue<Double> = LinkedList<Double>()
val queueActions: Queue<Char> = LinkedList<Char>()
println('\"' + input.toString() + '\"')
prepareIn(input, queueNumbers, queueActions)
... | 0 | Kotlin | 0 | 0 | 8273ff6e20072015b01a1b8ba3432b8e17728601 | 2,146 | LearningKotlin | MIT License |
day3/day3/src/main/kotlin/Day13.kt | teemu-rossi | 437,894,529 | false | {"Kotlin": 28815, "Rust": 4678} | data class PointI(val x: Int, val y: Int)
fun main(args: Array<String>) {
val values = generateSequence(::readLine)
.mapNotNull { line -> line.trim().takeUnless { trimmed -> trimmed.isBlank() } }
.toList()
val coords = values
.filter { it.contains(",") }
.map {
val ... | 0 | Kotlin | 0 | 0 | 16fe605f26632ac2e134ad4bcf42f4ed13b9cf03 | 1,482 | AdventOfCode | MIT License |
src/main/kotlin/g0301_0400/s0373_find_k_pairs_with_smallest_sums/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0301_0400.s0373_find_k_pairs_with_smallest_sums
// #Medium #Array #Heap_Priority_Queue #2022_11_22_Time_1809_ms_(80.95%)_Space_119.1_MB_(66.67%)
import java.util.PriorityQueue
import kotlin.collections.ArrayList
class Solution {
private class Node(index: Int, num1: Int, num2: Int) {
var sum: Lon... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,350 | LeetCode-in-Kotlin | MIT License |
2022/src/main/kotlin/de/skyrising/aoc2022/day17/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2022.day17
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.ints.IntArrayList
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap
import kotlin.math.max
private fun collides(rock: List<Vec2i>, pos: Vec2i, landed: Set<Vec2i>): Boolean {
for (p in rock) {
val p1 = p + p... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 3,639 | aoc | MIT License |
src/Day06.kt | mcdimus | 572,064,601 | false | {"Kotlin": 32343} | import util.readInput
fun main() {
fun part1(input: List<String>) = findLastIndexOfUniqueCharsSequence(input[0], 4)
fun part2(input: List<String>) = findLastIndexOfUniqueCharsSequence(input[0], 14)
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day06_t... | 0 | Kotlin | 0 | 0 | dfa9cfda6626b0ee65014db73a388748b2319ed1 | 842 | aoc-2022 | Apache License 2.0 |
year2015/src/main/kotlin/net/olegg/aoc/year2015/day16/Day16.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2015.day16
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2015.DayOf2015
/**
* See [Year 2015, Day 16](https://adventofcode.com/2015/day/16)
*/
object Day16 : DayOf2015(16) {
private val PATTERN = "^Sue (\\d+): (.*)$".toRegex()
private val ANIMAL = "([a-z]+): (\\d+)".toR... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,520 | adventofcode | MIT License |
src/Day01.kt | RichardLiba | 572,867,612 | false | {"Kotlin": 16347} | import java.lang.Integer.max
fun main() {
fun part1(input: List<String>): Int {
var caloriesForElf = 0
val caloriesByElves: MutableList<Int> = mutableListOf()
var max = 0
input.forEach {
if (it.isEmpty() || it.toIntOrNull() == null) {
// next elf
... | 0 | Kotlin | 0 | 0 | 6a0b6b91b5fb25b8ae9309b8e819320ac70616ed | 1,219 | aoc-2022-in-kotlin | Apache License 2.0 |
baparker/10/main.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File
val OPENERS = listOf('(', '[', '{', '<')
val CLOSERS = listOf(')', ']', '}', '>')
val PENALTIES = listOf(3, 57, 1197, 25137)
val GOOD_VALUES = listOf(1, 2, 3, 4)
fun parseLineAndFindFirstError(line: String): Int {
val openerStack: MutableList<Char> = mutableListOf()
line.forEach {
... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 1,811 | advent-of-code-2021 | MIT License |
src/main/kotlin/g1701_1800/s1733_minimum_number_of_people_to_teach/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1701_1800.s1733_minimum_number_of_people_to_teach
// #Medium #Array #Greedy #2023_06_16_Time_580_ms_(100.00%)_Space_57.1_MB_(100.00%)
class Solution {
fun minimumTeachings(n: Int, languages: Array<IntArray>, friendships: Array<IntArray>): Int {
val m: Int = languages.size
val speak: Array... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,379 | LeetCode-in-Kotlin | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions35.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
import kotlin.math.min
fun test35() {
printlnResult(arrayOf("23:50", "23:59", "00:00"))
printlnResult(arrayOf("20:50", "23:59", "21:38", "19:23", "18:47", "22:16"))
}
/**
* Questions 35: Give a group of time, find the smallest time difference
*/
private fun Array<Str... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,382 | Algorithm | Apache License 2.0 |
src/days/Day05.kt | EnergyFusion | 572,490,067 | false | {"Kotlin": 48323} | import java.io.BufferedReader
fun main() {
val day = 5
fun buildStacks(map: List<String>): List<ArrayDeque<Char>> {
val numberOfColumns = map.last().trim().last().toString().toInt()
val stacks = List(numberOfColumns) { ArrayDeque<Char>() }
map.dropLast(1).reversed().forEach { line ->
... | 0 | Kotlin | 0 | 0 | 06fb8085a8b1838289a4e1599e2135cb5e28c1bf | 3,219 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/day18.kt | tobiasae | 434,034,540 | false | {"Kotlin": 72901} | import java.util.ArrayDeque
class Day18 : Solvable("18") {
override fun solveA(input: List<String>): String {
return input
.map { SnailFishNumber.fromString(it) }
.reduce { l, r -> l + r }
.magnitude()
.toString()
}
override fun solv... | 0 | Kotlin | 0 | 0 | 16233aa7c4820db072f35e7b08213d0bd3a5be69 | 4,958 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Day07.kt | arturkowalczyk300 | 573,084,149 | false | {"Kotlin": 31119} | //region data classes
enum class PROMPT_TYPE {
COMMAND_CD_ROOT, //move to root
COMMAND_CD_LOWER_LEVEL, //lower level, means deeper in file structure
COMMAND_CD_UPPER_LEVEL, //upper level means returning closer to the root of file system
COMMAND_LS
}
abstract class FileSystemElement(var size: Int, var ... | 0 | Kotlin | 0 | 0 | 69a51e6f0437f5bc2cdf909919c26276317b396d | 7,675 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/g1401_1500/s1498_number_of_subsequences_that_satisfy_the_given_sum_condition/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1401_1500.s1498_number_of_subsequences_that_satisfy_the_given_sum_condition
// #Medium #Array #Sorting #Binary_Search #Two_Pointers #Binary_Search_II_Day_15
// #2023_06_13_Time_487_ms_(97.89%)_Space_52.4_MB_(100.00%)
class Solution {
fun numSubseq(nums: IntArray, target: Int): Int {
// sorted arr... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,238 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/solutions/Day08.kt | chutchinson | 573,586,343 | false | {"Kotlin": 21958} | typealias Ray = Sequence<Int>
class Day08 : Solver {
override fun solve (input: Sequence<String>) {
val heights = input.map { it.map { it.digitToInt() }}.flatten().toList()
val grid = Grid(heights)
println(first(grid))
println(second(grid))
}
fun first (grid: Grid): In... | 0 | Kotlin | 0 | 0 | 5076dcb5aab4adced40adbc64ab26b9b5fdd2a67 | 1,810 | advent-of-code-2022 | MIT License |
src/main/kotlin/de/pgebert/aoc/days/Day05.kt | pgebert | 724,032,034 | false | {"Kotlin": 65831} | package de.pgebert.aoc.days
import de.pgebert.aoc.Day
import kotlin.math.max
import kotlin.math.min
class Day05(input: String? = null) : Day(5, "If You Give A Seed A Fertilizer", input) {
private val SEEDS_PREFIX = "seeds:"
override fun partOne(): Long = with(inputList.iterator()) {
var value = ne... | 0 | Kotlin | 1 | 0 | a30d3987f1976889b8d143f0843bbf95ff51bad2 | 2,418 | advent-of-code-2023 | MIT License |
2022/Day18.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | fun main() {
data class Point3(
val x: Int,
val y: Int,
val z: Int,
) {
fun sides() = listOf(
Point3(x+1, y, z), Point3(x-1, y, z),
Point3(x, y+1, z), Point3(x, y-1, z),
Point3(x, y, z+1), Point3(x, y, z-1),
)
}
val input = read... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 1,086 | advent-of-code-kotlin | Apache License 2.0 |
src/array/LeetCode283.kt | Alex-Linrk | 180,918,573 | false | null | package array
/**
* 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。
示例:
输入: [0,1,0,3,12]
输出: [1,3,12,0,0]
说明:
必须在原数组上操作,不能拷贝额外的数组。
尽量减少操作次数。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/move-zeroes
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
*/
class LeetCode283 {
fun moveZeroes(nums: IntArray): Unit {
... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 1,104 | LeetCode | Apache License 2.0 |
src/Day18/day19.kt | Nathan-Molby | 572,771,729 | false | {"Kotlin": 95872, "Python": 13537, "Java": 3671} | package Day18
import readInput
import java.util.Objects
import kotlin.math.*
class Coordinate(var x: Int, var y: Int, var z: Int) {
override fun equals(other: Any?) = (other is Coordinate)
&& x == other.x
&& y == other.y
&& z == other.z
override fun hashCode(): Int {
... | 0 | Kotlin | 0 | 0 | 750bde9b51b425cda232d99d11ce3d6a9dd8f801 | 6,759 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/de/consuli/aoc/year2022/days/Day03.kt | ulischulte | 572,773,554 | false | {"Kotlin": 40404} | package de.consuli.aoc.year2022.days
import de.consuli.aoc.common.Day
class Day03 : Day(3, 2022) {
override fun partOne(testInput: Boolean): Any {
return getInput(testInput).sumOf {
getPriorityForItemInBothCompartments(it)
}
}
override fun partTwo(testInput: Boolean): Any {
... | 0 | Kotlin | 0 | 2 | 21e92b96b7912ad35ecb2a5f2890582674a0dd6a | 1,054 | advent-of-code | Apache License 2.0 |
src/day6/Day06.kt | kacperhreniak | 572,835,614 | false | {"Kotlin": 85244} | package day6
import readInput
private fun calculate(input: String, uniqueCharCount: Int): Int {
val cache = hashMapOf<Char, Int>()
for((index, item) in input.withIndex()) {
if(cache.containsKey(item).not()) {
cache.put(item, index)
} else {
val currentIndex = cache[item... | 0 | Kotlin | 1 | 0 | 03368ffeffa7690677c3099ec84f1c512e2f96eb | 881 | aoc-2022 | Apache License 2.0 |
src/array/LeetCode131.kt | Alex-Linrk | 180,918,573 | false | null | package array
import kotlin.math.max
/**
* 分割回文串
给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。
返回 s 所有可能的分割方案。
示例:
输入: "aab"
输出:
[
["aa","b"],
["a","a","b"]
]
*/
class Solution131 {
fun newPartition(s: String): List<List<String>> {
var start = 1
var newList = mutableListOf<List<String>>()
if (sta... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 3,276 | LeetCode | Apache License 2.0 |
src/main/Day03.kt | lifeofchrome | 574,709,665 | false | {"Kotlin": 19233} | package main
import readInput
fun main() {
val input = readInput("Day03")
val day3 = Day03(input)
print("Part 1: ${day3.part1()}\n")
print("Part 2: ${day3.part2()}")
}
class Day03(private val input: List<String>) {
private fun itemToPriority(item: Char): Int {
return when(item.code) {
... | 0 | Kotlin | 0 | 0 | 6c50ea2ed47ec6e4ff8f6f65690b261a37c00f1e | 1,237 | aoc2022 | Apache License 2.0 |
src/main/java/com/booknara/problem/array/CheckIfTwoStringArraysAreEquivalentKt.kt | booknara | 226,968,158 | false | {"Java": 1128390, "Kotlin": 177761} | package com.booknara.problem.array
/**
* 1662. Check If Two String Arrays are Equivalent (Easy)
* https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/
*/
class CheckIfTwoStringArraysAreEquivalentKt {
// T:O(max(len(n), len(m)), S:O(1)
fun arrayStringsAreEqual(word1: Array<String>, word2: Arr... | 0 | Java | 1 | 1 | 04dcf500ee9789cf10c488a25647f25359b37a53 | 1,450 | playground | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem90/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem90
/**
* LeetCode page: [90. Subsets II](https://leetcode.com/problems/subsets-ii/);
*/
class Solution {
/* Complexity:
* Time O(N * 2^N) and Space O(N * 2^N) where N is the size of nums;
*/
fun subsetsWithDup(nums: IntArray): List<List<Int>> {
val coun... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,203 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day09.kt | luiscobo | 574,302,765 | false | {"Kotlin": 19047} | import javax.swing.plaf.metal.MetalTabbedPaneUI
import kotlin.math.abs
import kotlin.math.sign
typealias Position = Pair<Int, Int>
// Para saber si las posiciones están cercanas
fun touching(H: Position, T: Position): Boolean {
return abs(H.first - T.first) <= 1 &&
abs(H.second - T.second) <= 1
}
fun ... | 0 | Kotlin | 0 | 0 | c764e5abca0ea40bca0b434bdf1ee2ded6458087 | 2,564 | advent-of-code-2022 | Apache License 2.0 |
src/test/kotlin/biz/koziolek/adventofcode/year2023/day02/Day2Test.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2023.day02
import biz.koziolek.adventofcode.findInput
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
@Tag("2023")
internal class Day2Test {
private val sampleInput = """
Game 1: 3 blue, 4 red; 1 red, 2... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 4,026 | advent-of-code | MIT License |
src/2020/Day9_2.kts | Ozsie | 318,802,874 | false | {"Kotlin": 99344, "Python": 1723, "Shell": 975} | import java.io.File
val input = ArrayList<Long>()
File("input/2020/day9").forEachLine {
input.add(it.toLong())
}
val window = 25
input.forEachIndexed { i, current -> if (i >= window && !check(input.subList(i - window, i), current)) crack(current) }
fun check(subList: List<Long>, current: Long): Boolean {
v... | 0 | Kotlin | 0 | 0 | d938da57785d35fdaba62269cffc7487de67ac0a | 912 | adventofcode | MIT License |
src/main/kotlin/kr/co/programmers/P42579.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
class P42579 {
fun solution(genres: Array<String>, plays: IntArray): IntArray {
// 해시 구조로 저장
// 장르 : [<인덱스, 재생 횟수>, ..., ...]
val hash = mutableMapOf<String, MutableList<IntArray>>().apply {
for (i in plays.indices) {
val genre = genres[... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,095 | algorithm | MIT License |
year2019/day20/maze/src/main/kotlin/com/curtislb/adventofcode/year2019/day20/maze/Maze.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.year2019.day20.maze
import com.curtislb.adventofcode.common.collection.getOrNull
import com.curtislb.adventofcode.common.grid.Grid
import com.curtislb.adventofcode.common.geometry.Point
import com.curtislb.adventofcode.common.graph.UnweightedGraph
import com.curtislb.adventofcode.comm... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 10,870 | AdventOfCode | MIT License |
src/main/kotlin/adventofcode2020/Day16TicketTranslation.kt | n81ur3 | 484,801,748 | false | {"Kotlin": 476844, "Java": 275} | package adventofcode2020
class Day17TickeTranslation
data class CodeRange(val name: String, val firstRange: IntRange, val secondRange: IntRange) {
fun isValidNumber(number: Int) = number in firstRange || number in secondRange
}
class TicketReader {
val validRanges = mutableListOf<CodeRange>()
val validTi... | 0 | Kotlin | 0 | 0 | fdc59410c717ac4876d53d8688d03b9b044c1b7e | 2,538 | kotlin-coding-challenges | MIT License |
stepik/sportprogramming/UnlimitedAudienceApplicationsGreedyAlgorithm.kt | grine4ka | 183,575,046 | false | {"Kotlin": 98723, "Java": 28857, "C++": 4529} | package stepik.sportprogramming
import java.io.File
fun main() {
val rooms = IntArray(33000) { 0 }
val applications = readFromFile()
println("Max of applications is ${count(rooms, applications)}")
}
private fun readFromFile(): MutableList<AudienceApplication> {
val applications = mutableListOf<Audien... | 0 | Kotlin | 0 | 0 | c967e89058772ee2322cb05fb0d892bd39047f47 | 1,377 | samokatas | MIT License |
leetcode/src/main/kotlin/com/artemkaxboy/leetcode/p01/Leet198.kt | artemkaxboy | 513,636,701 | false | {"Kotlin": 547181, "Java": 13948} | package com.artemkaxboy.leetcode.p01
import com.artemkaxboy.leetcode.LeetUtils.toIntArray
import kotlin.system.measureNanoTime
class Leet198 {
class MySolution {
private val knownResults = HashMap<Int, Pair<Int, Int>>()
// nanotime = 82218, 36926, 47676, 2171884, 21085261
fun rob(nums: I... | 0 | Kotlin | 0 | 0 | 516a8a05112e57eb922b9a272f8fd5209b7d0727 | 8,859 | playground | MIT License |
src/Day05.kt | annagergaly | 572,917,403 | false | {"Kotlin": 6388} | fun main() {
fun part1(input: List<String>): String {
val stacks = listOf(
mutableListOf('V', 'J', 'B', 'D'),
mutableListOf('F', 'D', 'R', 'W', 'B', 'V', 'P'),
mutableListOf('Q', 'W', 'C', 'D', 'L', 'F', 'G', 'R'),
mutableListOf('B', 'D', 'N', 'L', 'M', 'P', '... | 0 | Kotlin | 0 | 0 | 89b71c93e341ca29ddac40e83f522e5449865b2d | 2,111 | advent-of-code22 | Apache License 2.0 |
kotlin/numbertheory/MultiplicativeFunction.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package numbertheory
import java.util.Arrays
// f(a*b) = f(a)*f(b) | gcd(a,b)=1
interface MultiplicativeFunction {
fun apply(prime: Long, exponent: Int, power: Long): Long
operator fun get(x: Long): Long {
var x = x
var res: Long = 1
var d: Long = 2
while (d * d <= x) {
... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 2,431 | codelibrary | The Unlicense |
src/main/kotlin/co/csadev/adventOfCode/Searching.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /*
* Copyright (c) 2022 by <NAME>
*/
package co.csadev.adventOfCode
import com.sksamuel.scrimage.color.Color
import java.util.*
/**
* Creates a path from an end point going through parent nodes back to the beginning
*/
fun Map<Point2D, Point2D>.pathThroughList(end: Point2D): List<Point2D> {
var cur = end
... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 2,171 | advent-of-kotlin | Apache License 2.0 |
src/main/kotlin/io/matrix/MaximalSquare.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.matrix
import io.utils.runTests
// https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/531/week-4/3312/
class MaximalSquare {
fun execute(input: Array<IntArray>): Int {
val visited = mutableSetOf<Pair<Int, Int>>()
var result = 0
input.forEachIndexed { index, row ->
r... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 2,274 | coding | MIT License |
src/main/kotlin/g2301_2400/s2321_maximum_score_of_spliced_array/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2301_2400.s2321_maximum_score_of_spliced_array
// #Hard #Array #Dynamic_Programming #2023_06_30_Time_497_ms_(50.00%)_Space_56.9_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
fun maximumsSplicedArray(nums1: IntArray, nums2: IntArray): Int {
var nums1 = nums1
var nums2 = nums2
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,938 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/book/recipe/data/SummaryExtension.kt | becgabi | 363,655,691 | false | null | package com.book.recipe.data
fun Recipe.toSummary(): RecipeSummary {
val sum = recipeIngredients.reduce { acc, recipeIngredient -> acc + recipeIngredient }
return RecipeSummary(
recipe = this,
sumNutritionFact = sum.ingredient.nutritionFact,
sumWeightInGram = sum.weightInGram
)
}
o... | 0 | Kotlin | 0 | 0 | 67887851a82a96206e9bcea9102b0a11c6382b31 | 1,466 | recipe-book | MIT License |
src/Day02/Day02.kt | suttonle24 | 573,260,518 | false | {"Kotlin": 26321} | package Day02
import readInput
//--- Day 2: Rock Paper Scissors ---
//The Elves begin to set up camp on the beach. To decide whose tent gets to be closest to the snack storage, a giant Rock Paper Scissors tournament is already in progress.
//
//Rock Paper Scissors is a game between two players. Each game contains ma... | 0 | Kotlin | 0 | 0 | 039903c7019413d13368a224fd402625023d6f54 | 6,490 | AoC-2022-Kotlin | Apache License 2.0 |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day05.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwenty
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
import kotlin.math.pow
class Day05 : Day<Int> {
private val registeredSeats: List<Seat> =
readDayInput()
.lineSequence()
.map { it.parseSeat() }
.toList()... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 2,547 | adventofcode | Apache License 2.0 |
src/main/kotlin/days/Day05.kt | poqueque | 430,806,840 | false | {"Kotlin": 101024} | package days
import util.Coor
class Day05 : Day(5) {
override fun partOne(): Any {
val data = mutableMapOf<Coor, Int>()
inputList.forEach {
val (start, stop) = it.split(" -> ").map { it.split(",") }
val s = Coor(start[0].toInt(), start[1].toInt())
val e = Coor(... | 0 | Kotlin | 0 | 0 | 4fa363be46ca5cfcfb271a37564af15233f2a141 | 2,686 | adventofcode2021 | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year19/Day18.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year19
import com.grappenmaker.aoc.*
fun PuzzleSet.day18() = puzzle(day = 18) {
fun Char.isKey() = this in 'a'..'z'
val grid = inputLines.asCharGrid()
val totalKeys = grid.elements.count(Char::isKey)
fun Grid<Char>.adj(point: Point, keys: Set<Char>) = point.adjacentSides... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,966 | advent-of-code | The Unlicense |
src/main/kotlin/days/Day19.kt | TheMrMilchmann | 433,608,462 | false | {"Kotlin": 94737} | /*
* Copyright (c) 2021 <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 | dfc91afab12d6dad01de552a77fc22a83237c21d | 4,436 | AdventOfCode2021 | MIT License |
src/main/kotlin/exercise/medium/id57/Solution57.kt | kotler-dev | 706,379,223 | false | {"Kotlin": 63887} | package exercise.medium.id57
import kotlin.math.max
import kotlin.math.min
class Solution57 {
fun insert(intervals: Array<IntArray>, newInterval: IntArray): Array<IntArray> {
if (intervals.isEmpty()) return arrayOf(newInterval)
if (newInterval.isEmpty()) return intervals
println("[${newI... | 0 | Kotlin | 0 | 0 | 0659e72dbf28ce0ec30aa550b6a83c1927161b14 | 5,144 | kotlin-leetcode | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/longest_common_prefix/LongestCommonPrefix.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.longest_common_prefix
import datsok.shouldEqual
import org.junit.Test
/**
* https://leetcode.com/problems/longest-common-prefix
*/
class LongestCommonPrefixTests {
@Test fun `find the longest common prefix string amongst an array of strings`() {
longestCommonPrefix(arrayOf(... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,007 | katas | The Unlicense |
Kotlin/src/WordSearch.kt | TonnyL | 106,459,115 | false | null | /**
* Given a 2D board and a word, find if the word exists in the grid.
*
* The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring.
* The same letter cell may not be used more than once.
*
* For example,
* Given board =
*
... | 1 | Swift | 22 | 189 | 39f85cdedaaf5b85f7ce842ecef975301fc974cf | 1,698 | Windary | MIT License |
src/week1/GroupAnagrams.kt | anesabml | 268,056,512 | false | null | package week1
import java.util.*
import kotlin.system.measureNanoTime
class GroupAnagrams {
/** Group By
* Time complexity : O(log n)
* Space complexity : O(1)
*/
fun groupAnagrams(strs: Array<String>): List<List<String>> {
return strs.groupBy { it.toCharArray().sorted() }.map { it.va... | 0 | Kotlin | 0 | 1 | a7734672f5fcbdb3321e2993e64227fb49ec73e8 | 2,145 | leetCode | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year17/Day24.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year17
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.splitInts
fun PuzzleSet.day24() = puzzle(day = 24) {
data class Component(val portA: Int, val portB: Int)
val allComponents = inputLines.map { l -> l.splitInts().let { (a, b) -> Component(a, b) } }
data ... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,504 | advent-of-code | The Unlicense |
src/main/kotlin/Day18.kt | cbrentharris | 712,962,396 | false | {"Kotlin": 171464} | import java.util.*
import kotlin.String
import kotlin.collections.List
object Day18 {
data class Segment(val coordinates: Set<Day17.Coordinate>) {
val minX = coordinates.minOf { it.x }
val maxX = coordinates.maxOf { it.x }
val minY = coordinates.minOf { it.y }
val maxY = coordinates... | 0 | Kotlin | 0 | 1 | f689f8bbbf1a63fecf66e5e03b382becac5d0025 | 10,769 | kotlin-kringle | Apache License 2.0 |
instantsearch-core/src/commonMain/kotlin/com/algolia/instantsearch/core/tree/Extensions.kt | algolia | 55,971,521 | false | {"Kotlin": 689459} | package com.algolia.instantsearch.core.tree
public fun <T> Tree<T>.findNode(
separator: String,
content: T,
isMatchingNode: (T, Node<T>, String) -> Boolean
): Node<T>? = children.findNode(separator, content, isMatchingNode)
public fun <T> Tree<T>.findNode(
content: T,
isMatchingNode: (T, Node<T>) ... | 15 | Kotlin | 32 | 155 | cb068acebbe2cd6607a6bbeab18ddafa582dd10b | 2,998 | instantsearch-android | Apache License 2.0 |
src/main/kotlin/be/brammeerten/graphs/Dijkstra.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.graphs
object Dijkstra {
fun <K, V> findShortestPath(graph: Graph<K, V>, start: K, end: K,
cache: HashMap<Pair<K, K>, List<Node<K, V>>?>? = null): List<Node<K, V>>? {
// Check cache
val cached = cache?.get(start to end)
if (cached != nu... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 1,917 | Advent-of-Code | MIT License |
kotlin/12.kt | NeonMika | 433,743,141 | false | {"Kotlin": 68645} | class Day12 : Day<Graph<String>>("12") {
val Graph<String>.start get() = nodes["start"]!!
val Graph<String>.end get() = nodes["end"]!!
val Node<String>.isSmall get() = data[0].isLowerCase()
val Node<String>.isBig get() = !isSmall
fun Graph<String>.dfs(
cur: Node<String>,
path: List<N... | 0 | Kotlin | 0 | 0 | c625d684147395fc2b347f5bc82476668da98b31 | 1,258 | advent-of-code-2021 | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.