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/year2022/day20/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2022.day20
import io.kotest.matchers.shouldBe
import utils.cyclical
import utils.readInput
fun main() {
val testInput = readInput("20", "test_input").map(String::toLong)
val realInput = readInput("20", "input").map(String::toLong)
testInput.asSequence()
.withIndex()
.run { run... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 1,925 | Advent-of-Code | Apache License 2.0 |
src/Day01.kt | luiscobo | 574,302,765 | false | {"Kotlin": 19047} | fun main() {
fun part1(input: List<String>): Int {
var n = 0
var mayor = 0
var suma = 0
input.forEach {
if (it.trim().isEmpty()) {
n++
if (suma > mayor) {
mayor = suma
}
suma = 0
... | 0 | Kotlin | 0 | 0 | c764e5abca0ea40bca0b434bdf1ee2ded6458087 | 1,050 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/leetcode/kotlin/array/easy/628. Maximum Product of Three Numbers.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package leetcode.kotlin.array.easy
private fun maximumProduct(nums: IntArray): Int {
var max = Int.MIN_VALUE
for (i in 0..nums.lastIndex - 2) {
for (j in i + 1 until nums.lastIndex) {
for (k in j + 1..nums.lastIndex) {
var p = nums[i] * nums[j] * nums[k]
max ... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,828 | leetcode-kotlin | Apache License 2.0 |
src/Day02.kt | samorojy | 572,624,502 | false | {"Kotlin": 5094} | fun main() {
val inputs = readInput("Day02")
println("first=${calculateScore(inputs,true)}")
println("second=${calculateScore(inputs,false)}")
}
fun calculateScore(input: List<String>, withPlay: Boolean): Int {
val lose = mapOf(1 to 0, 2 to 1, 0 to 2)
val won = mapOf(0 to 1, 1 to 2, 2 to 0)
re... | 0 | Kotlin | 0 | 0 | 7a38657c4ff7b42c5d49379014f88d054183bd2b | 926 | advent-of-code | Apache License 2.0 |
server/src/main/kotlin/com/heerkirov/hedge/server/library/compiler/grammar/definintion/SyntaxExpression.kt | HeerKirov | 298,201,781 | false | null | package com.heerkirov.hedge.server.library.compiler.grammar.definintion
//文法产生式的定义,作用是和syntax.txt中的定义对应。
/**
* 被定义的文法产生式。
*/
data class SyntaxExpression(val index: Int, val key: KeyNotation, val sequence: List<Notation>)
/**
* 文法产生式中的文法符号。
*/
interface Notation
/**
* 终结符。
*/
interface TerminalNotation : Notat... | 0 | TypeScript | 0 | 1 | 8140cd693759a371dc5387c4a3c7ffcef6fb14b2 | 2,248 | Hedge-v2 | MIT License |
src/2021/Day10.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2021`
import java.io.File
import java.math.BigInteger
import java.util.*
fun main() {
Day10().solve()
}
class Day10 {
val input = """
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 2,131 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/eharrison/game/tdcreator/AStar.kt | toddharrison | 190,808,157 | false | null | package com.eharrison.game.tdcreator
import java.util.PriorityQueue
import java.util.ArrayList
typealias Neighbors<Node> = (Node) -> List<Node>
typealias Cost<Node> = (Node, Node) -> Double
typealias Exclude<Node> = (Node) -> Boolean
typealias Heuristic<Node> = (Node, Node) -> Double
fun <Node> aStar(
start: Nod... | 1 | Kotlin | 0 | 1 | 269b3f2405b1ddbd99db55fe4ebde38f9fc9b411 | 2,826 | tdcreator | MIT License |
advent4/src/main/kotlin/Main.kt | thastreet | 574,294,123 | false | {"Kotlin": 29380} | import java.io.File
fun main(args: Array<String>) {
val lines = File("input.txt").readLines()
val pairs: List<Pair<IntRange, IntRange>> = parsePairs(lines)
println("part1Answer: ${part1(pairs)}")
println("part2Answer: ${part2(pairs)}")
}
fun parsePairs(lines: List<String>): List<Pair<IntRange, IntRa... | 0 | Kotlin | 0 | 0 | e296de7db91dba0b44453601fa2b1696af9dbb15 | 1,235 | advent-of-code-2022 | Apache License 2.0 |
src/adventofcode/blueschu/y2017/day21/solution.kt | blueschu | 112,979,855 | false | null | package adventofcode.blueschu.y2017.day21
import java.io.File
import java.util.*
val initialImage: Array<BitSet> = arrayOf(
BitSet(3).apply { set(1) },
BitSet(3).apply { set(0) },
BitSet(3).apply { set(0, 3) }
)
val input: List<String> by lazy {
File("resources/y2017/day21.txt")
.bufferedRead... | 0 | Kotlin | 0 | 0 | 9f2031b91cce4fe290d86d557ebef5a6efe109ed | 4,025 | Advent-Of-Code | MIT License |
src/Day12.kt | IvanChadin | 576,061,081 | false | {"Kotlin": 26282} | import java.util.*
fun main() {
val inputName = "Day12_test"
val a = readInput(inputName).map { it.toCharArray() }
data class Pt(val x: Int, val y: Int)
fun part1(): Int {
val q: Queue<Pair<Pt, Int>> = LinkedList()
var end: Pt? = null
for (x in a.indices) {
for (y... | 0 | Kotlin | 0 | 0 | 2241437e6c3a20de70306a0cb37b6fe2ed8f9e3a | 2,561 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FindDuplicateSubtrees.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,635 | kotlab | Apache License 2.0 |
year2021/day05/part1/src/main/kotlin/com/curtislb/adventofcode/year2021/day05/part1/Year2021Day05Part1.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Day 5: Hydrothermal Venture ---
You come across a field of hydrothermal vents on the ocean floor! These vents constantly produce
large, opaque clouds, so it would be best to avoid them if possible.
They tend to form in lines; the submarine helpfully produces a list of nearby lines of vents (your
puzzle input) ... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,369 | AdventOfCode | MIT License |
src/main/kotlin/Day04.kt | dliszewski | 573,836,961 | false | {"Kotlin": 57757} | class Day04 {
fun part1(input: List<String>): Int {
return input
.map { it.toRanges() }
.count { (range1, range2) -> range1 includeRange range2 }
}
fun part2(input: List<String>): Int {
return input
.map { it.toRanges() }
.count { (range1, ra... | 0 | Kotlin | 0 | 0 | 76d5eea8ff0c96392f49f450660220c07a264671 | 1,066 | advent-of-code-2022 | Apache License 2.0 |
src/Day03/Day03.kt | suttonle24 | 573,260,518 | false | {"Kotlin": 26321} | package Day03
import readInput
//--- Day 3: Rucksack Reorganization ---
//One Elf has the important job of loading all of the rucksacks with supplies for the jungle journey. Unfortunately, that Elf didn't quite follow the packing instructions, and so a few items now need to be rearranged.
//
//Each rucksack has two ... | 0 | Kotlin | 0 | 0 | 039903c7019413d13368a224fd402625023d6f54 | 8,085 | AoC-2022-Kotlin | Apache License 2.0 |
src/main/kotlin/g0901_1000/s0953_verifying_an_alien_dictionary/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s0953_verifying_an_alien_dictionary
// #Easy #Array #String #Hash_Table #Programming_Skills_I_Day_9_String
// #2023_05_02_Time_137_ms_(100.00%)_Space_35.5_MB_(93.75%)
class Solution {
fun isAlienSorted(words: Array<String>, order: String): Boolean {
val map = IntArray(26)
for (i... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,091 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/de/mbdevelopment/adventofcode/year2021/solvers/day17/Day17Puzzle2.kt | Any1s | 433,954,562 | false | {"Kotlin": 96683} | package de.mbdevelopment.adventofcode.year2021.solvers.day17
import de.mbdevelopment.adventofcode.year2021.solvers.PuzzleSolver
import kotlin.math.max
class Day17Puzzle2 : PuzzleSolver {
override fun solve(inputLines: Sequence<String>) =
bruteForceNumberOfSuccessfullInitialVelocities(inputLines.first()).... | 0 | Kotlin | 0 | 0 | 21d3a0e69d39a643ca1fe22771099144e580f30e | 1,708 | AdventOfCode2021 | Apache License 2.0 |
Day_10/Solution_Part2.kts | 0800LTT | 317,590,451 | false | null | import java.io.File
import java.math.BigInteger
val INPUT_FILE_NAME = "test.txt"
// This was my initial implementation, though I knew it wouldn't work for the
// puzzle input. There are too many overlapping cases and we need to memoize the results.
// It works fine for the two small inputs.
/*
fun countCombinations(... | 0 | Kotlin | 0 | 0 | 191c8c307676fb0e7352f7a5444689fc79cc5b54 | 1,515 | advent-of-code-2020 | The Unlicense |
lib/src/main/kotlin/de/linkel/aoc/utils/rangeset/IntRangeSet.kt | norganos | 726,350,504 | false | {"Kotlin": 162220} | package de.linkel.aoc.utils.rangeset
import de.linkel.aoc.utils.iterables.intersect
import de.linkel.aoc.utils.iterables.intersects
class IntRangeSetFactory: RangeFactory<Int, IntRange, Int> {
companion object {
val INSTANCE = IntRangeSetFactory()
}
override fun build(start: Int, endInclusive: In... | 0 | Kotlin | 0 | 0 | 3a1ea4b967d2d0774944c2ed4d96111259c26d01 | 1,892 | aoc-utils | Apache License 2.0 |
src/Day03.kt | ElenaRgC | 572,898,962 | false | null | fun buscarCaracter(elemento: String): Char {
var i = 0
var j = 0
var caracterRepetido = ' '
while (i < elemento.length / 2) {
j = elemento.length / 2
while (j < elemento.length) {
if (elemento[i] == elemento[j]) {
caracterRepetido = elemento[i]
... | 0 | Kotlin | 0 | 0 | b7505e891429970c377f7b45bfa8b5157f85c457 | 2,244 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/staricka/adventofcode2022/Day15.kt | mathstar | 569,952,400 | false | {"Kotlin": 77567} | package com.staricka.adventofcode2022
import com.staricka.adventofcode2022.Day15.Sensor.Companion.toSensor
import kotlin.math.abs
class Day15(
private val part1Row: Int = 2000000,
private val part2Limit: Int = 4000000
) : Day {
override val id = 15
enum class Tile {
AIR, SENSOR, BEACON
}
data class ... | 0 | Kotlin | 0 | 0 | 2fd07f21348a708109d06ea97ae8104eb8ee6a02 | 3,698 | adventOfCode2022 | MIT License |
src/y2022/day04.kt | sapuglha | 573,238,440 | false | {"Kotlin": 33695} | package y2022
import extensions.contains
import readFileAsLines
fun main() {
fun getElves(line: String): Pair<IntRange, IntRange> {
val (first, second) = line.split(",")
val (firstBegin, firstEnd) = first.split("-").map(String::toInt)
val (secondBegin, secondEnd) = second.split("-").map(St... | 0 | Kotlin | 0 | 0 | 82a96ccc8dcf38ae4974e6726e27ddcc164e4b54 | 948 | adventOfCode2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CountPalindromicSubsequence.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,916 | kotlab | Apache License 2.0 |
src/commonMain/kotlin/faraday/base/Distance.kt | Amagi82 | 289,812,027 | false | null | package faraday.base
import faraday.Prefixes
import faraday.Units
import faraday.derived.Energy
import faraday.derived.Force
import faraday.derived.kinematic.Velocity
import faraday.derived.mechanical.Area
import faraday.derived.mechanical.FuelEfficiency
import faraday.derived.mechanical.Stiffness
import faraday.deriv... | 0 | Kotlin | 0 | 0 | b0f08fc06e51344736ef0953a42061044de47f80 | 4,457 | Faraday | Apache License 2.0 |
Retos/Reto #2 - EL PARTIDO DE TENIS [Media]/kotlin/IsmaelMatiz.kts | mouredev | 581,049,695 | false | {"Python": 3866914, "JavaScript": 1514237, "Java": 1272062, "C#": 770734, "Kotlin": 533094, "TypeScript": 457043, "Rust": 356917, "PHP": 281430, "Go": 243918, "Jupyter Notebook": 221090, "Swift": 216751, "C": 210761, "C++": 164758, "Dart": 159755, "Ruby": 70259, "Perl": 52923, "VBScript": 49663, "HTML": 45912, "Raku": ... | /*
* Escribe un programa que muestre cómo transcurre un juego de tenis y quién lo ha ganado.
* El programa recibirá una secuencia formada por "P1" (Player 1) o "P2" (Player 2), según quien
* gane cada punto del juego.
*
* - Las puntuaciones de un juego son "Love" (cero), 15, 30, 40, "Deuce" (empate), ventaja.
* ... | 4 | Python | 2,929 | 4,661 | adcec568ef7944fae3dcbb40c79dbfb8ef1f633c | 1,768 | retos-programacion-2023 | Apache License 2.0 |
src/day1/Day01.kt | kacperhreniak | 572,835,614 | false | {"Kotlin": 85244} | import java.util.PriorityQueue
import kotlin.math.max
private const val MAX_SIZE = 3
private fun part1(input: List<String>): Int {
var max = Int.MIN_VALUE
var temp = 0
input.forEach {
if (it.isEmpty() && temp > 0) {
max = max(max, temp)
temp = 0
} else {
... | 0 | Kotlin | 1 | 0 | 03368ffeffa7690677c3099ec84f1c512e2f96eb | 1,124 | aoc-2022 | Apache License 2.0 |
src/test/kotlin/be/brammeerten/y2023/Day10Pt2Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2023
import be.brammeerten.C
import be.brammeerten.readFile
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
class Day10Pt2Test {
@Test
fun `part 1`() {
// val map = PipeMap(readFile("2023/day10/exampleInput3.txt"))
// val map = PipeMa... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 8,696 | Advent-of-Code | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SortArrayByParity2.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,587 | kotlab | Apache License 2.0 |
scripts/Day3.kts | matthewm101 | 573,325,687 | false | {"Kotlin": 63435} | import java.io.File
data class Sack(val first: Set<Int>, val second: Set<Int>) {
fun match() = first.intersect(second)
fun all() = first.union(second)
}
data class Group(val first: Sack, val second: Sack, val third: Sack) {
fun badge() = first.all().intersect(second.all()).intersect(third.all())
}
fun ad... | 0 | Kotlin | 0 | 0 | bbd3cf6868936a9ee03c6783d8b2d02a08fbce85 | 1,191 | adventofcode2022 | MIT License |
src/Day06.kt | josemarcilio | 572,290,152 | false | {"Kotlin": 5535} | fun main() {
fun solve(input: String, window: Int): Int {
return input.indices.windowed(window, step = 1) { values ->
if (values.map{ input[it] }.toSet().size == window) {
return@windowed values.last() + 1
}
-1
}.first { it > 0 }
}
fun pa... | 0 | Kotlin | 0 | 0 | d628345afeb014adce189fddac53a1fcd98479fb | 690 | advent-of-code-2022 | Apache License 2.0 |
src/main/aoc2021/Day3.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2021
class Day3(val input: List<String>) {
private fun getOneCounts(numbers: List<String>): List<Int> {
val len = numbers.first().length
val oneCounts = Array(len) { 0 }
numbers.forEach { number ->
number.forEachIndexed { index, c ->
if (c == '1') {
... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,078 | aoc | MIT License |
src/Day04.kt | romainbsl | 572,718,344 | false | {"Kotlin": 17019} | fun main() {
fun String.toRange(): Set<Int> {
val (start, end) = split("-").map(String::toInt)
return IntRange(start, end).toSet()
}
fun List<String>.toAssignments(): List<Pair<Set<Int>, Set<Int>>> = map {
val (left, right) = it.split(",")
left.toRange() to right.toRange()
... | 0 | Kotlin | 0 | 0 | b72036968769fc67c222a66b97a11abfd610f6ce | 974 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/Day16.kt | andrewrlee | 434,584,657 | false | {"Kotlin": 29493, "Clojure": 14117, "Shell": 398} | import Day16.Type.EQUAL_TO
import Day16.Type.G_THAN
import Day16.Type.LITERAL
import Day16.Type.L_THAN
import Day16.Type.MAX
import Day16.Type.MIN
import Day16.Type.PRODUCT
import Day16.Type.SUM
import java.io.File
import java.math.BigInteger
import java.nio.charset.Charset.defaultCharset
object Day16 {
enum cla... | 0 | Kotlin | 0 | 0 | aace0fccf9bb739d57f781b0b79f2f3a5d9d038e | 5,394 | adventOfCode2021 | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2015/Day06.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.P
import se.saidaspen.aoc.util.ints
import se.saidaspen.aoc.util.rectangle
fun main() = Day06.run()
object Day06 : Day(2015, 6) {
override fun part1(): Any {
val map = mutableMapOf<P<Int, Int>, Boolean>()
... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,792 | adventofkotlin | MIT License |
src/org/mjurisic/aoc2020/day7/Day7.kt | mjurisic | 318,555,615 | false | null | package org.mjurisic.aoc2020.day7
import java.io.File
import java.util.function.Consumer
class Day7 {
companion object {
@JvmStatic
fun main(args: Array<String>) = try {
val nodes = HashMap<String, Node>()
val vertices = ArrayList<Vertex>()
File(ClassLoader.ge... | 0 | Kotlin | 0 | 0 | 9fabcd6f1daa35198aaf91084de3b5240e31b968 | 3,582 | advent-of-code-2020 | Apache License 2.0 |
N-smooth_numbers/Kotlin/src/NSmooth.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
var primes = mutableListOf<BigInteger>()
var smallPrimes = mutableListOf<Int>()
// cache all primes up to 521
fun init() {
val two = BigInteger.valueOf(2)
val three = BigInteger.valueOf(3)
val p521 = BigInteger.valueOf(521)
val p29 = BigInteger.valueOf(29)
primes.add(tw... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 2,333 | rosetta | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions25.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
import com.qiaoyuang.algorithm.round1.SingleDirectionNode
import com.qiaoyuang.algorithm.round1.printlnLinkedList
fun test25() {
printlnResult(
head1 = SingleDirectionNode(element = 1, next = SingleDirectionNode(element = 2, next = SingleDirectionNode(element = 3)))... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 2,012 | Algorithm | Apache License 2.0 |
src/main/kotlin/kotml/knn/KNN.kt | tommypacker | 127,594,710 | false | null | package kotml.knn
import kotml.utils.DataRow
import kotml.utils.MathHelper
class KNN (val data: Array<DataRow>, val labels: Array<String>, val k: Int = 1, val weighted: Boolean = false){
/**
* Test our model by making predictions and comparing them to the actual labels
*/
fun test(testData: Array<... | 4 | Kotlin | 2 | 13 | c4b69e7f15de3d8b63f8e3251ebae2ccc23bb8d0 | 2,728 | kotml | MIT License |
src/day8/day8.kt | TimCastelijns | 113,205,922 | false | null | package day8
import java.io.File
fun main(args: Array<String>) {
val lines = File("src/day8/input").readLines()
p1(lines)
p2(lines)
}
fun p1(lines: List<String>) {
val values = mutableMapOf<String, Int>()
for (line in lines) {
values.put(line.split(" ")[0], 0)
}
for (line in lin... | 0 | Kotlin | 0 | 0 | 656f2a424b323175cd14d309bc25430ac7f7250f | 2,027 | aoc2017 | MIT License |
src/main/kotlin/g1801_1900/s1898_maximum_number_of_removable_characters/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1898_maximum_number_of_removable_characters
// #Medium #Array #String #Binary_Search #Binary_Search_II_Day_6
// #2023_06_22_Time_636_ms_(100.00%)_Space_54.4_MB_(33.33%)
class Solution {
fun maximumRemovals(s: String, p: String, removable: IntArray): Int {
if (s.isEmpty()) {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,582 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/common/Utils.kt | hughjdavey | 225,440,374 | false | null | package common
import java.util.Stack
fun <T> stackOf(vararg input: T): Stack<T> {
val stack = Stack<T>()
input.toList().reversed().forEach { stack.push(it) }
return stack
}
// credit LukArToDo - https://code.sololearn.com/c24EP02YuQx3/#kt
fun <T> permutations(ts: List<T>): List<List<T>> {
if (ts.siz... | 0 | Kotlin | 0 | 1 | 84db818b023668c2bf701cebe7c07f30bc08def0 | 1,695 | aoc-2019 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/jacobhyphenated/day10/Day10.kt | jacobhyphenated | 572,119,677 | false | {"Kotlin": 157591} | package com.jacobhyphenated.day10
import com.jacobhyphenated.Day
import java.io.File
import java.math.BigDecimal
import kotlin.math.absoluteValue
// Monitoring Station
class Day10: Day<List<Asteroid>> {
override fun getInput(): List<Asteroid> {
return mapAsteroids(
this.javaClass.classLoader.g... | 0 | Kotlin | 0 | 0 | 1a0b9cb6e9a11750c5b3b5a9e6b3d63649bf78e4 | 5,810 | advent2019 | The Unlicense |
src/Utils.kt | Tandrial | 47,354,790 | false | null | import java.io.File
import java.util.regex.Pattern
import kotlin.math.abs
import kotlin.system.measureTimeMillis
/**
* Returns the alphabetically sorted String
*
* @return The string sorted alphabetically
*/
fun String.sort(): String = this.toCharArray().sorted().joinToString()
/**
* Parses the File contents int... | 0 | Kotlin | 1 | 1 | 9294b2cbbb13944d586449f6a20d49f03391991e | 2,312 | Advent_of_Code | MIT License |
src/Day25.kt | EdoFanuel | 575,561,680 | false | {"Kotlin": 80963} | class Day25 {
fun decode(input: String): Long {
var result = 0L
for (c in input) {
result *= 5
result += when(c) {
'2' -> 2
'1' -> 1
'0' -> 0
'-' -> -1
'=' -> -2
else -> throw Ille... | 0 | Kotlin | 0 | 0 | 46a776181e5c9ade0b5e88aa3c918f29b1659b4c | 1,582 | Advent-Of-Code-2022 | Apache License 2.0 |
kotlin/graphs/flows/MinCostFlowSimple.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package graphs.flows
import java.util.Arrays
object MinCostFlowSimple {
fun minCostFlow(cap: Array<IntArray>, cost: Array<IntArray>, s: Int, t: Int): IntArray {
val n = cap.size
val d = IntArray(n)
val p = IntArray(n)
var flow = 0
var flowCost = 0
while (true) {
... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,584 | codelibrary | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SetMismatch.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2024 <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,835 | kotlab | Apache License 2.0 |
Kotlin/5 kyu Maximum subarray sum.kt | MechaArms | 508,384,440 | false | {"Kotlin": 22917, "Python": 18312} | /*
The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers:
maxSequence(listOf(-2, 1, -3, 4, -1, 2, 1, -5, 4));
// should be 6: listOf(4, -1, 2, 1)
Easy case is when the list is made up of only positive numbers and the maximum sum is the sum of ... | 0 | Kotlin | 0 | 1 | b23611677c5e2fe0f7e813ad2cfa21026b8ac6d3 | 788 | My-CodeWars-Solutions | MIT License |
LeetCode/Kotlin/src/main/kotlin/org/redquark/tutorials/leetcode/MergeKSortedLists.kt | ani03sha | 297,402,125 | false | null | package org.redquark.tutorials.leetcode
class MergeKSortedLists {
internal fun mergeKLists(lists: Array<ListNode?>): ListNode? {
// Base condition
return if (lists.isEmpty()) {
null
} else mergeKLists(lists, 0, lists.size - 1)
}
private fun mergeKLists(lists: Array<Lis... | 2 | Java | 40 | 64 | 67b6ebaf56ec1878289f22a0324c28b077bcd59c | 2,631 | RedQuarkTutorials | MIT License |
src/Day18.kt | spaikmos | 573,196,976 | false | {"Kotlin": 83036} | fun main() {
fun parseInput(input: List<String>): MutableList<List<Int>> {
val lava = mutableListOf<List<Int>>()
for (i in input) {
val a = i.split(',').map{ it -> it.toInt()}
lava.add(a)
}
return lava
}
fun part1(input: MutableList<List<Int>>): Int {... | 0 | Kotlin | 0 | 0 | 6fee01bbab667f004c86024164c2acbb11566460 | 2,448 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/22.kts | reitzig | 318,492,753 | false | null | @file:Include("shared.kt")
import java.io.File
// NB: Would like this to be an inline class, but alas, not possible in kscript (yet)
data class Card(val value: Int)
data class Hand(val cards: List<Card>) {
fun isEmpty(): Boolean = cards.isEmpty()
val score: Int
get() = cards.reversed().mapIndexed { ... | 0 | Kotlin | 0 | 0 | f17184fe55dfe06ac8897c2ecfe329a1efbf6a09 | 2,619 | advent-of-code-2020 | The Unlicense |
Java_part/Assigment9/src/Q1.kt | enihsyou | 58,862,788 | false | {"Java": 77446, "Python": 65409, "Kotlin": 35032, "C++": 6214, "C": 3796, "CMake": 818} | import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.RepeatedTest
import java.util.*
import java.util.Collections.swap
import kotlin.test.assertEquals
/**
* 1)分治算法求n个数的数组中找出第二个最大元素
*/
fun main(args: Array<String>) {
Scanner(System.`in`).use { s ->
println("输入数组数字,以非数字结束")
val list = ArrayL... | 0 | Java | 0 | 0 | 09a109bb26e0d8d165a4d1bbe18ec7b4e538b364 | 1,889 | Sorting-algorithm | MIT License |
src/main/kotlin/aoc2022/Utils.kt | davidsheldon | 565,946,579 | false | {"Kotlin": 161960} | package aoc2022
import java.io.File
import java.math.BigInteger
import java.security.MessageDigest
/**
* Reads lines from the given input txt file.
*/
fun readInput(name: String) = File("src", "$name.txt").readLines()
/**
* Converts string to aoc2022.md5 hash.
*/
fun String.md5(): String = BigInteger(1, MessageD... | 0 | Kotlin | 0 | 0 | 5abc9e479bed21ae58c093c8efbe4d343eee7714 | 3,110 | aoc-2022-kotlin | Apache License 2.0 |
src/Day01.kt | JCampbell8 | 572,669,444 | false | {"Kotlin": 10115} | fun main() {
fun getCalorieList(input: List<String>):List<Int> {
val sums:MutableList<Int> = mutableListOf()
var sum = 0
input.forEach {
if (it == "") {
sums.add(sum)
sum = 0
} else {
sum += it.toInt()
}
... | 0 | Kotlin | 0 | 1 | 0bac6b866e769d0ac6906456aefc58d4dd9688ad | 917 | advent-of-code-2022 | Apache License 2.0 |
day05/kotlin/RJPlog/day2105_1_2.kts | razziel89 | 438,180,535 | true | {"Rust": 368326, "Python": 219109, "Go": 200337, "Kotlin": 80185, "Groovy": 67858, "JavaScript": 45619, "TypeScript": 43504, "CSS": 35030, "Shell": 18611, "C": 5260, "Ruby": 2359, "Dockerfile": 2285, "HTML": 227, "C++": 153} | import java.io.File
// tag::lines[]
fun lines(solution: Int = 0): Int {
var ground = mutableMapOf<Pair<Int, Int>, Int>()
var result: Int = 0
File("day2105_puzzle_input.txt").forEachLine {
var instruction = it.split(" -> ")
var pos1 = instruction[0].split(",")
var pos2 = instruction[1].split(",")
var x1: In... | 1 | Rust | 0 | 0 | 91a801b3c812cc3d37d6088a2544227cf158d114 | 3,221 | aoc-2021 | MIT License |
src/day25/a/day25a.kt | pghj | 577,868,985 | false | {"Kotlin": 94937} | package day25.a
import readInputLines
import shouldBe
fun main() {
val l = read()
val v = printSnafu(l.sumOf { parseSnafu(it) })
shouldBe("2=10---0===-1--01-20", v)
}
fun valueOfSnafuChar(c: Char): Long = "=-012".indexOf(c) - 2L
fun snafuDigitToChar(d: Int): Char = "=-012"[d+2]
fun parseSnafu(s: String... | 0 | Kotlin | 0 | 0 | 4b6911ee7dfc7c731610a0514d664143525b0954 | 892 | advent-of-code-2022 | Apache License 2.0 |
year2021/day16/part2/src/main/kotlin/com/curtislb/adventofcode/year2021/day16/part2/Year2021Day16Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Part Two ---
Now that you have the structure of your transmission decoded, you can calculate the value of the
expression it represents.
Literal values (type ID 4) represent a single number as described above. The remaining type IDs are
more interesting:
- Packets with type ID 0 are `sum` packets - their value... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,923 | AdventOfCode | MIT License |
src/main/kotlin/g0401_0500/s0410_split_array_largest_sum/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0401_0500.s0410_split_array_largest_sum
// #Hard #Array #Dynamic_Programming #Greedy #Binary_Search
// #2022_12_03_Time_165_ms_(100.00%)_Space_33.9_MB_(100.00%)
class Solution {
fun splitArray(nums: IntArray, m: Int): Int {
var maxVal = 0
var minVal = nums[0]
for (num in nums) {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,404 | LeetCode-in-Kotlin | MIT License |
src/Day09.kt | zt64 | 572,594,597 | false | null | import kotlin.math.absoluteValue
private object Day9 : Day(9) {
private val visitedPoints = hashSetOf<Point>()
private val motions = input.lines().map {
val (direction, steps) = it.split(" ")
Direction[direction] to steps.toInt()
}
override fun part1(): Int {
var head = Point(... | 0 | Kotlin | 0 | 0 | 4e4e7ed23d665b33eb10be59670b38d6a5af485d | 1,624 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/me/peckb/aoc/_2021/calendar/day13/Day13.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2021.calendar.day13
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import javax.inject.Inject
import kotlin.Int.Companion.MIN_VALUE
import kotlin.math.max
class Day13 @Inject constructor(private val generatorFactory: InputGeneratorFactory) {
companion object {
const va... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 3,303 | advent-of-code | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions44.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import kotlin.math.pow
fun test44() {
printlnResult(0)
printlnResult(1)
printlnResult(5)
printlnResult(10)
printlnResult(13)
printlnResult(15)
printlnResult(19)
printlnResult(190)
printlnResult(191)
printlnResult(1000)
}
/**
* Questions ... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,086 | Algorithm | Apache License 2.0 |
src/main/kotlin/g1901_2000/s1948_delete_duplicate_folders_in_system/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1901_2000.s1948_delete_duplicate_folders_in_system
// #Hard #Array #String #Hash_Table #Trie #Hash_Function
// #2023_06_20_Time_1420_ms_(100.00%)_Space_80.6_MB_(100.00%)
class Solution {
private var duplicates: MutableMap<String, ArrayList<Folder>>? = null
private var foldersWithRemovedNames: Mutable... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,895 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ArrayStringsAreEqual.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,443 | kotlab | Apache License 2.0 |
src/main/kotlin/4. Median of Two Sorted Arrays.kts | ShreckYe | 206,086,675 | false | null | import kotlin.math.max
import kotlin.math.min
class Solution {
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
val totalSize = nums1.size + nums2.size
val totalMid = totalSize / 2
val odd = totalSize % 2 == 1
val longerNums: IntArray
val shorterNums: ... | 0 | Kotlin | 0 | 0 | 20e8b77049fde293b5b1b3576175eb5703c81ce2 | 1,951 | leetcode-solutions-kotlin | MIT License |
src/day23/a/day23a.kt | pghj | 577,868,985 | false | {"Kotlin": 94937} | package day23.a
import readInputLines
import shouldBe
import util.IntVector
import vec
fun main() {
val map = read()
map.simulate(10)
val answer = map.width() * map.height() - map.elves.size
shouldBe(3812, answer)
}
class Ground(
val elves: HashMap<IntVector, Elf>
) {
fun print() {
v... | 0 | Kotlin | 0 | 0 | 4b6911ee7dfc7c731610a0514d664143525b0954 | 3,717 | advent-of-code-2022 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions15.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
fun test15() {
printlnResult("abc", "cbadabacg")
}
/**
* Questions 15: Find all anagrams of s1 in s2, return the indexes
*/
private fun findAnagrams(s1: String, s2: String): List<Int> {
require(s2.length >= s1.length) { "The input is illegal" }
val s1CharMap = Has... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,168 | Algorithm | Apache License 2.0 |
proyecto-1/codigo/VerificadorTSP.kt | lmisea | 640,071,913 | false | null | /**
* Verificador de soluciones para el problema del vendedor viajero
* Recibe como argumentos el archivo de instancia y el archivo de solucion
* Imprime si la solucion es correcta o no y muestra algunos errores si los hay
*/
import java.io.BufferedReader
import java.io.File
import java.io.FileReader
/**
* Funcion: d... | 0 | Kotlin | 1 | 0 | 948a9e52d0760a82a163d01c4361e07a021444cb | 5,397 | lab-algos-2 | MIT License |
advent-of-code-2020/src/main/kotlin/eu/janvdb/aoc2020/day08/Computer.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2020.day08
import eu.janvdb.aocutil.kotlin.readLines
import java.util.function.BiConsumer
import java.util.function.Consumer
class ComputerState {
var programCounter = 0
var accumulator = 0L
}
enum class EndCondition {
NORMAL_END, INFINITE_LOOP
}
class ExitState(val endState: ComputerState, ... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,108 | advent-of-code | Apache License 2.0 |
src/main/kotlin/fr/pturpin/coursera/dynprog/PrimitiveCalculator.kt | TurpIF | 159,055,822 | false | null | package fr.pturpin.coursera.dynprog
class PrimitiveCalculator(private val number: Int) {
private val availableOperations = listOf(
MultByOperation(2),
MultByOperation(3),
AddToOperation(1)
)
private val cache = mutableMapOf<Int, OperationStates>()
fun getMinimumOperationsToCo... | 0 | Kotlin | 0 | 0 | 86860f8214f9d4ced7e052e008b91a5232830ea0 | 2,662 | coursera-algo-toolbox | MIT License |
src/Day01.kt | uzorov | 576,933,382 | false | {"Kotlin": 6068} | import java.io.File
import java.util.*
fun main() {
fun parseInput(input: String): List<List<Int>> = input.split("\n\n").map { elf:String ->
elf.split("\n").map { it.toInt() }
}
fun List<List<Int>>.topNElves(n: Int): Int {
val best: TreeSet<Int> = sortedSetOf<Int>()
for (calories:... | 0 | Kotlin | 0 | 0 | be4ec026f6114f2fa7ae7ebd9b55af9215de8e7b | 977 | aoc-2022-in-kotlin | Apache License 2.0 |
dcp_kotlin/src/main/kotlin/dcp/day280/day280.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day280
// day280.kt
// By <NAME>, 2020.
typealias Vertex = Int
typealias AdjacencyList = Set<Vertex>
typealias AdjacencyGraph = Map<Vertex, AdjacencyList>
/**
* Perform a DFS to search for cycles. If we find, in our DFS, a vertex that is a neighbour of the top vertex of the
* stack that is not its paren... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 2,132 | daily-coding-problem | MIT License |
src/main/java/aoc/xxi/Day5.kt | XuaTheGrate | 434,629,962 | false | {"Kotlin": 19136} | package aoc.xxi
class Day5: DayXXI() {
override val dayNum = 5
data class Vector2(val x1: Int, val x2: Int, val y1: Int, val y2: Int)
private val geysers = data.map {
val (start, end) = it.split(" -> ")
val (x1, y1) = start.split(",").map(String::toInt)
val (x2, y2) = end.split(",... | 0 | Kotlin | 0 | 1 | 7caeac6fe5c51b853eb59526306401ba516bcea8 | 2,013 | Advent-of-Code | The Unlicense |
Myjava/projects/src/com/learn/day05/19. 黑马商店.kt | turbohiro | 158,934,823 | false | {"Java": 96641, "Kotlin": 46735, "HTML": 27149, "Shell": 16087, "Batchfile": 6794} | package com.learn.day05
/**函数式编程的训练
*
*/
data class Product(val name:String, val price:Double)
data class Order(val products:List<Product>,val isDelivered:Boolean)
data class Customer(val name:String,val city:String,val orders:List<Order>)
data class Shop(val name:String,val customers:List<Customer>)
//模拟产品数据
val ... | 0 | Java | 0 | 0 | 55268b5c1c5e202641fd1acfce4e842d8567f9e0 | 2,216 | kotlin_learning | MIT License |
30-days-leetcoding-challenge/April 27/src/Solution.kt | alexey-agafonov | 240,769,182 | false | null | import kotlin.math.max
import kotlin.math.min
class Solution {
fun maximalSquare(matrix: Array<CharArray>): Int {
if (matrix.isEmpty()) {
return 0
}
var result = 0
val dp = Array(matrix.size) { IntArray(matrix[0].size) }
for (i in matrix.indices) {
... | 0 | Kotlin | 0 | 0 | d43d9c911c6fd89343e392fd6f93b7e9d02a6c9e | 1,395 | leetcode | MIT License |
src/Day05.kt | colund | 573,040,201 | false | {"Kotlin": 10244} | fun main() {
println("Day5 part 1: " + day5(::part1))
println("Day5 part 2: " + day5(::part2))
}
private fun day5(
doInstruction: (
count: Int,
stacks: MutableList<MyStack>,
fromIndex: Int,
toIndex: Int
) -> Unit
): String {
val stacks = mutableListOf<MyStack>()
... | 0 | Kotlin | 0 | 0 | 49dcd2fccad0e54ee7b1a9cb99df2acdec146759 | 1,713 | aoc-kotlin-2022 | Apache License 2.0 |
Line_circle_intersection/Kotlin/src/LineCircleIntersection.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 kotlin.math.absoluteValue
import kotlin.math.sqrt
const val eps = 1e-14
class Point(val x: Double, val y: Double) {
override fun toString(): String {
var xv = x
if (xv == 0.0) {
xv = 0.0
}
var yv = y
if (yv == 0.0) {
yv = 0.0
}
... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 4,215 | rosetta | MIT License |
advanced-algorithms/kotlin/src/h1PrecPmtnRFMax.kt | nothingelsematters | 135,926,684 | false | {"Jupyter Notebook": 7400788, "Java": 512017, "C++": 378834, "Haskell": 261217, "Kotlin": 251383, "CSS": 45551, "Vue": 37772, "Rust": 34636, "HTML": 22859, "Yacc": 14912, "PLpgSQL": 10573, "JavaScript": 9741, "Makefile": 8222, "TeX": 7166, "FreeMarker": 6855, "Python": 6708, "OCaml": 5977, "Nix": 5059, "ANTLR": 4802, "... | import java.io.File
import java.util.Scanner
private fun <T> MutableList<T>.addAll(vararg ts: T) = addAll(ts)
data class Job(
val time: Long,
var release: Long,
val index: Int,
val f: (Long) -> Long,
val times: MutableList<Long> = mutableListOf(),
)
private data class Block(val start: Long, var t... | 0 | Jupyter Notebook | 3 | 5 | d442a3d25b579b96c6abda13ed3f7e60d1747b53 | 4,408 | university | Do What The F*ck You Want To Public License |
src/Day01.kt | BrianEstrada | 572,700,177 | false | {"Kotlin": 22757} | fun main() {
fun getElves(input: List<String>): IntArray {
val elfs = IntArray(input.count { it.isEmpty() } + 1) { 0 }
var elfIndex = 0
for (value in input) {
if (value.isEmpty()) {
elfIndex++
} else {
elfs[elfIndex] += value.toInt()
... | 1 | Kotlin | 0 | 1 | 032a4693aff514c9b30e979e63560dc48917411d | 797 | aoc-kotlin-2022 | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/swap_nodes_in_pairs/SwapNodesInPairs.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.swap_nodes_in_pairs
import katas.kotlin.leetcode.ListNode
import katas.kotlin.leetcode.listNodes
import datsok.shouldEqual
import org.junit.Test
/**
* https://leetcode.com/problems/swap-nodes-in-pairs
*/
class SwapNodesInPairsTests {
@Test fun `swap every two adjacent nodes`() {
... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,364 | katas | The Unlicense |
PeakInArray.kt | prashantsinghpaliwal | 537,191,958 | false | {"Kotlin": 9473} | // Question Link - https://leetcode.com/problems/find-peak-element/
fun main() {
val arr = arrayOf(2, 3, 4, 7, 8, 6, 5, 1)
println(findPeak(arr))
}
fun findPeak(
arr: Array<Int>
): Int {
var start = 0
var end = arr.size -1
while (start < end) {
val mid = start + (end - start) / 2
... | 0 | Kotlin | 0 | 0 | e66599817508beb4e90de43305939d200a9e3964 | 1,287 | DsAlgo | Apache License 2.0 |
src/day19.kt | eldarbogdanov | 577,148,841 | false | {"Kotlin": 181188} | import kotlin.math.max
fun main() {
data class State(
val oreRobots: Int, val clayRobots: Int, val obsidianRobots: Int, val geodeRobots: Int,
val clay: Int, val obsidian: Int, val geode: Int
) {
fun next(): State {
return State(
oreRobots, clayRobots, obsidia... | 0 | Kotlin | 0 | 0 | bdac3ab6cea722465882a7ddede89e497ec0a80c | 4,390 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/colinodell/advent2021/Day14.kt | colinodell | 433,864,377 | true | {"Kotlin": 111114} | package com.colinodell.advent2021
class Day14(input: List<String>) {
private val template = input[0]
private val insertionRules = input.drop(2).map { line ->
line.split(" -> ").let { it[0] to it[0][0] + it[1] + it[0][1] }
}.toMap()
fun solvePart1() = polymerizeAndCalculateAnswer(10)
fun so... | 0 | Kotlin | 0 | 1 | a1e04207c53adfcc194c85894765195bf147be7a | 1,201 | advent-2021 | Apache License 2.0 |
scripts/Day18.kts | matthewm101 | 573,325,687 | false | {"Kotlin": 63435} | import java.io.File
data class Cube(val x: Int, val y: Int, val z: Int) {
operator fun plus(c: Cube) = Cube(x+c.x,y+c.y,z+c.z)
fun neighbors() = listOf(Cube(1,0,0),Cube(-1,0,0),Cube(0,1,0),Cube(0,-1,0),Cube(0,0,1),Cube(0,0,-1)).map { this + it }
}
val droplet = File("../inputs/18.txt").readLines().map { val s... | 0 | Kotlin | 0 | 0 | bbd3cf6868936a9ee03c6783d8b2d02a08fbce85 | 1,366 | adventofcode2022 | MIT License |
src/main/kotlin/day2.kt | sviams | 726,160,356 | false | {"Kotlin": 9233} | object day2 {
data class DrawSet(val red: Int, val green: Int, val blue: Int)
data class Game(val id: Int, val sets: List<DrawSet>) {
val power: Int by lazy { sets.maxOf { it.red } * sets.maxOf { it.blue } * sets.maxOf { it.green } }
fun withinLimit(r: Int, b: Int, g: Int): Boolean = sets.all {... | 0 | Kotlin | 0 | 0 | 4914a54b21e8aac77ce7bbea3abc88ac04037d50 | 1,278 | aoc23 | Apache License 2.0 |
app/src/main/kotlin/advent_of_code/year_2021/AdventOfCode2021.kt | mavomo | 574,441,138 | false | {"Kotlin": 56468} | package advent_of_code.year_2021
class AdventOfCode2021 {
fun countingDepthMeasurementIncreases(report: List<Int>): Int {
var increaseCounter = 0
for (depth in report.withIndex()) {
val depthValue = depth.value
val nextIdx = depth.index + 1
if (nextIdx < report.... | 0 | Kotlin | 0 | 0 | b7fec100ea3ac63f48046852617f7f65e9136112 | 2,066 | advent-of-code | MIT License |
src/Day17-delete.kt | p357k4 | 573,068,508 | false | {"Kotlin": 59696} | package ndrsh.puzzles.adventofcode2022
import java.io.File
// positions are represented as ints, a position with coords x,y (where y increases as rocks fall) is represented as k = y*cols + x
typealias Rocks = List<Int>
val rows = 20_000
val cols = 7
val bottom = rows*cols
val line = File("src/Day17_test.txt").readLi... | 0 | Kotlin | 0 | 0 | b9047b77d37de53be4243478749e9ee3af5b0fac | 2,856 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/kishor/kotlin/algo/problems/arrayandstrings/PairSum.kt | kishorsutar | 276,212,164 | false | null | package com.kishor.kotlin.algo.problems.arrayandstrings
fun main(args: Array<String>) {
println(numberOfWays(arrayOf(1, 2, 3, 4, 3), 6))
println(numberOfWays(arrayOf(1, 5, 3, 3, 3), 6))
println(numberOfWaysUsingHashSet(arrayOf(1, 2, 3, 4, 3), 6))
println(numberOfWaysUsingHashSet(arrayOf(1, 5, 3, 3, 3),... | 0 | Kotlin | 0 | 0 | 6672d7738b035202ece6f148fde05867f6d4d94c | 1,210 | DS_Algo_Kotlin | MIT License |
src/Day01.kt | eps90 | 574,098,235 | false | {"Kotlin": 9738} | fun main() {
fun caloriesPerElf(input: List<String>): List<Int> {
return input
.fold(mutableListOf()) { acc, s ->
if (s.isEmpty()) {
acc.add(0)
acc
} else {
val lastElem = acc.lastOrNull() ?: 0
... | 0 | Kotlin | 0 | 0 | bbf58c512fddc0ef1112c3bee5e5c6d43f5aabc0 | 949 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/io/jadon/election/model.kt | phase | 277,456,271 | false | null | package io.jadon.election
import java.util.*
import kotlin.math.abs
import kotlin.math.floor
import kotlin.math.pow
/**
* Categories of issues
*/
enum class Category {
ECONOMIC, // Equalities <-> Markets
DIPLOMATIC, // Nation <-> World
CIVIL, // Liberty <-> Authority
SOCIETAL // Tradition <-> Progre... | 0 | Kotlin | 0 | 7 | 3002e4a2082a35fb9735f4bd5574ca51b9dff1a5 | 7,548 | electoral-systems | The Unlicense |
src/main/kotlin/day02/RockPaperScissors.kt | iamwent | 572,947,468 | false | {"Kotlin": 18217} | package day02
import readInput
class RockPaperScissors(
private val name: String
) {
private fun readRockPaperScissors(): List<Pair<Char, Char>> {
return readInput(name).map { line ->
return@map (line.first()) to (line.last())
}
}
fun part1(): Int {
return readRock... | 0 | Kotlin | 0 | 0 | 77ce9ea5b227b29bc6424d9a3bc486d7e08f7f58 | 1,228 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day5.kt | andilau | 433,504,283 | false | {"Kotlin": 137815} | package days
import kotlin.math.absoluteValue
@AdventOfCodePuzzle(
name = "Hydrothermal Venture",
url = "https://adventofcode.com/2021/day/5",
date = Date(day = 5, year = 2021)
)
class Day5(input: List<String>) : Puzzle {
private val lines = input.map { Line.from(it) }.toSet()
override fun partOn... | 0 | Kotlin | 0 | 0 | b3f06a73e7d9d207ee3051879b83e92b049a0304 | 2,057 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/algorithm/core.kt | Tiofx | 175,697,373 | false | null | package algorithm
open class Program(operators: List<IOperator>) : List<IOperator> by operators, Relations {
inline fun S(i: Int) = get(i)
override val operators: List<IOperator> get() = this
fun I(operator: Int) = this[operator].R.filter { it !in this.take(operator).flatMap(IOperator::C) }.toSet()
f... | 0 | Kotlin | 0 | 0 | 32c1cc3e95940e377ed9a99293eccc871ce13864 | 1,709 | CPF | The Unlicense |
year2017/src/main/kotlin/net/olegg/aoc/year2017/day16/Day16.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2017.day16
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2017.DayOf2017
/**
* See [Year 2017, Day 16](https://adventofcode.com/2017/day/16)
*/
object Day16 : DayOf2017(16) {
override fun first(): Any? {
return data
.split(",")
.fold(StringBuilder("abcdefgh... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 2,534 | adventofcode | MIT License |
src/main/java/com/barneyb/aoc/aoc2022/day10/CathodeRayTube.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2022.day10
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toInt
import com.barneyb.aoc.util.toSlice
fun main() {
Solver.execute(
::parse,
::signalStrengths,
::render, // RBPARAGF
)
}
internal data class State(
val cycle: Int = 0,
val ... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 1,557 | aoc-2022 | MIT License |
src/main/kotlin/algorithms/ManhattanTouristProblem.kt | jimandreas | 377,843,697 | false | null | @file:Suppress("SameParameterValue", "UnnecessaryVariable", "UNUSED_VARIABLE", "ControlFlowWithEmptyBody", "unused")
package algorithms
import kotlin.math.max
/**
* Code Challenge: Find the length of a longest path in the Manhattan Tourist Problem.
*
* See also:
* stepik: @link: https://stepik.org/lesson/240301/... | 0 | Kotlin | 0 | 0 | fa92b10ceca125dbe47e8961fa50242d33b2bb34 | 3,369 | stepikBioinformaticsCourse | Apache License 2.0 |
src/main/kotlin/com/github/davio/aoc/y2021/Day3.kt | Davio | 317,510,947 | false | {"Kotlin": 405939} | package com.github.davio.aoc.y2021
import com.github.davio.aoc.general.Day
import com.github.davio.aoc.general.getInputAsList
import java.util.function.BiPredicate
import kotlin.math.pow
fun main() {
Day3.getResultPart1()
Day3.getResultPart2()
}
object Day3 : Day() {
/*
--- Day 3: Binary Diagnostic ---
... | 1 | Kotlin | 0 | 0 | 4fafd2b0a88f2f54aa478570301ed55f9649d8f3 | 7,751 | advent-of-code | MIT License |
src/questions/RomanToInteger.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import java.util.*
import kotlin.collections.LinkedHashMap
import kotlin.test.assertEquals
/**
* Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
* I = 1, V=5, X = 10, L = 50, C = 100, D = 500, M = 1000
*
* For example, 2 ... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,263 | algorithms | MIT License |
year2021/day02/part1/src/main/kotlin/com/curtislb/adventofcode/year2021/day02/part1/Year2021Day02Part1.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Day 2: Dive! ---
Now, you need to figure out how to pilot this thing.
It seems like the submarine can take a series of commands like `forward 1`, `down 2`, or `up 3`:
- `forward X` increases the horizontal position by X units.
- `down X` increases the depth by X units.
- `up X` decreases the depth by X units.... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,394 | AdventOfCode | MIT License |
src/Day04.kt | AleksanderBrzozowski | 574,061,559 | false | null | fun main() {
fun IntRange.fullyOverlaps(other: IntRange) = this.first >= other.first && this.last <= other.last
fun IntRange.partiallyOverlaps(other: IntRange) = this.any { other.contains(it) }
fun String.toRange(): Pair<IntRange, IntRange> {
val (firstRange, secondRange) = split(",")
... | 0 | Kotlin | 0 | 0 | 161c36e3bccdcbee6291c8d8bacf860cd9a96bee | 935 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g0901_1000/s0990_satisfiability_of_equality_equations/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s0990_satisfiability_of_equality_equations
// #Medium #Array #String #Graph #Union_Find
// #2023_05_11_Time_163_ms_(100.00%)_Space_37.6_MB_(100.00%)
class Solution {
private lateinit var par: IntArray
fun equationsPossible(equations: Array<String>): Boolean {
var counter = 0
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,568 | LeetCode-in-Kotlin | MIT License |
2022/src/main/kotlin/Day09.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | import kotlin.math.abs
import kotlin.math.sign
object Day09 {
fun part1(input: String) = simulateRope(input, 2)
fun part2(input: String) = simulateRope(input, 10)
private fun simulateRope(input: String, size: Int): Int {
val rope = MutableList(size) { Point(0, 0) }
val tailsVisited = mutableSetOf(rope... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 1,282 | advent-of-code | MIT License |
app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/challenges/MathChallenge.kt | ahuamana | 627,986,788 | false | null | package com.lukaslechner.coroutineusecasesonandroid.playground.challenges
// Challenge
// Have the function MathChallenge(str) take the str parameter, which will be a simple mathematical formula with three numbers, a single operator (+, -, *, or /) and an equal sign (=) and return the digit that completes the equation... | 0 | Kotlin | 0 | 0 | 931ce884b8c70355e38e007141aab58687ed1909 | 3,086 | KotlinCorutinesExpert | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.