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/jsTest/kotlin/io/github/offlinebrain/khexagon/algorythm/PathfindingTest.kt | OfflineBrain | 663,452,814 | false | null | import io.github.offlinebrain.khexagon.algorythm.AccessibilityTrie
import io.github.offlinebrain.khexagon.algorythm.aStar
import io.github.offlinebrain.khexagon.coordinates.AxisPoint
import io.github.offlinebrain.khexagon.math.circle
import io.github.offlinebrain.khexagon.math.distanceTo
import io.kotest.core.spec.styl... | 0 | Kotlin | 0 | 1 | 1bf3b6f073fbad98eeb10ea83730e883cf8ed7d5 | 10,377 | khexagon | MIT License |
src/main/kotlin/github/walkmansit/aoc2020/Day07.kt | walkmansit | 317,479,715 | false | null | package github.walkmansit.aoc2020
class Day07(val input: List<String>) : DayAoc<Int, Int> {
private class Graph {
private val nodes: MutableMap<String, Node> = mutableMapOf()
fun addNodeWithParent(parentName: String, name: String, weight: Int) {
fun findWithCreate(value: String): No... | 0 | Kotlin | 0 | 0 | 9c005ac4513119ebb6527c01b8f56ec8fd01c9ae | 3,056 | AdventOfCode2020 | MIT License |
2021/src/main/kotlin/com/trikzon/aoc2021/Day9.kt | Trikzon | 317,622,840 | false | {"Kotlin": 43720, "Rust": 21648, "C#": 12576, "C++": 4114, "CMake": 397} | package com.trikzon.aoc2021
import java.util.*
import kotlin.collections.ArrayList
fun main() {
val input = getInputStringFromFile("/day9.txt")
benchmark(Part.One, ::day9Part1, input, 498, 50)
benchmark(Part.Two, ::day9Part2, input, 1071000, 50)
}
fun day9Part1(input: String): Int {
val grid = Array(... | 0 | Kotlin | 1 | 0 | d4dea9f0c1b56dc698b716bb03fc2ad62619ca08 | 3,785 | advent-of-code | MIT License |
src/main/kotlin/_0040_CombinationSumII.kt | ryandyoon | 664,493,186 | false | null | // https://leetcode.com/problems/combination-sum-ii
fun combinationSum2(candidates: IntArray, target: Int): List<List<Int>> {
candidates.sort()
return mutableSetOf<List<Int>>().also {
buildCombinations(candidates, startIndex = 0, target = target, combination = mutableListOf(), combinations = it)
}.t... | 0 | Kotlin | 0 | 0 | 7f75078ddeb22983b2521d8ac80f5973f58fd123 | 1,208 | leetcode-kotlin | MIT License |
kotlin/1799-maximize-score-after-n-operations.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | class Solution {
fun maxScore(nums: IntArray): Int {
val cache = IntArray(1 shl nums.size) { -1 }
fun dfs(mask: Int, op: Int): Int {
if (cache[mask] != -1) return cache[mask]
for (i in 0 until nums.size) {
for (j in i + 1 until nums.size) {
... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,066 | leetcode | MIT License |
src/main/kotlin/g2701_2800/s2791_count_paths_that_can_form_a_palindrome_in_a_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2701_2800.s2791_count_paths_that_can_form_a_palindrome_in_a_tree
// #Hard #Dynamic_Programming #Depth_First_Search #Tree #Bit_Manipulation #Bitmask
// #2023_08_06_Time_683_ms_(100.00%)_Space_54_MB_(100.00%)
class Solution {
private fun getMap(parent: List<Int>, s: String, dp: IntArray, idx: Int): Int {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,617 | LeetCode-in-Kotlin | MIT License |
kotlin/0399-evaluate-division.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | class Solution {
fun calcEquation(equations: List<List<String>>, values: DoubleArray, queries: List<List<String>>): DoubleArray {
val adj = HashMap<String, ArrayList<Pair<String, Double>>>().apply {
for (i in equations.indices) {
val (a, b) = equations[i]
val valu... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,582 | leetcode | MIT License |
src/pl/shockah/aoc/y2021/Day3.kt | Shockah | 159,919,224 | false | null | package pl.shockah.aoc.y2021
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import pl.shockah.aoc.AdventTask
import pl.shockah.unikorn.collection.Array2D
import pl.shockah.unikorn.collection.takeRows
class Day3: AdventTask<Array2D<Boolean>, Int, Long>(2021, 3) {
override fun parseInput(raw... | 0 | Kotlin | 0 | 0 | 9abb1e3db1cad329cfe1e3d6deae2d6b7456c785 | 2,596 | Advent-of-Code | Apache License 2.0 |
src/day01/Day01.kt | wasabi-muffin | 726,936,666 | false | {"Kotlin": 10804} | package day01
import base.Day
fun main() = Day01.run()
object Day01 : Day<Int>("01") {
override val test1Expected: Int = 142
override val test2Expected: Int = 281
override fun part1(input: List<String>): Int = input.sumOf { line ->
line.first { it.isDigit() }.digitToInt() * 10 +
line... | 0 | Kotlin | 0 | 0 | 544cdd359e4456a74b1584cbf1e5dddca97f1394 | 1,728 | advent-of-code-2023 | Apache License 2.0 |
src/Day01.kt | sjgoebel | 573,578,579 | false | {"Kotlin": 21782} | fun main() {
fun part1(input: List<String>): Int {
val nums = mutableListOf<Int>()
var sum = 0
for (s in input) {
if (s != "") {
sum += Integer.parseInt(s)
} else {
nums.add(sum)
sum = 0
}
}
n... | 0 | Kotlin | 0 | 0 | ae1588dbbb923dbcd4d19fd1495ec4ebe8f2593e | 1,113 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day11.kt | chasegn | 573,224,944 | false | {"Kotlin": 29978} | import java.lang.IllegalArgumentException
/**
* Day 11 for Advent of Code 2022
* https://adventofcode.com/2022/day/11
*/
class Day11 : Day {
override val inputFileName: String = "Day11"
override val test1Expected: Long? = null
// override val test1Expected: Long = 10605
override val test2Expected: Lo... | 0 | Kotlin | 0 | 0 | 2b9a91f083a83aa474fad64f73758b363e8a7ad6 | 4,997 | advent-of-code-2022 | Apache License 2.0 |
src/adventofcode/Day13.kt | Timo-Noordzee | 573,147,284 | false | {"Kotlin": 80936} | package adventofcode
import org.openjdk.jmh.annotations.*
import java.util.concurrent.TimeUnit
private sealed interface Packet : Comparable<Packet> {
class IntPacket(val value: Int) : Packet {
override fun compareTo(other: Packet) = when (other) {
is IntPacket -> value.compareTo(other.value)
... | 0 | Kotlin | 0 | 2 | 10c3ab966f9520a2c453a2160b143e50c4c4581f | 3,856 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day3.kt | hughjdavey | 159,955,618 | false | null | package days
class Day3 : Day(3) {
private val claims = inputList.map { Claim(it) }
private val maxX = claims.map { it.maxX() }.sorted().last()
private val maxY = claims.map { it.maxY() }.sorted().last()
private val grid = Array(maxX + 1) { Array<MutableSet<Int>>(maxY + 1) { mutableSetOf() } }
in... | 0 | Kotlin | 0 | 0 | 4f163752c67333aa6c42cdc27abe07be094961a7 | 2,232 | aoc-2018 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/_2021/Day8.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2021
import REGEX_LINE_SEPARATOR
import REGEX_WHITESPACE
import aoc
fun main() {
aoc(2021, 8) {
aocRun { input ->
input.split(REGEX_LINE_SEPARATOR).sumOf { line ->
line.substringAfter(" | ").split(REGEX_WHITESPACE).count { digit ->
digit.length.let { it == 2 || it == 3 || it == 4 || it == 7 }
... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 3,549 | AdventOfCode | Creative Commons Zero v1.0 Universal |
AoC2021day08-SevenSegment/src/main/kotlin/Main.kt | mcrispim | 533,770,397 | false | {"Kotlin": 29888} | import java.io.File
fun main() {
val inputFile = File("data.txt")
val inputLines = inputFile.readLines()
var result = 0
for (line in inputLines) {
val data = line.split(" | ")
val leftData = data.first().split(" ")
val rightdata = data.last().split(" ")
val rosetta =... | 0 | Kotlin | 0 | 0 | ac4aa71c9b5955fa4077ae40fc7e3fc3d5242523 | 2,440 | AoC2021 | MIT License |
src/main/kotlin/Day1.kt | cbrentharris | 712,962,396 | false | {"Kotlin": 171464} | import kotlin.String
import kotlin.collections.List
object Day1 {
fun part1(input: List<String>): String = input.sumOf(::findFirstAndLastDigit).toString()
private fun findFirstAndLastDigit(i: String): Int {
val digits = i.filter { it.isDigit() }
return (digits.take(1) + digits.takeLast(1)).toI... | 0 | Kotlin | 0 | 1 | f689f8bbbf1a63fecf66e5e03b382becac5d0025 | 864 | kotlin-kringle | Apache License 2.0 |
src/main/kotlin/days/Day25.kt | andilau | 573,139,461 | false | {"Kotlin": 65955} | package days
import kotlin.math.pow
@AdventOfCodePuzzle(
name = "Full of Hot Air",
url = "https://adventofcode.com/2022/day/25",
date = Date(day = 25, year = 2022)
)
class Day25(val input: List<String>) : Puzzle {
override fun partOne() = input.sumOf(::snafuToDecimal).toSnafu()
override fun part... | 0 | Kotlin | 0 | 0 | da824f8c562d72387940844aff306b22f605db40 | 1,945 | advent-of-code-2022 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/model/method/HalfDivisionMethod.kt | Roggired | 348,065,860 | false | null | package model.method
import model.equation.Equation
import kotlin.math.abs
import kotlin.math.sign
class HalfDivisionMethod(
equation: Equation,
leftBound: Double,
rightBound: Double,
accuracy: Double
): Method(equation, leftBound, rightBound, accuracy) {
private val solutions: ArrayList<Double> =... | 0 | Kotlin | 0 | 2 | 983935fc1ca2a6da564ff8300c2a53cc85dd8701 | 2,807 | maths_lab2 | MIT License |
src/main/kotlin/days/Day4.kt | andilau | 433,504,283 | false | {"Kotlin": 137815} | package days
@AdventOfCodePuzzle(
name = "<NAME>",
url = "https://adventofcode.com/2021/day/4",
date = Date(day = 4, year = 2021)
)
class Day4(input: List<String>) : Puzzle {
private val draws = readDraws(input)
private val boards = readBoards(input)
override fun partOne() =
draws.firs... | 0 | Kotlin | 0 | 0 | b3f06a73e7d9d207ee3051879b83e92b049a0304 | 2,213 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
src/AoC6.kt | Pi143 | 317,631,443 | false | null | import java.io.File
fun main() {
//testsDay6()
println("Starting Day 6 A Test 1")
calculateDay6PartA("Input/2020_Day6_A_Test1")
println("Starting Day 6 A Real")
calculateDay6PartA("Input/2020_Day6_A")
println("Starting Day 6 B Test 1")
calculateDay6PartB("Input/2020_Day6_A_Test1")
pri... | 0 | Kotlin | 0 | 1 | fa21b7f0bd284319e60f964a48a60e1611ccd2c3 | 1,982 | AdventOfCode2020 | MIT License |
leetcode2/src/leetcode/house-robber.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* 198. 打家劫舍
* https://leetcode-cn.com/problems/house-robber/
* Created by test
* Date 2019/9/14 16:09
* Description
* 系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。
给定一个代表每个房屋存放金额的非负整数数组,计算你在不触动警报装置的情况下,能够偷窃到的最高金额。
示例 1:
输入: [1,2,3,1]
输出: 4
解释: 偷窃 1 号房屋 (金额 = 1) ,然后偷窃 3 号房屋 (金额 = 3)。
偷窃到的最高金额 = 1 +... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,650 | leetcode | MIT License |
src/Day11_part2.kt | armandmgt | 573,595,523 | false | {"Kotlin": 47774} | fun main() {
data class Monkey(
val id: Int,
var inspections: Long = 0,
val divisor: Long,
val items: MutableList<Long>,
val operation: (Long, Long) -> Long,
val destination: (Long) -> Int
) {
override fun equals(other: Any?): Boolean {
if (thi... | 0 | Kotlin | 0 | 1 | 0d63a5974dd65a88e99a70e04243512a8f286145 | 4,455 | advent_of_code_2022 | Apache License 2.0 |
src/test/kotlin/be/brammeerten/y2023/Day8Other2Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2023
import be.brammeerten.extractRegexGroups
import be.brammeerten.readFile
import be.brammeerten.toCharList
import org.junit.jupiter.api.Test
class Day8Other2Test {
@Test
fun `part 2`() {
val lines = readFile("2023/day8/input.txt")
val instructions = lines[0].toChar... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 2,683 | Advent-of-Code | MIT License |
src/main/kotlin/com/anahoret/aoc2022/day04/main.kt | mikhalchenko-alexander | 584,735,440 | false | null | package com.anahoret.aoc2022.day04
import java.io.File
private fun parseRange(str: String): IntRange {
val (min, max) = str.split("-").map(String::toInt)
return IntRange(min, max)
}
private fun parsePair(str: String): Pair<IntRange, IntRange> {
val (first, second) = str.split(",")
.map(::parseRan... | 0 | Kotlin | 0 | 0 | b8f30b055f8ca9360faf0baf854e4a3f31615081 | 1,080 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem875/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem875
/**
* LeetCode page: [875. Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/);
*/
class Solution {
/* Complexity:
* Time O(NLogM) and Space O(1) where N is the size of piles and M is the largest value in piles;
*/
fun minEatingSpeed(pi... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,298 | hj-leetcode-kotlin | Apache License 2.0 |
year2016/src/main/kotlin/net/olegg/aoc/year2016/day4/Day4.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2016.day4
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2016.DayOf2016
/**
* See [Year 2016, Day 4](https://adventofcode.com/2016/day/4)
*/
object Day4 : DayOf2016(4) {
private val ROOM_PATTERN = "^(.+)-(\\d+)\\[(.+)]$".toRegex()
private const val A_CODE = 'a'.code
o... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,428 | adventofcode | MIT License |
src/Day04.kt | iam-afk | 572,941,009 | false | {"Kotlin": 33272} | fun main() {
fun part1(input: List<String>): Int =
input.map { it.split(',', '-').map(String::toInt) }
.count { (p1, q1, p2, q2) -> p1 <= p2 && q2 <= q1 || p2 <= p1 && q1 <= q2 }
fun part2(input: List<String>): Int =
input.map { it.split(',', '-').map(String::toInt) }
.... | 0 | Kotlin | 0 | 0 | b30c48f7941eedd4a820d8e1ee5f83598789667b | 645 | aockt | Apache License 2.0 |
src/main/kotlin/io/github/mikaojk/day2/part1/day2Part1.kt | MikAoJk | 573,000,620 | false | {"Kotlin": 15562} | package io.github.mikaojk.day2.part1
import io.github.mikaojk.common.getFileAsString
fun day2Part1(): Int {
val opponent = Player(score = 0)
val you = Player(score = 0)
val game = getFileAsString("src/main/resources/day2/game.txt")
val rounds = game.split("\\n".toRegex()).map { round ->
Roun... | 0 | Kotlin | 0 | 0 | eaa90abc6f64fd42291ab42a03478a3758568ecf | 2,367 | aoc2022 | MIT License |
AtCoder/abc209/D.kt | thedevelopersanjeev | 112,687,950 | false | null | private fun readLn() = readLine() ?: ""
private fun readLns() = readLn().split(" ")
private fun readInts() = readLns().map { it.toInt() }
private const val MAXN = 100005
private const val LOG = 20
private var adj = Array(MAXN) { ArrayList<Int>() }
private var depth = Array(MAXN) { 0 }
private var up = Array(MAXN) { Ar... | 0 | C++ | 58 | 146 | 610520cc396fb13a03c606b5fb6739cfd68cc444 | 1,459 | Competitive-Programming | MIT License |
src/main/kotlin/o9referenzdatentypen/Fraction.kt | lm41 | 636,474,764 | false | null | package o9referenzdatentypen
/**
* Programmieren Trainieren Seite 192
* W.9.2 <NAME>
*
* Erweitert um [Fraction.divide] und weitere helper wie [Fraction.shorten] und [Fraction.gcd]
* */
fun main() {
val a = Fraction(numerator = 1, denominator = 2)
val b = Fraction(numerator = 1, denominator = 4)
val... | 0 | Kotlin | 0 | 0 | bba220a34daed25dc5baa9a844ca54f3b8564390 | 3,849 | pro-train-kotlin | MIT License |
src/leetcodeProblem/leetcode/editor/en/RemoveDuplicatesFromSortedListIi.kt | faniabdullah | 382,893,751 | false | null | //Given the head of a sorted linked list, delete all nodes that have duplicate
//numbers, leaving only distinct numbers from the original list. Return the linked
//list sorted as well.
//
//
// Example 1:
//
//
//Input: head = [1,2,3,3,4,4,5]
//Output: [1,2,5]
//
//
// Example 2:
//
//
//Input: head = [1,1,1,2,... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 1,911 | dsa-kotlin | MIT License |
src/Day2/Day2.kt | tomashavlicek | 571,148,506 | false | {"Kotlin": 3033} | package Day2
import readInput
fun main() {
data class Operation(val operation: String, val amount: Int)
fun part1(input: List<String>): Int {
var horizontalPosition = 0
var depth = 0
val operations = input.map { it.split(' ') }.map { Operation(operation = it[0], amount = it[1].toInt(... | 0 | Kotlin | 0 | 0 | 52f7febaacaab3ee9809899d21077fecac39c13b | 1,508 | aoc-2021-in-kotlin | Apache License 2.0 |
src/Day05.kt | JonasDBB | 573,382,821 | false | {"Kotlin": 17550} | import java.util.Stack
private fun setupStacks(input: List<String>): MutableList<Stack<Char>> {
val listLineI = input.indexOfFirst { it[1] == '1' }
var nrOfStacks = input[listLineI].count { !it.isWhitespace() }
// this only works until 99 stacks, but input only goes to 9 anyway so w/e
if (nrOfStacks > ... | 0 | Kotlin | 0 | 0 | 199303ae86f294bdcb2f50b73e0f33dca3a3ac0a | 2,193 | AoC2022 | Apache License 2.0 |
src/chapter5/section2/ex10_Size.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter5.section2
import chapter5.section1.Alphabet
import edu.princeton.cs.algs4.Queue
/**
* size()方法
* 为TrieST和TST实现最为即时的size()方法(在每个结点中保存子树中的键的总数)
*
* 解:参考二叉查找树的实现[chapter3.section2.BinarySearchTree]
*/
class InstantTrieST<V : Any>(private val alphabet: Alphabet) : StringST<V> {
private inner cla... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 11,634 | Algorithms-4th-Edition-in-Kotlin | MIT License |
code/day_13/src/jvm8Main/kotlin/task1.kt | dhakehurst | 725,945,024 | false | {"Kotlin": 105846} | package day_13
import korlibs.datastructure.getCyclicOrNull
data class Size(
val cols: Int,
val rows: Int
)
class Grid<T>(
/**
* list of rows
*/
val lines: List<List<T>>
) {
val size get() = Size(lines[0].size, lines.size)
fun getOrNull(x: Int, y: Int): T? = lines.getOrNull(y)?.get... | 0 | Kotlin | 0 | 0 | be416bd89ac375d49649e7fce68c074f8c4e912e | 3,699 | advent-of-code | Apache License 2.0 |
archive/2022/Day01.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | package aoc2022
fun main() {
fun part1(input: List<String>): Int {
var sum = 0
var max = 0
for (line in input) {
if (line.trim().isEmpty()) {
max = max.coerceAtLeast(sum)
sum = 0
} else {
sum += line.toInt()
... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 1,123 | advent-of-code-2022 | Apache License 2.0 |
src/commonMain/kotlin/advent2020/day13/Day13Puzzle.kt | jakubgwozdz | 312,526,719 | false | null | package advent2020.day13
fun part1(input: String): String {
val ts = input.trim().lines()[0].toInt()
val wait = buses(input).map { it to it - ts % it }.minByOrNull { it.second }!!
return (wait.first * wait.second).toString()
}
fun part2(input: String): String {
var multiple = 1L
var result = 0L
... | 0 | Kotlin | 0 | 2 | e233824109515fc4a667ad03e32de630d936838e | 815 | advent-of-code-2020 | MIT License |
src/Year2021Day03.kt | zhangt2333 | 575,260,256 | false | {"Kotlin": 34993} | // https://github.com/Mistborn94/advent-of-code-2021/blob/main/src/main/kotlin/day3/Day3.kt
fun main() {
fun bitmask(size: Int) = 2.pow(size) - 1
fun part1(lines: List<String>): Int {
val gamma = lines
.map { it.toList().map(Char::digitToInt) }
.reduce { l1, l2 -> l1.zip(l2, Int... | 0 | Kotlin | 0 | 0 | cdba887c4df3a63c224d5a80073bcad12786ac71 | 1,294 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/java/challenges/educative_grokking_coding_interview/top_k_elements/_1/KthLargest.kt | ShabanKamell | 342,007,920 | false | null | package challenges.educative_grokking_coding_interview.top_k_elements._1
import java.util.*
/**
Given an infinite stream of integers (sorted or unsorted), nums, design a class to find the kth
largest element in a stream.
Note: It is the kth largest element in the sorted order, not the kth distinct element.
The class... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 2,801 | CodingChallenges | Apache License 2.0 |
implementation/src/main/kotlin/io/github/tomplum/aoc/display/DisplayAnalyser.kt | TomPlum | 431,391,240 | false | {"Kotlin": 114607} | package io.github.tomplum.aoc.display
import io.github.tomplum.aoc.display.DisplayValues.*
class DisplayAnalyser(data: List<String>) {
private val entries = data.map { entry ->
val values = entry.trim().split(" | ")
val signalPatterns = SignalPatterns(values[0].trim().split(" "))
val outpu... | 0 | Kotlin | 0 | 0 | cccb15593378d0bb623117144f5b4eece264596d | 2,698 | advent-of-code-2021 | Apache License 2.0 |
src/Day01.kt | rifkinni | 573,123,064 | false | {"Kotlin": 33155, "Shell": 125} | import java.util.Collections.max
class Day01 {
fun parseSupplies(input: List<String>): List<Int> {
return input.joinToString(",").split(",,").map { collection ->
collection.split(",").map { num -> Integer.parseInt(num) }.sum()
}
}
}
fun main() {
fun part1(input: List<String>): ... | 0 | Kotlin | 0 | 0 | c2f8ca8447c9663c0ce3efbec8e57070d90a8996 | 871 | 2022-advent | Apache License 2.0 |
app/src/main/java/com/betulnecanli/kotlindatastructuresalgorithms/SortingAlgorithms/MergeSort/MergeSort.kt | betulnecanli | 568,477,911 | false | {"Kotlin": 167849} | package com.betulnecanli.kotlindatastructuresalgorithms.SortingAlgorithms.MergeSort
//Merge sort is one of the most efficient sorting algorithms. With a time complexity of
//O(n log n), it’s one of the fastest of all general-purpose sorting algorithms. The idea
//behind merge sort is divide and conquer — t... | 2 | Kotlin | 2 | 40 | 70a4a311f0c57928a32d7b4d795f98db3bdbeb02 | 3,027 | Kotlin-Data-Structures-Algorithms | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem662/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem662
import com.hj.leetcode.kotlin.common.model.TreeNode
/**
* LeetCode page: [662. Maximum Width of Binary Tree](https://leetcode.com/problems/maximum-width-of-binary-tree/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(N) where N is the number of nodes i... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,392 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/aoc2015/Day06.kt | w8mr | 572,700,604 | false | {"Kotlin": 140954} | package aoc2015
import aoc.parser.Parsers.eol
import aoc.parser.Parsers.number
import aoc.parser.and
import aoc.parser.asParser
import aoc.parser.oneOrMore
import aoc.parser.seq
class Day06 {
enum class Instruction(val text: String) {
On("turn on"),
Off("turn off"),
Toggle("toggle")
}
... | 0 | Kotlin | 0 | 0 | e9bd07770ccf8949f718a02db8d09daf5804273d | 1,900 | aoc-kotlin | Apache License 2.0 |
advent-of-code-2022/src/main/kotlin/year_2022/Day03.kt | rudii1410 | 575,662,325 | false | {"Kotlin": 37749} | package year_2022
import util.Runner
fun main() {
fun getCharScore(ch: Char) = if (ch.isUpperCase()) (ch - 'A' + 1) + 26 else (ch - 'a' + 1)
fun MutableMap<Char, Int>.addScore(key: Char) {
this[key] = this.getOrDefault(key, 0) + 1
}
fun MutableMap<Char, Int>.calculate(minimum: Int): Int {
... | 1 | Kotlin | 0 | 0 | ab63e6cd53746e68713ddfffd65dd25408d5d488 | 1,260 | advent-of-code | Apache License 2.0 |
src/Day01.kt | kuolemax | 573,740,719 | false | {"Kotlin": 21104} | fun main() {
fun countPerCalories(input: List<String>): MutableList<Int> {
val arr = mutableListOf<Int>()
var index = 0
var newStart = 0
val lines = input.iterator()
while (lines.hasNext()) {
val next = lines.next()
if (next.isNotBlank()) {
... | 0 | Kotlin | 0 | 0 | 3045f307e24b6ca557b84dac18197334b8a8a9bf | 1,302 | aoc2022--kotlin | Apache License 2.0 |
src/main/kotlin/days/Day13.kt | mir47 | 318,882,845 | false | null | package days
class Day13 : Day(13) {
private val schedule = inputList[1].split(',').map { if (it == "x") -1 else it.toInt() }
override fun partOne(): Any {
val arrival = inputList[0].toInt()
val result = schedule
.filter { it != -1 }
.map { Pair(it, arrival + it - (arr... | 0 | Kotlin | 0 | 0 | 4c15e214f7164523f04d4b741102a279c38e2072 | 1,782 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/Day14.kt | iownthegame | 573,926,504 | false | {"Kotlin": 68002} | import kotlin.math.max
import kotlin.math.min
class RockLine(val fromPoint: Position, val toPoint: Position)
fun main() {
fun parseMap(input: List<String>, extendsFloor: Boolean): Array<Array<Char>> {
val rockLines = mutableListOf<RockLine>()
var maxX: Int = 0
var maxY: Int = 0
fo... | 0 | Kotlin | 0 | 0 | 4e3d0d698669b598c639ca504d43cf8a62e30b5c | 7,412 | advent-of-code-2022 | Apache License 2.0 |
semestr.06/ТРСиПВ/bellman/src/main/kotlin/bellman/graph/algorithm/plainBellmanFord.kt | justnero | 43,222,066 | false | null | package bellman.graph.algorithm
import bellman.graph.INFINITE
import bellman.graph.InputGraph
import bellman.graph.PlainAdjacency
import bellman.graph.PlainAdjacencyList
import bellman.graph.Util.AdjacencyMatrixUtil.toPlainAdjacencyList
import bellman.graph.Util.PlainAdjacencyListUtil.edgeNumber
import bellman.graph.U... | 0 | Java | 6 | 16 | 14f58f135e57475b98826c4128b2b880b6a2cb9a | 1,746 | university | MIT License |
2023/src/main/kotlin/net/daams/solutions/8b.kt | Michiel-Daams | 573,040,288 | false | {"Kotlin": 39925, "Nim": 34690} | package net.daams.solutions
import net.daams.Solution
class `8b`(input: String): Solution(input) {
override fun run() {
val splitInput = input.split("\n")
val directions = splitInput.first()
val elements = splitInput.subList(2, splitInput.size).map { Element(it.split(" = ")[0]) }
... | 0 | Kotlin | 0 | 0 | f7b2e020f23ec0e5ecaeb97885f6521f7a903238 | 1,771 | advent-of-code | MIT License |
src/Day08.kt | maewCP | 579,203,172 | false | {"Kotlin": 59412} | fun main() {
val verbose = false
fun part1(input: List<String>): Int {
var result = 0
val trees = mutableListOf<MutableList<Pair<Int, Boolean>>>()
input.forEach { line ->
val treeRow = mutableListOf<Pair<Int, Boolean>>()
line.toList().forEach { height ->
... | 0 | Kotlin | 0 | 0 | 8924a6d913e2c15876c52acd2e1dc986cd162693 | 4,351 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/leetcode/dynamic/word_break/WordBreak.kt | Pawlllosss | 526,668,214 | false | {"Kotlin": 61939} | package leetcode.dynamic.word_break
import trie.structure.Trie
fun main() {
println(wordBreak("leetcode", listOf("leet", "code")))
println(wordBreakWithTrie("leetcode", listOf("leet", "code")))
}
fun wordBreak(s: String, wordDict: List<String>): Boolean {
val wordBreakMatch = BooleanArray(s.length)
... | 0 | Kotlin | 0 | 0 | 94ad00ca3e3e8ab7a2cb46f8846196ae7c55c8b4 | 1,615 | Kotlin-algorithms | MIT License |
tasks-3/lib/src/main/kotlin/flows/algo/Scaling.kt | AzimMuradov | 472,473,231 | false | {"Kotlin": 127576} | package flows.algo
import flows.structures.Matrix
import flows.structures.Network
import kotlin.math.*
/**
* The Flow Scaling Algorithm.
*/
public fun <V> Network<V>.calculateMaxflowByScaling(): UInt {
var maxflow = 0u
val residualNetworkCapacities = Matrix.empty(keys = graph.vertices, noValue = 0u).apply ... | 0 | Kotlin | 0 | 0 | 01c0c46df9dc32c2cc6d3efc48b3a9ee880ce799 | 1,870 | discrete-math-spbu | Apache License 2.0 |
src/Day01.kt | mlidal | 572,869,919 | false | {"Kotlin": 20582} | fun main() {
fun part1(input: List<String>): Int {
val calories = mutableListOf<Int>()
var calorieSum = 0
input.forEach {
if (it.isNotBlank()) {
calorieSum += it.toInt()
} else {
calories.add(calorieSum)
calorieSum = 0
... | 0 | Kotlin | 0 | 0 | bea7801ed5398dcf86a82b633a011397a154a53d | 1,136 | AdventOfCode2022 | Apache License 2.0 |
src/Day17.kt | simonbirt | 574,137,905 | false | {"Kotlin": 45762} | import kotlin.math.min
fun main() {
Day17.printSolutionIfTest(3068, 56000011)
}
object Day17: Day<Long, Long>(17) {
private fun <T> Sequence<T>.repeat() = sequence { while (true) yieldAll(this@repeat) }
private val shapes = listOf(
"####",
"""
.#.
###
... | 0 | Kotlin | 0 | 0 | 962eccac0ab5fc11c86396fc5427e9a30c7cd5fd | 5,932 | advent-of-code-2022 | Apache License 2.0 |
ASCII Text Signature/task/test/Authors.kt | Perl99 | 273,730,854 | false | null | import java.util.*
private class Letter(
val rows: List<String>
) {
init {
if (rows.distinctBy { it.length }.size != 1) {
throw IllegalStateException("Bad letter. Not equal width in lines: ${rows.distinctBy { it.length }}")
}
}
val width get() = rows[0].length
val h... | 0 | Kotlin | 0 | 0 | 4afb085918697c41a5722f50e8a7bb65fcab0854 | 2,569 | hyperskill-kotlin-ascii-text-signature | MIT License |
src/year2022/day12/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2022.day12
import io.kotest.matchers.shouldBe
import utils.MapDetails
import utils.detailsSequence
import utils.findShortestRoute
import utils.readInput
fun main() {
val testInput = readInput("12", "test_input").map(String::toList)
val realInput = readInput("12", "input").map(String::toList)
... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 2,166 | Advent-of-Code | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/UniquePaths.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 | 4,982 | kotlab | Apache License 2.0 |
src/Day01.kt | Kbzinho-66 | 572,299,619 | false | {"Kotlin": 34500} | fun main() {
fun part1(calories: List<Int>): Int {
return calories[0]
}
fun part2(calories: List<Int>): Int {
return calories.slice(0..2).sum()
}
fun getCalories(input: List<String>): List<Int> {
var carried = 0
val caloriesPerElf: MutableList<Int> = mutableListOf()... | 0 | Kotlin | 0 | 0 | e7ce3ba9b56c44aa4404229b94a422fc62ca2a2b | 1,197 | advent_of_code_2022_kotlin | Apache License 2.0 |
kotlin/0662-maximum-width-of-binary-tree.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | /**
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree node.
* class TreeNode(var `val`: Int) {
* var left: TreeNode? = null
* var right: TreeNode? = null
* }
*/
/*
* BFS solution
*/
class Solution {
fun widthOfBinaryTree(root: TreeNode?): Int {
root?: retu... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,623 | leetcode | MIT License |
src/main/kotlin/com/sk/topicWise/tree/medium/2385. Amount of Time for Binary Tree to Be Infected.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.topicWise.tree.medium
import com.sk.topicWise.tree.TreeNode
import kotlin.collections.ArrayDeque
import kotlin.collections.HashMap
class Solution2385 {
fun amountOfTime(root: TreeNode?, start: Int): Int {
var amount = 0
// if subtree does not contain infected node, return maximum ... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 3,372 | leetcode-kotlin | Apache License 2.0 |
src/main/java/me/olegthelilfix/leetcoding/old/IntegerToRoman.kt | olegthelilfix | 300,408,727 | false | null | package me.olegthelilfix.leetcoding.old
data class RomanNumber(val letter: String, val value: Int)
val numberOrder : List<RomanNumber> = listOf(
RomanNumber("M", 1000),
RomanNumber("CM", 900),
RomanNumber("D", 500),
RomanNumber("CD", 400),
RomanNumber("C", 100),
RomanNu... | 0 | Kotlin | 0 | 0 | bf17d2f6915b7a491d93f57f8e7461adda7029c0 | 1,880 | MyKata | MIT License |
src/test/kotlin/nl/dirkgroot/adventofcode/year2022/Day16Test.kt | dirkgroot | 317,968,017 | false | {"Kotlin": 187862} | package nl.dirkgroot.adventofcode.year2022
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import nl.dirkgroot.adventofcode.util.input
import nl.dirkgroot.adventofcode.util.invokedWith
import java.util.*
private fun solution1(input: String) = parse(input).maxPressureRelease()
private fu... | 1 | Kotlin | 1 | 1 | ffdffedc8659aa3deea3216d6a9a1fd4e02ec128 | 5,145 | adventofcode-kotlin | MIT License |
src/main/kotlin/d11/D11_1.kt | MTender | 734,007,442 | false | {"Kotlin": 108628} | package d11
import input.Input
import kotlin.math.abs
fun expandUniverse(universe: List<String>): List<String> {
var expanded = universe.map { "" }.toMutableList()
// expand columns
for (colI in universe[0].indices) {
val col = universe.map { it[colI] }.joinToString("")
expanded = if (col... | 0 | Kotlin | 0 | 0 | a6eec4168b4a98b73d4496c9d610854a0165dbeb | 1,332 | aoc2023-kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LongestIncreasingSubsequence.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,568 | kotlab | Apache License 2.0 |
src/questions/CousinsBinaryTree.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import questions.common.TreeNode
import utils.shouldBe
/**
* Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y,
* return true if the nodes corresponding to the values x and y in the tree are cousins,... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,965 | algorithms | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2021/Day05.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2021
import se.saidaspen.aoc.util.Day
import se.saidaspen.aoc.util.P
import se.saidaspen.aoc.util.ints
import kotlin.math.sign
fun main() = Day05.run()
object Day05 : Day(2021, 5) {
val lines = input.lines().map { ints(it) }.map { P(P(it[0], it[1]), P(it[2], it[3])) }
override f... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,118 | adventofkotlin | MIT License |
src/aoc2022/day10/Day10.kt | svilen-ivanov | 572,637,864 | false | {"Kotlin": 53827} | package aoc2022.day10
import readInput
import kotlin.math.abs
fun main() {
fun part1(input: List<String>) {
var x = 1
val valByCycle = mutableListOf(x)
for (line in input) {
val commandLine = line.split(" ")
val commandName = commandLine[0]
val arg = if ... | 0 | Kotlin | 0 | 0 | 456bedb4d1082890d78490d3b730b2bb45913fe9 | 2,413 | aoc-2022 | Apache License 2.0 |
src/Day21.kt | janbina | 112,736,606 | false | null | package Day21
import getInput
import kotlin.test.assertEquals
fun main(args: Array<String>) {
val input = getInput(21)
.readLines()
.map { it.split(" => ").map { it.split('/').map { it.toCharArray() }.toTypedArray() } }
.map { Enhancements.Enhancement(it[0], it[1]) }
... | 0 | Kotlin | 0 | 0 | 71b34484825e1ec3f1b3174325c16fee33a13a65 | 3,845 | advent-of-code-2017 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaximumBags.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,417 | kotlab | Apache License 2.0 |
src/main/kotlin/com/kishor/kotlin/algo/problems/arrayandstrings/GroupAnagrams.kt | kishorsutar | 276,212,164 | false | null | package com.kishor.kotlin.algo.problems.arrayandstrings
import java.util.*
import kotlin.collections.ArrayList
fun main() {
// groupAnagrams()
println("${groupAnagrams(arrayOf( "eat", "tea", "tan", "ate", "nat", "bat"))}")
// groupAnagramsTes(arrayOf( "eat", "tea", "tan", "ate", "nat", "bat"))
}
/*fun gro... | 0 | Kotlin | 0 | 0 | 6672d7738b035202ece6f148fde05867f6d4d94c | 1,505 | DS_Algo_Kotlin | MIT License |
kotlin/numeric/KaratsubaMultiply.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package numeric
import java.util.Arrays
// https://en.wikipedia.org/wiki/Karatsuba_algorithm
object KaratsubaMultiply {
fun karatsubaMultiply(a: IntArray, b: IntArray): IntArray {
var a = a
var b = b
if (a.size < b.size) a = Arrays.copyOf(a, b.size)
if (a.size > b.size) b = Arrays.... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,666 | codelibrary | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ImageSmoother.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 | 6,051 | kotlab | Apache License 2.0 |
day2/src/main/kotlin/com/lillicoder/adventofcode2023/day2/Day2.kt | lillicoder | 731,776,788 | false | {"Kotlin": 98872} | package com.lillicoder.adventofcode2023.day2
fun main() {
val day2 = Day2()
val games = GameParser().parse("input.txt")
println("The sum of all valid game IDs is ${day2.part1(games)}.")
println("The sum of all minimum cubes powers is ${day2.part2(games)}.")
}
class Day2() {
fun part1(games: List<G... | 0 | Kotlin | 0 | 0 | 390f804a3da7e9d2e5747ef29299a6ad42c8d877 | 5,532 | advent-of-code-2023 | Apache License 2.0 |
src/Day01.kt | HylkeB | 573,815,567 | false | {"Kotlin": 83982} | fun main() {
fun getSortedCaloriesPerElf(input: List<String>): List<Int> {
return input.fold(mutableListOf(0)) { acc, cur ->
if (cur.isBlank()) {
acc.add(0)
} else {
acc[acc.lastIndex] += cur.toInt()
}
acc
}.sortedDescen... | 0 | Kotlin | 0 | 0 | 8649209f4b1264f51b07212ef08fa8ca5c7d465b | 867 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/thesis/utils/unification.kt | danilkolikov | 123,672,959 | false | null | /**
* Unification algorithm for type inference
*
* @author <NAME>
*/
package thesis.utils
import thesis.preprocess.expressions.algebraic.term.AlgebraicEquation
import thesis.preprocess.expressions.algebraic.term.AlgebraicTerm
/**
* Solves system of algebraic equations
*/
fun solveSystem(system: List<Algebraic... | 0 | Kotlin | 0 | 2 | 0f5ad2d9fdd1f03d3bf62255da14b05e4e0289e1 | 2,992 | fnn | MIT License |
src/main/kotlin/com/rtarita/days/Day5.kt | RaphaelTarita | 724,581,070 | false | {"Kotlin": 64943} | package com.rtarita.days
import com.rtarita.structure.AoCDay
import com.rtarita.util.day
import kotlinx.datetime.LocalDate
object Day5 : AoCDay {
private data class MapTriple(
val destStart: Long,
val origStart: Long,
val rangeSize: Long
) {
val origRange: LongRange
... | 0 | Kotlin | 0 | 0 | 4691126d970ab0d5034239949bd399c8692f3bb1 | 2,667 | AoC-2023 | Apache License 2.0 |
src/main/kotlin/io/queue/DecodeString.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.queue
import java.util.*
import kotlin.math.pow
class DecodeString {
fun execute(input: String): String {
val stack = Stack<String>()
input.map { it.toString() }.map { char ->
when {
char == "[" -> stack.push(char)
char == "]" -> pushOrAdd(stack, generateValue(stack))
... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,945 | coding | MIT License |
src/main/kotlin/Day7.kt | Mestru | 112,782,719 | false | null | import java.io.File
import kotlin.math.abs
data class Program(var weight: Int, var parent: String?, var children: List<String>?)
val programs = HashMap<String, Program>()
fun main(args: Array<String>) {
// part 1
val lineRegex = "(\\w+) \\((\\d+)\\)( -> )?(.+)?".toRegex()
var name: String
var weight... | 0 | Kotlin | 0 | 0 | 2cc4211efc7fa32fb951c19d11cb4a452bfeec2c | 2,119 | Advent_of_Code_2017 | MIT License |
data_structures/y_fast_trie/Kotlin/YFastTrie.kt | ZoranPandovski | 93,438,176 | false | {"Jupyter Notebook": 21909905, "C++": 1692994, "Python": 1158220, "Java": 806066, "C": 560110, "JavaScript": 305918, "Go": 145277, "C#": 117882, "PHP": 85458, "Kotlin": 72238, "Rust": 53852, "Ruby": 43243, "MATLAB": 34672, "Swift": 31023, "Processing": 22089, "HTML": 18961, "Haskell": 14298, "Dart": 11842, "CSS": 10509... | /**
* Y-fast trie is a data structure for storing integers from a bounded domain
* It supports exact and predecessor or successor queries in time O(log log M), using O(n) space,
* where n is the number of stored values and M is the maximum value in the domain.
* More info about the structure and complexity here: h... | 62 | Jupyter Notebook | 1,994 | 1,298 | 62a1a543b8f3e2ca1280bf50fc8a95896ef69d63 | 7,046 | al-go-rithms | Creative Commons Zero v1.0 Universal |
kotlin/src/main/kotlin/io/github/piszmog/aoc/Day4.kt | Piszmog | 433,651,411 | false | null | package io.github.piszmog.aoc
import java.time.Instant
fun main(args: Array<String>) {
val start = Instant.now()
val reader = getFileReader(args[0])
var row = 0
var numLines = ""
val boardLines = mutableListOf<String>()
reader.lines().forEach {
if (row == 0) {
numLines = it... | 0 | Rust | 0 | 0 | a155cb7644017863c703e97f22c8338ccb5ef544 | 3,397 | aoc-2021 | MIT License |
src/Day22.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | import kotlin.math.max
import kotlin.math.min
private const val EXPECTED_1 = 5
private const val EXPECTED_2 = 7
data class Brick(val coord: MutableList<Int>, val size: MutableList<Int>) {
fun maxFall(other: Brick): Int {
if (other.coord[2] > coord[2]) {
return Int.MAX_VALUE
}
... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 4,365 | advent-of-code-2022 | Apache License 2.0 |
day07/src/main/kotlin/Day07.kt | bzabor | 160,240,195 | false | null | class Day07(private val input: List<String>) {
private val possibleNexts = mutableSetOf<Node>()
private val path = mutableListOf<Node>()
private val nodeMap = mutableMapOf<Char, Node>()
fun part1(): String {
buildNodeMap()
possibleNexts.addAll(nodeMap.values.filter { it.required.size =... | 0 | Kotlin | 0 | 0 | 14382957d43a250886e264a01dd199c5b3e60edb | 3,821 | AdventOfCode2018 | Apache License 2.0 |
src/Day21p2.kt | Riaz1 | 577,017,303 | false | {"Kotlin": 15653} | fun main() {
data class LineItem(
val operand1: String,
val operator: String,
val operand2: String,
var result: Double?,
var result1: Double?,
var result2: Double?,
var parent: String?
)
fun getPathFromRoot(key: String, steps: Map<String, LineItem>): ... | 0 | Kotlin | 0 | 0 | 4d742e404ece13203319e1923ffc8e1f248a8e15 | 5,023 | aoc2022 | Apache License 2.0 |
src/Day08.kt | kenyee | 573,186,108 | false | {"Kotlin": 57550} | import java.util.concurrent.atomic.AtomicInteger
fun main() { // ktlint-disable filename
fun sumInnerTreesInDirection(
visible: Array<Array<Boolean>>,
array: List<String>,
dir: Direction,
row: Int,
col: Int
): Int {
val numRows = array.size
val numCols = ... | 0 | Kotlin | 0 | 0 | 814f08b314ae0cbf8e5ae842a8ba82ca2171809d | 7,761 | KotlinAdventOfCode2022 | Apache License 2.0 |
app/src/main/kotlin/com/resurtm/aoc2023/day04/Solution.kt | resurtm | 726,078,755 | false | {"Kotlin": 119665} | package com.resurtm.aoc2023.day04
import kotlin.math.pow
private fun parseNums(rawNums: String): Set<Int> =
rawNums.trim().split(" ").map { it.trim() }.filter { it.isNotEmpty() }.map { it.toInt() }.toSet()
private fun parseLine(line: String): ParseLineResult {
val parts1 = line.split(":")
val parts2 = pa... | 0 | Kotlin | 0 | 0 | fb8da6c246b0e2ffadb046401502f945a82cfed9 | 1,560 | advent-of-code-2023 | MIT License |
11.kts | pin2t | 725,922,444 | false | {"Kotlin": 48856, "Go": 48364, "Shell": 54} | import java.util.*
import kotlin.math.abs
data class Galaxy(var col: Long, var row: Long) {
fun distance(other: Galaxy): Long = abs(this.row - other.row) + abs(this.col - other.col)
}
val scanner = Scanner(System.`in`)
val galaxies = ArrayList<Galaxy>()
var rows: Long = 0
while (scanner.hasNext()) {
scanner.ne... | 0 | Kotlin | 1 | 0 | 7575ab03cdadcd581acabd0b603a6f999119bbb6 | 1,142 | aoc2023 | MIT License |
src/Day03_part2.kt | yashpalrawat | 573,264,560 | false | {"Kotlin": 12474} | fun main() {
val input = readInput("Day03")
val priorities = getPriorities()
val result = (input.indices step 3).sumOf {
val firstElevRuksPack = input[it]
val secondElevRuksPack = input[it + 1]
val thirdElevRuksPack = input[it + 2]
priorities[findCommanCharacter(firstElevR... | 0 | Kotlin | 0 | 0 | 78a3a817709da6689b810a244b128a46a539511a | 904 | code-advent-2022 | Apache License 2.0 |
src/main/kotlin/day08/day08.kt | andrew-suprun | 725,670,189 | false | {"Kotlin": 18354, "Python": 17857, "Dart": 8224} | package day08
import java.io.File
data class Targets(val left: String, val right: String)
fun main() {
run(start = { it == "AAA" }, end = { it == "ZZZ" })
run(start = { it.endsWith('A') }, end = { it.endsWith('Z') })
}
fun run(start: (String) -> Boolean, end: (String) -> Boolean) {
val lines = File("inp... | 0 | Kotlin | 0 | 0 | dd5f53e74e59ab0cab71ce7c53975695518cdbde | 1,575 | AoC-2023 | The Unlicense |
src/main/kotlin/com/github/davio/aoc/general/Math.kt | Davio | 317,510,947 | false | {"Kotlin": 405939} | package com.github.davio.aoc.general
import kotlin.math.*
val Int.squared get() = this * this
val Long.squared get() = this * this
val Int.sqrt get() = sqrt(this.toDouble())
val Long.sqrt get() = sqrt(this.toDouble())
fun Double.roundUp() = ceil(this).toLong()
fun Double.roundDown() = this.toLong()
fun gcd(n1: Int, ... | 1 | Kotlin | 0 | 0 | 4fafd2b0a88f2f54aa478570301ed55f9649d8f3 | 1,276 | advent-of-code | MIT License |
src/main/kotlin/charizard/Engine.kt | mohakapt | 677,036,849 | false | null | package charizard
/**
* Calculates the final evaluation of the given board.
* This is a recursive function, it calls itself to evaluate the board after each possible move.
* To use it for the first time, you should call it with the default parameters.
*
* @param board The board to evaluate.
* @param alpha The be... | 0 | Kotlin | 0 | 2 | fd67f349b9bb33c15b4bdd48d9d1fef76dd35ed8 | 3,061 | Minimax | MIT License |
src/main/kotlin/solved/p581/Solution.kt | mr-nothing | 469,475,608 | false | {"Kotlin": 162430} | package solved.p581
class Solution {
class SortingApproach {
// The idea is to sort initial array and compare both arrays from the start and from the end.
// The index of first element from the:
// - start that is not equal is the lower bound of the subsequence
// - end that if not ... | 0 | Kotlin | 0 | 0 | 0f7418ecc8675d8361ef31cbc1ee26ea51f7708a | 3,114 | leetcode | Apache License 2.0 |
src/Day12.kt | shepard8 | 573,449,602 | false | {"Kotlin": 73637} | fun main() {
fun part1(heights: List<List<Char>>) {
val chars = listOf(' ','╶','╷','┌','╴','─','┐','┬','╵','└','│','├','┘','┴','┤','┼')
heights.forEachIndexed { y, line -> line.forEachIndexed { x, c ->
val leftAllowed = heights[y].getOrElse(x - 1) { 'z' + 2 } <= c + 1
val rig... | 0 | Kotlin | 0 | 1 | 81382d722718efcffdda9b76df1a4ea4e1491b3c | 1,036 | aoc2022-kotlin | Apache License 2.0 |
solutions/aockt/y2022/Y2022D04.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2022
import io.github.jadarma.aockt.core.Solution
object Y2022D04 : Solution {
private val inputRegex = Regex("""^(\d+)-(\d+),(\d+)-(\d+)$""")
/** Parses the [input] and returns the list of elf cleanup section assignments. */
private fun parseInput(input: String): List<Pair<IntRange, IntR... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 1,473 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaximumAverageSubarray1.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,592 | kotlab | Apache License 2.0 |
leetcode2/src/leetcode/kth-smallest-element-in-a-bst.kt | hewking | 68,515,222 | false | null | package leetcode
import leetcode.structure.TreeNode
/**
* 230. 二叉搜索树中第K小的元素
* https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/
* Created by test
* Date 2019/9/30 19:18
* Description
* 给定一个二叉搜索树,编写一个函数 kthSmallest 来查找其中第 k 个最小的元素。
说明:
你可以假设 k 总是有效的,1 ≤ k ≤ 二叉搜索树元素个数。
示例 1:
输入: root = [3,1,4,nul... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,448 | leetcode | MIT License |
src/Day11.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | import kotlin.math.abs
fun main() {
val input = readInput("Day11")
val (n, m) = input.size to input[0].length
val expandY = input.map { line -> line.all { it=='.' } }
val expandX = (0 until m).map { j -> input.all { it[j] == '.' } }
fun countExpand(x1: Int, x2: Int, expandX: List<Boolean>): Int {
... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 1,072 | advent-of-code-kotlin | Apache License 2.0 |
src/nativeMain/kotlin/xyz/justinhorton/aoc2022/Day08.kt | justinhorton | 573,614,839 | false | {"Kotlin": 39759, "Shell": 611} | package xyz.justinhorton.aoc2022
import kotlin.math.abs
/**
* https://adventofcode.com/2022/day/8
*/
class Day08(override val input: String) : Day() {
override fun part1(): String {
val grid = Grid.fromChars(input) { it.digitToInt() }
return grid.enumeratePoints()
.count { (x, y) -> ... | 0 | Kotlin | 0 | 1 | bf5dd4b7df78d7357291c7ed8b90d1721de89e59 | 1,691 | adventofcode2022 | MIT License |
src/main/kotlin/ru/spbstu/kparsec/examples/tip/constraint/Equalities.kt | vorpal-research | 115,148,080 | false | null | package ru.spbstu.kparsec.examples.tip.constraint
import java.util.*
sealed class Node {
abstract operator fun contains(v: Node): Boolean
}
data class Var(val id: String = dict[currentId].also { ++currentId }) : Node() {
override fun contains(v: Node): Boolean = v == this
override fun toString() = id
... | 0 | Kotlin | 0 | 0 | 3238c73af7bb4269176dac57b51614b1402313e5 | 3,400 | kparsec | MIT License |
src/aoc2022/Day03.kt | NoMoor | 571,730,615 | false | {"Kotlin": 101800} | package aoc2022
import utils.*
internal class Day03(lines: List<String>) {
init { lines.forEach { println(it) } }
private val lines = lines
.map {
val s = it.length / 2
listOf(it.toList().subList(0, s), it.toList().subList(s, it.length))
}.map {
it[0].intersect(it[1]).first()
}.map ... | 0 | Kotlin | 1 | 2 | d561db73c98d2d82e7e4bc6ef35b599f98b3e333 | 1,198 | aoc2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.