path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/main/kotlin/com/leetcode/P447.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package com.leetcode
// https://github.com/antop-dev/algorithm/issues/332
class P447 {
fun numberOfBoomerangs(points: Array<IntArray>): Int {
var answer = 0
for (i in points.indices) {
val map = mutableMapOf<Int, Int>()
for (j in points.indices) {
if (i == j)... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,013 | algorithm | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions29.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
import com.qiaoyuang.algorithm.round1.SingleDirectionNode
fun test29() {
val node1 = SingleDirectionNode(element = 1)
node1.next = node1
printlnResult(node1, 2)
val node2 = SingleDirectionNode(element = 2)
node2.next = node2
printlnResult(node2, 1)
p... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 2,053 | Algorithm | Apache License 2.0 |
src/main/kotlin/g1201_1300/s1297_maximum_number_of_occurrences_of_a_substring/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1201_1300.s1297_maximum_number_of_occurrences_of_a_substring
// #Medium #String #Hash_Table #Sliding_Window
// #2023_06_08_Time_253_ms_(75.00%)_Space_38_MB_(100.00%)
@Suppress("UNUSED_PARAMETER")
class Solution {
fun maxFreq(s: String, max: Int, minSize: Int, maxSize: Int): Int {
// the map of oc... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,892 | LeetCode-in-Kotlin | MIT License |
src/Misc.kt | Flame239 | 570,094,570 | false | {"Kotlin": 60685} | import java.io.File
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.system.measureNanoTime
fun readInput(name: String) = File("input", "$name.txt").readLines()
fun gcd(a: Int, b: Int): Int {
if (b == 0) return a
return gcd(b, a % b)
}
fun lcm(a: Int, b: Int): Int {
ret... | 0 | Kotlin | 0 | 0 | 27f3133e4cd24b33767e18777187f09e1ed3c214 | 944 | advent-of-code-2022 | Apache License 2.0 |
leetcode/src/offer/middle/Offer45.kt | zhangweizhe | 387,808,774 | false | null | package offer.middle
import java.lang.StringBuilder
fun main() {
// 剑指 Offer 45. 把数组排成最小的数
// https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/
println(minNumber(intArrayOf(3,30,34,5,9)))
}
fun minNumber(nums: IntArray): String {
mergeSort(nums, 0, nums.size - 1)
val sb = Str... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,451 | kotlin-study | MIT License |
Kotlin/Corrections/chapitre 3/ProceduresFonctions/src/demo.kt | P-Giraffe | 80,914,727 | false | {"C#": 69509, "Java": 27950, "Swift": 17118, "Kotlin": 9670} | import NePasToucher.readInt
fun main(args: Array<String>) {
ex4()
}
fun ex1() {
pythagore(2.2,5.0)
}
fun pythagore(coteA:Double, coteB:Double) {
val carrehyp = coteA*coteA + coteB*coteB
val hyp = Math.sqrt(carrehyp)
println("L'hypothénuse mesure ${hyp}")
}
fun ex2() {
demandeValeurs(7)
d... | 0 | C# | 0 | 2 | 2df53ce5ec4673e6d3bcc202376d40d3d3a6bdd9 | 2,124 | BasesProgrammation | Apache License 2.0 |
kotlin/day02/deep.kt | aesdeef | 433,698,136 | false | {"Python": 118972, "Elm": 30537, "JavaScript": 6228, "Kotlin": 2090, "HTML": 244} | package day02
import java.io.File
data class Instruction(val command: String, val value: Int)
fun main() {
val instructions = parseInput()
val part1 = solvePart1(instructions)
val part2 = solvePart2(instructions)
println(part1)
println(part2)
}
fun parseInput(): List<Instruction> {
return Fi... | 0 | Python | 0 | 2 | 4561bcf12ac03d360f5b28c48ef80134f97613b9 | 1,231 | advent-of-code-2021 | MIT License |
app/src/main/java/com/github/shannonbay/studybuddy/TextToSSMLConverter.kt | shannonbay | 686,516,365 | false | {"Kotlin": 37122} | package com.github.shannonbay.studybuddy
class TextToSSMLIterator(inputText: String) : Iterator<String> {
private val sentences: List<String> = inputText.split(Regex("[.!?]"))
private var sentenceIndex = 0
private var phraseIndex = 0
private var wordIndex = 0
private var emphasisLevel = 1
over... | 0 | Kotlin | 0 | 0 | 633eb6441cfe5cb602248322cb5fd2f014898194 | 2,628 | study-buddy | MIT License |
src/main/kotlin/g2301_2400/s2318_number_of_distinct_roll_sequences/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2301_2400.s2318_number_of_distinct_roll_sequences
// #Hard #Dynamic_Programming #Memoization #2023_06_30_Time_441_ms_(100.00%)_Space_49.6_MB_(100.00%)
class Solution {
private val memo = Array(10001) { Array(7) { IntArray(7) } }
private val mod = 1000000007
private val m = arrayOf(
intArr... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,032 | LeetCode-in-Kotlin | MIT License |
year2022/src/main/kotlin/net/olegg/aoc/year2022/day19/Day19.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2022.day19
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.Vector4D
import net.olegg.aoc.year2022.DayOf2022
import java.util.PriorityQueue
/**
* See [Year 2022, Day 19](https://adventofcode.com/2022/day/19)
*/
object Day19 : DayOf2022(19) {
private val PATTERN = (
"Bl... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 4,510 | adventofcode | MIT License |
src/test/kotlin/ch/ranil/aoc/aoc2022/Day07.kt | stravag | 572,872,641 | false | {"Kotlin": 234222} | package ch.ranil.aoc.aoc2022
import ch.ranil.aoc.AbstractDay
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
object Day07 : AbstractDay() {
@Test
fun tests() {
assertEquals(95437, compute1(testInput))
assertEquals(1084134, compute1(puzzleInput))
assertEquals(24933642... | 0 | Kotlin | 1 | 0 | dbd25877071cbb015f8da161afb30cf1968249a8 | 2,115 | aoc | Apache License 2.0 |
src/Day02.kt | realpacific | 573,561,400 | false | {"Kotlin": 59236} | fun main() {
fun part1(input: List<String>): Int {
var totalScores = 0
input.forEach { line ->
val (opponentMove, myMove) = line.split(" ")
when (myMove) {
"X" -> totalScores += 1
"Y" -> totalScores += 2
"Z" -> totalScores += 3
... | 0 | Kotlin | 0 | 0 | f365d78d381ac3d864cc402c6eb9c0017ce76b8d | 2,222 | advent-of-code-2022 | Apache License 2.0 |
Kotlin/min_number_of_1.kt | manan025 | 412,155,744 | false | null | import java.lang.Integer.min
import java.util.*
/*
KOTLIN PROGRAM TO FIND THE ROWS WITH MINIMUM NUMBER OF 1s
INPUT FORMAT :
number of rows and number of column
||THE ARRAY ||
OUTPUT FORMAT:
ith row which has the least number of 1s
the elements of row which has the least number of 1s
INPUT:
5 4
1 1 1 2
1 1 5 2
0 0 1 1
... | 115 | Java | 89 | 26 | c185dcedc449c7e4f6aa5e0d8989589ef60b9565 | 1,743 | DS-Algo-Zone | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year15/Day11.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year15
import com.grappenmaker.aoc.PuzzleSet
import kotlin.math.abs
fun PuzzleSet.day11() = puzzle {
val password = input.trim().map { it.digitCode }
val (first, second) = generateSequence(password) { it.nextPassword() }
.filter { it.isValid() }.map { pwd -> pwd.joinToStri... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,835 | advent-of-code | The Unlicense |
src/main/kotlin/com/jacobhyphenated/advent2023/day22/Day22.kt | jacobhyphenated | 725,928,124 | false | {"Kotlin": 121644} | package com.jacobhyphenated.advent2023.day22
import com.jacobhyphenated.advent2023.Day
import kotlin.math.max
import kotlin.math.min
/**
* Day 22: Sand Slabs
*
* Blocks of sand are falling and represented by the puzzle input.
* Each line has two 3d coordinates that describe n number of 1 cube sections of sand tha... | 0 | Kotlin | 0 | 0 | 90d8a95bf35cae5a88e8daf2cfc062a104fe08c1 | 5,536 | advent2023 | The Unlicense |
kotlin/10.kt | NeonMika | 433,743,141 | false | {"Kotlin": 68645} | class Day10 : Day<List<List<Char>>>("10") {
val pairs = mapOf(
')' to '(',
']' to '[',
'}' to '{',
'>' to '<'
)
val corruptedCost = mapOf(
')' to 3L,
']' to 57L,
'}' to 1197L,
'>' to 25137L
)
val invalidCost = mapOf(
'(' to 1,... | 0 | Kotlin | 0 | 0 | c625d684147395fc2b347f5bc82476668da98b31 | 1,858 | advent-of-code-2021 | MIT License |
src/main/kotlin/com/ginsberg/advent2020/Day04.kt | tginsberg | 315,060,137 | false | null | /*
* Copyright (c) 2020 by <NAME>
*/
/**
* Advent of Code 2020, Day 4 - Passport Processing
* Problem Description: http://adventofcode.com/2020/day/4
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2020/day4/
*/
package com.ginsberg.advent2020
class Day04(input: String) {
private val ... | 0 | Kotlin | 2 | 38 | 75766e961f3c18c5e392b4c32bc9a935c3e6862b | 1,189 | advent-2020-kotlin | Apache License 2.0 |
aoc2022/aoc2022-kotlin/src/main/kotlin/de/havox_design/aoc2022/day15/BeaconExclusionZone.kt | Gentleman1983 | 737,309,232 | false | {"Kotlin": 342004, "Scala": 9632} | package de.havox_design.aoc2022.day15
class BeaconExclusionZone(private var filename: String) {
private val data = readFile()
fun processPart1(desiredRow: Int): Int =
data.mapNotNull { it.findRange(desiredRow) }
.reduce()
.sumOf { it.last - it.first }
fun processPart2(cave... | 4 | Kotlin | 0 | 1 | b94716fbc95f18e68774eb99069c0b703875615c | 2,718 | aoc2022 | Apache License 2.0 |
src/main/kotlin/day1/RocketEquation.kt | jabrena | 226,094,749 | false | null | package day1
import kotlin.math.floor
/**
*
* --- 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 Chr... | 1 | Kotlin | 0 | 0 | 60f2e4143a0a69097235ccb623079a0f19150681 | 2,581 | advent-of-code-2019 | Apache License 2.0 |
src/main/kotlin/days/Day04.kt | TheMrMilchmann | 433,608,462 | false | {"Kotlin": 94737} | /*
* Copyright (c) 2021 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, dis... | 0 | Kotlin | 0 | 1 | dfc91afab12d6dad01de552a77fc22a83237c21d | 4,862 | AdventOfCode2021 | MIT License |
src/Day16.kt | anilkishore | 573,688,256 | false | {"Kotlin": 27023} | class Valve(val id: String, val flowRate: Int = 0, val edges: List<String> = listOf())
fun main() {
val input = readInput("Day16")
val valves = input.map { inp ->
val ss = inp.split(";")
val s1 = ss[0].split(" ")
val rate = ss[0].split("=")[1].toInt()
val edges = ss[1].split(",... | 0 | Kotlin | 0 | 0 | f8f989fa400c2fac42a5eb3b0aa99d0c01bc08a9 | 1,027 | AOC-2022 | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/adjust_salaries/AdjustSalaries.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.adjust_salaries
import datsok.shouldEqual
import org.junit.Test
/**
* Give an array of salaries. The total salary has a budget.
* At the beginning, the total salary of employees is larger than the budget.
* It is required to find the number k, and reduce all the salaries larger than k... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,645 | katas | The Unlicense |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day17.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 Day17 : Day<Int> {
companion object {
private const val PRINT_DEBUG = false
}
private data class Point4D(val x: Int, val y: Int, val z: Int, val w: Int)
private data clas... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 5,021 | adventofcode | Apache License 2.0 |
src/algorithms/sorter/merge/Main.kt | bdatdo0601 | 130,766,362 | false | null | package algorithms.sorter.merge
import algorithms.sorter.utils.Element
import algorithms.sorter.utils.SortAlgorithmEnum
import algorithms.sorter.insertion.insertionSorter
object MergeSortTester {
private class ExampleElement(override val value: Number) : Element {
override fun toString(): String {
... | 0 | Kotlin | 0 | 0 | 0d320f800a2fa6fb96a193d0bbf9eb2beb42a1c3 | 6,335 | project-bunny | MIT License |
src/main/kotlin/g2001_2100/s2056_number_of_valid_move_combinations_on_chessboard/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2056_number_of_valid_move_combinations_on_chessboard
// #Hard #Array #String #Simulation #Backtracking
// #2023_06_25_Time_600_ms_(100.00%)_Space_44.1_MB_(100.00%)
class Solution {
// 0: rook, queen, bishop
private val dirs = arrayOf(
arrayOf(intArrayOf(-1, 0), intArrayOf(1, 0), in... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 3,589 | LeetCode-in-Kotlin | MIT License |
leetcode-75-kotlin/src/main/kotlin/RemovingStarsFromAString.kt | Codextor | 751,507,040 | false | {"Kotlin": 49566} | /**
* You are given a string s, which contains stars *.
*
* In one operation, you can:
*
* Choose a star in s.
* Remove the closest non-star character to its left, as well as remove the star itself.
* Return the string after all stars have been removed.
*
* Note:
*
* The input will be generated such that the... | 0 | Kotlin | 0 | 0 | 0511a831aeee96e1bed3b18550be87a9110c36cb | 1,515 | leetcode-75 | Apache License 2.0 |
src/Day01.kt | maquirag | 576,698,073 | false | {"Kotlin": 3883} | fun main() {
val day = "01"
fun countBags(input: List<String>): List<Int> = sequence {
var total = 0
input.forEach {
if (it.isBlank()) {
yield(total)
total = 0
} else {
total += it.toInt()
}
}
yi... | 0 | Kotlin | 0 | 0 | 23403172e909f8fb0c87e953d06fc0921c75fc32 | 885 | aoc2022-kotlin | Apache License 2.0 |
src/test/kotlin/leetcode/mock/MockInterviews.kt | Magdi | 390,731,717 | false | null | package leetcode
import org.junit.Test
import org.junit.Assert.*
import java.util.*
import kotlin.collections.HashMap
import kotlin.collections.HashSet
class MockInterviews1Test {
@Test
fun `test case 1`() {
assertEquals("", MockSolution1().removeDuplicates("aa"))
assertEquals("a", MockSoluti... | 0 | Kotlin | 0 | 0 | 63bc711dc8756735f210a71454144dd033e8927d | 4,448 | ProblemSolving | Apache License 2.0 |
kotlin/src/main/kotlin/adventofcode/day8/Day8_2.kt | thelastnode | 160,586,229 | false | null | package adventofcode.day8
import java.io.File
import java.util.*
object Day8_2 {
fun parse(line: String): List<Int> {
return Scanner(line).asSequence().map { it.toInt(10) }.toList()
}
private fun <T> MutableList<T>.pop(n: Int): List<T> {
val res = this.take(n)
(0 until n).forEach ... | 0 | Kotlin | 0 | 0 | 8c9a3e5a9c8b9dd49eedf274075c28d1ebe9f6fa | 1,359 | adventofcode | MIT License |
advent2022/src/main/kotlin/year2022/Day13.kt | bulldog98 | 572,838,866 | false | {"Kotlin": 132847} | package year2022
import AdventDay
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
sealed class Elem : Comparable<Elem>
data class ListElem(val elem: List<Elem>) : Elem() {
override fun ... | 0 | Kotlin | 0 | 0 | 02ce17f15aa78e953a480f1de7aa4821b55b8977 | 2,451 | advent-of-code | Apache License 2.0 |
src/Day10.kt | acunap | 573,116,784 | false | {"Kotlin": 23918} | import kotlin.math.max
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
@OptIn(ExperimentalTime::class)
fun main() {
fun part1(input: List<String>) : Int {
val markedCycleIndexes = listOf(20, 60, 100, 140, 180, 220)
var cyclesIndex = 1
var signalStrength = 1
var ac... | 0 | Kotlin | 0 | 0 | f06f9b409885dd0df78f16dcc1e9a3e90151abe1 | 2,739 | advent-of-code-2022 | Apache License 2.0 |
src/Day01.kt | mr-cell | 575,589,839 | false | {"Kotlin": 17585} | fun main() {
fun parseInput(input: List<String>): List<Int> =
input.fold(mutableListOf(mutableListOf<Int>())) { acc, i ->
if (i == "") acc.add(mutableListOf())
else acc.last().add(i.toInt())
acc
}
.map { it.sum() }
.sortedDescending()
... | 0 | Kotlin | 0 | 0 | 2528bf0f72bcdbe7c13b6a1a71e3d7fe1e81e7c9 | 847 | advent-of-code-2022 | Apache License 2.0 |
app/src/main/java/com/cristianovecchi/mikrokanon/dataAnalysis/Kmeans.kt | CristianoVecchi | 358,026,092 | false | null | package com.cristianovecchi.mikrokanon.dataAnalysis
// version 1.2.21
import java.util.Random
import kotlin.math.*
data class Point(var x: Double, var y: Double, var group: Int, val partIndex: Int, val noteIndex: Int)
typealias LPoint = List<Point>
typealias MLPoint = MutableList<Point>
val origin get() = Point(0.... | 0 | Kotlin | 0 | 4 | 291915e53e98603f2fe14154dbdd445187649b67 | 5,158 | MikroKanon | MIT License |
séance 1 et 2 _ classe et objet/correction/Complexe.kt | strouilhet | 683,668,398 | false | {"Kotlin": 11285} | import kotlin.math.PI
import kotlin.math.atan
import kotlin.math.round
import kotlin.math.sqrt
class Complexe(val reel: Double = 0.0, val im: Double = 0.0) {
constructor(c: Complexe) : this(c.reel, c.im)
fun module(): Double = sqrt(reel * reel + im * im)
fun argument(): Double =
if (reel == 0.0)... | 0 | Kotlin | 0 | 0 | f779bf1e69f9666da225866aca777252438953a1 | 1,869 | KeepCalmAndCode3 | MIT License |
2021/src/day06/Solution.kt | vadimsemenov | 437,677,116 | false | {"Kotlin": 56211, "Rust": 37295} | package day06
import java.nio.file.Files
import java.nio.file.Paths
fun main() {
val mem = Array(2) {
Array(9) {
LongArray(257) { -1 }
}
}
fun model(daysLeft: Int, day: Int, part: Int): Long {
require(daysLeft in 0..8)
require(part in 0..1)
val lastDay = if (part == 0) 80 else 256
r... | 0 | Kotlin | 0 | 0 | 8f31d39d1a94c862f88278f22430e620b424bd68 | 1,248 | advent-of-code | Apache License 2.0 |
src/kotlin/kt_101/Lambdas_111.kt | iJKENNEDY | 343,256,517 | false | null | package kt_101
class Lambdas_111 {
fun iterando_lambdas(){
// val values = listOf(1,3,4,6,7,8,9,13,23,59,50)
// values.forEach{
// println("$it: ${it*it}")
// }
println()
var prices = listOf(1.3,4.94,99.95,55.49)
val largePrices = prices.filter {
... | 0 | Kotlin | 0 | 0 | 08f08f782264b0f173eea4dc235aebe4492e4536 | 2,046 | kotlin_code_101 | MIT License |
src/main/kotlin/day17.kt | Arch-vile | 572,557,390 | false | {"Kotlin": 132454} | package day17
import aoc.utils.*
import kotlin.text.toList
data class Shape(val blocks: List<Cursor>) {
fun isFalling(stationary: List<Shape>): Boolean {
val intersect = stationary.flatMap { it.blocks }.intersect(this.blocks.toSet())
return intersect.isEmpty()
}
fun move(move: Cursor, st... | 0 | Kotlin | 0 | 0 | e737bf3112e97b2221403fef6f77e994f331b7e9 | 5,681 | adventOfCode2022 | Apache License 2.0 |
src/Day01.kt | cypressious | 572,916,585 | false | {"Kotlin": 40281} | fun main() {
fun part1(input: List<String>): Int {
return input.map { it.toInt() }.windowed(2, 1).count { (a, b) -> b > a }
}
fun part2(input: List<String>): Int {
return input
.asSequence()
.map { it.toInt() }
.windowed(3, 1)
.map { it.sum() ... | 0 | Kotlin | 0 | 0 | 169fb9307a34b56c39578e3ee2cca038802bc046 | 669 | AdventOfCode2021 | Apache License 2.0 |
src/2021/Day17_1.kts | Ozsie | 318,802,874 | false | {"Kotlin": 99344, "Python": 1723, "Shell": 975} | import java.io.File
import kotlin.math.absoluteValue
import kotlin.math.max
File("input/2021/day17").forEachLine { line ->
val (xTarget, yTarget) = line.substring(13).split(", ")
val (xMin, xMax) = xTarget.substring(2).split("..").map { it.toInt() }.sortedBy { it }
val (yMin, yMax) = yTarget.substring(2).s... | 0 | Kotlin | 0 | 0 | d938da57785d35fdaba62269cffc7487de67ac0a | 1,932 | adventofcode | MIT License |
src/main/kotlin/day1.kt | tianyu | 574,561,581 | false | {"Kotlin": 49942} | private fun main() {
part1("The elf carrying the most calories has:") {
calories().max()
}
part2("The three elves carrying the most calories has:") {
calories().top(3).sum()
}
}
private fun calories() = sequence {
withInputLines("day1.txt") {
var calories = 0
val inventory = iterator()
w... | 0 | Kotlin | 0 | 0 | 6144cc0ccf1a51ba2e28c9f38ae4e6dd4c0dc1ea | 750 | AdventOfCode2022 | MIT License |
advent-of-code-2023/src/test/kotlin/Day9Test.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | import io.kotest.matchers.collections.shouldContainAll
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
class Day9Test {
private val testInput =
"""
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45
"""
.trimIndent()
@Test
fun `sil... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 1,776 | advent-of-code | MIT License |
src/main/kotlin/utils/AlgorithmAStar.kt | joakimgy | 347,076,060 | false | null | package utils
interface Graph {
interface Vertex
interface Edge<T : Vertex> {
val a: T
val b: T
}
}
abstract class AlgorithmAStar<V : Graph.Vertex, E : Graph.Edge<V>>(
private val edges: List<E>
) : Graph {
private val V.neighbors: List<V>
get() = edges
.asSeque... | 0 | Kotlin | 0 | 0 | 0d6915b4c7ffde4ba2024584fab4b9b16b719d9a | 3,283 | tower-defence | MIT License |
src/main/kotlin/de/pgebert/aoc/days/Day08.kt | pgebert | 724,032,034 | false | {"Kotlin": 65831} | package de.pgebert.aoc.days
import de.pgebert.aoc.Day
import de.pgebert.aoc.utils.lcm
class Day08(input: String? = null) : Day(8, "Haunted Wasteland", input) {
private val nodeRegex = "(\\S+) = \\((\\S+), (\\S+)\\)".toRegex()
override fun partOne(): Int {
val (instructions, nodes) = parseInput()
... | 0 | Kotlin | 1 | 0 | a30d3987f1976889b8d143f0843bbf95ff51bad2 | 1,726 | advent-of-code-2023 | MIT License |
src/main/aoc2015/Day12.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2015
import java.util.*
class Day12(val input: String) {
fun solvePart1(): Int {
return input.split(',', ':', '[', ']', '{', '}').mapNotNull { it.toIntOrNull() }.sum()
}
private data class Node(var sum: Int = 0, var red: Boolean = false, val children: MutableList<Node> = mutableListOf... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,589 | aoc | MIT License |
src/main/kotlin/adventofcode2023/day20/day20.kt | dzkoirn | 725,682,258 | false | {"Kotlin": 133478} | package adventofcode2023.day20
import adventofcode2023.day8.findLCM
import adventofcode2023.readInput
import java.util.LinkedList
import java.util.Queue
import kotlin.time.measureTime
data class Signal(
val level: SignalLevel,
val source: String,
val destination: String
) {
enum class SignalLevel {
... | 0 | Kotlin | 0 | 0 | 8f248fcdcd84176ab0875969822b3f2b02d8dea6 | 5,220 | adventofcode2023 | MIT License |
src/week4/FindWords.kt | anesabml | 268,056,512 | false | null | package week4
class FindWords {
fun findWords(board: Array<CharArray>, words: Array<String>): List<String> {
val result = mutableListOf<String>()
val root = buildTrie(words)
for (i in board.indices) {
for (j in board[0].indices) {
dfs(board, root, result, i, j)
... | 0 | Kotlin | 0 | 1 | a7734672f5fcbdb3321e2993e64227fb49ec73e8 | 1,574 | leetCode | Apache License 2.0 |
src/main/kotlin/graph/core/TopoSort.kt | yx-z | 106,589,674 | false | null | package graph.core
import graph.core.Status.*
import util.OneArray
import util.toOneArray
// topological sort of a directed acyclic graph (dag)
fun <V> Graph<V>.topoSort(checkIdentity: Boolean = true): OneArray<Vertex<V>> {
val sorted = ArrayList<Vertex<V>>()
val status = HashMap<Vertex<V>, Status>()
vertices.fo... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 1,774 | AlgoKt | MIT License |
src/main/kotlin/space/d_lowl/kglsm/problem/MAXSAT.kt | d-lowl | 300,622,439 | false | null | package space.d_lowl.kglsm.problem
import kotlin.random.Random
data class SATLiteral(val index: Int, val negated: Boolean) {
override fun toString(): String = "${if (negated) "¬" else ""}x$index"
}
class SATClause(private val literals: Array<SATLiteral>) {
private val maxIndex = literals.map { it.index }.max... | 17 | Kotlin | 0 | 1 | 0886e814be75a77fa8f33faa867329aef19085a5 | 1,351 | kGLSM | MIT License |
src/main/kotlin/de/nosswald/aoc/days/Day06.kt | 7rebux | 722,943,964 | false | {"Kotlin": 34890} | package de.nosswald.aoc.days
import de.nosswald.aoc.Day
// https://adventofcode.com/2023/day/6
object Day06 : Day<Int>(6, "Wait For It") {
override fun partOne(input: List<String>): Int {
val (times, records) = input.map { line ->
line
.split(":")
.last()
... | 0 | Kotlin | 0 | 1 | 398fb9873cceecb2496c79c7adf792bb41ea85d7 | 1,376 | advent-of-code-2023 | MIT License |
src/main/kotlin/Problem32.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | @file:Suppress("MagicNumber")
/**
* Pandigital products
*
* We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example,
* the 5-digit number, 15234, is 1 through 5 pandigital.
*
* The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing m... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 1,600 | project-euler | MIT License |
src/Day12.kt | hijst | 572,885,261 | false | {"Kotlin": 26466} | import java.util.Queue
import java.util.LinkedList
fun main() {
data class Cell(val row: Int, val col: Int, var depth: Int = 0)
fun IntGrid.findFirstIndex(value: Int): Cell =
rows.indexOfFirst { it.contains(value) }.let {
Cell(
it ,
it.let { row -> rows[row]... | 0 | Kotlin | 0 | 0 | 2258fd315b8933642964c3ca4848c0658174a0a5 | 4,426 | AoC-2022 | Apache License 2.0 |
ceria/02/src/main/kotlin/Solution.kt | VisionistInc | 317,503,410 | false | null | import java.io.File;
fun main(args : Array<String>) {
val input = File(args.first()).readLines()
println("Solution 1: ${solution1(input)}")
println("Solution 2: ${solution2(input)}")
}
private fun solution1(input: List<String>) :Int {
var validPasswordIndexes = mutableListOf<Int>()
input.forEach... | 0 | Rust | 0 | 0 | 002734670384aa02ca122086035f45dfb2ea9949 | 1,343 | advent-of-code-2020 | MIT License |
src/Day13.kt | lsimeonov | 572,929,910 | false | {"Kotlin": 66434} | import readInput
import java.lang.Integer.max
interface JsonValue : Comparable<JsonValue> {
fun equals(other: JsonValue): Boolean
override operator fun compareTo(other: JsonValue): Int
companion object {
fun parse(input: String): JsonValue {
val trimmed = input.trim()
retu... | 0 | Kotlin | 0 | 0 | 9d41342f355b8ed05c56c3d7faf20f54adaa92f1 | 5,010 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day05/Day05.kt | dustinconrad | 572,737,903 | false | {"Kotlin": 100547} | package day05
import byEmptyLines
import readResourceAsBufferedReader
fun main() {
println("part 1: ${part1(readResourceAsBufferedReader("5_1.txt").readLines())}")
println("part 2: ${part2(readResourceAsBufferedReader("5_1.txt").readLines())}")
}
fun part1(input: List<String>): String {
return solve(inpu... | 0 | Kotlin | 0 | 0 | 1dae6d2790d7605ac3643356b207b36a34ad38be | 2,483 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/graph/dijkstra/Dijkstra.kt | Mw-majo | 499,332,924 | false | {"Kotlin": 10226} | package graph.dijkstra
class Dijkstra() {
private val ansList: List<List<List<Int>>>
private val shortestPathCosts = mutableListOf<Map<Int, Int>>()
private val edges: List<List<Int>>
private val nodeNumber: Int
private val id: IntRange
private val graphData: Array<Array<Int>>
private val n... | 0 | Kotlin | 0 | 0 | 879af69c9e7d03517ee5b81f3d0ae1bd188ec467 | 4,139 | dijkstara | Apache License 2.0 |
src/main/kotlin/days/Day07.kt | julia-kim | 435,257,054 | false | {"Kotlin": 15771} | package days
import readInput
import kotlin.math.absoluteValue
fun main() {
fun part1(input: List<String>): Int {
val horizontalPositions = input[0].split(",").map { it.toInt() }
val outcomes: MutableList<Int> = mutableListOf()
horizontalPositions.forEach { pos ->
var totalFuel... | 0 | Kotlin | 0 | 0 | 5febe0d5b9464738f9a7523c0e1d21bd992b9302 | 1,410 | advent-of-code-2021 | Apache License 2.0 |
2020/src/year2020/day03/Day03.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2020.day03
import util.readAllLines
private fun findTrees(dx: Int, dy: Int): Int {
val input = readAllLines("input.txt")
val height = input.size
val width = input[0].length
val matrix: Array<MutableList<Char>> = Array(height) { mutableListOf<Char>() }
for (i in 0 until height) {
... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 936 | adventofcode | MIT License |
advent-of-code2015/src/main/kotlin/utils.kt | REDNBLACK | 128,669,137 | false | null | import java.math.BigInteger
import java.security.MessageDigest
fun parseInput(file: String): String {
return Thread.currentThread()
.contextClassLoader
.getResourceAsStream(file)
.bufferedReader()
.use { it.readText() }
.trim()
}
fun Iterable<Int>.mul() ... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 2,354 | courses | MIT License |
src/main/kotlin/day20.kt | gautemo | 725,273,259 | false | {"Kotlin": 79259} | import shared.*
fun main() {
val input = Input.day(20)
println(day20A(input))
println(day20B(input))
}
fun day20A(input: Input): Int {
val modules = createModules(input)
val broadcaster = modules.first { it is Broadcaster }
repeat(1000) {
broadcaster.pulse(false, "aptly")
while... | 0 | Kotlin | 0 | 0 | 6862b6d7429b09f2a1d29aaf3c0cd544b779ed25 | 3,729 | AdventOfCode2023 | MIT License |
src/Day01.kt | orirabi | 574,124,632 | false | {"Kotlin": 14153} | fun main() {
fun getMaxCalories(input: List<String>): Int {
var highest = 1 to 0
var current = 1
var currentSum = 0
input.forEach {
if (it.isBlank()) {
if (currentSum > highest.second) {
highest = current to currentSum
}... | 0 | Kotlin | 0 | 0 | 41cb10eac3234ae77ed7f3c7a1f39c2f9d8c777a | 1,068 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2015/Day24.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2015
import se.saidaspen.aoc.util.Day
import se.saidaspen.aoc.util.ints
import se.saidaspen.aoc.util.words
import java.util.*
fun main() {
Day24.run()
}
object Day24 : Day(2015, 24) {
inline fun <reified T> combinations(arr: Array<T>, m: Int) = sequence {
val n = arr.size... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,593 | adventofkotlin | MIT License |
src/main/kotlin/com/sk/topicWise/tree/124. Binary Tree Maximum Path Sum.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.topicWise.tree
class Solution124 {
/**
* Traverse the tree and while backtrack, maintain mas_so_far at every node, return max passing through
* current node. We need to return values for first 3 cases from below, 4th case will be considered
* in max_so_far
*
* For each node ... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,511 | leetcode-kotlin | Apache License 2.0 |
Fermat_numbers/Kotlin/src/FermatNumbers.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} | import java.math.BigInteger
import kotlin.math.pow
fun main() {
println("First 10 Fermat numbers:")
for (i in 0..9) {
println("F[$i] = ${fermat(i)}")
}
println()
println("First 12 Fermat numbers factored:")
for (i in 0..12) {
println("F[$i] = ${getString(getFactors(i, fermat(i))... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 3,505 | rosetta | MIT License |
generator/api/src/commonMain/kotlin/com/github/jcornaz/kwik/generator/api/GeneratorCombination.kt | mmiikkkkaa | 391,233,716 | true | {"Kotlin": 137409} | package com.github.jcornaz.kwik.generator.api
import kotlin.random.Random
/**
* Returns a generator of values built from the elements of `this` generator and the [other] generator
* using the provided [transform] function applied to each pair of elements.
*/
fun <A, B, R> Generator<A>.combineWith(
other: Gener... | 0 | Kotlin | 0 | 0 | b25753bac300e410cff143bf079b55bd79d193dd | 5,013 | kwik | Apache License 2.0 |
kotlin/0778-swim-in-rising-water.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | class Solution {
fun swimInWater(grid: Array<IntArray>): Int {
val visited = Array<BooleanArray>(grid.size){ BooleanArray(grid[0].size) }
val minHeap = PriorityQueue<IntArray>{ a: IntArray, b: IntArray -> a[0] - b[0] } //[height, r, c]
val directions = arrayOf(intArrayOf(1,-1,0,0),intArrayOf... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,110 | leetcode | MIT License |
src/main/aoc2016/Day3.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2016
class Day3(private val input: List<String>) {
private data class Shape(val x: Int, val y: Int, val z: Int)
private fun process(input: List<String>): List<Shape> {
val shapes = mutableListOf<Shape>()
input.forEach { line ->
val entry = line.trim().split(" ").filter {... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,461 | aoc | MIT License |
src/Day08.kt | k3vonk | 573,555,443 | false | {"Kotlin": 17347} | fun main() {
fun <E: Any> printPrettyGrid(grid: MutableList<MutableList<E>>) {
println()
grid.forEach {
println(it)
}
}
fun parseInputIntoGrid(input: List<String>, grid: MutableList<MutableList<Char>>) {
input.forEach {
grid.add(it.toMutableList())
... | 0 | Kotlin | 0 | 1 | 68a42c5b8d67442524b40c0ce2e132898683da61 | 5,473 | AOC-2022-in-Kotlin | Apache License 2.0 |
src/main/kotlin/days/Day12.kt | andilau | 433,504,283 | false | {"Kotlin": 137815} | package days
@AdventOfCodePuzzle(
name = "Passage Pathing",
url = "https://adventofcode.com/2021/day/12",
date = Date(day = 12, year = 2021)
)
class Day12(val input: List<String>) : Puzzle {
private val links = input.parseInput()
override fun partOne() =
links.generatePaths { path, next ->... | 0 | Kotlin | 0 | 0 | b3f06a73e7d9d207ee3051879b83e92b049a0304 | 2,316 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
openrndr-math/src/commonMain/kotlin/org/openrndr/math/Bezier.kt | openrndr | 122,222,767 | false | {"Kotlin": 2343473, "ANTLR": 9333, "GLSL": 2677, "CSS": 87} | package org.openrndr.math
import kotlin.math.sqrt
/* quadratic bezier */
fun bezier(x0: Double, c0: Double, x1: Double, t: Double): Double {
val it = 1.0 - t
val it2 = it * it
val t2 = t * t
return it2 * x0 + 2.0 * it * t * c0 + t2 * x1
}
fun derivative(x0: Double, c0: Double, x1: Double, t: Double)... | 34 | Kotlin | 71 | 808 | 7707b957f1c32d45f2fbff6b6a95a1a2da028493 | 6,075 | openrndr | BSD 2-Clause FreeBSD License |
src/main/kotlin/aoc2017/KnotHash.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2017
import komu.adventofcode.utils.octetsToHex
import komu.adventofcode.utils.swap
fun knotHash(input: String): String {
val lengths = lengthsFromAscii(input)
val sparseHash = knotHashArray(lengths, rounds = 64)
return denseHash(sparseHash)
}
fun knotHashChecksum(lengths: L... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 1,349 | advent-of-code | MIT License |
src/advent/of/code/SeventhPuzzle.kt | 1nco | 725,911,911 | false | {"Kotlin": 112713, "Shell": 103} | package advent.of.code
import java.util.*
class SeventhPuzzle {
companion object {
private val day = "7";
private var input: MutableList<String> = arrayListOf();
private var result = 0L;
private var resultSecond = 0L;
var hands = mutableListOf<Hand>();
var char... | 0 | Kotlin | 0 | 0 | 0dffdeba1ebe0b44d24f94895f16f0f21ac8b7a3 | 4,768 | advent-of-code | Apache License 2.0 |
src/array/LeetCode295.kt | Alex-Linrk | 180,918,573 | false | null | package array
import kotlin.math.min
/**
* 数据流的中位数
* 中位数是有序列表中间的数。如果列表长度是偶数,中位数则是中间两个数的平均值。
*
*例如,
*
*[2,3,4] 的中位数是 3
*
*[2,3] 的中位数是 (2 + 3) / 2 = 2.5
*
*设计一个支持以下两种操作的数据结构:
*
*void addNum(int num) - 从数据流中添加一个整数到数据结构中。
*double findMedian() - 返回目前所有元素的中位数。
*示例:
*
*addNum(1)
*addNum(2)
*findMedian() ->... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 2,081 | LeetCode | Apache License 2.0 |
src/main/kotlin/de/lostmekka/raymarcher/Point.kt | LostMekka | 166,667,888 | false | null | package de.lostmekka.raymarcher
import kotlin.math.abs
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
data class Point(val x: Double, val y: Double, val z: Double) {
constructor(x: Number, y: Number, z: Number) : this(x.toDouble(), y.toDouble(), z.toDouble())
val length by lazy { sqrt(... | 0 | Kotlin | 0 | 0 | ee4232112b2341901a32fa8378687cae3aab0c8d | 2,886 | ray-marcher-kt | MIT License |
src/test/kotlin/days/y2022/Day02Test.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2022
import days.Day
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.Is.`is`
import org.junit.jupiter.api.Test
class Day02Test {
@Test
fun testExampleOne() {
assertThat(
Day02().partOne(
"""
A Y
B X
... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 2,941 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/shtanko/algorithms/leetcode/RangeAddition.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,170 | kotlab | Apache License 2.0 |
src/main/kotlin/d13/d13.kt | LaurentJeanpierre1 | 573,454,829 | false | {"Kotlin": 118105} | package d13
import readInput
import java.lang.IllegalStateException
sealed class Item : Comparable<Item>
class ItemList(val list: List<Item>) : Item() {
/**
* Compares this object with the specified object for order. Returns zero if this object is equal
* to the specified [other] object, a negative numb... | 0 | Kotlin | 0 | 0 | 5cf6b2142df6082ddd7d94f2dbde037f1fe0508f | 3,829 | aoc2022 | Creative Commons Zero v1.0 Universal |
baparker/04/main.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File
import kotlin.collections.mutableListOf
var numberList: List<String> = mutableListOf()
var boardList: MutableList<MutableList<String>> = mutableListOf()
val BOARD_SIZE = 5
fun getNumbersAndBoards() {
var lineIndex = 0
var boardIndex = -1
File("input.txt").forEachLine {
if (line... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 2,934 | advent-of-code-2021 | MIT License |
kotlin/2251-number-of-flowers-in-full-bloom.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | // two heaps
class Solution {
fun fullBloomFlowers(flowers: Array<IntArray>, _people: IntArray): IntArray {
val people = _people.mapIndexed { i, p -> p to i }.sortedBy { it.first }
val res = IntArray (_people.size)
var count = 0
val start = PriorityQueue<Int>()
val end = Prio... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,435 | leetcode | MIT License |
src/main/kotlin/com/nibado/projects/advent/y2018/Day11.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2018
import com.nibado.projects.advent.Day
import com.nibado.projects.advent.Point
import com.nibado.projects.advent.collect.SummedAreaTable
import kotlin.math.min
object Day11 : Day {
private val grid = Grid(6392)
class Grid(serial: Int) {
private val grid = IntAr... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 1,634 | adventofcode | MIT License |
src/main/kotlin/com/jacobhyphenated/advent2022/day5/Day5.kt | jacobhyphenated | 573,603,184 | false | {"Kotlin": 144303} | package com.jacobhyphenated.advent2022.day5
import com.jacobhyphenated.advent2022.Day
// Distinguish between Crates as the data structure holding the initial state of the stacks
// and CratesMut which is a mutable data structure used when executing the crane instructions
typealias CratesMut = List<MutableList<Char>>
... | 0 | Kotlin | 0 | 0 | 9f4527ee2655fedf159d91c3d7ff1fac7e9830f7 | 4,881 | advent2022 | The Unlicense |
aoc-2021/src/commonMain/kotlin/fr/outadoc/aoc/twentytwentyone/Day03.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwentyone
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
@Suppress("NonAsciiCharacters", "LocalVariableName")
class Day03 : Day<Int> {
private val input: List<IntArray> = readDayInput()
.lineSequence()
.map { line -> line.map { it.digit... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 2,227 | adventofcode | Apache License 2.0 |
day03/part2.kts | bmatcuk | 726,103,418 | false | {"Kotlin": 214659} | // --- Part Two ---
// The engineer finds the missing part and installs it in the engine! As the
// engine springs to life, you jump in the closest gondola, finally ready to
// ascend to the water source.
//
// You don't seem to be going very fast, though. Maybe something is still
// wrong? Fortunately, the gondola has... | 0 | Kotlin | 0 | 0 | a01c9000fb4da1a0cd2ea1a225be28ab11849ee7 | 2,836 | adventofcode2023 | MIT License |
kotlinP/src/main/java/com/jadyn/kotlinp/dynamic/dynamic-0.kt | JadynAi | 136,196,478 | false | null | package com.jadyn.kotlinp.dynamic
import kotlin.math.max
/**
*JadynAi since 4/20/21
*/
fun main() {
// println("fib result ${maxSubArray(intArrayOf(-2, 1, -3, 4, -1, 2, 1, -5, 4))}")
// println("counts ${climbStairs(4)}")
// println("max profit ${maxProfit1(intArrayOf(3, 3, 6, 7, 1, 6, 5, 4, 10))}")
pr... | 0 | Kotlin | 6 | 17 | 9c5efa0da4346d9f3712333ca02356fa4616a904 | 4,202 | Kotlin-D | Apache License 2.0 |
src/Lesson2Arrays/CyclicRotation.kt | slobodanantonijevic | 557,942,075 | false | {"Kotlin": 50634} | /**
* 100/100
* @param A
* @param K
* @return
*/
fun solution(A: IntArray, K: Int): IntArray? {
val N = A.size
val result = IntArray(N)
for (i in 0 until N) {
val key: Int = (i + K) % N
result[key] = A[i]
}
return result
}
/**
* An array A consisting of N integers is given. Ro... | 0 | Kotlin | 0 | 0 | 155cf983b1f06550e99c8e13c5e6015a7e7ffb0f | 1,659 | Codility-Kotlin | Apache License 2.0 |
src/main/kotlin/g0101_0200/s0110_balanced_binary_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0101_0200.s0110_balanced_binary_tree
// #Easy #Depth_First_Search #Tree #Binary_Tree #Programming_Skills_II_Day_2 #Level_2_Day_6_Tree
// #Udemy_Tree_Stack_Queue #2023_07_11_Time_182_ms_(71.30%)_Space_36.5_MB_(78.48%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`v... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,890 | LeetCode-in-Kotlin | MIT License |
2021/src/main/kotlin/com/trikzon/aoc2021/Day12.kt | Trikzon | 317,622,840 | false | {"Kotlin": 43720, "Rust": 21648, "C#": 12576, "C++": 4114, "CMake": 397} | package com.trikzon.aoc2021
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
fun main() {
val input = getInputStringFromFile("/day12.txt")
benchmark(Part.One, ::day12Part1, input, 5252, 5000)
benchmark(Part.One, ::day12Part2, input, 147784, 50)
}
fun day12Part1(inp... | 0 | Kotlin | 1 | 0 | d4dea9f0c1b56dc698b716bb03fc2ad62619ca08 | 4,989 | advent-of-code | MIT License |
src/Day10.kt | oleksandrbalan | 572,863,834 | false | {"Kotlin": 27338} | import kotlin.math.abs
fun main() {
val input = readInput("Day10")
.filterNot { it.isEmpty() }
.map {
when {
it.startsWith(COMMAND_ADDX) -> listOf(0, it.split(" ")[1].toInt())
it.startsWith(COMMAND_NOOP) -> listOf(0)
else -> error("Command... | 0 | Kotlin | 0 | 2 | 1493b9752ea4e3db8164edc2dc899f73146eeb50 | 1,064 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | SeanDijk | 575,314,390 | false | {"Kotlin": 29164} | import java.util.*
import kotlin.math.abs
import kotlin.math.sign
fun main() {
data class Coordinate(val x: Int, val y: Int) {
fun moveX(int: Int) = copy(x = x + int)
fun moveY(int: Int) = copy(y = y + int)
fun left() = moveX(-1)
fun right() = moveX(1)
fun up() = moveY(1)
... | 0 | Kotlin | 0 | 0 | 363747c25efb002fe118e362fb0c7fecb02e3708 | 7,431 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day15.kt | tianyu | 574,561,581 | false | {"Kotlin": 49942} | import assertk.assertThat
import assertk.assertions.*
import kotlin.math.absoluteValue
private fun main() {
tests {
val sensors = sensors("day15-example.txt")
"Read sensors" {
assertThat(sensors).containsAll(
Sensor(2, 18, -2, 15),
Sensor(10, 20, 10, 16),
Sensor(0, 11, 2, 10),
... | 0 | Kotlin | 0 | 0 | 6144cc0ccf1a51ba2e28c9f38ae4e6dd4c0dc1ea | 4,597 | AdventOfCode2022 | MIT License |
src/com/zypus/SLIP/algorithms/SpringEvolution.kt | zypus | 213,665,750 | false | null | package com.zypus.SLIP.algorithms
import com.zypus.SLIP.algorithms.genetic.Selection
import com.zypus.SLIP.algorithms.genetic.Selections
import com.zypus.SLIP.algorithms.genetic.builder.evolution
import com.zypus.SLIP.algorithms.genetic.crossover
import com.zypus.SLIP.algorithms.genetic.mutate
import com.zypus.SLIP.co... | 0 | Kotlin | 0 | 0 | 418ee8837752143194fd769e86fac85e15136929 | 2,589 | SLIP | MIT License |
leetcode/src/main/kotlin/com/artemkaxboy/leetcode/p10/Leet1034.kt | artemkaxboy | 513,636,701 | false | {"Kotlin": 547181, "Java": 13948} | package com.artemkaxboy.leetcode.p10
import com.artemkaxboy.leetcode.LeetUtils
import java.util.*
/**
* Medium
* Runtime 256ms Beats 100.0%
* Memory 37.7MB Beats 50.00%
*/
class Leet1034 {
class Solution {
private lateinit var grid: Array<IntArray>
private val queue: Queue<Pair<Int... | 0 | Kotlin | 0 | 0 | 516a8a05112e57eb922b9a272f8fd5209b7d0727 | 4,106 | playground | MIT License |
openrndr-math/src/main/kotlin/org/openrndr/math/Equations.kt | ericyd | 308,041,887 | true | {"Kotlin": 1389413, "Java": 759791, "ANTLR": 9333, "CSS": 4706, "GLSL": 1846, "Shell": 548} | package org.openrndr.math
private const val DISCRIMINANT_EPSILON = 1e-10
private const val SOLUTION_EPSILON = 1e-8
private val MACHINE_EPSILON = Math.ulp(1.0)
private const val EPSILON = 1e-14
// adapted from https://github.com/paperjs/paper.js/blob/develop/src/util/Numerical.js
// converted from Artifex Equations.ja... | 0 | Kotlin | 0 | 0 | 504c91db41658c3c6d464e4b60f9f017096c0f6d | 4,669 | openrndr | BSD 2-Clause FreeBSD License |
Cyclotomic_Polynomial/Kotlin/src/CyclotomicPolynomial.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} | import java.util.TreeMap
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.sqrt
private const val algorithm = 2
fun main() {
println("Task 1: cyclotomic polynomials for n <= 30:")
for (i in 1..30) {
val p = cyclotomicPolynomial(i)
println("CP[$i] = $p")
}
println()
... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 14,482 | rosetta | MIT License |
src/main/kotlin/ru/glukhov/aoc/Day10.kt | cobaku | 576,736,856 | false | {"Kotlin": 25268} | package ru.glukhov.aoc
import java.io.BufferedReader
fun main() {
val microcode = Problem.forDay("day10").use { parseMicrocode(it) }
println("Result of the first problem: ${first(microcode)}")
println("Result of the first problem:\n ${second(microcode)}")
}
private fun first(microcode: List<Pair<Operatio... | 0 | Kotlin | 0 | 0 | a40975c1852db83a193c173067aba36b6fe11e7b | 2,304 | aoc2022 | MIT License |
capitulo5/src/main/kotlin/5.8TaxadeEstacionamento.kt | Cursos-Livros | 667,537,024 | false | {"Kotlin": 104564} | //5.8 (Taxa de estacionamento) Um estacionamento cobra uma taxa mínima de $ 2,00 para estacionar até três
//horas. A garagem cobra um adicional de US$ 0,50 por hora para cada hora ou parte dela além de três
//horas. A cobrança máxima para qualquer período de 24 horas é de US$ 10,00. Suponha que não haja estacionamento ... | 0 | Kotlin | 0 | 0 | f2e005135a62b15360c2a26fb6bc2cbad18812dd | 1,939 | Kotlin-Como-Programar | MIT License |
src/Day01.kt | jwalter | 573,111,342 | false | {"Kotlin": 19975} | fun main() {
fun sumOfEachElf(input: List<String>): MutableList<Int> {
val res = input.fold(mutableListOf<Int>()) { acc, value ->
if (value.isBlank() || acc.isEmpty()) {
acc.add(0)
} else {
acc.add(acc.removeLast() + value.toInt())
}
... | 0 | Kotlin | 0 | 0 | 576aeabd297a7d7ee77eca9bb405ec5d2641b441 | 801 | adventofcode2022 | Apache License 2.0 |
src/Day03.kt | felldo | 572,233,925 | false | {"Kotlin": 76496} | fun main() {
val map: Map<String, Int> = mapOf(
"a" to 1,
"b" to 2,
"c" to 3,
"d" to 4,
"e" to 5,
"f" to 6,
"g" to 7,
"h" to 8,
"i" to 9,
"j" to 10,
"k" to 11,
"l" to 12,
"m" to 13,
"n" to 14,
"o... | 0 | Kotlin | 0 | 0 | 0ef7ac4f160f484106b19632cd87ee7594cf3d38 | 1,857 | advent-of-code-kotlin-2022 | Apache License 2.0 |
2021/src/Day06.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | // https://adventofcode.com/2021/day/6
fun main() {
fun part1() {
var fishDays = mutableMapOf<Int, Long>().withDefault { 0 }
val days = 256
val newFishDayCount = 8
val resetFishDayCount = 6
for (line in readInput("Day06")) {
for (fish in line.split(",")) {
fishDays[fish.toInt()] = ... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 1,010 | advent-of-code | Apache License 2.0 |
app/src/main/kotlin/me/mataha/misaki/util/text/Levenshtein.kt | mataha | 302,513,601 | false | {"Kotlin": 92734, "Gosu": 702, "Batchfile": 104, "Shell": 90} | package me.mataha.misaki.util.text
import me.mataha.misaki.util.functional.assign
import me.mataha.misaki.util.math.min
/**
* Calculates [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance)
* between two character sequences. A higher score indicates a greater distance.
*
* Only deletions, in... | 0 | Kotlin | 0 | 0 | 748a5b25a39d01b2ffdcc94f1a99a6fbc8a02685 | 1,528 | misaki | MIT License |
src/main/kotlin/advent/Advent7.kt | v3rm0n | 225,866,365 | false | null | package advent
import intcode.Calculator
import java.util.concurrent.LinkedBlockingQueue
class Advent7 : Advent {
override fun firstTask(input: List<String>) = phases(input)
override fun secondTask(input: List<String>): Long {
val intcodes = input.flatMap { it.split(',').map(String::toLong) }
... | 0 | Kotlin | 0 | 1 | 5c36cb254100f80a6e9c16adff5e7aadc8c9e98f | 2,761 | aoc2019 | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.