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/g2001_2100/s2014_longest_subsequence_repeated_k_times/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2014_longest_subsequence_repeated_k_times
// #Hard #String #Greedy #Backtracking #Counting #Enumeration
// #2023_06_23_Time_333_ms_(100.00%)_Space_39_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
fun longestSubsequenceRepeatedK(s: String, k: Int): String {
val ca = s.toChar... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,645 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/daytwelve/DayTwelve.kt | pauliancu97 | 619,525,509 | false | null | package daytwelve
import getLines
import java.util.PriorityQueue
import kotlin.math.abs
import kotlin.math.min
private typealias Matrix = MutableList<MutableList<Int>>
private val Matrix.rows: Int
get() = this.size
private val Matrix.cols: Int
get() = this.first().size
private operator fun Matrix.get(coord... | 0 | Kotlin | 0 | 0 | 78af929252f094a34fe7989984a30724fdb81498 | 5,853 | advent-of-code-2022 | MIT License |
src/Day21.kt | Riaz1 | 577,017,303 | false | {"Kotlin": 15653} |
fun main() {
data class LineItem(
val key1: String,
val operator: String,
val key2: String,
var result: Double?
)
val fileName =
"Day21_input"
// "Day21_sample"
val steps = readInput(fileName).associateBy(
keySelector = {v -> v.substringBefore(":... | 0 | Kotlin | 0 | 0 | 4d742e404ece13203319e1923ffc8e1f248a8e15 | 1,910 | aoc2022 | Apache License 2.0 |
src/main/kotlin/days/Day7.kt | vovarova | 726,012,901 | false | {"Kotlin": 48551} | package days
import util.DayInput
class Day7 : Day("7") {
class HandBet(val hand: Hand, val bet: Int)
class Hand(val handString: String)
class HandRulesPart1(val hand: Hand) {
val map = hand.handString.groupingBy { it }.eachCount()
val cardRate = mapOf(
Pair('2', 2),
... | 0 | Kotlin | 0 | 0 | 77df1de2a663def33b6f261c87238c17bbf0c1c3 | 5,422 | adventofcode_2023 | Creative Commons Zero v1.0 Universal |
Rationals/src/rationals/Rational.kt | Sharkaboi | 258,941,707 | false | null | package rationals
import java.lang.IllegalArgumentException
import java.math.BigInteger
class Rational(private var numerator: BigInteger, private var denominator: BigInteger):Comparable<Rational> {
init {
if (denominator == BigInteger.ZERO)
throw IllegalArgumentException()
else if (den... | 0 | Kotlin | 0 | 0 | 977968b41ecc0ed1b62b50784bfebc3fa9d95a11 | 5,140 | Kotlin-for-java-devs-course | MIT License |
src/day01/Day01.kt | EndzeitBegins | 573,569,126 | false | {"Kotlin": 111428} | package day01
import readInput
import readTestInput
private fun List<String>.toSnackSumSequence(): Sequence<Int> = sequence {
var sum = 0
for (item in this@toSnackSumSequence) {
if (item.isBlank()) {
this.yield(sum)
sum = 0
} else {
sum += item.toInt()
... | 0 | Kotlin | 0 | 0 | ebebdf13cfe58ae3e01c52686f2a715ace069dab | 898 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day04.kt | mnajborowski | 573,619,699 | false | {"Kotlin": 7975} | fun main() {
fun part1(input: List<String>): Int =
input
.map { pairRangesString ->
pairRangesString.split(',', '-')
.let { it[0].toInt()..it[1].toInt() to it[2].toInt()..it[3].toInt() }
}
.count { (firstRange, secondRange) ->
... | 0 | Kotlin | 0 | 0 | e54c13bc5229c6cb1504db7e3be29fc9b9c4d386 | 884 | advent-of-code-2022 | Apache License 2.0 |
mobile/src/main/java/ch/epfl/sdp/mobile/application/tournaments/PoolResults.kt | epfl-SDP | 462,385,783 | false | {"Kotlin": 1271815, "Shell": 359} | package ch.epfl.sdp.mobile.application.tournaments
import androidx.compose.ui.util.fastSumBy
import ch.epfl.sdp.mobile.application.ChessDocument
import ch.epfl.sdp.mobile.application.ChessMetadata.Companion.BlackWon
import ch.epfl.sdp.mobile.application.ChessMetadata.Companion.Stalemate
import ch.epfl.sdp.mobile.appli... | 15 | Kotlin | 2 | 13 | 71f6e2a5978087205b35f82e89ed4005902d697e | 2,742 | android | MIT License |
src/main/kotlin/g1701_1800/s1775_equal_sum_arrays_with_minimum_number_of_operations/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1701_1800.s1775_equal_sum_arrays_with_minimum_number_of_operations
// #Medium #Array #Hash_Table #Greedy #Counting
// #2023_06_18_Time_529_ms_(100.00%)_Space_52.7_MB_(100.00%)
class Solution {
fun minOperations(nums1: IntArray, nums2: IntArray): Int {
val longer = if (nums1.size > nums2.size) num... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,038 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/org/softlang/util/Algorithms.kt | lukashaertel | 80,610,151 | false | null | package org.softlang.util
/**
* Mapper of object types to indices, used in algorithms that are index based
*/
data class Mapper<T>(val forward: Map<T, Int>, val backward: Map<Int, T>) {
/**
* Number of mapped objects.
*/
val size get() = forward.size
operator fun get(item: T) = forward.getValu... | 0 | Kotlin | 0 | 0 | ddeb400bcca9ee5547ee09034458f423589312d8 | 6,405 | megal-vm | MIT License |
src/Day02.kt | morris-j | 573,197,835 | false | {"Kotlin": 7085} | fun main() {
fun scorePlay(play: String): Int {
return when(play) {
"A" -> 1
"B" -> 2
"C" -> 3
else -> 0
}
}
fun scoreOutcome(opponent: String, play: String): Int {
return when(opponent) {
// Rock
"A" -> when(p... | 0 | Kotlin | 0 | 0 | e3f2d02dad432dbc1b15c9e0eefa7b35ace0e316 | 2,661 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/sschr15/aocsolutions/util/watched/WatchedIntegerIterables.kt | sschr15 | 317,887,086 | false | {"Kotlin": 184127, "TeX": 2614, "Python": 446} | @file:OptIn(ExperimentalTypeInference::class)
package sschr15.aocsolutions.util.watched
import kotlin.experimental.ExperimentalTypeInference
fun Iterable<WatchedInt>.sum() = fold(0.watched()) { acc, i -> acc + i }
fun Iterable<WatchedInt>.product() = fold(1.watched()) { acc, i -> acc * i }
fun Iterable<WatchedInt>.a... | 0 | Kotlin | 0 | 0 | e483b02037ae5f025fc34367cb477fabe54a6578 | 1,658 | advent-of-code | MIT License |
src/Day10.kt | timmiller17 | 577,546,596 | false | {"Kotlin": 44667} | fun main() {
fun part1(input: List<String>): Int {
val instructions = input.map { it.split(' ') }
var cycleCounter = 0
var X = 1
var signalStrengthSum = 0
fun runCycle() {
cycleCounter++
if (listOf(20, 60, 100, 140, 180, 220).contains(cycleCounter)) ... | 0 | Kotlin | 0 | 0 | b6d6b647c7bb0e6d9e5697c28d20e15bfa14406c | 2,248 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/sschr15/aocsolutions/Day11.kt | sschr15 | 317,887,086 | false | {"Kotlin": 184127, "TeX": 2614, "Python": 446} | package sschr15.aocsolutions
import sschr15.aocsolutions.util.*
import kotlin.math.absoluteValue
/**
* AOC 2023 [Day 11](https://adventofcode.com/2023/day/11)
* Challenge: whoops our spacetime is destroying itself right in front of our eyes
*/
object Day11 : Challenge {
@ReflectivelyUsed
override fun solve... | 0 | Kotlin | 0 | 0 | e483b02037ae5f025fc34367cb477fabe54a6578 | 2,593 | advent-of-code | MIT License |
src/Day01.kt | GarrettShorr | 571,769,671 | false | {"Kotlin": 82669} | import java.lang.Exception
fun main() {
fun part1(input: List<String>): Int {
val elves = mutableListOf<Int>()
var totalCalories = 0
for(food in input) {
if (food != "") {
totalCalories += food.toInt()
} else {
elves.add(totalCalories)
totalCalories = 0
}
}
... | 0 | Kotlin | 0 | 0 | 391336623968f210a19797b44d027b05f31484b5 | 1,105 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/g1901_2000/s1964_find_the_longest_valid_obstacle_course_at_each_position/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1901_2000.s1964_find_the_longest_valid_obstacle_course_at_each_position
// #Hard #Array #Binary_Search #Binary_Indexed_Tree
// #2023_06_21_Time_846_ms_(40.00%)_Space_52.5_MB_(99.09%)
@Suppress("NAME_SHADOWING")
class Solution {
fun longestObstacleCourseAtEachPosition(obstacles: IntArray): IntArray {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,407 | LeetCode-in-Kotlin | MIT License |
src/main/java/challenges/educative_grokking_coding_interview/fast_slow_pointers/_4/CircularArrayLoop.kt | ShabanKamell | 342,007,920 | false | null | package challenges.educative_grokking_coding_interview.fast_slow_pointers._4
import java.util.*
/**
An input array, nums containing non-zero integers, is given, where the value at each index represents the number of places to skip forward (if the value is positive) or backward (if the value is negative). When skippin... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 4,140 | CodingChallenges | Apache License 2.0 |
src/main/kotlin/day14/Day14.kt | daniilsjb | 572,664,294 | false | {"Kotlin": 69004} | package day14
import java.io.File
import kotlin.math.min
import kotlin.math.max
fun main() {
val data = parse("src/main/kotlin/day14/Day14.txt")
val answer1 = part1(data)
val answer2 = part2(data)
println("🎄 Day 14 🎄")
println()
println("[Part 1]")
println("Answer: $answer1")
pr... | 0 | Kotlin | 0 | 0 | 6f0d373bdbbcf6536608464a17a34363ea343036 | 3,061 | advent-of-code-2022 | MIT License |
android/src/main/kotlin/com/cloudwebrtc/webrtc/model/VideoConstraints.kt | krida2000 | 510,302,729 | false | null | package com.cloudwebrtc.webrtc.model
import org.webrtc.CameraEnumerator
/**
* Direction in which the camera produces the video.
*
* @property value [Int] representation of this enum which will be expected on the Flutter side.
*/
enum class FacingMode(val value: Int) {
/**
* Indicates that the video source is... | 0 | Rust | 0 | 0 | 146467b24dd16a2786c3843f773cd08da68bc83c | 7,320 | webrtc | MIT License |
2023/09/Solution.kt | AdrianMiozga | 588,519,359 | false | {"Kotlin": 110785, "Python": 11275, "Assembly": 3369, "C": 2378, "Pawn": 1390, "Dart": 732} | import java.io.File
private const val FILENAME = "2023/09/input.txt"
fun main() {
partOne()
partTwo()
}
private fun partOne() {
val file = File(FILENAME).readLines()
.map { it -> it.split(" ").map { it.toInt() } }
var sum = 0
for (line in file) {
val sequence: MutableList<Mutabl... | 0 | Kotlin | 0 | 0 | c9cba875089d8d4fb145932c45c2d487ccc7e8e5 | 1,823 | Advent-of-Code | MIT License |
src/net/sheltem/aoc/y2022/Day07.kt | jtheegarten | 572,901,679 | false | {"Kotlin": 178521} | package net.sheltem.aoc.y2022
const val maxSpace: Long = 70_000_000
const val spaceNeeded: Long = 30_000_000
suspend fun main() {
Day07().run()
}
class Day07 : Day<Long>(95437, 24933642) {
override suspend fun part1(input: List<String>): Long = input.buildTree().getAllFolders().map { it.size }.filter { it <... | 0 | Kotlin | 0 | 0 | ac280f156c284c23565fba5810483dd1cd8a931f | 1,827 | aoc | Apache License 2.0 |
src/main/kotlin/g1301_1400/s1367_linked_list_in_binary_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1301_1400.s1367_linked_list_in_binary_tree
// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Linked_List
// #Programming_Skills_II_Day_4 #2023_06_06_Time_237_ms_(92.86%)_Space_39.4_MB_(78.57%)
import com_github_leetcode.ListNode
import com_github_leetcode.TreeNode
/*
* Example:
* va... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,430 | LeetCode-in-Kotlin | MIT License |
Lab6/src/main/kotlin/GrahamMethod.kt | knu-3-velychko | 276,473,844 | false | null | //Graham Algorithm for sorted points set
class GrahamMethod(private val points: MutableList<Point>) {
val hull by lazy {
if (points.size <= 3) {
points.toList()
} else {
val start = getLowest()
val ind = points.indexOf(start)
points[ind] = points[0]
... | 0 | Kotlin | 0 | 0 | b16603d78bf44f927f4f6389754a5d015a25f7e2 | 1,524 | ComputerGraphics | MIT License |
src/Day04.kt | Advice-Dog | 436,116,275 | true | {"Kotlin": 25836} | fun main() {
fun part1(input: List<String>): Int {
val board = input.toBoard()
board.numbers.forEach {
println("Calling number: $it")
board.call(it)
val bingo = board.boards.find { it.hasBingo() }
if (bingo != null) {
println("BINGO"... | 0 | Kotlin | 0 | 0 | 2a2a4767e7f0976dba548d039be148074dce85ce | 3,257 | advent-of-code-kotlin-template | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LuckyNumbersInMatrix.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,172 | kotlab | Apache License 2.0 |
src/main/kotlin/g2701_2800/s2709_greatest_common_divisor_traversal/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2701_2800.s2709_greatest_common_divisor_traversal
// #Hard #Array #Math #Union_Find #Number_Theory
// #2023_07_31_Time_892_ms_(81.82%)_Space_73.7_MB_(81.82%)
@Suppress("NAME_SHADOWING")
class Solution {
private var map: MutableMap<Int, Int>? = null
private lateinit var set: IntArray
private fun ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,783 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem74/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem74
/**
* LeetCode page: [74. Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/);
*/
class Solution {
/* Complexity:
* Time O(LogM+LogN) and Space O(1) where M and N are the number of rows and columns in matrix;
*/
fun searchMatrix(matrix: Ar... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,254 | hj-leetcode-kotlin | Apache License 2.0 |
kotlin/graphs/flows/MaxFlowEdmondsKarp.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package graphs.flows
import java.util.stream.Stream
// https://en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm in O(V * E^2)
class MaxFlowEdmondsKarp(nodes: Int) {
var graph: Array<List<Edge>>
inner class Edge(var s: Int, var t: Int, var rev: Int, var cap: Int) {
var f = 0
}
fun addBidi... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 2,026 | codelibrary | The Unlicense |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions27.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 test27() {
printlnResult(SingleDirectionNode(element = 8, next = SingleDirectionNode(element = 8)))
printlnResult(SingleDirectionNode(element = 8, next ... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 3,170 | Algorithm | Apache License 2.0 |
advent/src/test/kotlin/org/elwaxoro/advent/y2021/Dec12.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2021
import org.elwaxoro.advent.Node
import org.elwaxoro.advent.PuzzleDayTester
/**
* Passage Pathing
*/
class Dec12 : PuzzleDayTester(12, 2021) {
override fun part1(): Any = parse().let { nodes ->
val start = nodes["start"]!!
// reserve the special small cave ahead... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 2,283 | advent-of-code | MIT License |
src/main/kotlin/day5/Day5.kt | mortenberg80 | 574,042,993 | false | {"Kotlin": 50107} | package day5
class Day5 {
fun getOrganizer(filename: String): CrateOrganizer {
val readLines = this::class.java.getResourceAsStream(filename).bufferedReader().readLines()
return CrateOrganizer(readLines)
}
}
/*
[N] [C] [Z]
[Q] [G] [V] [S] [V]
[L] [C] [M] [T... | 0 | Kotlin | 0 | 0 | b21978e145dae120621e54403b14b81663f93cd8 | 5,395 | adventofcode2022 | Apache License 2.0 |
src/Day06.kt | zirman | 572,627,598 | false | {"Kotlin": 89030} | fun main() {
fun part(input: List<String>, startOfPacketSize: Int): Int {
return input[0].windowed(startOfPacketSize, 1)
.indexOfFirst { it.toSet().size == startOfPacketSize } + startOfPacketSize
}
fun part1(input: List<String>): Int {
return part(input, 4)
}
fun part2(... | 0 | Kotlin | 0 | 1 | 2ec1c664f6d6c6e3da2641ff5769faa368fafa0f | 1,068 | aoc2022 | Apache License 2.0 |
src/Day24.kt | Allagash | 572,736,443 | false | {"Kotlin": 101198} | import java.io.File
import java.lang.Exception
import java.util.*
import kotlin.math.abs
import kotlin.system.measureTimeMillis
// Advent of Code 2022, Day 24: <NAME>
class Day24(input: String) {
private val startCol: Int
private val endCol: Int
private val startPos: Pt
private val endPos: Pt
priv... | 0 | Kotlin | 0 | 0 | 8d5fc0b93f6d600878ac0d47128140e70d7fc5d9 | 7,117 | AdventOfCode2022 | Apache License 2.0 |
src/day13/Day13.kt | pnavais | 574,712,395 | false | {"Kotlin": 54079} | package day13
import readInput
import java.util.Stack
typealias PacketPair = Pair<Packet, Packet>
interface Value {
fun getData(): Any
}
class IntValue(private val data: Int) : Value {
override fun getData(): Int {
return this.data
}
companion object {
fun from(s: String): IntValue {... | 0 | Kotlin | 0 | 0 | ed5f521ef2124f84327d3f6c64fdfa0d35872095 | 6,527 | advent-of-code-2k2 | Apache License 2.0 |
codeforces/eduround68/YetAnotherCrossesProblem.kt | grine4ka | 183,575,046 | false | {"Kotlin": 98723, "Java": 28857, "C++": 4529} | package codeforces.eduround68
import java.io.PrintWriter
import kotlin.math.min
// https://codeforces.com/contest/1194/problem/B
// this is mine
//fun eduround68.eduround68.eduround68.round567.round567.round573.codeforces.codeforces.codeforces.eduround69.kotlinheroes.kotlinheroes.main(args: Array<String>) {
// val... | 0 | Kotlin | 0 | 0 | c967e89058772ee2322cb05fb0d892bd39047f47 | 2,708 | samokatas | MIT License |
src/main/kotlin/days/aoc2023/Day15.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2023
import days.Day
class Day15 : Day(2023, 15) {
override fun partOne(): Any {
return calculatePartOne(inputString)
}
override fun partTwo(): Any {
return calculatePartTwo(inputString)
}
fun calculatePartOne(input: String): Int {
return input.split(",").... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 1,851 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
app/src/main/java/com/softaai/dsa_kotlin/radixsort/RadixSort.kt | amoljp19 | 537,774,597 | false | {"Kotlin": 139041} | package com.softaai.dsa_kotlin.radixsort
/**
* Created by amoljp19 on 11/22/2022.
* softAai Apps.
*/
fun MutableList<Int>.radixSort(){
val base = 10
var done = false
var digits = 1
while (!done){
done = true
val buckets = arrayListOf<MutableList<Int>>().apply {
for (i... | 0 | Kotlin | 0 | 1 | 3dabfbb1e506bec741aed3aa13607a585b26ac4c | 2,834 | DSA_KOTLIN | Apache License 2.0 |
src/Day03.kt | frango9000 | 573,098,370 | false | {"Kotlin": 73317} | fun main() {
val input = readInput("Day03")
println(Day03.part1(input))
println(Day03.part2(input))
}
class Day03 {
companion object {
fun part1(input: List<String>): Int {
return input.map { it.chunked(it.length / 2) }
.map { it[0].filter { x -> it[1].contains(x) }.... | 0 | Kotlin | 0 | 0 | 62e91dd429554853564484d93575b607a2d137a3 | 697 | advent-of-code-22 | Apache License 2.0 |
jvm/src/main/kotlin/boj/ChickenDelivery.kt | imdudu1 | 196,377,985 | false | {"Java": 47989, "Kotlin": 39952, "Python": 38168, "Go": 15491, "Rust": 2583, "JavaScript": 1023} | package boj
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
class ChickenDelivery constructor(private val map: Array<Array<Int>>) {
private val stores: List<Point> by lazy { getObjects(2) }
private val houses: List<Point> by lazy { getObjects(1) }
... | 0 | Java | 0 | 0 | ee7df895761b095d02a08f762c682af5b93add4b | 1,965 | algorithm-diary | MIT License |
aoc2023/src/main/kotlin/de/havox_design/aoc2023/day21/StepCounter.kt | Gentleman1983 | 737,309,232 | false | {"Kotlin": 746488, "Java": 441473, "Scala": 33415, "Groovy": 5725, "Python": 3319} | package de.havox_design.aoc2023.day21
import de.havox_design.aoc.utils.kotlin.model.directions.UDLRDirection
import de.havox_design.aoc.utils.kotlin.model.positions.Position2d
import kotlin.math.pow
class StepCounter(private var filename: String) {
private val ICON_ROCK = '#'
private val ICON_START = 'S'
... | 4 | Kotlin | 0 | 1 | 35ce3f13415f6bb515bd510a1f540ebd0c3afb04 | 5,757 | advent-of-code | Apache License 2.0 |
src/leetcodeProblem/leetcode/editor/en/ValidSudoku.kt | faniabdullah | 382,893,751 | false | null | //Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be
//validated according to the following rules:
//
//
// Each row must contain the digits 1-9 without repetition.
// Each column must contain the digits 1-9 without repetition.
// Each of the nine 3 x 3 sub-boxes of the grid must contain t... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,952 | dsa-kotlin | MIT License |
src/nativeMain/kotlin/Day7.kt | rubengees | 576,436,006 | false | {"Kotlin": 67428} | class Day7 : Day {
private data class File(val name: String, val size: Int)
private data class Dir(
val name: String,
val parent: Dir? = null
) {
private val dirs = mutableListOf<Dir>()
private val files = mutableListOf<File>()
val size: Int
get() {
... | 0 | Kotlin | 0 | 0 | 21f03a1c70d4273739d001dd5434f68e2cc2e6e6 | 2,485 | advent-of-code-2022 | MIT License |
2017/src/main/kotlin/Day10.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | import utils.splitCommas
import utils.toIntList
import java.util.*
object Day10 {
fun part1(input: String, size: Int = 256): Int {
val list = (0 until size).toMutableList()
val lengths = input.splitCommas().toIntList()
hash(list, lengths)
return list[0] * list[1]
}
fun part2(input: String): Str... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 1,678 | advent-of-code | MIT License |
src/main/aoc2015/Day6.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2015
import Pos
import kotlin.math.max
class Day6(input: List<String>) {
sealed class Instruction(val x: IntRange, val y: IntRange) {
class Toggle(x: IntRange, y: IntRange) : Instruction(x, y) {
override fun op(v: Int, part1: Boolean) = if (part1) (v + 1) % 2 else v + 2
}
... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,984 | aoc | MIT License |
src/Day04.kt | tristanrothman | 572,898,348 | false | null | fun main() {
fun String.toIntRange() = this.substringBefore("-").toInt()..this.substringAfter("-").toInt()
fun String.toIntRanges() = this.substringBefore(",").toIntRange() to this.substringAfter(",").toIntRange()
infix fun IntRange.contains(other: IntRange) = first <= other.first && last >= other.last
... | 0 | Kotlin | 0 | 0 | e794ab7e0d50f22d250c65b20e13d9b5aeba23e2 | 952 | advent-of-code-2022 | Apache License 2.0 |
kotlin/0074-search-a-2d-matrix.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} | // binary search on rows to find row, then binary search on actual row O(log(m*n))
class Solution {
// TC: O(log m + log n)
fun searchMatrix(matrix: Array<IntArray>, target: Int): Boolean {
var row = matrix.size
var col = matrix.first().size
var top = 0
var bot = row - 1
... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 2,010 | leetcode | MIT License |
Möbius_function/Kotlin/src/MobiusFunction.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.sqrt
fun main() {
println("First 199 terms of the möbius function are as follows:")
print(" ")
for (n in 1..199) {
print("%2d ".format(mobiusFunction(n)))
if ((n + 1) % 20 == 0) {
println()
}
}
}
private const val MU_MAX = 1000000
private var ... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 1,334 | rosetta | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/StrangePrinter.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,946 | kotlab | Apache License 2.0 |
algorithm/src/test/kotlin/com/seanshubin/condorcet/algorithm/CondorcetAlgorithmTest.kt | SeanShubin | 190,099,313 | false | null | package com.seanshubin.condorcet.algorithm
import kotlin.test.Test
import kotlin.test.assertEquals
class CondorcetAlgorithmTest {
@Test
fun typical() {
// given
val election = "typical election"
val candidates = setOf("frank", "grace", "eve")
val eligibleVoters = setOf("bob", "... | 2 | Kotlin | 0 | 0 | 61219ae238b47792a5d347625f4963a1b2841d2d | 2,503 | condorcet5 | The Unlicense |
src/main/kotlin/g0401_0500/s0494_target_sum/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0401_0500.s0494_target_sum
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Backtracking
// #Big_O_Time_O(n*(sum+s))_Space_O(n*(sum+s))
// #2022_09_16_Time_308_ms_(89.61%)_Space_37.2_MB_(61.04%)
@Suppress("NAME_SHADOWING")
class Solution {
fun findTargetSumWays(nums: IntArray, target: Int... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,250 | LeetCode-in-Kotlin | MIT License |
aoc-common/src/main/kotlin/nl/jstege/adventofcode/aoccommon/utils/extensions/Collections.kt | JStege1206 | 92,714,900 | false | null | package nl.jstege.adventofcode.aoccommon.utils.extensions
/**
* Extra utilities for lists.
* @author <NAME>
*/
/**
* Transposes a list of lists in 2 dimensional space. This function does not check whether all
* rows have an equal amount of elements. Rather, it assumes all rows have an equal amount of
* elements... | 0 | Kotlin | 0 | 0 | d48f7f98c4c5c59e2a2dfff42a68ac2a78b1e025 | 4,233 | AdventOfCode | MIT License |
src/Day05.kt | luiscobo | 574,302,765 | false | {"Kotlin": 19047} | import java.util.*
fun main() {
val stacks = mutableListOf<Stack<Char>>()
fun crearPilas(n: Int) {
for (i in 0 until n) {
stacks.add(Stack())
}
}
fun procesarLinea(linea: String): Boolean {
if (linea.isNotEmpty()) {
for (i in 1 until linea.length step 4... | 0 | Kotlin | 0 | 0 | c764e5abca0ea40bca0b434bdf1ee2ded6458087 | 2,993 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/at/mpichler/aoc/solutions/year2022/Day04.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2022
import at.mpichler.aoc.lib.Day
import at.mpichler.aoc.lib.PartSolution
import java.lang.RuntimeException
open class Part4A : PartSolution() {
lateinit var pairs: List<String>
override fun parseInput(text: String) {
pairs = text.trim().split("\n")
}
o... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 1,753 | advent-of-code-kotlin | MIT License |
src/Day05.kt | Inn0 | 573,532,249 | false | {"Kotlin": 16938} | data class Move(
val amount: Int,
val from: Int,
val to: Int
)
fun main() {
fun getCargo(input: List<String>): MutableList<MutableList<Char>> {
val inputCargo = input.subList(0, input.indexOf(""))
val cleanedInputCargo = mutableListOf<String>()
var inputSize = 0
inputCar... | 0 | Kotlin | 0 | 0 | f35b9caba5f0c76e6e32bc30196a2b462a70dbbe | 3,538 | aoc-2022 | Apache License 2.0 |
src/poyea/aoc/mmxxii/day03/Day03.kt | poyea | 572,895,010 | false | {"Kotlin": 68491} | package poyea.aoc.mmxxii.day03
import poyea.aoc.utils.readInput
fun part1(input: String): Int {
return input.split("\n").sumOf {
val char = it.substring(0, it.length / 2).toSet().intersect(it.substring(it.length / 2).toSet()).first()
if (char.isLowerCase()) char - 'a' + 1 else char - 'A' + 27
... | 0 | Kotlin | 0 | 1 | fd3c96e99e3e786d358d807368c2a4a6085edb2e | 666 | aoc-mmxxii | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[54]螺旋矩阵.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。
//
//
//
// 示例 1:
//
//
//输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
//输出:[1,2,3,6,9,8,7,4,5]
//
//
// 示例 2:
//
//
//输入:matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]
//输出:[1,2,3,4,8,12,11,10,9,5,6,7]
//
//
//
//
// 提示:
//
//
// m == matrix.length
// n == matrix[i]... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,891 | MyLeetCode | Apache License 2.0 |
src/main/kotlin/com/github/davio/aoc/y2022/Day2.kt | Davio | 317,510,947 | false | {"Kotlin": 405939} | package com.github.davio.aoc.y2022
import com.github.davio.aoc.general.Day
import com.github.davio.aoc.general.call
import com.github.davio.aoc.general.getInputAsSequence
import com.github.davio.aoc.y2022.Day2.Outcome.*
import com.github.davio.aoc.y2022.Day2.RockPaperScissors.*
import kotlin.system.measureTimeMillis
... | 1 | Kotlin | 0 | 0 | 4fafd2b0a88f2f54aa478570301ed55f9649d8f3 | 2,682 | advent-of-code | MIT License |
kotlin/pig-latin/src/main/kotlin/PigLatin.kt | colintheshots | 117,450,747 | false | null | import java.util.*
object PigLatin {
private val vowels = setOf('a','e','i','o','u')
fun translate(input: String) : String {
require(input.all { it.isLowerCase() || it.isWhitespace() })
return input.replace("\\b\\w+\\b".toRegex()) { result : MatchResult ->
val word = result.value
... | 0 | Kotlin | 0 | 0 | f284aecd7f017c3fd972c1dcf9d1c4b25866d614 | 2,482 | ExercismKotlin | Apache License 2.0 |
src/Day05.kt | baghaii | 573,918,961 | false | {"Kotlin": 11922} | import java.util.*
import kotlin.collections.ArrayDeque
fun main() {
fun part1(input: List<String>, stacks: List<Stack<Char>>): String {
input.forEach {
val tokens = it.split(' ')
val howMany = tokens[1].toInt()
val fromStack = tokens[3].toInt() - 1
val toSta... | 0 | Kotlin | 0 | 0 | 8c66dae6569f4b269d1cad9bf901e0a686437469 | 3,569 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/com/ikueb/advent18/Day17.kt | h-j-k | 159,901,179 | false | null | package com.ikueb.advent18
import com.ikueb.advent18.model.*
import java.util.*
object Day17 {
private const val DEFINITION = "(.)=(\\d+), .=(\\d+)..(\\d+)"
private val source = Point(500, 0)
fun getWaterReach(input: List<String>): Int {
val state = process(input)
val yMin = state.getTok... | 0 | Kotlin | 0 | 0 | f1d5c58777968e37e81e61a8ed972dc24b30ac76 | 4,483 | advent18 | Apache License 2.0 |
src/main/kotlin/aoc2022/Day04.kt | davidsheldon | 565,946,579 | false | {"Kotlin": 161960} | package aoc2022
import utils.InputUtils
fun main() {
val testInput = """2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8""".split("\n")
fun String.toIntRange(): IntRange {
val (start, end) = split('-')
return start.toInt()..end.toInt()
}
infix fun IntRange.covers(second: IntRange) = ... | 0 | Kotlin | 0 | 0 | 5abc9e479bed21ae58c093c8efbe4d343eee7714 | 1,263 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/Day10.kt | SimonMarquis | 724,825,757 | false | {"Kotlin": 30983} | import Day10.Pipe.`▉`
class Day10(input: List<String>) {
private val map = input.map { it.map(Char::toChar).map(Pipe.Companion::from).toTypedArray() }.toTypedArray()
private val start: Coordinate = map.withIndex().firstNotNullOf { (y, pipes) ->
pipes.withIndex().firstNotNullOfOrNull { (x, pipe) ->
... | 0 | Kotlin | 0 | 1 | 043fbdb271603c84b7e5eddcd0e8f323c6ebdf1e | 2,804 | advent-of-code-2023 | MIT License |
src/main/kotlin/uk/co/baconi/playground/countdown/calculateSolution.kt | beercan1989 | 482,206,407 | false | {"Kotlin": 8623} | package uk.co.baconi.playground.countdown
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import org.slf4j.LoggerFactory
import kotlin.math.abs
enum class Operation(val perform: (Int, Int) -> Int, private val description: String) {
Add(Int::plus, "+"),
Minus(Int::minus, "-"),
Times(... | 0 | Kotlin | 0 | 0 | 5e8feb7e2b39e40a2f7ea3ff0861f7557831d7b8 | 4,704 | playground-countdown-calculator | Apache License 2.0 |
src/Day01.kt | jpereyrol | 573,074,843 | false | {"Kotlin": 9016} | fun List<String>.getCaloriesPerElfAsList(): List<Int> {
var currentSum = 0
val caloriesPerElf: MutableList<Int> = mutableListOf()
for (line in this) {
if (line == "") {
caloriesPerElf.add(currentSum)
currentSum = 0
} else {
currentSum += line.toInt()
... | 0 | Kotlin | 0 | 0 | e17165afe973392a0cbbac227eb31d215bc8e07c | 894 | advent-of-code | Apache License 2.0 |
src/main/kotlin/_2020/Day11.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2020
import aocRun
fun main() {
aocRun(puzzleInput) { input ->
return@aocRun runSeatModel(
parseSeatLayout(input),
{ seating, x, y -> hasNoAdjacentOccupiedSeats(seating, x, y) },
{ seating, x, y -> has4OrMoreAdjacentOccupiedSeats(seating, x, y) }
)
}
aocRun(puzzleInput) { input ->
return@ao... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 14,299 | AdventOfCode | Creative Commons Zero v1.0 Universal |
AtCoder/abc204/C.kt | thedevelopersanjeev | 112,687,950 | false | null | private fun readLn() = readLine()!!
private fun readLns() = readLn().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readLns().map { it.toInt() }
fun main() {
val (n, m) = readInts()
val adj = ArrayList<ArrayList<Int>>()
for (i in 0 until n) adj.add(ArrayList())
for (i in 0... | 0 | C++ | 58 | 146 | 610520cc396fb13a03c606b5fb6739cfd68cc444 | 807 | Competitive-Programming | MIT License |
src/main/java/com/ncorti/aoc2021/Exercise02.kt | cortinico | 433,486,684 | false | {"Kotlin": 36975} | package com.ncorti.aoc2021
object Exercise02 {
fun part1(): Int =
getInputAsTest("02") { split("\n") }
.map { it.split(" ") }
.map { it[0] to it[1].toInt() }
.fold(0 to 0) { (depth, horizontal), (move, unit) ->
when (move) {
"forward"... | 0 | Kotlin | 0 | 4 | af3df72d31b74857201c85f923a96f563c450996 | 1,208 | adventofcode-2021 | MIT License |
src/main/kotlin/leetcode/Problem1482.kt | fredyw | 28,460,187 | false | {"Java": 1280840, "Rust": 363472, "Kotlin": 148898, "Shell": 604} | package leetcode
import kotlin.math.max
import kotlin.math.min
/**
* https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/
*/
class Problem1482 {
fun minDays(bloomDay: IntArray, m: Int, k: Int): Int {
if (bloomDay.size < m * k) {
return -1
}
var min = Int.M... | 0 | Java | 1 | 4 | a59d77c4fd00674426a5f4f7b9b009d9b8321d6d | 1,212 | leetcode | MIT License |
generator/src/main/kotlin/com/kylemayes/generator/generate/file/Bitmasks.kt | KyleMayes | 305,287,877 | false | {"Rust": 6654307, "Kotlin": 153555, "GLSL": 3759, "Python": 2709, "Shell": 1142, "Makefile": 800, "PowerShell": 721} | // SPDX-License-Identifier: Apache-2.0
package com.kylemayes.generator.generate.file
import com.kylemayes.generator.generate.support.generateAliases
import com.kylemayes.generator.generate.support.generateManualUrl
import com.kylemayes.generator.registry.Bitflag
import com.kylemayes.generator.registry.Bitmask
import ... | 12 | Rust | 29 | 216 | c120c156dc5a6ebcfd8870d8688001f4accfb373 | 2,417 | vulkanalia | Apache License 2.0 |
src/main/kotlin/day18/Day18.kt | Jessevanbekkum | 112,612,571 | false | null | package day18
import util.readLines
class Day18 {
val snd = Regex("snd (\\w)")
val set = Regex("set (\\w) ([\\w-]*)")
val add = Regex("add (\\w) ([\\w-]*)")
val mul = Regex("mul (\\w) ([\\w-]*)")
val mod = Regex("mod (\\w) ([\\w-]*)")
val rcv = Regex("rcv (\\w)")
val jgz = Regex("jgz (\\w)... | 0 | Kotlin | 0 | 0 | 1340efd354c61cd070c621cdf1eadecfc23a7cc5 | 1,481 | aoc-2017 | Apache License 2.0 |
src/main/kotlin/g2001_2100/s2065_maximum_path_quality_of_a_graph/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2065_maximum_path_quality_of_a_graph
// #Hard #Array #Graph #Backtracking #2023_06_26_Time_429_ms_(100.00%)_Space_46.7_MB_(100.00%)
class Solution {
private var maxQuality = 0
internal class Node(var i: Int, var time: Int)
fun maximalPathQuality(values: IntArray, edges: Array<IntArra... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,822 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/leetcode/kotlin/array/easy/122. Best Time to Buy and Sell Stock II.kt | sandeep549 | 251,593,168 | false | null | package leetcode.kotlin.array.easy
fun main() {
println(maxProfit(intArrayOf(7, 1, 5, 3, 6, 4)))
println(maxProfit(intArrayOf(1, 2, 3, 4, 5)))
println(maxProfit(intArrayOf(7, 6, 4, 3, 1)))
println(maxProfit2(intArrayOf(7, 1, 5, 3, 6, 4)))
println(maxProfit2(intArrayOf(1, 2, 3, 4, 5)))
println(... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 2,108 | kotlinmaster | Apache License 2.0 |
src/2022/Day22.kt | ttypic | 572,859,357 | false | {"Kotlin": 94821} | package `2022`
import readInput
import splitBy
fun main() {
fun part1(input: List<String>): Int {
val (map, directionsLines) = input.splitBy { it.isEmpty() }
val directions = "\\d+|R|L".toRegex().findAll(directionsLines.first()).map { it.value }.toList()
var positionColumn = map.first().i... | 0 | Kotlin | 0 | 0 | b3e718d122e04a7322ed160b4c02029c33fbad78 | 11,329 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/Day11.kt | andrewrlee | 434,584,657 | false | {"Kotlin": 29493, "Clojure": 14117, "Shell": 398} | import java.io.File
import java.nio.charset.Charset.defaultCharset
import kotlin.streams.toList
typealias OctopusGrid = Map<Pair<Int, Int>, Day11.Octopus>
object Day11 {
private fun toCoordinates(row: Int, line: String) = line.chars()
.map(Character::getNumericValue)
.toList()
.mapIndexed ... | 0 | Kotlin | 0 | 0 | aace0fccf9bb739d57f781b0b79f2f3a5d9d038e | 2,424 | adventOfCode2021 | MIT License |
src/Day05.kt | cagriyildirimR | 572,811,424 | false | {"Kotlin": 34697} | import java.util.Stack
val input5 = readInput("Day05")
val crates = input5.take(8).reversed()
val instructions =input5.drop(10).map { i -> i.split("move", "from", "to", " ").filter { it != "" }.map { it.toInt() } }
fun day05Part2(){
val conveyor = Stack<String>()
val listOfPiles = List(9) { Stack<String>() ... | 0 | Kotlin | 0 | 0 | 343efa0fb8ee76b7b2530269bd986e6171d8bb68 | 1,261 | AoC | Apache License 2.0 |
src/Day23.kt | MickyOR | 578,726,798 | false | {"Kotlin": 98785} | fun main() {
var move = Array(4) { listOf<Pair<Int, Int>>() }
move[0] = listOf( Pair(-1, -1), Pair(-1, 0), Pair(-1, 1)) // up
move[1] = listOf( Pair(1, 1), Pair(1, 0), Pair(1, -1) ) // down
move[2] = listOf( Pair(1, -1), Pair(0, -1), Pair(-1, -1) ) // left
move[3] = listOf( Pair(-1, 1), Pair(0, 1),... | 0 | Kotlin | 0 | 0 | c24e763a1adaf0a35ed2fad8ccc4c315259827f0 | 7,202 | advent-of-code-2022-kotlin | Apache License 2.0 |
year2023/day03/part2/src/main/kotlin/com/curtislb/adventofcode/year2023/day03/part2/Year2023Day03Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- 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 a phone labeled... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,099 | AdventOfCode | MIT License |
src/main/kotlin/co/csadev/advent2021/Day02.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2021 by <NAME>
* Advent of Code 2021, Day 2
* Problem Description: http://adventofcode.com/2021/day/2
*/
package co.csadev.advent2021
import co.csadev.adventOfCode.BaseDay
import co.csadev.adventOfCode.Resources.resourceAsList
class Day02(data: List<String> = resourceAsList("22day02.txt")) :
... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 1,148 | advent-of-kotlin | Apache License 2.0 |
src/main/kotlin/g2901_3000/s2916_subarrays_distinct_element_sum_of_squares_ii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2901_3000.s2916_subarrays_distinct_element_sum_of_squares_ii
// #Hard #Array #Dynamic_Programming #Segment_Tree #Binary_Indexed_Tree
// #2023_12_31_Time_467_ms_(100.00%)_Space_58_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
private var n = 0
private lateinit var tree1: LongArray
priv... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,681 | LeetCode-in-Kotlin | MIT License |
y2017/src/main/kotlin/adventofcode/y2017/Day18.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2017
import adventofcode.io.AdventSolution
fun main()
{
Day18.solve()
}
object Day18 : AdventSolution(2017, 18, "Duet") {
override fun solvePartOne(input: String): String {
val instructions = parseInstructions(input)
val context = ExecutionContext()
var ip = 0
var mostRecentSound = "... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 2,539 | advent-of-code | MIT License |
omnia/src/commonMain/omnia/algorithm/SetAlgorithms.kt | StrangePan | 224,343,744 | false | {"Kotlin": 490047} | package omnia.algorithm
import omnia.data.structure.Set
import omnia.data.structure.immutable.ImmutableSet
import omnia.data.structure.immutable.ImmutableSet.Companion.toImmutableSet
object SetAlgorithms {
/**
* Computes the mathematical union of two sets. Returns a new set containing all of the items
* pres... | 0 | Kotlin | 0 | 1 | c6328c20a4f4712f94b2b721219eed5361846292 | 2,824 | omnia | The Unlicense |
aoc/src/main/kotlin/com/bloidonia/aoc2023/day09/Main.kt | timyates | 725,647,758 | false | {"Kotlin": 45518, "Groovy": 202} | package com.bloidonia.aoc2023.day09
import com.bloidonia.aoc2023.lines
private const val example = """0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45"""
private fun parse(input: String) = input.split(Regex("\\s+")).map { it.toLong() }
// Generate the difference lists, and reverse them
private fun differences(input: ... | 0 | Kotlin | 0 | 0 | 158162b1034e3998445a4f5e3f476f3ebf1dc952 | 1,061 | aoc-2023 | MIT License |
leetcode/src/main/kotlin/com/artemkaxboy/leetcode/p01/Leet118.kt | artemkaxboy | 513,636,701 | false | {"Kotlin": 547181, "Java": 13948} | package com.artemkaxboy.leetcode.p01
/**
* Optimizations
* Runtime 158ms Beats 86.92%
* Memory 35.4MB Beats 75.39%
*/
class Leet118 {
class Solution {
fun generate(numRows: Int): List<List<Int>> {
val result = ArrayList<List<Int>>(numRows)
var rowIndex = 0
... | 0 | Kotlin | 0 | 0 | 516a8a05112e57eb922b9a272f8fd5209b7d0727 | 2,744 | playground | MIT License |
src/_2022/Day01.kt | albertogarrido | 572,874,945 | false | {"Kotlin": 36434} | package _2022
import readInput
fun main() {
fun getCaloriesPerElf(input: List<String>): Array<Int> {
val calories = Array(input.count { it == "" } + 2) { 0 }
var elf = 1
input.forEach {
if (it == "") {
elf++
} else {
calories[elf] = c... | 0 | Kotlin | 0 | 0 | ef310c5375f67d66f4709b5ac410d3a6a4889ca6 | 967 | AdventOfCode.kt | Apache License 2.0 |
src/main/kotlin/g1101_1200/s1143_longest_common_subsequence/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1101_1200.s1143_longest_common_subsequence
// #Medium #Top_100_Liked_Questions #String #Dynamic_Programming
// #Algorithm_II_Day_17_Dynamic_Programming #Dynamic_Programming_I_Day_19
// #Udemy_Dynamic_Programming #Big_O_Time_O(n*m)_Space_O(n*m)
// #2022_09_13_Time_307_ms_(38.36%)_Space_38.7_MB_(86.99%)
class ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 836 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/day03/Day03.kt | dustinconrad | 572,737,903 | false | {"Kotlin": 100547} | package day03
import readResourceAsBufferedReader
fun main() {
println("part 1: ${part1(readResourceAsBufferedReader("3_1.txt").readLines())}")
println("part 2: ${part2(readResourceAsBufferedReader("3_1.txt").readLines())}")
}
fun part1(input: List<String>): Int {
return input.map { parsePart1(it) }
... | 0 | Kotlin | 0 | 0 | 1dae6d2790d7605ac3643356b207b36a34ad38be | 1,078 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ReversePairs.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,572 | kotlab | Apache License 2.0 |
neetcode/src/main/java/org/linkedlist/LinkedList.kt | gouthamhusky | 682,822,938 | false | {"Kotlin": 24242, "Java": 24233} | package org.linkedlist
class ListNode(var `val`: Int) {
var next: ListNode? = null
}
fun deleteDuplicates(head: ListNode?): ListNode? {
var node = head ?: return null
while (node!!.next != null){
if(node.`val` == node.next!!.`val`)
node.next = node.next!!.next
else
... | 0 | Kotlin | 0 | 0 | a0e158c8f9df8b2e1f84660d5b0721af97593920 | 5,783 | leetcode-journey | MIT License |
src/main/kotlin/com/chriswk/aoc/advent2021/Day10.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2021
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.report
class Day10: AdventDay(2021, 10) {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day = Day10()
report {
day.part1()
}
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 1,900 | adventofcode | MIT License |
src/main/kotlin/com/sk/set2/229. Majority Element II.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.set2
private fun majorityElement(nums: IntArray): List<Int> {
val l = nums.size / 3
val g = nums
.toList()
.groupingBy { it }
.eachCount()
.filter { it.value > l }
.map { it.key }
return g
}
private fun majorityElement2(nums: IntArray): List<Int> {
... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,861 | leetcode-kotlin | Apache License 2.0 |
src/day12/Code.kt | fcolasuonno | 572,734,674 | false | {"Kotlin": 63451, "Dockerfile": 1340} | package day12
import Coord
import closeNeighbours
import day06.main
import readInput
fun main() {
fun parse(input: List<String>): Triple<Coord, Coord, Map<Coord, Char>> {
val map = input.flatMapIndexed { y, s -> s.mapIndexed { x, c -> Coord(x, y) to c } }.toMap()
val start = map.entries.first { it... | 0 | Kotlin | 0 | 0 | 9cb653bd6a5abb214a9310f7cac3d0a5a478a71a | 1,849 | AOC2022 | Apache License 2.0 |
src/main/kotlin/day10/Adapters.kt | lukasz-marek | 317,632,409 | false | {"Kotlin": 172913} | package day10
data class Adapter(val output: Int)
interface AdaptersConnector {
fun connect(adapters: List<Adapter>): Map<Int, Int>
}
class AdaptersConnectorImpl : AdaptersConnector {
override fun connect(adapters: List<Adapter>): Map<Int, Int> {
val sortedAdapterValues = adapters.map { it.output }.s... | 0 | Kotlin | 0 | 0 | a16e95841e9b8ff9156b54e74ace9ccf33e6f2a6 | 2,358 | aoc2020 | MIT License |
src/deselby/std/NDRange.kt | deselby-research | 166,023,166 | false | null | package deselby.std
import kotlin.math.max
import kotlin.math.min
class NDRange(val range : Array<IntProgression>) : Iterable<IntArray> {
val nDimensions : Int
get() = range.size
val shape : IntArray
get() = IntArray(nDimensions) {
(this[it].last - this[it].first + 1)/this[it].step
... | 0 | Kotlin | 1 | 8 | 6c76a9a18e2caafc1ff00ab970d0df4d703f0119 | 2,738 | ProbabilisticABM | MIT License |
common/comparison/src/main/kotlin/com/curtislb/adventofcode/common/comparison/MinMax.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.common.comparison
/**
* The minimum and maximum of a group of comparable values.
*
* @param min The minimum value from the original group.
* @param max The maximum value from the original group.
*/
data class MinMax<T>(val min: T, val max: T)
/**
* Returns the minimum and maxim... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 1,764 | AdventOfCode | MIT License |
src/chapter1/section4/ex2.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter1.section4
/**
* 修改ThreeSum,正确处理两个较大的int值相加可能溢出的情况。
*
* 解:两个数正负号相同才可能溢出,如果两个数正负号相同,相加后和的正负号和原来的符号不同,则发生溢出
* 如果两个数相加溢出,第三个数在整数范围内无论取什么值,三个数的和都不可能为0
* 唯一例外是前两个数的和溢出后的值为Int.MIN_VALUE,第三个值为Int.MIN_VALUE 前两个值溢出,但和为0
* (因为最小负整数Int.MIN_VALUE的绝对值比最大正整数Int.MAX_VALUE的绝对值大1)
* 也可以将Int转换为Long或BigInteger计算,这样... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,809 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/day01/day01.kt | brighta | 572,053,290 | false | null | package day01
import readInput
fun main() {
fun splitFileIntoElves(file: List<String>): List<Int> {
val elves: MutableList<Int> = mutableListOf()
var currentElf = 0
for (line in file) {
if (line == "") {
elves.add(currentElf)
currentElf = 0
... | 0 | Kotlin | 0 | 0 | 23971f6b72523f91aa6488e87cf12e804a089a78 | 1,081 | advent-of-code-kotlin | Apache License 2.0 |
advent-of-code-2018/src/test/java/aoc/Advent16.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | package aoc
import org.assertj.core.api.KotlinAssertions.assertThat
import org.junit.Test
class Advent16 {
data class UnknownOperation(val opcode: Int, val a: Int, val b: Int, val c: Int)
data class Observation(
val before: Registers,
val operation: UnknownOperation,
val after: Regis... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 51,622 | advent-of-code | MIT License |
kotlin/src/com/s13g/aoc/aoc2018/Day24.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | /*
* Copyright 2019 <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 i... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 7,173 | euler | Apache License 2.0 |
day-3/src/Part1.kt | woojiahao | 225,170,972 | false | null | import Direction.*
import kotlin.math.abs
import kotlin.system.measureTimeMillis
val o = 0 to 0
fun manhattanDistance(i: Point) = abs(o.x - i.x) + abs(o.y - i.y)
fun move(pos: Point, t: Travel) =
when (t.direction) {
L -> (pos.x - 1 downTo (pos.x - t.distance)).map { it to pos.y }
R -> ((pos.x + 1)..(pos.x... | 0 | Kotlin | 0 | 2 | 4c9220a49dbc093fbe7f0d6692fa0390a63e702a | 1,237 | aoc-19 | MIT License |
2022/Day20/problems.kt | moozzyk | 317,429,068 | false | {"Rust": 102403, "C++": 88189, "Python": 75787, "Kotlin": 72672, "OCaml": 60373, "Haskell": 53307, "JavaScript": 51984, "Go": 49768, "Scala": 46794} | import java.io.File
import kotlin.math.*
class Node(val value: Long, var next: Node?, var prev: Node?) {}
fun addNode(value: Long, predecessor: Node?): Node {
if (predecessor == null) {
var newNode = Node(value, null, null)
newNode.next = newNode
newNode.prev = newNode
return newNo... | 0 | Rust | 0 | 0 | c265f4c0bddb0357fe90b6a9e6abdc3bee59f585 | 2,795 | AdventOfCode | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.