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/Day22.kt | gijs-pennings | 573,023,936 | false | {"Kotlin": 20319} | private lateinit var nodes: List<List<Node>>
private val w get() = nodes.size
private val h get() = nodes[0].size
fun main() {
val lines = readInput(22)
val map = lines.dropLast(2)
val path = lines.last()
nodes = List(map.maxOf { it.length }) { x ->
List(map.size) { y ->
Node(FullP... | 0 | Kotlin | 0 | 0 | 8ffbcae744b62e36150af7ea9115e351f10e71c1 | 4,779 | aoc-2022 | ISC License |
src/main/kotlin/year2022/Day09.kt | simpor | 572,200,851 | false | {"Kotlin": 80923} | import kotlin.math.absoluteValue
class Day09 {
fun parse(input: String): List<Pair<String, Int>> = input.lines().map { l ->
val s = l.split(" ")
Pair(s[0], s[1].toInt())
}
fun moveFunction(move: String): (Point) -> Point = when (move) {
"U" -> { pos: Point -> pos.copy(y = pos.y +... | 0 | Kotlin | 0 | 0 | 631cbd22ca7bdfc8a5218c306402c19efd65330b | 4,297 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/io/undefined/AccountMerge.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.undefined
import io.utils.runTests
// https://leetcode.com/problems/accounts-merge/
class AccountMerge {
fun execute(input: List<List<String>>): List<List<String>> {
val information = input.mapIndexed { index, list -> index to (list.first() to list.subList(1, list.size).toMutableSet()) }.toMap().to... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,714 | coding | MIT License |
stepik/sportprogramming/ScheduleGreedyAlgorithm.kt | grine4ka | 183,575,046 | false | {"Kotlin": 98723, "Java": 28857, "C++": 4529} | package stepik.sportprogramming
private const val MAX_DAYS = 5000
private val used: BooleanArray = BooleanArray(MAX_DAYS) { false }
private val orders = mutableListOf<Order>()
fun main() {
val n = readInt()
repeat(n) {
orders.add(readOrder())
}
val sortedByDeadlineOrders = orders.sortedDescen... | 0 | Kotlin | 0 | 0 | c967e89058772ee2322cb05fb0d892bd39047f47 | 1,078 | samokatas | MIT License |
codeforces/round901/d_ok_but_should_be_wa.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.round901
private fun solve(): Double {
val (n, m) = readInts()
val d = List(n + 1) { DoubleArray(m - n + 1) }
for (i in 1..n) {
var kBest = 0
for (s in d[i].indices) {
val range = maxOf(kBest - 5, 0)..minOf(kBest + 11, s)
var best = Double.MAX_VALUE
for (k in range) {
val new = (... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 636 | competitions | The Unlicense |
src/aoc2022/Day11.kt | FluxCapacitor2 | 573,641,929 | false | {"Kotlin": 56956} | package aoc2022
import Day
import splitOn
object Day11 : Day(2022, 11) {
private val monkeys = mutableListOf<Monkey>()
data class Monkey(
val items: MutableList<Long>,
val operation: (Long) -> Long,
val test: (Long) -> Boolean,
val ifTrue: Int,
val ifFalse: Int,
... | 0 | Kotlin | 0 | 0 | a48d13763db7684ee9f9129ee84cb2f2f02a6ce4 | 4,824 | advent-of-code-2022 | Apache License 2.0 |
src/day17/Day17.kt | Volifter | 572,720,551 | false | {"Kotlin": 65483} | package day17
import utils.*
const val WIDTH = 7
val ROCKS = listOf(
Rock(
Coords(0, 0),
Coords(1, 0),
Coords(2, 0),
Coords(3, 0)
),
Rock(
Coords(1, 0),
Coords(0, -1),
Coords(1, -1),
Coords(2, -1),
Coords(1, -2)
),
Rock(
... | 0 | Kotlin | 0 | 0 | c2c386844c09087c3eac4b66ee675d0a95bc8ccc | 4,818 | AOC-2022-Kotlin | Apache License 2.0 |
Array/cuijilin/Array.kt | JessonYue | 268,215,243 | false | null | package luge
/*167. 两数之和 II - 输入有序数组*/
/*给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数。
函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2。
说明:
返回的下标值(index1 和 index2)不是从零开始的。
你可以假设每个输入只对应唯一的答案,而且你不可以重复使用相同的元素。
示例:
输入: numbers = [2, 7, 11, 15], target = 9
输出: [1,2]
解释: 2 与 7 之和等于目标数 9 。因此 index1 = 1, index2 = 2 。*/
priv... | 0 | C | 19 | 39 | 3c22a4fcdfe8b47f9f64b939c8b27742c4e30b79 | 2,729 | LeetCodeLearning | MIT License |
app/src/main/java/com/betulnecanli/kotlindatastructuresalgorithms/CodingPatterns/CyclicSort.kt | betulnecanli | 568,477,911 | false | {"Kotlin": 167849} | /*
The Cyclic Sort pattern is used to solve problems where the goal is to sort an array of numbers in a specific range
or find the missing or duplicate number in a range. Let's tackle a simple problem:
"Find the Missing Number in a Consecutive Array." I'll provide a Kotlin implementation for it.
Usage: Use this tech... | 2 | Kotlin | 2 | 40 | 70a4a311f0c57928a32d7b4d795f98db3bdbeb02 | 3,915 | Kotlin-Data-Structures-Algorithms | Apache License 2.0 |
src/main/kotlin/day15_chiton_risk/ChitonRisk.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package day15_chiton_risk
import geom2d.Point
import geom2d.Rect
import geom2d.asLinearOffset
import java.util.*
/**
* 2D plane again. "You start... your destination" means a graph walk. "Lowest
* total risk" means an optimization problem. The wrinkle is that the
* optimization needs to be integrated into the walk... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 3,900 | aoc-2021 | MIT License |
src/main/kotlin/net/dinkla/raytracerchallenge/math/Tuple.kt | jdinkla | 325,043,782 | false | {"Kotlin": 127433, "Gherkin": 74260} | package net.dinkla.raytracerchallenge.math
import net.dinkla.raytracerchallenge.math.Approx.isDifferenceSmall
import java.util.Objects
import kotlin.math.sqrt
typealias Vector = Tuple
typealias Point = Tuple
data class Tuple(val x: Double, val y: Double, val z: Double, val w: Double) {
fun isPoint(): Boolean = w... | 0 | Kotlin | 0 | 1 | 0cf1a977250e6ea9e725fab005623e7a627ad29e | 2,406 | ray-tracer-challenge | MIT License |
kotlin/0743-network-delay-time.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 {
//times[i] == [source, target, weight]
fun networkDelayTime(times: Array<IntArray>, n: Int, k: Int): Int {
val adjList = ArrayList<ArrayList<Pair<Int,Int>>>(times.size)
for(i in 0..n)
adjList.add(ArrayList<Pair<Int,Int>>())
for(time in times){
val... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,305 | leetcode | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SubarraysDivByK.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,814 | kotlab | Apache License 2.0 |
src/main/kotlin/coursework/sorting/MergeSort.kt | Whitedrawn | 674,729,151 | false | null | package coursework.sorting
import coursework.database.BOOK
object MergeSort {
var tick = 0
fun sort(scrambled: ArrayList<BOOK>): Pair<ArrayList<BOOK>, Int> {
tick = 0
val res = ArrayList(scrambled)
if (scrambled.size <= 1)
return Pair(res, tick)
else {
... | 0 | Kotlin | 0 | 0 | 502e68f30238331152fa4950f2003bcf93080bac | 2,788 | JavaLibrary | MIT License |
src/main/kotlin/Day22.kt | dlew | 75,886,947 | false | null | import java.util.*
import java.util.regex.Pattern
class Day22 {
data class Coord(val x: Int, val y: Int)
data class Node(val x: Int, val y: Int, val size: Int, val used: Int, val avail: Int)
companion object {
private val NODE_PATTERN =
Pattern.compile("/dev/grid/node-x(\\d+)-y(\\d+)\\s+(\\d+)T\\s... | 0 | Kotlin | 2 | 12 | 527e6f509e677520d7a8b8ee99f2ae74fc2e3ecd | 3,988 | aoc-2016 | MIT License |
2023/src/day04/Day04.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day04
import java.io.File
import kotlin.math.pow
fun main() {
val input = File("src/day04/Day04.txt").readLines()
val scratchers = Pile(input)
println(scratchers.getPointValue())
println(scratchers.getCardCount())
}
val SPACE = Regex("\\s+")
class Pile(input: List<String>) {
private val... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 2,237 | adventofcode | Apache License 2.0 |
aoc-2018/src/main/kotlin/nl/jstege/adventofcode/aoc2018/days/Day04.kt | JStege1206 | 92,714,900 | false | null | package nl.jstege.adventofcode.aoc2018.days
import nl.jstege.adventofcode.aoccommon.days.Day
import nl.jstege.adventofcode.aoccommon.utils.extensions.extractValues
class Day04 : Day(title = "Repose Record") {
companion object Configuration {
private const val INPUT_PATTERN_STRING =
"""\[(\d{4}... | 0 | Kotlin | 0 | 0 | d48f7f98c4c5c59e2a2dfff42a68ac2a78b1e025 | 2,316 | AdventOfCode | MIT License |
src/Day06.kt | Advice-Dog | 436,116,275 | true | {"Kotlin": 25836} | fun main() {
fun getLanternfishCount(input: List<String>, days: Int): Long {
val fishCount = mutableListOf<Long>()
for (i in 0 until 9) {
fishCount.add(0)
}
val list = input.first().split(",").map { it.toInt() }
list.forEach {
fishCount[it]++
... | 0 | Kotlin | 0 | 0 | 2a2a4767e7f0976dba548d039be148074dce85ce | 1,388 | advent-of-code-kotlin-template | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2017/Day25.kt | tginsberg | 112,672,087 | false | null | /*
* Copyright (c) 2017 by <NAME>
*/
package com.ginsberg.advent2017
/**
* AoC 2017, Day 25
*
* Problem Description: http://adventofcode.com/2017/day/25
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2017/day25/
*/
class Day25(input: List<String>) {
private val machine = parseInput(... | 0 | Kotlin | 0 | 15 | a57219e75ff9412292319b71827b35023f709036 | 1,951 | advent-2017-kotlin | MIT License |
src/Day10.kt | brunojensen | 572,665,994 | false | {"Kotlin": 13161} | private val strings = readInput("Day10.test")
fun main() {
fun sumSixSignalStrengths(cycle : Int, register : Int) =
if(cycle % 40 == 20) cycle * register else 0
fun part1(input: List<String>): Long {
var cycle = 0
var sumSixSignalStrengths = 0L
var register = 1
input.forEach {
sumSixSi... | 0 | Kotlin | 0 | 0 | 2707e76f5abd96c9d59c782e7122427fc6fdaad1 | 898 | advent-of-code-kotlin-1 | Apache License 2.0 |
leetcode2/src/leetcode/RotateArray.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* 189. 旋转数组
* https://leetcode-cn.com/problems/rotate-array/
* Created by test
* Date 2019/6/7 1:29
* Description
* 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
示例 1:
输入: [1,2,3,4,5,6,7] 和 k = 3
输出: [5,6,7,1,2,3,4]
解释:
向右旋转 1 步: [7,1,2,3,4,5,6]
向右旋转 2 步: [6,7,1,2,3,4,5]
向右旋转 3 步: [5,6,7,1,2,3,4]
示例... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,848 | leetcode | MIT License |
src/test/kotlin/ch/ranil/aoc/aoc2023/Day15.kt | stravag | 572,872,641 | false | {"Kotlin": 234222} | package ch.ranil.aoc.aoc2023
import ch.ranil.aoc.AbstractDay
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
class Day15 : AbstractDay() {
@Test
fun part1TestHash() {
assertEquals(52, hash("HASH"))
}
@Test
fun part1Test() {
assertEquals(1320, compute1(testInput)... | 0 | Kotlin | 1 | 0 | dbd25877071cbb015f8da161afb30cf1968249a8 | 2,218 | aoc | Apache License 2.0 |
2023/2/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 kotlin.text.Regex
import java.io.File
data class Round(
val reds: Int = 0,
val greens: Int = 0,
val blues: Int = 0,
)
data class Game(
val id: Int,
val rounds: List<Round>,
)
val games = File("input").readLines().map { line ->
val matchedGameId = Regex("Game ([0-9]+):").matchAt(line, 0... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 1,222 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/endredeak/aoc2022/Day05.kt | edeak | 571,891,076 | false | {"Kotlin": 44975} | package endredeak.aoc2022
fun main() {
solve("Supply Stacks") {
val regex = Regex("move (\\d+) from (\\d+) to (\\d+)")
data class Move(val size: Int, val from: Int, val to: Int)
fun input() = run {
val stackLines = lines.filter { it.contains("[") }
val ops = lines.... | 0 | Kotlin | 0 | 0 | e0b95e35c98b15d2b479b28f8548d8c8ac457e3a | 1,888 | AdventOfCode2022 | Do What The F*ck You Want To Public License |
app/src/main/java/pt/eandrade/leetcodedaily/problems/LowestCommonAncestorBinarySearchTree.kt | eandrade-dev | 513,632,885 | false | {"Kotlin": 27612} | package pt.eandrade.leetcodedaily.problems
import pt.eandrade.leetcodedaily.misc.IsProblem
import pt.eandrade.leetcodedaily.misc.Utils.Companion.TreeNode
import pt.eandrade.leetcodedaily.misc.Utils.Companion.printTree
class LowestCommonAncestorBinarySearchTree : IsProblem {
override fun run() : String {
v... | 0 | Kotlin | 0 | 0 | a60190869baf120db377359de89a15531e77749c | 2,124 | leetcode-daily | Apache License 2.0 |
leetcode/src/offer/Offer42.kt | zhangweizhe | 387,808,774 | false | null | package offer
fun main() {
// https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/
// 剑指 Offer 42. 连续子数组的最大和
println(maxSubArray2(intArrayOf(1,2,3,-2,3,4)))
}
private fun maxSubArray(nums: IntArray): Int {
val tmp = IntArray(nums.size)
tmp[0] = nums[0]
var max = nums[0]
... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,318 | kotlin-study | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SortVowels.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,035 | kotlab | Apache License 2.0 |
src/Day01.kt | hrach | 572,585,537 | false | {"Kotlin": 32838} | fun main() {
fun part1(input: List<String>): Int {
val groups = mutableListOf<List<Int>>()
var group = mutableListOf<Int>()
input.forEach {
if (it.isBlank()) group = mutableListOf<Int>().also { groups.add(it) }
else group.add(it.toInt())
}
return groups.maxOf { it.sum() }
}
fun part2(input: List<Str... | 0 | Kotlin | 0 | 1 | 40b341a527060c23ff44ebfe9a7e5443f76eadf3 | 760 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | eo | 574,058,285 | false | {"Kotlin": 45178} | // https://adventofcode.com/2022/day/3
fun main() {
fun itemPriority(item: Char) = if (item.isLowerCase()) {
item - 'a' + 1
} else {
item - 'A' + 27
}
fun part1(input: List<String>): Int {
return input
.map { it.chunked(it.length / 2).map(String::toSet) }
... | 0 | Kotlin | 0 | 0 | 8661e4c380b45c19e6ecd590d657c9c396f72a05 | 880 | aoc-2022-in-kotlin | Apache License 2.0 |
advent-of-code-2020/src/main/kotlin/eu/janvdb/aoc2020/day20/Day20.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2020.day20
import eu.janvdb.aocutil.kotlin.readGroupedLines
val MONSTER = Picture(
listOf(
" # ",
"# ## ## ###",
" # # # # # # "
)
)
fun main() {
val tiles = readGroupedLines(2020, "input20.txt").map(::MapTile)
val topLeftCorner = getTopLeftCorner(tile... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,650 | advent-of-code | Apache License 2.0 |
src/main/kotlin/day7.kt | gautemo | 572,204,209 | false | {"Kotlin": 78294} | import shared.getText
fun main() {
val input = getText("day7.txt")
println(day7A(input))
println(day7B(input))
}
fun day7A(input: String): Int {
val rootDir = getRootDir(input)
return rootDir.allDirs().sumOf {
if(it.getSize() <= 100000) it.getSize() else 0
}
}
fun day7B(input: String)... | 0 | Kotlin | 0 | 0 | bce9feec3923a1bac1843a6e34598c7b81679726 | 1,712 | AdventOfCode2022 | MIT License |
src/main/kotlin/me/consuegra/algorithms/KSymmetricBinaryTree.kt | aconsuegra | 91,884,046 | false | {"Java": 113554, "Kotlin": 79568} | package me.consuegra.algorithms
import me.consuegra.datastructure.KBinaryTreeNode
/**
* Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
* Example :
*
* 1
* / \
* 2 2
* / \ / \
* 3 4 4 3
*
* The above binary tree is symmetric.
* But the following ... | 0 | Java | 0 | 7 | 7be2cbb64fe52c9990b209cae21859e54f16171b | 1,649 | algorithms-playground | MIT License |
src/Day14/Day14.kt | AllePilli | 572,859,920 | false | {"Kotlin": 47397} | package Day14
import TerminalUtils
import checkAndPrint
import measureAndPrintTimeMillis
import minMaxRange
import readInput
import kotlin.math.max
import kotlin.math.min
fun main() {
val showAnimationInTerminal = false
val startPosition = 500 to 0
fun List<String>.prepareInput() = flatMap { line ->
... | 0 | Kotlin | 0 | 0 | 614d0ca9cc925cf1f6cfba21bf7dc80ba24e6643 | 5,282 | AdventOfCode2022 | Apache License 2.0 |
y2016/src/main/kotlin/adventofcode/y2016/Day07.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2016
import adventofcode.io.AdventSolution
object Day07 : AdventSolution(2016, 7, "Internet Protocol Version 7") {
override fun solvePartOne(input: String) = input.lineSequence().count(::isValidTLS).toString()
override fun solvePartTwo(input: String) = input.lineSequence().count(::isValidSSL)... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,238 | advent-of-code | MIT License |
kotlin/problems/src/solution/DFSPrograms.kt | lunabox | 86,097,633 | false | {"Kotlin": 146671, "Python": 38767, "JavaScript": 19188, "Java": 13966} | package solution
import com.sun.org.apache.xpath.internal.operations.Bool
class DFSPrograms {
/**
* https://leetcode-cn.com/problems/number-of-islands/
*/
fun numIslands(grid: Array<CharArray>): Int {
var ans = 0
grid.forEachIndexed { i, chars ->
chars.forEachIndexed { j,... | 0 | Kotlin | 0 | 0 | cbb2e3ad8f2d05d7cc54a865265561a0e391a9b9 | 1,628 | leetcode | Apache License 2.0 |
src/main/kotlin/com/groundsfam/advent/y2023/d16/Day16.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2023.d16
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.Direction
import com.groundsfam.advent.Direction.DOWN
import com.groundsfam.advent.Direction.LEFT
import com.groundsfam.advent.Direction.RIGHT
import com.groundsfam.advent.Direction.UP
import com.groundsfam.adven... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 3,507 | advent-of-code | MIT License |
src/main/kotlin/day15/RecursivePathfinder.kt | Ostkontentitan | 434,500,914 | false | {"Kotlin": 73563} | package day15
class RecursivePathfinder : Pathfinder {
override fun searchOptimalPath(
map: Array<Array<Int>>
): Int {
val destination = CavePosition(map.lastIndex, map.first().lastIndex, map.last().last())
val start = CavePosition(0, 0, map[0][0])
val bestForPosition: Array<Arr... | 0 | Kotlin | 0 | 0 | e0e5022238747e4b934cac0f6235b92831ca8ac7 | 3,996 | advent-of-kotlin-2021 | Apache License 2.0 |
codeforces/vk2022/round1/f.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.vk2022.round1
fun main() {
val (n, qIn) = readInts()
val pOpenClose = qIn / 10_000.toModular()
val one = 1.toModular()
val pCloseOpen = one - pOpenClose
val cnk = List(n + 1) { i -> Array(i + 1) { one } }
for (i in cnk.indices) {
for (j in 1 until i) {
cnk[i][j] = cnk[i - 1][j - 1] + cnk... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 2,347 | competitions | The Unlicense |
src/main/kotlin/com/hj/leetcode/kotlin/problem1406/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1406
/**
* LeetCode page: [1406. Stone Game III](https://leetcode.com/problems/stone-game-iii/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(1) where N is the size of stoneValue;
*/
fun stoneGameIII(stoneValue: IntArray): String {
val (al... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,917 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day01/Day01.kt | emillourens | 572,599,575 | false | {"Kotlin": 32933} | fun main() {
fun part1(input: List<String>): Int {
var calories = 0
var counter = 1
var elfWithTheLargestCal = 0
var prevLargest = 0
for (item in input)
{
if(item == "")
{
counter++
calories = 0
con... | 0 | Kotlin | 0 | 0 | 1f9739b73ef080b012e505e0a4dfe88f928e893d | 1,412 | AoC2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/Allocator.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 | 5,066 | kotlab | Apache License 2.0 |
src/main/kotlin/at/mpichler/aoc/solutions/year2022/Day15.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2022
import at.mpichler.aoc.lib.Day
import at.mpichler.aoc.lib.Order
import at.mpichler.aoc.lib.PartSolution
import at.mpichler.aoc.lib.Vector2i
import java.lang.IllegalStateException
import kotlin.math.absoluteValue
open class Part15A : PartSolution() {
lateinit var sensors:... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 3,867 | advent-of-code-kotlin | MIT License |
src/Day06.kt | KliminV | 573,758,839 | false | {"Kotlin": 19586} | fun main() {
fun part1(input: String): Int {
return firstOccurrenceNDistinctChars(input, 4)
}
fun part2(input: String): Int {
return firstOccurrenceNDistinctChars(input, 14)
}
// test if implementation meets criteria from the description, like:
val testInput = read("Day06_test")
... | 0 | Kotlin | 0 | 0 | 542991741cf37481515900894480304d52a989ae | 880 | AOC-2022-in-kotlin | Apache License 2.0 |
src/Day01.kt | graesj | 572,651,121 | false | {"Kotlin": 10264} | fun main() {
fun part1(input: List<String>): Int {
return input
.map { it.toIntOrNull() }
.runningFold(0) { acc, calories ->
calories?.let {
acc + it
} ?: 0
}.max()
}
fun part2(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | df7f855a14c532f3af7a8dc86bd159e349cf59a6 | 854 | aoc-2022 | Apache License 2.0 |
src/Day05.kt | EdoFanuel | 575,561,680 | false | {"Kotlin": 80963} | import java.util.*
fun main() {
val stacks = Array<Stack<Char>>(9) { Stack() }
stacks[0] += "TDWZVP".toList()
stacks[1] += "LSWVFJD".toList()
stacks[2] += "ZMLSVTBH".toList()
stacks[3] += "RSJ".toList()
stacks[4] += "CZBGFMLW".toList()
stacks[5] += "QVWHZRGB".toList()
stacks[6] += "VJPC... | 0 | Kotlin | 0 | 0 | 46a776181e5c9ade0b5e88aa3c918f29b1659b4c | 1,492 | Advent-Of-Code-2022 | Apache License 2.0 |
src/main/kotlin/year2023/day01/Problem.kt | Ddxcv98 | 573,823,241 | false | {"Kotlin": 154634} | package year2023.day01
import IProblem
import java.util.NoSuchElementException
class Problem : IProblem {
private val map = mapOf(
"1" to 1,
"2" to 2,
"3" to 3,
"4" to 4,
"5" to 5,
"6" to 6,
"7" to 7,
"8" to 8,
"9" to 9,
"one" to 1,
... | 0 | Kotlin | 0 | 0 | 455bc8a69527c6c2f20362945b73bdee496ace41 | 1,816 | advent-of-code | The Unlicense |
src/main/kotlin/days/Day13Data.kt | yigitozgumus | 572,855,908 | false | {"Kotlin": 26037} | package days
import utils.SolutionData
import utils.Utils
fun main() = with(Day13Data()) {
println(" --- Part 1 --- ")
solvePart1()
println(" --- Part 2 --- ")
solvePart2()
}
class Day13Data: SolutionData(inputFile = "inputs/day13.txt") {
val pairs = rawData
.windowed(size = 2, step=3)
.map { (left... | 0 | Kotlin | 0 | 0 | 9a3654b6d1d455aed49d018d9aa02d37c57c8946 | 829 | AdventOfCode2022 | MIT License |
src/main/kotlin/g1001_1100/s1020_number_of_enclaves/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1001_1100.s1020_number_of_enclaves
// #Medium #Array #Depth_First_Search #Breadth_First_Search #Matrix #Union_Find
// #Graph_Theory_I_Day_3_Matrix_Related_Problems
// #2023_05_21_Time_369_ms_(76.26%)_Space_90.3_MB_(16.91%)
class Solution {
fun numEnclaves(grid: Array<IntArray>): Int {
val visited... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,306 | LeetCode-in-Kotlin | MIT License |
src/day4/main.kt | rafagalan | 573,145,902 | false | {"Kotlin": 5674} | package day4
import readInput
fun parseInput(input: String) =
input
.split(",", "-")
.windowed(2, 2) {(lowerBound, upperBound) ->
IntArray(upperBound.toInt() - lowerBound.toInt() + 1) { it + lowerBound.toInt() }.toSet()
}
fun main() {
fun part1(input: List<String>) =
... | 0 | Kotlin | 0 | 0 | 8e7d3f25fe52a4153479adb56c5924b50f6c0be9 | 1,071 | AdventOfCode2022 | Apache License 2.0 |
src/Day15_2.kt | jrmacgill | 573,065,109 | false | {"Kotlin": 76362} | import utils.*
class Day15_2 {
val ranges = mutableMapOf<Point, Int>()
fun contained(min : Point, max : Point) : Boolean {
ranges.forEach{
val dist = it.value
if (it.key.manhattanDistanceTo(min) <= dist && it.key.manhattanDistanceTo(max) <=dist && it.key.manhattanDistanceTo(P... | 0 | Kotlin | 0 | 1 | 3dcd590f971b6e9c064b444139d6442df034355b | 2,135 | aoc-2022-kotlin | Apache License 2.0 |
Kotlin for Java Developers. Week 4/Rationals/Task/src/rationals/Rational.kt | binout | 159,054,839 | false | null | package rationals
import java.math.BigInteger
class Rational(private val numerator: BigInteger,
private val denominator: BigInteger = BigInteger.ONE)
: Comparable<Rational> {
init {
require(denominator != BigInteger.ZERO)
}
operator fun unaryMinus(): Rational = Rational(-nume... | 0 | Kotlin | 1 | 5 | 40ff182f63d29443fa3c29730560d37e2325501a | 3,540 | coursera-kotlin | Apache License 2.0 |
src/main/kotlin/dec6/Main.kt | dladukedev | 318,188,745 | false | null | package dec6
fun chunkInput(input: String): List<String> {
return input.split(Regex("\\n\\n"))
}
fun getCharactersFromChunk(chunk: String): List<List<Char>> {
return chunk.lines()
.map { it.trim() }
.map { it.toCharArray().toTypedArray().toList() }
.filter { it.isNotEmpty() }
}
fun ge... | 0 | Kotlin | 0 | 0 | d4591312ddd1586dec6acecd285ac311db176f45 | 1,457 | advent-of-code-2020 | MIT License |
solutions/aockt/y2015/Y2015D19.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2015
import io.github.jadarma.aockt.core.Solution
object Y2015D19 : Solution {
/** Returns all the possible transformations the machine can do. */
private fun parseInput(input: List<String>): List<Pair<String, String>> =
input.dropLast(2).map {
val (first, second) = it.spli... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 2,466 | advent-of-code-kotlin-solutions | The Unlicense |
kotlin/src/com/daily/algothrim/leetcode/medium/FourSum.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode.medium
/**
* 18. 四数之和
*/
class FourSum {
companion object {
@JvmStatic
fun main(args: Array<String>) {
FourSum().fourSum(intArrayOf(1, 0, -1, 0, -2, 2), 0).forEach {
it.forEach { i ->
print(i)
}... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,438 | daily_algorithm | Apache License 2.0 |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[32]最长有效括号.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.util.*
//给你一个只包含 '(' 和 ')' 的字符串,找出最长有效(格式正确且连续)括号子串的长度。
//
//
//
//
//
// 示例 1:
//
//
//输入:s = "(()"
//输出:2
//解释:最长有效括号子串是 "()"
//
//
// 示例 2:
//
//
//输入:s = ")()())"
//输出:4
//解释:最长有效括号子串是 "()()"
//
//
// 示例 3:
//
//
//输入:s = ""
//输出:0
//
//
//
//
// 提示:
//
//
// 0 <= s.length <= 3 * 104
//... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,476 | MyLeetCode | Apache License 2.0 |
src/main/kotlin/us/jwf/aoc2021/Day18Snailfish.kt | jasonwyatt | 433,743,675 | false | {"Kotlin": 49932} |
fun main() {
val data = readInputFile("day18")
fun part1(): Int {
val sum = data
.map { Snailfish.parse(it).populateParents() }
.reduce { accumulator, value -> accumulator + value }
return sum.magnitude
}
fun part2(): Int {
val numbers = data.toList()
... | 0 | Kotlin | 0 | 0 | 6d4f19df3b7cb1906052b80a4058fa394a12740f | 5,876 | AdventOfCode-Kotlin | Apache License 2.0 |
src/main/kotlin/algorithms/StringAlgorithms.kt | AgentKnopf | 240,955,745 | false | null | package algorithms
/**
* Two strings are an anagram of each other, if they contain the same letters, the same number of times,
* possibly in a different order.
* @return true if the given strings are anagrams of each other, ignoring capitalization; false otherwise.
*/
internal fun isAnagram(left: String, right: S... | 0 | Kotlin | 1 | 0 | 5367ce67e54633e53b2b951c2534bf7b2315c2d8 | 5,236 | technical-interview | MIT License |
src/AOC2022/Day10/Day10.kt | kfbower | 573,519,224 | false | {"Kotlin": 44562} | package AOC2022.Day10
import AOC2022.readInput
fun main(){
/* addx V takes two cycles to complete. After two cycles, the X register is increased by the value V. (V can be negative.)
noop takes one cycle to complete. It has no other effect.*/
/*signal strength (the cycle number multiplied by the value of... | 0 | Kotlin | 0 | 0 | 48a7c563ebee77e44685569d356a05e8695ae36c | 4,947 | advent-of-code-2022 | Apache License 2.0 |
app/src/test/java/online/vapcom/codewars/algorithms/SkyScraperTests.kt | vapcomm | 503,057,535 | false | {"Kotlin": 142486} | package online.vapcom.codewars.algorithms
import online.vapcom.codewars.algorithms.Skyscrapers.getVisibleFromEnd
import online.vapcom.codewars.algorithms.Skyscrapers.getVisibleFromStart
import online.vapcom.codewars.algorithms.Skyscrapers.packPermutationToInt
import online.vapcom.codewars.algorithms.Skyscrapers.permut... | 0 | Kotlin | 0 | 0 | 97b50e8e25211f43ccd49bcee2395c4bc942a37a | 3,352 | codewars | MIT License |
src/automaton/FiniteStateMachine.kt | q-lang | 128,704,097 | false | null | package automaton
import graph.NonDeterministicGraph
import graph.SimpleGraph
data class FiniteStateMachine<STATE, SYMBOL>(
val nfaStart: STATE,
val nfa: NonDeterministicGraph<STATE, SYMBOL?>,
val groups: Map<String, Group<STATE>>
) : Automaton<STATE, SYMBOL> {
// Deterministic Finite Autom... | 0 | Kotlin | 1 | 0 | 2d8a8b4d32ae8ec5b8ed9cce099bd58f37838833 | 2,074 | q-lang | MIT License |
src/Day10.kt | lonskiTomasz | 573,032,074 | false | {"Kotlin": 22055} | fun main() {
fun part1(input: List<String>): Int {
var cycle = 0
var x = 1
var sum = 0
fun cycle() {
cycle += 1
if (cycle in listOf(20, 60, 100, 140, 180, 220)) sum += x * cycle
}
input.forEach { line ->
when {
lin... | 0 | Kotlin | 0 | 0 | 9e758788759515049df48fb4b0bced424fb87a30 | 1,358 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/tools/manhattan.kt | verwoerd | 224,986,977 | false | null | package tools
import kotlin.math.abs
/**
* @author verwoerd
* @since 3-12-2019
*/
data class Coordinate(val x: Int, val y: Int) : Comparable<Coordinate> {
override fun compareTo(other: Coordinate): Int = when (val result = y.compareTo(other.y)) {
0 -> x.compareTo(other.x)
else -> result
}
operator f... | 0 | Kotlin | 0 | 0 | 554377cc4cf56cdb770ba0b49ddcf2c991d5d0b7 | 1,822 | AoC2019 | MIT License |
advent2022/src/main/kotlin/year2022/Day21.kt | bulldog98 | 572,838,866 | false | {"Kotlin": 132847} | package year2022
import AdventDay
typealias ValueNumber = Long
private fun String.toValueNumber(): ValueNumber = toLong()
class Day21 : AdventDay(2022, 21) {
enum class HumanPosition {
NONE,
LEFT,
RIGHT
}
enum class MathOperation(
val separator: String,
val computa... | 0 | Kotlin | 0 | 0 | 02ce17f15aa78e953a480f1de7aa4821b55b8977 | 6,656 | advent-of-code | Apache License 2.0 |
jvm/src/main/kotlin/io/prfxn/aoc2021/day17.kt | prfxn | 435,386,161 | false | {"Kotlin": 72820, "Python": 362} | // Trick Shot (https://adventofcode.com/2021/day/17)
package io.prfxn.aoc2021
import kotlin.math.max
fun main() {
val (targetXRange, targetYRange) =
"-?\\d+".toRegex().findAll(textResourceReader("input/17.txt").readText())
.map { it.value.toInt() }
.let {
val (x1... | 0 | Kotlin | 0 | 0 | 148938cab8656d3fbfdfe6c68256fa5ba3b47b90 | 1,553 | aoc2021 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/Nqueens2.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,062 | kotlab | Apache License 2.0 |
src/com/kingsleyadio/adventofcode/y2021/day07/Alternative.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2021.day07
import com.kingsleyadio.adventofcode.util.readInput
fun part1(input: List<Int>): Int {
val min = input.minOrNull()!!
val max = input.maxOrNull()!!
val plane = IntArray(max - min + 1)
for (value in input) plane[value - min]++
val aligningForward = ... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 981 | adventofcode | Apache License 2.0 |
src/Day01.kt | jsebasct | 572,954,137 | false | {"Kotlin": 29119} | fun main() {
fun part1(input: List<String>): Int {
val caloriesElf = mutableListOf<Int>()
var sum = 0
for (calorie in input) {
if (calorie != "") {
sum += calorie.toInt()
} else {
caloriesElf.add(sum)
sum = 0
... | 0 | Kotlin | 0 | 0 | c4a587d9d98d02b9520a9697d6fc269509b32220 | 1,099 | aoc2022 | Apache License 2.0 |
year2023/day11/part2/src/main/kotlin/com/curtislb/adventofcode/year2023/day11/part2/Year2023Day11Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Part Two ---
The galaxies are much older (and thus much farther apart) than the researcher initially estimated.
Now, instead of the expansion you did before, make each empty row or column one million times
larger. That is, each empty row should be replaced with 1000000 empty rows, and each empty column
should ... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 1,628 | AdventOfCode | MIT License |
src/main/kotlin/at/mpichler/aoc/solutions/year2022/Day02.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2022
import at.mpichler.aoc.lib.Day
import at.mpichler.aoc.lib.PartSolution
open class Part2A : PartSolution() {
private lateinit var rounds: List<String>
internal open val table = mapOf(
"AX" to 4,
"AY" to 8,
"AZ" to 3,
"BX" to 1,
... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 1,058 | advent-of-code-kotlin | MIT License |
advent-of-code-2019/src/test/java/Day3CrossedWired.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | import org.assertj.core.api.Assertions.assertThat
import org.junit.Ignore
import org.junit.Test
import kotlin.math.absoluteValue
class Day3CrossedWired {
val testInput = listOf(
Triple(
"R8,U5,L5,D3",
"U7,R6,D4,L4", 6
),
Triple(
"R75,D30,R83,U83,L12,D49,R... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 6,515 | advent-of-code | MIT License |
src/main/kotlin/com/ginsberg/advent2016/Day15.kt | tginsberg | 74,924,040 | false | null | /*
* Copyright (c) 2016 by <NAME>
*/
package com.ginsberg.advent2016
/**
* Advent of Code - Day 15: December 15, 2016
*
* From http://adventofcode.com/2016/day/15
*
*/
class Day15(input: List<String>) {
companion object {
val DISC_REGEX = Regex("""Disc #(\d+) has (\d+) positions; at time=0, it is ... | 0 | Kotlin | 0 | 3 | a486b60e1c0f76242b95dd37b51dfa1d50e6b321 | 1,206 | advent-2016-kotlin | MIT License |
dataStructuresAndAlgorithms/src/main/java/com/crazylegend/datastructuresandalgorithms/graphs/djikstra/Dijkstra.kt | ch8n | 379,267,678 | true | {"Kotlin": 1841146} | package com.crazylegend.datastructuresandalgorithms.graphs.djikstra
import com.crazylegend.datastructuresandalgorithms.graphs.Edge
import com.crazylegend.datastructuresandalgorithms.graphs.Vertex
import com.crazylegend.datastructuresandalgorithms.graphs.adjacency.AdjacencyList
import com.crazylegend.datastructuresanda... | 0 | Kotlin | 0 | 1 | 815cc480758a6119d60d5e0b5ccd78ee03fdb73e | 2,754 | Set-Of-Useful-Kotlin-Extensions-and-Helpers | MIT License |
src/Day01.kt | kenyee | 573,186,108 | false | {"Kotlin": 57550} |
fun main() { // ktlint-disable filename
fun getTopCalories(input: List<String>): List<Int> {
var elfCal = 0
val calorieSubtotals = mutableListOf<Int>()
for (line in input) {
if (line.isEmpty()) {
calorieSubtotals.add(elfCal)
elfCal = 0
... | 0 | Kotlin | 0 | 0 | 814f08b314ae0cbf8e5ae842a8ba82ca2171809d | 1,324 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/KnightProbability.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 | 4,633 | kotlab | Apache License 2.0 |
src/main/kotlin/g0401_0500/s0403_frog_jump/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0401_0500.s0403_frog_jump
// #Hard #Array #Dynamic_Programming #2022_11_30_Time_240_ms_(100.00%)_Space_37.1_MB_(100.00%)
import java.util.HashMap
import java.util.HashSet
class Solution {
// global hashmap to store visited index -> set of jump lengths from that index
private val visited: HashMap<Int... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,504 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/aoc2022/Day25.kt | w8mr | 572,700,604 | false | {"Kotlin": 140954} | package aoc2022
import aoc.parser.followedBy
import aoc.parser.map
import aoc.parser.oneOrMore
import aoc.parser.regex
class Day25 {
val SnafuDigits = "=-012"
data class Snafu(val number: String) {
val SnafuDigits = "=-012"
init {
require(number.all { it in SnafuDigits}) { "numbe... | 0 | Kotlin | 0 | 0 | e9bd07770ccf8949f718a02db8d09daf5804273d | 1,327 | aoc-kotlin | Apache License 2.0 |
src/chapter2/section4/ex23_MultiwayHeaps.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter2.section4
import chapter2.getCompareTimes
import chapter2.getDoubleArray
import chapter2.less
import chapter2.section1.cornerCases
import chapter2.section2.getMergeSortComparisonTimes
import chapter2.swap
/**
* 基于完全多叉树的堆排序(区别于完全二叉树)
* 索引从0开始,设多叉树的父节点为k,分叉为t,则子节点为 t*k+1 t*k+2 ... t*k+t
* 设多叉树的子节点为m,... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,955 | Algorithms-4th-Edition-in-Kotlin | MIT License |
2022/src/Day10.kt | Saydemr | 573,086,273 | false | {"Kotlin": 35583, "Python": 3913} | package src
fun main() {
var part2vals = mutableListOf<Int>()
fun part1(input: List<String>): Int {
var register = 1
var registerNext = 0
val values = mutableListOf<Int>()
input.map { it.trim().split(" ") }
.forEach {
register += registerNext
... | 0 | Kotlin | 0 | 1 | 25b287d90d70951093391e7dcd148ab5174a6fbc | 1,278 | AoC | Apache License 2.0 |
src/Day02.kt | cgeesink | 573,018,348 | false | {"Kotlin": 10745} | fun main() {
fun calculateChoiceScore(myChoice: Char): Int {
val choiceScore = when (myChoice) {
'X' -> 1
'Y' -> 2
'Z' -> 3
else -> 0
}
return choiceScore
}
fun calculateGameScore(opponentChoice: Char, myChoice: Char): Int {
va... | 0 | Kotlin | 0 | 0 | 137fb9a9561f5cbc358b7cfbdaf5562c20d6b10d | 2,658 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SortedSquares.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 |
solutions/src/Day20.kt | khouari1 | 573,893,634 | false | {"Kotlin": 132605, "HTML": 175} | import java.util.*
fun main() {
fun part1(input: List<String>): Long = mix(input)
fun part2(input: List<String>): Long = mix(input, timesToMix = 10, decryptionKey = 811589153)
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day20_test")
check(part1(... | 0 | Kotlin | 0 | 1 | b00ece4a569561eb7c3ca55edee2496505c0e465 | 2,711 | advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/me/peckb/aoc/_2015/calendar/day15/Day15.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2015.calendar.day15
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import javax.inject.Inject
import kotlin.math.max
typealias Counts = List<Int>
class Day15 @Inject constructor(private val generatorFactory: InputGeneratorFactory) {
fun partOne(filename: String) = generat... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 6,111 | advent-of-code | MIT License |
2021/src/day18/day18.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day18
import java.io.File
import kotlin.math.ceil
fun main() {
val input = File("src/day18", "day18input.txt").readLines().map { Snailfish.parseFish(it) }
val sum = input.reduce { acc: Snailfish, snailfish: Snailfish -> acc + snailfish }
println(sum.getMagnitude())
println(findGreatestMagnitud... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 7,507 | adventofcode | Apache License 2.0 |
kotlin/2022/day02/Day02.kt | nathanjent | 48,783,324 | false | {"Rust": 147170, "Go": 52936, "Kotlin": 49570, "Shell": 966} | class Day02 {
enum class Result(val score: Int) {
Win(6),
Lose(0),
Draw(3),
}
enum class Shape(val score: Int) {
Rock(1),
Paper(2),
Scissors(3),
}
fun part1(input: Iterable<String>): Int {
return input
.asSequence()
.filter { it.isNotBlank() }
.map { it.spli... | 0 | Rust | 0 | 0 | 7e1d66d2176beeecaac5c3dde94dccdb6cfeddcf | 2,956 | adventofcode | MIT License |
kotlin/src/katas/kotlin/leetcode/bst_vertical_traversal/VerticalTraversal.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.bst_vertical_traversal
import org.junit.Test
import java.util.*
import kotlin.collections.ArrayList
class VerticalTraversalTests {
@Test fun `vertical order traversal`() {
require(verticalTraversal(Node(1)) == listOf(listOf(1)))
val tree = Node(3,
Node(9)... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,357 | katas | The Unlicense |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[43]字符串相乘.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.lang.StringBuilder
//给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式。
//
// 示例 1:
//
// 输入: num1 = "2", num2 = "3"
//输出: "6"
//
// 示例 2:
//
// 输入: num1 = "123", num2 = "456"
//输出: "56088"
//
// 说明:
//
//
// num1 和 num2 的长度小于110。
// num1 和 num2 只包含数字 0-9。
// num1 和 num2 均不以零开头,除非是数字 ... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,815 | MyLeetCode | Apache License 2.0 |
solutions/src/Day19.kt | khouari1 | 573,893,634 | false | {"Kotlin": 132605, "HTML": 175} | import java.util.*
fun main() {
fun part1(input: List<String>): Int =
getBlueprintsFrom(input)
.sumOf { blueprint ->
val robots = listOf(Robot.OreRobot)
val geodes = getHighestGeodeCount(blueprint, robots, 24)
blueprint.id * geodes
}
... | 0 | Kotlin | 0 | 1 | b00ece4a569561eb7c3ca55edee2496505c0e465 | 8,314 | advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/nl/kelpin/fleur/advent2018/Day17.kt | fdlk | 159,925,533 | false | null | package nl.kelpin.fleur.advent2018
import kotlin.math.max
import kotlin.math.min
sealed class Soil {
abstract fun contains(point: Point): Boolean
}
data class Vertical(val x: Int, val yRange: IntRange) : Soil() {
companion object {
private val re = Regex("""x=(\d+), y=(\d+)\.\.(\d+)""")
fun o... | 0 | Kotlin | 0 | 3 | a089dbae93ee520bf7a8861c9f90731eabd6eba3 | 5,581 | advent-2018 | MIT License |
src/Day09.kt | robinpokorny | 572,434,148 | false | {"Kotlin": 38009} | import kotlin.math.sign
private fun parse(input: List<String>): List<Char> = input
.flatMap {
val (dir, steps) = it.split(" ")
List(steps.toInt()) { dir.single() }
}
private fun moveHead(head: Point, move: Char): Point = when (move) {
'R' -> head.copy(x = head.x + 1)
'L' -> head.copy(x... | 0 | Kotlin | 0 | 2 | 56a108aaf90b98030a7d7165d55d74d2aff22ecc | 1,914 | advent-of-code-2022 | MIT License |
lib/src/main/kotlin/de/linkel/aoc/utils/rangeset/LongRangeSet.kt | norganos | 726,350,504 | false | {"Kotlin": 162220} | package de.linkel.aoc.utils.rangeset
import de.linkel.aoc.utils.iterables.intersect
import de.linkel.aoc.utils.iterables.intersects
class LongRangeSetFactory: RangeFactory<Long, LongRange, Long> {
companion object {
val INSTANCE = LongRangeSetFactory()
}
override fun build(start: Long, endInclusi... | 0 | Kotlin | 0 | 0 | 3a1ea4b967d2d0774944c2ed4d96111259c26d01 | 1,933 | aoc-utils | Apache License 2.0 |
src/day08/Main.kt | nikwotton | 572,814,041 | false | {"Kotlin": 77320} | package day08
import java.io.File
const val workingDir = "src/day08"
fun main() {
val sample = File("$workingDir/sample.txt")
val input1 = File("$workingDir/input_1.txt")
println("Step 1a: ${runStep1(sample)}") // 21
println("Step 1b: ${runStep1(input1)}")
println("Step 2a: ${runStep2(sample)}") ... | 0 | Kotlin | 0 | 0 | dee6a1c34bfe3530ae6a8417db85ac590af16909 | 2,436 | advent-of-code-2022 | Apache License 2.0 |
leetcode/kotlin/search-in-rotated-sorted-array.kt | PaiZuZe | 629,690,446 | false | null | class Solution {
fun search(nums: IntArray, target: Int): Int {
val pivot = findPivot(nums, 0, nums.size, nums.last())
return binSearchWithPivot(nums, target, 0, nums.size, pivot)
}
private fun binSearchWithPivot(nums: IntArray, target: Int, start: Int, end: Int, pivot: Int): Int {
... | 0 | Kotlin | 0 | 0 | 175a5cd88959a34bcb4703d8dfe4d895e37463f0 | 1,165 | interprep | MIT License |
src/medium/_5LongestPalindromicSubstring.kt | ilinqh | 390,190,883 | false | {"Kotlin": 382147, "Java": 32712} | package medium
class _5LongestPalindromicSubstring {
class Solution {
fun longestPalindrome(s: String): String {
if (s.length < 2) {
return s
}
val sb = StringBuffer().append('#')
for (char in s) {
sb.append("${char}#")
... | 0 | Kotlin | 0 | 0 | 8d2060888123915d2ef2ade293e5b12c66fb3a3f | 2,508 | AlgorithmsProject | Apache License 2.0 |
kotlin/src/main/kotlin/com/pbh/soft/day5/Day5Solver.kt | phansen314 | 579,463,173 | false | {"Kotlin": 105902} | package com.pbh.soft.day5
import cc.ekblad.konbini.*
import com.pbh.soft.common.Solver
import com.pbh.soft.common.parsing.ParsingUtils.onSuccess
import com.pbh.soft.day5.RangeKind.LOCATION
import com.pbh.soft.day5.RangeKind.SEED
import mu.KLogging
object Day5Solver : Solver, KLogging() {
override fun solveP1(text: ... | 0 | Kotlin | 0 | 0 | 7fcc18f453145d10aa2603c64ace18df25e0bb1a | 5,701 | advent-of-code | MIT License |
src/main/kotlin/net/codetreats/aoc/common/Dijkstra.kt | codetreats | 725,535,998 | false | {"Kotlin": 45007, "Shell": 1060} | package net.codetreats.aoc.common
class Dijkstra {
/**
* Calculate the minimum distance between startNode and endNode.
* The algorithm expects, that there are exactly [nodeCount] nodes with names from 0 to [nodeCount - 1]
* @param: nodeCount the total number of nodes
* @param: startNOde the nam... | 0 | Kotlin | 1 | 1 | 3cd4aa53093b5f95328cf478e63fe2a7a4e90961 | 2,197 | aoc2023 | MIT License |
src/main/aoc2016/Day13.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2016
class Day13(private val favoriteNumber: Int, private val target: Pair<Int, Int>) {
private fun numOneBits(number: Int): Int = number.toString(2).count { it == '1' }
private fun Pair<Int, Int>.isWall(): Boolean {
val x = first
val y = second
val value = x * x + 3 * x + 2... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,300 | aoc | MIT License |
dcp_kotlin/src/main/kotlin/dcp/day267/day267.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day267
// day267.kt
// By <NAME>, 2019.
import java.lang.IllegalArgumentException
// Represent the board as an 8x8 grid with (0,0) being in the upper left corner, the first coordinate representing
// the x-axis, and the second coordinate representing the y-axis.
enum class Direction {
VERTICAL_N,
... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 8,312 | daily-coding-problem | MIT License |
src/main/kotlin/y2015/day05/Day05.kt | TimWestmark | 571,510,211 | false | {"Kotlin": 97942, "Shell": 1067} | package y2015.day05
fun main() {
AoCGenerics.printAndMeasureResults(
part1 = { part1() },
part2 = { part2() }
)
}
fun input(): List<String> {
return AoCGenerics.getInputLines("/y2015/day05/input.txt")
}
fun String.hasDoubleChar(): Boolean {
var prevChar: Char? = null
this.forEach ... | 0 | Kotlin | 0 | 0 | 23b3edf887e31bef5eed3f00c1826261b9a4bd30 | 1,742 | AdventOfCode | MIT License |
src/main/kotlin/io/jadon/election/voting.kt | phase | 277,456,271 | false | null | package io.jadon.election
/**
* A voter's vote in an election
*/
data class Vote(
val voter: Voter,
val preferences: MutableList<Party>
) {
fun first(): Party? = preferences.firstOrNull()
fun copy(): Vote = Vote(voter, ArrayList(preferences))
}
fun List<Vote>.copy(): List<Vote> = this.map { it.copy... | 0 | Kotlin | 0 | 7 | 3002e4a2082a35fb9735f4bd5574ca51b9dff1a5 | 5,340 | electoral-systems | The Unlicense |
src/datastructure/graphs/Graphs.kt | minielectron | 332,678,510 | false | {"Java": 127791, "Kotlin": 48336} | package datastructure.graphs
import java.util.LinkedList
import java.util.PriorityQueue
data class Edge(val source: Int, val destination: Int, val weight: Int)
class Graphs(private val nodes: Int) {
private val graph = Array(nodes) { ArrayList<Edge>() } // Fixed array size to 'nodes'
fun createGraph() {
... | 0 | Java | 0 | 0 | f2aaff0a995071d6e188ee19f72b78d07688a672 | 9,927 | data-structure-and-coding-problems | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.