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/dev/shtanko/algorithms/leetcode/MinIntegerAdjacentSwaps.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 | 5,565 | kotlab | Apache License 2.0 |
src/main/kotlin/days/Day18.kt | jgrgt | 575,475,683 | false | {"Kotlin": 94368} | package days
class Day18 : Day(18) {
override fun partOne(): Any {
return Day18Game(inputList).solve()
}
override fun partTwo(): Any {
return Day18Game2(inputList).solve()
}
}
class Day18Game(val lines: List<String>) {
fun solve(): Any {
val points = lines.map { Point3.fr... | 0 | Kotlin | 0 | 0 | 5174262b5a9fc0ee4c1da9f8fca6fb86860188f4 | 3,808 | aoc2022 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/luna5ama/mdsfgen/EquationSolver.kt | Luna5ama | 654,146,121 | false | null | package dev.luna5ama.mdsfgen
import kotlin.math.abs
import kotlin.math.cos
import kotlin.math.pow
import kotlin.math.sqrt
fun solveQuadratic(x: FloatArray, a: Float, b: Float, c: Float): Int {
// a == 0 -> linear equation
if (a == 0.0f || abs(b) > 1e12 * abs(a)) {
if (b == 0.0f) {
if (c ==... | 0 | Kotlin | 0 | 0 | 3cfbd1346fadb35eb48de34eb1205c0e9a4db61e | 1,948 | msdfgen-kt | MIT License |
src/main/kotlin/aoc23/Day09.kt | tahlers | 725,424,936 | false | {"Kotlin": 65626} | package aoc23
object Day09 {
fun calculateSumOfExtrapolatedValues(input: String): Long {
val baseNumbers = parseInput(input)
val generated = baseNumbers.map { generateNextValueLists(it) }
val extrapolated = generated.map { calculateExtrapolation(it) }
return extrapolated.sum()
... | 0 | Kotlin | 0 | 0 | 0cd9676a7d1fec01858ede1ab0adf254d17380b0 | 1,734 | advent-of-code-23 | Apache License 2.0 |
src/main/kotlin/daytwo/DayTwo.kt | pauliancu97 | 619,525,509 | false | null | package daytwo
import getLines
enum class Choice(
private val elfString: String,
private val playerString: String,
val score: Int
) {
Rock("A", "X", 1),
Paper("B", "Y", 2),
Scrissor("C", "Z", 3);
fun beats(choice: Choice): Boolean =
when (this) {
Rock -> choice == Scri... | 0 | Kotlin | 0 | 0 | 78af929252f094a34fe7989984a30724fdb81498 | 3,307 | advent-of-code-2022 | MIT License |
src/main/kotlin/com/groundsfam/advent/y2020/d23/Day23.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2020.d23
import com.groundsfam.advent.DATAPATH
import kotlin.io.path.div
import kotlin.io.path.useLines
// Implements part of the API of a mutable doubly linked list
data class ListNode(var prev: ListNode?, var next: ListNode?, val value: Int) {
override fun toString() = "ListNode(p... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 2,929 | advent-of-code | MIT License |
src/main/kotlin/de/niemeyer/aoc2022/Day04.kt | stefanniemeyer | 572,897,543 | false | {"Kotlin": 175820, "Shell": 133} | /**
* Advent of Code 2022, Day 4: Camp Cleanup
* Problem Description: https://adventofcode.com/2022/day/4
*/
package de.niemeyer.aoc2022
import de.niemeyer.aoc.utils.Resources.resourceAsList
import de.niemeyer.aoc.utils.getClassName
import de.niemeyer.aoc.utils.intersects
typealias Assignment = Pair<IntRange, Int... | 0 | Kotlin | 0 | 0 | ed762a391d63d345df5d142aa623bff34b794511 | 1,395 | AoC-2022 | Apache License 2.0 |
src/Day09.kt | hufman | 573,586,479 | false | {"Kotlin": 29792} | import kotlin.math.absoluteValue
import kotlin.math.sign
enum class SnakeInstructionDirection {
Up,
Down,
Left,
Right
}
class SnakePosition(var x: Int, var y: Int) {
fun moveDirection(direction: SnakeInstructionDirection) {
when (direction) {
SnakeInstructionDirection.Up -> y--
SnakeInstructionDirection.... | 0 | Kotlin | 0 | 0 | 1bc08085295bdc410a4a1611ff486773fda7fcce | 2,930 | aoc2022-kt | Apache License 2.0 |
Kotlin for Java Developers. Week 2/Mastermind/Task/src/mastermind/evaluateGuess.kt | tinglu | 248,072,283 | false | null | package mastermind
data class Evaluation(val rightPosition: Int, val wrongPosition: Int)
/**
* My Solution .... LOL :
* */
// fun evaluateGuess(secret: String, guess: String): Evaluation {
// val letters = mutableMapOf<Char, Int>()
// secret.forEach { letters.put(it, letters.getOrDefault(it, 0) + 1) }
// ... | 0 | Kotlin | 0 | 0 | 7a2e9034e6e51c6ffb619a525c1b1c932b265b0c | 1,954 | learn-kotlin | BSD with attribution |
jax/codeforces/uncategorized/8-kotlin/c_rhyme.kt | jaxvanyang | 423,682,977 | false | {"C++": 1073738, "Kotlin": 10571, "Java": 8975, "Python": 3215, "Shell": 508, "Makefile": 389, "PowerShell": 341} | fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readStrs() = readLn().split(" ")
fun readInts() = readStrs().map { it.toInt() }
fun main() {
repeat(readInt()) {
solve()
}
}
fun solve() {
val n = readInt()
val a = Array(n) {
val (s, t, flag) = readStrs()
Pair(calc(s, t), flag.toInt())
}
... | 0 | C++ | 0 | 0 | ee41f1cbf692b7b1463a9467401bb6e7d38aecce | 887 | acm | MIT License |
core/src/org/flightofstairs/redesignedPotato/model/Dice.kt | FlightOfStairs | 95,606,091 | false | null | package org.flightofstairs.redesignedPotato.model
import java.lang.Math.abs
import java.security.SecureRandom
val random = SecureRandom()
sealed class DiceExpression {
fun average(): Int = averagePrecise().toInt()
fun roll(): Int = when(this) {
is RollModifier -> number
is Dice -> IntRange(1... | 0 | Kotlin | 0 | 0 | 530a011e884ddfa8c6b39529c1d187441e36478a | 3,741 | redesigned-potato | MIT License |
src/main/java/com/barneyb/aoc/aoc2022/day22/MonkeyMap.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2022.day22
import com.barneyb.aoc.aoc2022.day22.Tile.OPEN
import com.barneyb.aoc.aoc2022.day22.Tile.WALL
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toSlice
import com.barneyb.util.Dir.EAST
import com.barneyb.util.HashMap
import com.barneyb.util.Rect
import com.barneyb.uti... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 2,582 | aoc-2022 | MIT License |
src/main/kotlin/days/Day15.kt | hughjdavey | 225,440,374 | false | null | package days
import common.IntcodeComputer
import java.util.UUID
class Day15 : Day(15) {
private fun program() = inputString.split(",").map { it.trim().toLong() }.toMutableList()
override fun partOne(): Any {
return RepairDroid().doUntil { it.position?.statusCode == 2 }?.position?.distanceTravelled ... | 0 | Kotlin | 0 | 1 | 84db818b023668c2bf701cebe7c07f30bc08def0 | 3,435 | aoc-2019 | Creative Commons Zero v1.0 Universal |
letcode/src/main/java/daily/LeetCode10.kt | chengw315 | 343,265,699 | false | null | package letcode10
fun main() {
val solution = Solution10()
//false
val match9 = solution.isMatch("aaa", "aaaa")
//true
val match8 = solution.isMatch("ab", ".*..")
//true
val match7 = solution.isMatch("aab", "c*a*b*")
//false
val match = solution.isMatch("aa", "a")
//true
val... | 0 | Java | 0 | 2 | 501b881f56aef2b5d9c35b87b5bcfc5386102967 | 2,101 | daily-study | Apache License 2.0 |
src/Day12.kt | ostersc | 572,991,552 | false | {"Kotlin": 46059} | import java.util.*
fun main() {
// I knew this was a classic dijkstra problem and didn't feel like reimplmenting, so stole from
// https://rosettacode.org/wiki/Dijkstra%27s_algorithm#Kotlin
class Edge(val v1: String, val v2: String, val dist: Int)
/** One vertex of the graph, complete with mappings to... | 0 | Kotlin | 0 | 1 | 3eb6b7e3400c2097cf0283f18b2dad84b7d5bcf9 | 8,112 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimumTimeToCompleteTrips.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,572 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimumAbsoluteDifferenceBST.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 | 3,487 | kotlab | Apache License 2.0 |
android/app/src/main/java/com/thepyprogrammer/ktlib/signalProcessing/Complex.kt | terminalai | 312,471,067 | false | null | package com.thepyprogrammer.gaitanalyzeralgos.signalprocessing
import kotlin.math.*
data class Complex(val re: Double, val im: Double = 0.0, val isUnit:Boolean = false) {
infix operator fun plus(x: Complex) = Complex(re + x.re, im + x.im)
infix operator fun plus(x: Double) = Complex(re + x, im)
infix oper... | 1 | Jupyter Notebook | 4 | 10 | 2064375ddc36bf38f3ff65f09e776328b8b4612a | 2,016 | GaitMonitoringForParkinsonsDiseasePatients | MIT License |
2021/kotlin/src/main/kotlin/com/codelicia/advent2021/Day05.kt | codelicia | 627,407,402 | false | {"Kotlin": 49578, "PHP": 554, "Makefile": 293} | package com.codelicia.advent2021
import kotlin.math.max
import kotlin.math.min
typealias Vent = Pair<Int, Int>
typealias VentLine = Pair<Vent, Vent>
class Day05(input: String) {
private val vents: List<VentLine> = input.trimIndent()
.lines()
.map { x ->
val xs = x.split(" -> ")
... | 2 | Kotlin | 0 | 0 | df0cfd5c559d9726663412c0dec52dbfd5fa54b0 | 2,037 | adventofcode | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1020/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1020
/**
* LeetCode page: [1020. Number of Enclaves](https://leetcode.com/problems/number-of-enclaves/);
*/
class Solution {
/* Complexity:
* Time O(MN) and Space O(MN) where M and N are the number of rows and columns of grid;
*/
fun numEnclaves(grid: Array<Int... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,763 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day06.kt | dyomin-ea | 572,996,238 | false | {"Kotlin": 21309} | fun main() {
fun indexOfFirstWindow(size: Int, input: String): Int =
input.windowed(size)
.indexOfFirst { it.toSet().size == it.length }
fun part1(input: List<String>): List<Int> {
return input.map { indexOfFirstWindow(4, it) + 4 }
}
fun part2(input: List<String>): List<Int> {
return input.map { indexO... | 0 | Kotlin | 0 | 0 | 8aaf3f063ce432207dee5f4ad4e597030cfded6d | 890 | advent-of-code-2022 | Apache License 2.0 |
Kth_Largest_Element_in_an_Array_v3.kt | xiekch | 166,329,519 | false | {"C++": 165148, "Java": 103273, "Kotlin": 97031, "Go": 40017, "Python": 22302, "TypeScript": 17514, "Swift": 6748, "Rust": 6579, "JavaScript": 4244, "Makefile": 349} | class Solution {
fun findKthLargest(nums: IntArray, k: Int): Int {
return partition(nums, nums.size - k, 0, nums.size - 1)
}
private fun partition(nums: IntArray, k: Int, left: Int, right: Int): Int {
if (right == left) return nums[left]
val pivot = nums[left]
var start = le... | 0 | C++ | 0 | 0 | eb5b6814e8ba0847f0b36aec9ab63bcf1bbbc134 | 1,269 | leetcode | MIT License |
src/Day05.kt | kthun | 572,871,866 | false | {"Kotlin": 17958} | import java.util.*
fun createStartingStacks(lineIterator: Iterator<String>): MutableMap<Int, Deque<Char>> {
val stacks = mutableMapOf<Int, Deque<Char>>()
var numStacks = 0
for (line in lineIterator) {
if (line[1] == '1') {
numStacks = line.trim().split("\\s+".toRegex()).last().toInt()
... | 0 | Kotlin | 0 | 0 | 5452702e4e20ef2db3adc8112427c0229ebd1c29 | 3,738 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | RusticFlare | 511,529,667 | false | {"Kotlin": 8523} | package io.github.rusticflare.aoc
import io.github.rusticflare.aoc.intcode.IntcodeComputer
import io.github.rusticflare.aoc.intcode.asMemory
import io.github.rusticflare.aoc.intcode.execute
import kotlin.math.absoluteValue
fun main() {
fun String.toDirection(): Direction = when(first()){
'U' -> Direction... | 0 | Kotlin | 0 | 0 | 9b20c71a1dca74a5c4e07a1054af01e5afb2a0ac | 2,501 | advent-of-code-2019-kotlin | Apache License 2.0 |
src/week2/LongestNonRepeatingSubstring.kt | anesabml | 268,056,512 | false | null | package week2
import kotlin.math.max
import kotlin.system.measureNanoTime
class LongestNonRepeatingSubstring {
/** HashSet
* We keep track of the window in a set
* In each iteration:
* If the char is in the window we slide the start index to the right
* Else we slide the end index to the rig... | 0 | Kotlin | 0 | 1 | a7734672f5fcbdb3321e2993e64227fb49ec73e8 | 3,065 | leetCode | Apache License 2.0 |
src/main/kotlin/com/manalili/advent/Day06.kt | maines-pet | 162,116,190 | false | null | package com.manalili.advent
import kotlin.math.abs
class Day06(val input: List<String>){
var coordinates: List<ChronalCoordinate>
var height: IntRange
var width: IntRange
init {
coordinates = input.map {
val (x, y) = it.split(", ")
ChronalCoordinate(x.toInt(), y.toInt()... | 0 | Kotlin | 0 | 0 | 25a01e13b0e3374c4abb6d00cd9b8d7873ea6c25 | 1,717 | adventOfCode2018 | MIT License |
src/main/kotlin/mirecxp/aoc23/day11/Day11.kt | MirecXP | 726,044,224 | false | {"Kotlin": 42343} | package mirecxp.aoc23.day11
import mirecxp.aoc23.readInput
data class Coord(val row: Long, val col: Long)
//https://adventofcode.com/2023/day/11
class Day11(private val inputPath: String) {
private var lines: List<String> = readInput(inputPath)
fun solve(expansionIndex: Long) {
println("Solving day... | 0 | Kotlin | 0 | 0 | 6518fad9de6fb07f28375e46b50e971d99fce912 | 3,814 | AoC-2023 | MIT License |
src/Day03.kt | mkulak | 573,910,880 | false | {"Kotlin": 14860} | fun main() {
fun part1(input: List<String>): Int =
input.sumOf { line ->
val first = line.take(line.length / 2).toSet()
val second = line.drop(line.length / 2).toSet()
first.intersect(second).sumOf { if (it > 'Z') it.code - 'a'.code + 1 else it.code - 'A'.code + 27 }
... | 0 | Kotlin | 0 | 0 | 3b4e9b32df24d8b379c60ddc3c007d4be3f17d28 | 691 | AdventOfKo2022 | Apache License 2.0 |
src/day24/Day24.kt | daniilsjb | 726,047,752 | false | {"Kotlin": 66638, "Python": 1161} | package day24
import java.io.File
import kotlin.math.max
fun main() {
val data = parse("src/day24/Day24.txt")
println("🎄 Day 24 🎄")
println()
println("[Part 1]")
println("Answer: ${part1(data)}")
// For Part 2, see the Python implementation.
}
private data class Vec3(
val x: Long,
... | 0 | Kotlin | 0 | 0 | 46a837603e739b8646a1f2e7966543e552eb0e20 | 2,086 | advent-of-code-2023 | MIT License |
src/main/kotlin/com/kishor/kotlin/algo/algorithms/graph/UnionFind.kt | kishorsutar | 276,212,164 | false | null | package com.kishor.kotlin.algo.algorithms.graph
import java.util.*
fun main() {
val unionFind = UnionFind(6)
unionFind.accept(Scanner(System.`in`))
unionFind.display()
println(unionFind.containsCycle())
}
class UnionFind(val vertCount: Int) {
private data class Edge(val src: Int, val dst: Int, ... | 0 | Kotlin | 0 | 0 | 6672d7738b035202ece6f148fde05867f6d4d94c | 2,237 | DS_Algo_Kotlin | MIT License |
LeetCode/0077. Combinations/Solution.kt | InnoFang | 86,413,001 | false | {"C++": 501928, "Kotlin": 291271, "Python": 280936, "Java": 78746, "Go": 43858, "JavaScript": 27490, "Rust": 6410} | class Solution {
private val res = ArrayList<List<Int>>()
fun combine(n: Int, k: Int): List<List<Int>> {
if (n < 1 || k < 1 || n < k) return res
combination(n, k, 1, ArrayList<Int>())
return res
}
private fun combination(n: Int, k: Int, start: Int, list: ArrayList<Int>) {
... | 0 | C++ | 8 | 20 | 2419a7d720bea1fd6ff3b75c38342a0ace18b205 | 1,604 | algo-set | Apache License 2.0 |
src/main/kotlin/day7/Day7.kt | gornovah | 573,055,751 | false | {"Kotlin": 20487} | package day7
import load
fun main() {
val loadedData = load("/day-7.txt")
val mapOfLoadedData = createMap(loadedData)
println("Solution to Day 7, Part 1 is '${solveDay7PartOne(mapOfLoadedData)}'")
println("Solution to Day 7, Part 2 is '${solveDay7PartTwo(mapOfLoadedData)}'")
}
fun solveDay7PartOne(... | 0 | Kotlin | 0 | 0 | 181d1094111bd137f70a580ca32a924b582adf70 | 1,606 | advent_of_code_2022 | MIT License |
src/main/kotlin/de/zeitlinger/rails/RunCalculator.kt | zeitlinger | 119,668,097 | false | null | package de.zeitlinger.rails
fun calculateBestRun(run: Run, tried: MutableSet<Run>, board: Board): Run {
if (!tried.add(run)) {
return run
}
val runs: List<Run> = run.trainRuns.flatMap { trainRun ->
val train = trainRun.train
val stations = trainRun.stations
if (stations.is... | 0 | Kotlin | 0 | 0 | 364d710976b70fbcec2c02f1583c50573a506232 | 2,231 | rails | Apache License 2.0 |
src/Day05.kt | seana-zr | 725,858,211 | false | {"Kotlin": 28265} | import kotlin.math.min
fun main() {
// to save memory, we represent ranges as data structures instead of raw keys and values
data class RangeMap(
val sourceStart: Long,
val sourceEnd: Long,
val destStart: Long,
val destEnd: Long,
) {
fun appliesTo(n: Long): Boolean ... | 0 | Kotlin | 0 | 0 | da17a5de6e782e06accd3a3cbeeeeb4f1844e427 | 4,666 | advent-of-code-kotlin-template | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaximumSubarray.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,652 | kotlab | Apache License 2.0 |
src/main/kotlin/aoc23/Day01.kt | tom-power | 573,330,992 | false | {"Kotlin": 254717, "Shell": 1026} | package aoc23
import aoc23.Day01Solution.part1Day01
import aoc23.Day01Solution.part2Day01
import common.Year23
object Day01 : Year23 {
fun List<String>.part1(): Int = part1Day01()
fun List<String>.part2(): Int = part2Day01()
}
object Day01Solution {
fun List<String>.part1Day01(): Int =
map { it.... | 0 | Kotlin | 0 | 0 | baccc7ff572540fc7d5551eaa59d6a1466a08f56 | 1,627 | aoc | Apache License 2.0 |
y2022/src/main/kotlin/adventofcode/y2022/Day05.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2022
import adventofcode.io.AdventSolution
import adventofcode.util.algorithm.transposeString
object Day05 : AdventSolution(2022, 5, "Camp Cleanup") {
override fun solvePartOne(input: String): String {
val (bricks, moves) = parse(input)
val b = bricks.toMutableList()
... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,562 | advent-of-code | MIT License |
src/Day07.kt | WilsonSunBritten | 572,338,927 | false | {"Kotlin": 40606} | fun main() {
fun part1(input: List<String>): Int {
// map of full path directories to a list of filesizes in them
val directories = mutableMapOf<String, MutableList<Int>>()
val currentFullPath = mutableListOf("/")
input.subList(1, input.size).mapNotNull {
if (it.startsWi... | 0 | Kotlin | 0 | 0 | 363252ffd64c6dbdbef7fd847518b642ec47afb8 | 4,552 | advent-of-code-2022-kotlin | Apache License 2.0 |
y2019/src/main/kotlin/adventofcode/y2019/Day03.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2019
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Vec2
import kotlin.math.absoluteValue
fun main() = Day03.solve()
object Day03 : AdventSolution(2019, 3, "Crossed Wires") {
override fun solvePartOne(input: String): Int? {
val (a, b) = input.lines().map(this... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,369 | advent-of-code | MIT License |
src/Day01.kt | chasebleyl | 573,058,526 | false | {"Kotlin": 15274} | import java.math.BigInteger
fun main() {
fun sortedElvesByCalories(input: List<String>): List<BigInteger> {
val elfCalories = mutableListOf<BigInteger>()
var currentElfCalories = BigInteger.ZERO
input.forEach { calories ->
if (calories.isEmpty()) {
elfCalories.ad... | 0 | Kotlin | 0 | 1 | f2f5cb5fd50fb3e7fb9deeab2ae637d2e3605ea3 | 1,266 | aoc-2022 | Apache License 2.0 |
src/Day09.kt | RusticFlare | 574,508,778 | false | {"Kotlin": 78496} | import kotlin.math.absoluteValue
import kotlin.math.sign
import kotlin.properties.Delegates.observable
private val start = 0 to 0
private sealed interface Knot {
var position: Pair<Int, Int>
class Tail : Knot {
val positions = mutableSetOf(start)
override var position by observable(initialVa... | 0 | Kotlin | 0 | 1 | 10df3955c4008261737f02a041fdd357756aa37f | 2,231 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/jacobhyphenated/advent2022/day9/Day9.kt | jacobhyphenated | 573,603,184 | false | {"Kotlin": 144303} | package com.jacobhyphenated.advent2022.day9
import com.jacobhyphenated.advent2022.Day
import kotlin.math.absoluteValue
/**
* Day 9: Rope Bridge
*
* Knots on a rope follow a particular pattern that can be represented in 2d space.
* The tail knot must always be adjacent (including diagonals) to the head knot.
* As... | 0 | Kotlin | 0 | 0 | 9f4527ee2655fedf159d91c3d7ff1fac7e9830f7 | 4,080 | advent2022 | The Unlicense |
src/Day10.kt | palex65 | 572,937,600 | false | {"Kotlin": 68582} | private typealias CPU = List<Int> // Values of register X at each cycle
private fun execProgram(lines: List<String>): CPU = buildList {
var regX = 1
fun tick() {
add(regX)
}
for (line in lines) {
when (val op = line.substringBefore(' ')) {
"noop" -> tick()
"addx"... | 0 | Kotlin | 0 | 2 | 35771fa36a8be9862f050496dba9ae89bea427c5 | 1,512 | aoc2022 | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/combinations/CombinationsTests.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.combinations
import datsok.shouldEqual
import org.junit.jupiter.api.Test
//
// https://leetcode.com/problems/combinations ✅
//
// Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
// You may return the answer in any order.
// Constraints:
// 1 ... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,606 | katas | The Unlicense |
src/Day07.kt | karloti | 573,006,513 | false | {"Kotlin": 25606} | import Command.*
import Content.Directory
import Content.File
import java.util.*
enum class Errors {
UNKNOWN_COMMAND_LINE,
DIRECTORY_NOT_FOUND,
}
enum class Command(val regex: Regex) {
DIRECTORY("dir (.+)".toRegex()),
FILE("(\\d+) (.+)".toRegex()),
CD("\\$ cd (.+)".toRegex()),
LS("\\$ ls".toRe... | 0 | Kotlin | 1 | 2 | 39ac1df5542d9cb07a2f2d3448066e6e8896fdc1 | 3,435 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day14.kt | wgolyakov | 572,463,468 | false | null | import kotlin.math.min
import kotlin.math.max
fun main() {
val sandStart = 500 to 0
fun parse(input: List<String>): Triple<MutableSet<Pair<Int, Int>>, Pair<Int, Int>, Pair<Int, Int>> {
val rocks = mutableSetOf<Pair<Int, Int>>()
var minX = sandStart.first
var minY = sandStart.second
var maxX = sandStart.firs... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 2,429 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc2022/Day15.kt | w8mr | 572,700,604 | false | {"Kotlin": 140954} | package aoc2022
import aoc.*
import aoc.parser.followedBy
import aoc.parser.number
import aoc.parser.seq
import aoc.parser.zeroOrMore
import kotlin.math.absoluteValue
class Day15() {
data class SensorBeacon(val sensorLocation: Coord, val beaconLocation: Coord)
// Sensor at x=2, y=18: closest beacon is at x=-... | 0 | Kotlin | 0 | 0 | e9bd07770ccf8949f718a02db8d09daf5804273d | 1,798 | aoc-kotlin | Apache License 2.0 |
src/Day01.kt | khongi | 572,983,386 | false | {"Kotlin": 24901} | fun main() {
fun part1(input: List<String>): Int {
var acc = 0
var max = 0
input.forEach { number ->
if (number.isNotEmpty()) {
val value = number.toInt()
acc += value
} else {
if (max < acc) {
max = ... | 0 | Kotlin | 0 | 0 | 9cc11bac157959f7934b031a941566d0daccdfbf | 1,324 | adventofcode2022 | Apache License 2.0 |
src/Day07.kt | dmstocking | 575,012,721 | false | {"Kotlin": 40350} | import java.util.Stack
sealed class Node {
abstract fun size(): Int
}
class Directory(val children: MutableMap<String, Node> = mutableMapOf()): Node() {
override fun size(): Int = children.entries.sumOf { it.value.size() }
}
class File(private val size: Int): Node() {
override fun size(): Int = size
}
fun... | 0 | Kotlin | 0 | 0 | e49d9247340037e4e70f55b0c201b3a39edd0a0f | 4,786 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/week1/MaxProductSubArray.kt | anesabml | 268,056,512 | false | null | package week1
import kotlin.math.max
import kotlin.system.measureNanoTime
class MaxProductSubArray {
/** Brute force (really bad)
* Time complexity : O(n2)
* Space complexity : O(1)
*/
fun maxProductSubArray(nums: IntArray): Int {
if (nums.isEmpty()) return 0
var maxProduct = I... | 0 | Kotlin | 0 | 1 | a7734672f5fcbdb3321e2993e64227fb49ec73e8 | 2,705 | leetCode | Apache License 2.0 |
Algo_Ds_Notes-master/Algo_Ds_Notes-master/Floyd_Warshall_Algorithm/Floyd_Warshall_Algorithm.kt | rajatenzyme | 325,100,742 | false | {"C++": 709855, "Java": 559443, "Python": 397216, "C": 381274, "Jupyter Notebook": 127469, "Go": 123745, "Dart": 118962, "JavaScript": 109884, "C#": 109817, "Ruby": 86344, "PHP": 63402, "Kotlin": 52237, "TypeScript": 21623, "Rust": 20123, "CoffeeScript": 13585, "Julia": 2385, "Shell": 506, "Erlang": 385, "Scala": 310, ... | // version 1.1
object FloydWarshall {
fun doCalcs(weights: Array<IntArray>, nVertices: Int) {
val dist = Array(nVertices) { DoubleArray(nVertices) { Double.POSITIVE_INFINITY } }
for (w in weights) dist[w[0] - 1][w[1] - 1] = w[2].toDouble()
val next = Array(nVertices) { IntArray(nVertices) ... | 0 | C++ | 0 | 0 | 65a0570153b7e3393d78352e78fb2111223049f3 | 2,291 | Coding-Journey | MIT License |
hoon/HoonAlgorithm/src/main/kotlin/programmers/lv01/Lv1_68644.kt | boris920308 | 618,428,844 | false | {"Kotlin": 137657, "Swift": 35553, "Java": 1947, "Rich Text Format": 407} | package programmers.lv01
/**
* no.68644
* 두 개 뽑아서 더하기
* https://school.programmers.co.kr/learn/courses/30/lessons/68644
*
* 문제 설명
* 정수 배열 numbers가 주어집니다.
* numbers에서 서로 다른 인덱스에 있는 두 개의 수를 뽑아 더해서 만들 수 있는 모든 수를
* 배열에 오름차순으로 담아 return 하도록 solution 함수를 완성해주세요.
*
* 제한사항
* numbers의 길이는 2 이상 100 이하입니다.
* numbers... | 1 | Kotlin | 1 | 2 | 88814681f7ded76e8aa0fa7b85fe472769e760b4 | 1,588 | HoOne | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2018/Day15.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2018
import java.util.ArrayDeque
import java.util.Deque
object Day15 {
fun parseInput(input: List<String>): Pair<GameState, Set<Player>> {
val cave = input.map { it.map { if (it == '#') '#' else '.' }.joinToString(separator = "") }
val gameState = GameState(cave)
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 8,093 | adventofcode | MIT License |
src/main/math/EulerTotientFunction.kt | vamsi3 | 504,166,472 | false | {"Kotlin": 10048} | package com.vamsi3.algorithm.math
fun eulerTotientFunction(n: Int): Int {
var phi = n
primeDivisors(n).forEach { primeDivisor -> phi -= phi / primeDivisor }
return phi
}
fun generateEulerTotientFunction(n: Int, algorithm: GenerateEulerTotientFunctionAlgorithm) = when (algorithm) {
GenerateEulerTotient... | 0 | Kotlin | 0 | 0 | 5eda4c454984866e00a5d26c73dfb6f2437017e7 | 1,203 | algorithm-library | MIT License |
src/main/kotlin/leetcode/Problem2212.kt | fredyw | 28,460,187 | false | {"Java": 1280840, "Rust": 363472, "Kotlin": 148898, "Shell": 604} | package leetcode
/**
* https://leetcode.com/problems/maximum-points-in-an-archery-competition/
*/
class Problem2212 {
fun maximumBobPoints(numArrows: Int, aliceArrows: IntArray): IntArray {
val answer = Answer()
maximumBobPoints(numArrows, aliceArrows, IntArray(12), 0, 0, answer)
return a... | 0 | Java | 1 | 4 | a59d77c4fd00674426a5f4f7b9b009d9b8321d6d | 1,239 | leetcode | MIT License |
ceria/10/src/main/kotlin/Solution.kt | VisionistInc | 317,503,410 | false | null | import java.io.File;
import java.util.Collections;
fun main(args : Array<String>) {
val input = File(args.first()).readLines().map{ it.toInt() }
println("Solution 1: ${solution1(input)}")
println("Solution 2: ${solution2(input)}")
}
private fun solution1(input :List<Int>) :Int {
var highestAdapter = i... | 0 | Rust | 0 | 0 | 002734670384aa02ca122086035f45dfb2ea9949 | 3,630 | advent-of-code-2020 | MIT License |
src/main/kotlin/gurus/two-pointers.kt | dzca | 581,929,762 | false | {"Kotlin": 75573} | package gurus
import warmup.min
import kotlin.math.pow
/**
* Given an array of sorted numbers and a target sum, find
* a pair in the array whose sum is equal to the given target.
*/
fun findSum(a: IntArray, n:Int): IntArray{
var l = 0
var r = a.size - 1
while(l <= r){
var s = a[l] + a[r]
... | 0 | Kotlin | 0 | 0 | b1e7d1cb739e21ed7e8b7484d6efcd576857830f | 4,861 | kotlin-algrithm | MIT License |
src/main/kotlin/me/peckb/aoc/_2016/calendar/day13/Day13.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2016.calendar.day13
import me.peckb.aoc.pathing.GenericIntDijkstra
import me.peckb.aoc.pathing.GenericIntDijkstra.DijkstraNode
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
class Day13 @Inject constructor(private val generatorFactory: InputGenera... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 2,441 | advent-of-code | MIT License |
src/Day03.kt | Venkat-juju | 572,834,602 | false | {"Kotlin": 27944} | fun main() {
fun Char.toPriority() = this - (if (isUpperCase()) 'A' - 27 else 'a' - 1)
fun part1(input: List<String>): Int {
return input.sumOf { ruckSack ->
val compartments = ruckSack.chunked(ruckSack.length / 2)
val letter = ((compartments.first().toSet()) intersect compartm... | 0 | Kotlin | 0 | 0 | 785a737b3dd0d2259ccdcc7de1bb705e302b298f | 925 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DeleteTreeNodes.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 | 2,309 | kotlab | Apache License 2.0 |
sdk/src/main/kotlin/tesl/analysis/DeckAnalysis.kt | markjfisher | 213,163,541 | false | null | package tesl.analysis
import tesl.model.*
import tesl.model.Collection
data class DeckAnalysis(
private val deck: CardGrouping
) {
val commonCount: Int
val rareCount: Int
val epicCount: Int
val legendaryCount: Int
val soulgemCost: Int
val prophecyCount: Int
val creatureCount: Int
v... | 0 | Kotlin | 1 | 1 | 3c743bbc2f6170b4c16a860c846350d455aa6a05 | 6,442 | tesl-java-sdk | MIT License |
src/main/kotlin/codes/jakob/aoc/solution/Day07.kt | The-Self-Taught-Software-Engineer | 433,875,929 | false | {"Kotlin": 56277} | package codes.jakob.aoc.solution
import kotlin.math.abs
object Day07 : Solution() {
override fun solvePart1(input: String): Any {
val crabPositions: List<Int> = parseInput(input)
val fuelPerPosition: Map<Int, Long> = calculateFuelConsumptionPerPosition(crabPositions) { start, end ->
ab... | 0 | Kotlin | 0 | 6 | d4cfb3479bf47192b6ddb9a76b0fe8aa10c0e46c | 1,652 | advent-of-code-2021 | MIT License |
advent-of-code2015/src/main/kotlin/day6/Advent6.kt | REDNBLACK | 128,669,137 | false | null | package day6
import array2d
import day6.Operation.Pos
import day6.Operation.Type.*
import parseInput
import splitToLines
/**
--- Day 6: Probably a Fire Hazard ---
Because your neighbors keep defeating you in the holiday house decorating contest year after year, you've decided to deploy one million lights in a 1000x1... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 4,428 | courses | MIT License |
src/Day03.kt | bherbst | 572,621,759 | false | {"Kotlin": 8206} | import java.lang.IllegalArgumentException
fun main() {
fun findCommonChar(line: String): Char {
val halfLength = line.length / 2
val firstHalf = line.take(halfLength).toSet()
val secondHalf = line.takeLast(halfLength).toSet()
return firstHalf.first { secondHalf.contains(it) }
}... | 0 | Kotlin | 0 | 0 | 64ce532d7a0c9904db8c8d09ff64ad3ab726ec7e | 1,282 | 2022-advent-of-code | Apache License 2.0 |
src/main/kotlin/kt/kotlinalgs/app/tree/IntervalTree.ws.kts | sjaindl | 384,471,324 | false | null | package kt.kotlinalgs.app.tree
println("test")
val tree = BinarySearchTree<Int>(null)
/*
[5, 20] max = 20
[10, 30] max = 30
[12, 15] max = 15
[15, 20] max = 40
[17, 19] max = 40
[30, 40] max = 40
*/
tree.insert((15 to 20))
tree.insert((10 to 30))
tree.insert((17 to 19))
tree.insert((5 to 20))
tree.insert((12 to 15... | 0 | Java | 0 | 0 | e7ae2fcd1ce8dffabecfedb893cb04ccd9bf8ba0 | 3,475 | KotlinAlgs | MIT License |
src/Day11.kt | Tomcat88 | 572,566,485 | false | {"Kotlin": 52372} | import java.math.BigInteger
fun main() {
fun part1(input: List<Monkey>) {
repeat(20) { i ->
input.forEach { m ->
m.items.forEach { itm ->
m.testFn.invoke(m.op.invoke(itm) / BigInteger.valueOf(3))
.let { (newItm, newM) ->
... | 0 | Kotlin | 0 | 0 | 6d95882887128c322d46cbf975b283e4a985f74f | 3,563 | advent-of-code-2022 | Apache License 2.0 |
src/Day07.kt | Shykial | 572,927,053 | false | {"Kotlin": 29698} | fun main() {
fun part1(input: List<String>) = processInput(input).second.asSequence()
.map { it.calculateTotalSize() }
.filter { it < 100_000 }
.sum()
fun part2(input: List<String>): Long {
val totalAvailableSpace = 70_000_000L
val unusedSpaceAtLeast = 30_000_000
... | 0 | Kotlin | 0 | 0 | afa053c1753a58e2437f3fb019ad3532cb83b92e | 4,007 | advent-of-code-2022 | Apache License 2.0 |
leetcode/src/offer/middle/Offer49.kt | zhangweizhe | 387,808,774 | false | null | package offer.middle
fun main() {
// 剑指 Offer 49. 丑数
// https://leetcode.cn/problems/chou-shu-lcof/
println(nthUglyNumber1(10))
}
fun nthUglyNumber(n: Int): Int {
// 所有丑数,都可以拆分为 pow(2,x) * pow(3,y) * pow(5,z)
// 第 n 个丑数,可以由 第 n-1 个丑数 *2 或者 *3 或者 *5 得到
val dp = IntArray(n)
// 1 是第一个丑数
d... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,741 | kotlin-study | MIT License |
src/main/kotlin/year2023/day-02.kt | ppichler94 | 653,105,004 | false | {"Kotlin": 182859} | package year2023
import lib.aoc.Day
import lib.aoc.Part
import lib.splitLines
fun main() {
Day(2, 2023, PartA2(), PartB2()).run()
}
open class PartA2 : Part() {
data class Game(var id: Int, var sets: List<Set>)
data class Set(var red: Int, var green: Int, var blue: Int) {
operator fun plus(other... | 0 | Kotlin | 0 | 0 | 49dc6eb7aa2a68c45c716587427353567d7ea313 | 2,125 | Advent-Of-Code-Kotlin | MIT License |
src/main/kotlin/io/github/clechasseur/adventofcode2021/Day11.kt | clechasseur | 435,726,930 | false | {"Kotlin": 315943} | package io.github.clechasseur.adventofcode2021
import io.github.clechasseur.adventofcode2021.util.Pt
object Day11 {
private val data = """
4764745784
4643457176
8322628477
7617152546
6137518165
1556723176
2187861886
2553422625
4817584638
... | 0 | Kotlin | 0 | 0 | 4b893c001efec7d11a326888a9a98ec03241d331 | 1,923 | adventofcode2021 | MIT License |
src/main/kotlin/year2023/day21/Problem.kt | Ddxcv98 | 573,823,241 | false | {"Kotlin": 154634} | package year2023.day21
import IProblem
class Problem(private val steps: Int = 64) : IProblem {
private val matrix = javaClass
.getResourceAsStream("/2023/21.txt")!!
.bufferedReader()
.lines()
.map(String::toCharArray)
.toList()
.toTypedArray()
private val n = m... | 0 | Kotlin | 0 | 0 | 455bc8a69527c6c2f20362945b73bdee496ace41 | 2,546 | advent-of-code | The Unlicense |
src/main/kotlin/Day21.kt | i-redbyte | 433,743,675 | false | {"Kotlin": 49932} | typealias Cube = Array<Array<Array<Array<WorldCopy?>>>>
data class WorldCopy(var w1: Long, var w2: Long) {
companion object {
var cube: Cube? = null
fun find(p1: Int, p2: Int, s1: Int, s2: Int): WorldCopy {
cube?.get(p1)?.get(p2)?.get(s1)?.get(s2)?.let { return it }
val c =... | 0 | Kotlin | 0 | 0 | 6d4f19df3b7cb1906052b80a4058fa394a12740f | 1,856 | AOC2021 | Apache License 2.0 |
src/main/kotlin/com/ikueb/advent18/Day13.kt | h-j-k | 159,901,179 | false | null | package com.ikueb.advent18
import com.ikueb.advent18.model.*
object Day13 {
fun getFirstCollision(input: List<String>) =
process(input) { it.getCollisions().isEmpty() }
.getCollisions().keys
.sorted()
.first()
fun getLastCartStanding(in... | 0 | Kotlin | 0 | 0 | f1d5c58777968e37e81e61a8ed972dc24b30ac76 | 3,912 | advent18 | Apache License 2.0 |
solutions/aockt/y2021/Y2021D12.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
object Y2021D12 : Solution {
/** A pathfinding service able to navigate between the `start` and `end` caves via the given connections. */
private class Navigator(connections: Iterable<Pair<String, String>>) {
/** Simple data holder rep... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,294 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/se/brainleech/adventofcode/aoc2022/Aoc2022Day03.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 Aoc2022Day03 {
private fun String.firstHalf() = this.substring(0, (this.length / 2))
private fun String.secondHalf() = this.substring... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 1,648 | adventofcode | MIT License |
src/main/kotlin/Day12.kt | SimonMarquis | 570,868,366 | false | {"Kotlin": 50263} | class Day12(input: List<String>) {
private val heightMap = HeightMap(input)
private val start = heightMap.find('S').single()
private val end = heightMap.find('E').single()
fun part1(): Int = with(heightMap) {
bfs(start = start, end = end)!!
}
fun part2(): Int = with(heightMap) {
... | 0 | Kotlin | 0 | 0 | a2129cc558c610dfe338594d9f05df6501dff5e6 | 2,019 | advent-of-code-2022 | Apache License 2.0 |
LeetCode/Kotlin/src/main/kotlin/org/redquark/tutorials/leetcode/MedianOfTwoSortedArrays.kt | ani03sha | 297,402,125 | false | null | package org.redquark.tutorials.leetcode
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
// Check if num1 is smaller than num2
// If not, then we will swap num1 with num2
if (nums1.size > nums2.size) {
return findMedianSortedArrays(nums2, nums1)
}
// Lengths of two arr... | 2 | Java | 40 | 64 | 67b6ebaf56ec1878289f22a0324c28b077bcd59c | 2,424 | RedQuarkTutorials | MIT License |
src/Day04.kt | dominiquejb | 572,656,769 | false | {"Kotlin": 10603} | fun main() {
fun String.toIntRange(): IntRange {
val (start, end) = this.split("-").map { it.toInt() }
return IntRange(start, end)
}
fun IntRange.contains(other: IntRange): Boolean {
return this.first <= other.first && this.last >= other.last
}
fun IntRange.overlaps(other: ... | 0 | Kotlin | 0 | 0 | f4f75f9fc0b5c6c81759357e9dcccb8759486f3a | 1,103 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/at/mpichler/aoc/solutions/year2022/Day18.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2022
import at.mpichler.aoc.lib.*
open class Part18A : PartSolution() {
lateinit var cubes: List<Vector3i>
override fun parseInput(text: String) {
val lines = text.trim().split("\n")
val cubes = mutableListOf<Vector3i>()
for (line in lines) {
... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 2,987 | advent-of-code-kotlin | MIT License |
src/main/day5/Day05.kt | Derek52 | 572,850,008 | false | {"Kotlin": 22102} | package main.day5
import main.readInput
import java.util.Stack
fun main() {
val input = readInput("day5/day5")
val stackA = Stack<Char>()
stackify(stackA, "DTWFJSHN")
val stackB = Stack<Char>()
stackify(stackB, "HRPQTNBG")
val stackC = Stack<Char>()
stackify(stackC, "LQV")
val stac... | 0 | Kotlin | 0 | 0 | c11d16f34589117f290e2b9e85f307665952ea76 | 2,776 | 2022AdventOfCodeKotlin | Apache License 2.0 |
src/com/ajithkumar/aoc2022/Day05.kt | ajithkumar | 574,372,025 | false | {"Kotlin": 21950} | package com.ajithkumar.aoc2022
import com.ajithkumar.utils.*
import java.util.*
import java.util.Deque
data class MoveInstruction(val count: Int, val source: Int, val destination: Int)
fun main() {
fun cratesFromInput(input: List<String>): List<Deque<String>> {
val inputFirstPartEnd = input.indexOf("")
... | 0 | Kotlin | 0 | 0 | f95b8d1c3c8a67576eb76058a1df5b78af47a29c | 2,631 | advent-of-code-kotlin-template | Apache License 2.0 |
src/main/kotlin/tr/emreone/adventofcode/days/Day09.kt | EmRe-One | 726,902,443 | false | {"Kotlin": 95869, "Python": 18319} | package tr.emreone.adventofcode.days
import tr.emreone.kotlin_utils.automation.Day
typealias Sequence = MutableList<Long>
class Day09 : Day(9, 2023, "Mirage Maintenance") {
private fun predictNext(sequence: Sequence): Long {
val differences = mutableListOf<Sequence>()
differences.add(sequence.w... | 0 | Kotlin | 0 | 0 | c75d17635baffea50b6401dc653cc24f5c594a2b | 2,269 | advent-of-code-2023 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/PalindromePartitioning3.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 | 2,097 | kotlab | Apache License 2.0 |
codeforces/round584/f.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.round584
private const val M = 1_000_000_007
fun main() {
val (n, m) = readInts()
val nei = List(n) { mutableListOf<Pair<String, Int>>() }
repeat(m) { i ->
val label = (i + 1).toString()
val (a, b) = readInts().map { it - 1 }
nei[a].add(label to b)
nei[b].add(label to a)
}
val gap = m.... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,669 | competitions | The Unlicense |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[101]对称二叉树.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.util.*
import javax.swing.tree.TreeNode
//给定一个二叉树,检查它是否是镜像对称的。
//
//
//
// 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。
//
// 1
// / \
// 2 2
// / \ / \
//3 4 4 3
//
//
//
//
// 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:
//
// 1
// / \
// 2 2
// \ \
// 3 3
//
//
//
//
// 进阶:
//
// 你可以运用递归和... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 2,170 | MyLeetCode | Apache License 2.0 |
src/day05/Day05.kt | Regiva | 573,089,637 | false | {"Kotlin": 29453} | package day05
import readText
fun main() {
val id = "05"
val testOutput = "CMZ"
fun readDrawingSimple(fileName: String): Drawing {
val drawing = readText(fileName).split("\n\n")
val stacks = drawing[0].split("\n").map { ArrayDeque(it.toList()) }.toMutableList()
val commands = dra... | 0 | Kotlin | 0 | 0 | 2d9de95ee18916327f28a3565e68999c061ba810 | 2,426 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/enderdincer/okey/game/engine/evaluator/run/DefaultTileRunEvaluator.kt | enderdincer | 498,879,253 | false | {"Kotlin": 47748, "Java": 1184} | package com.enderdincer.okey.game.engine.evaluator.run
import com.enderdincer.okey.game.engine.commons.Tiles.hasDuplicate
import com.enderdincer.okey.game.engine.domain.Tile
import com.enderdincer.okey.game.engine.domain.TileColor
class DefaultTileRunEvaluator : TileRunEvaluator {
override fun findAllRuns(rack: ... | 1 | Kotlin | 0 | 0 | 66166dc4cc44d78504c16aea00fce739cd5f5ae5 | 4,485 | okey-game-engine | MIT License |
src/Day01.kt | ChenJiaJian96 | 576,533,624 | false | {"Kotlin": 11529} | /**
* https://adventofcode.com/2022/day/1
*/
fun main() {
fun List<String>.toGroupList(): ArrayList<List<String>> {
val inputs = ArrayList<List<String>>()
var curList = arrayListOf<String>()
forEach {
if (it.isNotEmpty()) {
curList += it
} else {
... | 0 | Kotlin | 0 | 0 | b1a88f437aee756548ac5ba422e2adf2a43dce9f | 1,182 | Advent-Code-2022 | Apache License 2.0 |
src/Day02.kt | krisbrud | 573,455,086 | false | {"Kotlin": 8417} | import java.lang.Exception
import javax.swing.plaf.OptionPaneUI
enum class MatchResult { WIN, DRAW, LOSE }
enum class Move { ROCK, PAPER, SCISSORS }
fun main() {
fun calcOwnMovePoints(move: Move): Int {
return when (move) {
Move.ROCK -> 1
Move.PAPER -> 2
Move.SCISSORS -... | 0 | Kotlin | 0 | 0 | 02caf3a30a292d7b8c9e2b7788df74650e54573c | 3,646 | advent-of-code-2022 | Apache License 2.0 |
mobile/src/main/java/ch/epfl/sdp/mobile/application/chess/notation/Flows.kt | epfl-SDP | 462,385,783 | false | {"Kotlin": 1271815, "Shell": 359} | package ch.epfl.sdp.mobile.application.chess.notation
import ch.epfl.sdp.mobile.application.chess.engine.Game
import ch.epfl.sdp.mobile.application.chess.notation.AlgebraicNotation.parseGame
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
/**
* Returns the longest common prefix length between... | 15 | Kotlin | 2 | 13 | 71f6e2a5978087205b35f82e89ed4005902d697e | 1,141 | android | MIT License |
src/day04/Day04.kt | TheJosean | 573,113,380 | false | {"Kotlin": 20611} | package day04
import readInput
fun main() {
fun parseRanges(range: String) =
range.split(',')
.flatMap { s ->
s.split('-').map { it.toInt() }
}.chunked(2)
.sortedWith(compareBy<List<Int>> { it[0] }.thenByDescending { it[1] })
.flatten()
... | 0 | Kotlin | 0 | 0 | 798d5e9b1ce446ba3bac86f70b7888335e1a242b | 1,043 | advent-of-code | Apache License 2.0 |
src/main/kotlin/hackerrank/problemsolving/medium/TransformMatrixIntoMagicSquare.kt | LennyRamos | 210,012,335 | false | null | package hackerrank.problemsolving.medium
import funalgorithms.MagicSquareOddOrder
import utils.Log
import java.util.*
import kotlin.math.abs
/**
* We define a magic square to be an NxN matrix of distinct positive integers
* from to where the sum of any row, column, or diagonal of length is always
* equal to the sa... | 0 | Kotlin | 0 | 1 | 0903a99f438097ae9e54886a18d80b15432110ce | 5,020 | core | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[64]最小路径和.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给定一个包含非负整数的 m x n 网格 grid ,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小。
//
// 说明:每次只能向下或者向右移动一步。
//
//
//
// 示例 1:
//
//
//输入:grid = [[1,3,1],[1,5,1],[4,2,1]]
//输出:7
//解释:因为路径 1→3→1→1→1 的总和最小。
//
//
// 示例 2:
//
//
//输入:grid = [[1,2,3],[4,5,6]]
//输出:12
//
//
//
//
// 提示:
//
//
// m == grid.length
// n == grid[i].lengt... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,509 | MyLeetCode | Apache License 2.0 |
jvm/src/main/kotlin/io/prfxn/aoc2021/day22.kt | prfxn | 435,386,161 | false | {"Kotlin": 72820, "Python": 362} | // Reactor Reboot (https://adventofcode.com/2021/day/22)
package io.prfxn.aoc2021
import kotlin.math.max
import kotlin.math.min
fun main() {
data class Cuboid(val xr: IntRange, val yr: IntRange, val zr: IntRange) {
private infix fun IntRange.overlap(other: IntRange) = max(first, other.first)..min(last,... | 0 | Kotlin | 0 | 0 | 148938cab8656d3fbfdfe6c68256fa5ba3b47b90 | 1,897 | aoc2021 | MIT License |
src/Day14.kt | inssein | 573,116,957 | false | {"Kotlin": 47333} | import kotlin.math.max
import kotlin.math.min
fun main() {
fun List<String>.buildGrid() = this.flatMap { line ->
line.split(" -> ")
.map { it.split(",").map { p -> p.toInt() } }
.windowed(2)
.flatMap { (from, to) ->
val (fromX, fromY) = from
... | 0 | Kotlin | 0 | 0 | 095d8f8e06230ab713d9ffba4cd13b87469f5cd5 | 2,383 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day003.kt | ruffCode | 398,923,968 | false | null | import java.math.BigInteger
object Day003 {
private val input = PuzzleInput("day003.txt").readLines()
@JvmStatic
fun main(args: Array<String>) {
val vectors = listOf(1 to 1, 3 to 1, 5 to 1, 7 to 1, 1 to 2)
println(partOne(input, vectors.last()))
println(partOneBetter(input, 1 to 2... | 0 | Kotlin | 0 | 0 | 477510cd67dac9653fc61d6b3cb294ac424d2244 | 1,704 | advent-of-code-2020-kt | MIT License |
src/day21/Day21.kt | Volifter | 572,720,551 | false | {"Kotlin": 65483} | package day21
import utils.*
class Monkey {
var cachedNumber: Long? = null
var leftMonkey: Monkey? = null
var rightMonkey: Monkey? = null
var operator: Char? = null
val number: Long? get() {
cachedNumber?.let {
return it
}
if (leftMonkey == null || rightMonke... | 0 | Kotlin | 0 | 0 | c2c386844c09087c3eac4b66ee675d0a95bc8ccc | 3,292 | AOC-2022-Kotlin | Apache License 2.0 |
src/day08/Day08_part1.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day08
import readLines
data class Tree(val height: Int, var visible: Boolean)
fun traverseBorders(forest: List<List<Tree>>): Int {
var count = 0
for (i in forest.indices) {
for (j in forest[i].indices) {
if (i == 0 || j == 0 || i == forest.size - 1 || j == forest[i].size - 1) {
... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 3,047 | aoc2022 | Apache License 2.0 |
src/Day04.kt | ExpiredMinotaur | 572,572,449 | false | {"Kotlin": 11216} | import java.lang.Integer.min
fun main() {
fun part1(input: List<String>): Int {
val ranges = input.map { it.split(',')
.map { r -> r.split("-")}.map { r -> r[0].toInt()..r[1].toInt() }.map{r->r.toSet()} }
var overlap = 0
for(line in ranges)
{
val inter = l... | 0 | Kotlin | 0 | 0 | 7ded818577737b0d6aa93cccf28f07bcf60a9e8f | 1,172 | AOC2022 | Apache License 2.0 |
src/main/kotlin/g0701_0800/s0721_accounts_merge/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0701_0800.s0721_accounts_merge
// #Medium #Array #String #Depth_First_Search #Breadth_First_Search #Union_Find
// #2023_02_28_Time_364_ms_(100.00%)_Space_45_MB_(90.91%)
import java.util.TreeSet
class Solution {
class UnionFind(size: Int) {
private var size: Int
private var numComponents:... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,705 | LeetCode-in-Kotlin | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.