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/dokerplp/bot/utli/StrignSimilarity.kt | dokerplp | 407,882,967 | false | {"Kotlin": 55171} | package dokerplp.bot.utli
import java.util.*
/*
Code was taken from
https://stackoverflow.com/questions/955110/similarity-string-comparison-in-java
*/
/**
* Calculates the similarity (a number within 0 and 1) between two strings.
*/
fun stringSimilarity(s1: String, s2: String): Double {
var longer = s1
var sh... | 0 | Kotlin | 0 | 0 | b3c530a3c7aff82a9072348ba036b364f33d0769 | 1,701 | abit-vt-bot | Apache License 2.0 |
src/main/kotlin/egger/software/hmm/algorithm/Viterbi.kt | eggeral | 127,237,737 | false | null | package egger.software.hmm.algorithm
import egger.software.hmm.HiddenMarkovModelWithObservations
import egger.software.hmm.StateWithProbability
import egger.software.hmm.probabilityOf
val <TState, TObservation> HiddenMarkovModelWithObservations<TState, TObservation>.mostLikelyStateSequence: List<TState>
get() {
... | 0 | Kotlin | 0 | 0 | 7252d9cd552ca57b82e027ebe2be2cb1ac6e30f6 | 2,687 | hidden-markov-model-examples | MIT License |
src/main/kotlin/g1401_1500/s1477_find_two_non_overlapping_sub_arrays_each_with_target_sum/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1401_1500.s1477_find_two_non_overlapping_sub_arrays_each_with_target_sum
// #Medium #Array #Hash_Table #Dynamic_Programming #Binary_Search #Sliding_Window
// #2023_06_13_Time_746_ms_(100.00%)_Space_50.7_MB_(100.00%)
class Solution {
fun minSumOfLengths(arr: IntArray, target: Int): Int {
var l = 0... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,145 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/RelativeSortArray.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 | 1,536 | kotlab | Apache License 2.0 |
src/main/kotlin/icfp2019/analyzers/ConservativeDistanceAnalyzer.kt | bspradling | 193,332,580 | true | {"JavaScript": 797310, "Kotlin": 85937, "CSS": 9434, "HTML": 5859} | package icfp2019.analyzers
import icfp2019.core.Analyzer
import icfp2019.core.DistanceEstimate
import icfp2019.model.GameBoard
import icfp2019.model.GameState
import icfp2019.model.Node
import icfp2019.model.Point
import org.jgrapht.alg.connectivity.ConnectivityInspector
import org.jgrapht.alg.spanning.PrimMinimumSpan... | 0 | JavaScript | 0 | 0 | 9f7e48cce858cd6a517d4fb69b9a0ec2d2a69dc5 | 2,228 | icfp-2019 | The Unlicense |
examples/src/main/kotlin/Sudoku.kt | UnitTestBot | 501,947,851 | false | {"Kotlin": 2669379, "C++": 97881, "C": 3122, "Shell": 2021, "CMake": 962} | import io.ksmt.KContext
import io.ksmt.expr.KExpr
import io.ksmt.expr.KInt32NumExpr
import io.ksmt.solver.KModel
import io.ksmt.solver.KSolverStatus
import io.ksmt.solver.z3.KZ3Solver
import io.ksmt.sort.KBoolSort
import io.ksmt.sort.KIntSort
import io.ksmt.utils.mkConst
import kotlin.system.measureTimeMillis
import ko... | 9 | Kotlin | 11 | 27 | fa2a997312627d7bc5afcaa3dfa1f1673221ce46 | 5,024 | ksmt | Apache License 2.0 |
算法/寻找两个正序数组的中位数4.kt | Simplation | 506,160,986 | false | {"Kotlin": 10116} | package com.example.rain_demo.algorithm
/**
*@author: Rain
*@time: 2022/7/20 14:34
*@version: 1.0
*@description: 寻找两个正序数组的中位数
*/
fun main() {
val nums1 = intArrayOf(1, 3)
val nums2 = intArrayOf(2)
val size1 = nums1.size
val size2 = nums2.size
val size = size1 + size2
if (size % 2 == 0) {... | 0 | Kotlin | 0 | 0 | d45feaa4c8ea2a08ce7357ee609a2df5b0639b68 | 2,604 | OpenSourceRepository | Apache License 2.0 |
src/main/kotlin/pub/edholm/aoc2017/day3/SpiralMemory.kt | Edholm | 112,762,269 | false | null | package pub.edholm.aoc2017.day3
import pub.edholm.aoc2017.utils.getInputForDay
import pub.edholm.aoc2017.utils.getResource
fun main(args: Array<String>) {
// Increase stack size with -Xss before running.
val formattedInput = formatInput(getInputForDay(3))
val spiralMemory = SpiralMemory()
println("Day 3:")
... | 0 | Kotlin | 0 | 3 | 1a087fa3dff79f7da293852a59b9a3daec38a6fb | 1,722 | aoc2017 | The Unlicense |
src/main/kotlin/g0901_1000/s0996_number_of_squareful_arrays/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s0996_number_of_squareful_arrays
// #Hard #Array #Dynamic_Programming #Math #Bit_Manipulation #Backtracking #Bitmask
// #2023_05_12_Time_139_ms_(100.00%)_Space_34.5_MB_(100.00%)
import kotlin.math.sqrt
class Solution {
var count = 0
fun numSquarefulPerms(nums: IntArray): Int {
val ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,283 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/aoc2015/Day02.kt | davidsheldon | 565,946,579 | false | {"Kotlin": 161960} | package aoc2015
import aoc2022.product
import utils.InputUtils
fun main() {
fun sides(len: List<Int>) = listOf((len[0]*len[1]), ( len[1]*len[2]),( len[0]*len[2]))
fun area(len: List<Int>) = 2*sides(len).sum() + sides(len).min()
fun boxes(input: List<String>) = input.map { it.split("x").map { it.toInt() ... | 0 | Kotlin | 0 | 0 | 5abc9e479bed21ae58c093c8efbe4d343eee7714 | 888 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/day3/PerfectlySphericalHousesInAVacuum.kt | SaujanShr | 685,121,393 | false | null | package day3
import getInput
val INPUT = getInput("day3")
fun run1(): String {
return getHousesVisitedNormal(INPUT).size
.toString()
}
fun run2(): String {
return getHousesVisitedRobot(INPUT).size
.toString()
}
fun getHousesVisitedNormal(directions: String): Set<Pair<Int, Int>> {
var loc... | 0 | Kotlin | 0 | 0 | c6715a9570e62c28ed022c5d9b330a10443206c4 | 1,467 | adventOfCode2015 | Apache License 2.0 |
src/main/kotlin/linked_lists/Question5.kt | jimmymorales | 446,845,269 | false | {"Kotlin": 46222} | package linked_lists
private fun LinkedListNode<Int>.plus(node: LinkedListNode<Int>): LinkedListNode<Int> {
var n1: LinkedListNode<Int>? = this
var n2: LinkedListNode<Int>? = node
val resHead = LinkedListNode(0)
var current: LinkedListNode<Int>? = null
var acm = 0
while (n1 != null || n2 != nul... | 0 | Kotlin | 0 | 0 | 8a32d379d5f3a2e779f6594d949f63d2e02aad4c | 1,295 | algorithms | MIT License |
string-similarity/src/commonMain/kotlin/com/aallam/similarity/Jaccard.kt | aallam | 597,692,521 | false | null | package com.aallam.similarity
import com.aallam.similarity.internal.Shingle
/**
* Each input string is converted into a set of n-grams, the Jaccard index is then computed as `|A ∩ B| / |A ∪ B|`.
*
* Like Q-Gram distance, the input strings are first converted into sets of n-grams (sequences of n characters, also
*... | 0 | Kotlin | 0 | 1 | 40cd4eb7543b776c283147e05d12bb840202b6f7 | 1,353 | string-similarity-kotlin | MIT License |
Kotlin/src/Permutations.kt | TonnyL | 106,459,115 | false | null | /**
* Given a collection of distinct numbers, return all possible permutations.
*
* For example,
* [1,2,3] have the following permutations:
* [
* [1,2,3],
* [1,3,2],
* [2,1,3],
* [2,3,1],
* [3,1,2],
* [3,2,1]
* ]
*
* Accepted.
*/
class Permutations {
fun permute(nums: IntArray): List<List<Int>> {
... | 1 | Swift | 22 | 189 | 39f85cdedaaf5b85f7ce842ecef975301fc974cf | 965 | Windary | MIT License |
src/exercises/Day06.kt | Njko | 572,917,534 | false | {"Kotlin": 53729} | // ktlint-disable filename
package exercises
import readInput
fun main() {
// Can be solved with: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/windowed-sequence.html
fun searchIndexOfMarker(data: String, markerSize: Int): Int {
var startIndex = 0
var indexOfMarker = markerSize
... | 0 | Kotlin | 0 | 2 | 68d0c8d0bcfb81c183786dfd7e02e6745024e396 | 1,728 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2015/Day07.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2015
import se.saidaspen.aoc.util.Day
fun main() = Day07.run()
object Day07 : Day(2015, 7) {
private var data = input.lines()
private val values = mutableMapOf<String, Int>()
private val consts = mutableMapOf<String, String>()
private val ands = mutableMapOf<String, Pair<... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 2,601 | adventofkotlin | MIT License |
src/main/kotlin/com/ginsberg/advent2016/Day21.kt | tginsberg | 74,924,040 | false | null | /*
* Copyright (c) 2016 by <NAME>
*/
package com.ginsberg.advent2016
/**
* Advent of Code - Day 21: December 21, 2016
*
* From http://adventofcode.com/2016/day/21
*
*/
class Day21(val instructions: List<String>) {
companion object {
private val SWAP_POSITION = Regex("""^swap position (\d+) with po... | 0 | Kotlin | 0 | 3 | a486b60e1c0f76242b95dd37b51dfa1d50e6b321 | 3,855 | advent-2016-kotlin | MIT License |
src/day01/Day01.kt | tiginamaria | 573,173,440 | false | {"Kotlin": 7901} | fun main() {
fun sums(input: List<String>): List<Int> {
val curSums = mutableListOf<Int>()
var curSum = 0
input.forEach {
if (it.isEmpty()) {
curSums.add(curSum)
curSum = 0
} else {
curSum += it.toInt()
}
... | 0 | Kotlin | 0 | 0 | bf81cc9fbe11dce4cefcb80284e3b19c4be9640e | 781 | advent-of-code-kotlin | Apache License 2.0 |
2020/day4/day4.kt | Deph0 | 225,142,801 | false | null |
class day4 {
fun part1(input: List<String>): Int {
val validFields = listOf(
"byr", // (Birth Year)
"iyr", // (Issue Year)
"eyr", // (Expiration Year)
"hgt", // (Height)
"hcl", // (Hair Color)
"ecl", // (Eye Color)
"pid" // (Passport ID)
// "cid" // (Country ... | 0 | Kotlin | 0 | 0 | 42a4fce4526182737d9661fae66c011f0948e481 | 30,850 | adventofcode | MIT License |
src/Day11.kt | a-glapinski | 572,880,091 | false | {"Kotlin": 26602} | import utils.readInputAsText
fun main() {
val input = readInputAsText("day11_input")
val monkeys = input.split("\n\n").map { Monkey(note = it.lines()) }
fun playKeepAway(monkeys: List<Monkey>, roundCount: Int, calculateWorryLevel: (Long, Int) -> Long): Long {
val modulus = monkeys.map { it.divisor... | 0 | Kotlin | 0 | 0 | c830d23ffc2ab8e9a422d015ecd413b5b01fb1a8 | 2,596 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/io/github/pshegger/aoc/y2020/Y2020D10.kt | PsHegger | 325,498,299 | false | null | package io.github.pshegger.aoc.y2020
import io.github.pshegger.aoc.common.BaseSolver
import io.github.pshegger.aoc.common.updated
import kotlin.math.pow
class Y2020D10 : BaseSolver() {
override val year = 2020
override val day = 10
override fun part1(): Int {
val data = parseInput()
val a... | 0 | Kotlin | 0 | 0 | 346a8994246775023686c10f3bde90642d681474 | 1,335 | advent-of-code | MIT License |
src/main/kotlin/chapter3/sec4/listing.kt | DavidGomesh | 680,857,367 | false | {"Kotlin": 204685} | package chapter3.sec4
sealed class List<out A>
object Nil : List<Nothing>() {
override fun toString(): String = "Nil"
}
data class Cons<out A>(val head: A, val tail: List<A>) : List<A>()
//tag::init1[]
fun sum(xs: List<Int>): Int = when (xs) {
is Nil -> 0
is Cons -> xs.head + sum(xs.tail)
}
fun product... | 0 | Kotlin | 0 | 0 | 41fd131cd5049cbafce8efff044bc00d8acddebd | 1,239 | fp-kotlin | MIT License |
src/main/kotlin/day02_dive/Dive.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package day02_dive
import util.saveTextFile
import java.io.PrintWriter
/**
* Compound state is the name of the game: modeling the position and depth as a
* single value. The input is not simple data to process either, but rather a
* set of instructions to interpret, necessitating building a (very simple)
* "virtu... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 4,065 | aoc-2021 | MIT License |
kotlin/src/com/s13g/aoc/aoc2020/Day9.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2020
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
/**
* --- Day 9: Encoding Error ---
* https://adventofcode.com/2020/day/9
*/
class Day9 : Solver {
override fun solve(lines: List<String>): Result {
val input = lines.map { it.toLong() }
val resultA = partA(25, input)
... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 1,193 | euler | Apache License 2.0 |
app/src/y2021/day16/Day16PacketDecoder.kt | henningBunk | 432,858,990 | false | {"Kotlin": 124495} | package y2021.day16
import common.*
import common.annotations.AoCPuzzle
fun main(args: Array<String>) {
Day16PacketDecoder().solveThem()
}
@AoCPuzzle(2021, 16)
class Day16PacketDecoder : AocSolution {
override val answers = Answers(samplePart1 = 31, samplePart2 = 54, part1 = 889, part2 = 739303923668)
o... | 0 | Kotlin | 0 | 0 | 94235f97c436f434561a09272642911c5588560d | 4,983 | advent-of-code-2021 | Apache License 2.0 |
kotlin/geometry/Closest2PointsFast.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package geometry
import numeric.FFT
import optimization.Simplex
object Closest2PointsFast {
// Find closest pair in O(n*log(n))
fun findClosestPair(points: Array<Point?>): Array<Point?> {
Arrays.sort(points, Comparator.comparingInt { p -> p.x })
val sortedY: Array<Point> = points.clone()
... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 3,114 | codelibrary | The Unlicense |
src/day04/Day04.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day04
import readInput
fun main() {
fun part1(input: List<String>): Int {
return input.map {
it.split(",", "-").map { it.toInt() }
}.count {
val (first, second, third, fourth) = it
(first in third..fourth && second in third..fourth) || (third in first..... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 793 | aoc-2022-kotlin | Apache License 2.0 |
solutions/src/RegexMatching.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | /**
* https://leetcode.com/problems/regular-expression-matching/
*/
class RegexMatching {
fun isMatch(s: String, p: String) : Boolean {
val dpArray = arrayOfNulls<Array<Boolean?>>(s.length+1)
for (i in dpArray.indices) {
dpArray[i] = arrayOfNulls(p.length+1)
}
for (i in... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 1,237 | leetcode-solutions | MIT License |
src/main/kotlin/de/mbdevelopment/adventofcode/year2021/solvers/day12/Day12Puzzle.kt | Any1s | 433,954,562 | false | {"Kotlin": 96683} | package de.mbdevelopment.adventofcode.year2021.solvers.day12
import de.mbdevelopment.adventofcode.year2021.solvers.PuzzleSolver
abstract class Day12Puzzle : PuzzleSolver {
companion object {
@JvmStatic
protected val START = Cave.SmallCave("start")
@JvmStatic
protected val END = C... | 0 | Kotlin | 0 | 0 | 21d3a0e69d39a643ca1fe22771099144e580f30e | 1,408 | AdventOfCode2021 | Apache License 2.0 |
src/Day10.kt | makohn | 571,699,522 | false | {"Kotlin": 35992} | fun main() {
fun part1(input: List<String>): Int {
var acc = 0
var x = 1
var cycle = 0
fun tick() {
cycle++
if (cycle in (20 .. 220) step 40) {
acc += cycle * x
}
}
for (parts in input.map { it.split(" ") }) {
... | 0 | Kotlin | 0 | 0 | 2734d9ea429b0099b32c8a4ce3343599b522b321 | 1,464 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/askrepps/advent2021/day15/Day15.kt | askrepps | 726,566,200 | false | {"Kotlin": 302802} | /*
* MIT License
*
* Copyright (c) 2021-2023 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modi... | 0 | Kotlin | 0 | 0 | 89de848ddc43c5106dc6b3be290fef5bbaed2e5a | 3,723 | advent-of-code-kotlin | MIT License |
src/main/kotlin/enigma/util/Util.kt | aurelioklv | 737,580,684 | false | {"Kotlin": 83511} | package com.aurelioklv.enigma.util
val alphabet = ('A'..'Z').joinToString(separator = "")
val defaultWiring: Map<Char, Char> = ('A'..'Z').associateWith { it }
fun validateWiring(wiring: Map<Char, Char>, kind: String) {
require(wiring.isNotEmpty()) {
"Wiring is empty"
}
require(wiring.all { (key, ... | 0 | Kotlin | 0 | 0 | 2110e20ab9e5d2160b0e32bda137b0f63a93ecc3 | 1,993 | enigma | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[98]验证二叉搜索树.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} |
//给你一个二叉树的根节点 root ,判断其是否是一个有效的二叉搜索树。
//
// 有效 二叉搜索树定义如下:
//
//
// 节点的左子树只包含 小于 当前节点的数。
// 节点的右子树只包含 大于 当前节点的数。
// 所有左子树和右子树自身必须也是二叉搜索树。
//
//
//
//
// 示例 1:
//
//
//输入:root = [2,1,3]
//输出:true
//
//
// 示例 2:
//
//
//输入:root = [5,1,4,null,null,3,6]
//输出:false
//解释:根节点的值是 5 ,但是右子节点的值是 4 。
//
//
//
//
// 提... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,809 | MyLeetCode | Apache License 2.0 |
archive/2022/Day06.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | private const val EXPECTED_1 = 7
private const val EXPECTED_2 = 19
private class Day06(isTest: Boolean) : Solver(isTest) {
fun firstUniqueSubstring(data: String, len: Int): Int {
val lastSeen = IntArray(26) { -100 }
var candidateStart = 0
data.forEachIndexed { index, char ->
val... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 1,029 | advent-of-code-2022 | Apache License 2.0 |
2022/src/main/kotlin/de/skyrising/aoc2022/day13/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2022.day13
import de.skyrising.aoc.*
import kotlinx.serialization.json.*
private fun compare(left: JsonElement, right: JsonElement): Int {
if (left is JsonPrimitive && right is JsonPrimitive) {
return left.int - right.int
}
if (left is JsonArray && right is JsonArray) {
... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 1,613 | aoc | MIT License |
src/main/kotlin/ru/spbstu/player/Christofides.kt | belyaev-mikhail | 192,383,116 | false | null | package ru.spbstu.player
import org.graphstream.algorithm.Kruskal
import org.graphstream.graph.Edge
import org.graphstream.graph.Graph
import org.graphstream.graph.Node
import org.graphstream.graph.implementations.SingleGraph
import org.jgrapht.alg.shortestpath.JohnsonShortestPaths
import org.jgrapht.alg.tour.Christof... | 1 | Kotlin | 0 | 0 | cd5c7d668bf6615fd7e639ddfce0c135c138de42 | 2,394 | icfpc-2019 | MIT License |
src/main/kotlin/aoc03/Solution03.kt | rainer-gepardec | 573,386,353 | false | {"Kotlin": 13070} | package aoc03
import java.nio.file.Paths
val valueMap = calculateValueMap();
fun calculateValueMap(): Map<Char, Int> {
val tmpMap = mutableMapOf<Char, Int>()
var c = 'a';
while (c <= 'z') {
tmpMap[c] = c.code - 96;
c++
}
c = 'A'
while (c <= 'Z') {
tmpMap[c] = c.code -... | 0 | Kotlin | 0 | 0 | c920692d23e8c414a996e8c1f5faeee07d0f18f2 | 1,378 | aoc2022 | Apache License 2.0 |
src/main/kotlin/trees/BinaryTree.kt | gabrielshanahan | 306,346,842 | false | {"Kotlin": 4410} | package trees
import java.lang.IllegalArgumentException
import kotlin.math.max
import kotlin.math.min
sealed class Type {
object Leaf: Type() { override fun toString(): String = "Leaf" }
object Single: Type() { override fun toString(): String = "Single" }
object Double: Type() { override fun toString():... | 0 | Kotlin | 0 | 0 | f9f2dee8e819da5ded9ed37ee285f852e7aadc37 | 2,227 | BinarySearchTree | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DeepestLeavesSum.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,764 | kotlab | Apache License 2.0 |
lib/src/main/kotlin/com/dzirbel/robopower/util/MapExtensions.kt | dzirbel | 581,328,184 | false | {"Kotlin": 178493} | package com.dzirbel.robopower.util
/**
* Returns the key(s) whose associated values are the largest according to [comparator].
*/
internal fun <K, V> Map<K, V>.maxKeysBy(comparator: Comparator<V>): Set<K> {
val iterator = iterator()
if (!iterator.hasNext()) throw NoSuchElementException()
val first = ite... | 0 | Kotlin | 1 | 1 | 6c6f0a17361d7ed45bdd4d4b51d257f18dee5d98 | 1,162 | robopower | MIT License |
2020/src/year2020/day09/Day09.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2020.day09
import util.readAllLinesAsLong
private fun findFirstFailure(filename: String, preambleLength: Int): Pair<Long, List<Long>> {
val original = readAllLinesAsLong(filename)
val list = original.toMutableList()
while (list.size > preambleLength) {
val testValue = list[preambleLen... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 1,414 | adventofcode | MIT License |
src/main/kotlin/io/nozemi/aoc/solutions/year2021/day08/impl/SegmentPattern.kt | Nozemi | 433,882,587 | false | {"Kotlin": 92614, "Shell": 421} | package io.nozemi.aoc.solutions.year2021.day08.impl
class SegmentPattern(
val outputPatterns: Array<Set<Char>>,
val signalPatterns: Array<Set<Char>>,
) {
private val knownLetters: MutableMap<Char, Char> = mutableMapOf()
private val knownNumbers: Array<Set<Char>> = Array(10) { emptySet() }
/**
... | 0 | Kotlin | 0 | 0 | fc7994829e4329e9a726154ffc19e5c0135f5442 | 6,269 | advent-of-code | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/RotateImage.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,208 | kotlab | Apache License 2.0 |
2021/src/day24/Day24.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day24
import readInput
import java.lang.IllegalStateException
import java.text.SimpleDateFormat
import java.util.*
val POSSIBLE_DIGIT = listOf(9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L)
fun getVarFromStr(str: String, w: Long, x: Long, y: Long, z: Long) : Long {
return when (str) {
"z" -> z
"w" -... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 5,621 | advent-of-code | Apache License 2.0 |
src/Day01.kt | dakr0013 | 572,861,855 | false | {"Kotlin": 105418} | import kotlin.test.assertEquals
fun main() {
fun part1(input: List<String>): Int {
return input
.joinToString("\n")
.split("\n\n")
.map { inventory -> inventory.split("\n").sumOf { it.toInt() } }
.max()
}
fun part2(input: List<String>): Int {
return input
.joinToS... | 0 | Kotlin | 0 | 0 | 6b3adb09f10f10baae36284ac19c29896d9993d9 | 764 | aoc2022 | Apache License 2.0 |
src/org/mjurisic/aoc2020/day14/Day14.kt | mjurisic | 318,555,615 | false | null | package org.mjurisic.aoc2020.day14
import java.io.File
import java.math.BigInteger
class Day14 {
companion object {
@JvmStatic
fun main(args: Array<String>) = try {
var mask = ""
val mem = HashMap<String, BigInteger>()
File(ClassLoader.getSystemResource("reso... | 0 | Kotlin | 0 | 0 | 9fabcd6f1daa35198aaf91084de3b5240e31b968 | 3,301 | advent-of-code-2020 | Apache License 2.0 |
common/src/main/kotlin/be/swsb/aoc/common/Positioning.kt | Sch3lp | 318,098,967 | false | null | package be.swsb.aoc.common
import be.swsb.aoc.common.Position.Companion.at
import java.io.Serializable
data class Quadrants<out T>(
val topRight: T,
val bottomRight: T,
val topLeft: T,
val bottomLeft: T
) : Serializable {
/**
* Returns string representation of the [Quadrants]... | 0 | Kotlin | 0 | 0 | 32630a7efa7893b4540fd91d52c2ff3588174c96 | 2,314 | Advent-of-Code-2020 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LongestNiceSubstring.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,472 | kotlab | Apache License 2.0 |
src/_2022/Day04.kt | albertogarrido | 572,874,945 | false | {"Kotlin": 36434} | package _2022
import readInput
fun main() {
runTests()
runScenario(readInput("2022","day04"))
}
private fun runScenario(input: List<String>) {
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>): Int {
var redundancies = 0
parseAssignments(input).forEach {
... | 0 | Kotlin | 0 | 0 | ef310c5375f67d66f4709b5ac410d3a6a4889ca6 | 2,109 | AdventOfCode.kt | Apache License 2.0 |
src/main/kotlin/aoc2015/day01_almost_lisp/almost_lisp.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package aoc2015.day01_almost_lisp
import kotlin.streams.toList
fun main() {
util.solve(280, ::partOne)
util.solve(1797, ::partTwo)
}
private fun String.toDeltaStream() = this.chars()
.map(::parenToDelta)
fun partOne(input: String) = input
.toDeltaStream()
.reduce(0, Int::plus)
fun partTwo(input... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 952 | aoc-2021 | MIT License |
src/medium/_215KthLargestElementInAnArray.kt | ilinqh | 390,190,883 | false | {"Kotlin": 382147, "Java": 32712} | package medium
class _215KthLargestElementInAnArray {
// 堆排序可以尽可能的降低时间复杂度
class Solution {
fun findKthLargest(nums: IntArray, k: Int): Int {
var heapSize = nums.size
buildMaxHeap(nums, heapSize)
for (i in (nums.size - 1) downTo (nums.size - k + 1)) {
swap(nums, 0, i)
... | 0 | Kotlin | 0 | 0 | 8d2060888123915d2ef2ade293e5b12c66fb3a3f | 1,194 | AlgorithmsProject | Apache License 2.0 |
src/main/kotlin/me/grison/aoc/y2021/Day12.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc.y2021
import me.grison.aoc.*
import java.util.function.Predicate
class Day12 : Day(12, 2021) {
override fun title() = "Passage Pathing"
private val graph = inputList.map { it.normalSplit("-").pair() }.toGraph()
override fun partOne() = graph.countAllPaths("start", "end", trackVisit... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 1,791 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/io/binarysearch/MedianTwoSortedArrays.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.binarysearch
import kotlin.math.max
import kotlin.math.min
//https://leetcode.com/explore/learn/card/binary-search/146/more-practices-ii/1040/
class MedianTwoSortedArrays {
fun execute(input0: IntArray, input1: IntArray): Double {
val smallInput = if (input0.size < input1.size) input0 else input1
... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,470 | coding | MIT License |
src/chapter4/section3/ex10.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter4.section3
import edu.princeton.cs.algs4.In
import edu.princeton.cs.algs4.Queue
/**
* 为稠密图实现EdgeWeightedGraph,使用邻接矩阵(存储权重的二维数组),不允许存在平行边。
*/
class AdjacencyMatrixEWG(V: Int) : EWG(V) {
private val matrix = Array(V) { Array(V) { Double.POSITIVE_INFINITY } }
constructor(input: In) : this(input... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,999 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/Day25.kt | janbina | 112,736,606 | false | null | package Day25
import java.util.*
import kotlin.test.assertEquals
fun main(args: Array<String>) {
//INPUT:
val initialState = 1
val steps = 12_172_063
val transitions = listOf(
TuringMachine.Transition(1, false, 2, true, TuringMachine.Transition.Move.RIGHT),
TuringMachine.Trans... | 0 | Kotlin | 0 | 0 | 71b34484825e1ec3f1b3174325c16fee33a13a65 | 2,450 | advent-of-code-2017 | MIT License |
kotlin tutorial/scratch.kts | AlexandraDediu | 244,655,422 | false | null | val x = 5 //also type inference
println(x)
var name = "John" //daca vrem ca valoarea sa se poata modifica
name = "Mary"
println(name)
var name1: String? = null //var can be nullable
val length = name1?.length ?: -1
println(length)
//val length2 = name1!!.length
//println(length2)
fun sumOfTwo(x: Int, y: Int): Int {... | 0 | Kotlin | 0 | 0 | c4b37692343899083e1a643085e9db4b9b484f6c | 1,852 | aquamarine | Apache License 2.0 |
src/main/kotlin/org/team2471/frc/lib/math/Geometry.kt | TeamMeanMachine | 72,503,638 | false | {"Kotlin": 139167, "Java": 95325} | package org.team2471.frc.lib.math
import java.lang.Math.pow
import java.lang.Math.sqrt
data class Point(val x: Double, val y: Double) {
companion object {
@JvmStatic
val ORIGIN: Point = Point(0.0, 0.0)
}
operator fun unaryPlus() = this
operator fun unaryMinus() = Point(-x, -y)
... | 3 | Kotlin | 3 | 15 | 93dd7e7163ec2535e11965687e563369ca899f21 | 3,276 | meanlib | The Unlicense |
day20/src/main/kotlin/ver_b.kt | jabbalaci | 115,397,721 | false | null | package b
import java.math.BigInteger
import java.io.File
data class Point(var x: BigInteger, var y: BigInteger, var z: BigInteger)
data class Particle(val id: Int, val line: String) {
private val points = mutableListOf<Point>()
init {
val REGEX = Regex("""<(.*?)>""")
val matchedResults = R... | 0 | Kotlin | 0 | 0 | bce7c57fbedb78d61390366539cd3ba32b7726da | 2,959 | aoc2017 | MIT License |
Mastermind/src/mastermind/evaluateGuess.kt | Sharkaboi | 258,941,707 | false | null | package mastermind
import java.lang.Integer.min
data class Evaluation(val rightPosition: Int, val wrongPosition: Int)
fun evaluateGuess( secret: String, guess: String): Evaluation {
//count of right positions
var right = 0
//A-0,B-1,C-2,D-3,E-4,F-5
//array for A-F with count for each occurrence (secr... | 0 | Kotlin | 0 | 0 | 977968b41ecc0ed1b62b50784bfebc3fa9d95a11 | 1,300 | Kotlin-for-java-devs-course | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MctFromLeafValues.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,438 | kotlab | Apache License 2.0 |
src/main/kotlin/me/grison/aoc/y2020/Day23.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc.y2020
import me.grison.aoc.Day
import me.grison.aoc.normalSplit
import kotlin.collections.set
class Day23 : Day(23, 2020) {
override fun title() = "Crab Cups"
override fun partOne(): Any {
val cups = loadCups()
var cup: Cup = cups[0]
for (i in 1..100) {
... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 2,837 | advent-of-code | Creative Commons Zero v1.0 Universal |
kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/strings.kt | ca-r0-l | 258,232,982 | true | {"Kotlin": 2272378, "HTML": 423, "Java": 153} | package io.kotest.property.arbitrary
import io.kotest.fp.firstOption
import io.kotest.property.Arb
import io.kotest.property.Shrinker
import kotlin.random.nextInt
/**
* Returns an [Arb] where each random value is a String of length between minSize and maxSize.
* By default the arb uses a [ascii] codepoint generator... | 0 | null | 0 | 1 | e176cc3e14364d74ee593533b50eb9b08df1f5d1 | 2,321 | kotest | Apache License 2.0 |
src/main/kotlin/solutions/CHK/CheckoutSolution.kt | DPNT-Sourcecode | 718,056,917 | false | {"Kotlin": 22059, "Shell": 2184} | package solutions.CHK
import kotlin.jvm.internal.Intrinsics.Kotlin
object CheckoutSolution {
fun checkout(skus: String): Int {
var total = 0
val counts = mutableMapOf<Char, Int>()
val groupDiscountItems = listOf('S', 'T', 'X', 'Y', 'Z')
val individualPrices = mapOf('S' to 20, 'T' ... | 0 | Kotlin | 0 | 0 | b1947b8c4243303f6998f2e23774b175423a3718 | 5,269 | CHK-edzx01 | Apache License 2.0 |
kotlin/src/test/kotlin/be/swsb/aoc2023/day4/Solve.kt | Sch3lp | 724,797,927 | false | {"Kotlin": 44815, "Rust": 14075} | package be.swsb.aoc2023.day4
import be.swsb.aoc2023.readFile
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.equals.shouldBeEqual
import org.junit.jupiter.api.Test
class Day4Test {
private val actualInput = readFile("2023/day4/input.txt")
@Test
fun parse() {
v... | 0 | Kotlin | 0 | 1 | dec9331d3c0976b4de09ce16fb8f3462e6f54f6e | 2,253 | Advent-of-Code-2023 | MIT License |
src/main/kotlin/g1601_1700/s1658_minimum_operations_to_reduce_x_to_zero/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1601_1700.s1658_minimum_operations_to_reduce_x_to_zero
// #Medium #Array #Hash_Table #Binary_Search #Prefix_Sum #Sliding_Window
// #2023_06_15_Time_532_ms_(50.00%)_Space_53_MB_(100.00%)
class Solution {
fun minOperations(nums: IntArray, x: Int): Int {
var totalArraySum = 0
for (each in nu... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,133 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/org/example/adventofcode/puzzle/Day02.kt | peterlambrechtDev | 573,146,803 | false | {"Kotlin": 39213} | package org.example.adventofcode.puzzle
import org.example.adventofcode.util.FileLoader
private const val DELIMITER = " "
private val part1Map = mutableMapOf(Pair("A", 1), Pair("B", 2), Pair("C", 3), Pair("X", 1), Pair("Y", 2), Pair("Z", 3))
private val part2Map = mutableMapOf(
Pair(1, mutableMapOf(Pair("Z", 2)... | 0 | Kotlin | 0 | 0 | aa7621de90e551eccb64464940daf4be5ede235b | 2,409 | adventOfCode2022 | MIT License |
app/src/main/java/io/github/pshegger/gamedevexperiments/algorithms/pathfinding/AStar.kt | PsHegger | 99,228,633 | false | null | package io.github.pshegger.gamedevexperiments.algorithms.pathfinding
import io.github.pshegger.gamedevexperiments.algorithms.maze.BaseMazeGenerator
import java.util.*
/**
* @author <EMAIL>
*/
class AStar(maze: List<List<BaseMazeGenerator.FieldValue>>, val heuristic: (Coordinate, Coordinate) -> Float, val tieBreaker... | 0 | Kotlin | 0 | 0 | 694d273a6d3dff49cf314cbe16e17b5f77c7738e | 3,113 | GameDevExperiments | MIT License |
src/main/kotlin/dev/claudio/adventofcode2021/Day8Part2.kt | ClaudioConsolmagno | 434,559,159 | false | {"Kotlin": 78336} | package dev.claudio.adventofcode2021
fun main() {
Day8Part2().main()
}
private class Day8Part2 {
fun main() {
val input: List<InputLine> = Support.readFileAsListString("day8-input.txt")
.map {
val split = it.split("|")
InputLine(
split[0... | 0 | Kotlin | 0 | 0 | 5f1aff1887ad0a7e5a3af9aca7793f1c719e7f1c | 3,626 | adventofcode-2021 | Apache License 2.0 |
src/Day01.kt | NunoPontes | 572,963,410 | false | {"Kotlin": 7416} | fun main() {
fun calculateList(input: List<String>): MutableList<Int> {
val mutableListCalories = mutableListOf<Int>()
mutableListCalories.add(0)
input.forEach { calorie ->
if (calorie.isNotBlank()) {
mutableListCalories[mutableListCalories.lastIndex] =
... | 0 | Kotlin | 0 | 0 | 78b67b952e0bb51acf952a7b4b056040bab8b05f | 996 | advent-of-code-2022 | Apache License 2.0 |
app/src/main/kotlin/com/resurtm/aoc2023/day19/Part1.kt | resurtm | 726,078,755 | false | {"Kotlin": 119665} | package com.resurtm.aoc2023.day19
internal fun solvePart1(input: Input): Long =
input.workflows.fold(0L) { acc, it -> acc + traverseWorkflow(it, input.rules) }
private fun traverseWorkflow(workflow: Workflow, rules: Map<String, Rule>): Long {
var curr = "in"
while (curr !in arrayOf("A", "R")) {
v... | 0 | Kotlin | 0 | 0 | fb8da6c246b0e2ffadb046401502f945a82cfed9 | 1,366 | advent-of-code-2023 | MIT License |
Kotlin/src/SearchA2DMatrix.kt | TonnyL | 106,459,115 | false | null | /**
* Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
*
* Integers in each row are sorted from left to right.
* The first integer of each row is greater than the last integer of the previous row.
* For example,
*
* Consider the following matrix... | 1 | Swift | 22 | 189 | 39f85cdedaaf5b85f7ce842ecef975301fc974cf | 1,016 | Windary | MIT License |
src/main/kotlin/oct_challenge2021/Trie.kt | yvelianyk | 405,919,452 | false | {"Kotlin": 147854, "Java": 610} | package oct_challenge2021
fun main() {
val trie = Trie()
trie.insert("apple")
val res1 = trie.search("apple")
assert(res1)
val res2 = trie.search("app")
assert(!res2)
val res3 = trie.startsWith("app")
assert(res3)
trie.insert("app")
val res4 = trie.search("app")
assert(res4)... | 0 | Kotlin | 0 | 0 | 780d6597d0f29154b3c2fb7850a8b1b8c7ee4bcd | 1,629 | leetcode-kotlin | MIT License |
src/main/kotlin/org/mechdancer/geometry/transformation/Quaternion.kt | MechDancer | 128,765,281 | false | null | package org.mechdancer.geometry.transformation
import org.mechdancer.algebra.doubleEquals
import org.mechdancer.algebra.hash
import org.mechdancer.algebra.implement.vector.vector3D
import kotlin.math.sqrt
/** 四元数 */
data class Quaternion(
val a: Double,
val b: Double,
val c: Double,
val d: Double
) {
... | 1 | Kotlin | 1 | 6 | 2cbc7e60b3cd32f46a599878387857f738abda46 | 1,893 | linearalgebra | Do What The F*ck You Want To Public License |
src/main/io/uuddlrlrba/ktalgs/sorts/MergeSort.kt | bmaslakov | 83,349,679 | false | null | /*
* Copyright (c) 2017 Kotlin Algorithm Club
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merg... | 4 | Kotlin | 144 | 883 | a8fa9edf615d0498bd1d2e8328f72a180d345343 | 2,566 | kotlin-algorithm-club | MIT License |
src/Day10.kt | ech0matrix | 572,692,409 | false | {"Kotlin": 116274} | import kotlin.math.abs
fun main() {
fun part1(input: List<String>): Int {
var x = 1
var cycle = 0
val calcCycle = setOf(20, 60, 100, 140, 180, 220)
var signal = 0
for(line in input) {
cycle++
val split = line.split(' ')
val command = spl... | 0 | Kotlin | 0 | 0 | 50885e12813002be09fb6186ecdaa3cc83b6a5ea | 1,800 | aoc2022 | Apache License 2.0 |
src/test/kotlin/de/tek/adventofcode/y2022/day14/RegolithReservoirTest.kt | Thumas | 576,671,911 | false | {"Kotlin": 192328} | package de.tek.adventofcode.y2022.day14
import de.tek.adventofcode.y2022.util.math.Point
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
class CaveTest : StringSpec({
val rockPositionsFromExample = listOf(
498 to 4,
498 to 5,
498 to 6,
497 to 6,
... | 0 | Kotlin | 0 | 0 | 551069a21a45690c80c8d96bce3bb095b5982bf0 | 3,318 | advent-of-code-2022 | Apache License 2.0 |
foundations/binary-search/BinarySearch.kt | ivan-magda | 102,283,964 | false | null | import java.util.*
fun binarySearchRecursively(array: Array<Int>, target: Int): Int {
if (array.isEmpty()) {
return -1
}
return binarySearchRecursively(array, target, 0, array.size - 1)
}
private fun binarySearchRecursively(array: Array<Int>, target: Int, start: Int, end: Int): Int {
if (star... | 0 | Kotlin | 0 | 2 | da06ec75cbd06c8e158aec86ca813e72bd22a2dc | 1,390 | introduction-algorithms | MIT License |
codeforces/deltix2021summer/d.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.deltix2021summer
fun ask(or: Boolean, i: Int, j: Int): Int {
val s = if (or) "or" else "and"
println("$s ${i + 1} ${j + 1}")
return readInt()
}
fun main() {
val (n, k) = readInts()
val (ands, ors) = List(2) { or -> List(n - 1) { ask(or == 1, 0, it + 1) } }
val and12 = ask(false, 1, 2)
val a ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 900 | competitions | The Unlicense |
com/ztoais/dailycoding/algoexpert/easy/TwoNumberSum.kt | RanjithRagavan | 479,563,314 | false | {"Kotlin": 7371} | package com.ztoais.dailycoding.algoexpert.easy
/*
Two Number Sum
Write a function that takes in a non-empty array of distinct integers and an integer representing a target sum. If any
two numbers in the input array sum up to the target sum, the function should return then in an array. in any order. if
no two numbers s... | 0 | Kotlin | 0 | 0 | a5f29dd82c0c50fc7d2490fd1be6234cdb4d1d8a | 2,066 | daily-coding | MIT License |
src/main/kotlin/OpenRange.kt | snarks | 165,013,289 | false | null | /*
* 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 in wr... | 0 | Kotlin | 0 | 0 | 96d114ebe93782a6824451b7178f5b49313a71a0 | 3,267 | OpenRange | Apache License 2.0 |
src/main/kotlin/me/peckb/aoc/_2020/calendar/day16/Day16.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2020.calendar.day16
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
class Day16 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
data class Field(val name: String, val lowerRange: IntRange, val upperRange: IntRange)... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 3,757 | advent-of-code | MIT License |
kotlin/src/main/kotlin/com/tolchev/algo/matrix/1559DetectCycles2DFast.kt | VTolchev | 692,559,009 | false | {"Kotlin": 53858, "C#": 47939, "Java": 1802} | package com.tolchev.algo.matrix
class DetectCycles2DFast {
fun containsCycle(grid: Array<CharArray>): Boolean {
val possibleSteps = arrayOf (-1 to 0, 1 to 0, 0 to-1, 0 to 1)
var visited = Array(grid.size){ BooleanArray(grid[0].size){false} }
val maxRow = grid.size
val maxCol = gr... | 0 | Kotlin | 0 | 0 | c3129f23e4e7ba42b44f9fb4af39a95f4a762550 | 1,471 | algo | MIT License |
src/main/kotlin/io/github/clechasseur/adventofcode/y2015/Day24.kt | clechasseur | 568,233,589 | false | {"Kotlin": 242914} | package io.github.clechasseur.adventofcode.y2015
import io.github.clechasseur.adventofcode.y2015.data.Day24Data
object Day24 {
private val input = Day24Data.input
fun part1(): Long = minQuantumEntanglement(input.sum() / 3L)
fun part2(): Long = minQuantumEntanglement(input.sum() / 4L)
private fun mi... | 0 | Kotlin | 0 | 0 | e5a83093156cd7cd4afa41c93967a5181fd6ab80 | 1,076 | adventofcode2015 | MIT License |
aoc2022/day3.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2022
import utils.InputRetrieval
fun main() {
Day3.execute()
}
object Day3 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
private val PRIORITIES = ('a'..'z').plus('A'..'Z')
private fun part1(in... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 948 | Advent-Of-Code | MIT License |
src/commonMain/kotlin/com/jeffpdavidson/kotwords/model/Coded.kt | jpd236 | 143,651,464 | false | {"Kotlin": 4390419, "HTML": 41919, "Rouge": 3731, "Perl": 1705, "Shell": 744, "JavaScript": 618} | package com.jeffpdavidson.kotwords.model
import com.jeffpdavidson.kotwords.formats.Puzzleable
import com.jeffpdavidson.kotwords.util.trimmedLines
data class Coded(
val title: String,
val creator: String,
val copyright: String,
val description: String,
val grid: List<List<Char?>>,
val assignmen... | 5 | Kotlin | 5 | 19 | c2dc23bafc7236ba076a63060e08e6dc134c8e24 | 3,747 | kotwords | Apache License 2.0 |
src/main/kotlin/ctci/chaptereight/Coins.kt | amykv | 538,632,477 | false | {"Kotlin": 169929} | package ctci.chaptereight
// 8.11 - page 136
// Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write
// Kotlin code to calculate the number of ways representing n cents.
fun main() {
val cents = 50
println("Number of ways to represent $cents cents: ... | 0 | Kotlin | 0 | 2 | 93365cddc95a2f5c8f2c136e5c18b438b38d915f | 1,973 | dsa-kotlin | MIT License |
src/main/kotlin/day03/Day3.kt | limelier | 725,979,709 | false | {"Kotlin": 48112} | package day03
import common.InputReader
private typealias PartPos = Pair<Int, Int>
public fun main() {
val matrix = InputReader("day03/input.txt").lines().map { it.toCharArray() }
// establish bounds
val rowIndices = matrix.indices
val colIndices = matrix[0].indices
var partNumberSum = 0
va... | 0 | Kotlin | 0 | 0 | 0edcde7c96440b0a59e23ec25677f44ae2cfd20c | 2,258 | advent-of-code-2023-kotlin | MIT License |
app/jvmApp/src/main/java/ru/snowmaze/barstats/GetPlayerStatisticsResultMapper.kt | Snowmaze-dev | 739,169,546 | false | {"Kotlin": 99000} | package ru.snowmaze.barstats
import ru.snowmaze.barstats.models.GetStatisticsResult
import ru.snowmaze.barstats.models.PlayerData
import ru.snowmaze.barstats.models.PlayerStats
import ru.snowmaze.barstats.models.WithPlayerStat
import java.util.concurrent.TimeUnit
fun GetStatisticsResult.mapToSection(splitter: String)... | 0 | Kotlin | 0 | 0 | 7e289b6bab307e635a9daab34afc24103c8a0636 | 4,601 | BarStats | Apache License 2.0 |
advent-of-code-2020/src/test/java/aoc/Points.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | package aoc
import kotlin.math.abs
data class Point(val x: Int, val y: Int, val z: Int = 0, val w: Int = 0) {
operator fun minus(other: Point) = Point(x - other.x, y - other.y, z - other.z, w - other.w)
operator fun plus(other: Point) = Point(x + other.x, y + other.y, z + other.z, w + other.w)
operator fu... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 1,775 | advent-of-code | MIT License |
src/day02/Day02.kt | EdwinChang24 | 572,839,052 | false | {"Kotlin": 20838} | package day02
import readInput
fun main() {
part1()
part2()
}
fun part1() {
val guide = readInput(2).map { it[0] to it[2] }
var total = 0
for (strategy in guide) {
total += when (strategy) {
'A' to 'X', 'B' to 'Y', 'C' to 'Z' -> 3
'A' to 'Y', 'B' to 'Z', 'C' to 'X'... | 0 | Kotlin | 0 | 0 | e9e187dff7f5aa342eb207dc2473610dd001add3 | 972 | advent-of-code-2022 | Apache License 2.0 |
src/week3/BuildTree.kt | anesabml | 268,056,512 | false | null | package week3
class BuildTree {
/** Recursive
* Preorder -> root, left, right
* Inorder -> left, root, right
* We get the root from the preorder traversal and the left / right from inorder traversal
* We find the root index in inoder traversal array, we know that inorder traverses left before ... | 0 | Kotlin | 0 | 1 | a7734672f5fcbdb3321e2993e64227fb49ec73e8 | 2,269 | leetCode | Apache License 2.0 |
AOC2022/src/main/kotlin/AOC8.kt | bsautner | 575,496,785 | false | {"Kotlin": 16189, "Assembly": 496} | import java.io.File
class AOC8 {
var maxScore = 0
fun process() {
val input = File("/home/ben/aoc/input-8.txt")
val sample = input.useLines { it.toList() }
val matrix = sample.map { it.toCharArray() }.toTypedArray()
var count = 0
matrix.mapIndexed { y, row ->
... | 0 | Kotlin | 0 | 0 | 5f53cb1c4214c960f693c4f6a2b432b983b9cb53 | 1,898 | Advent-of-Code-2022 | The Unlicense |
src/main/kotlin/dev/bogwalk/batch2/Problem22.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch2
/**
* Problem 22: Names Scores
*
* https://projecteuler.net/problem=22
*
* Goal: Given an unsorted list of N names, first sort alphabetically, then, given 1 of the
* names, multiply the sum of the value of all its characters by its position in the alphabetical
* list.
*
* Constraint... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 1,467 | project-euler-kotlin | MIT License |
LeetCode/Kotlin/src/main/kotlin/org/redquark/tutorials/leetcode/SubstringWithConcatenationOfAllWords.kt | ani03sha | 297,402,125 | false | null | package org.redquark.tutorials.leetcode
class SubstringWithConcatenationOfAllWords {
fun findSubstring(s: String, words: Array<String>): List<Int> {
// Resultant list
val indices: MutableList<Int> = ArrayList()
// Base conditions
if (s.isEmpty() || words.isEmpty()) {
r... | 2 | Java | 40 | 64 | 67b6ebaf56ec1878289f22a0324c28b077bcd59c | 2,507 | RedQuarkTutorials | MIT License |
aoc-2015/src/main/kotlin/aoc/AocDay7.kt | triathematician | 576,590,518 | false | {"Kotlin": 615974} | package aoc
class AocDay7: AocDay(7) {
companion object { @JvmStatic fun main(args: Array<String>) { AocDay7().run() } }
override val testinput = """
123 -> x
456 -> y
x AND y -> d
x OR y -> e
x LSHIFT 2 -> f
y RSHIFT 2 -> g
NOT x -> h
NOT y -> i... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 2,327 | advent-of-code | Apache License 2.0 |
src/main/kotlin/g1401_1500/s1411_number_of_ways_to_paint_n_3_grid/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1401_1500.s1411_number_of_ways_to_paint_n_3_grid
// #Hard #Dynamic_Programming #2023_06_07_Time_201_ms_(100.00%)_Space_37.1_MB_(100.00%)
class Solution {
fun numOfWays(n: Int): Int {
val dp = Array(n + 1) { IntArray(12) }
dp[1].fill(1)
val transfer = arrayOf(
intArrayO... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,305 | LeetCode-in-Kotlin | MIT License |
aoc2023/day1.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2023
import utils.InputRetrieval
fun main() {
Day1.execute()
}
private object Day1 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
private fun part1(input: List<String>): Int = input.sumOf {
... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 1,168 | Advent-Of-Code | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions81.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
fun test81() {
printlnResult(intArrayOf(3, 5, 2), 8)
printlnResult(intArrayOf(2, 3, 5), 10)
}
/**
* Questions 81: Given an IntArray that doesn't contain the same integers. And, given a value,
* please find all subsets that the sum of subset equals this value, integers... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,222 | Algorithm | Apache License 2.0 |
协程/collection/CollectionComparable.kt | wdfHPY | 305,254,522 | false | null | package com.lonbon.kotlin.collection
/**
* 排序 Comparable.
* 1. 存在自然排序。针对一个类需要自然排序的话,那么需要实现的Comparable接口。并且实现Comparable接口。
* 2.
*/
class CollectionComparable {
}
fun main() {
/* val v1 = Version(1, 2)
val v2 = Version(2, 1)
println(v1 > v2)*/
collectionPolymerization()
}
/**
* 定义自然排序的话 -> 正值表示大
*... | 0 | Kotlin | 0 | 0 | d879b0280c2e8579b480af9da484bc8a434dac0d | 5,626 | kotlinStudy | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/searching/FindFirstAndLastPositionOfElement.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.searching
fun main() {
val nums = listOf(5, 7, 7, 8, 8, 10)
val target = 8
print(searchRange(nums, target)) // [3,4]
}
// O(log(n)) time | O(1) space
private fun searchRange(arr: List<Int>, target: Int): Pair<Int, Int> {
return Pair(findFirstIndex(arr,... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 1,097 | algs4-leprosorium | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.