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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
app/src/main/kotlin/com/simplemobiletools/calculator/helpers/StatFunctions.kt | ModestosV | 116,624,977 | true | {"Java": 84718, "Kotlin": 79549} | package com.simplemobiletools.calculator.helpers
fun updateStats(results: ArrayList<String>){
getMean(results)
getMedian(results)
getMode(results)
getRange(results)
}
fun getMean(results: ArrayList<String>): String{
var avg = 0.0
for(r in results) {
if(r.isEmpty())
return "... | 10 | Java | 4 | 0 | 3b7b7ebd44d3307ff27e47c7c8724ffba4d5a6f8 | 2,392 | Simple-Calculator-DreamTeam | Apache License 2.0 |
src/Day10.kt | lsimeonov | 572,929,910 | false | {"Kotlin": 66434} | fun main() {
fun part1(input: List<String>): Int {
var clock = 0
var registry = 1
var total = 0
input.forEach { l ->
var calculated = false
if (l == "noop") {
clock++
} else {
for (i in 1..2) {
... | 0 | Kotlin | 0 | 0 | 9d41342f355b8ed05c56c3d7faf20f54adaa92f1 | 2,102 | advent-of-code-2022 | Apache License 2.0 |
src/test/kotlin/dev/shtanko/algorithms/leetcode/SimilarStringGroupsTest.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 | 3,117 | kotlab | Apache License 2.0 |
src/main/kotlin/days/aoc2022/Day3.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2022
import days.Day
class Day3 : Day(2022, 3) {
override fun partOne(): Any {
return calculatePartOne(inputList)
}
override fun partTwo(): Any {
return calculatePartTwo(inputList)
}
fun calculatePartOne(inputList: List<String>): Int {
return inputList
... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 1,347 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
Kotlin/src/SubsetsII.kt | TonnyL | 106,459,115 | false | null | /**
* Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
*
* Note: The solution set must not contain duplicate subsets.
*
* For example,
* If nums = [1,2,2], a solution is:
*
* [
* [2],
* [1],
* [1,2,2],
* [2,2],
* [1,2],
* []
* ]
*
* Accept... | 1 | Swift | 22 | 189 | 39f85cdedaaf5b85f7ce842ecef975301fc974cf | 1,091 | Windary | MIT License |
src/main/kotlin/days/Day24.kt | andilau | 429,557,457 | false | {"Kotlin": 103829} | package days
@AdventOfCodePuzzle(
name = "It Hangs in the Balance",
url = "https://adventofcode.com/2015/day/24",
date = Date(day = 24, year = 2015)
)
class Day24(private val weights: List<Int>) : Puzzle {
override fun partOne() = findBest(weights, 3)?.quantumEntanglement() ?: error("Not found")
... | 0 | Kotlin | 0 | 0 | 55932fb63d6a13a1aa8c8df127593d38b760a34c | 1,441 | advent-of-code-2015 | Creative Commons Zero v1.0 Universal |
src/test/kotlin/days/y2022/Day07Test.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2022
import days.Day
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.Is.`is`
import org.junit.jupiter.api.Test
class Day07 : Day(2022, 7) {
private lateinit var rootDir: FSNode
override fun partOne(input: String): Any {
parseInput(input)
return rootDir.chi... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 3,703 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/org/prime/util/DerivationBuilder.kt | miloserdova-l | 433,512,408 | true | {"Kotlin": 18468} | package org.prime.util
import org.prime.util.machines.LinearBoundedAutomaton
import org.prime.util.machines.TuringMachine
interface DerivationBuilder {
fun buildDerivation(input: List<String>, grammar: Grammar): MutableList<String>
}
/**
* Derivation builder uses TuringMachine to get accumulated used deltas to ... | 0 | Kotlin | 1 | 0 | f912a88f65458effce107318efc0a2a82ece45aa | 2,985 | primary-numbers-grammar | MIT License |
src/main/kotlin/day4/Day4.kt | Mee42 | 433,459,856 | false | {"Kotlin": 42703, "Java": 824} | package dev.mee42.day4
import dev.mee42.*
fun main() {
val inputRaw = input(day = 4, year = 2021)
val (bingoNumbers, boardsSplit) = inputRaw
.split("\n", limit = 2)
.twoElements()
.manipulateTuple { bingoNumbers, boards ->
bingoNumbers.ints() to boards.split("\n\n").map { ... | 0 | Kotlin | 0 | 0 | db64748abc7ae6a92b4efa8ef864e9bb55a3b741 | 1,647 | aoc-2021 | MIT License |
src/main/kotlin/g1601_1700/s1610_maximum_number_of_visible_points/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1601_1700.s1610_maximum_number_of_visible_points
// #Hard #Array #Math #Sorting #Sliding_Window #Geometry
// #2023_06_15_Time_1343_ms_(100.00%)_Space_101_MB_(100.00%)
import kotlin.math.atan
class Solution {
fun visiblePoints(points: List<List<Int>>, angle: Int, location: List<Int>): Int {
var m... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,827 | LeetCode-in-Kotlin | MIT License |
modules/fathom/src/main/kotlin/silentorb/mythic/fathom/surfacing/MergeVertices.kt | silentorb | 227,508,449 | false | null | package silentorb.mythic.fathom.surfacing
import silentorb.mythic.spatial.Vector3
tailrec fun groupNearbyVertices(distanceTolerance: Float, remaining: List<Vector3>,
groups: List<List<Vector3>>): List<List<Vector3>> =
if (remaining.size < 2)
groups
else {
val next =... | 0 | Kotlin | 0 | 2 | 74462fcba9e7805dddec1bfcb3431665df7d0dee | 1,921 | mythic-kotlin | MIT License |
src/Day06.kt | orirabi | 574,124,632 | false | {"Kotlin": 14153} | fun main() {
fun CharArray.isDistinct(i: Int, requiredCount: Int): Boolean {
if (i < requiredCount - 1) {
return false
}
return generateSequence(i to this[i]) { it.first - 1 to this[it.first - 1] }
.take(requiredCount)
.map { it.second }
.dis... | 0 | Kotlin | 0 | 0 | 41cb10eac3234ae77ed7f3c7a1f39c2f9d8c777a | 1,080 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/adventofcode/year2017/Day15DuelingGenerators.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2017
import adventofcode.Puzzle
import adventofcode.PuzzleInput
class Day15DuelingGenerators(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val generators by lazy { input.lines().map { it.split(" ").last().toLong() }.zipWithNext().first() }
override fun partOne() =... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 1,655 | AdventOfCode | MIT License |
src/main/kotlin/models/Coord3d.kt | aormsby | 571,002,889 | false | {"Kotlin": 80084} | package models
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.sqrt
data class Coord3d(
var x: Int,
var y: Int,
var z: Int
) {
operator fun plus(c: Coord3d) = Coord3d(x = x + c.x, y = y + c.y, z = z + c.z)
operator fun minus(c: Coord3d) = Coord3d(x = x - c.x, y = y - c.y, z = z - ... | 0 | Kotlin | 0 | 0 | 1bef4812a65396c5768f12c442d73160c9cfa189 | 2,386 | advent-of-code-2022 | MIT License |
app/src/main/java/com/arya/matrixcalculator/logic/InverseOperation.kt | arryaaas | 300,893,861 | false | {"Kotlin": 36162} | package com.arya.matrixcalculator.logic
object InverseOperation {
// const val N = 3
// Function to get cofactor of A[p][q] in temp[][]. n is current
// dimension of A[][]
private fun getCofactor(A: Array<Array<Float>>, temp: Array<Array<Float>>, p: Int, q: Int, n: Int) {
var i = 0
v... | 0 | Kotlin | 0 | 1 | 393d2e9ff271bd5aceabc2074be1ac7a96d8a271 | 4,236 | Matrix-Calculator | MIT License |
src/main/kotlin/adventofcode2020/Day19MonsterMessage.kt | n81ur3 | 484,801,748 | false | {"Kotlin": 476844, "Java": 275} | package adventofcode2020
class Day19MonsterMessage
data class MessageRule(
var ruleExpression: String = "",
) {
val fullRule: String
get() = ruleExpression
override fun toString(): String = (ruleExpression).replace(" ", "")
val isEvaluated: Boolean
get() {
val regex = "[a... | 0 | Kotlin | 0 | 0 | fdc59410c717ac4876d53d8688d03b9b044c1b7e | 2,351 | kotlin-coding-challenges | MIT License |
domain/src/main/kotlin/io/exflo/domain/extensions/ListExt.kt | 41north | 237,284,768 | false | null | /*
* Copyright (c) 2020 41North.
*
* 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... | 16 | Kotlin | 7 | 17 | 218d6f83db11268d8e5cb038e96f1d3fcd0a6cc0 | 1,574 | besu-exflo | Apache License 2.0 |
src/advent/of/code/TwelvethPuzzle.kt | 1nco | 725,911,911 | false | {"Kotlin": 112713, "Shell": 103} | package advent.of.code
import java.util.*
class TwelvethPuzzle {
companion object {
private const val DAY = "12";
private var input: MutableList<String> = arrayListOf();
private var result = 0L;
private var resultSecond = 0L;
private var resultThird = 0L;
priva... | 0 | Kotlin | 0 | 0 | 0dffdeba1ebe0b44d24f94895f16f0f21ac8b7a3 | 8,380 | advent-of-code | Apache License 2.0 |
src/main/kotlin/adventofcode2020/solution/Day8.kt | lhess | 320,667,380 | false | null | package adventofcode2020.solution
import adventofcode2020.Solution
import adventofcode2020.resource.PuzzleInput
class Day8(puzzleInput: PuzzleInput<String>) : Solution<String, Int>(puzzleInput) {
override fun runPart1() =
CPU(puzzleInput).run {
runCPU()
check(state == CPU.State.HAL... | 0 | null | 0 | 1 | cfc3234f79c27d63315994f8e05990b5ddf6e8d4 | 4,460 | adventofcode2020 | The Unlicense |
src/Day01.kt | mnajborowski | 573,619,699 | false | {"Kotlin": 7975} | fun main() {
fun part1(input: List<String>): Int {
var mostCalories = 0
input.fold(0) { acc, item ->
if (item.isBlank()) {
if (acc > mostCalories)
mostCalories = acc
0
} else
acc + item.toInt()
}
... | 0 | Kotlin | 0 | 0 | e54c13bc5229c6cb1504db7e3be29fc9b9c4d386 | 810 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/bajdcc/util/intervalTree/IntervalNode.kt | bajdcc | 32,624,604 | false | {"Kotlin": 1131761, "HTML": 42480, "CSS": 37889, "JavaScript": 2703} | package com.bajdcc.util.intervalTree
import java.util.*
/**
* The Node class contains the interval tree information for one single node
*
* @author <NAME>
*/
class IntervalNode<Type>(intervalList: List<Interval<Type>>) {
private var intervals: SortedMap<Interval<Type>, MutableList<Interval<Type>>> = TreeMap(... | 0 | Kotlin | 20 | 65 | 90b19af98da99b53bba5b3269ad5666df7c05e49 | 3,540 | jMiniLang | MIT License |
2022/src/day01/day01.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day01
import readInput
fun List<String>.toElvesCalories(): List<Int> {
val elves = mutableListOf<Int>()
foldIndexed(0) { idx, acc, value ->
if (value.isEmpty() || idx == size - 1) {
0.also { elves.add(acc) }
} else {
acc + value.toInt()
}
}
retu... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 840 | advent-of-code | Apache License 2.0 |
year2021/day21/part2/src/main/kotlin/com/curtislb/adventofcode/year2021/day21/part2/Year2021Day21Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Part Two ---
Now that you're warmed up, it's time to play the real game.
A second compartment opens, this time labeled Dirac dice. Out of it falls a single three-sided die.
As you experiment with the die, you feel a little strange. An informational brochure in the
compartment explains that this is a quantum d... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,522 | AdventOfCode | MIT License |
src/Day01.kt | palex65 | 572,937,600 | false | {"Kotlin": 68582} |
fun List<String>.toCalories() =
splitBy { it.isEmpty() } // List<List<String>>
.map { it.map { it.toInt() }.sum() } // List<Int>
fun part1(calories: List<Int>) = calories.max()
fun part2(calories: List<Int>) = calories.sorted().takeLast(3).sum()
fun main() {
val testCalories = readInpu... | 0 | Kotlin | 0 | 2 | 35771fa36a8be9862f050496dba9ae89bea427c5 | 562 | aoc2022 | Apache License 2.0 |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[69]x 的平方根.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //实现 int sqrt(int x) 函数。
//
// 计算并返回 x 的平方根,其中 x 是非负整数。
//
// 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。
//
// 示例 1:
//
// 输入: 4
//输出: 2
//
//
// 示例 2:
//
// 输入: 8
//输出: 2
//说明: 8 的平方根是 2.82842...,
// 由于返回类型是整数,小数部分将被舍去。
//
// Related Topics 数学 二分查找
// 👍 730 👎 0
//leetcode submit region begin(Prohibit modification... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,202 | MyLeetCode | Apache License 2.0 |
src/org/prime/util/Converter.kt | miloserdova-l | 433,512,408 | true | {"Kotlin": 31409} | package org.prime.util
import org.prime.util.machines.Direction
import org.prime.util.machines.TapeMachine
interface Converter {
fun machineToGrammar(machine: TapeMachine): Grammar
}
object Constants {
const val EPSILON = "epsilon"
const val RIGHT = ">"
const val COMMENT = "//"
const val BLANK = ... | 0 | Kotlin | 0 | 0 | f912a88f65458effce107318efc0a2a82ece45aa | 14,376 | primary-numbers-grammar | MIT License |
src/Day06.kt | fercarcedo | 573,142,185 | false | {"Kotlin": 60181} | private const val START_OF_PACKET_MARKER_LENGTH = 4
private const val START_OF_MESSAGE_MARKER_LENGTH = 14
private const val MARKER_NOT_FOUND = -1
fun main() {
fun play(input: List<String>, markerLength: Int): Int {
val line = input[0]
for (i in 0 until line.length - markerLength) {
val... | 0 | Kotlin | 0 | 0 | e34bc66389cd8f261ef4f1e2b7f7b664fa13f778 | 1,395 | Advent-of-Code-2022-Kotlin | Apache License 2.0 |
src/Day25.kt | frungl | 573,598,286 | false | {"Kotlin": 86423} | fun main() {
fun Long.toSnafu(): String {
var s = ""
var n = this
while (n > 0L) {
val rem = n % 5L
var res = n / 5L
if (rem < 3L)
s += rem.toString()
else {
if (rem == 3L)
s += "="
... | 0 | Kotlin | 0 | 0 | d4cecfd5ee13de95f143407735e00c02baac7d5c | 1,180 | aoc2022 | Apache License 2.0 |
src/main/kotlin/leetcode/kotlin/dp/hard/85. Maximal Rectangle.kt | sandeep549 | 251,593,168 | false | null | package leetcode.kotlin.dp.hard
private fun maximalRectangle(matrix: Array<CharArray>): Int {
/**
* Consider all rectangle which has top left corner at r,c index.
* For every row, find max area with minimum column size which has all 1 in it.
* Traverse every row top to down and keep track of minimum... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 2,330 | kotlinmaster | Apache License 2.0 |
Android Kotlin/KotlinFunny/app/src/main/kotlin/ru/guar7387/kotlinfunny/features/collections.kt | ArturVasilov | 34,915,513 | false | {"Java": 5837467, "Kotlin": 29850} | package ru.guar7387.kotlinfunny.features
import java.util.ArrayList
import java.util.HashMap
public fun listTest() {
val immutableList = listOf(1, 2, 3, 4, 5)
val list = ArrayList<Int>()
for (value in immutableList) {
list.add(value)
}
assert(list.size() == 5)
assert(list.sum() == 15... | 0 | Java | 0 | 3 | 3a6483468c896fc97080680918e90d61983d3c23 | 1,525 | AndroidCourses | Apache License 2.0 |
FineMedianSortedArrays.kt | linisme | 111,369,586 | false | null | class FindMedianSortedArraysSolution {
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
var i1 = 0
var i2 = 0
var length1 = nums1.size
var length2 = nums2.size
var sortedSize = length1 + length2
var sortedArray = IntArray(sortedSize)
var k = 0
wh... | 0 | Kotlin | 1 | 0 | 4382afcc782da539ed0d535c0a5b3a257e0c8097 | 1,013 | LeetCodeInKotlin | MIT License |
src/main/kotlin/homework5/ParserTree.kt | martilut | 342,898,976 | false | {"Kotlin": 107965} | package homework5
interface ParserTreeNode {
fun calculate(): Int
fun outputValue(height: Int): String
}
class OperandNode(private val value: Int) : ParserTreeNode {
override fun calculate(): Int = value
override fun outputValue(height: Int): String =
".".repeat(height) + this.value.toString()... | 0 | Kotlin | 0 | 0 | 091a57cbca3fca8869ea5b61d2e0f2f77ccdb792 | 2,692 | spbu_2021_kotlin_homeworks | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DivideArrayWithMaxDifference.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 | 1,419 | kotlab | Apache License 2.0 |
day13/src/Day13.kt | simonrules | 491,302,880 | false | {"Kotlin": 68645} | import java.io.File
class Day13(path: String) {
private val size = 2000
private val map = BooleanArray(size * size)
private val folds = mutableListOf<Pair<Char, Int>>()
private var width = 0
private var height = 0
init {
File(path).forEachLine {
if (it.contains(",")) {
... | 0 | Kotlin | 0 | 0 | d9e4ae66e546f174bcf66b8bf3e7145bfab2f498 | 2,810 | aoc2021 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NumOfWaysGrid.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,317 | kotlab | Apache License 2.0 |
year2021/day09/part2/src/main/kotlin/com/curtislb/adventofcode/year2021/day09/part2/Year2021Day09Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Part Two ---
Next, you need to find the largest basins so you know what areas are most important to avoid.
A basin is all locations that eventually flow downward to a single low point. Therefore, every low
point has a basin, although some basins are very small. Locations of height 9 do not count as being
in an... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 1,891 | AdventOfCode | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[1078]Bigram 分词.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给出第一个词 first 和第二个词 second,考虑在某些文本 text 中可能以 "first second third" 形式出现的情况,其中 se
//cond 紧随 first 出现,third 紧随 second 出现。
//
// 对于每种这样的情况,将第三个词 "third" 添加到答案中,并返回答案。
//
//
//
// 示例 1:
//
//
//输入:text = "alice is a good girl she is a good student", first = "a", second =
//"good"
//输出:["girl","student"]
//
//
// 示例 ... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,505 | MyLeetCode | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year22/Day15.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year22
import com.grappenmaker.aoc.*
import com.grappenmaker.aoc.Direction.*
fun PuzzleSet.day15() = puzzle {
val scanners = inputLines.map { l ->
val ints = l.splitInts()
Scanner(Point(ints[0], ints[1]), Point(ints[2], ints[3]))
}
fun Point.isValid() = scanne... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,139 | advent-of-code | The Unlicense |
solutions/src/CutTreeEdge.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | /**
* https://www.hackerrank.com/challenges/cut-the-tree/problem
*
* The problem made it seem like a tree, but was actually an undirected graph.
* I decided to just call it a day on this one
*/
class CutTreeEdge {
fun cutTheTree(data: Array<Int>, edges: Array<Array<Int>>): Int {
val totalSum = data.sum... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 1,936 | leetcode-solutions | MIT License |
src/kotlin2022/Day03.kt | egnbjork | 571,981,366 | false | {"Kotlin": 18156} | package kotlin2022
import readInput
fun main() {
val gameInput = readInput("Day03_test")
println("task1 ${gameInput.sumOf { getCharPriority(findCommonChar(it)) }}")
println("task2 ${gameInput.chunked(3).sumOf{ getCharPriority(findCommonChar(it)) }}")
}
fun findCommonChar(items: List<String>): Char {
... | 0 | Kotlin | 0 | 0 | 1294afde171a64b1a2dfad2d30ff495d52f227f5 | 802 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/g0101_0200/s0200_number_of_islands/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0101_0200.s0200_number_of_islands
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Depth_First_Search
// #Breadth_First_Search #Matrix #Union_Find
// #Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search
// #Graph_Theory_I_Day_1_Matrix_Related_Problems #Level_1_Day_9_Graph/BFS/DFS #U... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,193 | LeetCode-in-Kotlin | MIT License |
src/main/aoc2015/Day14.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2015
import kotlin.math.min
class Day14(input: List<String>) {
data class Reindeer(val Name: String, val speed: Int, val duration: Int, val rest: Int) {
var score = 0
var currentDistance = 0
private set
private var currentTime = 0
private fun isMoving(): B... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,841 | aoc | MIT License |
y2019/src/main/kotlin/adventofcode/y2019/Day07.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2019
import adventofcode.io.AdventSolution
import adventofcode.language.intcode.IntCodeProgram
import adventofcode.util.collections.cycle
import adventofcode.util.collections.permutations
fun main() = Day07.solve()
object Day07 : AdventSolution(2019, 7, "Amplification Circuit") {
override ... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,153 | advent-of-code | MIT License |
src/day02/Day02.kt | robin-schoch | 572,718,550 | false | {"Kotlin": 26220} | package day02
import AdventOfCodeSolution
fun main() {
Day02.run()
}
sealed class Shape {
abstract val points: Int
abstract fun losses(): Shape
abstract fun wins(): Shape
private fun draws() = this
infix fun plays(opponent: Shape) = when (this) {
opponent.draws() -> DRAW
oppo... | 0 | Kotlin | 0 | 0 | fa993787cbeee21ab103d2ce7a02033561e3fac3 | 2,142 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day11.kt | Gitvert | 725,292,325 | false | {"Kotlin": 97000} | import kotlin.math.abs
const val EXPANSION_TIMES = 999999L
fun day11 (lines: List<String>) {
day11part1(lines)
day11part2(lines)
}
fun day11part1(lines: List<String>) {
val expanded = expandUniverse(lines)
val positions = findGalaxyPositions(expanded)
val totalManhattan = findManhattanDistance(po... | 0 | Kotlin | 0 | 0 | f204f09c94528f5cd83ce0149a254c4b0ca3bc91 | 4,025 | advent_of_code_2023 | MIT License |
src/Day14.kt | erwinw | 572,913,172 | false | {"Kotlin": 87621} | @file:Suppress("MagicNumber")
import kotlin.math.sign
private const val DAY = "14"
private const val PART1_CHECK = 24
private const val PART2_CHECK = 93
private enum class Rego {
START,
ROCK,
SAND
}
private fun printGrid(grid: List<List<Rego?>>) {
val withInit = grid.map { it.toMutableList() }
... | 0 | Kotlin | 0 | 0 | 57cba37265a3c63dea741c187095eff24d0b5381 | 4,851 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/eu/michalchomo/adventofcode/year2023/Day06.kt | MichalChomo | 572,214,942 | false | {"Kotlin": 56758} | package eu.michalchomo.adventofcode.year2023
import eu.michalchomo.adventofcode.Day
import eu.michalchomo.adventofcode.main
object Day06 : Day {
override val number: Int = 6
override fun part1(input: List<String>): String = input.let {
val times = it[0].getNumbers()
val distances = it[1].get... | 0 | Kotlin | 0 | 0 | a95d478aee72034321fdf37930722c23b246dd6b | 1,187 | advent-of-code | Apache License 2.0 |
src/main/kotlin/LambdasCollections.kt | ersushantsood | 191,845,135 | false | null | fun main() {
val li = listOf<Int>(1,2,3,4)
println(li.filter({i:Int -> i%2 ==0}))
//Map operation
println (li.map { it * 2 })
val lstNumbers = listOf<Number>(Number("one",1),Number("two",2),Number("three",3))
println("Numbers:"+lstNumbers.map { it.name })
//Find and groupBy
val li... | 0 | Kotlin | 0 | 0 | 94aab4e4334f8ed24947f4551362d6fc8cfd8154 | 3,080 | kotlinSamples | Apache License 2.0 |
src/main/kotlin/twentytwentytwo/Day13.kt | JanGroot | 317,476,637 | false | {"Kotlin": 80906} | package twentytwentytwo
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import kotlin.math.sign
fun main() {
val input = {}.javaClass.getR... | 0 | Kotlin | 0 | 0 | 04a9531285e22cc81e6478dc89708bcf6407910b | 2,024 | aoc202xkotlin | The Unlicense |
src/Day4/Day4.kt | tomashavlicek | 571,148,715 | false | {"Kotlin": 23780} | package Day4
import readInput
import containsFull
fun main() {
fun part1(input: List<String>): Int {
return input.map { elfPair ->
elfPair.split(',').map { elf ->
val parts = elf.split('-')
IntRange(parts[0].toInt(), parts[1].toInt())
}
}.co... | 0 | Kotlin | 0 | 0 | 899d30e241070903fe6ef8c4bf03dbe678310267 | 1,104 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/day17.kt | Gitvert | 433,947,508 | false | {"Kotlin": 82286} | import kotlin.math.abs
fun day17() {
val lines: List<String> = readFile("day17.txt")
day17part1(lines)
day17part2(lines)
}
fun day17part1(lines: List<String>) {
val xPos = lines[0].split(",")[0].split("=")[1].split("..")
val yPos = lines[0].split(",")[1].split("=")[1].split("..")
val xPair = ... | 0 | Kotlin | 0 | 0 | 02484bd3bcb921094bc83368843773f7912fe757 | 2,230 | advent_of_code_2021 | MIT License |
src/Day04.kt | sungi55 | 574,867,031 | false | {"Kotlin": 23985} | fun main() {
val day = "Day04"
fun getRanges(input: List<String>) =
input.map { set ->
set.split(",")
.map { ranges -> ranges.split("-").map { it.toInt() } }
.map { (it.component1()..it.component2()).toList() }
}
fun part1(input: List<String>): ... | 0 | Kotlin | 0 | 0 | 2a9276b52ed42e0c80e85844c75c1e5e70b383ee | 909 | aoc-2022 | Apache License 2.0 |
fuzzywuzzy_kotlin/src/main/java/com/frosch2010/fuzzywuzzy_kotlin/algorithms/Utils.kt | jens-muenker | 695,555,771 | false | {"Kotlin": 88201} | package com.frosch2010.fuzzywuzzy_kotlin.algorithms
import java.util.Arrays
import java.util.Collections
import java.util.PriorityQueue
object Utils {
fun tokenize(`in`: String): List<String> {
return Arrays.asList(*`in`.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() }
.toTypedArray())
... | 0 | Kotlin | 0 | 0 | da452a7027069e9c6adb6b11a430e125a50ce0ca | 2,023 | fuzzywuzzy-kotlin | The Unlicense |
app/src/main/kotlin/me/mataha/misaki/solutions/adventofcode/aoc2015/d03/Day.kt | mataha | 302,513,601 | false | {"Kotlin": 92734, "Gosu": 702, "Batchfile": 104, "Shell": 90} | package me.mataha.misaki.solutions.adventofcode.aoc2015.d03
import me.mataha.misaki.domain.NoOpParser
import me.mataha.misaki.domain.adventofcode.AdventOfCode
import me.mataha.misaki.domain.adventofcode.AdventOfCodeDay
import me.mataha.misaki.util.extensions.next
/** See the puzzle's full description [here](https://a... | 0 | Kotlin | 0 | 0 | 748a5b25a39d01b2ffdcc94f1a99a6fbc8a02685 | 1,717 | misaki | MIT License |
src/main/kotlin/com/sherepenko/leetcode/solutions/LongestCommonSubsequence.kt | asherepenko | 264,648,984 | false | null | package com.sherepenko.leetcode.solutions
import com.sherepenko.leetcode.Solution
import kotlin.math.max
class LongestCommonSubsequence(
private val text1: String,
private val text2: String
) : Solution {
companion object {
fun longestCommonSubsequence(text1: String, text2: String): Int {
... | 0 | Kotlin | 0 | 0 | 49e676f13bf58f16ba093f73a52d49f2d6d5ee1c | 1,164 | leetcode | The Unlicense |
solutions/aockt/y2022/Y2022D13.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2022
import aockt.y2022.Y2022D13.PacketData.*
import io.github.jadarma.aockt.core.Solution
object Y2022D13 : Solution {
/** An element in a [Packet]. */
private sealed interface PacketData : Comparable<PacketData> {
/** Contains a single positive integer literal.*/
@JvmInline
... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 4,662 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/aoc2018/Day19.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2018
class Day19(val input: List<String>) {
private val registers = MutableList(6) { 0 }
fun solvePart1(): Long {
val elf = ElfCode(input)
elf.runProgram()
return elf.registers[0]
}
private fun theProgram() {
// init part (line 1 + 17 - 35)
register... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,128 | aoc | MIT License |
kotlin/src/katas/kotlin/hackerrank/NonDivisibleSubset.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.hackerrank
import datsok.shouldEqual
import org.junit.Test
// https://www.hackerrank.com/challenges/non-divisible-subset
class NonDivisibleSubset {
@Test fun `example from the task description`() {
nonDivisibleSubset(k = 4, array = arrayOf(19, 10, 12, 10, 24, 25, 22)) shouldEqual 3
... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,493 | katas | The Unlicense |
src/main/kotlin/aoc22/Day21.kt | tom-power | 573,330,992 | false | {"Kotlin": 254717, "Shell": 1026} | package aoc22
import aoc22.Day21Domain.HumanMonkey
import aoc22.Day21Domain.MathMonkey
import aoc22.Day21Domain.Monkey
import aoc22.Day21Domain.NumberMonkey
import aoc22.Day21Domain.Operator
import aoc22.Day21Domain.Operator.*
import aoc22.Day21Parser.toMonkeys
import aoc22.Day21Parser.toRootMonkey
import aoc22.Day21R... | 0 | Kotlin | 0 | 0 | baccc7ff572540fc7d5551eaa59d6a1466a08f56 | 5,628 | aoc | Apache License 2.0 |
src/main/kotlin/day19/Day19.kt | alxgarcia | 435,549,527 | false | {"Kotlin": 91398} | package day19
import java.io.File
import kotlin.math.absoluteValue
typealias Position = Triple<Int, Int, Int>
typealias Transformation = (Triple<Int, Int, Int>) -> Triple<Int, Int, Int>
private operator fun Position.plus(offset: Position): Position =
Position(first + offset.first, second + offset.second, third + o... | 0 | Kotlin | 0 | 0 | d6b10093dc6f4a5fc21254f42146af04709f6e30 | 6,144 | advent-of-code-2021 | MIT License |
src/main/kotlin/com/github/davio/aoc/y2020/Day6.kt | Davio | 317,510,947 | false | {"Kotlin": 405939} | package com.github.davio.aoc.y2020
import com.github.davio.aoc.general.Day
import com.github.davio.aoc.general.call
import com.github.davio.aoc.general.getInputAsSequence
fun main() {
Day6.getResult()
}
object Day6 : Day() {
/*
* --- Day 6: Custom Customs ---
As your flight approaches the regional air... | 1 | Kotlin | 0 | 0 | 4fafd2b0a88f2f54aa478570301ed55f9649d8f3 | 4,157 | advent-of-code | MIT License |
src/leetcode_study_badge/data_structure/Day2.kt | faniabdullah | 382,893,751 | false | null | package leetcode_study_badge.data_structure
import java.util.*
class Day2 {
fun sortColors(nums: IntArray) {
var one = 0
var two = 0
var insertPosition = -1
repeat(nums.count()) {
if (nums[it] == 0) {
insertPosition++
nums[insertPositio... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,220 | dsa-kotlin | MIT License |
src/main/kotlin/io/array/SubarraySumEqualsK.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.array
import io.utils.runTests
// https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/531/week-4/3307/
class SubarraySumEqualsK {
fun execute(input: IntArray, target: Int): Int {
var result = 0
val stack = input.map { elem -> elem.also { if (elem == target) result++ } }.toMuta... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,095 | coding | MIT License |
src/Day03.kt | li-xin-yi | 573,617,763 | false | {"Kotlin": 23422} | fun main() {
fun solvePart1(input: List<String>): Int {
var res = 0
for (line in input) {
val length = line.length
val first = line.substring(0, length / 2).toSet()
val second = line.substring(length / 2).toSet()
val item = first.intersect(second).firs... | 0 | Kotlin | 0 | 1 | fb18bb7e462b8b415875a82c5c69962d254c8255 | 1,002 | AoC-2022-kotlin | Apache License 2.0 |
leetcode2/src/leetcode/ValidParentheses.kt | hewking | 68,515,222 | false | null | package leetcode
import java.util.*
/**
* 有效的括号 栈相关
* https://leetcode-cn.com/problems/valid-parentheses/
* Created by test
* Date 2019/5/18 15:36
* Description
* 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。
有效字符串需满足:
左括号必须用相同类型的右括号闭合。
左括号必须以正确的顺序闭合。
注意空字符串可被认为是有效字符串。
示例 1:
输入: "()"
输出: true
示例 2:
输入: "... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,562 | leetcode | MIT License |
marathons/atcoder/ahc21_toyota2023_pyramidSorting/pyramidSorting.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package marathons.atcoder.ahc21_toyota2023_pyramidSorting
import kotlin.random.Random
private fun solve(f: List<IntArray>) {
val answers = mutableListOf<List<String>>()
for (mode in 0 until 5 + 12) {
answers.add(solveGreedy(f.map { it.clone() }, mode))
}
val ans = answers.minBy { it.size }
println("" + ans.siz... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 3,292 | competitions | The Unlicense |
src/main/kotlin/io/undefined/IsBalanceParentheses.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.undefined
import io.undefined.IsBalanceParentheses.Parameter
class IsBalanceParentheses {
data class Parameter(
val input: String,
val bruteForceSolution: String,
val stackSolution: String,
val backAndForthSolution: String,
val debug: Boolean = false
)
fun balanceBruceForce(inpu... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 4,433 | coding | MIT License |
src/main/kotlin/de/tek/adventofcode/y2022/util/math/Graph.kt | Thumas | 576,671,911 | false | {"Kotlin": 192328} | package de.tek.adventofcode.y2022.util.math
class Graph<T>(edges: List<Edge<T>>) {
private val neighbourMap = edges.groupBy(Edge<T>::from) { it }
constructor(edges: Set<Pair<T, T>>) : this(edges.map { Edge(it, 1) })
fun vertices(): Set<T> = neighbourMap.keys
fun toPath(vertices: List<T>): List<Edge<... | 0 | Kotlin | 0 | 0 | 551069a21a45690c80c8d96bce3bb095b5982bf0 | 2,545 | advent-of-code-2022 | Apache License 2.0 |
src/aoc2017/kot/Day10.kt | Tandrial | 47,354,790 | false | null | package aoc2017.kot
import itertools.chunksOfSize
import toHexString
import toIntList
import java.io.File
object Day10 {
fun hashRound(input: List<Int>, rep: Int = 1): List<Int> {
var mem = (0..255).toList()
var pos = 0
var skipS = 0
repeat(rep) {
for (len in input) {
// reverse subLis... | 0 | Kotlin | 1 | 1 | 9294b2cbbb13944d586449f6a20d49f03391991e | 1,540 | Advent_of_Code | MIT License |
src/day08/Day08_Part1.kt | m-jaekel | 570,582,194 | false | {"Kotlin": 13764} | package day08
import readInput
import java.util.*
fun main() {
fun part1(input: List<String>): Int {
val treeMap: List<List<Tree>> = input.map { row ->
row.chunked(1).map {
Tree(it.toInt(), UUID.randomUUID())
}
}
val transposedTreeMap = treeMap.mapI... | 0 | Kotlin | 0 | 1 | 07e015c2680b5623a16121e5314017ddcb40c06c | 1,467 | AOC-2022 | Apache License 2.0 |
src/Day21.kt | andrikeev | 574,393,673 | false | {"Kotlin": 70541, "Python": 18310, "HTML": 5558} | fun main() {
fun part1(input: List<String>): Long {
val monkeys = buildMap {
input.forEach {
val (name, job) = MonkeyJob.parse(it)
put(name, job)
}
}
fun MonkeyJob.Calculate.firstMonkey() = monkeys.getValue(monkey1)
fun Monkey... | 0 | Kotlin | 0 | 1 | 1aedc6c61407a28e0abcad86e2fdfe0b41add139 | 7,274 | aoc-2022 | Apache License 2.0 |
Kotlin for Java Developers. Week 3/Taxi Park/Task/src/taxipark/TaxiParkTask.kt | binout | 159,054,839 | false | null | package taxipark
import java.util.*
import kotlin.math.absoluteValue
/*
* Task #1. Find all the drivers who performed no trips.
*/
fun TaxiPark.findFakeDrivers(): Set<Driver> {
val driversWhoPerformedAtrip = this.trips.map { it.driver }
return this.allDrivers.filter { it !in driversWhoPerformedAtrip }.toSet... | 0 | Kotlin | 1 | 5 | 40ff182f63d29443fa3c29730560d37e2325501a | 2,614 | coursera-kotlin | Apache License 2.0 |
src/main/aoc2021/Day14.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2021
/**
* Very similar solution to day 6.
* @see Day6
*/
class Day14(input: List<String>) {
private val template = input.first()
// Map of conversions. Example: "NN -> C" is transformed into rules[NN]: listOf(NC, CN)
private val rules = input.drop(2).map { it.split(" -> ") }.associate { (a... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,177 | aoc | MIT License |
src/main/kotlin/g0101_0200/s0154_find_minimum_in_rotated_sorted_array_ii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0101_0200.s0154_find_minimum_in_rotated_sorted_array_ii
// #Hard #Array #Binary_Search #Binary_Search_II_Day_13
// #2022_10_11_Time_275_ms_(84.00%)_Space_39_MB_(56.00%)
class Solution {
fun findMin(nums: IntArray): Int {
return if (nums.isEmpty()) {
0
} else find(0, nums.size ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 970 | LeetCode-in-Kotlin | MIT License |
src/2023/Day11.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2023`
import common.Linearizer
import java.io.File
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun main() {
Day11().solve()
}
class Day11 {
val input1 = """
...#......
.......#..
#.........
..........
......#...
... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 4,286 | advent-of-code | Apache License 2.0 |
AdventOfCode/2022/aoc22/src/main/kotlin/day20.kt | benhunter | 330,517,181 | false | {"Rust": 172709, "Python": 143372, "Kotlin": 37623, "Java": 17629, "TypeScript": 3422, "JavaScript": 3124, "Just": 1078} | import java.math.BigInteger
data class ValueStartIndexPair(val value: BigInteger, val startIndex: Int)
fun day20() {
val day = 20
println("day $day")
val startTime = System.nanoTime()
val filename = "$day-input.txt"
val text = getTextFromResource(filename).trim()
val lines = text.split("\n").... | 0 | Rust | 0 | 1 | a424c12f4d95f9d6f8c844e36d6940a2ac11d61d | 2,327 | coding-challenges | MIT License |
src/main/kotlin/sort_algorithm/quickSort.kt | korilin | 347,404,763 | false | null | package sort_algorithm
/**
* 快速排序
* 时间复杂度:
* 最优时间复杂度:Ο(n*log(n))
* 平均时间复杂度:Ο(n*log(n))
* 最坏时间复杂度:Ο(n²)
* 空间复杂度:Ο(1)
*
* Quick Sort
* Time Complexity:
* Optimal Time Complexity: Ο(n*log(n))
* Average Time Complexity: Ο(n*log(n))
* Worst Time Complexity: Ο(n²)
* Space Complexity: Ο(1)
*/
fun qu... | 0 | Kotlin | 0 | 1 | b96ba1b2998b0c6b057fc9b77f677a3183c436ed | 1,065 | DSA-kt | MIT License |
8_eight/PaintString.kt | thalees | 250,902,664 | false | null | fun main() {
class Ans(val a: String, val m: String)
repeat(readLine()!!.toInt()) {
val s = readLine()!!
val n = s.length
val dp = Array(n) { i -> arrayOfNulls<Ans>(i + 1) }
dp[0][0] = Ans(s.substring(0, 1), "R")
var best = Ans(s, "")
fun updateBest(p: Ans) {
... | 0 | Kotlin | 0 | 0 | 3b499d207d366450c7b2facbd99a345c86b6eff8 | 997 | kotlin-code-challenges | MIT License |
src/leetcodeProblem/leetcode/editor/en/LongestSubstringWithoutRepeatingCharacters.kt | faniabdullah | 382,893,751 | false | null | //Given a string s, find the length of the longest substring without repeating
//characters.
//
//
// Example 1:
//
//
//Input: s = "abcabcbb"
//Output: 3
//Explanation: The answer is "abc", with the length of 3.
//
//
// Example 2:
//
//
//Input: s = "bbbbb"
//Output: 1
//Explanation: The answer is "b", with th... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 1,770 | dsa-kotlin | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[67]二进制求和.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.lang.StringBuilder
//给你两个二进制字符串,返回它们的和(用二进制表示)。
//
// 输入为 非空 字符串且只包含数字 1 和 0。
//
//
//
// 示例 1:
//
// 输入: a = "11", b = "1"
//输出: "100"
//
// 示例 2:
//
// 输入: a = "1010", b = "1011"
//输出: "10101"
//
//
//
// 提示:
//
//
// 每个字符串仅由字符 '0' 或 '1' 组成。
// 1 <= a.length, b.length <= 10^4
// 字符串如果不是 "0" ,就... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,504 | MyLeetCode | Apache License 2.0 |
2019/day4/part_a.kt | sergeknystautas | 226,467,020 | false | null | package aoc2019.day4;
// import kotlin.int.rem;
/*
Scans a range between two 6 digit numbers and counting how many combinations meet a set of rules.
*/
fun Descending(digits: List<Int>) : Boolean {
var prev = digits[0];
for (i in 1..digits.size - 1) {
if (prev > digits[i]) {
return true;... | 0 | Kotlin | 0 | 0 | 38966bc742f70122681a8885e986ed69dd505243 | 2,141 | adventofkotlin2019 | Apache License 2.0 |
src/day1/Day01.kt | Johnett | 572,834,907 | false | {"Kotlin": 9781} | package day1
import readInput
fun main() {
fun getCalorieList(calories: List<String>):MutableList<Int> {
var totalCalories = 0
val calorieSum: MutableList<Int> = mutableListOf()
calories.forEach { calorie ->
if (calorie.isNotBlank()) {
totalCalories += calorie.... | 0 | Kotlin | 0 | 1 | c8b0ac2184bdad65db7d2f185806b9bb2071f159 | 1,086 | AOC-2022-in-Kotlin | Apache License 2.0 |
src/main/kotlin/tr/emreone/adventofcode/days/Day03.kt | EmRe-One | 568,569,073 | false | {"Kotlin": 166986} | package tr.emreone.adventofcode.days
object Day03 {
// Lowercase item types a through z have priorities 1 through 26.
// Uppercase item types A through Z have priorities 27 through 52.
private fun getPriority(char: Char): Int {
return if (char.isLowerCase()) {
char - 'a' + 1
} ... | 0 | Kotlin | 0 | 0 | a951d2660145d3bf52db5cd6d6a07998dbfcb316 | 980 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/colinodell/advent2022/Day05.kt | colinodell | 572,710,708 | false | {"Kotlin": 105421} | package com.colinodell.advent2022
class Day05(input: String) {
private val stacks = mutableMapOf<Int, MutableList<Char>>()
private val moves: List<Move>
init {
val (rawStacks, rawCommands) = input.split("\n\n")
for (row in rawStacks.split("\n").dropLast(1)) {
row.chunked(4).fo... | 0 | Kotlin | 0 | 1 | 32da24a888ddb8e8da122fa3e3a08fc2d4829180 | 1,629 | advent-2022 | MIT License |
src/main/kotlin/ru/timakden/aoc/year2016/Day09.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2016
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 9: Explosives in Cyberspace](https://adventofcode.com/2016/day/9).
*/
object Day09 {
@JvmStatic
fun main(args: Array<String>) {
measure {
val input = readInput("year2016/... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 1,602 | advent-of-code | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ZeroOneMatrix.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,376 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ValidateBinaryTreeNodes.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,869 | kotlab | Apache License 2.0 |
src/main/kotlin/leetcode/kotlin/misc/463. Island Perimeter.kt | sandeep549 | 251,593,168 | false | null | package leetcode.kotlin.misc
fun main() {
println(
islandPerimeter(
arrayOf(
intArrayOf(0, 1, 0, 0),
intArrayOf(1, 1, 1, 0),
intArrayOf(0, 1, 0, 0),
intArrayOf(1, 1, 0, 0)
)
)
)
}
private fun islandPerimete... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 2,396 | kotlinmaster | Apache License 2.0 |
src/main/kotlin/year2022/Day05.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2022
import java.util.*
class Day05(input: String) {
data class CrateMove(val num: Int, val from: Int, val to: Int)
private val lines = input.lines()
private val emptyLine = lines.indexOfFirst { it.isEmpty() }
private val stacks = lines.parseStacks()
private val regex = Regex("\\d... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 1,662 | aoc-2022 | Apache License 2.0 |
src/day01/Day01.kt | dusanpetren | 577,801,981 | false | {"Kotlin": 1685} | package day01
import println
import readInput
fun main() {
fun part1(input: String): Int {
val data = input.split("\n\n").map { elf ->
elf.lines().filter { it != "" }.sumOf { it.toInt() }
}
return data.max()
}
fun part2(input: String): Int {
return input.split... | 0 | Kotlin | 0 | 0 | 82a26cbd0897e2d3e841c6ed9ac4fddf497ec05a | 924 | AoC-2022-Kotlin | Apache License 2.0 |
src/Day01.kt | PascalHonegger | 573,052,507 | false | {"Kotlin": 66208} | fun main() {
fun List<String>.splitIntoElves(): List<List<Int>> = buildList {
var elf = mutableListOf<Int>()
this@splitIntoElves.forEach {
if (it.isBlank()) {
add(elf)
elf = mutableListOf()
} else {
elf += it.toInt()
... | 0 | Kotlin | 0 | 0 | 2215ea22a87912012cf2b3e2da600a65b2ad55fc | 899 | advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | rounakdatta | 540,743,612 | false | {"Kotlin": 19962} | class Board(input: MutableList<MutableList<Pair<String, Boolean>>>, isCompleted: Boolean) {
private val actualBoard = input
var completed: Boolean = isCompleted
var numberThatHelpedMeWin: Int = -1
fun applyNumber(numberToPlayWith: String): Board {
return Board(this.actualBoard.map {
... | 0 | Kotlin | 0 | 1 | 130d340aa4c6824b7192d533df68fc7e15e7e910 | 5,655 | aoc-2021 | Apache License 2.0 |
src/main/kotlin/io/github/raphaeltarita/days/Day8.kt | RaphaelTarita | 433,468,222 | false | {"Kotlin": 89687} | package io.github.raphaeltarita.days
import io.github.raphaeltarita.structure.AoCDay
import io.github.raphaeltarita.util.day
import io.github.raphaeltarita.util.inputPath
import io.github.raphaeltarita.util.intersect
import io.github.raphaeltarita.util.negate
import io.github.raphaeltarita.util.pow
import kotlinx.date... | 0 | Kotlin | 0 | 3 | 94ebe1428d8882d61b0463d1f2690348a047e9a1 | 6,297 | AoC-2021 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch0/Problem2.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch0
import dev.bogwalk.util.custom.RollingQueue
/**
* Problem 2: Even Fibonacci Numbers
*
* https://projecteuler.net/problem=2
*
* Goal: Find the sum of all even numbers in the Fibonacci sequence less than N.
*
* Constraints: 10 <= N <= 4e16
*
* e.g.: N = 44
* even fibonacci < N... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,900 | project-euler-kotlin | MIT License |
src/chapter1/section4/ex25_Throwing2Eggs.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter1.section4
import extensions.formatDouble
import extensions.inputPrompt
import extensions.readInt
import kotlin.math.sqrt
/**
* 扔两个鸡蛋
* 和上一题相同的问题,但现在假设你只有两个鸡蛋,而你的成本模型则是扔鸡蛋的次数。
* 设计一种策略,最多扔2*sqrt(N)次鸡蛋即可判断出F的值,然后想办法把这个成本降低到~c*sqrt(F)次。
* 这和查找命中(鸡蛋完好无损)比未命中(鸡蛋被摔碎)的成本小得多的情形类似。
*
* 解:先求出sqrt(N)的值,分别从... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 2,711 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/main/kotlin/leetcode/advanceds/Trie2.kt | sandeep549 | 251,593,168 | false | null | package leetcode.advanceds
private class Trie2 {
private class TrieNode {
var end = false
var children: MutableMap<Char, TrieNode?> = HashMap()
}
private var root = TrieNode()
// Insert word into Trie
fun insert(word: String) {
var trieNode: TrieNode = root
for (ch... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 2,085 | kotlinmaster | Apache License 2.0 |
src/aoc2017/kot/Day13.kt | Tandrial | 47,354,790 | false | null | package aoc2017.kot
import java.io.File
import kotlin.system.measureTimeMillis
object Day13 {
data class Layer(val depth: Int, val range: Int) {
fun isAtStart(offset: Int): Boolean = (depth + offset) % (2 * (range - 1)) == 0
}
// Sum of all layers which are at position 0 when we pass
fun partOne(input: L... | 0 | Kotlin | 1 | 1 | 9294b2cbbb13944d586449f6a20d49f03391991e | 1,079 | Advent_of_Code | MIT License |
src/Day14.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | fun main() {
fun read() = readInput("Day14").map { it.toCharArray() }
var map: List<CharArray> = read()
fun tiltN() {
for (i in map.indices) {
for (j in map[i].indices) {
if (map[i][j] == 'O') {
map[i][j] = '.'
var i1 = i
... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 2,651 | advent-of-code-kotlin | Apache License 2.0 |
2021/src/Day21.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | import kotlin.math.abs
import kotlin.math.max
// https://adventofcode.com/2021/day/20
fun main() {
class Dice {
var points = 0
var rolls = 0
fun roll() : Int {
rolls++
if (points == 100) {
points = 0
}
points++
return points
}
}
fun part1() {
// var pl... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 3,219 | advent-of-code | Apache License 2.0 |
src/main/java/challenges/leetcode/AddTwoNumbers.kt | ShabanKamell | 342,007,920 | false | null | package challenges.leetcode
/**
You are given two non-empty linked lists representing two non-negative integers.
The digits are stored in reverse order, and each of their nodes contains a single digit.
Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading z... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 2,717 | CodingChallenges | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.