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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
kotlin/src/com/daily/algothrim/leetcode/AddToArrayForm.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
import kotlin.math.pow
/**
* 989. 数组形式的整数加法
*
* 对于非负整数 X 而言,X 的数组形式是每位数字按从左到右的顺序形成的数组。例如,如果 X = 1231,那么其数组形式为 [1,2,3,1]。
* 给定非负整数 X 的数组形式 A,返回整数 X+K 的数组形式。
* */
class AddToArrayForm {
companion object {
@JvmStatic
fun main(args: Array<String>) {
// ... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,098 | daily_algorithm | Apache License 2.0 |
src/array/LeetCode347.kt | Alex-Linrk | 180,918,573 | false | null | package array
/**
* 前K个高频元素
* 给定一个非空的整数数组,返回其中出现频率前 k 高的元素。
*
*示例 1:
*
*输入: nums = [1,1,1,2,2,3], k = 2
*输出: [1,2]
*示例 2:
*
*输入: nums = [1], k = 1
*输出: [1]
*说明:
*
*你可以假设给定的 k 总是合理的,且 1 ≤ k ≤ 数组中不相同的元素的个数。
*你的算法的时间复杂度必须优于 O(n log n) , n 是数组的大小。
*/
class LeetCode347 {
fun topKFrequent(nums: IntArray,... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 2,235 | LeetCode | Apache License 2.0 |
src/main/kotlin/days/Day11.kt | jgrgt | 433,952,606 | false | {"Kotlin": 113705} | package days
class Day11 : Day(11) {
override fun runPartOne(lines: List<String>): Any {
val levels = parse(lines)
val octopusses = Octopusses(levels)
return (0..99).sumOf {
octopusses.flash()
}
}
override fun runPartTwo(lines: List<String>): Any {
val l... | 0 | Kotlin | 0 | 0 | 6231e2092314ece3f993d5acf862965ba67db44f | 3,244 | aoc2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/day5.kt | nerok | 436,232,451 | false | {"Kotlin": 32118} | import java.io.File
import kotlin.math.abs
fun main(args: Array<String>) {
val lines = File("day5input.txt").reader()
var coordinates = mutableListOf<List<Pair<Int, Int>>>()
var size = 0
lines.forEachLine { fileLine ->
fileLine
.split("->")
.map { coordinates ->
... | 0 | Kotlin | 0 | 0 | 4dee925c0f003fdeca6c6f17c9875dbc42106e1b | 3,471 | Advent-of-code-2021 | MIT License |
src/Day08.kt | 6234456 | 572,616,769 | false | {"Kotlin": 39979} | import kotlin.math.abs
import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
val src = input.map { it.toCharArray().map { it.digitToInt() }.toIntArray() }.toTypedArray()
val n = input.size
// up down left right
val dps: Array<Array<BooleanArray>> = Array(4){Arra... | 0 | Kotlin | 0 | 0 | b6d683e0900ab2136537089e2392b96905652c4e | 5,518 | advent-of-code-kotlin-2022 | Apache License 2.0 |
app/src/main/kotlin/ca/warp7/rt/ext/predictor/Alliance.kt | Team865 | 159,395,287 | false | null | package ca.warp7.rt.ext.predictor
abstract class Alliance(open val teams: List<Team>)
data class TeamStats(var hatch: Int, var cargo: Int)
class Alliance2019(override val teams: List<Team2019>) : Alliance(teams) {
private fun chooseStrat(panelL1: Double, panelL2: Double, panelL3: Double,
... | 0 | Kotlin | 0 | 2 | 4c97affce1eb48e14511a4b0824bb45fbb4cbcb9 | 5,652 | Restructured-Tables | MIT License |
src/main/kotlin/days/Day2.kt | andilau | 544,512,578 | false | {"Kotlin": 29165} | package days
import days.Day2.Point.Companion.DOWN
import days.Day2.Point.Companion.LEFT
import days.Day2.Point.Companion.RIGHT
import days.Day2.Point.Companion.UP
import java.lang.IllegalArgumentException
@AdventOfCodePuzzle(
name = "Bathroom Security",
url = "https://adventofcode.com/2016/day/2",
date =... | 3 | Kotlin | 0 | 0 | b2a836bd3f1c5eaec32b89a6ab5fcccc91b665dc | 2,708 | advent-of-code-2016 | Creative Commons Zero v1.0 Universal |
src/Day05.kt | Aldas25 | 572,846,570 | false | {"Kotlin": 106964} | fun main() {
fun part1(input: List<String>, stacks: Array<ArrayDeque<Char>>): String {
var ans = ""
for (str in input) {
val parts = str.split(" ")
val quantity = parts[1].toInt()
val from = parts[3].toInt()
val to = parts[5].toInt()
rep... | 0 | Kotlin | 0 | 0 | 80785e323369b204c1057f49f5162b8017adb55a | 2,328 | Advent-of-Code-2022 | Apache License 2.0 |
src/nativeMain/kotlin/Day2.kt | rubengees | 576,436,006 | false | {"Kotlin": 67428} | class Day2 : Day {
private val winTable = mapOf(1 to 3, 2 to 1, 3 to 2)
private fun calculateScorePart1(left: Char, right: Char): Int {
val leftCode = left.code - 'A'.code + 1
val rightCode = right.code - 'X'.code + 1
return when {
winTable[rightCode] == leftCode -> 6 + rig... | 0 | Kotlin | 0 | 0 | 21f03a1c70d4273739d001dd5434f68e2cc2e6e6 | 1,452 | advent-of-code-2022 | MIT License |
src/main/java/com/github/mmauro94/irws/Utils.kt | MMauro94 | 202,988,256 | false | {"HTML": 765422, "Kotlin": 20314} | package com.github.mmauro94.irws
/**
* Computes the Jaccard distance between two generic elements [elem1] and [elem2].
* @see jaccardIndex
*/
inline fun <T, X> jaccardDistance(elem1: T, elem2: T, crossinline setSelector: (T) -> Set<X>): Double {
return 1 - jaccardIndex(elem1, elem2, setSelector)
}
/**
* Comp... | 0 | HTML | 0 | 0 | 7582bd3e3fbca9dc8ed254c37cd36c8fb8f22105 | 2,118 | irws-project | The Unlicense |
src/Day06.kt | azat-ismagilov | 573,217,326 | false | {"Kotlin": 75114} | fun main() {
fun String.findFirstSubstringWithDifferentChars(substringLength: Int): Int {
for (index in substringLength..length)
if ((index - substringLength until index)
.map { this[it] }
.toSet()
.size == substringLength
)... | 0 | Kotlin | 0 | 0 | abdd1b8d93b8afb3372cfed23547ec5a8b8298aa | 1,331 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day01.kt | krisbrud | 573,455,086 | false | {"Kotlin": 8417} | fun main() {
fun splitOnBlank(list: List<String>): List<List<Int>> {
return list.fold(mutableListOf(mutableListOf<Int>())) { acc, item ->
if (item.isBlank()) {
acc.add(mutableListOf())
} else {
acc.last().add(item.toInt())
}
acc... | 0 | Kotlin | 0 | 0 | 02caf3a30a292d7b8c9e2b7788df74650e54573c | 969 | advent-of-code-2022 | Apache License 2.0 |
src/chapter1/problem2/solution1.kts | neelkamath | 395,940,983 | false | null | /*
Question:
Check Permutation: Given two strings, write a method to decide if one is a permutation of the other.
Solution:
Using a map.
*/
listOf("hello" to "hello", "hello" to "hleol", "hello" to "helo", "" to "bye", "b" to "by", "bye" to "eyb")
.forEach { (string1, string2) -> println("$string1, $string2: ${a... | 0 | Kotlin | 0 | 0 | 4421a061e5bf032368b3f7a4cee924e65b43f690 | 834 | ctci-practice | MIT License |
src/main/kotlin/com/ginsberg/advent2023/Day08.kt | tginsberg | 723,688,654 | false | {"Kotlin": 112398} | /*
* Copyright (c) 2023 by <NAME>
*/
/**
* Advent of Code 2023, Day 8 - Haunted Wasteland
* Problem Description: http://adventofcode.com/2023/day/8
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2023/day8/
*/
package com.ginsberg.advent2023
class Day08(input: List<String>) {
private ... | 0 | Kotlin | 0 | 12 | 0d5732508025a7e340366594c879b99fe6e7cbf0 | 1,365 | advent-2023-kotlin | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions3.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import com.qiaoyuang.algorithm.round0.exchange
fun test3() {
val numbers0 = intArrayOf(2, 3, 1, 0, 2, 5, 3)
val numbers1 = intArrayOf(2, 3, 5, 4, 3, 2, 6, 7)
println("The repeat number is: ${findNumber1(numbers0)}")
println("The repeat number is: ${findNumber1(nu... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 2,057 | Algorithm | Apache License 2.0 |
src/Day04.kt | wlghdu97 | 573,333,153 | false | {"Kotlin": 50633} | fun main() {
fun String.toRange(): IntRange {
val (a, b) = this.split("-")
val range = a.toInt()..b.toInt()
if (range.step < 0) {
throw IllegalArgumentException()
}
return range
}
fun IntRange.includes(other: IntRange): Boolean {
return when {
... | 0 | Kotlin | 0 | 0 | 2b95aaaa9075986fa5023d1bf0331db23cf2822b | 1,810 | aoc-2022 | Apache License 2.0 |
src/Day07.kt | zirman | 572,627,598 | false | {"Kotlin": 89030} | import java.lang.Exception
import java.util.Stack
//typealias Foo = Map<String, Foo>
sealed interface Filesystem {
data class Directory(val nodes: MutableMap<String, Filesystem>) : Filesystem
data class File(val size: Long) : Filesystem
}
sealed interface Size {
data class Directory(override val size: Lon... | 0 | Kotlin | 0 | 1 | 2ec1c664f6d6c6e3da2641ff5769faa368fafa0f | 6,629 | aoc2022 | Apache License 2.0 |
common/assertion-functions/src/main/kotlin/com/testerum/common_assertion_functions/utils/SimilarStringsFinder.kt | jesus2099 | 405,913,304 | true | {"Kotlin": 2228036, "TypeScript": 1665096, "SCSS": 1583387, "HTML": 453456, "Java": 53935, "Shell": 8666, "Gherkin": 5241, "JavaScript": 4659, "Batchfile": 3382, "Groovy": 597} | package com.testerum.common_assertion_functions.utils
import org.apache.commons.lang3.StringUtils
import java.util.*
private val MAX_DIFFERENCE_PERCENTAGE = 50
fun didYouMean(desiredString: String,
existingStrings: Iterable<String>): String {
val similarStrings: List<String> = existingStrings.find... | 0 | null | 0 | 0 | 1bacdd86da1a240ad9f2932e21c69f628a1fc66c | 2,207 | testerum_testerum | Apache License 2.0 |
leetcode-75-kotlin/src/main/kotlin/DeleteTheMiddleNodeOfALinkedList.kt | Codextor | 751,507,040 | false | {"Kotlin": 49566} | import commonclasses.ListNode
/**
* You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list.
*
* The middle node of a linked list of size n is the ⌊n / 2⌋th node from the start using 0-based indexing,
* where ⌊x⌋ denotes the largest integer less than or equa... | 0 | Kotlin | 0 | 0 | 0511a831aeee96e1bed3b18550be87a9110c36cb | 1,997 | leetcode-75 | Apache License 2.0 |
app/src/main/java/com/isaacsufyan/numerologycompose/numerology/NumerologyFinder.kt | IsaacSufyan | 515,466,716 | false | null | package com.isaacsufyan.numerologycompose.numerology
import com.isaacsufyan.numerologycompose.numerology.big.BigDecimalMath
import java.math.BigInteger
import java.math.MathContext
object NumerologyFinder {
fun find(inputNumber: Int, selectedOptionOfPieValue: Int): Int {
var n = inputNumber
n++
... | 0 | Kotlin | 0 | 2 | 43f74c04eec52fdf096cf9219d638f26555cc383 | 3,941 | NumerologyTestApp | Apache License 2.0 |
src/week1/MaxSubArray.kt | anesabml | 268,056,512 | false | null | package week1
import kotlin.math.max
import kotlin.system.measureNanoTime
class MaxSubArray {
/** Brute force (really bad)
* Time complexity : O(n2)
* Space complexity : O(1)
*/
fun maxSubArray(nums: IntArray): Int {
var max = Int.MIN_VALUE
for (start in nums.indices) {
... | 0 | Kotlin | 0 | 1 | a7734672f5fcbdb3321e2993e64227fb49ec73e8 | 1,817 | leetCode | Apache License 2.0 |
advent/src/test/kotlin/org/elwaxoro/advent/y2022/Dec16.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2022
import org.elwaxoro.advent.Node
import org.elwaxoro.advent.PuzzleDayTester
/**
* Day 16: Proboscidea Volcanium
*/
class Dec16 : PuzzleDayTester(16, 2022) {
override fun part1(): Any = loader().let { valves ->
(1..30).fold(listOf(Path(valves["AA"]!!, 30))) { paths, _ ->... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 4,936 | advent-of-code | MIT License |
src/main/kotlin/com/github/wakingrufus/aoc/Day4.kt | wakingrufus | 159,674,364 | false | null | package com.github.wakingrufus.aoc
import mu.KLogging
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
sealed class Event(val time: LocalDateTime)
data class ShiftStart(val guardId: String, val timestamp: LocalDateTime) : Event(timestamp)
data class SleepStart(val timestamp: LocalDateTime) :... | 0 | Kotlin | 0 | 0 | bdf846cb0e4d53bd8beda6fdb3e07bfce59d21ea | 5,491 | advent-of-code-2018 | MIT License |
src/main/kotlin/Day01.kt | bent-lorentzen | 727,619,283 | false | {"Kotlin": 68153} | import java.time.LocalDateTime
import java.time.ZoneOffset
fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
it.first { c -> c in ('1'..'9') }.minus('0') * 10 +
it.last { c -> c in ('1'..'9') }.minus('0')
}
}
fun part2(input: List<Strin... | 0 | Kotlin | 0 | 0 | 41f376bd71a8449e05bbd5b9dd03b3019bde040b | 1,450 | aoc-2023-in-kotlin | Apache License 2.0 |
src/main/kotlin/controller/Solver.kt | mihassan | 600,617,064 | false | null | package controller
import model.*
import util.Bag
import util.frequency
enum class Strategy(val display: String) {
AlphabeticOrder("Alphabetic order"),
ShortestFirst("Shortest first"),
LongestFirst("Longest first"),
RandomOrder("Random order")
}
class Solver(
private val dictionary: Dictionary,
private v... | 0 | Kotlin | 0 | 2 | f99324e092a9eb7d9644417ac3423763059513ee | 3,263 | qless-solver | Apache License 2.0 |
src/main/kotlin/days/Day3.kt | nicopico-dev | 726,255,944 | false | {"Kotlin": 37616} | package days
import kotlin.math.max
import kotlin.math.min
class Day3(
inputFileNameOverride: String? = null,
) : Day(3, inputFileNameOverride) {
override fun partOne(): Any {
return getPartNumbers()
.sum()
}
internal fun getPartNumbers(): List<Int> {
val schematic = Schem... | 0 | Kotlin | 0 | 0 | 1a13c8bd3b837c1ce5b13f90f326f0277249d23e | 4,874 | aoc-2023 | Creative Commons Zero v1.0 Universal |
src/Day01.kt | sabercon | 648,989,596 | false | null | fun main() {
fun findTwoWithSum(nums: Set<Int>, sum: Int): Pair<Int, Int>? {
return nums.find { (sum - it) in nums }
?.let { it to (sum - it) }
}
fun findThreeWithSum(nums: Set<Int>, sum: Int): Triple<Int, Int, Int>? {
return nums.firstNotNullOfOrNull {
findTwoWithSu... | 0 | Kotlin | 0 | 0 | 81b51f3779940dde46f3811b4d8a32a5bb4534c8 | 637 | advent-of-code-2020 | MIT License |
leetcode2/src/leetcode/letter-combinations-of-a-phone-number.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* 17. 电话号码的字母组合
* https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
* Created by test
* Date 2019/12/14 12:21
* Description
* 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。
给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。
示例:
输入:"23"
输出:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,858 | leetcode | MIT License |
src/day19/Day19.kt | EndzeitBegins | 573,569,126 | false | {"Kotlin": 111428} | package day19
import readInput
import readTestInput
private data class Blueprint(
val id: Int,
val oreRobotOreCost: Int,
val clayRobotOreCost: Int,
val obsidianRobotOreCost: Int,
val obsidianRobotClayCost: Int,
val geodeRobotOreCost: Int,
val geodeRobotObsidianCost: Int,
) {
val maxOre... | 0 | Kotlin | 0 | 0 | ebebdf13cfe58ae3e01c52686f2a715ace069dab | 7,786 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/me/bytebeats/algo/kt/Solution7.kt | bytebeats | 251,234,289 | false | null | package me.bytebeats.algo.kt
import me.bytebeats.algs.ds.ListNode
import me.bytebeats.algs.ds.TreeNode
class Solution7 {
fun verticalTraversal(root: TreeNode?): List<List<Int>> {//987
val ans = mutableMapOf<Int, MutableMap<Int, MutableList<Int>>>()
if (root != null) {
val queue = muta... | 0 | Kotlin | 0 | 1 | 7cf372d9acb3274003bb782c51d608e5db6fa743 | 36,656 | Algorithms | MIT License |
AtvRevisao/Atv3.kt | Matheus-Inacioal | 678,814,162 | false | null | fun main() {
val numbers = mutableListOf<Int>()
println("Digite uma série de números separados por espaços (ou '0' para sair):")
while (true) {
val input = readLine()
if (input == "0") {
break
}
val number = input?.toIntOrNull()
if (number != null) {
... | 0 | Kotlin | 0 | 1 | 9ce1df31953ee073400ea9fa872e29dca09ccccb | 1,449 | AtividadesKotlinQualificaResolucao | MIT License |
solution/kotlin/day20/src/main/kotlin/domain/yahtzee/constrain/input/YahtzeeCalculator.kt | advent-of-craft | 721,598,788 | false | {"Java": 240720, "C#": 208054, "Kotlin": 162843, "TypeScript": 162359, "Shell": 16244, "JavaScript": 10227} | package domain.yahtzee.constrain.input
object YahtzeeCalculator {
fun number(roll: Roll, number: Int): Int = calculate(
{ r -> r.dice.filter { die -> die == number }.sum() }, roll
)
fun threeOfAKind(roll: Roll): Int = calculateNOfAKind(roll, 3)
fun fourOfAKind(roll: Roll): Int = calculateNOfAK... | 0 | Java | 60 | 71 | 3cc9e8b2c59963db97919b808a8285fbe3157c34 | 2,006 | advent-of-craft | MIT License |
src/iii_conventions/MyDate.kt | ajconnell | 141,942,347 | false | {"Kotlin": 73953, "Java": 4952} | package iii_conventions
import iii_conventions.multiAssignemnt.isLeapYear
data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate> {
override fun compareTo(other: MyDate): Int {
if (this.year != other.year) return this.year.compareTo(other.year)
if (this.month != ... | 0 | Kotlin | 0 | 0 | ca2dd4493ee31ca2d14e8134d670c13a65eafece | 2,063 | completedkotlinkoans | MIT License |
2021/day-2/day2kotlin/Main.kts | Petrosz007 | 160,567,363 | false | {"Rust": 92773, "C#": 77404, "Haskell": 32217, "HTML": 17700, "C++": 3462, "F#": 1963, "Kotlin": 1039, "PHP": 1020, "Dockerfile": 949, "Makefile": 200, "Just": 34} | import java.io.File
data class Instruction(val instruction: String, val value: Long)
data class Position(val horizontal: Long, val depth: Long, val aim: Long) {
val part1 = this.horizontal * this.aim
val part2 = this.horizontal * this.depth
}
fun execute(instruction: Instruction, pos: Position): Position =
... | 0 | Rust | 0 | 0 | 0404412a777d0d2d60802b615f4ebdb4cdb5c4ad | 1,039 | advent-of-code | MIT License |
src/main/kotlin/days/Day17.kt | butnotstupid | 571,247,661 | false | {"Kotlin": 90768} | package days
import java.lang.Integer.max
import kotlin.reflect.full.primaryConstructor
class Day17 : Day(17) {
override fun partOne(): Any {
return topRowDiffs(2022).sum()
}
override fun partTwo(): Any {
val totalSize = 1_000_000_000_000
val headSize = 10000
val tailSize ... | 0 | Kotlin | 0 | 0 | 4760289e11d322b341141c1cde34cfbc7d0ed59b | 5,213 | aoc-2022 | Creative Commons Zero v1.0 Universal |
src/Day02.kt | annagergaly | 572,917,403 | false | {"Kotlin": 6388} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
when (it) {
"A X" -> 4
"A Y" -> 8
"A Z" -> 3
"B X" -> 1
"B Y" -> 5
"B Z" -> 9
"C X" -> 7
"C Y" -... | 0 | Kotlin | 0 | 0 | 89b71c93e341ca29ddac40e83f522e5449865b2d | 908 | advent-of-code22 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions38.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import kotlin.math.abs
fun test38() {
printResult1("abc")
printResult1("abcd")
printlnResult2(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0))
printlnResult2(intArrayOf(1, 2, 3, 4, 5, 6, 7, 8))
printlnResult2(intArrayOf(0, 9, 9, 9, 9, 9, 9, 9))
printlnResult3(7)
... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 3,349 | Algorithm | Apache License 2.0 |
src/main/kotlin/me/peckb/aoc/_2016/calendar/day24/Day24.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2016.calendar.day24
import me.peckb.aoc._2016.calendar.day24.Day24.DuctType.OPEN
import me.peckb.aoc._2016.calendar.day24.Day24.DuctType.WALL
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import me.peckb.aoc.generators.PermutationGenerator
import ... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 3,681 | advent-of-code | MIT License |
src/main/kotlin/day13/day13.kt | corneil | 572,437,852 | false | {"Kotlin": 93311, "Shell": 595} | package day13
import utils.groupLines
import utils.readFile
import utils.readLines
import utils.separator
import java.util.*
fun main() {
val test = readLines(
"""[1,1,3,1,1]
[1,1,5,1,1]
[[1],[2,3,4]]
[[1],4]
[9]
[[8,7,6]]
[[4,4],4,4]
[[4,4],... | 0 | Kotlin | 0 | 0 | dd79aed1ecc65654cdaa9bc419d44043aee244b2 | 4,854 | aoc-2022-in-kotlin | Apache License 2.0 |
leetcode/src/main/kotlin/com/artemkaxboy/leetcode/p00/Leet46.kt | artemkaxboy | 513,636,701 | false | {"Kotlin": 547181, "Java": 13948} | package com.artemkaxboy.leetcode.p00
import com.artemkaxboy.leetcode.LeetUtils
/**
* Runtime: 217ms Beats: 50.88%
* Memory: 37.5MB Beats: 54.42%
*/
class Leet46 {
class Solution {
fun permute(nums: IntArray): List<List<Int>> {
var i = 1
val size = nums.s... | 0 | Kotlin | 0 | 0 | 516a8a05112e57eb922b9a272f8fd5209b7d0727 | 2,162 | playground | MIT License |
src/day07/Day07.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day07
import readInput
import java.util.*
abstract class FileSystemNode(val name: String, var size: Int, val parent: FileSystemNode?): Iterable<FileSystemNode> {
abstract fun addChild(child: FileSystemNode)
abstract fun hasChildren(): Boolean
abstract fun computeSize(): Int
}
class FileSystemFil... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 4,894 | AdventOfCode2022 | Apache License 2.0 |
src/main/java/leetcode/lettercombinations/Solution.kt | thuytrinh | 106,045,038 | false | null | package leetcode.lettercombinations
import java.util.*
/**
* https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/
*/
class Solution {
private val kb = hashMapOf(
'1' to "",
'2' to "abc",
'3' to "def",
'4' to "ghi",
'5' to "jkl",
'6' to "mno",
'... | 0 | Kotlin | 0 | 1 | 23da0286a88f855dcab1999bcd7174343ccc1164 | 1,419 | algorithms | MIT License |
leetcode/src/offer/middle/Offer26.kt | zhangweizhe | 387,808,774 | false | null | package offer.middle
import linkedlist.TreeNode
fun main() {
// 剑指 Offer 26. 树的子结构
// https://leetcode.cn/problems/shu-de-zi-jie-gou-lcof/
}
fun isSubStructure(A: TreeNode?, B: TreeNode?): Boolean {
if (A == null || B == null) {
return false
}
// isSub(A, B) 判断 B 是不是以 A 为根节点的树的子结构
//... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,317 | kotlin-study | MIT License |
src/Day01.kt | Flexicon | 576,933,699 | false | {"Kotlin": 5474} | fun main() {
fun sumTop(input: List<String>, n: Int): Int {
return input.blocks { backpack -> backpack.sumOf { it.toInt() } }
.sorted()
.takeLast(n)
.sum()
}
fun part1(input: List<String>): Int {
return sumTop(input, 1)
}
fun part2(input: List<St... | 0 | Kotlin | 0 | 0 | 7109cf333c31999296e1990ce297aa2db3a622f2 | 823 | aoc-2022-in-kotlin | Apache License 2.0 |
leetcode2/src/leetcode/kth-largest-element-in-an-array.kt | hewking | 68,515,222 | false | null | package leetcode
import java.util.*
import kotlin.Comparator
/**
* 215. 数组中的第K个最大元素
* https://leetcode-cn.com/problems/kth-largest-element-in-an-array/
* Created by test
* Date 2019/10/6 0:11
* Description
* 在未排序的数组中找到第 k 个最大的元素。请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。
示例 1:
输入: [3,2,1,5,6,4] 和 k = 2
输出: 5
示... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,312 | leetcode | MIT License |
src/Day04_part1.kt | abeltay | 572,984,420 | false | {"Kotlin": 91982, "Shell": 191} | fun main() {
fun part1(input: List<String>): Int {
fun hasOverlap(elf1: Pair<Int, Int>, elf2: Pair<Int, Int>): Boolean {
if (elf1.first <= elf2.first && elf1.second >= elf2.second) {
return true
} else if (elf2.first <= elf1.first && elf2.second >= elf1.second) {
... | 0 | Kotlin | 0 | 0 | a51bda36eaef85a8faa305a0441efaa745f6f399 | 1,103 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | vonElfvin | 572,857,181 | false | {"Kotlin": 11658} | fun main() {
fun part1(input: List<String>): Int = input.sumOf {
val (opponent, me) = it.split(' ')
when (me) {
"X" -> 1 + when (opponent) {
"A" -> 3
"B" -> 0
else -> 6
}
"Y" -> 2 + when (opponent) {
... | 0 | Kotlin | 0 | 0 | 6210f23f871f646fcd370ec77deba17da4196efb | 1,180 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day10.kt | julia-kim | 569,976,303 | false | null | package days
import readInput
fun main() {
fun part1(input: List<String>): Int {
// cycleNumber to register
val signals: MutableMap<Int, Int> = mutableMapOf()
var cycleNumber = 0
var x = 1
// Find the signal strength during the 20th, 60th, 100th, 140th, 180th, and 220th cyc... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 2,156 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | dominiquejb | 572,656,769 | false | {"Kotlin": 10603} | fun main() {
fun scorePart1(round: String): Int {
return when (round) {
"A X" -> 4 // Draw, Rock = 3 + 1 = 4
"A Y" -> 8 // Win, Paper = 6 + 2 = 8
"A Z" -> 3 // Loss, Scissors = 0 + 3 = 3
"B X" -> 1 // Loss, Rock = 0 + 1 = 1
"B Y" -> 5 /... | 0 | Kotlin | 0 | 0 | f4f75f9fc0b5c6c81759357e9dcccb8759486f3a | 1,640 | advent-of-code-2022 | Apache License 2.0 |
src/Day21.kt | schoi80 | 726,076,340 | false | {"Kotlin": 83778} | typealias Garden = MutableInput<Char>
fun Garden.canStep(curr: RowCol): List<RowCol> {
return adjacent(curr).filter { this.get(it).let { it == '.' || it == 'S' } }
}
fun Garden.step(curr: Set<RowCol>): MutableSet<RowCol> {
return curr.fold(mutableSetOf()) { acc, it ->
acc.addAll(canStep((it)))
... | 0 | Kotlin | 0 | 0 | ee9fb20d0ed2471496185b6f5f2ee665803b7393 | 3,522 | aoc-2023 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ThreeSumSmaller.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,461 | kotlab | Apache License 2.0 |
src/main/kotlin/eu/michalchomo/adventofcode/year2023/Day02.kt | MichalChomo | 572,214,942 | false | {"Kotlin": 56758} | package eu.michalchomo.adventofcode.year2023
import eu.michalchomo.adventofcode.Day
import eu.michalchomo.adventofcode.main
object Day02 : Day {
override val number: Int = 2
override fun part1(input: List<String>): String = input.sumOf { line ->
val (game, cubes) = line.split(':')
val gameNu... | 0 | Kotlin | 0 | 0 | a95d478aee72034321fdf37930722c23b246dd6b | 1,279 | advent-of-code | Apache License 2.0 |
src/main/kotlin/Day006.kt | ruffCode | 398,923,968 | false | null | object Day006 {
private val input = PuzzleInput("day006.txt").readText().trim()
@JvmStatic
fun main(args: Array<String>) {
println(partOne(input))
println(partTwoWrong(input))
println(partTwoCorrect(input))
}
internal fun partOne(input: String): Int =
input.getGrou... | 0 | Kotlin | 0 | 0 | 477510cd67dac9653fc61d6b3cb294ac424d2244 | 1,276 | advent-of-code-2020-kt | MIT License |
src/Day04.kt | emmanueljohn1 | 572,809,704 | false | {"Kotlin": 12720} | fun main() {
data class ElfPair(val range1: IntRange, val range2: IntRange){
private val set1 = range1.toSet()
private val set2 = range2.toSet()
fun isFullyContained(): Boolean {
return set1.containsAll(set2) || set2.containsAll(set1)
}
fun isOverlap(): Boolean {... | 0 | Kotlin | 0 | 0 | 154db2b1648c9d12f82aa00722209741b1de1e1b | 1,354 | advent22 | Apache License 2.0 |
src/main/kotlin/KotlinCollectionApiOne.kt | xhh4215 | 201,702,018 | false | null | fun main() {
FilterTest(lists)
FilterPeopleTest(peoplelists)
MapTest(lists)
MapPeopleTest(peoplelists)
FilterAndMapTest(peoplelists)
FindMaxByFilter(peoplelists)
}
/***
* fliter 函数遍历集合并选出应用给定的lambda后返回true的那些元素
* filter排除你不想要的元素,但是他不会改变这些元素
*/
private val lists = listOf(1, 2, 3, 4, 5, 6)
pri... | 0 | Kotlin | 0 | 0 | b06bde9e2e63e60a1353e3f5dc731677cfd3fa51 | 1,509 | KotlinFrist | Apache License 2.0 |
src/Day01.kt | MartinsCode | 572,817,581 | false | {"Kotlin": 77324} | fun main() {
fun part1(input: List<String>): Int {
// we have an undetermined number of elves.
// with an undetermined number of input line
// So in pseudocode:
// Read each line
// if empty: switch to next elf
// else add number to same elf
val calPerElf: Mut... | 0 | Kotlin | 0 | 0 | 1aedb69d80ae13553b913635fbf1df49c5ad58bd | 1,344 | AoC-2022-12-01 | Apache License 2.0 |
kotlin/app/src/main/kotlin/coverick/aoc/day4/CampCleanup.kt | RyTheTurtle | 574,328,652 | false | {"Kotlin": 82616} | package coverick.aoc.day4
import readResourceFile
//https://adventofcode.com/2022/day/4
val INPUT_FILE = "campCleanup-input.txt"
fun isOverlapped(it:List<String>):Boolean {
val leftRanges = it[0].split("-").map { Integer.valueOf(it)}
val rightRanges = it[1].split("-").map { Integer.valueOf(it)}
val left... | 0 | Kotlin | 0 | 0 | 35a8021fdfb700ce926fcf7958bea45ee530e359 | 1,480 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/com/github/michaelbull/advent2023/day17/CityMap.kt | michaelbull | 726,012,340 | false | {"Kotlin": 195941} | package com.github.michaelbull.advent2023.day17
import com.github.michaelbull.advent2023.math.Vector2
import com.github.michaelbull.advent2023.math.Vector2IntMap
import com.github.michaelbull.advent2023.math.toVector2IntMap
import java.util.PriorityQueue
fun Sequence<String>.toCityMap(): CityMap {
return CityMap(... | 0 | Kotlin | 0 | 1 | ea0b10a9c6528d82ddb481b9cf627841f44184dd | 3,170 | advent-2023 | ISC License |
src/main/kotlin/com/leonra/adventofcode/advent2023/day01/Day1.kt | LeonRa | 726,688,446 | false | {"Kotlin": 30456} | package com.leonra.adventofcode.advent2023.day01
import com.leonra.adventofcode.shared.readResource
/** https://adventofcode.com/2023/day/1 */
private object Day1 {
fun partOne(): Int {
fun findCalibrationValue(line: String): Int =
10 * line.first { it.isDigit() }.digitToInt() + line.last { i... | 0 | Kotlin | 0 | 0 | 46bdb5d54abf834b244ba9657d0d4c81a2d92487 | 1,793 | AdventOfCode | Apache License 2.0 |
src/main/kotlin/aoc2022/Day24.kt | w8mr | 572,700,604 | false | {"Kotlin": 140954} | package aoc2022
import aoc.*
import aoc.parser.asArray
import aoc.parser.byEnum
import aoc.parser.followedBy
import aoc.parser.oneOrMore
import java.util.*
class Day24() {
enum class GridType(val text: String) {
WALL("#"),
EMPTY("."),
UP("^"),
RIGHT(">"),
DOWN("v"),
... | 0 | Kotlin | 0 | 0 | e9bd07770ccf8949f718a02db8d09daf5804273d | 4,911 | aoc-kotlin | Apache License 2.0 |
src/commonMain/kotlin/com/github/h0tk3y/betterParse/st/SyntaxTree.kt | h0tk3y | 96,618,996 | false | {"Kotlin": 171609} | package com.github.h0tk3y.betterParse.st
import com.github.h0tk3y.betterParse.combinators.map
import com.github.h0tk3y.betterParse.grammar.Grammar
import com.github.h0tk3y.betterParse.grammar.ParserReference
import com.github.h0tk3y.betterParse.parser.Parser
/** Stores the syntactic structure of a [parser] parsing re... | 37 | Kotlin | 41 | 391 | af4599c04f84463a4b708e7e1385217b41ae7b9e | 2,478 | better-parse | Apache License 2.0 |
src/Day09.kt | greg-burgoon | 573,074,283 | false | {"Kotlin": 120556} | import kotlin.math.sqrt
enum class DIRECTION {
UP, DOWN, LEFT, RIGHT
}
fun main() {
class Position(x: Int, y: Int, tail: Position?){
var x = x
var y = y
val tail = tail
var positionHistory = HashSet<Position>()
fun copyPosition(): Position{
return Position(... | 0 | Kotlin | 0 | 1 | 74f10b93d3bad72fa0fc276b503bfa9f01ac0e35 | 5,260 | aoc-kotlin | Apache License 2.0 |
calendar/day02/Day2.kt | mpetuska | 571,764,215 | false | {"Kotlin": 18073} | package day02
import Day
import Lines
class Day2 : Day() {
override fun part1(input: Lines): Any {
val rules = mapOf(
"A" to mapOf(
"X" to 4,
"Y" to 8,
"Z" to 3,
),
"B" to mapOf(
"X" to 1,
"Y" to 5,
"Z" to 9,
),
"C" to mapOf(
... | 0 | Kotlin | 0 | 0 | be876f0a565f8c14ffa8d30e4516e1f51bc3c0c5 | 1,095 | advent-of-kotlin-2022 | Apache License 2.0 |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day20.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
class Day20 : Day<Long> {
companion object {
private const val PRINT_DEBUG = false
}
private data class Position(val x: Int, val y: Int)
private data class Tile(val id: Long, v... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 11,584 | adventofcode | Apache License 2.0 |
src/main/kotlin/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0863_all_nodes_distance_k_in_binary_tree
// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
// #2023_04_04_Time_147_ms_(95.83%)_Space_35.2_MB_(95.83%)
import com_github_leetcode.TreeNode
/*
* Definition for a binary tree node.
* class TreeNode(var `val`: Int = 0) {
* v... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,655 | LeetCode-in-Kotlin | MIT License |
src/Day14.kt | diego09310 | 576,378,549 | false | {"Kotlin": 28768} | import kotlin.math.max
import kotlin.math.min
fun main() {
data class Point(var x: Int, var y: Int)
lateinit var occupied: HashMap<Int, HashSet<Int>>
// For visualization
lateinit var sandList: HashMap<Int, HashSet<Int>>
var sandTime = false
var minX = 500
var maxX = 500
fun addPoint(... | 0 | Kotlin | 0 | 0 | 644fee9237c01754fc1a04fef949a76b057a03fc | 5,388 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/org/bradfordmiller/fuzzyrowmatcher/algos/Algo.kt | bmiller1009 | 267,343,413 | false | null | package org.bradfordmiller.fuzzyrowmatcher.algos
import org.apache.commons.text.similarity.*
import org.slf4j.LoggerFactory
import java.util.*
/**
* enumerated list of all algorithm types supported by Fuzzy Matcher
*
* The values are
* - JaroDistance
* - LevenshteinDistance
* - HammingDistance
* - JaccardDista... | 5 | Kotlin | 0 | 1 | 65d509f25bc18e36bd0ece53333111ca9630608e | 8,295 | fuzzy-row-matcher | Apache License 2.0 |
src/2023/Day19.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2023`
import java.io.File
import java.lang.RuntimeException
import java.math.BigInteger
import java.util.*
import kotlin.math.max
import kotlin.math.min
fun main() {
Day19().solve()
}
class Day19 {
val input1 = """
px{a<2006:qkq,m>2090:A,rfg}
pv{a>1716:R,A}
lnx{m>1548:A,A}... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 7,661 | advent-of-code | Apache License 2.0 |
src/main/kotlin/io/github/kmakma/adventofcode/y2020/Y2020Day17.kt | kmakma | 225,714,388 | false | null | package io.github.kmakma.adventofcode.y2020
import io.github.kmakma.adventofcode.utils.Day
fun main() {
Y2020Day17().solveAndPrint()
}
class Y2020Day17 : Day(2020, 17, "Conway Cubes") {
private lateinit var startCubes: Map<ConwayCube, Boolean>
private lateinit var inputList: List<List<Char>>
overri... | 0 | Kotlin | 0 | 0 | 7e6241173959b9d838fa00f81fdeb39fdb3ef6fe | 3,434 | adventofcode-kotlin | MIT License |
src/main/kotlin/g2301_2400/s2392_build_a_matrix_with_conditions/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2301_2400.s2392_build_a_matrix_with_conditions
// #Hard #Array #Matrix #Graph #Topological_Sort
// #2023_07_02_Time_706_ms_(100.00%)_Space_65.8_MB_(100.00%)
import java.util.LinkedList
import java.util.Queue
class Solution {
// Using topological sort to solve this problem
fun buildMatrix(k: Int, row... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,821 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/net/wrony/aoc2023/a8/8.kt | kopernic-pl | 727,133,267 | false | {"Kotlin": 52043} | package net.wrony.aoc2023.a8
import kotlin.io.path.Path
import kotlin.io.path.readLines
fun <T> Sequence<T>.repeat() = sequence { while (true) yieldAll(this@repeat) }
fun main() {
Path("src/main/resources/8.txt").readLines().let {
it[0].toCharArray() to it.drop(2).map { m ->
m.split(" = ")
... | 0 | Kotlin | 0 | 0 | 1719de979ac3e8862264ac105eb038a51aa0ddfb | 2,156 | aoc-2023-kotlin | MIT License |
src/main/kotlin/me/peckb/aoc/_2017/calendar/day21/Day21.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2017.calendar.day21
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
class Day21 @Inject constructor(private val generatorFactory: InputGeneratorFactory) {
fun partOne(filename: String) = generatorFactory.forFile(filename).readAs(::day21) { input ... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 2,996 | advent-of-code | MIT License |
src/day06/Day06.kt | martinhrvn | 724,678,473 | false | {"Kotlin": 27307, "Jupyter Notebook": 1336} | package day06
import readInput
import readNumbers
import removeLabel
import removeRegex
data class Race(val time: Long, val distance: Long) {
fun getWays(): Int {
return (0..time).count { i -> (time - i) * i > distance }
}
}
class Day06(private val input: List<String>) {
fun parseInputAsList(): List<Race>... | 0 | Kotlin | 0 | 0 | 59119fba430700e7e2f8379a7f8ecd3d6a975ab8 | 1,052 | advent-of-code-2023-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ValidParenthesesStringPath.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,688 | kotlab | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions14.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import kotlin.math.pow
fun test14() {
fun printlnResult1(n: Int) = println("The rope length is $n, the max product is ${getTheMaxCutProduct1(n)}")
printlnResult1(2)
printlnResult1(3)
printlnResult1(5)
printlnResult1(8)
printlnResult1(12)
fun printlnRe... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,712 | Algorithm | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2020/Day23.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2020
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import java.util.*
/**
* --- Day 23: Crab Cups ---
* https://adventofcode.com/2020/day/23
*/
class Day23 : Solver {
override fun solve(lines: List<String>): Result {
val cupsInput = LinkedList(lines[0].map { it.toString().toIn... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 2,992 | euler | Apache License 2.0 |
shared/src/main/kotlin/org/javacs/kt/util/StringUtils.kt | fwcd | 135,159,301 | false | {"Kotlin": 529657, "Python": 10015, "Java": 1400, "Dockerfile": 741} | package org.javacs.kt.util
/**
* Computes a string distance using a slightly modified
* variant of the SIFT4 algorithm in linear time.
* Note that the function is asymmetric with respect to
* its two input strings and thus is not a metric in the
* mathematical sense.
*
* Based on the JavaScript implementation f... | 177 | Kotlin | 188 | 1,392 | eee8afa9b6b92c4c5ae445823b3719818d595ec1 | 3,495 | kotlin-language-server | MIT License |
src/main/kotlin/ru/amai/study/coursera/kotlin/week3/taxipark/TaxiParkTask.kt | slobanov | 401,728,467 | true | {"Kotlin": 149929} | package ru.amai.study.coursera.kotlin.week3.taxipark
/*
* Task #1. Find all the drivers who performed no trips.
*/
fun TaxiPark.findFakeDrivers(): Set<Driver> =
allDrivers - trips.map { it.driver }.toSet()
private fun List<Trip>.filterByCount(minCount: Int) =
flatMap { it.passengers }
.groupBy { it ... | 1 | Kotlin | 4 | 0 | ff8cafe57166b57900cbddf2a00b670e12ad1410 | 2,223 | kotlin-for-java-dev | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[84]柱状图中最大的矩形.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.util.*
//给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。
//
// 求在该柱状图中,能够勾勒出来的矩形的最大面积。
//
//
//
//
//
// 以上是柱状图的示例,其中每个柱子的宽度为 1,给定的高度为 [2,1,5,6,2,3]。
//
//
//
//
//
// 图中阴影部分为所能勾勒出的最大矩形面积,其面积为 10 个单位。
//
//
//
// 示例:
//
// 输入: [2,1,5,6,2,3]
//输出: 10
// Related Topics 栈 数组
// 👍 1101 👎 0
//leetc... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,560 | MyLeetCode | Apache License 2.0 |
kotlin/src/main/kotlin/AoC_Day12.kt | sviams | 115,921,582 | false | null | object AoC_Day12 {
private fun parseInput(input: List<String>) : Map<Int, List<Int>> = input.associate { value ->
val split = value.split(" <-> ")
split[0].toInt() to split[1].split(",").map { it.trimStart().toInt() }
}
private fun getGroupWithRoot(theMap: Map<Int, List<Int>>, alreadySeen:... | 0 | Kotlin | 0 | 0 | 19a665bb469279b1e7138032a183937993021e36 | 1,100 | aoc17 | MIT License |
Data-Structures/Graph/GraphUsingList.kt | ahampriyanshu | 278,614,006 | false | {"C++": 583777, "Java": 277289, "Python": 254940, "C": 223686, "C#": 127046, "JavaScript": 96050, "Ruby": 37909, "PHP": 37167, "Go": 34857, "TypeScript": 34282, "Swift": 16690, "Jupyter Notebook": 13334, "Kotlin": 9718, "Rust": 9569, "Shell": 7923, "Scala": 6275, "Haskell": 5456, "HTML": 2270, "Clojure": 348, "Makefile... | import kotlin.collections.ArrayList
class Node<T>(val value: T) {
val neighbors = ArrayList<Node<T>>()
fun addNeighbor(node: Node<T>) = neighbors.add(node)
override fun toString(): String = value.toString()
}
class Graph<T> {
private val nodes = HashSet<Node<T>>()
fun addNode(value: T) {
... | 0 | C++ | 760 | 156 | ea880b13c09df58922065ab408d23fa4d264fb7c | 2,435 | algo-ds-101 | MIT License |
src/2021/Day19.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2021`
import java.io.File
import java.lang.Math.abs
import java.util.*
import kotlin.math.absoluteValue
fun main() {
Day19().solve()
}
class Day19 {
companion object {
val allRoll90s: List<Roll90> = allRoll90s()
fun allRoll90s(): List<Roll90> {
val newPosPermutations = ... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 11,558 | advent-of-code | Apache License 2.0 |
src/chapter5/section2/TrieST.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter5.section2
import chapter5.section1.Alphabet
import edu.princeton.cs.algs4.Queue
/**
* 基于单词查找树的符号表
*/
open class TrieST<V : Any>(protected val alphabet: Alphabet) : StringST<V> {
protected inner class Node {
val next = arrayOfNulls<Node>(alphabet.R())
var value: V? = null
... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 4,571 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/main/kotlin/g0901_1000/s0912_sort_an_array/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s0912_sort_an_array
// #Medium #Array #Sorting #Heap_Priority_Queue #Divide_and_Conquer #Merge_Sort #Bucket_Sort
// #Counting_Sort #Radix_Sort #Udemy_Sorting_Algorithms
// #2023_04_16_Time_606_ms_(98.48%)_Space_47.6_MB_(57.11%)
class Solution {
fun sortArray(nums: IntArray): IntArray {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,293 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/d22/D22.kt | MTender | 734,007,442 | false | {"Kotlin": 108628} | package d22
import kotlin.math.max
data class Block(
val id: Int,
val start: Triple<Int, Int, Int>,
val end: Triple<Int, Int, Int>,
val supporting: MutableSet<Int> = mutableSetOf(),
val supportedBy: MutableSet<Int> = mutableSetOf()
)
data class ViewInfo(
val blockId: Int?,
val height: Int... | 0 | Kotlin | 0 | 0 | a6eec4168b4a98b73d4496c9d610854a0165dbeb | 2,818 | aoc2023-kotlin | MIT License |
atcoder/arc155/a.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package atcoder.arc155
private fun solve(): Boolean {
val (_, qIn) = readLongs()
val s = readLn()
val q = minOf(qIn % (2 * s.length) + 4 * s.length, qIn).toInt()
val c = (s + " ".repeat(q)).toCharArray()
val mark = BooleanArray(c.size) { false }
var answer = true
val queue = IntArray(c.size)
for (i in c.indice... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,258 | competitions | The Unlicense |
src/Day01.kt | markhor1999 | 574,354,173 | false | {"Kotlin": 4937} | fun main() {
fun List<List<Int>>.sortedNElementsSum(n: Int): Int {
val values = sortedSetOf<Int>()
for (element in map { it.sum() }) {
values.add(element)
if (values.size > n) {
values.remove(values.first())
}
}
return values.sum()
... | 0 | Kotlin | 0 | 0 | 800f218ff12908ebd885c3f475793c6be2d7fd7d | 881 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | buongarzoni | 572,991,996 | false | {"Kotlin": 26251} | fun solveDay03() {
val result = readInput("Day03").mapNotNull { it.getItem() }.sum()
println(result)
val result2 = readInput("Day03")
.chunked(3)
.mapNotNull { it.getChunkPoints() }
.sum()
println(result2)
}
private fun List<String>.getChunkPoints(): Int? {
for (character i... | 0 | Kotlin | 0 | 0 | 96aadef37d79bcd9880dbc540e36984fb0f83ce0 | 1,033 | AoC-2022 | Apache License 2.0 |
src/Day01.kt | atsvetkov | 572,711,515 | false | {"Kotlin": 10892} | import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
var maxCalories = 0
var currentTotal = 0
for (line in input) {
if (line.isEmpty()) {
maxCalories = max(maxCalories, currentTotal)
currentTotal = 0
} else {
... | 0 | Kotlin | 0 | 0 | 01c3bb6afd658a2e30f0aee549b9a3ac4da69a91 | 1,126 | advent-of-code-2022 | Apache License 2.0 |
src/nativeMain/kotlin/xyz/justinhorton/aoc2022/Day07.kt | justinhorton | 573,614,839 | false | {"Kotlin": 39759, "Shell": 611} | package xyz.justinhorton.aoc2022
import okio.Path
import okio.Path.Companion.toPath
/**
* https://adventofcode.com/2022/day/7
*/
class Day07(override val input: String) : Day() {
override fun part1(): String {
val fileSystem = buildFileSystem()
return fileSystem.keys
.map { dir -> to... | 0 | Kotlin | 0 | 1 | bf5dd4b7df78d7357291c7ed8b90d1721de89e59 | 3,048 | adventofcode2022 | MIT License |
src/main/kotlin/sschr15/aocsolutions/Day24.kt | sschr15 | 317,887,086 | false | {"Kotlin": 184127, "TeX": 2614, "Python": 446} | package sschr15.aocsolutions
import com.sschr15.z3kt.*
import sschr15.aocsolutions.util.*
/**
* AOC 2023 [Day 24](https://adventofcode.com/2023/day/24)
* Challenge: Killing hundreds of hailstones with one stone
* ~~that's how the saying goes, right?~~
*/
object Day24 : Challenge {
@ReflectivelyUsed
overri... | 0 | Kotlin | 0 | 0 | e483b02037ae5f025fc34367cb477fabe54a6578 | 2,820 | advent-of-code | MIT License |
src/main/kotlin/g2901_3000/s2948_make_lexicographically_smallest_array_by_swapping_elements/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2901_3000.s2948_make_lexicographically_smallest_array_by_swapping_elements
// #Medium #Array #Sorting #Union_Find #2024_01_16_Time_928_ms_(94.59%)_Space_77.9_MB_(21.62%)
import kotlin.math.abs
class Solution {
fun lexicographicallySmallestArray(nums: IntArray, limit: Int): IntArray {
val n = num... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,359 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/aoc2022/Day22.kt | w8mr | 572,700,604 | false | {"Kotlin": 140954} | package aoc2022
import aoc.parser.*
class Day22() {
enum class GridType(val text: String) {
EMPTY(" "),
OPEN("."),
WALL("#")
}
enum class Dir {
RIGHT,
DOWN,
LEFT,
UP
}
operator fun Dir.minus(other: Dir) =
Dir.values()[(this.ordinal ... | 0 | Kotlin | 0 | 0 | e9bd07770ccf8949f718a02db8d09daf5804273d | 9,250 | aoc-kotlin | Apache License 2.0 |
src/Day14.kt | ech0matrix | 572,692,409 | false | {"Kotlin": 116274} | fun main() {
fun setupCave(input: List<String>): MutableSet<Coordinates> {
val cave = mutableSetOf<Coordinates>()
for(formation in input) {
val parts = formation
.split(" -> ")
.map { it.split(',') }
.map { Coordinates(it[1].toInt(), it[0].... | 0 | Kotlin | 0 | 0 | 50885e12813002be09fb6186ecdaa3cc83b6a5ea | 3,725 | aoc2022 | Apache License 2.0 |
advent-of-code-2022/src/main/kotlin/Day03.kt | jomartigcal | 433,713,130 | false | {"Kotlin": 72459} | //Day 03: Rucksack Reorganization
//https://adventofcode.com/2022/day/3
import java.io.File
fun main() {
val rucksacks = File("src/main/resources/Day03.txt").readLines()
reorganizeRucksacks(rucksacks)
reorganizeRucksacksByGroup(rucksacks.chunked(3))
}
private fun reorganizeRucksacks(rucksacks: List<Strin... | 0 | Kotlin | 0 | 0 | 6b0c4e61dc9df388383a894f5942c0b1fe41813f | 1,023 | advent-of-code | Apache License 2.0 |
src/main/kotlin/g0601_0700/s0688_knight_probability_in_chessboard/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0601_0700.s0688_knight_probability_in_chessboard
// #Medium #Dynamic_Programming #2023_02_20_Time_144_ms_(100.00%)_Space_34.9_MB_(100.00%)
class Solution {
private val directions = arrayOf(
intArrayOf(-2, -1),
intArrayOf(-2, 1),
intArrayOf(-1, 2),
intArrayOf(1, 2),
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,516 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/Problem7.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | import kotlin.math.floor
import kotlin.math.sqrt
import kotlin.system.measureNanoTime
/**
* 10001st prime
*
* By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
*
* What is the 10001st prime number?
*
* https://projecteuler.net/problem=7
*/
fun main() {
pr... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 1,640 | project-euler | MIT License |
src/main/kotlin/aoc2022/Day19.kt | w8mr | 572,700,604 | false | {"Kotlin": 140954} | package aoc2022
import aoc.*
import aoc.parser.*
class Day19() {
//Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian.
enum class Material {
ORE,
CLAY,
OBSIDIAN,
GEODE
... | 0 | Kotlin | 0 | 0 | e9bd07770ccf8949f718a02db8d09daf5804273d | 11,813 | aoc-kotlin | Apache License 2.0 |
src/main/kotlin/be/swsb/aoc2021/day7/Day7.kt | Sch3lp | 433,542,959 | false | {"Kotlin": 90751} | package be.swsb.aoc2021.day7
import kotlin.math.*
object Day7 {
fun solve1(input: List<Int>): Fuel {
return findMostOptimalCost(input)
}
fun solve2(input: List<Int>): Fuel {
return findMostOptimalCost2(input)
}
}
fun findMostOptimalCost(positions: List<Position>): Fuel {
val cr... | 0 | Kotlin | 0 | 0 | 7662b3861ca53214e3e3a77c1af7b7c049f81f44 | 1,373 | Advent-of-Code-2021 | MIT License |
src/Day21.kt | Allagash | 572,736,443 | false | {"Kotlin": 101198} | import java.io.File
// Advent of Code 2022, Day 21: Monkey Math
class Day21(input: String) {
data class Day21Exp(val name: String, var value: Long? = null, var var1: String? = null,
var op:Char? = null, var var2: String? = null)
companion object {
private val DAY21_PATTERN_VA... | 0 | Kotlin | 0 | 0 | 8d5fc0b93f6d600878ac0d47128140e70d7fc5d9 | 3,730 | AdventOfCode2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.