path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/main/kotlin/com/ginsberg/advent2019/Day06.kt | tginsberg | 222,116,116 | false | null | /*
* Copyright (c) 2019 by <NAME>
*/
/**
* Advent of Code 2019, Day 6 - Universal Orbit Map
* Problem Description: http://adventofcode.com/2019/day/6
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2019/day6/
*/
package com.ginsberg.advent2019
class Day06(input: List<String>) {
// Not... | 0 | Kotlin | 2 | 23 | a83e2ecdb6057af509d1704ebd9f86a8e4206a55 | 1,086 | advent-2019-kotlin | Apache License 2.0 |
kotlin/16.3Sum Closest(最接近的三数之和).kt | learningtheory | 141,790,045 | false | {"Python": 4025652, "C++": 1999023, "Java": 1995266, "JavaScript": 1990554, "C": 1979022, "Ruby": 1970980, "Scala": 1925110, "Kotlin": 1917691, "Go": 1898079, "Swift": 1827809, "HTML": 124958, "Shell": 7944} | /**
<p>Given an array <code>nums</code> of <em>n</em> integers and an integer <code>target</code>, find three integers in <code>nums</code> such that the sum is closest to <code>target</code>. Return the sum of the three integers. You may assume that each input would have exactly one solution.</p>
<p><strong... | 0 | Python | 1 | 3 | 6731e128be0fd3c0bdfe885c1a409ac54b929597 | 1,540 | leetcode | MIT License |
src/main/kotlin/aoc2022/Day04.kt | lukellmann | 574,273,843 | false | {"Kotlin": 175166} | package aoc2022
import AoCDay
// https://adventofcode.com/2022/day/4
object Day04 : AoCDay<Int>(
title = "Camp Cleanup",
part1ExampleAnswer = 2,
part1Answer = 459,
part2ExampleAnswer = 4,
part2Answer = 779,
) {
private class ElfPair(input: String) {
val sections1: IntRange
val ... | 0 | Kotlin | 0 | 1 | 344c3d97896575393022c17e216afe86685a9344 | 1,463 | advent-of-code-kotlin | MIT License |
src/main/kotlin/com/sk/topicWise/tree/medium/105. Construct Binary Tree from Preorder and Inorder Traversal.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.topicWise.tree.medium
import com.sk.topicWise.tree.TreeNode
import com.sun.source.tree.Tree
class Solution105 {
/**
* 1. traverse in preorder from left to right and pick one element e1.
* 2. find this element e1's location in inorder, divide inorder in two parts being e1 as pivot.
*... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,063 | leetcode-kotlin | Apache License 2.0 |
src/main/java/challenges/educative_grokking_coding_interview/merge_intervals/_2/InsertInterval.kt | ShabanKamell | 342,007,920 | false | null | package challenges.educative_grokking_coding_interview.merge_intervals._2
import challenges.educative_grokking_coding_interview.merge_intervals.Interval
import challenges.util.PrintHyphens
import java.util.*
object InsertInterval {
private fun insertInterval(existingIntervals: List<Interval>, newInterval: Interv... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 2,233 | CodingChallenges | Apache License 2.0 |
src/main/kotlin/g1701_1800/s1723_find_minimum_time_to_finish_all_jobs/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1701_1800.s1723_find_minimum_time_to_finish_all_jobs
// #Hard #Array #Dynamic_Programming #Bit_Manipulation #Backtracking #Bitmask
// #2023_06_16_Time_167_ms_(100.00%)_Space_33.3_MB_(100.00%)
class Solution {
private var min = Int.MAX_VALUE
fun minimumTimeRequired(jobs: IntArray, k: Int): Int {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,036 | LeetCode-in-Kotlin | MIT License |
ejercicio4A.kt | salvaMsanchez | 658,507,022 | false | null | // Parte 1: Crea una lista “listaRandom” de 100 elementos compuesta de números aleatorios comprendidos entre el 0 y el 9.
// Imprime la lista por pantalla
// Parte 2: Crea una lista vacía “listaResultado” en cuya posición…
// Posición 0 se debe contar cuantos 0 hay en la listaRandom.
// Posición 1 se debe contar cuant... | 0 | Kotlin | 0 | 0 | a2fa5b8e26d73e1602f33c2081216b8fad7725b5 | 2,198 | curso-intro-kotlin | MIT License |
baparker/17/main.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import kotlin.math.abs
import kotlin.math.sqrt
var xMin = 0
var xMax = 0
var yMin = 0
var yMax = 0
fun step(curX: Int, curY: Int, tarX: Int, tarY: Int): Boolean {
val nextX = curX + tarX
val nextY = curY + tarY
if ((nextX >= xMin && nextX <= xMax) && (nextY >= yMin && nextY <= yMax)) {
return tru... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 1,313 | advent-of-code-2021 | MIT License |
src/main/kotlin/com/github/dmstocking/levenshtein/Levenshtein.kt | dmstocking | 651,298,593 | false | null | package com.github.dmstocking.levenshtein
import kotlin.math.min
class Levenshtein(private var height: Int = 16, private var width: Int = 16) {
private var distance = Array(height) { Array(width) { 0 } }
init {
for (i in 0 until width) {
distance[i][0] = i
}
for (j in 0 ... | 0 | Kotlin | 0 | 0 | 30609663842123a360db8aa6e066c9ae1180a923 | 1,459 | levenshtein | MIT License |
src/main/kotlin/model/Board.kt | mihassan | 600,617,064 | false | null | package model
import util.Bag
import util.frequency
import util.groupContiguousBy
import util.isDistinct
import util.transpose
enum class Direction {
Horizontal,
Vertical
}
enum class Orientation {
Portrait,
Landscape
}
data class Point(val x: Int, val y: Int) {
fun moveBy(dir: Direction, steps: Int): Poi... | 0 | Kotlin | 0 | 2 | f99324e092a9eb7d9644417ac3423763059513ee | 5,880 | qless-solver | Apache License 2.0 |
src/main/kotlin/days/Day14.kt | poqueque | 430,806,840 | false | {"Kotlin": 101024} | package days
import kotlin.math.min
class Day14 : Day(14) {
override fun partOne(): Any {
var data = inputList[0]
val rules = mutableMapOf<String,String>()
inputList.forEach {
if (it.contains("->")){
val (a,b) = it.split(" -> ")
rules[a] = b
... | 0 | Kotlin | 0 | 0 | 4fa363be46ca5cfcfb271a37564af15233f2a141 | 2,755 | adventofcode2021 | MIT License |
src/main/kotlin/com/github/kory33/kalgebra/operations/Operations.kt | kory33 | 135,460,140 | false | null | package com.github.kory33.kalgebra.operations
/**
* Interface for operations which take two values of type [M] and return a value of type [M].
*
* The requirement is that for all `(x1, y1): (M, M)` and `(x2, y2): (M, M)`,
* if `x1 == x2` and `y1 == y2` then `x1 applyTo y1 == x2 applyTo y2`.
*
* This means that t... | 0 | Kotlin | 0 | 2 | ae2420a27ef848c13fd5728d6c5cfeae3901f905 | 2,206 | Kalgebra | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ShortestPalindrome.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,617 | kotlab | Apache License 2.0 |
src/Day04.kt | Shykial | 572,927,053 | false | {"Kotlin": 29698} | fun main() {
fun part1(input: List<String>) = input.count { line ->
line.cutExcluding(",")
.map { it.parseIntRange() }
.let { it.first hasFullOverlapWith it.second }
}
fun part2(input: List<String>) = input.count { line ->
line.cutExcluding(",")
.map { i... | 0 | Kotlin | 0 | 0 | afa053c1753a58e2437f3fb019ad3532cb83b92e | 964 | advent-of-code-2022 | Apache License 2.0 |
day07/src/Day07.kt | simonrules | 491,302,880 | false | {"Kotlin": 68645} | import java.io.File
import kotlin.math.absoluteValue
class Day07(path: String) {
private var positions = mutableListOf<Int>()
private var fuelCost = mutableListOf<Int>()
init {
val lines = File(path).readLines()
val items = lines[0].split(',')
items.forEach { positions.add(it.toInt... | 0 | Kotlin | 0 | 0 | d9e4ae66e546f174bcf66b8bf3e7145bfab2f498 | 1,564 | aoc2021 | Apache License 2.0 |
src/main/kotlin/se/brainleech/adventofcode/aoc2022/Aoc2022Day06.kt | fwangel | 435,571,075 | false | {"Kotlin": 150622} | package se.brainleech.adventofcode.aoc2022
import se.brainleech.adventofcode.compute
import se.brainleech.adventofcode.readLines
import se.brainleech.adventofcode.verify
class Aoc2022Day06 {
private fun process(input: String, packetSize: Int) : Int {
if (input.length < packetSize) return -1
retur... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 1,291 | adventofcode | MIT License |
src/main/kotlin/day3.kt | Arch-vile | 572,557,390 | false | {"Kotlin": 132454} | package day3
import aoc.utils.intersect
import aoc.utils.readInput
import aoc.utils.splitMiddle
fun part1(): Int {
return readInput("day3-input.txt")
.map { it.toCharArray().toList() }
.map { it.splitMiddle()}
.map { it.first.intersect(it.second) }
.map { it.first() }
.sum... | 0 | Kotlin | 0 | 0 | e737bf3112e97b2221403fef6f77e994f331b7e9 | 697 | adventOfCode2022 | Apache License 2.0 |
year2022/src/cz/veleto/aoc/year2022/Day16.kt | haluzpav | 573,073,312 | false | {"Kotlin": 164348} | package cz.veleto.aoc.year2022
import cz.veleto.aoc.core.AocDay
class Day16(config: Config) : AocDay(config) {
private val inputRegex = Regex("""^Valve ([A-Z]+) has flow rate=([0-9]+); tunnels? leads? to valves? (.+)$""")
override fun part1(): String {
val valves = parseValves()
val startVal... | 0 | Kotlin | 0 | 1 | 32003edb726f7736f881edc263a85a404be6a5f0 | 8,169 | advent-of-pavel | Apache License 2.0 |
src/Day12.kt | floblaf | 572,892,347 | false | {"Kotlin": 28107} | fun main() {
data class Coordinate(
val value: Char,
val x: Int,
val y: Int,
var d1: Int = 0,
var d2: Int = 0
) {
fun canAccess(coordinate: Coordinate): Boolean {
return coordinate.value - this.value <= 1
}
}
val input = readInput("Da... | 0 | Kotlin | 0 | 0 | a541b14e8cb401390ebdf575a057e19c6caa7c2a | 2,376 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/arrays/NumberOfIslands.kt | ghonix | 88,671,637 | false | null | package arrays
import java.util.LinkedList
import java.util.Queue
class NumberOfIslands {
data class Coordinate(val row: Int, val col: Int)
fun numIslands(grid: Array<CharArray>): Int {
val visited = HashSet<Coordinate>()
var islandsFound = 0
for (row in grid.indices) {
... | 0 | Kotlin | 0 | 2 | 25d4ba029e4223ad88a2c353a56c966316dd577e | 2,629 | Problems | Apache License 2.0 |
src/main/kotlin/days/Day3.kt | MaciejLipinski | 317,582,924 | true | {"Kotlin": 60261} | package days
class Day3 : Day(3) {
override fun partOne(): Any {
val tobogganMap = inputList.map { mapLineFrom(it) }
val width = tobogganMap[0].size
var treeCount = 0
for (i in tobogganMap.indices) {
val y = i
val x =
if (i == 0) {
... | 0 | Kotlin | 0 | 0 | 1c3881e602e2f8b11999fa12b82204bc5c7c5b51 | 1,921 | aoc-2020 | Creative Commons Zero v1.0 Universal |
01/src/commonMain/kotlin/Main.kt | daphil19 | 725,415,769 | false | {"Kotlin": 131380} | expect fun getLines(inputOrPath: String): List<String>
fun main() {
val lines = getLines(INPUT_FILE)
part1(lines)
part2(lines)
}
fun part1(lines: List<String>) {
println(lines.map { line -> line.toCharArray().filter { it.isDigit() } }
.sumOf { "${it.first()}${it.last()}".toLong() })
}
fun par... | 0 | Kotlin | 0 | 0 | 70646b330cc1cea4828a10a6bb825212e2f0fb18 | 1,145 | advent-of-code-2023 | Apache License 2.0 |
src/Day01.kt | Xacalet | 576,909,107 | false | {"Kotlin": 18486} | /**
* ADVENT OF CODE 2022 (https://adventofcode.com/2022/)
*
* Solution to day 1 (https://adventofcode.com/2022/day/1)
*
*/
fun main() {
data class Elf(val calories: List<Int>)
fun part1(elves: List<Elf>): Int {
return elves.maxOfOrNull { it.calories.sum() } ?: 0
}
fun part2(elves: List... | 0 | Kotlin | 0 | 0 | 5c9cb4650335e1852402c9cd1bf6f2ba96e197b2 | 608 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/io/tree/BinarySearchTreeFromPreOrderTraversal.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.tree
import io.models.TreeNode
import io.utils.runTests
class BinarySearchTreeFromPreOrderTraversal {
fun execute(A: IntArray, bound: Int = Int.MAX_VALUE, index: Int = 0): Pair<Int, TreeNode?> {
if (index == A.size || A[index] > bound) return index to null
val root = TreeNode(A[index])
val (... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 2,040 | coding | MIT License |
src/main/kotlin/dev/shtanko/algorithms/exercises/MaxPowerOfTwo.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,754 | kotlab | Apache License 2.0 |
src/main/kotlin/org/eln2/mc/data/SegmentTree.kt | age-series | 248,378,503 | false | {"Kotlin": 641936} | package org.eln2.mc.data
/**
* Represents the numeric range of a segment.
* @param min The lower boundary of this segment.
* @param max The upper boundary of this segment.
* [min] must be smaller than [max].
* */
data class ClosedInterval(val min: Double, val max: Double) {
val range get() = min..max
ini... | 49 | Kotlin | 20 | 53 | 86d843f49c3e23cba8ad256d45476069bf1459dd | 3,987 | ElectricalAge2 | MIT License |
src/main/kotlin/me/grison/aoc/y2016/Day03.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc.y2016
import me.grison.aoc.*
class Day03 : Day(3, 2016) {
override fun title() = "Squares With Three Sides"
override fun partOne() = triangles(inputList.map { it.allInts() })
override fun partTwo() = inputList.map { it.allInts() }.let { h ->
val vertical = listOf(h.map { it... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 958 | advent-of-code | Creative Commons Zero v1.0 Universal |
LeetCode/Maximum Compatibility Score Sum/main.kt | thedevelopersanjeev | 112,687,950 | false | null | import kotlin.math.max
class Solution {
var students = Array(0) { IntArray(0) }
var mentors = Array(0) { IntArray(0) }
var dp = IntArray(257) { -1 }
fun solve(i: Int, mask: Int): Int {
if (i == students.size) return 0
if (dp[mask] != -1) return dp[mask]
var (ans, one) = listOf(... | 0 | C++ | 58 | 146 | 610520cc396fb13a03c606b5fb6739cfd68cc444 | 899 | Competitive-Programming | MIT License |
command-channel/src/main/kotlin/dev/gimme/command/channel/manager/commandcollection/CommandCollection.kt | gimme | 315,114,245 | false | {"Kotlin": 143111, "Java": 18235} | package dev.gimme.command.channel.manager.commandcollection
import dev.gimme.command.Command
import dev.gimme.command.CommandSearchResult
/**
* Represents a collection of commands.
*/
interface CommandCollection : Collection<Command<*>> {
/** Returns all commands in this collection. */
val commands: Set<Co... | 0 | Kotlin | 0 | 0 | 66557fea569474ca2dc5b0135e5df669160db35a | 1,447 | command | MIT License |
src/main/kotlin/g0701_0800/s0756_pyramid_transition_matrix/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0701_0800.s0756_pyramid_transition_matrix
// #Medium #Depth_First_Search #Breadth_First_Search #Bit_Manipulation
// #2023_03_07_Time_268_ms_(100.00%)_Space_34.2_MB_(100.00%)
class Solution {
private fun dfs(c: CharArray, i: Int, l: Int, map: Array<IntArray>): Boolean {
if (l == 1) {
r... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,207 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/days/Day2Solution.kt | yigitozgumus | 434,108,608 | false | {"Kotlin": 17835} | package days
import BaseSolution
import java.io.File
const val FORWARD = "forward"
const val DOWN = "down"
const val UP = "up"
data class Command(val direction: String, val amount: Int)
data class Location(var horizontal: Int, var depth: Int)
data class LocationWithAim(var aim: Int, var horizontal: Int, var depth: I... | 0 | Kotlin | 0 | 0 | c0f6fc83fd4dac8f24dbd0d581563daf88fe166a | 1,493 | AdventOfCode2021 | MIT License |
Stage_5/src/main/kotlin/Main.kt | rafaelnogueiradev | 670,374,961 | false | null | package cinema
const val STANDARD: Int = 10
const val DISCOUNT: Int = 8
const val B_SYMBOL: Char = 'B'
const val S_SYMBOL: Char = 'S'
const val SMALL_ROOM: Int = 60
enum class Cinema(var number: Int) {
ROW(7), SEATS(8),
TOTAL_SEATS(ROW.number * SEATS.number),
SELECT_ROW(0), SELECT_SEAT(0),
PURCHASED_T... | 0 | Kotlin | 0 | 1 | b9a8d8960ff35bd8b77a198ab9abd7ff83b6e97f | 2,996 | Cinema-Room-Manager-Kotlin | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1470/Solution2.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1470
/**
* LeetCode page: [1470. Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/);
*/
class Solution2 {
/* Complexity:
* Time O(n) and Space O(1);
*/
fun shuffle(nums: IntArray, n: Int): IntArray {
require(nums.size == n * 2)
... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,288 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/twentytwentytwo/Day17.kt | JanGroot | 317,476,637 | false | {"Kotlin": 80906} | package twentytwentytwo
import twentytwentytwo.Structures.Point2d
import kotlin.math.floor
fun main() {
val input = {}.javaClass.getResource("input-17.txt")!!.readText().trim();
val test = {}.javaClass.getResource("input-17-1.txt")!!.readText();
val dayTest = Day17(test)
//println(dayTest.part1())
... | 0 | Kotlin | 0 | 0 | 04a9531285e22cc81e6478dc89708bcf6407910b | 4,482 | aoc202xkotlin | The Unlicense |
day16/Part1.kt | anthaas | 317,622,929 | false | null | import java.io.File
fun main(args: Array<String>) {
val input = File("input.txt").bufferedReader().use { it.readText() }.split("\n\n")
val rules = input[0].split("\n").map {
it.split(":")[1].split(" or ")
.map { it.split('-').let { (low, high) -> low.trim().toInt() to high.trim().toInt() } ... | 0 | Kotlin | 0 | 0 | aba452e0f6dd207e34d17b29e2c91ee21c1f3e41 | 762 | Advent-of-Code-2020 | MIT License |
kotlin/780.Max Chunks To Make Sorted(最多能完成排序的块).kt | learningtheory | 141,790,045 | false | {"Python": 4025652, "C++": 1999023, "Java": 1995266, "JavaScript": 1990554, "C": 1979022, "Ruby": 1970980, "Scala": 1925110, "Kotlin": 1917691, "Go": 1898079, "Swift": 1827809, "HTML": 124958, "Shell": 7944} | /**
<p>Given an array <code>arr</code> that is a permutation of <code>[0, 1, ..., arr.length - 1]</code>, we split the array into some number of "chunks" (partitions), and individually sort each chunk. After concatenating them, the result equals the sorted array.</p>
<p>What is the most number of ... | 0 | Python | 1 | 3 | 6731e128be0fd3c0bdfe885c1a409ac54b929597 | 3,501 | leetcode | MIT License |
src/main/kotlin/day19/BeaconScanner.kt | Arch-vile | 433,381,878 | false | {"Kotlin": 57129} | package day19
import utils.Point
import utils.read
import utils.splitAfter
fun main() {
val data = read("./src/main/resources/day19Input.txt")
.splitAfter("")
.map {
if(it.last() == "")
it.drop(1).dropLast(1)
else
it.drop(1)
}
... | 0 | Kotlin | 0 | 0 | 4cdafaa524a863e28067beb668a3f3e06edcef96 | 944 | adventOfCode2021 | Apache License 2.0 |
2022/src/test/kotlin/Day10.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
private enum class Op { NOOP, ADDX }
private data class Cycle(val during: Int, val after: Int)
class Day10 : StringSpec({
"puzzle part 01" {
val cycles = getCycles()
val signalStrength = listOf(20, 60, 100, 140, 180, 22... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 1,743 | adventofcode | MIT License |
src/main/kotlin/cc/stevenyin/algorithms/_01_binary_search/BinarySearchWhile.kt | StevenYinKop | 269,945,740 | false | {"Kotlin": 107894, "Java": 9565} | package cc.stevenyin.algorithms._01_binary_search
/**
* Binary search to find the index of target in a sorted array.
*
* @param array The sorted array to search.
* @param target The value to search for.
* @return The index of target if found, or the negation of the insertion point otherwise.
*/
fun <T: Comparabl... | 0 | Kotlin | 0 | 1 | 748812d291e5c2df64c8620c96189403b19e12dd | 1,038 | kotlin-demo-code | MIT License |
Algorithm/coding_interviews/Kotlin/Questions26.kt | ck76 | 314,136,865 | false | {"HTML": 1420929, "Java": 723214, "JavaScript": 534260, "Python": 437495, "CSS": 348978, "C++": 348274, "Swift": 325819, "Go": 310456, "Less": 203040, "Rust": 105712, "Ruby": 96050, "Kotlin": 88868, "PHP": 67753, "Lua": 52032, "C": 30808, "TypeScript": 23395, "C#": 4973, "Elixir": 4945, "Pug": 1853, "PowerShell": 471, ... | package com.qiaoyuang.algorithm
/**
* 判断一个树是否是另一个树的子树
*/
fun main() {
// 构造父树
val father = BinaryTreeNode(8)
val b = BinaryTreeNode(8)
val c = BinaryTreeNode(7)
val d = BinaryTreeNode(9)
val e = BinaryTreeNode(2)
val f = BinaryTreeNode(4)
val g = BinaryTreeNode(7)
father.mLeft = b
father.mRight = c
b.mLe... | 0 | HTML | 0 | 2 | 2a989fe85941f27b9dd85b3958514371c8ace13b | 1,575 | awesome-cs | Apache License 2.0 |
src/test/kotlin/boti996/lileto/tests/helpers/DataHelpers.kt | boti996 | 223,049,715 | false | null | package boti996.lileto.tests.helpers
// Lileto null value
internal const val liletoNullValue = "-"
/**
* Alias for simple testcases.
* [Pair]'s first element is a [String] in Lileto language.
* [Pair]'s second element is the expected result [String].
*/
internal typealias testcase = Pair<String, String>
internal ... | 0 | Kotlin | 0 | 0 | 190fbe56e0862956b45bbd62ff888da16a78891a | 2,833 | lileto_tests | MIT License |
src/main/kotlin/day10/part1/main.kt | TheMrMilchmann | 225,375,010 | false | null | /*
* Copyright (c) 2019 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, dis... | 0 | Kotlin | 0 | 1 | 9d6e2adbb25a057bffc993dfaedabefcdd52e168 | 2,371 | AdventOfCode2019 | MIT License |
src/Day04.kt | DevHexs | 573,262,501 | false | {"Kotlin": 11452} | fun main(){
fun part1(): Int{
val list = mutableListOf<String>()
var countRepeatWork = 0
for (i in readInput("Day04")){
for (j in i.split(",")){
val v = j.split('-').map { it.toInt() }
var rangeText = ""
for (k in v[0].rangeT... | 0 | Kotlin | 0 | 0 | df0ff2ed7c1ebde9327cd1a102499ac5467b73be | 1,397 | AdventOfCode-2022-Kotlin | Apache License 2.0 |
src/main/java/com/barneyb/aoc/aoc2022/day23/UnstableDiffusion.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2022.day23
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toSlice
import com.barneyb.util.HashSet
import com.barneyb.util.Vec2
fun main() {
Solver.execute(
::parse,
::openSpacesAfterTenRounds, // 3,684
::firstNoOpRound, // 862
)
}
internal fu... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 1,194 | aoc-2022 | MIT License |
libraries/stdlib/src/kotlin/OrderingJVM.kt | udalov | 10,645,710 | false | {"Java": 9931656, "Kotlin": 2142480, "JavaScript": 942412, "C++": 613791, "C": 193807, "Objective-C": 22634, "Shell": 12589, "Groovy": 1267} | package kotlin
import java.util.Comparator
/**
* Helper method for implementing [[Comparable]] methods using a list of functions
* to calculate the values to compare
*/
inline fun <T : Any> compareBy(a: T?, b: T?, vararg functions: T.() -> Comparable<*>?): Int {
require(functions.size > 0)
if (a === b) return... | 0 | Java | 1 | 6 | 3958b4a71d8f9a366d8b516c4c698aae80ecfe57 | 2,291 | kotlin-objc-diploma | Apache License 2.0 |
app/src/main/java/com/betulnecanli/kotlindatastructuresalgorithms/CodingPatterns/TheBreadth-FirstSearch.kt | betulnecanli | 568,477,911 | false | {"Kotlin": 167849} | /*
The Breadth-First Search (BFS) coding pattern is a popular technique for traversing or processing data structures
in a level-by-level manner.
It is commonly used with trees, graphs, and other structures where you want to visit all the neighbors at the current
depth before moving on to the next level.
*/
//1. Binar... | 2 | Kotlin | 2 | 40 | 70a4a311f0c57928a32d7b4d795f98db3bdbeb02 | 4,282 | Kotlin-Data-Structures-Algorithms | Apache License 2.0 |
inference/inference-ir-trees/src/commonMain/kotlin/io/kinference/trees/TreeSplit.kt | JetBrains-Research | 244,400,016 | false | {"Kotlin": 2252927, "Python": 4777, "JavaScript": 2402, "Dockerfile": 683} | package io.kinference.trees
enum class TreeSplitType {
BRANCH_GT,
BRANCH_GTE,
BRANCH_LT,
BRANCH_LEQ
}
sealed class TreeSplitter(val featureIds: IntArray, val nodeSplitValues: FloatArray) {
abstract fun split(input: FloatArray, srcIdx: Int, splitIdx: Int): Int
class GTTreeSplitter(featureIds: ... | 7 | Kotlin | 6 | 126 | 95a58a192b6fa48d1f4ac1f2cc08658e2361756d | 2,113 | kinference | Apache License 2.0 |
src/day01/Day01.kt | iulianpopescu | 572,832,973 | false | {"Kotlin": 30777} | package day01
import readFile
private const val DAY = "01"
private const val DAY_TEST = "day${DAY}/Day${DAY}_test"
private const val DAY_INPUT = "day${DAY}/Day${DAY}"
fun main() {
fun sumTopCalories(input: String, limit: Int = 1) = input
.split("\n\n")
.asSequence()
.map { backpack ->
... | 0 | Kotlin | 0 | 0 | 4ff5afb730d8bc074eb57650521a03961f86bc95 | 912 | AOC2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimumAbsDifference.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,305 | kotlab | Apache License 2.0 |
src/day01/Day01.kt | mahmoud-abdallah863 | 572,935,594 | false | {"Kotlin": 16377} | package day01
import assertEquals
import readInput
import readTestInput
import java.lang.Integer.max
fun main() {
fun part1(input: List<String>): Int {
var maxCalories = 0
var caloriesSum = 0
input.forEach { line ->
if (line.isBlank()){
maxCalories = max(maxCalo... | 0 | Kotlin | 0 | 0 | f6d1a1583267e9813e2846f0ab826a60d2d1b1c9 | 1,244 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2021/2021-06.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2021
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputText
fun main() {
val input = readInputText(2021, "06-input")
val test1 = readInputText(2021, "06-test1")
println("Part1:")
part1(test1).println()
part... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,051 | advent-of-code | MIT License |
src/main/kotlin/leetcode/kotlin/array/easy/121. Best Time to Buy and Sell Stock.kt | sandeep549 | 251,593,168 | false | null | package leetcode.kotlin.array.easy
import kotlin.math.max
fun main() {
println(maxProfit2(intArrayOf(7, 1, 5, 3, 6, 4)))
println(maxProfit2(intArrayOf(7, 6, 4, 3, 1)))
println(maxProfit3(intArrayOf(7, 1, 5, 3, 6, 4)))
println(maxProfit3(intArrayOf(7, 6, 4, 3, 1)))
}
/**
* Try with buy stock on each... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 1,336 | kotlinmaster | Apache License 2.0 |
y2022/src/main/kotlin/adventofcode/y2022/Day07.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2022
import adventofcode.io.AdventSolution
object Day07 : AdventSolution(2022, 7, "No Space Left On Device") {
override fun solvePartOne(input: String): Long {
return parse(input).values.filter { it <= 100_000 }.sum()
}
override fun solvePartTwo(input: String): Long {
... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,421 | advent-of-code | MIT License |
src/main/kotlin/com/ginsberg/advent2019/Day20.kt | tginsberg | 222,116,116 | false | null | /*
* Copyright (c) 2019 by <NAME>
*/
/**
* Advent of Code 2019, Day 20 - Donut Maze
* Problem Description: http://adventofcode.com/2019/day/20
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2019/day20/
*/
package com.ginsberg.advent2019
import java.util.ArrayDeque
class Day20(input: List... | 0 | Kotlin | 2 | 23 | a83e2ecdb6057af509d1704ebd9f86a8e4206a55 | 5,233 | advent-2019-kotlin | Apache License 2.0 |
DiagonalDifference.kt | Rxfa | 540,482,211 | false | {"Kotlin": 8429} | import java.io.*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.f... | 0 | Kotlin | 0 | 2 | 5ba1a7e707a62a63398a138b22c0b186f136bab7 | 1,233 | kotlin-basics | MIT License |
kotlin/275.H-Index II(H指数 II).kt | learningtheory | 141,790,045 | false | {"Python": 4025652, "C++": 1999023, "Java": 1995266, "JavaScript": 1990554, "C": 1979022, "Ruby": 1970980, "Scala": 1925110, "Kotlin": 1917691, "Go": 1898079, "Swift": 1827809, "HTML": 124958, "Shell": 7944} | /**
<p>Given an array of citations <strong>sorted in ascending order </strong>(each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.</p>
<p>According to the <a href="https://en.wikipedia.org/wiki/H-index" target="_blank">definition of h-index on W... | 0 | Python | 1 | 3 | 6731e128be0fd3c0bdfe885c1a409ac54b929597 | 4,890 | leetcode | MIT License |
leetcode2/src/leetcode/longest-univalue-path.kt | hewking | 68,515,222 | false | null | package leetcode
import leetcode.structure.TreeNode
/**
* 687. 最长同值路径
* https://leetcode-cn.com/problems/longest-univalue-path/
* @program: leetcode
* @description: ${description}
* @author: hewking
* @create: 2019-10-25 10:36
* 给定一个二叉树,找到最长的路径,这个路径中的每个节点具有相同值。 这条路径可以经过也可以不经过根节点。
注意:两个节点之间的路径长度由它们之间的边数表示。
示例... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,462 | leetcode | MIT License |
src/main/day08/Part2.kt | ollehagner | 572,141,655 | false | {"Kotlin": 80353} | package day08
import common.Direction
import common.Grid
import common.Point
import readInput
fun main() {
val input = readInput("day08/input.txt")
val grid = Grid(input.map { row -> row.chunked(1).map { it.toInt() } })
val maxView = grid.allPoints()
.maxOfOrNull { grid.allviews(it) }
println... | 0 | Kotlin | 0 | 0 | 6e12af1ff2609f6ef5b1bfb2a970d0e1aec578a1 | 1,155 | aoc2022 | Apache License 2.0 |
src/main/kotlin/g0001_0100/s0043_multiply_strings/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0001_0100.s0043_multiply_strings
// #Medium #String #Math #Simulation #Data_Structure_II_Day_8_String #Programming_Skills_II_Day_4
// #Level_2_Day_2_String #2023_07_05_Time_165_ms_(96.72%)_Space_36.1_MB_(67.21%)
class Solution {
private fun getIntArray(s: String): IntArray {
val chars = s.toCharA... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,594 | LeetCode-in-Kotlin | MIT License |
app/src/main/kotlin/kotlinadventofcode/2023/2023-05.kt | pragmaticpandy | 356,481,847 | false | {"Kotlin": 1003522, "Shell": 219} | // Originally generated by the template in CodeDAO
package kotlinadventofcode.`2023`
import com.github.h0tk3y.betterParse.combinators.*
import com.github.h0tk3y.betterParse.grammar.*
import com.github.h0tk3y.betterParse.lexer.*
import kotlinadventofcode.Day
import java.math.BigInteger
class `2023-05` : Day {
ove... | 0 | Kotlin | 0 | 3 | 26ef6b194f3e22783cbbaf1489fc125d9aff9566 | 15,091 | kotlinadventofcode | MIT License |
pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/Pagination.kt | InsanusMokrassar | 295,712,640 | false | {"Kotlin": 1002757, "Python": 2464, "Shell": 1071} | package dev.inmo.micro_utils.pagination
import dev.inmo.micro_utils.common.intersect
import kotlin.math.ceil
import kotlin.math.floor
/**
* Base interface of pagination
*
* If you want to request something, you should use [SimplePagination]. If you need to return some result including
* pagination - [PaginationRe... | 9 | Kotlin | 2 | 27 | f2857ee2becf3fa5b51978f25360dc153dff342b | 3,050 | MicroUtils | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year16/Day10.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year16
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.product
import kotlin.math.max
import kotlin.math.min
private const val outputMask = 0xff0000
fun PuzzleSet.day10() = puzzle {
val insns = inputLines.map { l ->
val parts = l.split(" ")
val nums ... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,970 | advent-of-code | The Unlicense |
src/main/kotlin/no/uib/inf273/operators/MaximizeSimilarity.kt | elgbar | 237,403,030 | false | {"Kotlin": 141160} | package no.uib.inf273.operators
import no.uib.inf273.Logger
import no.uib.inf273.processor.Solution
/**
* Find the vessel with least similarity and try and maximize it.
*
* The implementation does not satisfy the quality or speed need from the custom operators.
* It reasonably quickly find what cargoes are misfit... | 0 | Kotlin | 0 | 3 | 1f76550a631527713b1eba22817e6c1215f5d84e | 4,449 | INF273 | The Unlicense |
processor/src/main/kotlin/com/misterpemodder/aoc2022/SolutionProcessor.kt | MisterPeModder | 573,061,300 | false | {"Kotlin": 87294} | /*
* 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 wr... | 0 | Kotlin | 0 | 0 | af1b258325a7bd036a47b5395c90bbac42bbd337 | 3,392 | AdventOfCode2022 | Apache License 2.0 |
src/shmp/lang/language/derivation/ChangeHistory.kt | ShMPMat | 240,860,070 | false | null | package shmp.lang.language.derivation
import shmp.lang.generator.util.GeneratorException
import shmp.lang.language.lexis.Word
import shmp.lang.language.lineUp
interface ChangeHistory {
fun printHistory(parent: Word): String
val changeDepth: Int
}
data class DerivationHistory(val derivation: Derivation, va... | 0 | Kotlin | 0 | 1 | 4d26b0d50a1c3c6318eede8dd9678d3765902d4b | 2,628 | LanguageGenerator | MIT License |
src/main/kotlin/org/olafneumann/regex/generator/utils/IntRange.kt | noxone | 239,624,807 | false | {"Kotlin": 246877, "HTML": 22083, "CSS": 5034, "C": 2817, "Dockerfile": 1748, "JavaScript": 220} | package org.olafneumann.regex.generator.utils
fun IntRange.hasIntersectionWith(other: IntRange): Boolean {
return (this.first <= other.first && this.last >= other.first)
|| (other.first <= this.first && other.last >= this.first)
}
val IntRange.length: Int get() = endInclusive - first + 1
val IntRange... | 13 | Kotlin | 69 | 355 | 001cc69d2592afa70b492441e119753789494816 | 2,377 | regex-generator | MIT License |
kotlin/1851-minimum-interval-to-include-each-query.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | class Solution {
fun minInterval(intervals: Array<IntArray>, _queries: IntArray): IntArray {
intervals.sortWith(compareBy( {it[0]}, { it[1]}))
val queries = _queries.withIndex().sortedBy { it.value }
val minHeap = PriorityQueue<IntArray> (compareBy( { it[0] }, { it[1] }))
val res = I... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 816 | leetcode | MIT License |
src/chapter3/section5/ex24_NonOverlappingIntervalSearch.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter3.section5
/**
* 不重叠的区间查找
* 给定对象的一组互不重叠的区间,编写一个函数接受一个对象作为参数并判断它是否存在于其中任何一个区间内
* 例如,如果对象是整数而区间为1643-2033,5532-7643,8998-10332,5666653-5669321
* 那么查询9122的结果为在第三个区间,而8122的结果不在任何区间
*
* 解:Kotlin中有自带的区间类[kotlin.ranges.IntRange],先对区间数组按起始位置排序,再对数组二分查找
*/
fun ex24_NonOverlappingIntervalSearch(rangeArray:... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,402 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/exercises/StringPermutations.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 | 1,914 | kotlab | Apache License 2.0 |
src/Day10.kt | karloti | 573,006,513 | false | {"Kotlin": 25606} | import Instructions.*
sealed interface Instructions {
val value: Int
val cycle: Int
val total: Int
data class Noop(
override val value: Int = 0,
override val cycle: Int = cycle_++,
override val total: Int = total_,
) : Instructions
data class Addx(
override val... | 0 | Kotlin | 1 | 2 | 39ac1df5542d9cb07a2f2d3448066e6e8896fdc1 | 1,281 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day01.kt | raneric | 573,109,642 | false | {"Kotlin": 13043} | fun main() {
fun part1(input: List<String>): Int {
var higherCal = Int.MIN_VALUE
var tempData = 0
input.map {
if (it.isNotEmpty()) {
tempData += it.toInt()
} else {
higherCal = higherCal.coerceAtLeast(tempData)
tempData... | 0 | Kotlin | 0 | 0 | 9558d561b67b5df77c725bba7e0b33652c802d41 | 844 | aoc-kotlin-challenge | Apache License 2.0 |
src/main/java/challenges/cracking_coding_interview/moderate/q6_smallest_difference/QuestionC.kt | ShabanKamell | 342,007,920 | false | null | package challenges.cracking_coding_interview.moderate.q6_smallest_difference
import java.util.*
object QuestionC {
private fun getClosestValue(array: IntArray, target: Int): Int {
var low = 0
var high = array.size - 1
var mid: Int
while (low <= high) {
mid = low + (high... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 1,638 | CodingChallenges | Apache License 2.0 |
kotlin/05.kt | NeonMika | 433,743,141 | false | {"Kotlin": 68645} | class Day5 :
Day<List<Pair<Day5.Point, Day5.Point>>>("05") {
// Classes
data class Point(val x: Int, val y: Int) : Comparable<Point> {
operator fun rangeTo(other: Point) = sequence {
var cur = this@Point
yield(cur)
while (cur != other) {
cur = Poin... | 0 | Kotlin | 0 | 0 | c625d684147395fc2b347f5bc82476668da98b31 | 1,681 | advent-of-code-2021 | MIT License |
src/main/kotlin/edu/rice/fset/HashFamily.kt | danwallach | 362,519,139 | false | null | package edu.rice.fset
import kotlin.math.ceil
import kotlin.math.sqrt
// We need to be able to leverage the usual hashCode() methods into a *family* of hash
// functions. This is challenging because many core Java classes have really simplistic
// hash functions. Of particular note, Integer.hashCode() just returns th... | 0 | Kotlin | 0 | 0 | 18972974f130c64762ae81d7106a1ec2fa5a51dc | 4,375 | fset-kotlin | MIT License |
src/test/kotlin/io/noobymatze/aoc/y2022/Day14.kt | noobymatze | 572,677,383 | false | {"Kotlin": 90710} | package io.noobymatze.aoc.y2022
import io.noobymatze.aoc.Aoc
import kotlin.test.Test
class Day14 {
data class Pos(val row: Int, val col: Int) {
val downLeft: Pos get() = Pos(row + 1, col - 1)
val downRight: Pos get() = Pos(row + 1, col + 1)
val down: Pos get() = Pos(row + 1, col)
}
... | 0 | Kotlin | 0 | 0 | da4b9d894acf04eb653dafb81a5ed3802a305901 | 3,997 | aoc | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[217]存在重复元素.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.util.*
import kotlin.collections.HashMap
//给定一个整数数组,判断是否存在重复元素。
//
// 如果任意一值在数组中出现至少两次,函数返回 true 。如果数组中每个元素都不相同,则返回 false 。
//
//
//
// 示例 1:
//
// 输入: [1,2,3,1]
//输出: true
//
// 示例 2:
//
// 输入: [1,2,3,4]
//输出: false
//
// 示例 3:
//
// 输入: [1,1,1,3,3,4,3,2,4,2]
//输出: true
// Related Topics 数组 哈希表
/... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,235 | MyLeetCode | Apache License 2.0 |
src/y2023/Day24.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2023
import io.ksmt.KContext
import io.ksmt.expr.KExpr
import io.ksmt.solver.z3.KZ3Solver
import io.ksmt.sort.KIntSort
import io.ksmt.utils.getValue
import util.generateTakes
import util.readInput
import util.timingStatistics
import java.math.BigDecimal
import java.math.RoundingMode
object Day24 {
data c... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 4,661 | advent-of-code | Apache License 2.0 |
jtransc-core/src/com/jtransc/graph/StrongComponent.kt | jtransc | 51,313,992 | false | null | package com.jtransc.graph
import java.util.*
// https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
// G = Graph
// V = Vertices (Nodes)
// E = Edges (E)
fun <T> Digraph<T>.tarjanStronglyConnectedComponentsAlgorithm() = StrongComponentGraph(this, TarjanStronglyConnectedComponentsAlgorithm... | 59 | Java | 66 | 619 | 6f9a2166f128c2ce5fb66f9af46fdbdbcbbe4ba4 | 5,138 | jtransc | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem460/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem460
/**
* LeetCode page: [460. LFU Cache](https://leetcode.com/problems/lfu-cache/);
*/
class LFUCache(private val capacity: Int) {
private val values = hashMapOf<Int, Int>() // entry(key, value)
private val useCounts = hashMapOf<Int, Int>() // entry(key, useCount)
... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,414 | hj-leetcode-kotlin | Apache License 2.0 |
src/test/kotlin/days/Day2Test.kt | nicopico-dev | 726,255,944 | false | {"Kotlin": 37616} | package days
import days.Day2.Color.Blue
import days.Day2.Color.Green
import days.Day2.Color.Red
import days.Day2.Game
import days.Day2.Hypothesis
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
class Day2Test {
private val Int.red get() = Red to this... | 0 | Kotlin | 0 | 0 | 1a13c8bd3b837c1ce5b13f90f326f0277249d23e | 2,574 | aoc-2023 | Creative Commons Zero v1.0 Universal |
kotlin/src/com/s13g/aoc/aoc2022/Day5.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2022
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
/**
* --- Day 5: Supply Stacks ---
* https://adventofcode.com/2022/day/5
*/
class Day5 : Solver {
override fun solve(lines: List<String>): Result {
val re = """move (\d+) from (\d+) to (\d+)$""".toRegex()
val stacks = pars... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 1,245 | euler | Apache License 2.0 |
src/main/java/challenges/cracking_coding_interview/linked_list/sum_lists/SumListsA.kt | ShabanKamell | 342,007,920 | false | null | package challenges.cracking_coding_interview.linked_list.sum_lists
import challenges.data_structure.LinkedListNode
object SumListsA {
private fun addLists(l1: LinkedListNode, l2: LinkedListNode): LinkedListNode? {
return addLists(l1, l2, 0)
}
private fun addLists(l1: LinkedListNode?, l2: LinkedL... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 1,895 | CodingChallenges | Apache License 2.0 |
src/main/kotlin/domain/graphs/Graphs.kt | alexaldev | 424,953,645 | false | {"Kotlin": 12995} | package domain.graphs
import domain.TrianglesCounter
import domain.TrianglesCounterAlgorithm
import java.util.concurrent.ConcurrentHashMap
import java.util.stream.Stream
abstract class Graph {
abstract fun generateMetrics(): List<GraphMetrics>
abstract fun addEdge(sourceV: Int, destinationV: Int)
abstract... | 0 | Kotlin | 0 | 0 | f0dfaca21728493bd2a99cd9048e6f3f9e596f63 | 4,201 | GraphTriangleDetection | Apache License 2.0 |
src/Day6.kt | syncd010 | 324,790,559 | false | null | class Day6: Day {
private fun convert(input: List<String>) : Map<String, String> {
return input.map { it.split(")") }.associate { Pair(it[1], it[0]) }
}
/**
* Assuming [map] is a path map, returns the path from [from] to [to]
*/
private fun getMapPath(map: Map<String, String>, from: S... | 0 | Kotlin | 0 | 0 | 11c7c7d6ccd2488186dfc7841078d9db66beb01a | 1,121 | AoC2019 | Apache License 2.0 |
kold-examples/src/main/kotlin/com/github/kold/examples/SubFieldsValidation.kt | kotlin-kold | 256,402,175 | false | null | package com.github.kold.examples
import com.github.kold.context.combineFields
import com.github.kold.context.default
import com.github.kold.context.validateElements
import com.github.kold.context.validationContext
import com.github.kold.data.KoldData
import com.github.kold.validated.Validated
object SubFieldsValidati... | 0 | Kotlin | 0 | 1 | ac20a24389af3f612e3ea6875f5db365a9c54620 | 3,412 | kold | MIT License |
2021/kotlin/src/main/kotlin/com/codelicia/advent2021/Day10.kt | codelicia | 627,407,402 | false | {"Kotlin": 49578, "PHP": 554, "Makefile": 293} | package com.codelicia.advent2021
import java.util.Stack
class Day10(private val input: List<String>) {
private val scoreTable: Map<String, Long> = mapOf(
")" to 3L,
"]" to 57L,
"}" to 1197L,
">" to 25137L,
)
private val scoreTableForIncomplete: Map<String, Long> = mapOf(
... | 2 | Kotlin | 0 | 0 | df0cfd5c559d9726663412c0dec52dbfd5fa54b0 | 2,377 | adventofcode | MIT License |
puzzles/src/main/kotlin/com/kotlinground/puzzles/search/binarysearch/searchrange/searchRange.kt | BrianLusina | 113,182,832 | false | {"Kotlin": 483489, "Shell": 7283, "Python": 1725} | package com.kotlinground.puzzles.search.binarysearch.searchrange
/**
* Searches for the left and right positions of a target in nums
*
* For the first_pos, we want to find the leftmost target. So we will do binary search on nums, and whenever we find
* a target, we search for its left side to see whether there is ... | 1 | Kotlin | 1 | 0 | 5e3e45b84176ea2d9eb36f4f625de89d8685e000 | 1,705 | KotlinGround | MIT License |
src/main/kotlin/g2801_2900/s2830_maximize_the_profit_as_the_salesman/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2801_2900.s2830_maximize_the_profit_as_the_salesman
// #Medium #Array #Dynamic_Programming #Sorting #Binary_Search
// #2023_12_18_Time_776_ms_(100.00%)_Space_112.8_MB_(33.33%)
import kotlin.math.max
class Solution {
fun maximizeTheProfit(n: Int, offers: List<List<Int>>): Int {
val dp = IntArray(... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,215 | LeetCode-in-Kotlin | MIT License |
2020/src/main/kotlin/de/skyrising/aoc2020/day23/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2020.day23
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.ints.Int2IntMap
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap
/*
private fun move(cups: IntArray, count: Int): IntArray {
val size = cups.size
//println("-- move ${count + 1} --")
//println("cups: ${cups.conte... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 3,192 | aoc | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaximumXor.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,221 | kotlab | Apache License 2.0 |
Algorithms/src/main/kotlin/net/milosvasic/algorithms/sort/efficient/MergeSort.kt | milos85vasic | 80,288,639 | false | null | package net.milosvasic.algorithms.sort.efficient
import net.milosvasic.algorithms.sort.Sort
class MergeSort<T : Comparable<T>> : Sort<T> {
private var tmp = mutableListOf<T>()
override fun sort(elements: MutableList<T>, ascending: Boolean) {
tmp.addAll(elements)
mergeSort(elements, 0, eleme... | 0 | Kotlin | 1 | 5 | a2be55959035654463b4855058d07ccfb68ac4a7 | 1,629 | Fundamental-Algorithms | Apache License 2.0 |
src/Day04.kt | andyludeveloper | 573,249,939 | false | {"Kotlin": 7818} | fun main() {
fun List<String>.toIntRows() = this.map { row ->
row.split(",", "-").map(String::toInt)
}
fun part1(input: List<String>): Int =
input.toIntRows()
.count { (a1, a2, b1, b2) -> (a1 <= b1) && (a2 >= b2) || (a1 >= b1) && (a2 >= b2) }
fun part2(input: List<String>)... | 0 | Kotlin | 0 | 1 | 684cf9ff315f15bf29914ca25b44cca87ceeeedf | 650 | Kotlin-in-Advent-of-Code-2022 | Apache License 2.0 |
year2021/day21/dice/src/main/kotlin/com/curtislb/adventofcode/year2021/day21/dice/dirac/DiracDice.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.year2021.day21.dice.dirac
import com.curtislb.adventofcode.common.collection.Counter
import com.curtislb.adventofcode.common.iteration.nestedLoop
/**
* A set of dice, each of which can roll any integer from 1 to [sidesCount] with equal probability.
*
* @param diceCount The number ... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 1,287 | AdventOfCode | MIT License |
src/commonMain/kotlin/io/github/alexandrepiveteau/graphs/internal/graphs/AdjacencyListNetwork.kt | alexandrepiveteau | 630,931,403 | false | {"Kotlin": 132267} | package io.github.alexandrepiveteau.graphs.internal.graphs
import io.github.alexandrepiveteau.graphs.*
/**
* An implementation of [Network] which uses an adjacency list to store the links and weights.
*
* @param neighbors the adjacency list of the graph.
* @param weights the weights of the graph.
*/
internal cla... | 9 | Kotlin | 0 | 6 | a4fd159f094aed5b6b8920d0ceaa6a9c5fc7679f | 2,111 | kotlin-graphs | MIT License |
year2019/day06/orbits/src/main/kotlin/com/curtislb/adventofcode/year2019/day06/orbits/Universe.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.year2019.day06.orbits
import java.io.File
/**
* A collection of planets that may orbit one another.
*/
class Universe() {
/**
* A map from names to corresponding planets in the universe.
*/
private val planets: MutableMap<String, Planet> = mutableMapOf()
/**
... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 3,562 | AdventOfCode | MIT License |
src/2022/Day05.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2022`
import java.io.File
import java.util.*
fun main() {
Day05().solve()
}
class Day05 {
val input1 = """
[D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
""".trimIndent()
fun solve() {
val f = File("sr... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 2,182 | advent-of-code | Apache License 2.0 |
src/Day03.kt | vonElfvin | 572,857,181 | false | {"Kotlin": 11658} | const val UPPER = 65 - 27
const val LOWER = 96
fun main() {
fun part1(input: List<String>): Int = input.sumOf { row ->
val (left, right) = listOf(
row.substring(0, row.length / 2),
row.substring(row.length / 2)
).map(String::toCharArray)
val both = left.first { right... | 0 | Kotlin | 0 | 0 | 6210f23f871f646fcd370ec77deba17da4196efb | 750 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/kotlin/top/pengcheng789/algorithms/sort/LoopQuickSort.kt | pengcheng789 | 100,803,477 | false | null | /*
* copyright 2018 the original author or authors.
*
* 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 applicabl... | 0 | Kotlin | 0 | 0 | 667bca6217c81f85c7ac68830e5ed984c5c1965d | 1,946 | algorithms | Apache License 2.0 |
src/day_10.kt | gardnerdickson | 152,621,962 | false | null | import java.lang.StringBuilder
fun main(args: Array<String>) {
val input = "1113222113"
val answer1 = Day10.part1(input)
println("Part 1: $answer1")
val answer2 = Day10.part2(input)
println("Part 2: $answer2")
}
object Day10 {
private fun lookAndSay(sequence: String): String {
val dig... | 0 | Kotlin | 0 | 0 | 4a23ab367a87cae5771c3c8d841303b984474547 | 1,637 | advent-of-code-2015 | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem167/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem167
/**
* LeetCode page: [167. Two Sum II - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(1) where N is the size of numbers;
*/
fun twoSum(numbers: IntArray, t... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,140 | hj-leetcode-kotlin | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.