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/me/consuegra/algorithms/KOneAway.kt | aconsuegra | 91,884,046 | false | {"Java": 113554, "Kotlin": 79568} | package me.consuegra.algorithms
/**
* There are three types of edits that can be performed on strings: insert a character, remove a character, or
* replace a character. Given two strings, write a function to check if they are one edit (or) zero edits away.
* <p>
* Examples:
* <p>
* pale, ple -> true
* pales, ... | 0 | Java | 0 | 7 | 7be2cbb64fe52c9990b209cae21859e54f16171b | 1,467 | algorithms-playground | MIT License |
wordy/src/main/kotlin/Wordy.kt | 3mtee | 98,672,009 | false | null | import kotlin.math.pow
object Wordy {
private const val PREFIX = "What is "
private const val SUFFIX = "?"
private val operations = mapOf<String, (a: Int, b: Int) -> Int>(
"+" to { a, b -> a + b },
"-" to { a, b -> a - b },
"*" to { a, b -> a * b },
"/" to { a, b -> a / b }... | 0 | Kotlin | 0 | 0 | 6e3eb88cf58d7f01af2236e8d4727f3cd5840065 | 1,448 | exercism-kotlin | Apache License 2.0 |
src/main/kotlin/com/staricka/adventofcode2022/Day7.kt | mathstar | 569,952,400 | false | {"Kotlin": 77567} | package com.staricka.adventofcode2022
import kotlin.math.min
class Day7 : Day {
override val id = 7
enum class FileType {
DIRECTORY, REGULAR_FILE
}
interface File {
val fileType: FileType
val name: String
val size: Int
}
data class Directory(override val name: String, val parent: Direct... | 0 | Kotlin | 0 | 0 | 2fd07f21348a708109d06ea97ae8104eb8ee6a02 | 2,659 | adventOfCode2022 | MIT License |
2022/03/Solution.kt | AdrianMiozga | 588,519,359 | false | {"Kotlin": 110785, "Python": 11275, "Assembly": 3369, "C": 2378, "Pawn": 1390, "Dart": 732} | import java.io.File
private const val FILENAME = "2022/03/input.txt"
fun main() {
partOne()
partTwo()
}
private fun partOne() {
val file = File(FILENAME).readLines()
var sum = 0
for (line in file) {
val half = line.length / 2
val first = line.slice(0 until half)
val seco... | 0 | Kotlin | 0 | 0 | c9cba875089d8d4fb145932c45c2d487ccc7e8e5 | 1,265 | Advent-of-Code | MIT License |
2021/src/main/kotlin/org/suggs/adventofcode/Day06LanternFish.kt | suggitpe | 321,028,552 | false | {"Kotlin": 156836} | package org.suggs.adventofcode
object Day06LanternFish {
fun calculateNumberOfFishFrom(verySmallDataSet: List<Int>): FishCounter {
return FishCounter(verySmallDataSet)
}
}
/**
* Summary of the algo:
* 1. Don't try and calculate each fish ... there are 9 variants so pre-calc them
* 2. Optimise the c... | 0 | Kotlin | 0 | 0 | 9485010cc0ca6e9dff447006d3414cf1709e279e | 1,180 | advent-of-code | Apache License 2.0 |
src/Day04.kt | karloti | 573,006,513 | false | {"Kotlin": 25606} | fun main() {
fun Sequence<String>.splitBounds() = map { it.split('-', ',').map(String::toInt) }
fun part1(input: Sequence<String>): Int =
input.splitBounds().count { (a, b, c, d) -> (a <= c) && (b >= d) || (a >= c) && (b >= d) }
fun part2(input: Sequence<String>): Int =
input.splitBounds()... | 0 | Kotlin | 1 | 2 | 39ac1df5542d9cb07a2f2d3448066e6e8896fdc1 | 688 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/leetcode/Problem1604.kt | fredyw | 28,460,187 | false | {"Java": 1280840, "Rust": 363472, "Kotlin": 148898, "Shell": 604} | package leetcode
/**
* https://leetcode.com/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/
*/
class Problem1604 {
fun alertNames(keyName: Array<String>, keyTime: Array<String>): List<String> {
val map = mutableMapOf<String, MutableList<String>>()
for (i in keyName.in... | 0 | Java | 1 | 4 | a59d77c4fd00674426a5f4f7b9b009d9b8321d6d | 1,255 | leetcode | MIT License |
src/Day10.kt | MickyOR | 578,726,798 | false | {"Kotlin": 98785} | import java.lang.Math.abs
fun main() {
fun part1(input: List<String>): Int {
var cycle = 0;
var neededCycles = listOf<Int>(20, 60, 100, 140, 180, 220);
var x = 1;
var ans = 0;
for (line in input) {
var vs = line.split(" ");
if (vs[0] == "noop") {
... | 0 | Kotlin | 0 | 0 | c24e763a1adaf0a35ed2fad8ccc4c315259827f0 | 2,091 | advent-of-code-2022-kotlin | Apache License 2.0 |
app/src/main/kotlin/com/resurtm/aoc2023/day10/Solution.kt | resurtm | 726,078,755 | false | {"Kotlin": 119665} | package com.resurtm.aoc2023.day10
fun launchDay10(testCase: String) {
val env = readEnv(testCase)
ensureStart(env)
println("Day 10, part 1: ${calcPart1(env)}")
println("Day 10, part 2: ${calcPart2(env)}")
}
private fun calcPart2(env: Env): Int {
val flood = cleanDebris(env)
for (row in 0..<env... | 0 | Kotlin | 0 | 0 | fb8da6c246b0e2ffadb046401502f945a82cfed9 | 6,800 | advent-of-code-2023 | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year19/Day15.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year19
import com.grappenmaker.aoc.*
import com.grappenmaker.aoc.year19.MazeEntity.*
import com.grappenmaker.aoc.Direction.*
fun PuzzleSet.day15() = puzzle(15) {
val pc = startComputer(input)
fun Direction.asLong() = when (this) {
UP -> 1L
DOWN -> 2L
LEFT -... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,406 | advent-of-code | The Unlicense |
src/main/kotlin/icu/trub/aoc/day07/Hand.kt | dtruebin | 728,432,747 | false | {"Kotlin": 76202} | package icu.trub.aoc.day07
data class Hand(val cards: List<Card>) : Comparable<Hand> {
val type: HandType
get() = with(cards.groupingBy { it }.eachCount()) {
if (containsKey(Card.CJJ)) {
val jokerCount = this[Card.CJJ]
when {
containsValue(5) ... | 0 | Kotlin | 0 | 0 | 1753629bb13573145a9781f984a97e9bafc34b6d | 2,566 | advent-of-code | MIT License |
2022/src/Day05.kt | Saydemr | 573,086,273 | false | {"Kotlin": 35583, "Python": 3913} | package src
import java.util.Stack
fun main() {
fun part2(input: List<String>): String {
val stackIndex = input.indexOfFirst { it.isEmpty() }
val stackInput = input.subList(0, stackIndex-1)
val numStacks = input.subList(stackIndex-1, stackIndex)
.map { it.replace(" ", "")
... | 0 | Kotlin | 0 | 1 | 25b287d90d70951093391e7dcd148ab5174a6fbc | 3,525 | AoC | Apache License 2.0 |
src/main/kotlin/search/BinarySearch.kt | alexiscrack3 | 310,484,737 | false | {"Kotlin": 44433} | package search
class BinarySearch {
fun binarySearch(arr: IntArray, l: Int, r: Int, key: Int): Int {
if (r < l) return -1
val mid = (l + r) / 2
if (key == arr[mid]) {
return mid
}
return if (key > arr[mid]) {
binarySearch(arr, mid + 1, r, key)
... | 0 | Kotlin | 0 | 0 | a2019868ece9ee319d08a150466304bfa41a8ad3 | 1,754 | algorithms-kotlin | MIT License |
2023/src/main/kotlin/de/skyrising/aoc2023/day14/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2023.day14
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.ints.IntArrayList
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
inline fun CharGrid.shift(i: Int, range: IntProgression, rocks: Int, sett: CharGrid.(Int,Int,Char)->Unit) {
var r = rocks
val dist = (if (range... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 2,713 | aoc | MIT License |
src/Day10.kt | spaikmos | 573,196,976 | false | {"Kotlin": 83036} | fun main() {
fun part1(input: List<String>): Int {
var tick = 1
var x = 1
var score = 0
val signal = setOf(20, 60, 100, 140, 180, 220)
for (i in input) {
// Whether nop or addx, increment the tick and calculate the score
tick++
if (signal.... | 0 | Kotlin | 0 | 0 | 6fee01bbab667f004c86024164c2acbb11566460 | 1,379 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/sk/leetcode/kotlin/189. Rotate Array.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.leetcode.kotlin
class Solution189 {
// time-O(n*k); n is size of array
fun rotate(nums: IntArray, k: Int) {
var count = k % nums.size
repeat(count) {
val last = nums.last()
for (j in nums.lastIndex downTo 1) {
nums[j] = nums[j - 1]
... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,828 | leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/realjenius/evernote/noteslurp/evernote/TagStrategies.kt | realjenius | 179,378,196 | false | {"Kotlin": 48752} | package realjenius.evernote.noteslurp.evernote
import realjenius.evernote.noteslurp.KeywordTag
import realjenius.evernote.noteslurp.KeywordType
import realjenius.evernote.noteslurp.TagConfig
import java.nio.file.Path
import java.nio.file.Paths
data class TagContext(val rootDir: Path = Path.of("/"), val filePath: Path... | 0 | Kotlin | 0 | 2 | 324d809b84e9d70521422db3e969ed4b2f640dc1 | 2,968 | noteslurp | Apache License 2.0 |
src/main/kotlin/Day8.kt | corentinnormand | 725,992,109 | false | {"Kotlin": 40576} | import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
fun main(args: Array<String>) {
Day8().two()
}
class Day8 : Aoc("day8.txt") {
val test = """
LR
11A = (11B, XXX)
11B = (XXX, 11Z)
11Z = (11B, XXX)
22A = (22B, XXX)
22B = (2... | 0 | Kotlin | 0 | 0 | 2b177a98ab112850b0f985c5926d15493a9a1373 | 2,604 | aoc_2023 | Apache License 2.0 |
src/Day06.kt | Excape | 572,551,865 | false | {"Kotlin": 36421} | fun main() {
fun findFirstDistinct(input: String, n: Int) = input.windowed(n).indexOfFirst { it.toSet().size == n } + n
fun part1(input: String) = findFirstDistinct(input, 4)
fun part2(input: String) = findFirstDistinct(input, 14)
println(part1("mjqjpqmgbljsphdztnvjfqwrcgsmlb"))
check(part1("mjqjpqmgbljsph... | 0 | Kotlin | 0 | 0 | a9d7fa1e463306ad9ea211f9c037c6637c168e2f | 697 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/ca/warp7/frc/path/SplineOptimizer.kt | Team865 | 198,131,314 | false | null | package ca.warp7.frc.path
import ca.warp7.frc.geometry.*
import kotlin.math.sqrt
fun List<QuinticSegment2D>.sumDCurvature2(): Double = sumByDouble { segment ->
(0 until 100).sumByDouble { segment[it / 100.0].dCurvatureSquared() }
}
fun fitParabola(p1: Translation2D, p2: Translation2D, p3: Translation2D): Double... | 0 | Kotlin | 2 | 1 | d65cc67eccd04fece3a1510094aa656628dce301 | 5,481 | FRC-Commons-Kotlin | MIT License |
src/main/kotlin/y2023/day05/Day05.kt | niedrist | 726,105,019 | false | {"Kotlin": 19919} | package y2023.day05
import BasicDay
import util.FileReader
import kotlin.math.min
val d = FileReader.readResource("2023/day05.txt").split("\n\n")
val seeds = d[0].split(":")[1].split(" ").filter { it != "" }.map { it.toLong() }
fun String.toMapping() = this.split("\n").filter { it.first().isDigit() }.map { it.split("... | 0 | Kotlin | 0 | 1 | 37e38176d0ee52bef05f093b73b74e47b9011e24 | 1,247 | advent-of-code | Apache License 2.0 |
AoC2021day11-DumboOctopus/src/main/kotlin/Main.kt | mcrispim | 533,770,397 | false | {"Kotlin": 29888} | import java.io.File
const val LINES = 10
const val COLS = 10
const val STEPS = 100
fun main() {
val input = File("data.txt").readLines()
val grid = MutableList(LINES) { line -> MutableList(COLS) { col -> input[line][col].digitToInt() } }
var nFlashes = 0
var totalFlashes = 0
var step = 0
whil... | 0 | Kotlin | 0 | 0 | ac4aa71c9b5955fa4077ae40fc7e3fc3d5242523 | 2,031 | AoC2021 | MIT License |
src/day13/Main.kt | nikwotton | 572,814,041 | false | {"Kotlin": 77320} | package day13
import day13.Packet.List
import day13.Packet.Number
import java.io.File
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.int
import kotlinx.serialization.json.jsonArray
import kotlinx.seriali... | 0 | Kotlin | 0 | 0 | dee6a1c34bfe3530ae6a8417db85ac590af16909 | 2,741 | advent-of-code-2022 | Apache License 2.0 |
hierarchy/src/commonMain/kotlin/io/data2viz/hierarchy/treemap/Binary.kt | data2viz | 89,368,762 | false | null | /*
* Copyright (c) 2018-2021. data2viz sàrl.
*
* 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... | 79 | Kotlin | 29 | 389 | 5640d3e8f1ce4cd4e5d651431726869e329520fc | 3,021 | data2viz | Apache License 2.0 |
project_euler_kotlin/src/main/kotlin/Solution0017.kt | NekoGoddessAlyx | 522,068,054 | false | {"Kotlin": 44135, "Rust": 24687} | class Solution0017 : Solution() {
override fun solve(): String {
return (1L..1000L)
.sumOf { makeWordy(it).length.toLong() }
.toString()
}
private val onesMap = mapOf(
'0' to "zero",
'1' to "one",
'2' to "two",
'3' to "three",
'4' to ... | 0 | Kotlin | 0 | 0 | f899b786d5ea5ffd79da51604dc18c16308d2a8a | 2,201 | Project-Euler | The Unlicense |
2023/14/solve-2.kts | gugod | 48,180,404 | false | {"Raku": 170466, "Perl": 121272, "Kotlin": 58674, "Rust": 3189, "C": 2934, "Zig": 850, "Clojure": 734, "Janet": 703, "Go": 595} | import java.io.File
class Platform (val grid: List<List<Char>>) {
val rowIndices = grid.indices
val colIndices = grid[0].indices
fun northTilted(): Platform {
val newGrid = grid.map { it.toMutableList() }
colIndices.forEach { x ->
rowIndices.forEach { y ->
if (... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 3,380 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/Day08.kt | flexable777 | 571,712,576 | false | {"Kotlin": 38005} | fun main() {
fun part1(input: List<String>): Int {
val countedTrees = mutableSetOf<Pair<Int, Int>>()
//read input as ints
val matrix = input.map { r ->
r.toList().map { it.digitToInt() }
}
val indices = matrix.first().indices
var previouslyHighestTree:... | 0 | Kotlin | 0 | 0 | d9a739eb203c535a3d83bc5da1b6a6a90a0c7bd6 | 6,641 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g0601_0700/s0695_max_area_of_island/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0601_0700.s0695_max_area_of_island
// #Medium #Array #Depth_First_Search #Breadth_First_Search #Matrix #Union_Find
// #Algorithm_I_Day_7_Breadth_First_Search_Depth_First_Search
// #Graph_Theory_I_Day_2_Matrix_Related_Problems
// #2023_02_22_Time_324_ms_(24.06%)_Space_47.2_MB_(21.92%)
@Suppress("NAME_SHADOWIN... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,280 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/dvdmunckhof/aoc/event2022/Day18.kt | dvdmunckhof | 318,829,531 | false | {"Kotlin": 195848, "PowerShell": 1266} | package com.dvdmunckhof.aoc.event2022
import com.dvdmunckhof.aoc.common.Vector3d
class Day18(input: List<String>) {
private val cubes = input.mapTo(mutableSetOf()) {
val (x, y, z) = it.split(",").map(String::toInt)
Vector3d(x, y, z)
}
private val neighbours = arrayOf(
Vector3d(-1,... | 0 | Kotlin | 0 | 0 | 025090211886c8520faa44b33460015b96578159 | 1,532 | advent-of-code | Apache License 2.0 |
baparker/12/main.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File
import kotlin.collections.mutableListOf
open class Cave(val name: String) {
val destList: MutableList<String> = mutableListOf()
}
class SmallCave(name: String) : Cave(name) {
var visited = false
}
var counter = 0
fun traverseCaves(
caveMap: MutableMap<String, Cave>,
caveN... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 1,856 | advent-of-code-2021 | MIT License |
src/main/kotlin/hu/advent/of/code/year2020/day9/Puzzle9B.kt | sztojkatamas | 568,512,275 | false | {"Kotlin": 157914} | package hu.advent.of.code.year2020.day9
import hu.advent.of.code.AdventOfCodePuzzle
import hu.advent.of.code.BaseChallenge
@AdventOfCodePuzzle
class Puzzle9B : BaseChallenge(2020) {
override fun run() {
printPuzzleName()
val data = loadLongDataFromFile("data9.txt")
val preamble = 25
... | 0 | Kotlin | 0 | 0 | 6aa9e53d06f8cd01d9bb2fcfb2dc14b7418368c9 | 1,980 | advent-of-code-universe | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/Maximum69Number.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,373 | kotlab | Apache License 2.0 |
src/main/kotlin/tr/emreone/adventofcode/days/Day11.kt | EmRe-One | 568,569,073 | false | {"Kotlin": 166986} | package tr.emreone.adventofcode.days
import tr.emreone.adventofcode.isDivisibleBy
import tr.emreone.adventofcode.lcm
import tr.emreone.adventofcode.product
object Day11 {
val OPERATION_PATTERN = """Operation: new = old (\+|\*) (\d+|old)""".toRegex()
val DIVISIBLE_PATTERN = """Test: divisible by (\d+)""".toRe... | 0 | Kotlin | 0 | 0 | a951d2660145d3bf52db5cd6d6a07998dbfcb316 | 4,319 | advent-of-code-2022 | Apache License 2.0 |
src/Day21.kt | abeltay | 572,984,420 | false | {"Kotlin": 91982, "Shell": 191} | fun main() {
val human = "humn"
fun parseInput(input: List<String>): MutableMap<String, String> {
val out = mutableMapOf<String, String>()
for (it in input) {
val parts = it.split(": ")
out[parts[0]] = parts[1]
}
return out
}
fun monkeyYell(monkey... | 0 | Kotlin | 0 | 0 | a51bda36eaef85a8faa305a0441efaa745f6f399 | 3,475 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/ca/kiaira/advent2023/day12/Day12.kt | kiairatech | 728,913,965 | false | {"Kotlin": 78110} | package ca.kiaira.advent2023.day12
import ca.kiaira.advent2023.Puzzle
/**
* Object representing the solution to the "Advent of Code - Day 12: Hot Springs" puzzle.
*
* This object extends the [Puzzle] class, specifically handling puzzles with [SpringConditionRecords] as input.
* It provides implementations for par... | 0 | Kotlin | 0 | 1 | 27ec8fe5ddef65934ae5577bbc86353d3a52bf89 | 2,824 | kAdvent-2023 | Apache License 2.0 |
KotlinAdvent2018/week1/src/main/kotlin/net/twisterrob/challenges/adventOfKotlin2018/week1/Map.kt | TWiStErRob | 136,539,340 | false | {"Kotlin": 104880, "Java": 11319} | package net.twisterrob.challenges.adventOfKotlin2018.week1
class Map(private val cells: Array<Array<Cell>>) {
val rows: Int = cells.rows
val cols: Int = cells.cols
override fun toString() =
cells.joinToString("\n") { row ->
row.joinToString(separator = "", transform = Cell::format)
}
operator fun get(row:... | 1 | Kotlin | 1 | 2 | 5cf062322ddecd72d29f7682c3a104d687bd5cfc | 1,413 | TWiStErRob | The Unlicense |
src/Day07.kt | ixtryl | 575,312,836 | false | null | import java.lang.IllegalArgumentException
import java.util.*
object DAY07 {
fun run(fileName: String, sizeLimit: Int): Int {
val lines = readInput(fileName)
val root: Directory = buildTree(lines)
var result = 0
root.visit {
val size = it.size()
when (it) {
... | 0 | Kotlin | 0 | 0 | 78fa5f6f85bebe085a26333e3f4d0888e510689c | 4,567 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/day21/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day21
fun main() {
val player1 = Player(4)
val player2 = Player(3)
val die = DeterministicDie()
var roundNumber = 0
var losingPlayer: Player
while (player1.score < 1000 && player2.score < 1000) {
if (roundNumber % 2 == 0) {
val score = die.roll() + die.roll() + die.... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 3,539 | aoc-2021 | MIT License |
src/main/kotlin/days_2021/Day3.kt | BasKiers | 434,124,805 | false | {"Kotlin": 40804} | package days_2021
import util.Day
import util.Util
class Day3 : Day(3) {
val input = inputList.map { it.toCharArray().toList() };
val transposedInput = Util.transpose(input)
fun invertBitChar(char: Char) = when (char) {
'1' -> '0'
'0' -> '1'
else -> char
}
fun getOccurren... | 0 | Kotlin | 0 | 0 | 870715c172f595b731ee6de275687c2d77caf2f3 | 2,093 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/manerfan/althorithm/sort/QuickSort.kt | manerfan | 122,578,493 | false | null | /*
* ManerFan(http://manerfan.com). All Rights Reserved.
*
* 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 app... | 0 | Kotlin | 0 | 0 | 9210934e15acefd1b5bafc7f11b2078643ded239 | 2,964 | algorithm-with-kotlin | Apache License 2.0 |
src/main/kotlin/g2601_2700/s2641_cousins_in_binary_tree_ii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2601_2700.s2641_cousins_in_binary_tree_ii
// #Medium #Hash_Table #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
// #2023_07_18_Time_922_ms_(90.91%)_Space_67.3_MB_(36.36%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary t... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,955 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/leetcode/random_problems/easy/roman_to_integer/Main.kt | frikit | 254,842,734 | false | null | package com.leetcode.random_problems.easy.roman_to_integer
fun main() {
println("Test case 1:")
println(Solution().romanToInt("III")) // 3
println()
println("Test case 2:")
println(Solution().romanToInt("IV")) // 4
println()
println("Test case 3:")
println(Solution().romanToInt("IX"))... | 0 | Kotlin | 0 | 0 | dda68313ba468163386239ab07f4d993f80783c7 | 1,477 | leet-code-problems | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DecodeWays.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,529 | kotlab | Apache License 2.0 |
src/main/kotlin/twentytwentytwo/Day2.kt | JanGroot | 317,476,637 | false | {"Kotlin": 80906} | package twentytwentytwo
fun main() {
val input = {}.javaClass.getResource("input-2.txt")!!.readText().split("\n");
val day = Day2(input)
println(day.part1())
println(day.part2())
}
class Day2(private val input: List<String>) {
fun part1(): Int {
fun toScore(l: String): Int {
re... | 0 | Kotlin | 0 | 0 | 04a9531285e22cc81e6478dc89708bcf6407910b | 1,235 | aoc202xkotlin | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/GenerateParentheses.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,834 | kotlab | Apache License 2.0 |
reposilite-backend/src/main/kotlin/com/reposilite/storage/Comparators.kt | dzikoysk | 96,474,388 | false | {"Kotlin": 732353, "Vue": 113305, "JavaScript": 100693, "CSS": 9405, "Java": 6529, "HTML": 4488, "Shell": 2402, "Dockerfile": 1654} | /*
* Copyright (c) 2023 dzikoysk
*
* 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... | 26 | Kotlin | 160 | 1,163 | d0042d564bf664329c5b0107b7580655cefb1238 | 3,078 | reposilite | Apache License 2.0 |
day17/src/main/kotlin/dev/fwcd/adventofcode2021/Day17.kt | fwcd | 432,520,714 | false | null | package dev.fwcd.adventofcode2021
import kotlin.math.sign
data class Vec(val x: Int, val y: Int) {
operator fun plus(rhs: Vec) = Vec(x + rhs.x, y + rhs.y)
}
data class Rect(val min: Vec, val max: Vec) {
operator fun contains(pos: Vec): Boolean =
pos.x >= min.x && pos.x <= max.x
&& pos.y >=... | 0 | Rust | 0 | 5 | 9327e74340af776b68649fcbbb2a9eec1db7533b | 1,725 | advent-of-code-2021 | MIT License |
2020/src/main/kotlin/de/skyrising/aoc2020/day12/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2020.day12
import de.skyrising.aoc.*
import kotlin.math.*
val test = TestInput("""
F10
N3
F7
R90
F11
""")
@PuzzleName("Rain Risk")
fun PuzzleInput.part1(): Any {
var x = 0
var y = 0
var angle = 0
for (line in lines) {
val command = line[0]
v... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 1,907 | aoc | MIT License |
ConceptOfTheDay/Kotlin/src/main/java/org/redquark/conceptoftheday/AnagramSubstringSearch.kt | ani03sha | 297,402,125 | false | null | package org.redquark.conceptoftheday
/**
* @author <NAME>
*
* We are given two strings "text" and "pattern" of size n and m respectively where m < n.
* Find all the indices in text where anagrams of pattern are found.
*/
private fun findIndices(text: String, pattern: String): List<Int> {
// Lengths of strings... | 2 | Java | 40 | 64 | 67b6ebaf56ec1878289f22a0324c28b077bcd59c | 1,832 | RedQuarkTutorials | MIT License |
src/main/kotlin/days/Day08.kt | poqueque | 430,806,840 | false | {"Kotlin": 101024} | package days
class Day08 : Day(8) {
override fun partOne(): Any {
val lengths = mutableListOf(0, 0, 0, 0, 0, 0, 0, 0)
inputList.forEach {
val (_, output) = it.split(" | ")
val outputs = output.split(" ")
for (o in outputs) lengths[o.length]++
}
... | 0 | Kotlin | 0 | 0 | 4fa363be46ca5cfcfb271a37564af15233f2a141 | 3,040 | adventofcode2021 | MIT License |
src/main/java/challenges/educative_grokking_coding_interview/linkedlist_inplace_reveresal/_3/ReverseLinkedList.kt | ShabanKamell | 342,007,920 | false | null | package challenges.educative_grokking_coding_interview.linkedlist_inplace_reveresal._3
import challenges.educative_grokking_coding_interview.LinkedList
import challenges.educative_grokking_coding_interview.LinkedListNode
import challenges.educative_grokking_coding_interview.PrintList.printListWithForwardArrow
import c... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 3,789 | CodingChallenges | Apache License 2.0 |
src/Day06.kt | nielsz | 573,185,386 | false | {"Kotlin": 12807} | fun main() {
fun part1(input: String): Int {
return input.firstUniquePartWithSize(4).first
}
fun part2(input: String): Int {
return input.firstUniquePartWithSize(14).first
}
val input = readInput("Day06").first()
println(part1(input)) // 1210
println(part2(input)) // 3476
... | 0 | Kotlin | 0 | 0 | 05aa7540a950191a8ee32482d1848674a82a0c71 | 756 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/danielmichalski/algorithms/data_structures/_12_dijkstra_algorithm/Runner.kt | DanielMichalski | 288,453,885 | false | {"Kotlin": 101963, "Groovy": 19141} | package com.danielmichalski.algorithms.data_structures._12_dijkstra_algorithm
object Runner {
private const val VERTEX_A = "A"
private const val VERTEX_B = "B"
private const val VERTEX_C = "C"
private const val VERTEX_D = "D"
private const val VERTEX_E = "E"
private const val VERTEX_F = "F"
... | 0 | Kotlin | 1 | 7 | c8eb4ddefbbe3fea69a172db1beb66df8fb66850 | 2,298 | algorithms-and-data-structures-in-kotlin | MIT License |
src/main/kotlin/Puzzle5.kt | darwineee | 578,563,140 | false | {"Kotlin": 17166} | import java.io.File
private val numberRegex = "\\d+".toRegex()
/**
* With this puzzle we do not use stack data structure in part 1, even though it is maybe easier.
* Because I want to keep most common logic from both part of the puzzle.
*/
fun puzzle5(args: Array<String>, isOnWrongShip: Boolean) {
val graphSta... | 0 | Kotlin | 0 | 0 | f4354b88b657a6d6f803632bc6b43b5abb6943f1 | 2,573 | adventOfCode2022 | Apache License 2.0 |
src/test/kotlin/dev/bogwalk/model/util.kt | bog-walk | 454,630,193 | false | {"Kotlin": 72261} | package dev.bogwalk.model
import java.io.File
typealias TestPlay = Pair<CardHand, CardHand>
fun getTestResource(
filePath: String,
lineTrim: CharArray = charArrayOf(' ', '\n'),
lineSplit: String = " "
): List<List<String>> {
val resource = mutableListOf<List<String>>()
File(filePath).useLines { l... | 0 | Kotlin | 0 | 1 | c1b9daf3102f857cd84b81344af272f82fc18bf4 | 3,335 | poker-hands | MIT License |
src/rationals/Rational.kt | jihedamine | 242,868,210 | false | null | package rationals
import java.lang.IllegalArgumentException
import java.lang.NumberFormatException
import java.math.BigInteger
class Rational {
private val numerator: BigInteger
private val denominator: BigInteger
constructor(numerator: BigInteger) : this(numerator, BigInteger.ONE)
constructor(numer... | 0 | Kotlin | 1 | 0 | 61e7156c6ce59df6e2dc9137853ce08f9070b633 | 3,985 | kotlin_coursera | Apache License 2.0 |
src/binary.kt | dlew | 54,331,937 | false | null | /**
* Proof for the Riddler problem from March 18, 2016
*
* http://fivethirtyeight.com/features/can-you-best-the-mysterious-man-in-the-trench-coat/
*/
fun main(args: Array<String>) {
findBestOutcome(1, 1000, 9)
}
fun findBestOutcome(lowerBound: Int, upperBound: Int, maxGuesses: Int, verbose: Boolean = false) {
... | 0 | Kotlin | 1 | 6 | 55e9d2f6c56bdf1f2f7502c23d581b59ff1d4d80 | 2,166 | kotlin-riddler | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/TwoArraysEqualReversing.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,544 | kotlab | Apache License 2.0 |
app/src/test/java/tdc/com/bidirectionaldijkstrasalgorithm/model/forkotlin/BidirectionalDijkstraTest.kt | tangxiaocheng | 287,857,886 | false | null | package tdc.com.bidirectionaldijkstrasalgorithm.model.forkotlin
import com.google.common.truth.Truth
import org.junit.Test
import java.util.*
import java.util.Collections.sort
class BidirectionalDijkstraTest {
private fun Int.generateDirectedGraph(
numOfNodes: Int,
numOfEdges: Int,
distan... | 0 | Kotlin | 0 | 0 | 7614166ac676114df26435c7709c7dc2d9b52875 | 4,604 | BidirectionalDijkstrasAlgorithm | MIT License |
src/main/kotlin/days_2021/Day7.kt | BasKiers | 434,124,805 | false | {"Kotlin": 40804} | package days_2021
import util.Day
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
class Day7 : Day(7) {
val input = inputString.split(",").map(String::toInt)
val minInputVal = input.reduce { a, b -> min(a, b) }
val maxInputVal = input.reduce { a, b -> max(a, b) }
fun getExponenti... | 0 | Kotlin | 0 | 0 | 870715c172f595b731ee6de275687c2d77caf2f3 | 1,390 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/Day02.kt | rogierbom1 | 573,165,407 | false | {"Kotlin": 5253} | package main.kotlin
import readInput
fun String.toShape() = when (this) {
"A", "X" -> Rock
"B", "Y" -> Paper
"C", "Z" -> Scissors
else -> throw ShapeException.InvalidShapeException
}
fun String.toStrategicShape(opponentShape: Shape) = when (this) {
"X" -> opponentShape.trumps()
"Y" -> opponen... | 0 | Kotlin | 0 | 0 | b7a03e95785cb4a2ec0bfa170f4f667fc574c1d2 | 1,322 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/io/recursion/IntegerToRoman.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.recursion
import io.utils.runTests
// https://leetcode.com/problems/integer-to-roman/
class IntegerToRoman {
fun execute(input: Int): String = input.toRomanNumber()
}
private fun Int.toRomanNumber(): String = when (this) {
in Int.MIN_VALUE..0 -> ""
in 1..3 -> "I".repeat(this)
4 -> "IV"
in 5..8 ... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,151 | coding | MIT License |
year2015/src/main/kotlin/net/olegg/aoc/year2015/day11/Day11.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2015.day11
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.series
import net.olegg.aoc.year2015.DayOf2015
import java.math.BigInteger
import java.math.BigInteger.ONE
import java.math.BigInteger.ZERO
/**
* See [Year 2015, Day 11](https://adventofcode.com/2015/day/11)
*/
obje... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,859 | adventofcode | MIT License |
src/chapter1/section4/ex15a_TwoSumFaster.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter1.section4
import extensions.inputPrompt
import extensions.readAllInts
/**
* 快速3-sum
* 作为热身,使用一个线性级别的算法(而非基于二分查找的线性对数级别的算法)
* 实现TwoSumFaster来计算已排序的数组中和为0的整数对的数量。
* 用相同的思想为3-sum问题给出一个平方级别的算法。
*
* 解:先找到值为0的元素数量,当多于一个时,用组合公式计算组合数,需要查找N次
* 从两侧向中间查找,如果和大于0,右侧向左移一位,和小于0,左侧向右移一位
* 如果和为0,判断元素值是否为0,为0则直... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 2,246 | Algorithms-4th-Edition-in-Kotlin | MIT License |
2020/kotlin/day-8/main.kt | waikontse | 330,900,073 | false | null | import util.FileUtils
data class Accumulator(val acc: Int)
data class ProgramCounter(val pc: Int)
data class CPU(val acc: Accumulator, val pc: ProgramCounter)
fun main() {
val fileUtils: FileUtils = FileUtils("input.txt")
fileUtils.printLines()
// Challenge #1
val cpu: CPU = runProgram1(fileUtils.li... | 0 | Kotlin | 0 | 0 | abeb945e74536763a6c72cebb2b27f1d3a0e0ab5 | 3,152 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/g1801_1900/s1840_maximum_building_height/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1840_maximum_building_height
// #Hard #Array #Math #2023_06_22_Time_1210_ms_(100.00%)_Space_118.6_MB_(100.00%)
class Solution {
fun maxBuilding(n: Int, restrictions: Array<IntArray>): Int {
if (restrictions.isEmpty()) {
return n - 1
}
val m = restrictions.si... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,147 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/wtf/log/xmas2021/day/day06/Day06.kt | damianw | 434,043,459 | false | {"Kotlin": 62890} | package wtf.log.xmas2021.day.day06
import wtf.log.xmas2021.Day
import java.io.BufferedReader
@Suppress("SameParameterValue")
object Day06 : Day<List<Int>, Long, Long> {
override fun parseInput(reader: BufferedReader): List<Int> {
return reader.readLine().split(',').map { it.toInt() }
}
override ... | 0 | Kotlin | 0 | 0 | 1c4c12546ea3de0e7298c2771dc93e578f11a9c6 | 1,869 | AdventOfKotlin2021 | BSD Source Code Attribution |
src/Day10.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | import kotlin.math.absoluteValue
fun main() {
val testInput = readInput("Day10_test")
check(part1(testInput) == 13140)
val part2Test = """
##..##..##..##..##..##..##..##..##..##..
###...###...###...###...###...###...###.
####....####....####....####....####....
#####.....##... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 1,371 | aoc-22 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions42.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
fun test42() {
intArrayOf(1, -2, 3, 10, -4, 7, 2, -5).printlnResult()
intArrayOf().printlnResult()
intArrayOf(1, 1, 1, 1, 1, 1, 1, 1).printlnResult()
intArrayOf(-1, -1, -1, -1, -1, -1, -1, -1).printlnResult()
}
/**
* Questions 42: Find the biggest sum of sub-arr... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 757 | Algorithm | Apache License 2.0 |
day-4/src/Part1.kt | woojiahao | 225,170,972 | false | null | fun pairInput(i: Int, predicate: (Int, Int) -> Boolean) =
i.toString().zipWithNext { a, b -> predicate(a.toInt(), b.toInt()) }
fun hasRepeating(i: Int) = pairInput(i) { a, b -> a == b }.any { it }
fun isAscending(i: Int) = pairInput(i) { a, b -> a <= b }.all { it }
fun validate(i: Int) = hasRepeating(i) && isAscen... | 0 | Kotlin | 0 | 2 | 4c9220a49dbc093fbe7f0d6692fa0390a63e702a | 446 | aoc-19 | MIT License |
test/leetcode/TwoSum.kt | andrej-dyck | 340,964,799 | false | null | package leetcode
import lib.IntArrayArg
import org.assertj.core.api.Assertions
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.converter.ConvertWith
import org.junit.jupiter.params.provider.CsvSource
/**
* https://leetcode.com/problems/two-sum/
*
* 1. Two Sum
* [Easy]
*
* Given... | 0 | Kotlin | 0 | 0 | 3e3baf8454c34793d9771f05f330e2668fda7e9d | 2,067 | coding-challenges | MIT License |
year2019/day03/wire/src/main/kotlin/com/curtislb/adventofcode/year2019/day03/wire/Wire.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.year2019.day03.wire
import com.curtislb.adventofcode.common.geometry.Direction
import com.curtislb.adventofcode.common.geometry.Point
import com.curtislb.adventofcode.common.geometry.Segment
/**
* A wire consisting of a series of segments laid out in a 2D grid.
*
* @param wireStri... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 5,409 | AdventOfCode | MIT License |
src/org/aoc2021/Day21.kt | jsgroth | 439,763,933 | false | {"Kotlin": 86732} | package org.aoc2021
import java.nio.file.Files
import java.nio.file.Path
import kotlin.math.max
object Day21 {
data class Key(val p1Pos: Int, val p1Score: Int, val p2Pos: Int, val p2Score: Int, val isP1Turn: Boolean)
private fun solvePart1(lines: List<String>): Int {
var (p1Pos, p2Pos) = parseStartin... | 0 | Kotlin | 0 | 0 | ba81fadf2a8106fae3e16ed825cc25bbb7a95409 | 3,360 | advent-of-code-2021 | The Unlicense |
year2021/day14/polymer/src/main/kotlin/com/curtislb/adventofcode/year2021/day14/polymer/PolymerizationProcess.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.year2021.day14.polymer
import com.curtislb.adventofcode.common.collection.Counter
import com.curtislb.adventofcode.common.collection.mapToMap
import com.curtislb.adventofcode.common.comparison.minMaxByOrNull
import com.curtislb.adventofcode.common.io.forEachSection
import java.io.File... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 5,220 | AdventOfCode | MIT License |
src/main/kotlin/day07/part2/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 | 5,238 | AdventOfCode2019 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ClimbingStairs.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,913 | kotlab | Apache License 2.0 |
jvm_sandbox/projects/advent_of_code/src/main/kotlin/year2021/Day4.kt | jduan | 166,515,850 | false | {"Rust": 876461, "Kotlin": 257167, "Java": 139101, "Python": 114308, "Vim Script": 100117, "Shell": 96665, "C": 67784, "Starlark": 23497, "JavaScript": 20939, "HTML": 12920, "Ruby": 5087, "Thrift": 4518, "Nix": 2919, "HCL": 1069, "Lua": 926, "CSS": 826, "Assembly": 761, "Makefile": 591, "Haskell": 585, "Dockerfile": 50... | package year2021
import java.io.File
import java.lang.RuntimeException
class Board(private val board: List<List<Int>>) {
private val state: MutableMap<Pair<Int, Int>, Boolean> = mutableMapOf()
init {
for (i in board.indices) {
for (j in 0 until board[0].size) {
state[Pair(... | 58 | Rust | 1 | 0 | d5143e89ce25d761eac67e9c357620231cab303e | 3,335 | cosmos | MIT License |
src/main/kotlin/day19.kt | Gitvert | 433,947,508 | false | {"Kotlin": 82286} | fun day19() {
val lines: List<String> = readFile("day19.txt")
day19part1(lines)
day19part2(lines)
}
fun day19part1(lines: List<String>) {
val scanner0 = initScanner0(lines.subList(0, lines.indexOf("--- scanner 1 ---")))
val unknownRotationScanners = initUnknownRotationScanners(lines.subList(lines.... | 0 | Kotlin | 0 | 0 | 02484bd3bcb921094bc83368843773f7912fe757 | 9,877 | advent_of_code_2021 | MIT License |
src/main/kotlin/days/day15/Day15.kt | Stenz123 | 725,707,248 | false | {"Kotlin": 123279, "Shell": 862} | package days.day15
import days.Day
class Day15 : Day(false) {
override fun partOne(): Any {
return readInput()[0].split(",").sumOf { inp ->
var currentValue = 0
inp.forEach { c ->
currentValue += c.code
currentValue *= 17
currentValue... | 0 | Kotlin | 1 | 0 | 3de47ec31c5241947d38400d0a4d40c681c197be | 1,699 | advent-of-code_2023 | The Unlicense |
src/day06/Day06.kt | Ciel-MC | 572,868,010 | false | {"Kotlin": 55885} | package day06
import readInput
fun main() {
fun String.findDistinctOf(size: Int): Int {
return this.windowed(size).withIndex().first { it.value.toSet().size == size }.index + size
}
fun part1(input: String): Int {
return input.findDistinctOf(4)
}
fun part2(input: String): Int {
... | 0 | Kotlin | 0 | 0 | 7eb57c9bced945dcad4750a7cc4835e56d20cbc8 | 947 | Advent-Of-Code | Apache License 2.0 |
src/Day14.kt | MickyOR | 578,726,798 | false | {"Kotlin": 98785} | import kotlin.math.max
import kotlin.math.min
fun main() {
fun part1(input: List<String>): Int {
val matrix = Array(1001) { CharArray(1001) }
for (i in matrix.indices) {
for (j in matrix[i].indices) {
matrix[i][j] = '.'
}
}
for (line in input)... | 0 | Kotlin | 0 | 0 | c24e763a1adaf0a35ed2fad8ccc4c315259827f0 | 3,690 | advent-of-code-2022-kotlin | Apache License 2.0 |
kotlin/src/com/leetcode/42_TrappingRainWater.kt | programmerr47 | 248,502,040 | false | null | package com.leetcode
import kotlin.math.*
/**
* We make two projection arrays. And after that combine then with subtraction of original h[i].
* In more details:
* 1. We put ray of lights from left to right and consider h[i] as an obstacle, so it will put shadow after itself
* 2. We put ray of lights from right to... | 0 | Kotlin | 0 | 0 | 0b5fbb3143ece02bb60d7c61fea56021fcc0f069 | 2,844 | problemsolving | Apache License 2.0 |
src/Day06.kt | kipwoker | 572,884,607 | false | null |
fun main() {
fun getDiffIndex(input: List<String>, diffCount: Int): Int {
val line = input[0].toCharArray()
for (i in 0..line.size - diffCount) {
if (line.slice(i until i + diffCount).toSet().size == diffCount) {
return i + diffCount
}
}
ret... | 0 | Kotlin | 0 | 0 | d8aeea88d1ab3dc4a07b2ff5b071df0715202af2 | 892 | aoc2022 | Apache License 2.0 |
src/main/kotlin/d10/D10.kt | MTender | 734,007,442 | false | {"Kotlin": 108628} | package d10
fun findConnections(diagram: List<String>, loc: Pair<Int, Int>): List<Pair<Int, Int>> {
val here = diagram[loc.first][loc.second]
return when (here) {
'S' -> {
val connections = mutableListOf<Pair<Int, Int>>()
if ("F7|".contains(diagram[loc.first - 1][loc.second]))... | 0 | Kotlin | 0 | 0 | a6eec4168b4a98b73d4496c9d610854a0165dbeb | 2,044 | aoc2023-kotlin | MIT License |
src/Day06.kt | jvmusin | 572,685,421 | false | {"Kotlin": 86453} | fun main() {
fun solve(s: String, k: Int): Int {
return s.indices.first { i -> s.substring(i, i + k).toSet().size == k } + k
}
fun part1(input: List<String>): Int {
return solve(input[0], 4)
}
fun part2(input: List<String>): Int {
return solve(input[0], 14)
}
val d... | 1 | Kotlin | 0 | 0 | 4dd83724103617aa0e77eb145744bc3e8c988959 | 626 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g2001_2100/s2050_parallel_courses_iii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2050_parallel_courses_iii
// #Hard #Dynamic_Programming #Graph #Topological_Sort
// #2023_06_23_Time_974_ms_(100.00%)_Space_84.4_MB_(100.00%)
import java.util.ArrayDeque
import java.util.Queue
class Solution {
fun minimumTime(n: Int, relations: Array<IntArray>, time: IntArray): Int {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,547 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MakeAllStringsEqual.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,373 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/search/BinaryRecursiveSearch.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,528 | kotlab | Apache License 2.0 |
src/main/kotlin/Day07.kt | arosenf | 726,114,493 | false | {"Kotlin": 40487} | import kotlin.system.exitProcess
fun main(args: Array<String>) {
if (args.isEmpty() or (args.size < 2)) {
println("Hands not specified")
exitProcess(1)
}
val fileName = args.first()
println("Reading $fileName")
val result =
if (args[1] == "part1") {
val hands = ... | 0 | Kotlin | 0 | 0 | d9ce83ee89db7081cf7c14bcad09e1348d9059cb | 5,010 | adventofcode2023 | MIT License |
src/Day01.kt | robinpokorny | 572,434,148 | false | {"Kotlin": 38009} | typealias Backpack = List<Int>
private fun parse(input: String): List<Backpack> = input
.split("\n\n")
.map { it.lines().map(String::toInt) }
private fun sumOfLargestBackpack(input: List<Backpack>): Int = input
.maxOf { it.sum() }
private fun sumOf3LargestBackpacks(input: List<Backpack>): Int = input
... | 0 | Kotlin | 0 | 2 | 56a108aaf90b98030a7d7165d55d74d2aff22ecc | 852 | advent-of-code-2022 | MIT License |
src/day16.kts | miedzinski | 434,902,353 | false | {"Kotlin": 22560, "Shell": 113} | enum class PacketType(val id: Int) {
SUM(0),
PRODUCT(1),
MINIMUM(2),
MAXIMUM(3),
LITERAL(4),
GREATER_THAN(5),
LESS_THAN(6),
EQUALS(7),
}
class BitStream(private val chars: String) {
private val RADIX: Int = 16
private val BITS_PER_CHAR = 4
val bits = chars.asSequence().map {... | 0 | Kotlin | 0 | 0 | 6f32adaba058460f1a9bb6a866ff424912aece2e | 2,532 | aoc2021 | The Unlicense |
src/main/kotlin/io/rbrincke/dice/core/MultisetPermutationIterator.kt | rbrincke | 167,712,634 | false | {"Kotlin": 13146} | package io.rbrincke.dice.core
/**
* Multiset permutation iterator. Not thread safe.
*
* See *"Loopless Generation of Multiset Permutations using a Constant Number
* of Variables by Prefix Shifts."*, <NAME>, 2009.
*/
class MultisetPermutationIterator<E : Comparable<E>>(input: Collection<E>) : Iterator<List<E>> {
... | 0 | Kotlin | 0 | 0 | fc5aa0365d91ce360bf6e9c7589e3f5fc6bc8a82 | 2,499 | nontransitive-dice | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions9.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import com.qiaoyuang.algorithm.round0.Queue
import com.qiaoyuang.algorithm.round0.Stack
fun test9() {
val stack = TwoQueuesStack<Int>()
val queue = TwoStacksQueue<Int>()
repeat(10) {
stack.push(it)
queue.enqueue(it)
}
println("Stack input: [0,... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 2,209 | Algorithm | Apache License 2.0 |
src/com/ssynhtn/medium/UniquePermutations.kt | ssynhtn | 295,075,844 | false | {"Java": 639777, "Kotlin": 34064} | package com.ssynhtn.medium
import java.util.*
class UniquePermutations {
fun permuteUnique(nums: IntArray): List<List<Int>> {
nums.sort()
val collection = mutableListOf<List<Int>>()
permute(nums, 0, collection)
return collection
}
private fun permute(nums: IntArray, fixCo... | 0 | Java | 0 | 0 | 511f65845097782127bae825b07a51fe9921c561 | 1,929 | leetcode | Apache License 2.0 |
src/week-day-1/Pangram.kt | luix | 573,258,926 | false | {"Kotlin": 7897, "Java": 232} | package week1
/**
* Pangram (easy)
* Problem Statement
* A pangram is a sentence where every letter of the English alphabet
* appears at least once.
*
* Given a string sentence containing English letters (lower or upper-case),
* return true if sentence is a pangram, or false otherwise.
*
* Note: The given sen... | 0 | Kotlin | 0 | 0 | 8e9b605950049cc9a0dced9c7ba99e1e2458e53e | 1,399 | advent-of-code-kotlin-2022 | Apache License 2.0 |
com/ztoais/dailycoding/algoexpert/medium/ThreeNumberSum.kt | RanjithRagavan | 479,563,314 | false | {"Kotlin": 7371} | package com.ztoais.dailycoding.algoexpert.medium
import kotlin.io.path.createTempDirectory
/*
Three Number Sum
Write a function that takes in a non-empty array of distinct integers and an integer representing a target sum. The
function should find all triplets in the array that sum up to the target sum and return a... | 0 | Kotlin | 0 | 0 | a5f29dd82c0c50fc7d2490fd1be6234cdb4d1d8a | 2,553 | daily-coding | MIT License |
src/main/kotlin/org/sjoblomj/adventofcode/day3/Visualizer.kt | sjoblomj | 161,537,410 | false | null | package org.sjoblomj.adventofcode.day3
import org.sjoblomj.adventofcode.printJson
class Grid(val claims: List<Claim>, val cells: List<List<List<Int>>>)
internal fun visualizeArea(area: Area): String {
var output = ""
for (y in area.indices) {
for (x in area[0].indices) {
val claims = area[y][x]
... | 0 | Kotlin | 0 | 0 | 80db7e7029dace244a05f7e6327accb212d369cc | 1,079 | adventofcode2018 | MIT License |
src/test/kotlin/adventofcode/day05/Day05.kt | jwcarman | 573,183,719 | false | {"Kotlin": 183494} | /*
* Copyright (c) 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 i... | 0 | Kotlin | 0 | 0 | d6be890aa20c4b9478a23fced3bcbabbc60c32e0 | 3,792 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ArrIntoConsecutiveSubsequences.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,267 | kotlab | Apache License 2.0 |
src/main/kotlin/arrayandlist/medium/ProductOfArrayExceptSelf.kt | jiahaoliuliu | 747,189,993 | false | {"Kotlin": 97631} | package arrayandlist.medium
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* Given an integer array nums, return an array answer such that answer[i] is equal to the product of all
* the elements of nums except nums[i].
* The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit int... | 0 | Kotlin | 0 | 0 | c5ed998111b2a44d082fc6e6470d197554c0e7c9 | 2,229 | CodingExercises | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.