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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
kotlin/src/katas/kotlin/leetcode/longest_valid_parens/LongestValidParens.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.longest_valid_parens
import datsok.shouldEqual
import org.junit.Test
class LongestValidParensTest {
@Test fun examples() {
longestValidParentheses("") shouldEqual ""
longestValidParentheses(")") shouldEqual ""
longestValidParentheses(")(") shouldEqual ""
... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,696 | katas | The Unlicense |
src/main/kotlin/Question.kt | pjangam | 216,003,701 | false | null | class Question(private val words: List<String>) {
private val questionType: QuestionType
private val crypticRoman: List<String>
init {
require(isQuestion(words))
questionType = when {
QuestionType.MetalCost.matches(words) -> QuestionType.MetalCost
QuestionType.Number... | 0 | Kotlin | 0 | 0 | 2c4c43b42f705f408e667e13d8a1158bb33245a7 | 1,965 | MerchantGuideToGalaxy | MIT License |
src/Day08/day08.kt | NST-d | 573,224,214 | false | null | package Day08
import utils.readInputLines
import utils.readTestLines
import java.util.Arrays
import kotlin.math.max
fun main() {
fun printArray(arr: Array<BooleanArray>){
arr.forEach {
it.forEach { print("$it ") }
println()
}
}
fun part1(input: List<String>): Int... | 0 | Kotlin | 0 | 0 | c4913b488b8a42c4d7dad94733d35711a9c98992 | 3,255 | aoc22 | Apache License 2.0 |
src/Day12.kt | vitind | 578,020,578 | false | {"Kotlin": 60987} | import java.util.*
import kotlin.math.absoluteValue
fun main() {
data class Node(val position: Pair<Int,Int>, val cost: Int, val estimate: Int, val parentNode: Node? = null)
fun loadGrid(input: List<String>) = input.map { it.toCharArray() }
fun getLetter(grid: List<CharArray>, xPos: Int, yPos: Int) = grid... | 0 | Kotlin | 0 | 0 | 2698c65af0acd1fce51525737ab50f225d6502d1 | 6,936 | aoc2022 | Apache License 2.0 |
src/Day17.kt | syncd010 | 324,790,559 | false | null | class Day17: Day {
private fun convert(input: List<String>) : List<Long> {
return input[0].split(",").map { it.toLong() }
}
override fun solvePartOne(input: List<String>): Int {
val view = Intcode(convert(input))
.execute()
.map { it.toChar() }
... | 0 | Kotlin | 0 | 0 | 11c7c7d6ccd2488186dfc7841078d9db66beb01a | 1,522 | AoC2019 | Apache License 2.0 |
src/Day04.kt | ty-garside | 573,030,387 | false | {"Kotlin": 75779} | // Day 04 - Camp Cleanup
// https://adventofcode.com/2022/day/4
fun main() {
infix fun IntRange.fullyContains(that: IntRange) =
(this.first <= that.first) && (this.last >= that.last)
infix fun IntRange.overlapsWith(that: IntRange) =
(this.first >= that.first && this.first <= that.last) ||
... | 0 | Kotlin | 0 | 0 | 49ea6e3ad385b592867676766dafc48625568867 | 4,131 | aoc-2022-in-kotlin | Apache License 2.0 |
grind-75-kotlin/src/main/kotlin/ClimbingStairs.kt | Codextor | 484,602,390 | false | {"Kotlin": 27206} | /**
* You are climbing a staircase. It takes n steps to reach the top.
*
* Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
*
*
*
* Example 1:
*
* Input: n = 2
* Output: 2
* Explanation: There are two ways to climb to the top.
* 1. 1 step + 1 step
* 2. 2 step... | 0 | Kotlin | 0 | 0 | 87aa60c2bf5f6a672de5a9e6800452321172b289 | 983 | grind-75 | Apache License 2.0 |
src/main/kotlin/io/github/kmakma/adventofcode/utils/GeneralUtilities.kt | kmakma | 225,714,388 | false | null | package io.github.kmakma.adventofcode.utils
import java.math.BigInteger
/**
* Returns lists with elements of the list ordered in all possible ways
*/
fun <E> List<E>.allPermutations(): List<List<E>> {
return allPermutations(unordered = this)
}
private fun <E> allPermutations(ordered: List<E> = emptyList(), uno... | 0 | Kotlin | 0 | 0 | 7e6241173959b9d838fa00f81fdeb39fdb3ef6fe | 2,828 | adventofcode-kotlin | MIT License |
2022/Day12.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | fun main() {
val input = readInput("Day12").map { it.toCharArray() }
val n = input.size
val m = input[0].size
var source: Pair<Int, Int>? = null
var end: Pair<Int, Int>? = null
for (i in 0 until n) {
for (j in 0 until m) {
when (input[i][j]) {
'S' -> {
... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 1,490 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/dynamicprogramming/MaximumProductSubarray.kt | e-freiman | 471,473,372 | false | {"Kotlin": 78010} | package dynamicprogramming
fun processSubarray(a: Int, b: Int, negatives: Int, nums: IntArray): Int {
if (a > b) {
return 0
}
if (a == b) {
return nums[a]
}
var i = a
var j = b
var leftProd = 1
var rightProd = 1
if (negatives % 2 == 1) {
while (nums[i] > 0)... | 0 | Kotlin | 0 | 0 | fab7f275fbbafeeb79c520622995216f6c7d8642 | 1,594 | LeetcodeGoogleInterview | Apache License 2.0 |
src/util/algorithms/ConvexHull.kt | JBWills | 291,822,812 | false | null | package util.algorithms
import coordinate.Point
import util.algorithms.PointOrientation.Clockwise
import util.algorithms.PointOrientation.Colinear
import util.algorithms.PointOrientation.CounterClockwise
import util.polylines.MutablePolyLine
import util.polylines.PolyLine
// from: https://www.nayuki.io/res/convex-hu... | 0 | Kotlin | 0 | 0 | 569b27c1cb1dc6b2c37e79dfa527b9396c7a2f88 | 3,094 | processing-sketches | MIT License |
src/day09/Code.kt | fcolasuonno | 572,734,674 | false | {"Kotlin": 63451, "Dockerfile": 1340} | package day09
import Coord
import day06.main
import readInput
import kotlin.math.abs
import kotlin.math.sign
fun main() {
fun parse(input: List<String>) = input
.map { motion ->
val (dir, amount) = motion.split(" ")
(1..amount.toInt()).map {
when (dir) {
... | 0 | Kotlin | 0 | 0 | 9cb653bd6a5abb214a9310f7cac3d0a5a478a71a | 1,587 | AOC2022 | Apache License 2.0 |
src/main/kotlin/com/sk/topicWise/string/17. Letter Combinations of a Phone Number.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.topicWise.string
class Solution17 {
fun letterCombinations(digits: String): List<String> {
val map = mapOf(
2 to listOf('a', 'b', 'c'),
3 to listOf('d', 'e', 'f'),
4 to listOf('g', 'h', 'i'),
5 to listOf('j', 'k', 'l'),
6 to listOf(... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,888 | leetcode-kotlin | Apache License 2.0 |
src/Day10.kt | astrofyz | 572,802,282 | false | {"Kotlin": 124466} | fun main() {
fun Int.isInteresting():Int{
if (this in listOf(20, 60, 100, 140, 180, 220)){
return 1
}
return 0
}
fun part1(input: List<String>): Int {
var cycle = 0
var X = 1
var res = 0
for (line in input){
if (line.startsWith... | 0 | Kotlin | 0 | 0 | a0bc190b391585ce3bb6fe2ba092fa1f437491a6 | 1,945 | aoc22 | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2022/day18/day18.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2022.day18
import biz.koziolek.adventofcode.Coord3d
import biz.koziolek.adventofcode.findInput
import biz.koziolek.adventofcode.getAdjacentCoords
import java.util.ArrayDeque
import java.util.Queue
fun main() {
val inputFile = findInput(object {})
val droplet = parseDrople... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 2,643 | advent-of-code | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaxAncestorDiff.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,663 | kotlab | Apache License 2.0 |
2019/src/main/kotlin/com/github/jrhenderson1988/adventofcode2019/day18/Vault.kt | jrhenderson1988 | 289,786,400 | false | {"Kotlin": 216891, "Java": 166355, "Go": 158613, "Rust": 124111, "Scala": 113820, "Elixir": 112109, "Python": 91752, "Shell": 37} | package com.github.jrhenderson1988.adventofcode2019.day18
import com.github.jrhenderson1988.adventofcode2019.common.Direction
import com.github.jrhenderson1988.adventofcode2019.common.bfs
import kotlin.math.min
class Vault(
grid: Set<Pair<Int, Int>>,
private val keys: Map<Char, Pair<Int, Int>>,
private va... | 0 | Kotlin | 0 | 0 | 7b56f99deccc3790c6c15a6fe98a57892bff9e51 | 5,858 | advent-of-code | Apache License 2.0 |
src/Day2.kt | devPalacio | 574,493,024 | false | {"Kotlin": 8009, "Python": 1346} | import java.io.File
fun main() {
val input = File("src/day2.txt").readText().trim()
val games = input.split(System.lineSeparator())
.map { game -> game.split(" ") }
.map { it[0].first() to it[1].first() }
fun getTotalPoints(games: List<Pair<Char,Char>>) = games.sumOf {
val ... | 0 | Kotlin | 0 | 0 | 648755244e07887335d05601b5fe78bdcb8b1baa | 2,358 | AoC-2022 | Apache License 2.0 |
dcp_kotlin/src/main/kotlin/dcp/day194/day194.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day194
// day194.kt
// By <NAME>, 2019.
typealias PointType = Int
typealias Segment = Pair<PointType, PointType>
typealias Points = List<PointType>
/**
* Given a set of 2n points of the form (p_i, 0) and (q_i, 1) for i in [0,n), determine the number of line segments
* of the form (p_i, 0) to (q_i, 0) th... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 1,360 | daily-coding-problem | MIT License |
src/day03/Day03.kt | IThinkIGottaGo | 572,833,474 | false | {"Kotlin": 72162} | package day03
import readInput
fun main() {
val priority = buildMap {
('a'..'z').forEachIndexed { i, c -> put(c, i + 1) }
('A'..'Z').forEachIndexed { i, c -> put(c, i + 27) }
}
fun part1(input: List<String>): Int {
return input.sumOf { line ->
val c1 = line.substring(0... | 0 | Kotlin | 0 | 0 | 967812138a7ee110a63e1950cae9a799166a6ba8 | 1,069 | advent-of-code-2022 | Apache License 2.0 |
stepik/sportprogramming/LongestCommonSubsequenceDynamicProgramming.kt | grine4ka | 183,575,046 | false | {"Kotlin": 98723, "Java": 28857, "C++": 4529} | package stepik.sportprogramming
import java.io.File
import java.io.PrintWriter
import java.util.*
import kotlin.math.max
fun main() {
output {
val n = readInt()
val a = readIntArray(n)
val m = readInt()
val b = readIntArray(m)
val d = Array(n + 1) {
IntArray(m +... | 0 | Kotlin | 0 | 0 | c967e89058772ee2322cb05fb0d892bd39047f47 | 2,310 | samokatas | MIT License |
leetcode-75-kotlin/src/main/kotlin/ProductOfArrayExceptSelf.kt | Codextor | 751,507,040 | false | {"Kotlin": 49566} | /**
* Given an integer array nums,
* return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].
*
* The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.
*
* You must write an algorithm that runs in O(n) time and without using the... | 0 | Kotlin | 0 | 0 | 0511a831aeee96e1bed3b18550be87a9110c36cb | 1,327 | leetcode-75 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2023/2023-17.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2023
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.IntGrid
import com.github.ferinagy.adventOfCode.get
import com.github.ferinagy.adventOfCode.isIn
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCo... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 2,141 | advent-of-code | MIT License |
kotlin/graphs/shortestpaths/BellmanFord.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package graphs.shortestpaths
import java.util.stream.Stream
object BellmanFord {
val INF: Int = Integer.MAX_VALUE / 2
fun bellmanFord(graph: Array<List<Edge>>, s: Int, dist: IntArray, pred: IntArray): Boolean {
Arrays.fill(pred, -1)
Arrays.fill(dist, INF)
dist[s] = 0
val n = gr... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 2,517 | codelibrary | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaxProfitWithFee.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,984 | kotlab | Apache License 2.0 |
src/main/kotlin/asaad/DaySeven.kt | Asaad27 | 573,138,684 | false | {"Kotlin": 23483} | package asaad
import java.io.File
private const val MAX_STORAGE = 70000000
private const val REQUIRED_STORAGE = 30000000
private const val PART1 = 100000
class DaySeven(filePath: String) {
private val file = File(filePath)
private val input = readInput(file)
private var lineNumber = 0
private fun rea... | 0 | Kotlin | 0 | 0 | 16f018731f39d1233ee22d3325c9933270d9976c | 4,478 | adventOfCode2022 | MIT License |
src/day07/Day07.kt | sophiepoole | 573,708,897 | false | null | package day07
import readInput
fun main() {
// val input = readInput("day07/input_test")
val input = readInput("day07/input")
val day = Day07()
val fileSystem = day.parse(input)
println("Part 1: ${day.part1(fileSystem)}")
println("Part 2: ${day.part2(fileSystem)}")
}
sealed class Component
... | 0 | Kotlin | 0 | 0 | 00ad7d82cfcac2cb8a902b310f01a6eedba985eb | 2,173 | advent-of-code-2022 | Apache License 2.0 |
src/Day10.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} | class Day10 {
private var cycle = 0
private fun regX() = 1 + pendingInstructions.filter { it.first < cycle }.sumOf { it.second }
private var pendingInstructions = mutableListOf<Pair<Int, Int>>()
private fun runInstruction(instruction: String): Int {
var cycles = 0
when (instruction.sub... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 1,858 | aoc-22-kotlin | Apache License 2.0 |
src/day16/Day16.kt | easchner | 572,762,654 | false | {"Kotlin": 104604} | package day16
import readInputString
import java.util.PriorityQueue
import kotlin.math.max
import kotlin.math.pow
import kotlin.system.measureNanoTime
data class Connection (val label: String, var distance: Int)
data class Valve(
val label: String,
val flowRate: Int,
val connections: MutableList<Connecti... | 0 | Kotlin | 0 | 0 | 5966e1a1f385c77958de383f61209ff67ffaf6bf | 8,664 | Advent-Of-Code-2022 | Apache License 2.0 |
src/Day18.kt | greg-burgoon | 573,074,283 | false | {"Kotlin": 120556} | import java.util.TreeSet
fun main() {
fun calculateSurfaceArea(coordList: List<List<Int>>): Int {
var coordMap = mutableMapOf<String, Int>()
return coordList.map { listOfCoord ->
var neighbourDiscount = 0;
listOfCoord.forEachIndexed { index, i ->
var coordSt... | 0 | Kotlin | 0 | 1 | 74f10b93d3bad72fa0fc276b503bfa9f01ac0e35 | 4,880 | aoc-kotlin | Apache License 2.0 |
base-portable/src/commonMain/kotlin/jetbrains/datalore/base/algorithms/Geometry.kt | randomnetcat | 476,483,866 | true | {"Kotlin": 5698914, "Python": 781400, "C": 2832, "CSS": 1923, "Shell": 1759, "JavaScript": 1121} | /*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.base.algorithms
import jetbrains.datalore.base.gcommon.collect.IntSpan
import jetbrains.datalore.base.geometry.DoubleVector
import kotlin.math.abs
... | 1 | Kotlin | 1 | 0 | fe960f43d39844d04a89bd12490cd2dd4dbeaa51 | 2,149 | lets-plot | MIT License |
src/main/kotlin/days/Day4Solution.kt | yigitozgumus | 434,108,608 | false | {"Kotlin": 17835} | package days
import BaseSolution
class BingoBoard(rows: List<String>) {
private val rowCounter = MutableList(rows.size) { 0 }
private val colCounter = MutableList(rows.size) { 0 }
var winner = false
private val board = rows.toMutableList().mapTo(mutableListOf()) { row ->
row.split(" ").filter... | 0 | Kotlin | 0 | 0 | c0f6fc83fd4dac8f24dbd0d581563daf88fe166a | 1,954 | AdventOfCode2021 | MIT License |
src/year2023/day09/Day09.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2023.day09
import check
import readInput
fun main() {
val testInput = readInput("2023", "Day09_test")
check(part1(testInput), 114)
check(part2(testInput), 2)
val input = readInput("2023", "Day09")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 938 | AdventOfCode | Apache License 2.0 |
src/main/kotlin/days/aoc2021/Day3.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2021
import days.Day
class Day3 : Day(2021, 3) {
override fun partOne(): Any {
calculateGammaAndEpsilon(inputList).let { return it.first * it.second }
}
fun calculateGammaAndEpsilon(input: List<String>): Pair<Int,Int> {
val counts = Array(input.first().length) { 0 }
... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 2,323 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/leonra/adventofcode/advent2023/day06/Day6.kt | LeonRa | 726,688,446 | false | {"Kotlin": 30456} | package com.leonra.adventofcode.advent2023.day06
import com.leonra.adventofcode.shared.readResource
/** https://adventofcode.com/2023/day/6 */
private object Day6 {
fun partOne(): Int {
val times = mutableListOf<Int>()
val records = mutableListOf<Int>()
fun parseInputs(data: String): Lis... | 0 | Kotlin | 0 | 0 | 46bdb5d54abf834b244ba9657d0d4c81a2d92487 | 2,538 | AdventOfCode | Apache License 2.0 |
kt.kt | darian-catalin-cucer | 598,111,644 | false | null | fun quickSort(arr: IntArray, low: Int, high: Int) {
if (low < high) {
val pivotIndex = partition(arr, low, high)
quickSort(arr, low, pivotIndex - 1)
quickSort(arr, pivotIndex + 1, high)
}
}
fun partition(arr: IntArray, low: Int, high: Int): Int {
val pivot = arr[high]
var i = lo... | 0 | Kotlin | 0 | 0 | 1cea70defa6d6e7429bace2402b23ac769a2fbba | 1,508 | divide-and-conquer-algorithms | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SortArrayByParity.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,518 | kotlab | Apache License 2.0 |
src/main/kotlin/day4/day4.kt | aaronbush | 370,490,470 | false | null | package day4
import loadFile
fun main() {
val data = "/day4/input.txt".loadFile()
.fold(mutableListOf<MutableSet<Pair<String, String>>>(mutableSetOf())) { accum, line ->
if (line.isBlank()) {
accum.apply { add(mutableSetOf()) } // on blank line create new set of field/data
... | 0 | Kotlin | 0 | 0 | 41d69ebef7cfeae4079e8311b1060b272c5f9a29 | 2,380 | aoc-2020-kotlin | MIT License |
src/Day10.kt | ka1eka | 574,248,838 | false | {"Kotlin": 36739} | fun main() {
fun part1(input: List<String>): Int = sequence {
val breakPoints = setOf(20, 60, 100, 140, 180, 220)
var x = 1
var cycle = 0
input.forEach { command ->
val previousCycle = cycle
when (command) {
"noop" -> cycle++
el... | 0 | Kotlin | 0 | 0 | 4f7893448db92a313c48693b64b3b2998c744f3b | 2,033 | advent-of-code-2022 | Apache License 2.0 |
test/leetcode/ValidTicTacToeState.kt | andrej-dyck | 340,964,799 | false | null | package leetcode
import lib.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.params.*
import org.junit.jupiter.params.converter.*
import org.junit.jupiter.params.provider.*
/**
* https://leetcode.com/problems/valid-tic-tac-toe-state/
*
* 794. Valid Tic-Tac-Toe State
* [Medium]
*
* A ... | 0 | Kotlin | 0 | 0 | 3e3baf8454c34793d9771f05f330e2668fda7e9d | 5,489 | coding-challenges | MIT License |
src/main/kotlin/com/github/shmvanhouten/adventofcode/day4/RoomKeyDecoder.kt | SHMvanHouten | 109,886,692 | false | {"Kotlin": 616528} | package com.github.shmvanhouten.adventofcode.day4
class RoomKeyDecoder {
fun checkIfRoomsAreReal(keys: String): Int {
return keys
.split("\n")
.sumBy { checkIfRoomIsReal(it.trim()) }
}
fun getListOfValidRooms(encodedRoomNames: String): List<Room> {
return e... | 0 | Kotlin | 0 | 0 | a8abc74816edf7cd63aae81cb856feb776452786 | 2,520 | adventOfCode2016 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CountComponents.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,212 | kotlab | Apache License 2.0 |
src/Day01.kt | BHFDev | 572,832,641 | false | null | fun main() {
fun part1(input: List<String>): Int {
var highestCalories = 0
var currentCalories = 0
input.forEach {calories ->
if(calories.isEmpty()) {
if(currentCalories > highestCalories) {
highestCalories = currentCalories
}
... | 0 | Kotlin | 0 | 0 | b158069483fa02636804450d9ea2dceab6cf9dd7 | 1,221 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/org/sj/aoc2022/day01/CalorieCounter.kt | sadhasivam | 573,168,428 | false | {"Kotlin": 10910} | package org.sj.aoc2022.day01
val maxNCalories = 3
fun computeElvesCaloriesList(input: List<String>): List<Int> {
val elvesCalories = mutableListOf<Int>()
var calories = 0
input.forEach {
if (it.trim() != "") {
calories += it.toInt()
} else {
elvesCalories.add(calori... | 0 | Kotlin | 0 | 0 | 7a1ceaddbe7e72bad0e9dfce268387d333b62143 | 948 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/cc/stevenyin/algorithms/SortHelper.kt | StevenYinKop | 269,945,740 | false | {"Kotlin": 107894, "Java": 9565} | package cc.stevenyin.algorithms
import cc.stevenyin.algorithms._02_sorts.SortAlgorithm
import kotlin.random.Random
import kotlin.system.measureTimeMillis
class SortHelper {
}
enum class RandomType() {
NEARLY_ORDERED {
override fun generate(nums: Int): Array<Int> {
val random = Random(System.cu... | 0 | Kotlin | 0 | 1 | 748812d291e5c2df64c8620c96189403b19e12dd | 2,612 | kotlin-demo-code | MIT License |
src/main/kotlin/ca/kiaira/advent2023/day2/Day2.kt | kiairatech | 728,913,965 | false | {"Kotlin": 78110} | package ca.kiaira.advent2023.day2
import ca.kiaira.advent2023.Puzzle
import com.github.michaelbull.logging.InlineLogger
/**
* Class representing the Day 2 puzzle for Advent of Code 2023.
* It includes methods to parse game data and solve the puzzle for each part.
*
* @author <NAME> <<EMAIL>>
* @since December 8t... | 0 | Kotlin | 0 | 1 | 27ec8fe5ddef65934ae5577bbc86353d3a52bf89 | 3,474 | kAdvent-2023 | Apache License 2.0 |
src/Day03.kt | thomasreader | 573,047,664 | false | {"Kotlin": 59975} | import java.io.Reader
val priorities get() = mutableMapOf<Char, Int>().also { map ->
('a'..'z').forEachIndexed { index, c ->
map[c] = index + 1
}
('A'..'Z').forEachIndexed { index, c ->
map[c] = index + 27
}
}.toMap()
fun main() {
val testInput = """
vJrwpWtwJgWrhcsFMMfFFhF... | 0 | Kotlin | 0 | 0 | eff121af4aa65f33e05eb5e65c97d2ee464d18a6 | 1,892 | advent-of-code-2022-kotlin | Apache License 2.0 |
day10.kt | benjaminjkraft | 113,406,355 | false | null | fun doHash(lengths: List<Int>, n: Int, rounds: Int): Array<Int> {
var pos = 0
var skip = 0
val list = Array(n, { it })
for (round in 0 until rounds) {
for (i in lengths.indices) {
val listAgain = list.copyOf()
for (j in 0 until lengths[i]) {
list[(pos + j)... | 0 | Rust | 0 | 5 | e3ac3563bf2d535f68e503ce03c76f41ec77fc31 | 1,130 | aoc2017 | MIT License |
src/main/kotlin/ru/timakden/aoc/year2016/Day03.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2016
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 3: Squares With Three Sides](https://adventofcode.com/2016/day/3).
*/
object Day03 {
@JvmStatic
fun main(args: Array<String>) {
measure {
val input = readInput("year2016/... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 1,296 | advent-of-code | MIT License |
src/Day14.kt | TinusHeystek | 574,474,118 | false | {"Kotlin": 53071} | import extensions.grid.*
class Day14 : Day(14) {
private val directionalLower3: List<Point> = listOf(0 to 1, -1 to 1, 1 to 1)
enum class CavePointType {
ROCK, AIR, SAND, SPAWN_POINT
}
class CaveNode(point: Point) : Node(point) {
var type = CavePointType.AIR
override fun toSt... | 0 | Kotlin | 0 | 0 | 80b9ea6b25869a8267432c3a6f794fcaed2cf28b | 3,657 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/leetcode/P473.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package com.leetcode
// https://github.com/antop-dev/algorithm/issues/494
class P473 {
fun makesquare(matchsticks: IntArray): Boolean {
val sum = matchsticks.sum()
// 모든 성냥의 길이가 4면으로 떨어지지 않으면 안됨
if (sum % 4 > 0) return false
val length = sum / 4
// 길이가 긴 성냥순으로 정렬
mat... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,394 | algorithm | MIT License |
src/main/kotlin/com/mckernant1/leetcode/FlightTraversal.kt | mckernant1 | 494,952,749 | false | {"Kotlin": 33093} | package com.mckernant1.leetcode
/**
* Interview Question from Hopper.
*
* ChatGPT generated solution
*/
fun main() {
val flights = listOf(
Flight("A1", "City1", "City2"),
Flight("A2", "City2", "City3"),
Flight("A3", "City3", "City4"),
Flight("A4", "City4", "City5"),
Fli... | 0 | Kotlin | 0 | 0 | 5aaa96588925b1b8d77d7dd98dd54738deeab7f1 | 2,170 | kotlin-random | Apache License 2.0 |
src/Day04.kt | flexable777 | 571,712,576 | false | {"Kotlin": 38005} | fun main() {
infix fun IntRange.contains(other: IntRange): Boolean = this.first <= other.first && this.last >= other.last
fun getRangePairs(line: String): Pair<IntRange, IntRange> {
//Probably are some better ways of splitting
val split = line.split(",")
val assignment1 = split[0].spli... | 0 | Kotlin | 0 | 0 | d9a739eb203c535a3d83bc5da1b6a6a90a0c7bd6 | 1,506 | advent-of-code-2022 | Apache License 2.0 |
src/Day17.kt | cypressious | 572,916,585 | false | {"Kotlin": 40281} | fun main() {
fun parseTarget(input: String) = input
.split("=|,|(\\.\\.)".toRegex())
.mapNotNull { it.toIntOrNull() }
@Suppress("NAME_SHADOWING")
fun simulate(
target: List<Int>,
dx: Int,
dy: Int,
xOnly: Boolean = false,
yO... | 0 | Kotlin | 0 | 0 | 169fb9307a34b56c39578e3ee2cca038802bc046 | 2,261 | AdventOfCode2021 | Apache License 2.0 |
src/Day14.kt | hufman | 573,586,479 | false | {"Kotlin": 29792} | import java.lang.Integer.max
import java.lang.Integer.min
fun main() {
fun parse(input: List<String>): Array<BooleanArray> {
val grid = Array(300) {
BooleanArray(800) {false}
}
input.forEach { line ->
val endPoints = line.split(" -> ").map { segment ->
val pieces = segment.split(',').map {
it.toI... | 0 | Kotlin | 0 | 0 | 1bc08085295bdc410a4a1611ff486773fda7fcce | 3,375 | aoc2022-kt | Apache License 2.0 |
kotlin/0935-knight-dialer.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} | // Alternative solution
class Solution {
fun knightDialer(n: Int): Int {
if (n == 1) return 10
val mod = 1_000_000_007
var moves = longArrayOf(1L, 4L, 2L, 2L)
for(i in 0 until n - 1) {
val temp = LongArray (4)
temp[0] = moves[3]
temp[1] = (2 * mo... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 2,532 | leetcode | MIT License |
src/Day03.kt | GarrettShorr | 571,769,671 | false | {"Kotlin": 82669} | fun main() {
fun part1(input: List<String>): Int {
val LOWER_OFFSET = 97-1
val UPPER_OFFSET = 65-27
var total = 0
for(line in input) {
val firstHalf = line.substring(0, line.length/2)
val secondHalf = line.substring(line.length/2)
val shared = findSharedItem(firstHalf, secondHalf)
... | 0 | Kotlin | 0 | 0 | 391336623968f210a19797b44d027b05f31484b5 | 2,061 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/IPO.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,845 | kotlab | Apache License 2.0 |
src/main/kotlin/Day10.kt | lanrete | 244,431,253 | false | null | import mathUti.gcd
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.acos
import kotlin.math.sqrt
data class Coordinate(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
fun between(other: Coordinate): List<Coordinate> {
val xGap = other.x - x
val yGap = other.y - y
... | 0 | Kotlin | 0 | 1 | 15125c807abe53230e8d0f0b2ca0e98ea72eb8fd | 2,926 | AoC2019-Kotlin | MIT License |
src/questions/WordSearch.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
import kotlin.collections.LinkedHashSet
/**
* Given an m x n grid of characters board and a string word, return true if word exists in the grid.
* The word can be constructed from letters of sequentially adjacent cells, where adjacent ... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 6,396 | algorithms | MIT License |
src/main/kotlin/org/dreambroke/Day1.kt | DreamBroke | 729,562,380 | false | {"Kotlin": 5424} | package org.dreambroke
object Day1 : BaseProblem() {
@JvmStatic
fun main(args: Array<String>) {
solvePartA()
solvePartB()
}
override fun partA(input: String): String {
val lines = Utils.splitStringByLine(input)
var sum = 0
for (line in lines) {
val (... | 0 | Kotlin | 0 | 0 | 5269cf089d4d367e69cf240c0acda568db6e4b22 | 2,382 | AdventOfCode2023 | Apache License 2.0 |
src/Day17.kt | ambrosil | 572,667,754 | false | {"Kotlin": 70967} | import java.io.File
import kotlin.math.absoluteValue
fun main() {
val day17 = Day17(File("src/inputs/Day17.txt").readText())
println(day17.part1())
println(day17.part2())
}
class Day17(input: String) {
private val jets = jets(input)
private val shapes = shapes()
private val cave = (0..6).map ... | 0 | Kotlin | 0 | 0 | ebaacfc65877bb5387ba6b43e748898c15b1b80a | 3,738 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | acunap | 573,116,784 | false | {"Kotlin": 23918} | import java.lang.IllegalArgumentException
import java.util.*
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
@OptIn(ExperimentalTime::class)
fun main() {
fun part1(input: List<String>): Int {
return input
.map { it.split(" ") }
.map { listOf(ShapeStrategy.fromStri... | 0 | Kotlin | 0 | 0 | f06f9b409885dd0df78f16dcc1e9a3e90151abe1 | 3,538 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/leetcode/kotlin/hashtable/438. Find All Anagrams in a String.kt | sandeep549 | 251,593,168 | false | null | package leetcode.kotlin.hashtable
fun main() {
println(findAnagrams2("cbaebabacd", "abc"))
println(findAnagrams2("abab", "ab"))
}
// brute force
private fun findAnagrams(s: String, p: String): List<Int> {
var frequencyMap = p.toCharArray().groupBy { it }.mapValues { it.value.size }
fun isAnagram(start... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 2,490 | kotlinmaster | Apache License 2.0 |
src/day5/Day5.kt | blundell | 572,916,256 | false | {"Kotlin": 38491} | package day5
import readInput
data class Instruction(val moves: Int, val from: Int, val to: Int) {
override fun toString(): String {
return "move $moves from $from to $to"
}
}
fun main() {
fun parseStacks(input: List<String>): List<ArrayDeque<Char>> {
val captureCrates = "( {3}|\\[[A-Z]])... | 0 | Kotlin | 0 | 0 | f41982912e3eb10b270061db1f7fe3dcc1931902 | 3,915 | kotlin-advent-of-code-2022 | Apache License 2.0 |
gcj/y2022/round2/b_small.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2022.round2
import kotlin.math.round
import kotlin.math.sqrt
private fun dumb(m: Int): Int {
val a = List(m + 2) { BooleanArray(m + 2) }
val b = List(m + 2) { BooleanArray(m + 2) }
for (r in 0..m) {
for (x in 0..r) {
val y = round(sqrt(1.0 * r * r - x * x)).toInt()
b[x][y] = true
b[y][x] = t... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 715 | competitions | The Unlicense |
src/day21/Day21.kt | dakr0013 | 572,861,855 | false | {"Kotlin": 105418} | package day21
import kotlin.test.assertEquals
import readInput
fun main() {
fun part1(input: List<String>): Long {
return Expressions(input).root().value()
}
fun part2(input: List<String>): Long {
return Expressions(input).resolveHumn()
}
// test if implementation meets criteria from the descripti... | 0 | Kotlin | 0 | 0 | 6b3adb09f10f10baae36284ac19c29896d9993d9 | 4,594 | aoc2022 | Apache License 2.0 |
src/main/kotlin/net/dilius/daily/coding/problem/n00x/008.kt | diliuskh | 298,020,928 | false | null | package net.dilius.daily.coding.problem.n00x
import net.dilius.daily.coding.problem.Problem
data class UnivalTree(val left: UnivalTree?, val right: UnivalTree?, val value: Int)
class UnivalTreeCounter : Problem<UnivalTree, Int> {
override fun solve(input: UnivalTree): Int {
return solve0(input)
}
... | 0 | Kotlin | 0 | 0 | 7e5739f87dbce2b56d24e7bab63b6cee6bbc54bc | 2,014 | dailyCodingProblem | Apache License 2.0 |
src/Day10.kt | bin-wang | 572,801,360 | false | {"Kotlin": 19395} | import kotlin.math.abs
fun main() {
data class State(val register: Int, val history: List<Int>)
fun solve(input: List<String>): Int {
val finalState = input.fold(State(1, listOf())) { acc, line ->
when (line) {
"noop" -> State(acc.register, acc.history + acc.register)
... | 0 | Kotlin | 0 | 0 | dca2c4915594a4b4ca2791843b53b71fd068fe28 | 1,260 | aoc22-kt | Apache License 2.0 |
src/Day02.kt | MT-Jacobs | 574,577,538 | false | {"Kotlin": 19905} | import Shape.*
import GameState.*
fun main() {
fun part1(input: List<String>): Int {
return input.map {
it[0].toShape() to it[2].toShape()
}.sumOf { (theirShape, myShape) ->
myShape.evaluateAgainst(theirShape).score + myShape.score
}
}
fun part2(input: List<... | 0 | Kotlin | 0 | 0 | 2f41a665760efc56d531e56eaa08c9afb185277c | 2,478 | advent-of-code-2022 | Apache License 2.0 |
src/day22/Parser.kt | g0dzill3r | 576,012,003 | false | {"Kotlin": 172121} | package day22
import readInput
import java.io.File
import java.lang.IllegalStateException
import java.util.regex.Pattern
enum class Direction {
LEFT, RIGHT;
companion object {
fun parse (encoded: Char): Direction {
return when (encoded) {
'L' -> Direction.LEFT
... | 0 | Kotlin | 0 | 0 | 6ec11a5120e4eb180ab6aff3463a2563400cc0c3 | 3,334 | advent_of_code_2022 | Apache License 2.0 |
src/TwoToOne.kt | adamWeesner | 149,649,774 | false | null | import org.junit.Test
import java.util.*
import kotlin.test.assertEquals
/**
* Two To One Code Kata
* https://www.codewars.com/kata/5656b6906de340bd1b0000ac
*
* @author <NAME>
* @since 9/15/2018
*/
fun longest(s1: String, s2: String): String = (s1 + s2).split("").sorted().distinct().joinToString("", "", "")
cla... | 0 | Kotlin | 0 | 0 | aa988ccbaafceef898b16fb6da68e6bf1d04137c | 2,923 | Code-Katas | MIT License |
src/main/kotlin/g2401_2500/s2478_number_of_beautiful_partitions/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2401_2500.s2478_number_of_beautiful_partitions
// #Hard #String #Dynamic_Programming #2023_07_05_Time_230_ms_(100.00%)_Space_38.1_MB_(100.00%)
class Solution {
fun beautifulPartitions(s: String, k: Int, l: Int): Int {
val cs = s.toCharArray()
val n = cs.size
if (!prime(cs[0]) || p... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,684 | LeetCode-in-Kotlin | MIT License |
src/cn/leetcode/codes/simple121/Simple121.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple121
import cn.leetcode.codes.out
import kotlin.math.max
fun main() {
val nums = intArrayOf(7,1,5,3,6,4)
// val nums = intArrayOf(7,6,4,3,1)
val max = maxProfit(nums)
val max2 = maxProfit2(nums)
out("max = $max")
out("max2 = $max2")
}
/*
121. 买卖股票的最佳时机
给定一个数... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 1,912 | LeetCodeSimple | Apache License 2.0 |
src/Day02.kt | nikolakasev | 572,681,478 | false | {"Kotlin": 35834} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
val him = it.split(" ")[0]
val me = it.split(" ")[1]
val gameResult = if (him == "A" && me == "X") {
3 + 1
} else if (him == "A" && me == "Y") {
6 + 2
... | 0 | Kotlin | 0 | 1 | 5620296f1e7f2714c09cdb18c5aa6c59f06b73e6 | 1,987 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/io/github/clechasseur/adventofcode2021/Day18.kt | clechasseur | 435,726,930 | false | {"Kotlin": 315943} | package io.github.clechasseur.adventofcode2021
import io.github.clechasseur.adventofcode2021.data.Day18Data
import kotlin.math.ceil
import kotlin.math.floor
object Day18 {
private val data = Day18Data.data
fun part1(): Int = data.lines().map { it.iterator().nextNode() }.reduce { acc, n -> acc + n }.magnitude... | 0 | Kotlin | 0 | 0 | 4b893c001efec7d11a326888a9a98ec03241d331 | 3,868 | adventofcode2021 | MIT License |
src/kotlin/_2022/Task11.kt | MuhammadSaadSiddique | 567,431,330 | false | {"Kotlin": 20410} | package _2022
import Task
import readInput
import utils.Numbers.lowestCommonMultiple
import utils.Parse.firstInt
typealias ReliefWorryLevel = (Long) -> Long
typealias Inspection = Pair<Int, Long>
object Task11 : Task {
private val lcmDividers = lowestCommonMultiple(parseInput().map { it.divisibleBy })
over... | 0 | Kotlin | 0 | 0 | 3893ae1ac096c56e224e798d08d7fee60e299a84 | 2,915 | AdventCode-Kotlin | Apache License 2.0 |
src/main/kotlin/io/github/clechasseur/adventofcode/y2022/Day24.kt | clechasseur | 567,968,171 | false | {"Kotlin": 493887} | package io.github.clechasseur.adventofcode.y2022
import io.github.clechasseur.adventofcode.util.Direction
import io.github.clechasseur.adventofcode.util.Pt
import io.github.clechasseur.adventofcode.util.move
import io.github.clechasseur.adventofcode.y2022.data.Day24Data
object Day24 {
private val input = Day24Dat... | 0 | Kotlin | 0 | 0 | 7ead7db6491d6fba2479cd604f684f0f8c1e450f | 3,375 | adventofcode2022 | MIT License |
src/main/kotlin/aoc22/Day07.kt | tom-power | 573,330,992 | false | {"Kotlin": 254717, "Shell": 1026} | package aoc22
import aoc22.Day07Domain.Command
import aoc22.Day07Domain.Down
import aoc22.Day07Domain.Ls
import aoc22.Day07Domain.Cd
import aoc22.Day07Domain.Up
import aoc22.Day07Parser.parseCommands
import aoc22.Day07Solution.part1Day07
import aoc22.Day07Solution.part2Day07
import common.Year22
object Day07: Year22 ... | 0 | Kotlin | 0 | 0 | baccc7ff572540fc7d5551eaa59d6a1466a08f56 | 4,563 | aoc | Apache License 2.0 |
y2016/src/main/kotlin/adventofcode/y2016/Day13.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2016
import adventofcode.io.AdventSolution
object Day13 : AdventSolution(2016, 13, "Maze") {
var magicNumber: Int = 0
override fun solvePartOne(input: String): Int {
magicNumber = input.toInt()
return generateSequence(Solver(setOf(Cubicle(1, 1))), Solver::next)
.takeWhile { Cubicle(... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,146 | advent-of-code | MIT License |
src/main/kotlin/com/tonnoz/adventofcode23/day16/Day16Part2.kt | tonnoz | 725,970,505 | false | {"Kotlin": 78395} | package com.tonnoz.adventofcode23.day16
import com.tonnoz.adventofcode23.utils.println
import com.tonnoz.adventofcode23.utils.readCharMatrix
import kotlinx.coroutines.runBlocking
import java.lang.IllegalArgumentException
import kotlin.system.measureTimeMillis
object Day16Part2 {
@JvmStatic
fun main(args: Array<S... | 0 | Kotlin | 0 | 0 | d573dfd010e2ffefcdcecc07d94c8225ad3bb38f | 4,409 | adventofcode23 | MIT License |
src/Day04.kt | mvmlisb | 572,859,923 | false | {"Kotlin": 14994} | private fun String.parseIntRange(): IntRange {
val split = split("-")
return split.first().toInt()..split.last().toInt()
}
private fun processRanges(process: (IntRange, IntRange) -> Boolean) = readInput("Day04_test").map {
val split = it.split(",")
if (process(split.first().parseIntRange(), split.last(... | 0 | Kotlin | 0 | 0 | 648d594ec0d3b2e41a435b4473b6e6eb26e81833 | 732 | advent_of_code_2022 | Apache License 2.0 |
app/src/main/java/com/betulnecanli/kotlindatastructuresalgorithms/CodingPatterns/K-wayMerge.kt | betulnecanli | 568,477,911 | false | {"Kotlin": 167849} | /*
The "K-way Merge" coding pattern is commonly used to merge K sorted lists or arrays efficiently.
*/
//1. Kth Smallest Number in M Sorted Lists
import java.util.PriorityQueue
class ListNode(var `val`: Int) {
var next: ListNode? = null
}
fun mergeKLists(lists: Array<ListNode?>): ListNode? {
val minHeap = Pri... | 2 | Kotlin | 2 | 40 | 70a4a311f0c57928a32d7b4d795f98db3bdbeb02 | 3,488 | Kotlin-Data-Structures-Algorithms | Apache License 2.0 |
src/day14/Main.kt | nikwotton | 572,814,041 | false | {"Kotlin": 77320} | package day14
import java.io.File
import kotlin.random.Random
import kotlin.random.Random.Default
const val workingDir = "src/day14"
fun main() {
val sample = File("$workingDir/sample.txt")
val input1 = File("$workingDir/input_1.txt")
println("Step 1a: ${runStep1(sample)}") // 24
println("Step 1b: ${... | 0 | Kotlin | 0 | 0 | dee6a1c34bfe3530ae6a8417db85ac590af16909 | 4,419 | advent-of-code-2022 | Apache License 2.0 |
codeforces/round576/e.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.round576
fun main() {
val (n, rectNum) = readInts()
val rectangles = Array(rectNum) { readInts() }
val xSet = mutableSetOf(0, n)
val ySet = mutableSetOf(0, n)
for ((x1, y1, x2, y2) in rectangles) {
xSet.add(x1 - 1)
xSet.add(x2)
ySet.add(y1 - 1)
ySet.add(y2)
}
val xs = xSet.sorted()
v... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,800 | competitions | The Unlicense |
src/test/kotlin/nl/dirkgroot/adventofcode/year2022/Day05Test.kt | dirkgroot | 317,968,017 | false | {"Kotlin": 187862} | package nl.dirkgroot.adventofcode.year2022
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.shouldBe
import nl.dirkgroot.adventofcode.util.input
import nl.dirkgroot.adventofcode.util.invokedWith
private fun solution1(input: String) = pars... | 1 | Kotlin | 1 | 1 | ffdffedc8659aa3deea3216d6a9a1fd4e02ec128 | 2,922 | adventofcode-kotlin | MIT License |
2015/src/main/kotlin/com/koenv/adventofcode/Day24.kt | koesie10 | 47,333,954 | false | null | package com.koenv.adventofcode
import java.util.*
object Day24 {
fun getCombinations(choices: List<Int>, used: MutableSet<Int>, neededValue: Int, numberOfItems: Int, startIndex: Int = 0): MutableList<MutableList<Int>>? {
if (numberOfItems == 1) {
var maxSoFar = Int.MIN_VALUE
if (us... | 0 | Kotlin | 0 | 0 | 29f3d426cfceaa131371df09785fa6598405a55f | 2,582 | AdventOfCode-Solutions-Kotlin | MIT License |
hoon/HoonAlgorithm/src/main/kotlin/programmers/lv01/Lv1_77884.kt | boris920308 | 618,428,844 | false | {"Kotlin": 137657, "Swift": 35553, "Java": 1947, "Rich Text Format": 407} | package main.kotlin.programmers.lv01
import kotlin.math.sqrt
/**
*
* https://school.programmers.co.kr/learn/courses/30/lessons/77884
*
* 약수의 개수와 덧셈
* 문제 설명
* 두 정수 left와 right가 매개변수로 주어집니다.
* left부터 right까지의 모든 수들 중에서, 약수의 개수가 짝수인 수는 더하고, 약수의 개수가 홀수인 수는 뺀 수를 return 하도록 solution 함수를 완성해주세요.
*
* 제한사항
* 1 ≤ lef... | 1 | Kotlin | 1 | 2 | 88814681f7ded76e8aa0fa7b85fe472769e760b4 | 2,016 | HoOne | Apache License 2.0 |
src/main/kotlin/day9/AllInASingleNight.kt | SaujanShr | 685,121,393 | false | null | package day9
import getInput
val INPUT = getInput("day9")
fun run1(): String {
return INPUT
.getRoutes()
.getLocations()
.getOptimalDistance()
.toString()
}
fun run2(): String {
return INPUT
.getRoutes()
.getLocations()
.getLeastOptimalDistance()
... | 0 | Kotlin | 0 | 0 | c6715a9570e62c28ed022c5d9b330a10443206c4 | 1,913 | adventOfCode2015 | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/symmetric_tree/SymmetricTree.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.symmetric_tree
import katas.kotlin.leetcode.TreeNode
import datsok.shouldEqual
import org.junit.Test
import java.util.*
/**
* https://leetcode.com/problems/symmetric-tree/
*/
class SymmetricTreeTests {
@Test fun `check is tree is a mirror of itself`() {
TreeNode(1).isSymmet... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,689 | katas | The Unlicense |
src/day21/Day21.kt | ayukatawago | 572,742,437 | false | {"Kotlin": 58880} | package day21
import readInput
fun main() {
val input = readInput("day21/test")
val monkeyMap = hashMapOf<String, Monkey>()
input.forEach {
val regex = """([a-z]+): ([a-z]+) ([+\-*/]) ([a-z]+)""".toRegex()
val result = regex.matchEntire(it)?.groupValues ?: return@forEach
val monk... | 0 | Kotlin | 0 | 0 | 923f08f3de3cdd7baae3cb19b5e9cf3e46745b51 | 4,171 | advent-of-code-2022 | Apache License 2.0 |
src/test/kotlin/year2015/Day18.kt | abelkov | 47,995,527 | false | {"Kotlin": 48425} | package year2015
import kotlin.test.Test
import kotlin.test.assertEquals
private const val GRID_SIZE = 100
private const val STEPS = 100
class Day18 {
private fun getOnNeighbors(field: Array<Array<Int>>, i: Int, j: Int): Int = listOf(
field[i - 1][j - 1],
field[i - 1][j],
field[i - 1][j +... | 0 | Kotlin | 0 | 0 | 0e4b827a742322f42c2015ae49ebc976e2ef0aa8 | 3,090 | advent-of-code | MIT License |
src/main/kotlin/days/Day16.kt | felix-ebert | 317,592,241 | false | null | package days
class Day16 : Day(16) {
private val fields = mutableMapOf<String, List<IntRange>>()
private val myTicket = mutableListOf<Int>()
private val nearbyTickets = mutableListOf<List<Int>>()
init {
var isTicket = false
var isNearbyTicket = false
for (line in inputList) {... | 0 | Kotlin | 0 | 4 | dba66bc2aba639bdc34463ec4e3ad5d301266cb1 | 3,066 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/day13/Day13.kt | easchner | 572,762,654 | false | {"Kotlin": 104604} | package day13
import readInputSpaceDelimited
fun main() {
fun listCompare(a: String, b: String): Boolean? {
var at = a
var bt = b
if (a.toIntOrNull() != null && b.toIntOrNull() != null) {
if (a.toInt() < b.toInt())
return true
if (a.toInt() > b.toInt... | 0 | Kotlin | 0 | 0 | 5966e1a1f385c77958de383f61209ff67ffaf6bf | 3,808 | Advent-Of-Code-2022 | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year21/Day18.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year21
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.permPairs
fun PuzzleSet.day18() = puzzle(day = 18) {
// Parse all numbers (AST like)
val numbers = inputLines.map { SnailfishNumber.parse(it) }
// Part one
partOne = numbers.map { it.clone() }.reduce... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 5,792 | advent-of-code | The Unlicense |
2016/src/main/java/p4/Problem4.kt | ununhexium | 113,359,669 | false | null | package p4
import more.CircularList
import more.Input
val NAME = "name"
val ID = "id"
val CHECKSUM = "checksum"
val pattern = Regex("(?<$NAME>[\\p{Lower}-]+)-(?<$ID>\\p{Digit}+)\\[(?<$CHECKSUM>\\p{Lower}+)]")
val alphabet = CircularList(('a'..'z').toList())
fun shift(c: Char, amount: Int) = alphabet[c.toInt() - 'a... | 6 | Kotlin | 0 | 0 | d5c38e55b9574137ed6b351a64f80d764e7e61a9 | 2,130 | adventofcode | The Unlicense |
src/org/aoc2021/Day15.kt | jsgroth | 439,763,933 | false | {"Kotlin": 86732} | package org.aoc2021
import java.nio.file.Files
import java.nio.file.Path
import java.util.PriorityQueue
object Day15 {
data class RiskPath(val currentCost: Int, val row: Int, val col: Int)
private fun solve(lines: List<String>, shouldExpandGrid: Boolean = false): Int {
val rawGrid = parseLines(lines)... | 0 | Kotlin | 0 | 0 | ba81fadf2a8106fae3e16ed825cc25bbb7a95409 | 2,595 | advent-of-code-2021 | The Unlicense |
src/main/kotlin/com/ikueb/advent18/Day23.kt | h-j-k | 159,901,179 | false | null | package com.ikueb.advent18
import com.ikueb.advent18.model.Point3d
import kotlin.math.abs
object Day23 {
private const val DEFINITION = "pos=<([-\\d]+),([-\\d]+),([-\\d]+)>, r=(\\d+)"
fun getMostInRange(input: List<String>) = with(nanobots(input)) {
count { maxBy { bot -> bot.radius }!!.inRangeTo(it... | 0 | Kotlin | 0 | 0 | f1d5c58777968e37e81e61a8ed972dc24b30ac76 | 1,657 | advent18 | Apache License 2.0 |
day12/part2.kts | bmatcuk | 726,103,418 | false | {"Kotlin": 214659} | // --- Part Two ---
// As you look out at the field of springs, you feel like there are way more
// springs than the condition records list. When you examine the records, you
// discover that they were actually folded up this whole time!
//
// To unfold the records, on each row, replace the list of spring conditions
//... | 0 | Kotlin | 0 | 0 | a01c9000fb4da1a0cd2ea1a225be28ab11849ee7 | 2,844 | adventofcode2023 | MIT License |
src/Day09.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | import kotlin.math.abs
fun main() {
data class Point(var x: Int, var y: Int)
fun solve(input: List<String>, knots: Int): Int {
// Starting position is the "centre", with plenty of padding to avoid going into negative coordinates.
// Positive X goes right, positive Y goes up.
val rope =... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 3,168 | aoc-2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.