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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[448]找到所有数组中消失的数字.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次。
//
// 找到所有在 [1, n] 范围之间没有出现在数组中的数字。
//
// 您能在不使用额外空间且时间复杂度为O(n)的情况下完成这个任务吗? 你可以假定返回的数组不算在额外空间内。
//
// 示例:
//
//
//输入:
//[4,3,2,7,8,2,3,1]
//
//输出:
//[5,6]
//
// Related Topics 数组
// 👍 609 👎 0
//leetcode submit region begin(Prohibit modificatio... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,246 | MyLeetCode | Apache License 2.0 |
src/day16/first/Solution.kt | verwoerd | 224,986,977 | false | null | package day16.first
import tools.timeSolution
import kotlin.math.abs
fun main() = timeSolution {
var input = readLine()!!.toCharArray().map { (it - '0').toLong() }
val patterns = patternGenerator(input.size).take(input.size).toList()
patterns.map { it.joinToString(",") }.forEach(::println)
input = fft(input... | 0 | Kotlin | 0 | 0 | 554377cc4cf56cdb770ba0b49ddcf2c991d5d0b7 | 1,070 | AoC2019 | MIT License |
src/main/kotlin/cloud/dqn/leetcode/LongestCommonPrefixKt.kt | aviuswen | 112,305,062 | false | null | package cloud.dqn.leetcode
/**
* https://leetcode.com/problems/longest-common-prefix/description/
Write a function to find the longest common prefix string
amongst an array of strings.
*/
class LongestCommonPrefixKt {
class Solution {
/**
var largestPrefix = getLongestString(strs)
... | 0 | Kotlin | 0 | 0 | 23458b98104fa5d32efe811c3d2d4c1578b67f4b | 1,755 | cloud-dqn-leetcode | No Limit Public License |
src/Day10.kt | Allagash | 572,736,443 | false | {"Kotlin": 101198} | import java.io.File
// Advent of Code 2022, Day 10, Cathode-Ray Tube
fun main() {
fun readInput(name: String) = File("src", "$name.txt")
.readLines()
fun part1(input: List<String>): Int {
val importantCycles = listOf(20, 60, 100, 140, 180, 220)
var sum = 0
var cycle = 1
... | 0 | Kotlin | 0 | 0 | 8d5fc0b93f6d600878ac0d47128140e70d7fc5d9 | 1,737 | AdventOfCode2022 | Apache License 2.0 |
domain/src/main/kotlin/io/kfleet/geo/Node.kt | mseemann | 205,524,973 | false | null | package io.kfleet.geo
class Node(val x: Double, val y: Double, val w: Double, val h: Double, val quadrant: Quadrant) {
private val w2 = w / 2
private val h2 = h / 2
private val midX = x + w2
private val midY = y + h2
private val nw = lazy { Node(x, midY, w2, h2, Quadrant.NW) }
private val ne ... | 1 | Kotlin | 1 | 2 | 09507433f9177f793d2314416564a2fe39485a0c | 2,894 | kfleet | MIT License |
src/test/kotlin/com/igorwojda/integer/pyramidgenerator/solution.kt | tmdroid | 428,976,530 | true | {"Kotlin": 215713} | package com.igorwojda.integer.pyramidgenerator
// iterative solution
private object Solution1 {
private fun generatePyramid(n: Int): List<String> {
val list = mutableListOf<String>()
val numColumns = (n * 2) - 1
(0 until n).forEach { row ->
val numHashes = (row * 2) + 1
... | 1 | Kotlin | 2 | 0 | f82825274ceeaf3bef81334f298e1c7abeeefc99 | 2,682 | kotlin-puzzles | MIT License |
src/main/kotlin/day04/Code.kt | fcolasuonno | 317,324,330 | false | null | package day04
import isDebug
import java.io.File
fun main() {
val name = if (isDebug()) "test.txt" else "input.txt"
System.err.println(name)
val dir = ::main::class.java.`package`.name
val input = File("src/main/kotlin/$dir/$name").readLines()
val parsed = parse(input)
part1(parsed)
part2(... | 0 | Kotlin | 0 | 0 | e7408e9d513315ea3b48dbcd31209d3dc068462d | 2,068 | AOC2020 | MIT License |
src/main/kotlin/lib/Generator.kt | jetpants | 130,976,101 | false | null | package judoku
object Generator {
@JvmStatic
fun generate(size: Int, symmetry: Symmetry, minimal: Boolean = true): Grid {
val g = Grid(size)
return generate(g.boxWidth, g.boxHeight, symmetry, minimal)
}
@JvmStatic
fun generate(boxWidth: Int, boxHeight: Int, symmetry: Symmetry, _min... | 0 | Kotlin | 2 | 3 | 904c05456ecf83f8707f4d3c6c5afa0a50f4b9e7 | 3,965 | judoku | Apache License 2.0 |
src/Day01.kt | max-zhilin | 573,066,300 | false | {"Kotlin": 114003} | fun main() {
fun part1(input: List<String>): Int {
val list = mutableListOf<Int>()
list.add(0)
for (s in input) {
if (s.isEmpty()) {
list.add(0)
} else {
list[list.lastIndex]+= s.toInt()
}
}
return list.max()... | 0 | Kotlin | 0 | 0 | d9dd7a33b404dc0d43576dfddbc9d066036f7326 | 962 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FindDifference.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,493 | kotlab | Apache License 2.0 |
src/Day10.kt | monsterbrain | 572,819,542 | false | {"Kotlin": 42040} | fun main() {
fun part1(input: List<String>): Int {
var cycles = 0
var x = 1
val cycleMap = mutableMapOf<Int, Int>()
fun noopCycle() {
cycles += 1
cycleMap[cycles] = x
}
fun addCycle(value: Int) {
cycles += 1
cycleMap[... | 0 | Kotlin | 0 | 0 | 3a1e8615453dd54ca7c4312417afaa45379ecf6b | 3,719 | advent-of-code-kotlin-2022-Solutions | Apache License 2.0 |
src/main/kotlin/pl/bizarre/day8_2.kt | gosak | 572,644,357 | false | {"Kotlin": 26456} | package pl.bizarre
import pl.bizarre.common.loadInput
import kotlin.math.abs
import kotlin.math.max
fun main() {
val input = loadInput(8)
println("result ${day8_2(input)}")
}
fun day8_2(input: List<String>): Int {
val width = input.first().length
val height = input.size
val trees = mutableMapOf<P... | 0 | Kotlin | 0 | 0 | aaabc56532c4a5b12a9ce23d54c76a2316b933a6 | 4,302 | adventofcode2022 | Apache License 2.0 |
Kotlin/Floyd.kt | lprimeroo | 41,106,663 | false | null | import java.util.*
class Floyd {
fun shortestpath(adj: Array<IntArray>, path: Array<IntArray>): Array<IntArray> {
val n = adj.size
val ans = Array(n) { IntArray(n) }
// Implement algorithm on a copy matrix so that the adjacency isn't
// destroyed.
copy(ans, adj)
... | 56 | C++ | 186 | 99 | 16367eb9796b6d4681c5ddf45248e2bcda72de80 | 3,385 | DSA | MIT License |
src/main/kotlin/fp/kotlin/example/chapter03/TailRecursion.kt | funfunStory | 101,662,895 | false | null | package fp.kotlin.example.chapter03
import fp.kotlin.example.head
import fp.kotlin.example.tail
fun main() {
println(factorial(10)) // "3628800" 출력
println(maximum(listOf(1, 3, 2, 8, 4))) // "8" 출력
println(reverse("abcd")) // "dcba" 출력
println(toBinary(10)) // "1010" 출력
println(re... | 1 | Kotlin | 23 | 39 | bb10ea01d9f0e1b02b412305940c1bd270093cb6 | 3,009 | fp-kotlin-example | MIT License |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/searching/SearchInMatrix.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.searching
fun main() {
val matrix = listOf(
listOf(-20, -18, -12, -1, 1, 2, 4, 7, 16, 18),
listOf(-15, -13, -10, -9, -2, 1, 2, 7, 10, 14),
listOf(-20, -18, -12, -6, 11, 14, 16, 18, 19, 20),
listOf(-20, -19, -11, -7, -6, -4, 11, 12, 14... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 1,005 | algs4-leprosorium | MIT License |
src/adventofcode/Day23.kt | Timo-Noordzee | 573,147,284 | false | {"Kotlin": 80936} | package adventofcode
import org.openjdk.jmh.annotations.*
import java.util.concurrent.TimeUnit
private fun MutableSet<Point>.move(searchDirections: Array<Array<Move>>): Int {
var moved = 0
this.filter { it.getAllNeighbors().any { neighbor -> neighbor in this } }
.mapNotNull { elf ->
val (_... | 0 | Kotlin | 0 | 2 | 10c3ab966f9520a2c453a2160b143e50c4c4581f | 2,619 | advent-of-code-2022-kotlin | Apache License 2.0 |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[57]插入区间.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.util.*
import kotlin.collections.ArrayList
//给你一个 无重叠的 ,按照区间起始端点排序的区间列表。
//
// 在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。
//
//
//
// 示例 1:
//
//
//输入:intervals = [[1,3],[6,9]], newInterval = [2,5]
//输出:[[1,5],[6,9]]
//
//
// 示例 2:
//
//
//输入:intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], ne... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 2,251 | MyLeetCode | Apache License 2.0 |
src/Day06.kt | jorander | 571,715,475 | false | {"Kotlin": 28471} | fun main() {
val day = "Day06"
fun String.toNumberOfCharsBeforeUniqeSetOfSize(size: Int) = windowed(size)
.mapIndexed { index, s -> index + size to s }
.first { (_, s) -> s.toSet().size == size }.first
fun part1(input: String): Int {
return input.toNumberOfCharsBeforeUniqeSetOfSiz... | 0 | Kotlin | 0 | 0 | 1681218293cce611b2c0467924e4c0207f47e00c | 1,287 | advent-of-code-2022 | Apache License 2.0 |
src/hongwei/leetcode/playground/leetcodecba/M55JumpGame.kt | hongwei-bai | 201,601,468 | false | {"Java": 143669, "Kotlin": 38875} | package hongwei.leetcode.playground.leetcodecba
class M55JumpGame {
fun test() {
// val input = intArrayOf(2, 3, 1, 1, 4)
// val input = intArrayOf(3, 2, 1, 0, 4)
// val input = intArrayOf(2, 5, 0, 0)
val input = intArrayOf(3, 0, 8, 2, 0, 0, 1)
val result = canJump(input)
... | 0 | Java | 0 | 1 | 9d871de96e6b19292582b0df2d60bbba0c9a895c | 2,253 | leetcode-exercise-playground | Apache License 2.0 |
src/Day01.kt | wooodenleg | 572,658,318 | false | {"Kotlin": 30668} | fun getElfCalories(input: List<String>) = buildList {
var sum = 0
for (line in input) {
if (line.isBlank()) {
add(sum)
sum = 0
} else sum += line.toInt()
}
add(sum)
}
fun main() {
fun part1(input: List<String>): Int =
getElfCalories(input).max()
... | 0 | Kotlin | 0 | 1 | ff1f3198f42d1880e067e97f884c66c515c8eb87 | 753 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/groupnet/decomposition/ComponentDecomposition.kt | AlmasB | 174,802,362 | false | {"Kotlin": 167480, "Java": 91450, "CSS": 110} | package groupnet.decomposition
import groupnet.euler.*
import groupnet.gn.GNDescription
import groupnet.util.Tuple3
import groupnet.util.partition2Lazy
/**
* @author <NAME> (<EMAIL>)
*/
fun isAtomic(D: Description): Boolean {
val Z = Z(D) - azEmpty
if (Z.size == 1 && L(D).size > 1)
return false
... | 3 | Kotlin | 0 | 0 | 4aaa9de60ecdba5b9402b809e1e6e62489a1d790 | 2,039 | D2020 | Apache License 2.0 |
day15/src/main/kotlin/App.kt | ascheja | 317,918,055 | false | null | package net.sinceat.aoc2020.day15
fun main() {
println("1, 3, 2, ... = ${theElvesGamePart1(listOf(1, 3, 2)).nth(2020)}")
println("2, 1, 3, ... = ${theElvesGamePart1(listOf(2, 1, 3)).nth(2020)}")
println("1, 2, 3, ... = ${theElvesGamePart1(listOf(1, 2, 3)).nth(2020)}")
println("2, 3, 1, ... = ${theElves... | 0 | Kotlin | 0 | 0 | f115063875d4d79da32cbdd44ff688f9b418d25e | 1,379 | aoc2020 | MIT License |
src/Day06.kt | carloxavier | 574,841,315 | false | {"Kotlin": 14082} | fun main() {
check(day6("mjqjpqmgbljsphdztnvjfqwrcgsmlb") == 7)
check(day6("bvwbjplbgvbhsrlpgdmjqwftvncz") == 5)
check(day6("nppdvjthqldpwncqszvftbrmjlhg") == 6)
check(day6("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg") == 10)
check(day6("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw") == 11)
// first part
check... | 0 | Kotlin | 0 | 0 | 4e84433fe866ce1a8c073a7a1e352595f3ea8372 | 690 | adventOfCode2022 | Apache License 2.0 |
src/main/kotlin/Day01.kt | michaeljwood | 572,560,528 | false | {"Kotlin": 5391} | fun main() {
fun part1(input: String) = input.split("\n\n").map { line ->
line.split("\n").filter { it.isNotBlank() }.map { cal -> cal.toInt() }
}.maxOfOrNull { it.sum() }
fun part2(input: String) = input.split("\n\n").map { line ->
line.split("\n").filter { it.isNotBlank() }.map { cal -> c... | 0 | Kotlin | 0 | 0 | 8df2121f12a5a967b25ce34bce6678ab9afe4aa7 | 638 | advent-of-code-2022 | Apache License 2.0 |
2021/src/main/kotlin/day16_imp.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | @file:OptIn(ExperimentalUnsignedTypes::class)
import utils.Parser
import utils.Solution
fun main() {
Day16Imp.run()
}
object Day16Imp : Solution<UByteArray>() {
override val name = "day16"
override val parser = Parser { input ->
input.chunked(2).map { it.toUByte(16) }.toUByteArray()
}
sealed interface... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 3,792 | aoc_kotlin | MIT License |
year2019/day01/part1/src/main/kotlin/com/curtislb/adventofcode/year2019/day01/part1/Year2019Day01Part1.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Day 1: The Tyranny of the Rocket Equation ---
Santa has become stranded at the edge of the Solar System while delivering presents to other
planets! To accurately calculate his position in space, safely align his warp drive, and return to
Earth in time to save Christmas, he needs you to bring him measurements fr... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,068 | AdventOfCode | MIT License |
src/Day01.kt | rod41732 | 728,131,475 | false | {"Kotlin": 26028} | /**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
fun replaceWordWithNumber(input: String): String {
val numbers = listOf("zero", "one", "two", "three",
"four", "five", "six", "seven",
"eight", "nine")
var out = input
numbers.forE... | 0 | Kotlin | 0 | 0 | 05a308a539c8a3f2683b11a3a0d97a7a78c4ffac | 1,116 | aoc-23 | Apache License 2.0 |
src/main/kotlin/nl/meine/aoc/_2023/Day6.kt | mtoonen | 158,697,380 | false | {"Kotlin": 201978, "Java": 138385} | package nl.meine.aoc._2023
class Day6 {
fun one(timeString: List<Int>, distance:List<Int>): Int {
val times = timeString
val distances = distance
var total = 1;
times.forEachIndexed{index,time->
run {
val timeToBeat = distances[index]
var... | 0 | Kotlin | 0 | 0 | a36addef07f61072cbf4c7c71adf2236a53959a5 | 1,243 | advent-code | MIT License |
kotlin/PersistentTree.kt | indy256 | 1,493,359 | false | {"Java": 545116, "C++": 266009, "Python": 59511, "Kotlin": 28391, "Rust": 4682, "CMake": 571} | // https://en.wikipedia.org/wiki/Persistent_data_structure
object PersistentTree {
data class Node(
val left: Node? = null,
val right: Node? = null,
val sum: Int = (left?.sum ?: 0) + (right?.sum ?: 0)
)
fun build(left: Int, right: Int): Node {
if (left == right)... | 97 | Java | 561 | 1,806 | 405552617ba1cd4a74010da38470d44f1c2e4ae3 | 1,500 | codelibrary | The Unlicense |
src/shmp/lang/language/syntax/numeral/NumeralParadigm.kt | ShMPMat | 240,860,070 | false | null | package shmp.lang.language.syntax.numeral
import shmp.lang.language.NumeralSystemBase
import shmp.lang.language.lexis.Lexis
import shmp.lang.language.lineUpAll
import shmp.lang.language.syntax.SyntaxException
import shmp.lang.language.syntax.SyntaxRelation
import shmp.lang.language.syntax.numeral.NumeralConstructionTy... | 0 | Kotlin | 0 | 1 | 4d26b0d50a1c3c6318eede8dd9678d3765902d4b | 2,580 | LanguageGenerator | MIT License |
src/Day03.kt | vivekpanchal | 572,801,707 | false | {"Kotlin": 11850} |
const val ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
fun main() {
fun part1(input: List<String>): Int {
return input.map {str->
val pair=str.substring(0,str.length/2) to str.substring(str.length/2)
val common=pair.first.first { pair.second.contains(it)
... | 0 | Kotlin | 0 | 0 | f21a2dd08be66520e9c9de14611e50c14ea017f0 | 909 | Aoc-kotlin | Apache License 2.0 |
language/kotlin/fib.kt | A1rPun | 177,014,508 | false | null | import kotlin.math.pow
import kotlin.math.round
fun fib(n: Int): Int {
return if (n < 2) n else fib(n - 1) + fib(n - 2)
}
fun fibLinear(n: Int): Int {
var prevFib = 0
var fib = 1
repeat(n) {
val temp = prevFib + fib
prevFib = fib
fib = temp
}
return prevFib
}
fun fibFormula(n: Int): Int {
... | 0 | Haskell | 0 | 1 | 295de6ac0584672d936a0c7ad09cb464f916d27a | 880 | nurture | MIT License |
kotlin/src/com/s13g/aoc/aoc2023/Day8.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2023
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import com.s13g.aoc.lcm
import com.s13g.aoc.resultFrom
private typealias Network = Map<String, Node>
/**
* --- Day 8: <NAME> ---
* https://adventofcode.com/2023/day/8
*/
class Day8 : Solver {
val re = """(\w+) = \((\w+), (\w+)\)... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 2,040 | euler | Apache License 2.0 |
src/main/kotlin/de/startat/aoc2023/Day1.kt | Arondc | 727,396,875 | false | {"Kotlin": 194620} | package de.startat.aoc2023
class Day1 {
private val literalReplacements = sequenceOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"five" to 5,
"six" to 6,
"seven" to 7,
"eight" to 8,
"nine" to 9
)
fun star1() {
calculat... | 0 | Kotlin | 0 | 0 | 660d1a5733dd533aff822f0e10166282b8e4bed9 | 1,715 | AOC2023 | Creative Commons Zero v1.0 Universal |
src/chapter4/section1/ex35_TwoEdgeConnectivity.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter4.section1
/**
* 边的连通性
* 在一副连通图中,如果一条边被删除后图会被分为两个独立的连通分量,这条边就被成为桥。
* 没有桥的图称为边连通图。
* 开发一种基于深度优先搜索算法的数据类型,判断一个图是否时边连通图。
*
* 解:这题和4.1.34都可以参考练习4.1.10中的代码实现
*/
fun Graph.isConnectedGraph(): Boolean {
for (s in 0 until V) {
val iterable = adj(s)
if (iterable.count() <= 1) continue
... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,524 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/Day01.kt | jwklomp | 572,195,432 | false | {"Kotlin": 65103} | fun main() {
fun getSums(input: List<String>): List<Int> {
val indexes = listOf(0) + input.indexesOf("") + listOf(input.size)
return indexes.windowed(2)
.map { input.subList(it.first(), it.last())
.filterNot { it == "" }
.map { it.toInt() }
... | 0 | Kotlin | 0 | 0 | 1b1121cfc57bbb73ac84a2f58927ab59bf158888 | 715 | aoc-2022-in-kotlin | Apache License 2.0 |
app/src/main/java/com/jackson/tictactoe/utils/MinMaxAlgorithm.kt | Maxwell6635 | 722,506,658 | false | {"Kotlin": 45260} | package com.jackson.tictactoe.utils
object MinMaxAlgorithm {
private var player = 'x'
private var opponent = 'o'
private fun isMovesLeft(board: Array<CharArray>): Boolean {
for (i in 0..2) for (j in 0..2) if (board[i][j] == '_') return true
return false
}
private fun evaluate(b: A... | 0 | Kotlin | 0 | 0 | 62f8035ad23e777a07cac50cb058283e193d5526 | 3,419 | TicTacToe | MIT License |
src/main/aoc2022/Day17.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2022
import AMap
import Pos
class Day17(input: List<String>) {
enum class Rock(val height: Int, val parts: List<Pos>) {
Dash(1, listOf(Pos(0, 0), Pos(1, 0), Pos(2, 0), Pos(3, 0))),
Plus(3, listOf(Pos(1, 0), Pos(0, 1), Pos(1, 1), Pos(2, 1), Pos(1, 2))),
Angle(3, listOf(Pos(0, 0)... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 3,737 | aoc | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SplitIntoFibonacci.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 | 3,541 | kotlab | Apache License 2.0 |
src/main/kotlin/Day12.kt | Yeah69 | 317,335,309 | false | {"Kotlin": 73241} | import java.lang.Exception
import kotlin.math.abs
class Day12 : Day() {
override val label: String get() = "12"
private data class Situation(val waypoint: Pair<Int, Int>, val shipPosition: Pair<Int, Int>)
private fun Pair<Int, Int>.left(value: Int): Pair<Int, Int> =
when ((value % 360) / 90) {
... | 0 | Kotlin | 0 | 0 | 23121ede8e3e8fc7aa1e8619b9ce425b9b2397ec | 3,231 | AdventOfCodeKotlin | The Unlicense |
src/main/kotlin/engineer/thomas_werner/euler/Problem26.kt | huddeldaddel | 183,355,188 | true | {"Kotlin": 116039, "Java": 34495} | package de.huddeldaddel.euler
import java.lang.ArithmeticException
import java.math.BigDecimal
import java.math.BigInteger
import java.math.MathContext
import java.math.RoundingMode
/**
* Solution for https://projecteuler.net/problem=26
*/
fun main() {
println(Problem26().getDemoninatorWithMaxCycle())
}
class ... | 0 | Kotlin | 1 | 0 | df514adde8c62481d59e78a44060dc80703b8f9f | 2,231 | euler | MIT License |
src/Day06.kt | jsebasct | 572,954,137 | false | {"Kotlin": 29119} | import java.io.File
fun main() {
data class Movement(val amount: Int, val source: Int, val destination: Int)
fun getMovements(movementLines: String) = movementLines.split("\n")
.map { line ->
val splintedLine = line.split(" ")
.filter { it.toIntOrNull() != null }
... | 0 | Kotlin | 0 | 0 | c4a587d9d98d02b9520a9697d6fc269509b32220 | 4,241 | aoc2022 | Apache License 2.0 |
kotlin/src/com/leetcode/496_NextGreaterElementI.kt | programmerr47 | 248,502,040 | false | null | package com.leetcode
import java.util.*
import kotlin.collections.HashMap
//Straightforward solution time: O(n*m), space: O(1), where n = nums1.size, m = nums2.size
private class Solution496 {
fun nextGreaterElement(nums1: IntArray, nums2: IntArray): IntArray {
return IntArray(nums1.size) { i ->
... | 0 | Kotlin | 0 | 0 | 0b5fbb3143ece02bb60d7c61fea56021fcc0f069 | 1,543 | problemsolving | Apache License 2.0 |
src/commonMain/kotlin/eu/yeger/cyk/RunningCYK.kt | DerYeger | 302,742,119 | false | null | package eu.yeger.cyk
import eu.yeger.cyk.model.*
import eu.yeger.cyk.parser.word
public fun runningCYK(
wordString: String,
grammar: () -> Result<Grammar>
): Result<List<CYKState>> {
return word(wordString).with(grammar(), ::runningCYK)
}
public fun runningCYK(
word: Result<Word>,
grammar: Result... | 0 | Kotlin | 0 | 2 | 76b895e3e8ea6b696b3ad6595493fda9ee3da067 | 3,638 | cyk-algorithm | MIT License |
PF/9. Functions/Function_Exercise.kt | FasihMuhammadVirk | 606,810,021 | false | null | import java.util.*
import kotlin.collections.ArrayList
//Write a function that takes in two integers and return their sums
fun sum_numbers(x:Int , y:Int ):Int = x + y
//A function that reverse the value of the string
fun reverse_string(s:String):String = s.reversed()
//take an array of integer and return their aver... | 0 | Kotlin | 0 | 1 | 089dedc029434f64140d5a63246b8b35992a07ed | 2,911 | Concepts-in-Kotlin | MIT License |
src/ad/kata/aoc2021/day08/SignalDeduction.kt | andrej-dyck | 433,401,789 | false | {"Kotlin": 161613} | package ad.kata.aoc2021.day08
class SignalDeduction(
uniqueSignals: List<Signal>
) {
fun deduceDigits(signals: List<Signal>) =
signals.map { deducedSignalToDigits[it] }
private val deducedSignalToDigits: Map<Signal, Digit> by lazy {
uniqueLengthDigitsIn(uniqueSignals)
.withIde... | 0 | Kotlin | 0 | 0 | 28d374fee4178e5944cb51114c1804d0c55d1052 | 3,136 | advent-of-code-2021 | MIT License |
src/main/kotlin/solutions/Day3RucksackReorganization.kt | aormsby | 571,002,889 | false | {"Kotlin": 80084} | package solutions
import utils.Input
import utils.Solution
// run only this day
fun main() {
Day3RucksackReorganization()
}
class Day3RucksackReorganization : Solution() {
private val a = 'a'
private val A = 'A'
init {
begin("Day 3 - Rucksack Reorganization")
val input = Input.parse... | 0 | Kotlin | 0 | 0 | 1bef4812a65396c5768f12c442d73160c9cfa189 | 1,384 | advent-of-code-2022 | MIT License |
src/Day18.kt | cypressious | 572,916,585 | false | {"Kotlin": 40281} | import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonParser
import com.google.gson.JsonPrimitive
import kotlin.math.ceil
fun main() {
abstract class SNum {
var parent: SNum? = null
abstract fun magnitude(): Long
}
class SPair(var left: SNum, var r... | 0 | Kotlin | 0 | 0 | 169fb9307a34b56c39578e3ee2cca038802bc046 | 3,840 | AdventOfCode2021 | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2021/Day6.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2021
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.report
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import java.util.SortedMap
class Day6: AdventDay(2021, 6) {
companion object {
@JvmStatic
fun main(args: Array<St... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,326 | adventofcode | MIT License |
day20/src/main/kotlin/ver_a.kt | jabbalaci | 115,397,721 | false | null | package a
import java.math.BigInteger
import java.io.File
data class Point(var x: BigInteger, var y: BigInteger, var z: BigInteger)
data class Particle(val id: Int, val line: String) {
private val points = mutableListOf<Point>()
init {
val REGEX = Regex("""<(.*?)>""")
val matchedResults = R... | 0 | Kotlin | 0 | 0 | bce7c57fbedb78d61390366539cd3ba32b7726da | 3,074 | aoc2017 | MIT License |
src/day01/Day01.kt | JakubMosakowski | 572,993,890 | false | {"Kotlin": 66633} | package day01
import readInput
/**
* Santa's reindeer typically eat regular reindeer food, but they need a lot of magical energy to deliver presents on Christmas.
* For that, their favorite snack is a special type of star fruit that only grows deep in the jungle. The Elves have brought you on their annual expeditio... | 0 | Kotlin | 0 | 0 | f6e9a0b6c2b66c28f052d461c79ad4f427dbdfc8 | 4,310 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DecodeWays2.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 | 6,560 | kotlab | Apache License 2.0 |
2021/kotlin/src/main/kotlin/com/pietromaggi/aoc2021/day01/Day01.kt | pfmaggi | 438,378,048 | false | {"Kotlin": 113883, "Zig": 18220, "C": 7779, "Go": 4059, "CMake": 386, "Awk": 184} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in wr... | 0 | Kotlin | 0 | 0 | 7c4946b6a161fb08a02e10e99055a7168a3a795e | 1,364 | AdventOfCode | Apache License 2.0 |
src/Day01.kt | gomercin | 572,911,270 | false | {"Kotlin": 25313} | /**
* Searches I needed to make:
kotlin for loop
kotlin check string empty
kotlin string to integer
kotlin array
kotlin list
kotlin mutable list
kotlin sort
kotlin sort reverse
kotlin split list
kotlin sum list
*/
fun main() {
fun part1(input: List<String>): Int {
var currentMax = 0
var currentSu... | 0 | Kotlin | 0 | 0 | 30f75c4103ab9e971c7c668f03f279f96dbd72ab | 1,279 | adventofcode-2022 | Apache License 2.0 |
kotlin/strings/Manacher.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package strings
import java.util.Arrays
// Manacher's algorithm to finds all palindromes: https://cp-algorithms.com/string/manacher.html
object Manacher {
// d1[i] - how many palindromes of odd length with center at i
fun oddPalindromes(s: String): IntArray {
val n: Int = s.length()
val d1 = I... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,526 | codelibrary | The Unlicense |
src/main/kotlin/com/groundsfam/advent/y2020/d17/Day17.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2020.d17
import com.groundsfam.advent.DATAPATH
import java.util.ArrayDeque
import java.util.Queue
import kotlin.io.path.div
import kotlin.io.path.useLines
private typealias Point = Triple<Int, Int, Int>
private typealias State = Set<Point>
private fun State.next(): State {
val this... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 3,712 | advent-of-code | MIT License |
scripts/Day24.kts | matthewm101 | 573,325,687 | false | {"Kotlin": 63435} | import java.io.File
import kotlin.math.max
data class Pos(val x: Int, val y: Int) {
operator fun plus(a: Pos) = Pos(x + a.x, y + a.y)
}
val RIGHT = Pos(1,0)
val LEFT = Pos(-1,0)
val DOWN = Pos(0,1)
val UP = Pos(0,-1)
val raw = File("../inputs/24.txt").readLines()
val minWindX = 1
val minWindY = 1
val maxWindX = r... | 0 | Kotlin | 0 | 0 | bbd3cf6868936a9ee03c6783d8b2d02a08fbce85 | 4,594 | adventofcode2022 | MIT License |
src/array/LeetCode139.kt | Alex-Linrk | 180,918,573 | false | null | package array
import java.util.*
/**
*给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。
说明:
拆分时可以重复使用字典中的单词。
你可以假设字典中没有重复的单词。
示例 1:
输入: s = "leetcode", wordDict = ["leet", "code"]
输出: true
解释: 返回 true 因为 "leetcode" 可以被拆分成 "leet code"。
示例 2:
输入: s = "applepenapple", wordDict = ["apple", "pen"]
输出... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 1,507 | LeetCode | Apache License 2.0 |
src/Day10.kt | mkulak | 573,910,880 | false | {"Kotlin": 14860} | fun main() {
fun part1(input: List<String>): Int {
var cycle = 1
var register = 1
var res = 0
fun checkCycle() {
if (cycle in setOf(20, 60, 100, 140, 180, 220)) {
res += cycle * register
}
}
input.forEach { line ->
v... | 0 | Kotlin | 0 | 0 | 3b4e9b32df24d8b379c60ddc3c007d4be3f17d28 | 1,435 | AdventOfKo2022 | Apache License 2.0 |
src/main/kotlin/dayone/DayOne.kt | pauliancu97 | 619,525,509 | false | null | package dayone
import getLines
private fun getElvesCalories(strings: List<String>): List<List<Int>> {
val separatorIndices = listOf(-1) +
strings.withIndex().mapNotNull { (index, string) -> if (string.isEmpty()) index else null } +
listOf(strings.size)
return separatorIndices.zipWithNe... | 0 | Kotlin | 0 | 0 | 78af929252f094a34fe7989984a30724fdb81498 | 1,087 | advent-of-code-2022 | MIT License |
src/Day02.kt | cagriyildirimR | 572,811,424 | false | {"Kotlin": 34697} | import java.io.File
fun day02() {
val input = File("src/Day02.txt").readLines()
val resultTable = mapOf(
"Rock Rock" to 1 + 3,
"Rock Paper" to 2 + 6,
"Rock Scissor" to 3 + 0,
"Paper Rock" to 1 + 0,
"Paper Paper" to 2 + 3,
"Paper Scissor" to 3 + 6,
"Scis... | 0 | Kotlin | 0 | 0 | 343efa0fb8ee76b7b2530269bd986e6171d8bb68 | 1,228 | AoC | Apache License 2.0 |
kotlin/src/main/kotlin/io/github/ocirne/aoc/year2022/Day24.kt | ocirne | 327,578,931 | false | {"Python": 323051, "Kotlin": 67246, "Sage": 5864, "JavaScript": 832, "Shell": 68} | package io.github.ocirne.aoc.year2022
import io.github.ocirne.aoc.AocChallenge
import java.util.*
typealias Position = Pair<Int, Int>
data class MinutePosition(val minute: Int, val x: Int, val y: Int) {
constructor(minute: Int, p: Position) : this(minute, p.first, p.second)
fun position(): Position {
... | 0 | Python | 0 | 1 | b8a06fa4911c5c3c7dff68206c85705e39373d6f | 3,154 | adventofcode | The Unlicense |
src/Day13.kt | LauwiMeara | 572,498,129 | false | {"Kotlin": 109923} | const val OPEN_BRACKET = '['
const val CLOSE_BRACKET = ']'
const val COMMA = ','
const val DIVIDER_PACKET_1 = "[[2]]"
const val DIVIDER_PACKET_2 = "[[6]]"
data class PacketPair (var left: String, var right: String)
fun main() {
fun addBrackets(partPair: String, charIndex: Int): String {
val prev = partPai... | 0 | Kotlin | 0 | 1 | 34b4d4fa7e562551cb892c272fe7ad406a28fb69 | 5,183 | AoC2022 | Apache License 2.0 |
src/Day10.kt | Oktosha | 573,139,677 | false | {"Kotlin": 110908} | import kotlin.math.abs
fun main() {
fun getAnsIncrement(x: Int, op: Int): Int {
assert(op < 260)
if (op >= 20 && (op - 20) % 40 == 0) {
println("$op * $x = ${op * x}")
return op * x
}
return 0
}
fun part1(input: List<String>): Int {
var x = 1... | 0 | Kotlin | 0 | 0 | e53eea61440f7de4f2284eb811d355f2f4a25f8c | 1,405 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2021/day10/day10.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2021.day10
import biz.koziolek.adventofcode.findInput
import java.util.*
import kotlin.reflect.KClass
fun main() {
val inputFile = findInput(object {})
val lines = inputFile.bufferedReader().readLines()
val rootChunks = parseChunks(lines)
println("Corrupted chunk... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 6,655 | advent-of-code | MIT License |
src/main/kotlin/Day4.kt | Mestru | 112,782,719 | false | null | import java.io.File
val letters = "abcdefghijklmnopqrstuvwxyz".toCharArray()
fun main(args: Array<String>) {
// part 1
var numberOfCorrectPassphrases = 0
File("input/day4.txt").forEachLine { line -> run {
if (passphraseIsValid(line)) numberOfCorrectPassphrases++
}
}
println(numberOfCo... | 0 | Kotlin | 0 | 0 | 2cc4211efc7fa32fb951c19d11cb4a452bfeec2c | 1,823 | Advent_of_Code_2017 | MIT License |
src/day17/Day17.kt | easchner | 572,762,654 | false | {"Kotlin": 104604} | package day17
import readInputString
import kotlin.system.measureNanoTime
fun main() {
val rocks = mutableListOf<Array<Pair<Int, Int>>>()
rocks.add(arrayOf(Pair(0, 0), Pair(0, 1), Pair(0, 2), Pair(0, 3)))
rocks.add(arrayOf(Pair(0, 1), Pair(1, 0), Pair(1, 1), Pair(1, 2), Pair(2, 1)))
rocks.add(arrayOf(... | 0 | Kotlin | 0 | 0 | 5966e1a1f385c77958de383f61209ff67ffaf6bf | 7,335 | Advent-Of-Code-2022 | Apache License 2.0 |
Latin_Squares_in_reduced_form/Kotlin/src/Latin.kt | ncoe | 108,064,933 | false | {"D": 425100, "Java": 399306, "Visual Basic .NET": 343987, "C++": 328611, "C#": 289790, "C": 216950, "Kotlin": 162468, "Modula-2": 148295, "Groovy": 146721, "Lua": 139015, "Ruby": 84703, "LLVM": 58530, "Python": 46744, "Scala": 43213, "F#": 21133, "Perl": 13407, "JavaScript": 6729, "CSS": 453, "HTML": 409} | typealias Matrix = MutableList<MutableList<Int>>
fun dList(n: Int, sp: Int): Matrix {
val start = sp - 1 // use 0 basing
val a = generateSequence(0) { it + 1 }.take(n).toMutableList()
a[start] = a[0].also { a[0] = a[start] }
a.subList(1, a.size).sort()
val first = a[1]
// recursive closure pe... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 3,150 | rosetta | MIT License |
src/Day08.kt | sbaumeister | 572,855,566 | false | {"Kotlin": 38905} | fun createTreeMap(input: List<String>): MutableList<List<Int>> {
val treeMap = mutableListOf<List<Int>>()
input.forEach { line ->
val treeHeights = line.toCharArray().map { it.toString().toInt() }
treeMap.add(treeHeights)
}
return treeMap
}
fun isVisibleFromTop(treeMap: MutableList<List... | 0 | Kotlin | 0 | 0 | e3afbe3f4c2dc9ece1da7cf176ae0f8dce872a84 | 4,155 | advent-of-code-2022 | Apache License 2.0 |
src/Day01.kt | MisterTeatime | 561,848,263 | false | {"Kotlin": 20300} |
fun main() {
fun part1(input: List<String>): Int {
return input[0].count{"(".contains(it) } - input[0].count { ")".contains(it) }
}
fun part2(input: List<String>): Int {
var position = -1
var underground = false;
input[0].foldIndexed(0) { index, total, c ->
... | 0 | Kotlin | 0 | 0 | d684bd252a9c6e93106bdd8b6f95a45c9924aed6 | 881 | AoC2015 | Apache License 2.0 |
src/main/problem7/solution.kt | lorenzo-piersante | 515,177,846 | false | {"Kotlin": 15798, "Java": 4893} | package problem7
import java.util.Scanner
import kotlin.math.ceil
import kotlin.math.sqrt
private fun isPrime(n: Int) : Boolean {
val maxDivider = ceil(sqrt(n.toDouble())).toInt()
for (i in 2..maxDivider) {
if (n % i == 0) return false
}
return true
}
val primeNumbers = mutableSetOf(2, 3, 5... | 0 | Kotlin | 0 | 0 | 6159bb49cdfe94310a34edad138de2998352f1c2 | 1,423 | HackerRank-ProjectEuler | MIT License |
src/main/kotlin/g2901_3000/s2940_find_building_where_alice_and_bob_can_meet/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2901_3000.s2940_find_building_where_alice_and_bob_can_meet
// #Hard #Array #Binary_Search #Stack #Heap_Priority_Queue #Monotonic_Stack #Segment_Tree
// #Binary_Indexed_Tree #2024_01_03_Time_928_ms_(90.00%)_Space_84.9_MB_(65.00%)
import java.util.LinkedList
import kotlin.math.max
class Solution {
fun lef... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,773 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/biz/koziolek/adventofcode/year2022/day17/day17.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2022.day17
import biz.koziolek.adventofcode.Coord
import biz.koziolek.adventofcode.findInput
import biz.koziolek.adventofcode.parse2DMap
fun main() {
val jetPattern = findInput(object {}).bufferedReader().readLine()
val chamber = Chamber(width = 7, jetPattern = jetPattern... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 3,702 | advent-of-code | MIT License |
src/main/java/Exercise24-part2.kt | cortinico | 317,667,457 | false | null | fun main() {
val input =
object {}.javaClass.getResource("input-24.txt").readText().split("\n").map {
var idx = 0
val result = mutableListOf<Orient>()
while (idx < it.length) {
val token =
when (it[idx]) {
'e' ->... | 1 | Kotlin | 0 | 4 | a0d980a6253ec210433e2688cfc6df35104aa9df | 3,013 | adventofcode-2020 | MIT License |
src/main/kotlin/me/peckb/aoc/_2017/calendar/day14/Day14.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2017.calendar.day14
import me.peckb.aoc._2017.calendar.day10.Day10
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import java.util.ArrayDeque
class Day14 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
private val day... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 2,536 | advent-of-code | MIT License |
kotlin/src/main/kotlin/com/kodeinc/fireman/WordList.kt | evanjpw | 122,695,712 | false | {"C++": 9282, "Kotlin": 6501, "CMake": 412} | package com.kodeinc.fireman
import org.apache.commons.io.IOUtils
import java.nio.charset.Charset
internal fun makeLengthComparator(reversed: Boolean = false) : Comparator<CharSequence> {
val leftIsLess = if (reversed) 1 else -1
val leftIsGreater = if (reversed) -1 else 1
return Comparator { lhs, rhs ->
... | 0 | C++ | 0 | 0 | ac7444185debb84d7fb608085fa6de15581d8b52 | 3,236 | fireman | The Unlicense |
Chapter05/src/main/kotlin/9_Tail_Recursion.kt | PacktPublishing | 373,735,637 | false | null | tailrec fun sumRec(i: Int, sum: Long, numbers: List<Int>): Long {
return if (i == numbers.size) {
return sum
} else {
sumRec(i + 1, numbers[i] + sum, numbers)
}
}
fun main() {
val numbers = List(1_000_000) { it }
println(sumRec(0, 0, numbers))
val res = mergeSort(numbers.shuf... | 0 | Kotlin | 69 | 216 | e5a0ff239fc98fdde3cc1eb78c66df66907b88d3 | 1,337 | Kotlin-Design-Patterns-and-Best-Practices | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2015/Day19.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2015
import se.saidaspen.aoc.util.Day
fun main() = Day19.run()
object Day19 : Day(2015, 19) {
private var mol = input.lines().last()
val repls = input.lines().map { it.split(" => ") }.dropLast(2)
override fun part1(): Any {
val possibles = mutableListOf<String>()
... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,253 | adventofkotlin | MIT License |
src/Day23.kt | palex65 | 572,937,600 | false | {"Kotlin": 68582} | @file:Suppress("PackageDirectoryMismatch")
package day23
import readInput
import day23.Dir.*
//data class Pos(val row: Int, val col: Int)
class Pos private constructor(private val index: Int) {
val col get() = index % 256 - 50
val row get() = index / 256 - 50
override fun toString() = "($row,$col)"
ov... | 0 | Kotlin | 0 | 2 | 35771fa36a8be9862f050496dba9ae89bea427c5 | 3,403 | aoc2022 | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/linked_list/RemoveDuplicatesFromSortedLinkedListII.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.linked_list
/**
* Given the head of a sorted linked list,
* delete all nodes that have duplicate numbers,
* leaving only distinct numbers from the original list.
* Return the linked list sorted as well.
*
* Input: head = [1 -> 2 -> 3 -> 3 -> 4 -> 4 -> 5]
* Output... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 1,820 | algs4-leprosorium | MIT License |
src/main/aoc2023/Day4.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2023
import kotlin.math.pow
class Day4(input: List<String>) {
private val cards = input.map { line ->
Card(
line.substringAfter(": ").substringBefore(" |").split(" ")
.filter { it.isNotEmpty() }.map { it.toInt() },
line.substringAfter("| ").split(" ").fi... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,094 | aoc | MIT License |
src/main/kotlin/com/github/aoc/AOCD8P2.kt | frikit | 317,914,710 | false | null | package com.github.aoc
import com.github.aoc.utils.InputDay8Problem2
import com.github.aoc.utils.InputParser
fun main() {
val input = InputParser.parseInput(InputDay8Problem2)
.toMutableList()
val wrongIndex = findWrongStatementIndex(input, 0, mutableListOf())
println("Current input is : $input... | 0 | Kotlin | 0 | 0 | 2fca82225a19144bbbca39247ba57c42a30ef459 | 2,760 | aoc2020 | Apache License 2.0 |
HackerRank/MissingNumbers/Iteration1.kt | MahdiDavoodi | 434,677,181 | false | {"Kotlin": 57766, "JavaScript": 17002, "Java": 10647, "HTML": 696, "Python": 683} | fun missingNumbers(arr: Array<Int>, brr: Array<Int>): Set<Int> {
val map = mutableMapOf<Int, Int>()
for (i in brr) map[i] = (map[i] ?: 0) + 1
for (i in arr) {
map[i] = (map[i] ?: 1) - 1
if ((map[i] ?: 0) == 0) map.remove(i)
}
return map.keys.toSortedSet()
}
fun main() {
readLi... | 0 | Kotlin | 0 | 0 | 62a23187efc6299bf921a95c8787d02d5be51742 | 741 | ProblemSolving | MIT License |
src/pl/shockah/aoc/y2015/Day13.kt | Shockah | 159,919,224 | false | null | package pl.shockah.aoc.y2015
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import pl.shockah.aoc.AdventTask
import pl.shockah.aoc.parse4
import java.util.regex.Pattern
class Day13: AdventTask<Map<Pair<String, String>, Int>, Int, Int>(2015, 13) {
private val inputPattern: Pattern = Pattern... | 0 | Kotlin | 0 | 0 | 9abb1e3db1cad329cfe1e3d6deae2d6b7456c785 | 2,829 | Advent-of-Code | Apache License 2.0 |
code/supportLib/src/main/java/it/unipd/stage/sl/lib/rsa/RsaUtils.kt | Kraktun | 391,948,016 | false | {"Java": 189822, "Shell": 12686, "Kotlin": 12043, "HTML": 10394, "Python": 8690, "Batchfile": 3379} | package it.unipd.stage.sl.lib.rsa
import java.math.BigInteger
/*
The following functions come from
https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Key_generation
*/
/**
* @return true is a big integer is probably prime with certainty 15
*/
fun BigInteger.isPrime(): Boolean {
// not 100% correct, but error is... | 0 | Java | 0 | 0 | 28c5739e19eafc0514a0afeab98cb6e5ff3b5d61 | 3,827 | java_web_frameworks_cmp | MIT License |
day02/src/main/kotlin/com/shifteleven/adventofcode2023/day02/App.kt | pope | 733,715,471 | false | {"Kotlin": 3950, "Nix": 1630} | package com.shifteleven.adventofcode2023.day02
import java.io.StreamTokenizer
import java.io.StringReader
import kotlin.assert
import kotlin.math.max
data class Game(val id: Int, val views: List<IntArray>)
fun main() {
val lines = object {}.javaClass.getResourceAsStream("/input.txt")!!.bufferedReader().readLines()
... | 0 | Kotlin | 0 | 0 | cb2862a657d307b5ecd74ebb9c167548b67ba6fc | 2,010 | advent-of-code-2023-kotlin | The Unlicense |
src/Utils.kt | kmakma | 574,238,598 | false | null | import java.io.File
import java.math.BigInteger
import java.security.MessageDigest
import kotlin.math.abs
typealias Vector2D = Coord2D
/**
* Reads lines from the given input txt file.
*/
fun readInput(name: String) = File("src", "$name.txt")
.readLines()
/**
* Read whole input txt file as one string.
*/
fun ... | 0 | Kotlin | 0 | 0 | 950ffbce2149df9a7df3aac9289c9a5b38e29135 | 1,824 | advent-of-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/dev/killjoy/utils/Algorithms.kt | Blad3Mak3r | 295,118,697 | false | {"Kotlin": 269315, "Shell": 3389, "Dockerfile": 345, "Makefile": 123, "Procfile": 63} | /*******************************************************************************
* Copyright (c) 2021. Blademaker
*
* 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.... | 8 | Kotlin | 1 | 8 | f2c202b96aa799e8751c023e42f85a074aed8508 | 4,788 | Killjoy | Apache License 2.0 |
src/Day01/Day01.kt | NST-d | 573,224,214 | false | null | import utils.*
import kotlin.math.max
fun main() {
fun part1(input: List<String>) =
input.fold ( Pair(0,0)) { acc, line ->
var max = acc.first
var sum = acc.second
if ( line.isEmpty() ){
max = max(acc.first, acc.second)
sum = 0
... | 0 | Kotlin | 0 | 0 | c4913b488b8a42c4d7dad94733d35711a9c98992 | 952 | aoc22 | Apache License 2.0 |
advent-of-code-2023/src/main/kotlin/eu/janvdb/aoc2023/day01/day01.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2023.day01
import eu.janvdb.aocutil.kotlin.readLines
//const val FILENAME = "input01-test.txt"
//const val FILENAME = "input01-test2.txt"
const val FILENAME = "input01.txt"
val DIGIT_VALUES_1 = mapOf(
Pair("0", 0),
Pair("1", 1),
Pair("2", 2),
Pair("3", 3),
Pair("4", 4),
Pair("5", 5),
Pair... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,135 | advent-of-code | Apache License 2.0 |
src/Day01.kt | asgerp | 574,417,989 | false | {"Kotlin": 4641} | fun main() {
fun solve(lines: List<String>): List<Int> {
val cals = mutableListOf<Int>()
var currentCal = 0
for (l in lines) {
if (l.isBlank()) {
cals.add(currentCal)
currentCal = 0
} else {
currentCal += l.toInt()
... | 0 | Kotlin | 0 | 0 | e727c834161a6eb6c891a390b644f90599f7adac | 849 | aoc22 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SoupServings.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,630 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ReducingDishes.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,247 | kotlab | Apache License 2.0 |
src/test/kotlin/com/athaydes/samples/cards.kt | renatoathaydes | 84,996,216 | false | null | package com.athaydes.samples
/**
* This is a sample usage of the KUnion library.
*/
import com.athaydes.kunion.Union
import java.util.Collections
enum class Suit
{
Spades, Diamonds, Hearts, Clubs
}
enum class Symbol
{
Ace, Jack, Queen, King
}
typealias Rank = Union.U2<Int, Symbol>
fun rank(number: Int):... | 0 | Kotlin | 4 | 73 | 0bd9cbfe38c1186254f9738e8e25e858a36ddcff | 1,797 | kunion | Apache License 2.0 |
src/main/java/io/deeplay/qlab/data/Normalizer.kt | oQaris | 475,961,305 | false | {"Jupyter Notebook": 766904, "Java": 47993, "Kotlin": 23299} | package io.deeplay.qlab.data
class Normalizer(val context: NormContext) {
companion object {
fun fitMinimax(history: List<FloatArray>, from: Int = 0, to: Int = 1) = Normalizer(
context = buildList {
history.forEachColumn { column ->
val (max, min) = column.... | 0 | Jupyter Notebook | 0 | 0 | 5dd497b74a767c740386dc67e6841673b17b96fb | 2,781 | QLab | MIT License |
dataStructuresAndAlgorithms/src/main/java/dev/funkymuse/datastructuresandalgorithms/trees/binarySearchTree/BinarySearchTree.kt | FunkyMuse | 168,687,007 | false | {"Kotlin": 1728251} | package dev.funkymuse.datastructuresandalgorithms.trees.binarySearchTree
class BinarySearchTree<T : Comparable<T>> {
var root: BinarySearchNode<T>? = null
fun insert(value: T) {
root = insert(root, value)
}
private fun insert(
node: BinarySearchNode<T>?,
value: T
... | 0 | Kotlin | 92 | 771 | e2afb0cc98c92c80ddf2ec1c073d7ae4ecfcb6e1 | 2,478 | KAHelpers | MIT License |
src/leetcode_study_badge/algorithm/Day2.kt | faniabdullah | 382,893,751 | false | null | package leetcode_study_badge.algorithm
class Day2 {
fun sortedSquares(nums: IntArray): IntArray {
var right = nums.size - 1
var left = 0
val resultArray = IntArray(nums.size)
var insertPosition = nums.size - 1
while (left < right) {
val leftValue = nums[left] * ... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,185 | dsa-kotlin | MIT License |
dsalgo/src/commonMain/kotlin/com/nalin/datastructurealgorithm/ds/Graph.kt | nalinchhajer1 | 534,780,196 | false | {"Kotlin": 86359, "Ruby": 1605} | package com.nalin.datastructurealgorithm.ds
import kotlin.math.min
val GRAPH_UNDIRECTED = 1
val GRAPH_DIRECTED = 0
/**
* Graph:
* Create graph in format of Adjacency list. It stores connection for each node internally.
*/
class AdjacencyListGraph<T>(val directionType: Int = GRAPH_DIRECTED) {
val nodes: Mutabl... | 0 | Kotlin | 0 | 0 | eca60301dab981d0139788f61149d091c2c557fd | 12,095 | kotlin-ds-algo | MIT License |
y2020/src/main/kotlin/adventofcode/y2020/Day15.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2020
import adventofcode.io.AdventSolution
fun main() = Day15.solve()
object Day15 : AdventSolution(2020, 15, "Rambunctious Recitation") {
override fun solvePartOne(input: String) = input
.split(',')
.map(String::toInt)
.let { recitation(it, 2020) }
override fun... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 893 | advent-of-code | MIT License |
merge-sort/mergeSort.kt | babangsund | 212,265,663 | false | null | fun <T:Comparable<T>> merge(a: List<T>, b: List<T>): List<T> {
if (a.isEmpty() && b.isNotEmpty()) return b
if (b.isEmpty() && a.isNotEmpty()) return a
val (ah, at) = Pair(a[0], a.drop(1))
val (bh, bt) = Pair(b[0], b.drop(1))
return when {
ah >= bh -> listOf(bh) + merge(a, bt)
else ... | 0 | Kotlin | 0 | 1 | 0f05c412bd6193e4f8449e63c5935316d6dde20b | 733 | sorting-algorithms | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.