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/Day01.kt | mzlnk | 573,124,510 | false | {"Kotlin": 14876} | fun main() {
fun part1(input: List<String>): Int {
var max = 0
var current = 0
for(line: String in input) {
if(line.isEmpty()) {
max = Math.max(max, current)
current = 0
continue
}
current += line.toInt()
... | 0 | Kotlin | 0 | 0 | 3a8ec82e9a8b4640e33fdd801b1ef87a06fa5cd5 | 1,098 | advent-of-code-2022 | Apache License 2.0 |
letcode/src/main/java/daily/LeetCodeLCP13.kt | chengw315 | 343,265,699 | false | null | package daily
import java.util.*
fun main() {
//16
val i = SolutionLCP13().minimalSteps(arrayOf("S#O", "M..", "M.T"));
//-1
val i1 = SolutionLCP13().minimalSteps(arrayOf("S#O", "M.#", "M.T"));
//17
val i2 = SolutionLCP13().minimalSteps(arrayOf("S#O", "M.T", "M.."));
}
class SolutionLCP13 {
... | 0 | Java | 0 | 2 | 501b881f56aef2b5d9c35b87b5bcfc5386102967 | 5,994 | daily-study | Apache License 2.0 |
src/Day12.kt | anisch | 573,147,806 | false | {"Kotlin": 38951} | private typealias Area = Array<CharArray>
private fun Area.neighbors(c: Vec): List<Vec> {
val next = mutableListOf<Vec>()
val cc = when {
this[c.y][c.x] == 'S' -> 'a'
this[c.y][c.x] == 'E' -> 'z'
else -> this[c.y][c.x]
}
if (0 < c.x) {
val cl = this[c.y][c.x - 1]
... | 0 | Kotlin | 0 | 0 | 4f45d264d578661957800cb01d63b6c7c00f97b1 | 4,157 | Advent-of-Code-2022 | Apache License 2.0 |
solver/src/commonMain/kotlin/org/hildan/sudoku/solver/backtracking/Backtracking.kt | joffrey-bion | 9,559,943 | false | {"Kotlin": 51198, "HTML": 187} | package org.hildan.sudoku.solver.backtracking
import org.hildan.sudoku.model.*
private const val USE_FORWARD_CHECK = true
/** Heuristic of Most Constrained/Constraining Variables */
private const val USE_MCV_HEURISTICS = true
/** Heuristic of Least Constraining Value */
private const val USE_LCV_HEURISTIC = true
/... | 0 | Kotlin | 0 | 0 | 441fbb345afe89b28df9fe589944f40dbaccaec5 | 4,977 | sudoku-solver | MIT License |
2023/src/main/kotlin/sh/weller/aoc/Day11.kt | Guruth | 328,467,380 | false | {"Kotlin": 188298, "Rust": 13289, "Elixir": 1833} | package sh.weller.aoc
import sh.weller.aoc.util.to2DList
import kotlin.math.max
import kotlin.math.min
object Day11 : SomeDay<String, Long> {
override fun partOne(input: List<String>): Long =
calculateDistances(2, input.to2DList())
override fun partTwo(input: List<String>): Long =
calculateDi... | 0 | Kotlin | 0 | 0 | 69ac07025ce520cdf285b0faa5131ee5962bd69b | 2,165 | AdventOfCode | MIT License |
src/Day25.kt | uekemp | 575,483,293 | false | {"Kotlin": 69253} |
typealias Snafu = String
private fun Snafu.toInt(): Int {
val chars = toCharArray()
chars.reverse()
var f = 1
return chars.sumOf { c ->
val result = f * snafuToInt(c)
f *= 5
result
}
}
fun snafuToInt(digit: Char): Int {
return when(digit) {
'2' -> 2
'1'... | 0 | Kotlin | 0 | 0 | bc32522d49516f561fb8484c8958107c50819f49 | 873 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2021/2021-17.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2021
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputText
fun main() {
val input = readInputText(2021, "17-input")
val test1 = readInputText(2021, "17-test1")
print... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,858 | advent-of-code | MIT License |
jax/codeforces/uncategorized/8-kotlin/d_sweepstake.kt | jaxvanyang | 423,682,977 | false | {"C++": 1073738, "Kotlin": 10571, "Java": 8975, "Python": 3215, "Shell": 508, "Makefile": 389, "PowerShell": 341} | fun readLn() = readLine()!!
fun readStrs() = readLn().split(" ")
fun readInts() = readStrs().map { it.toInt() }
fun main() {
val (n, m) = readInts()
val a = Array(m) {
readInts()
}
val fCnt = IntArray(n + 1) { 0 }
val lCnt = IntArray(n + 1) { 0 }
val hashCnt = IntArray((n + 1) * n) { 0 }
fun hash(f: Int, l... | 0 | C++ | 0 | 0 | ee41f1cbf692b7b1463a9467401bb6e7d38aecce | 842 | acm | MIT License |
src/main/kotlin/g0401_0500/s0417_pacific_atlantic_water_flow/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0401_0500.s0417_pacific_atlantic_water_flow
// #Medium #Array #Depth_First_Search #Breadth_First_Search #Matrix
// #Graph_Theory_I_Day_4_Matrix_Related_Problems #Level_2_Day_10_Graph/BFS/DFS #Udemy_Graph
// #2022_12_06_Time_319_ms_(100.00%)_Space_37.5_MB_(100.00%)
class Solution {
private var col = 0
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,103 | LeetCode-in-Kotlin | MIT License |
math/FastFourierTransform.kt | wangchaohui | 737,511,233 | false | {"Kotlin": 36737} | data class Complex(
val re: Double = 0.0,
val im: Double = 0.0,
) {
operator fun plus(other: Complex) = Complex(re + other.re, im + other.im)
operator fun minus(other: Complex) = Complex(re - other.re, im - other.im)
operator fun times(other: Double) = Complex(re * other, im * other)
operator fu... | 0 | Kotlin | 0 | 0 | 241841f86fdefa9624e2fcae2af014899a959cbe | 2,164 | kotlin-lib | Apache License 2.0 |
lib/src/main/kotlin/com/github/xmppjingle/bayes/GaussianNaiveBayes.kt | xmppjingle | 583,324,456 | false | {"Kotlin": 35890} | package com.github.xmppjingle.bayes
import org.apache.commons.math3.stat.descriptive.moment.Variance
import kotlin.math.ln
import kotlin.math.pow
class GaussianDistribution(val mean: Double, val std: Double) {
fun probability(x: Double): Double {
val exponent = -(x - mean).pow(2.0) / (2.0 * std.pow(2.0))... | 0 | Kotlin | 1 | 0 | 9c0057acb21e8f32bd083c71b6532efe92ae5513 | 2,696 | homework | Apache License 2.0 |
src/main/kotlin/com/marcdenning/adventofcode/day18/Day18b.kt | marcdenning | 317,730,735 | false | {"Kotlin": 87536} | package com.marcdenning.adventofcode.day18
import java.io.File
fun main(args: Array<String>) {
val sum = File(args[0]).readLines().map { evaluateExpressionInverse(it) }.sum()
println("Sum of all operations: $sum")
}
fun evaluateExpressionInverse(expression: String) = evaluateExpressionTree(buildTreeFromExpr... | 0 | Kotlin | 0 | 0 | b227acb3876726e5eed3dcdbf6c73475cc86cbc1 | 1,981 | advent-of-code-2020 | MIT License |
calendar/day04/Day4.kt | divgup92 | 573,352,419 | false | {"Kotlin": 15497} | package day04
import Day
import Lines
import kotlin.streams.toList
class Day4 : Day() {
override fun part1(input: Lines) = input.stream().map { line -> getPairs(line) }.filter { pairs -> isFullOverlap(pairs) }.toList().count()
private fun getPairs(input: String) = input.split(",").stream().map { i -> i.spli... | 0 | Kotlin | 0 | 0 | dcd221197ecb374efa030a7993a0152099409f14 | 1,035 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/adventofcode2020/solution/Day2.kt | lhess | 320,667,380 | false | null | package adventofcode2020.solution
import adventofcode2020.Solution
import adventofcode2020.resource.PuzzleInput
class Day2(puzzleInput: PuzzleInput<String>) : Solution<String, Int>(puzzleInput) {
private val passwords = puzzleInput.map(Password::of)
override fun runPart1() =
passwords.count { (range,... | 0 | null | 0 | 1 | cfc3234f79c27d63315994f8e05990b5ddf6e8d4 | 1,102 | adventofcode2020 | The Unlicense |
aoc-2023/src/main/kotlin/aoc/aoc21.kts | triathematician | 576,590,518 | false | {"Kotlin": 615974} | import aoc.AocParser.Companion.parselines
import aoc.*
import aoc.util.*
val testInput = """
...........
.....###.#.
.###.##..#.
..#.#...#..
....#.#....
.##..S####.
.##..#...#.
.......##..
.##.#.####.
.##..##.##.
...........
""".parselines
// part 1
fun List<String>.part1(): Int {
val grid = GridBlinker(this, fi... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 6,552 | advent-of-code | Apache License 2.0 |
src/day01/Day01.kt | Dr4kn | 575,092,295 | false | {"Kotlin": 12652} | package day01
import readInput
fun main() {
fun part1(input: List<String>): Int {
var maxValue = 0
var currentValue = 0
input.forEachIndexed { index, value ->
if (value != "") {
currentValue += value.toInt()
}
if (value == "" || index =... | 0 | Kotlin | 0 | 0 | 6de396cb4eeb27ff0dd9a98b56e68a13c2c90cd5 | 1,378 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g0101_0200/s0109_convert_sorted_list_to_binary_search_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0101_0200.s0109_convert_sorted_list_to_binary_search_tree
// #Medium #Tree #Binary_Tree #Linked_List #Binary_Search_Tree #Divide_and_Conquer
// #2023_07_11_Time_191_ms_(100.00%)_Space_39.5_MB_(61.54%)
import com_github_leetcode.ListNode
import com_github_leetcode.TreeNode
/*
* Example:
* var li = ListNode... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,690 | LeetCode-in-Kotlin | MIT License |
src/Day04.kt | cerberus97 | 579,910,396 | false | {"Kotlin": 11722} | fun main() {
fun parseRange(range: String): IntRange {
val lo = range.substringBefore('-').toInt()
val hi = range.substringAfter('-').toInt()
return IntRange(lo, hi)
}
fun IntRange.contains(other: IntRange): Boolean = contains(other.first) && contains(other.last)
fun IntRange.overlaps(other: IntRa... | 0 | Kotlin | 0 | 0 | ed7b5bd7ad90bfa85e868fa2a2cdefead087d710 | 1,038 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/theo/TheoPcpK.kt | sssemil | 268,084,789 | false | null | package theo
import kotlin.math.abs
class TheoPcpK {
private fun visit(
instances: List<Instance>,
visitedStates: MutableList<Instance>,
initialState: Instance,
k: Int,
trace: List<Instance>
): List<List<Instance>?> {
val currentState = initialState.reduce()
... | 0 | Kotlin | 0 | 0 | 02d951b90e0225bb1fa36f706b19deee827e0d89 | 3,084 | math_playground | MIT License |
2017-kotlin/src/main/kotlin/com/morninghacks/aoc2017/Day07.kt | whaley | 116,508,747 | false | null | package com.morninghacks.aoc2017
import java.lang.invoke.MethodHandles
private data class NodeFromLine(val id: String, val weight: Int, val childIds: List<String>)
private data class Node(val id: String, val weight: Int, var children: List<Node> = listOf(), val parent: Node? = null) {
fun treeWeight() : Int = we... | 0 | Kotlin | 0 | 0 | 16ce3c9d6310b5faec06ff580bccabc7270c53a8 | 3,505 | advent-of-code | MIT License |
src/main/kotlin/days/Day10.kt | hughjdavey | 572,954,098 | false | {"Kotlin": 61752} | package days
import xyz.hughjd.aocutils.Collections.stackOf
import xyz.hughjd.aocutils.Tuples.product
class Day10 : Day(10) {
val program = inputList.map {
if (it == "noop") Noop() else {
val parts = it.split(" ")
AddX(v = parts[1].toInt())
}
}
override fun partOn... | 0 | Kotlin | 0 | 2 | 65014f2872e5eb84a15df8e80284e43795e4c700 | 2,748 | aoc-2022 | Creative Commons Zero v1.0 Universal |
kotlin/src/com/s13g/aoc/aoc2021/Day23.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2021
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import kotlin.math.max
import kotlin.math.min
/**
* --- Day 23: Amphipod ---
* https://adventofcode.com/2021/day/23
*/
class Day23 : Solver {
companion object {
val podCost = mutableMapOf(
"A" to 1,
"B" to 10,
... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 7,615 | euler | Apache License 2.0 |
src/main/kotlin/fr/pturpin/coursera/dynprog/ArithmeticExpression.kt | TurpIF | 159,055,822 | false | null | package fr.pturpin.coursera.dynprog
class ArithmeticExpression(private val strExpression: String) {
private val cache = ArrayList<MutableList<MinMaxExpression?>>(strExpression.length)
fun getMaximumValue(): Long {
clearCache()
return computeCachedMaximumValue(0, strExpression.length).maxExpre... | 0 | Kotlin | 0 | 0 | 86860f8214f9d4ced7e052e008b91a5232830ea0 | 3,653 | coursera-algo-toolbox | MIT License |
2021/14/kotlin/solve.kts | gugod | 48,180,404 | false | {"Raku": 170466, "Perl": 121272, "Kotlin": 58674, "Rust": 3189, "C": 2934, "Zig": 850, "Clojure": 734, "Janet": 703, "Go": 595} |
import java.io.File
val lines = File(args[0]).readLines()
val polymers = lines[0]
val rules = lines.slice(2..lines.lastIndex).map { it.split(" -> ") }.associate { it[0] to it[1] }
var freq = hashMapOf<String,Long>()
polymers.windowed(2).forEach {
freq.set(it, 1 + freq.getOrDefault(it, 0))
}
freq.set("_" + polym... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 1,201 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/Day03.kt | Jaavv | 571,865,629 | false | {"Kotlin": 14896} | // https://adventofcode.com/2022/day/3
fun main() {
val input = readInput("Day03")
val testinput = readInput("Day03_test")
println(day03part1(input)) //7691
println(day03part2(input)) //2508
}
val lowerPriority = ('a'..'z').mapIndexed { index, c -> c to index + 1 }.toMap()
val upperPriority = ('A'..'Z... | 0 | Kotlin | 0 | 0 | 5ef23a16d13218cb1169e969f1633f548fdf5b3b | 884 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CountSortedVowelStrings.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 | 4,698 | kotlab | Apache License 2.0 |
src/main/kotlin/days/Day5.kt | hughjdavey | 572,954,098 | false | {"Kotlin": 61752} | package days
import xyz.hughjd.aocutils.Collections.split
import java.util.Stack
class Day5 : Day(5) {
private val inputs = inputList.split("")
private val moves = getMoves(inputs[1])
override fun partOne(): Any {
return moveStacks(this::move9000)
}
override fun partTwo(): Any {
... | 0 | Kotlin | 0 | 2 | 65014f2872e5eb84a15df8e80284e43795e4c700 | 2,126 | aoc-2022 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SumOfRootToLeafBinaryNumbers.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 | 5,701 | kotlab | Apache License 2.0 |
src/main/kotlin/graph/variation/ShortestMidPoint.kt | yx-z | 106,589,674 | false | null | package graph.variation
import graph.core.Vertex
import graph.core.WeightedEdge
import graph.core.WeightedGraph
import graph.core.dijkstra
import util.max
// given an undirected weighted graph, a starting point s, and another starting
// point t, find a vertex v that minimize the total cost from s to v and t to v
fun... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 1,227 | AlgoKt | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/RemoveDuplicateLetters.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,912 | kotlab | Apache License 2.0 |
src/Day01.kt | Pixselve | 572,907,486 | false | {"Kotlin": 7404} | fun main() {
fun part1(input: List<String>): Int {
var max = 0
var current = 0
for (s in input) {
if (s.isEmpty()) {
max = current.coerceAtLeast(max)
current = 0
continue
}
current += s.toInt()
}
... | 0 | Kotlin | 0 | 0 | 10e14393b8b6ee3f98dfd4c37e32ad81f9952533 | 1,032 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/java/leetcode/a167_twoSumInputSortArray_SIMPLE/Solution.kt | Laomedeia | 122,696,571 | true | {"Java": 801075, "Kotlin": 38473, "JavaScript": 8268} | package leetcode.a167_twoSumInputSortArray_SIMPLE
/**
* 两数之和 II - 输入有序数组
*
给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数。
函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 index2。
说明:
返回的下标值(index1 和 index2)不是从零开始的。
你可以假设每个输入只对应唯一的答案,而且你不可以重复使用相同的元素。
示例:
输入: numbers = [2, 7, 11, 15], target = 9
输出: [1,2]
解释: 2 与 7 之和等于目标数 9 。因此... | 0 | Java | 0 | 0 | 0dcd8438e0846493ced9c1294ce686bac34c8614 | 1,900 | Java8InAction | MIT License |
src/main/kotlin/g1901_2000/s1938_maximum_genetic_difference_query/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1901_2000.s1938_maximum_genetic_difference_query
// #Hard #Array #Bit_Manipulation #Trie #2023_06_20_Time_855_ms_(100.00%)_Space_84.4_MB_(100.00%)
class Solution {
fun maxGeneticDifference(parents: IntArray, queries: Array<IntArray>): IntArray {
val n = parents.size
val fd = arrayOfNulls<... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,597 | LeetCode-in-Kotlin | MIT License |
src/test/kotlin/ch/ranil/aoc/aoc2023/Types.kt | stravag | 572,872,641 | false | {"Kotlin": 234222} | package ch.ranil.aoc.aoc2023
import org.junit.jupiter.api.Test
import kotlin.math.abs
import kotlin.test.assertEquals
import kotlin.test.assertTrue
interface Coordinate : Comparable<Coordinate> {
val x: Int
val y: Int
override fun compareTo(other: Coordinate): Int {
return compareValuesBy(this, o... | 0 | Kotlin | 1 | 0 | dbd25877071cbb015f8da161afb30cf1968249a8 | 2,647 | aoc | Apache License 2.0 |
src/util/Grid.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package util
import kotlin.math.max
import kotlin.math.min
typealias Pos = Pair<Int, Int>
typealias PosL = Pair<Long, Long>
operator fun Pos.plus(b: Pos) = this.first + b.first to this.second + b.second
operator fun PosL.minus(b: PosL) = this.first + b.first to this.second + b.second
operator fun Pos.times(b: Int) ... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 4,903 | advent-of-code | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2022/Day21.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2022
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import com.s13g.aoc.resultFrom
/**
* --- Day 21: Monkey Math ---
* https://adventofcode.com/2022/day/21
*/
class Day21 : Solver {
override fun solve(lines: List<String>): Result {
val monkeysA = parse(lines)
settle(monkeys... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 4,356 | euler | Apache License 2.0 |
aoc-2021/src/commonMain/kotlin/fr/outadoc/aoc/twentytwentyone/Day09.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwentyone
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.product
import fr.outadoc.aoc.scaffold.readDayInput
import kotlin.jvm.JvmInline
class Day09 : Day<Int> {
private companion object {
const val MAX_HEIGHT = 9
}
private val heightMap: HeightMap... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 2,247 | adventofcode | Apache License 2.0 |
src/Day10.kt | hottendo | 572,708,982 | false | {"Kotlin": 41152} | private class Tube(val cycles: IntArray) {
var cycleCount = 0
var register = 1
var signalStrength = 0
val screen = CharArray(240) { '.' }
fun calculateSignalStrength(): Int {
var signalStrength = 0
if (cycleCount in cycles) {
signalStrength = register * cycleCount
... | 0 | Kotlin | 0 | 0 | a166014be8bf379dcb4012e1904e25610617c550 | 2,926 | advent-of-code-2022 | Apache License 2.0 |
day07/src/main/kotlin/ver_b.kt | jabbalaci | 115,397,721 | false | null | package b
import java.io.File
object Tree {
private val nodes = mutableMapOf<String, Node>()
fun add(node: Node) {
this.nodes[node.name] = node
}
fun getNodeByName(name: String): Node? {
return this.nodes.getOrDefault(name, null)
}
fun getAllNodes(): List<Node> {
re... | 0 | Kotlin | 0 | 0 | bce7c57fbedb78d61390366539cd3ba32b7726da | 3,514 | aoc2017 | MIT License |
plugin/src/main/kotlin/net/siggijons/gradle/graphuntangler/graph/GraphUntangler.kt | siggijons | 615,653,143 | false | {"Kotlin": 47826} | package net.siggijons.gradle.graphuntangler.graph
import org.jgrapht.GraphMetrics
import org.jgrapht.alg.TransitiveReduction
import org.jgrapht.alg.scoring.BetweennessCentrality
import org.jgrapht.graph.AbstractGraph
import org.jgrapht.graph.AsSubgraph
import org.jgrapht.graph.DirectedAcyclicGraph
import org.jgrapht.t... | 2 | Kotlin | 1 | 31 | 1e154a8eb0541192219dac33449c949857552731 | 7,540 | graph-untangler-plugin | Apache License 2.0 |
Dynamic Programming/Longest Palindromic Subsequence/test/HiddenTests.kt | jetbrains-academy | 515,621,972 | false | {"Kotlin": 123026, "TeX": 51581, "Java": 3566, "Python": 1156, "CSS": 671} | import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import kotlin.math.max
import kotlin.random.Random
import kotlin.time.Duration.Companion.seconds
class HiddenTests {
companion... | 2 | Kotlin | 0 | 10 | a278b09534954656175df39601059fc03bc53741 | 6,403 | algo-challenges-in-kotlin | MIT License |
leetcode/kotlin/find-all-anagrams-in-a-string.kt | PaiZuZe | 629,690,446 | false | null | class Solution {
fun findAnagrams(s: String, p: String): List<Int> {
if (p.length > s.length) {
return listOf<Int>()
}
val pCharFrequencies = IntArray(26) { 0 }
val sCharFrequencies = IntArray(26) { 0 }
initCharFreqs(s, p, sCharFrequencies, pCharFrequencies)
... | 0 | Kotlin | 0 | 0 | 175a5cd88959a34bcb4703d8dfe4d895e37463f0 | 1,360 | interprep | MIT License |
src/Day04.kt | chasegn | 573,224,944 | false | {"Kotlin": 29978} |
/**
* Day 04 for Advent of Code 2022
* https://adventofcode.com/2022/day/4
*/
class Day04 : Day {
override val inputFileName: String = "Day04"
override val test1Expected: Int = 2
override val test2Expected: Int = 4
/**
* Accepted solution: 644
*/
override fun part1(input: List<String>... | 0 | Kotlin | 0 | 0 | 2b9a91f083a83aa474fad64f73758b363e8a7ad6 | 1,600 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day6.kt | jgrgt | 433,952,606 | false | {"Kotlin": 113705} | package days
class Day6 : Day(6) {
override fun partOne(): Any {
return p1(inputList, 80)
}
fun p1(inputList: List<String>, days: Int): Long {
val times = inputList[0].split(",").map { it.toInt() }
val startPopulation = Population(
age0 = times.count { it == 0 }.toLong(... | 0 | Kotlin | 0 | 0 | 6231e2092314ece3f993d5acf862965ba67db44f | 2,009 | aoc2021 | Creative Commons Zero v1.0 Universal |
day-25/src/main/kotlin/SeaCucumber.kt | diogomr | 433,940,168 | false | {"Kotlin": 92651} | import kotlin.system.measureTimeMillis
fun main() {
val partOneMillis = measureTimeMillis {
println("Part One Solution: ${partOne()}")
}
println("Part One Solved in: $partOneMillis ms")
val partTwoMillis = measureTimeMillis {
println("Part Two Solution: ${partTwo()}")
}
println... | 0 | Kotlin | 0 | 0 | 17af21b269739e04480cc2595f706254bc455008 | 2,445 | aoc-2021 | MIT License |
Collections/Max min/src/Task.kt | diskostu | 554,658,487 | false | {"Kotlin": 36179} | // Return a customer who has placed the maximum amount of orders
fun Shop.getCustomerWithMaxOrders(): Customer? =
customers.maxByOrNull { it.orders.size }
// Return the most expensive product that has been ordered by the given customer
fun getMostExpensiveProductBy(customer: Customer): Product? =
customer.orde... | 0 | Kotlin | 0 | 0 | 3cad6559e1add8d202e15501165e2aca0ee82168 | 1,548 | Kotlin_Koans | MIT License |
app/src/main/kotlin/advent/of/code/day04/Day04.kt | dbubenheim | 321,117,765 | false | null | package advent.of.code.day04
import advent.of.code.enumContains
import advent.of.code.toURL
import com.google.common.base.Splitter
import java.io.File
class Day04 {
companion object {
@JvmStatic
fun passportProcessing(validator : (Map<String, Any>) -> Validator) : Long {
val splitte... | 5 | Kotlin | 0 | 0 | c3b173fa5d579e0d3ba217319caf5e8cd090063f | 3,563 | advent-of-code-2020 | MIT License |
src/main/kotlin/ru/glukhov/aoc/Day9.kt | cobaku | 576,736,856 | false | {"Kotlin": 25268} | package ru.glukhov.aoc
import java.io.BufferedReader
import kotlin.math.abs
private class Field {
val head: Position = Position(0, 0)
val tail: Position = Position(0, 0)
private var oldDirection: Boolean? = true
fun apply(input: String) {
val (changeX, value) = input.parse()
val in... | 0 | Kotlin | 0 | 0 | a40975c1852db83a193c173067aba36b6fe11e7b | 2,493 | aoc2022 | MIT License |
src/questions/MinDeletionUniqueFrequency.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
/**
* Minimum Deletions to Make Character Frequencies Unique
*
* A string s is called good if there are no two different characters in s that have the same frequency.
* Given a string s, return the minimum number of characters you nee... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 1,646 | algorithms | MIT License |
src/leetcode_daily_chalange/InsertDeleteGetrandomO1.kt | faniabdullah | 382,893,751 | false | null | //Implement the RandomizedSet class:
//
//
// RandomizedSet() Initializes the RandomizedSet object.
// bool insert(int val) Inserts an item val into the set if not present.
//Returns true if the item was not present, false otherwise.
// bool remove(int val) Removes an item val from the set if present. Returns
//tr... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 3,194 | dsa-kotlin | MIT License |
algorithms/src/main/kotlin/org/baichuan/sample/algorithms/leetcode/simple/interview/MajorityElement.kt | scientificCommunity | 352,868,267 | false | {"Java": 154453, "Kotlin": 69817} | package org.baichuan.sample.algorithms.leetcode.simple.interview
/**
* 面试题 17.10. 主要元素
* https://leetcode.cn/problems/find-majority-element-lcci/
*/
class MajorityElement {
/**
* 摩尔投票解法
* 遍历,并对不同的元素进行抵消。
* 核心思路是:
* 1. **如果y的个数超过数组一半大小**,则经过抵消后剩下的数一定是y。
* 2. 如果个数超过一半大小的数不存在。则抵消后最后剩... | 1 | Java | 0 | 8 | 36e291c0135a06f3064e6ac0e573691ac70714b6 | 1,095 | blog-sample | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2022/Day16.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2022
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import com.s13g.aoc.resultFrom
import kotlin.math.max
/**
* --- Day 16: Proboscidea Volcanium ---
* https://adventofcode.com/2022/day/16
*/
class Day16 : Solver {
private val cache = mutableMapOf<String, Int>()
override fun solv... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 2,633 | euler | Apache License 2.0 |
src/main/kotlin/asaad/DayThree.kt | Asaad27 | 573,138,684 | false | {"Kotlin": 23483} | package asaad
import java.io.File
class DayThree(filePath: String) {
private val file = File(filePath)
private val input = readInput(file)
private fun readInput(file: File) = file.readLines()
private fun Char.toPriority(): Int = when {
this.isLowerCase() -> this - 'a' + 1
this.isUppe... | 0 | Kotlin | 0 | 0 | 16f018731f39d1233ee22d3325c9933270d9976c | 1,558 | adventOfCode2022 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FurthestBuilding.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 | 10,549 | kotlab | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2023/Day16.kt | tginsberg | 723,688,654 | false | {"Kotlin": 112398} | /*
* Copyright (c) 2023 by <NAME>
*/
/**
* Advent of Code 2023, Day 16 - The Floor Will Be Lava
* Problem Description: http://adventofcode.com/2023/day/16
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2023/day16/
*/
package com.ginsberg.advent2023
import com.ginsberg.advent2023.Point2D.C... | 0 | Kotlin | 0 | 12 | 0d5732508025a7e340366594c879b99fe6e7cbf0 | 2,499 | advent-2023-kotlin | Apache License 2.0 |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[643]子数组最大平均数 I.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给定 n 个整数,找出平均数最大且长度为 k 的连续子数组,并输出该最大平均数。
//
//
//
// 示例:
//
//
//输入:[1,12,-5,-6,50,3], k = 4
//输出:12.75
//解释:最大平均数 (12-5-6+50)/4 = 51/4 = 12.75
//
//
//
//
// 提示:
//
//
// 1 <= k <= n <= 30,000。
// 所给数据范围 [-10,000,10,000]。
//
// Related Topics 数组
// 👍 164 👎 0
//leetcode submit region begin(Prohibit mo... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,040 | MyLeetCode | Apache License 2.0 |
src/day07/Day07.kt | tschens95 | 573,743,557 | false | {"Kotlin": 32775} | package day07
import readInput
fun main() {
val totalSize = 70000000
val requiredSpace = 30000000
var mapDirectoryToSizeLimited = listOf<Int>()
var mapDirectoryToSize = listOf<Int>()
val root = Directory("/")
fun findDirectoriesWithSize(iterateDirectory: Directory, maxSize: Int) {
if... | 0 | Kotlin | 0 | 2 | 9d78a9bcd69abc9f025a6a0bde923f53c2d8b301 | 4,048 | AdventOfCode2022 | Apache License 2.0 |
dataStructuresAndAlgorithms/src/main/java/dev/funkymuse/datastructuresandalgorithms/trie/Trie.kt | FunkyMuse | 168,687,007 | false | {"Kotlin": 1728251} | package dev.funkymuse.datastructuresandalgorithms.trie
class Trie<Key> {
private val storedLists: MutableSet<List<Key>> = mutableSetOf()
val lists get() = storedLists.toList()
val count
get() = storedLists.count()
val isEmpty
get() = storedLists.isEmpty()
val isNotEmpty get() =... | 0 | Kotlin | 92 | 771 | e2afb0cc98c92c80ddf2ec1c073d7ae4ecfcb6e1 | 2,203 | KAHelpers | MIT License |
src/day2/day2s.kt | bienenjakob | 573,125,960 | false | {"Kotlin": 53763} | package day2
import inputTextOfDay
import testTextOfDay
const val rock = 1
const val paper = 2
const val scissors = 3
const val loose = 0
const val draw = 3
const val win = 6
fun part1s(text: String): Int = text.lines().sumOf {
when (it) {
// rock
"A X" -> rock + draw
"A Y" -> paper + wi... | 0 | Kotlin | 0 | 0 | 6ff34edab6f7b4b0630fb2760120725bed725daa | 1,178 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day7.kt | tpepper0408 | 317,612,203 | false | null | package days
class Day7 : Day<Int>(7) {
override fun partOne(): Int {
val colourMap = HashMap<String, List<Pair<String, Int>>>()
inputList.map { row ->
val (colour, childrenString) = row.split("bags contain")
.map { it.trim() }
val children: List<Pair<Str... | 0 | Kotlin | 0 | 0 | 67c65a9e93e85eeb56b57d2588844e43241d9319 | 2,705 | aoc2020 | Creative Commons Zero v1.0 Universal |
src/day01.kt | skuhtic | 572,645,300 | false | {"Kotlin": 36109} | fun main() {
day01.execute(forceBothParts = true)
}
val day01 = object : Day<Int>(1, 24000, 45000) {
override val testInput: InputData
get() = """
1000
2000
3000
4000
5000
6... | 0 | Kotlin | 0 | 0 | 8de2933df90259cf53c9cb190624d1fb18566868 | 1,060 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/dev/paulshields/aoc/day3/TobogganTrajectory.kt | Pkshields | 318,658,287 | false | null | package dev.paulshields.aoc.day3
import dev.paulshields.aoc.common.divideRoundingUp
import dev.paulshields.aoc.common.readFileAsStringList
fun main() {
println(" ** Day 3: Toboggan Trajectory ** \n")
val map = readFileAsStringList("/day3/Map.txt")
val result = generateSlopePath(1, 3, map)
.calcu... | 0 | Kotlin | 0 | 0 | a7bd42ee17fed44766cfdeb04d41459becd95803 | 1,463 | AdventOfCode2020 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ReorganizeString.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,545 | kotlab | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/greedy/NaiveHuffmanEncode.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.greedy
/**
* abacabad
* 4 14
* a: 0
* b: 10
* c: 110
* d: 111
* 01001100100111
*/
fun main() {
val s = "abacabad"
val letterToFreq = getLetterToFrequency(s = s)
val letterWeightStack = getLetterWeightStack(letterToFreq = letterToFreq)
val huffma... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 3,203 | algs4-leprosorium | MIT License |
src/day02/Day02.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day02
import readInput
enum class OpponentShape {
ROCK(),
PAPER(),
SCISSORS();
companion object {
fun getShape(shape: String): OpponentShape =
when (shape) {
"A" -> ROCK
"B" -> PAPER
"C" -> SCISSORS
else -> th... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 4,560 | AdventOfCode2022 | Apache License 2.0 |
leetcode/kotlin/most-stones-removed-with-same-row-or-column.kt | PaiZuZe | 629,690,446 | false | null | class Solution {
fun removeStones(stones: Array<IntArray>): Int {
val unionFind = IntArray(stones.size) { it }
val height = IntArray(stones.size) { 0 }
var resp = stones.size
for (i in 0 until stones.size) {
for (j in 0 until stones.size) {
if (isNeighbor... | 0 | Kotlin | 0 | 0 | 175a5cd88959a34bcb4703d8dfe4d895e37463f0 | 2,259 | interprep | MIT License |
src/main/kotlin/no/chriswk/aoc2019/Day12.kt | chriswk | 225,314,163 | false | null | package no.chriswk.aoc2019
class Day12 {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day12 = Day12()
report { day12.part1() }
report { day12.part2() }
}
}
fun part1(): Int {
val locations = parseLocations("day12.txt... | 0 | Kotlin | 0 | 0 | 14b527889b63952c2fba473a8da4ce37071a65bd | 1,923 | adventofcode2019 | MIT License |
day11/src/Day11.kt | simonrules | 491,302,880 | false | {"Kotlin": 68645} | import java.io.File
class Day11(private val path: String) {
private var map = mutableListOf<Int>()
private var flashMap: BooleanArray
private var height = 0
private var width = 0
init {
var i = 0
var j = 0
File(path).forEachLine { line ->
j = line.length
... | 0 | Kotlin | 0 | 0 | d9e4ae66e546f174bcf66b8bf3e7145bfab2f498 | 3,384 | aoc2021 | Apache License 2.0 |
src/main/kotlin/Puzzle19.kt | namyxc | 317,466,668 | false | null | object Puzzle19 {
@JvmStatic
fun main(args: Array<String>) {
val input = Puzzle19::class.java.getResource("puzzle19.txt").readText()
val calculatedMatchingStringCount = countMatchingStrings(input,Puzzle19::useSameRules)
println(calculatedMatchingStringCount)
val calculatedMatchi... | 0 | Kotlin | 0 | 0 | 60fa6991ac204de6a756456406e1f87c3784f0af | 4,400 | adventOfCode2020 | MIT License |
Contest/Biweekly Contest 82/Minimum Sum of Squared Difference/MinSumSquaredDiff.kt | xuedong | 189,745,542 | false | {"Kotlin": 332182, "Java": 294218, "Python": 237866, "C++": 97190, "Rust": 82753, "Go": 37320, "JavaScript": 12030, "Ruby": 3367, "C": 3121, "C#": 3117, "Swift": 2876, "Scala": 2868, "TypeScript": 2134, "Shell": 149, "Elixir": 130, "Racket": 107, "Erlang": 96, "Dart": 65} | class Solution {
fun minSumSquareDiff(nums1: IntArray, nums2: IntArray, k1: Int, k2: Int): Long {
val n = nums1.size
val differences = IntArray(n)
for (i in 0..n-1) {
differences[i] = Math.abs(nums1[i]-nums2[i])
}
val frequencies: MutableMap<Int,... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 2,040 | leet-code | MIT License |
src/main/kotlin/de/nosswald/aoc/days/Day01.kt | 7rebux | 722,943,964 | false | {"Kotlin": 34890} | package de.nosswald.aoc.days
import de.nosswald.aoc.Day
// https://adventofcode.com/2023/day/1
object Day01 : Day<Int>(1, "Trebuchet?!") {
private val digitsMap = mapOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"five" to 5,
"six" to 6,
"sev... | 0 | Kotlin | 0 | 1 | 398fb9873cceecb2496c79c7adf792bb41ea85d7 | 1,946 | advent-of-code-2023 | MIT License |
src/Day01.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | fun main() {
val testInput = readInput("Day01_test")
check(part1(testInput) == 24000)
check(part2(testInput) == 45000)
val input = readInput("Day01")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>): Int {
return input
.partitionBy { it.isEmpty()... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 592 | aoc-22 | Apache License 2.0 |
calendar/day14/Day14.kt | starkwan | 573,066,100 | false | {"Kotlin": 43097} | package day14
import Day
import Lines
class Day14 : Day() {
override fun part1(input: Lines): Any {
val wall = Wall(input)
val firstSandToFlowOver = { sand: Point -> sand.y >= wall.globalMaxY }
return wall.simulate(firstSandToFlowOver) - 1
}
override fun part2(input: Lines): Any {... | 0 | Kotlin | 0 | 0 | 13fb66c6b98d452e0ebfc5440b0cd283f8b7c352 | 2,815 | advent-of-kotlin-2022 | Apache License 2.0 |
src/Day04.kt | hijst | 572,885,261 | false | {"Kotlin": 26466} | fun main() {
fun IntRange.contains(other: IntRange) = first <= other.first && last >= other.last
fun IntRange.overlaps(other: IntRange) = !(first > other.last || last < other.first)
fun part1(input: List<Pair<IntRange, IntRange>>): Int =
input.count { pair ->
pair.first.contains(pair.s... | 0 | Kotlin | 0 | 0 | 2258fd315b8933642964c3ca4848c0658174a0a5 | 738 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/XorAllNums.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,966 | kotlab | Apache License 2.0 |
src/main/kotlin/day2/Solution.kt | krazyglitch | 573,086,664 | false | {"Kotlin": 31494} | package day2
import util.Utils
import java.lang.IllegalArgumentException
import java.time.Duration
import java.time.LocalDateTime
class Solution {
/** A = rock, B = paper, C = scissors
*
* First task:
* Assume second parameter maps to rock, paper, scissors.
* X = rock, Y = paper, Z... | 0 | Kotlin | 0 | 0 | db6b25f7668532f24d2737bc680feffc71342491 | 3,051 | advent-of-code2022 | MIT License |
src/main/kotlin/dev/paulshields/aoc/day6/CustomCustoms.kt | Pkshields | 318,658,287 | false | null | package dev.paulshields.aoc.day6
import dev.paulshields.aoc.common.readFileAsString
fun main() {
println(" ** Day 6: Customs Customs ** \n")
val delimiterBetweenCustomsForms = "\n\n"
val rawAnswersToCustomDeclaration = readFileAsString("/day6/CustomsDeclarationForms.txt")
.split(delimiterBetweenC... | 0 | Kotlin | 0 | 0 | a7bd42ee17fed44766cfdeb04d41459becd95803 | 1,586 | AdventOfCode2020 | MIT License |
leetcode/src/tree/Q145.kt | zhangweizhe | 387,808,774 | false | null | package tree
import linkedlist.TreeNode
import java.util.*
import kotlin.collections.ArrayList
fun main() {
// 145. 二叉树的后序遍历
// https://leetcode-cn.com/problems/binary-tree-postorder-traversal/
val root = TreeNode(1)
root.left = TreeNode(2)
root.left?.left = TreeNode(3)
root.right = TreeNode... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 4,077 | kotlin-study | MIT License |
advent/src/test/kotlin/org/elwaxoro/advent/y2015/Dec14.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2015
import org.elwaxoro.advent.PuzzleDayTester
import kotlin.math.min
/**
* Reindeer Olympics
*/
class Dec14 : PuzzleDayTester(14, 2015) {
override fun part1(): Any = parse().let { reindeer ->
reindeer.maxOf {
it.distanceTraveled(2503)
}
}
/**
... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 1,909 | advent-of-code | MIT License |
src/day7/Code.kt | fcolasuonno | 162,470,286 | false | null | package day7
import java.io.File
fun main(args: Array<String>) {
val name = if (false) "test.txt" else "input.txt"
val dir = ::main::class.java.`package`.name
val input = File("src/$dir/$name").readLines()
val parsed = parse(input)
println("Part 1 = ${part1(parsed)}")
println("Part 2 = ${part2... | 0 | Kotlin | 0 | 0 | 24f54bf7be4b5d2a91a82a6998f633f353b2afb6 | 3,957 | AOC2015 | MIT License |
src/main/kotlin/year2022/day-23.kt | ppichler94 | 653,105,004 | false | {"Kotlin": 182859} | package year2022
import lib.Grid2d
import lib.Position
import lib.aoc.Day
import lib.aoc.Part
import lib.math.Itertools
import lib.math.Vector
fun main() {
Day(23, 2022, PartA23(), PartB23()).run()
}
open class PartA23 : Part() {
private lateinit var elfs: MutableSet<Position>
private lateinit var direct... | 0 | Kotlin | 0 | 0 | 49dc6eb7aa2a68c45c716587427353567d7ea313 | 2,876 | Advent-Of-Code-Kotlin | MIT License |
day19/Part2.kt | anthaas | 317,622,929 | false | null | import java.io.File
fun main(args: Array<String>) {
val input = File("input2.txt").bufferedReader().use { it.readText() }.split("\n\n")
val rules = input[0].split("\n").associate { it.split(": ").let { (left, right) -> left.toInt() to right } }.toMutableMap().toSortedMap()
//hack to skip recursion
(0 u... | 0 | Kotlin | 0 | 0 | aba452e0f6dd207e34d17b29e2c91ee21c1f3e41 | 1,319 | Advent-of-Code-2020 | MIT License |
src/main/kotlin/aoc2016/GridComputing.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2016
import komu.adventofcode.utils.Direction
import komu.adventofcode.utils.Direction.DOWN
import komu.adventofcode.utils.Direction.RIGHT
import komu.adventofcode.utils.Point
import komu.adventofcode.utils.nonEmptyLines
fun gridComputing1(input: String) =
Grid.parse(input).viablePair... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 4,038 | advent-of-code | MIT License |
dataStructuresAndAlgorithms/src/main/java/dev/funkymuse/datastructuresandalgorithms/Utils.kt | FunkyMuse | 168,687,007 | false | {"Kotlin": 1728251} | package dev.funkymuse.datastructuresandalgorithms
import dev.funkymuse.datastructuresandalgorithms.sort.selectionSort
import java.util.Collections
internal fun <T> List<T>.swap(i: Int, j: Int): List<T> {
if (isInBounds(i) && isInBounds(j)) {
Collections.swap(this, i, j)
}
return this
}
private f... | 0 | Kotlin | 92 | 771 | e2afb0cc98c92c80ddf2ec1c073d7ae4ecfcb6e1 | 2,128 | KAHelpers | MIT License |
day07/src/main/kotlin/Main.kt | ickybodclay | 159,694,344 | false | null | import java.io.File
fun main() {
val input = File(ClassLoader.getSystemResource("input.txt").file)
val stepRegex = Regex("Step ([A-Z]) must be finished before step ([A-Z]) can begin.")
val stepMap = mutableMapOf<String, ArrayList<String>>()
input.readLines().map {
val stepMatch = stepRegex.ma... | 0 | Kotlin | 0 | 0 | 9a055c79d261235cec3093f19f6828997b7a5fba | 2,451 | aoc2018 | Apache License 2.0 |
src/main/kotlin/13-jun.kt | aladine | 276,334,792 | false | {"C++": 70308, "Kotlin": 53152, "Java": 10020, "Makefile": 511} | class Solution13jun {
fun largestDivisibleSubset(nums: IntArray): List<Int> {
if (nums.isEmpty()) return emptyList()
var l = Array(nums.size) { _ -> 1 }
nums.sort()
var maxSoFar = 0
var maxIndex: Int = -1
for ((i, v) in nums.withIndex()) {
// or for i in ... | 0 | C++ | 1 | 1 | 54b7f625f6c4828a72629068d78204514937b2a9 | 1,141 | awesome-leetcode | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem1287/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1287
/**
* LeetCode page: [1287. Element Appearing More Than 25% In Sorted Array](https://leetcode.com/problems/element-appearing-more-than-25-in-sorted-array/);
*/
class Solution {
/* Complexity:
* Time O(LogN) and Space O(1) where N is the size of arr;
*/
fun... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,036 | hj-leetcode-kotlin | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/medium/LetterCombinations.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode.medium
/**
* 17. 电话号码的字母组合
*
* 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。
* 给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。
*/
class LetterCombinations {
companion object {
@JvmStatic
fun main(args: Array<String>) {
LetterCombinations().letterCombinat... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 1,990 | daily_algorithm | Apache License 2.0 |
core/src/main/kotlin/com/bsse2018/salavatov/flt/algorithms/CYK.kt | vsalavatov | 241,599,920 | false | {"Kotlin": 149462, "ANTLR": 1960} | package com.bsse2018.salavatov.flt.algorithms
import com.bsse2018.salavatov.flt.grammars.ContextFreeGrammar
import com.bsse2018.salavatov.flt.grammars.ContextFreeGrammar.Companion.Epsilon
fun CYKQuery(cnfGrammar: ContextFreeGrammar, query: List<String>): Boolean {
if (query.isEmpty()) {
return cnfGrammar.... | 0 | Kotlin | 0 | 1 | c1c229c113546ef8080fc9d3568c5024a22b80a5 | 1,484 | bsse-2020-flt | MIT License |
src/main/kotlin/io/github/vihangpatil/kotlintricks/range/RangeExtensions.kt | vihangpatil | 149,867,318 | false | null | package io.github.vihangpatil.kotlintricks.range
/**
* @param[other] [ClosedRange]<[T]>
* @return [Boolean] if this [Comparable]<[T]> overlaps with [other]
*/
private fun <T : Comparable<T>> ClosedRange<T>.overlapsWith(
other: ClosedRange<T>
): Boolean {
return (other.start in start..endInclusive || oth... | 0 | Kotlin | 0 | 1 | d1f3da3796f4339d5c7e964d0d39db2ece2c7290 | 3,212 | kotlin-tricks | MIT License |
src/Day10.kt | a2xchip | 573,197,744 | false | {"Kotlin": 37206} | fun main() {
fun part1(input: List<String>): Int {
val cycles = mutableListOf<Int>()
val crt = MutableList(240) { Char(0) }
var register = 1
for (c in input) {
cycles.add(register)
if (c.startsWith("noop")) continue
val value = c.split(" ").last()... | 0 | Kotlin | 0 | 2 | 19a97260db00f9e0c87cd06af515cb872d92f50b | 940 | kotlin-advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/days/Day01.kt | julia-kim | 435,257,054 | false | {"Kotlin": 15771} | package days
import readInput
fun main() {
fun part1(input: List<String>): Int {
val it = input.map { it.toInt() }.iterator()
var count = 0
var previousDepthMeasurement = it.next()
while (it.hasNext()) {
val depthMeasurement = it.next()
if (depthMeasurement ... | 0 | Kotlin | 0 | 0 | 5febe0d5b9464738f9a7523c0e1d21bd992b9302 | 1,196 | advent-of-code-2021 | Apache License 2.0 |
25.kt | pin2t | 725,922,444 | false | {"Kotlin": 48856, "Go": 48364, "Shell": 54} | class Day25 {
val connections = HashMap<String, ArrayList<String>>()
fun run() {
while (true) {
var line = readlnOrNull() ?: break
val items = Regex("[a-z]+").findAll(line).map { it.value }.toList()
connections[items[0]] = ArrayList(items.subList(1, items.size))
... | 0 | Kotlin | 1 | 0 | 7575ab03cdadcd581acabd0b603a6f999119bbb6 | 2,008 | aoc2023 | MIT License |
src/main/kotlin/day14/Code.kt | fcolasuonno | 317,324,330 | false | null | package day14
import isDebug
import java.io.File
fun main() {
val name = if (isDebug()) "test.txt" else "input.txt"
System.err.println(name)
val dir = ::main::class.java.`package`.name
val input = File("src/main/kotlin/$dir/$name").readLines()
val parsed = parse(input)
part1(parsed)
part2(... | 0 | Kotlin | 0 | 0 | e7408e9d513315ea3b48dbcd31209d3dc068462d | 2,169 | AOC2020 | MIT License |
src/main/kotlin/adventofcode/year2023/Day02CubeConundrum.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2023
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import adventofcode.common.product
class Day02CubeConundrum(customInput: PuzzleInput? = null) : Puzzle(customInput) {
override fun partOne() = input
.lines()
.map(Game::invoke)
.filter { game -> game.i... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 1,934 | AdventOfCode | MIT License |
src/main/kotlin/g2801_2900/s2827_number_of_beautiful_integers_in_the_range/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2801_2900.s2827_number_of_beautiful_integers_in_the_range
// #Hard #Dynamic_Programming #Math #2023_12_18_Time_169_ms_(100.00%)_Space_38.7_MB_(100.00%)
import kotlin.math.max
@Suppress("kotlin:S107")
class Solution {
private lateinit var dp: Array<Array<Array<Array<IntArray>>>>
private var maxLength... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,591 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/g1801_1900/s1883_minimum_skips_to_arrive_at_meeting_on_time/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1883_minimum_skips_to_arrive_at_meeting_on_time
// #Hard #Array #Dynamic_Programming #2023_06_22_Time_278_ms_(100.00%)_Space_44.2_MB_(100.00%)
class Solution {
fun minSkips(dist: IntArray, speed: Int, hoursBefore: Int): Int {
val len = dist.size
// dp[i][j] finish ith road, ski... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,091 | LeetCode-in-Kotlin | MIT License |
core-kotlin-modules/core-kotlin-collections-map/src/test/kotlin/com/baeldung/frequencymap/FrequencyMapUnitTest.kt | Baeldung | 260,481,121 | false | {"Kotlin": 1476024, "Java": 43013, "HTML": 4883} | package com.baeldung.frequencymap
import org.junit.Test
import java.util.*
import kotlin.test.assertEquals
class FrequencyMapUnitTest {
@Test
fun `test frequency map using mutable map method`() {
val list = listOf(1, 2, 1, 3, 2, 4, 4, 7, 9, 7, 3, 2, 1)
val expectedMap = mapOf(1 to 3, 2 to 3, ... | 10 | Kotlin | 273 | 410 | 2b718f002ce5ea1cb09217937dc630ff31757693 | 3,944 | kotlin-tutorials | MIT License |
src/main/kotlin/g2301_2400/s2398_maximum_number_of_robots_within_budget/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2301_2400.s2398_maximum_number_of_robots_within_budget
// #Hard #Array #Binary_Search #Heap_Priority_Queue #Prefix_Sum #Sliding_Window #Queue
// #2023_07_02_Time_507_ms_(100.00%)_Space_48.9_MB_(100.00%)
class Solution {
// use sliding window to track the largest in a way that the sliding window only grow... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,054 | LeetCode-in-Kotlin | MIT License |
day15/Kotlin/day15.kt | Ad0lphus | 353,610,043 | false | {"C++": 195638, "Python": 139359, "Kotlin": 80248} | import java.io.*
import java.util.*
fun print_day_15() {
val yellow = "\u001B[33m"
val reset = "\u001b[0m"
val green = "\u001B[32m"
println(yellow + "-".repeat(25) + "Advent of Code - Day 15" + "-".repeat(25) + reset)
println(green)
val process = Runtime.getRuntime().exec("figlet Chiton -c -f sm... | 0 | C++ | 0 | 0 | 02f219ea278d85c7799d739294c664aa5a47719a | 2,298 | AOC2021 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.