path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/main/kotlin/g1701_1800/s1707_maximum_xor_with_an_element_from_array/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1701_1800.s1707_maximum_xor_with_an_element_from_array
// #Hard #Array #Bit_Manipulation #Trie #2023_06_15_Time_1295_ms_(100.00%)_Space_130.3_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
internal class QueryComparator : Comparator<IntArray> {
override fun compare(a: IntArray, b: IntA... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,576 | LeetCode-in-Kotlin | MIT License |
src/Day06.kt | iProdigy | 572,297,795 | false | {"Kotlin": 33616} | fun main() {
fun solve(input: String, n: Int) = input
.windowedSequence(n) { it.toHashSet() }
.indexOfFirst { it.size >= n } + n
fun part1(input: String) = solve(input, 4)
fun part2(input: String) = solve(input, 14)
// test if implementation meets criteria from the description, like:
... | 0 | Kotlin | 0 | 1 | 784fc926735fc01f4cf18d2ec105956c50a0d663 | 942 | advent-of-code-2022 | Apache License 2.0 |
src/day07/Day07.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day07
import readInput
import java.util.*
enum class NodeType {
DIR, FILE
}
data class MyNode(
val name: String,
val type: NodeType,
val parent: MyNode? = null,
val child: Stack<MyNode> = Stack<MyNode>(),
var size: Long = 0L
) {
override fun toString(): String {
return "$n... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 5,528 | aoc-2022-kotlin | Apache License 2.0 |
src/main/aoc2015/Day5.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2015
class Day5(val input: List<String>) {
private fun String.isNice(): Boolean {
var numVowels = 0
var twiceInARow = false
val blacklist = setOf("ab", "cd", "pq", "xy")
val vowels = setOf('a', 'e', 'i', 'o', 'u')
for (i in indices) {
if (i > 0) {
... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,843 | aoc | MIT License |
src/test/kotlin/chapter4/solutions/ex7/listing.kt | DavidGomesh | 680,857,367 | false | {"Kotlin": 204685} | package chapter4.solutions.ex7
import chapter3.Cons
import chapter3.List
import chapter3.Nil
import chapter4.Either
import chapter4.Left
import chapter4.Right
import chapter4.map2
import io.kotest.matchers.shouldBe
import io.kotest.core.spec.style.WordSpec
class Solution7 : WordSpec({
//tag::init[]
fun <E, A... | 0 | Kotlin | 0 | 0 | 41fd131cd5049cbafce8efff044bc00d8acddebd | 2,162 | fp-kotlin | MIT License |
kotlin/combinatorics/Partitions.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package combinatorics
import numeric.FFT
import optimization.Simplex
// https://en.wikipedia.org/wiki/Partition_(number_theory)
object Partitions {
fun nextPartition(p: List<Integer>): Boolean {
val n: Int = p.size()
if (n <= 1) return false
var s: Int = p.remove(n - 1) - 1
var i =... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 3,351 | codelibrary | The Unlicense |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions26.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import com.qiaoyuang.algorithm.round0.BinaryTreeNode
fun test26() {
val (head0, head1) = testCase1()
printlnResult(head0, head1)
val (head2, head3) = testCase2()
printlnResult(head2, head3)
val (head4, head5) = testCase3()
printlnResult(head4, head5)
... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 3,145 | Algorithm | Apache License 2.0 |
src/day10/Day10.kt | ZsemberiDaniel | 159,921,870 | false | null | package day10
import RunnablePuzzleSolver
import java.lang.Math.abs
import java.lang.StringBuilder
import java.util.regex.Pattern
class Day10 : RunnablePuzzleSolver {
lateinit var movingLights: Array<MovingLight>
var part2Solution: Int = -1
override fun readInput1(lines: Array<String>) {
val rege... | 0 | Kotlin | 0 | 0 | bf34b93aff7f2561f25fa6bd60b7c2c2356b16ed | 3,626 | adventOfCode2018 | MIT License |
mps-analyser/src/main/kotlin/nl/dslconsultancy/mps/analyser/projectOnDisk.kt | dslmeinte | 131,405,227 | false | null | package nl.dslconsultancy.mps.analyser
import nl.dslconsultancy.mps.analyser.util.asList
import nl.dslconsultancy.mps.analyser.util.csvRowOf
import nl.dslconsultancy.mps.analyser.xml.languageMetaDataXmlFromDisk
import java.nio.file.Files
import java.nio.file.Path
data class MpsProjectOnDisk(val mpsFiles: List<Path>,... | 2 | JetBrains MPS | 2 | 10 | 17b3014ebb78cb299844d8b8c284557f30ee211b | 1,686 | mps-open-source | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions44.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
import com.qiaoyuang.algorithm.round0.BinaryTreeNode
import com.qiaoyuang.algorithm.round0.Queue
fun test44() {
printlnResult(binaryTreeTestCase1())
printlnResult(binaryTreeTestCase2())
}
/**
* Questions 44: Find the biggest values every line in a binary tree
*/
priv... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,563 | Algorithm | Apache License 2.0 |
src/main/kotlin/dayFolders/day5/letterCombinationsOfPhone.kt | lilimapradhan9 | 255,344,059 | false | null | package dayFolders.day5
val digitToLetterMap = 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('m', 'n', 'o'),
7 to listOf('p', 'q', 'r', 's'),
8 to listOf('t', 'u', 'v'),
9 to listOf('w', 'x', 'y', 'z')
... | 0 | Kotlin | 0 | 0 | 356cef0db9f0ba1106c308d33c13358077aa0674 | 906 | kotlin-problems | MIT License |
src/Day10.kt | Akhunzaada | 573,119,655 | false | {"Kotlin": 23755} | class CPU {
private var register = 1
private var cycles = 0
fun exec(program: List<String>, op: (register: Int, cycles: Int) -> Unit) {
program.forEach {
op(register, ++cycles)
if (it.startsWith("addx")) {
op(register, ++cycles)
register += it... | 0 | Kotlin | 0 | 0 | b2754454080989d9579ab39782fd1d18552394f0 | 1,187 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/be/inniger/euler/problems01to10/Problem04.kt | bram-inniger | 135,620,989 | false | {"Kotlin": 20003} | package be.inniger.euler.problems01to10
import be.inniger.euler.util.isPalindrome
private const val BIGGEST_N_DIGIT_NUMBER = 999
private const val SMALLEST_N_DIGIT_NUMBER = 100
/**
* Largest palindrome product
*
* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2... | 0 | Kotlin | 0 | 0 | 8fea594f1b5081a824d829d795ae53ef5531088c | 685 | euler-kotlin | MIT License |
src/Day17.kt | Aldas25 | 572,846,570 | false | {"Kotlin": 106964} | import kotlin.math.max
fun main() {
val rocks: List<Array<Array<Boolean>>> = listOf(
// rock 1
arrayOf(arrayOf(true, true, true, true)),
// rock 2
arrayOf(
arrayOf(false, true, false),
arrayOf(true, true, true),
arrayOf(false, true, false)
... | 0 | Kotlin | 0 | 0 | 80785e323369b204c1057f49f5162b8017adb55a | 6,586 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/kotlin/dataModel/v3/AccumulatedTaxBracketV2.kt | daniel-rusu | 669,564,782 | false | {"Kotlin": 70755} | package dataModel.v3
import dataModel.v3.AccumulatedTaxBracketV2.Companion.toAccumulatedBracketsV2
import dataModel.base.Money
import dataModel.base.Money.Companion.dollars
import dataModel.base.Percent
import dataModel.base.TaxBracket
import solutions.linear.computeBracketTax
/**
* Similar to [TaxBracket] except th... | 0 | Kotlin | 0 | 1 | 166d8bc05c355929ffc5b216755702a77bb05c54 | 2,107 | tax-calculator | MIT License |
hand-ins/app/src/main/java/com/example/handins/hand_in_1.kt | Josef-TL | 751,238,665 | false | {"Kotlin": 11689} | package com.example.handins
import java.util.Scanner
fun main(){
checkAge()
val max : Int = getMax(1,18,8);
val min : Int = getMin(1,18,-8);
println(max); //18
println(min); //-8
val numList: List<Int> = listOf(0,-12,4,6,123)
println("Average of the list ${numList} is: " + calculateAverag... | 0 | Kotlin | 0 | 0 | f613326087e43ea6553a03ac30becf0d23f99478 | 4,454 | app-dev | MIT License |
src/Day10.kt | li-xin-yi | 573,617,763 | false | {"Kotlin": 23422} | fun main() {
fun solvePart1(input: List<String>): Int {
var res = 0
var time = 0
var value = 1
var i = 0
for (line in input) {
val inst = line.split(" ")
val newTime = time + inst.size
if (newTime >= 20 + i * 40) {
res += v... | 0 | Kotlin | 0 | 1 | fb18bb7e462b8b415875a82c5c69962d254c8255 | 1,476 | AoC-2022-kotlin | Apache License 2.0 |
kotlin/src/katas/kotlin/eightQueen/EightQueen21.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.eightQueen
import datsok.shouldEqual
import org.junit.Test
class EightQueen21 {
@Test fun `find positions of queens so that they don't attack each other`() {
Board(size = 0).findPositions().toList() shouldEqual listOf(Board(size = 0))
Board(size = 1).findPositions().toList() s... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,670 | katas | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SlidingWindowMax.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,775 | kotlab | Apache License 2.0 |
src/main/kotlin/com/mhv2109/difflib/SequenceMatcher.kt | mhv2109 | 155,640,302 | false | null | package com.mhv2109.difflib
private data class QueueElem(
val alo: Int,
val ahi: Int,
val blo: Int,
val bhi: Int
)
/**
* Kotlin implementation of Python difflib.SequenceMatcher.
*
* From difflib docs:
*
* The basic algorithm predates, and is a little fancier than, an algorithm published in the late 1980's by... | 2 | Kotlin | 0 | 1 | 73b83a5eb87440a53171aedcff634e9d542710cb | 8,482 | difflib | MIT License |
CombinacionesPalabras/src/main/java/Main.kt | ariannysOronoz | 603,181,296 | false | null | package com.includehelp.basic
import java.util.*
/* fun main(args: Array<String>) {
val num = 10
var i = 1
var factorial: Long = 1
while (i <= num) {
factorial *= i.toLong()
i++
}
println(" El Factorial de $num = $factorial")
}*/
// Kotlin... | 0 | Kotlin | 0 | 0 | a779f54a7ca7db9e377e2b911a101daaababf84c | 2,034 | tutorialKotlin | MIT License |
src/day06/Day06.kt | schrami8 | 572,631,109 | false | {"Kotlin": 18696} | package day06
import readInput
fun String.isUniqueCharacters() = toSet().size == length
// better to use https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/windowed.html
fun getStartOfMessageMarker(line: String, differentChars: Int): Int {
var i = 0
while (i + differentChars <= line.length) {
i... | 0 | Kotlin | 0 | 0 | 215f89d7cd894ce58244f27e8f756af28420fc94 | 1,384 | advent-of-code-kotlin | Apache License 2.0 |
src/advent/of/code/EightPuzzle.kt | 1nco | 725,911,911 | false | {"Kotlin": 112713, "Shell": 103} | package advent.of.code
import java.util.*
class EightPuzzle {
companion object {
private val day = "8";
private var input: MutableList<String> = arrayListOf();
private var result = 0L;
private var resultSecond = 0L;
private var instructions: String = "";
priva... | 0 | Kotlin | 0 | 0 | 0dffdeba1ebe0b44d24f94895f16f0f21ac8b7a3 | 4,837 | advent-of-code | Apache License 2.0 |
kotlin/structures/PersistentTree.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package structures
import numeric.FFT
import optimization.Simplex
// https://en.wikipedia.org/wiki/Persistent_data_structure
object PersistentTree {
fun build(left: Int, right: Int): Node {
if (left == right) return Node(0)
val mid = left + right shr 1
return Node(build(left, mid), build(m... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,704 | codelibrary | The Unlicense |
src/main/kotlin/com/ab/advent/day04/Models.kt | battagliandrea | 574,137,910 | false | {"Kotlin": 27923} | package com.ab.advent.day04
data class Assignment(val start: Int, val end: Int){
private val range = start..end
fun containsAll(other: Assignment) = range.intersect(other.range).size == other.range.count()
fun containsAny(other: Assignment) = range.intersect(other.range).isNotEmpty()
companion object... | 0 | Kotlin | 0 | 0 | cb66735eea19a5f37dcd4a31ae64f5b450975005 | 911 | Advent-of-Kotlin | Apache License 2.0 |
src/chapter1/section4/ex8.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter1.section4
/**
* 编写一个程序,计算输入文件中相等的整数对的数量。
* 如果你的第一个程序是平方级别的,请继续思考并用Array.sort()给出一个线性对数级别的答案。
*/
fun ex8a(array: IntArray): Long {
var count = 0L
for (i in array.indices) {
for (j in i + 1 until array.size) {
if (array[i] == array[j]) {
count++
... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,368 | Algorithms-4th-Edition-in-Kotlin | MIT License |
app/src/main/kotlin/kotlinadventofcode/2023/2023-23.kt | pragmaticpandy | 356,481,847 | false | {"Kotlin": 1003522, "Shell": 219} | // Originally generated by the template in CodeDAO
package kotlinadventofcode.`2023`
import com.github.h0tk3y.betterParse.combinators.*
import com.github.h0tk3y.betterParse.grammar.*
import com.github.h0tk3y.betterParse.lexer.*
import kotlinadventofcode.Day
import kotlinadventofcode.UI.UI
class `2023-23` : Day {
... | 0 | Kotlin | 0 | 3 | 26ef6b194f3e22783cbbaf1489fc125d9aff9566 | 27,937 | kotlinadventofcode | MIT License |
src/main/kotlin/net/mguenther/adventofcode/day12/Graph.kt | mguenther | 115,937,032 | false | null | package net.mguenther.adventofcode.day12
import java.util.Optional
import java.util.Queue
import java.util.concurrent.LinkedBlockingQueue
/**
* @author <NAME> (<EMAIL>)
*/
class UndirectedGraph(val resourceFile: String) {
private val adjacencyList: Map<Int, List<Int>> = load()
fun sizeOfConnectedComponen... | 0 | Kotlin | 0 | 0 | c2f80c7edc81a4927b0537ca6b6a156cabb905ba | 2,378 | advent-of-code-2017 | MIT License |
common/iteration/src/main/kotlin/com/curtislb/adventofcode/common/iteration/Permutations.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.common.iteration
/**
* Returns a [Sequence] of all ordered permutations of the elements in this list.
*/
fun <T> List<T>.permutations(): Sequence<List<T>> =
if (isEmpty()) {
emptySequence()
} else {
permutationsRecursive(prefix = mutableListOf(), usedIndices ... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 1,141 | AdventOfCode | MIT License |
src/main/kotlin/g1401_1500/s1482_minimum_number_of_days_to_make_m_bouquets/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1401_1500.s1482_minimum_number_of_days_to_make_m_bouquets
// #Medium #Array #Binary_Search #Binary_Search_II_Day_7
// #2023_06_13_Time_538_ms_(50.00%)_Space_53_MB_(83.33%)
class Solution {
fun minDays(bloomDay: IntArray, m: Int, k: Int): Int {
if (bloomDay.size < m.toLong() * k) return -1
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,361 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/d13/D13.kt | MTender | 734,007,442 | false | {"Kotlin": 108628} | package d13
fun parseInput(lines: List<String>): List<List<String>> {
return lines.split { it.isEmpty() }
}
fun equalRows(pattern: List<String>, i1: Int, i2: Int): Boolean {
return pattern[i1] == pattern[i2]
}
fun equalCols(pattern: List<String>, i1: Int, i2: Int): Boolean {
return pattern.all { it[i1] =... | 0 | Kotlin | 0 | 0 | a6eec4168b4a98b73d4496c9d610854a0165dbeb | 1,194 | aoc2023-kotlin | MIT License |
src/day3/result.kt | davidcurrie | 437,645,413 | false | {"Kotlin": 37294} | package day3
import java.io.File
import kotlin.reflect.KFunction1
fun main() {
val lines = File("src/day3/input.txt")
.readLines()
.map { line -> line.toList().map { char -> Character.getNumericValue(char) } }
val columns = lines.transpose()
println(columns.map { it.gamma() }.toDecimal() *... | 0 | Kotlin | 0 | 0 | dd37372420dc4b80066efd7250dd3711bc677f4c | 1,089 | advent-of-code-2021 | MIT License |
src/main/kotlin/g0801_0900/s0865_smallest_subtree_with_all_the_deepest_nodes/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0865_smallest_subtree_with_all_the_deepest_nodes
// #Medium #Hash_Table #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
// #2023_04_04_Time_147_ms_(100.00%)_Space_35.1_MB_(55.56%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Defini... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,758 | LeetCode-in-Kotlin | MIT License |
src/day8/day8.kt | Eynnzerr | 576,874,345 | false | {"Kotlin": 23356} | package day8
import java.io.File
import kotlin.math.max
fun main() {
var count = 0
var maxScore = 0
val matrix = File("src/day8/input.txt")
.readLines() // List<String>
.map { s ->
s.toCharArray().map { c ->
c.digitToInt()
}
} // List<List<... | 0 | Kotlin | 0 | 0 | 92e85d65f62900d98284cbc9f6f9a3010efb21b7 | 2,269 | advent-of-code-2022 | Apache License 2.0 |
src/Day15.kt | frozbiz | 573,457,870 | false | {"Kotlin": 124645} | import java.lang.Math.min
import kotlin.math.absoluteValue
class MultiRange {
val rangeList = mutableListOf<IntRange>()
operator fun plusAssign(range: IntRange) {
add(range)
}
operator fun plus(range: IntRange): MultiRange {
val ret = MultiRange()
ret.rangeList.addAll(rangeLis... | 0 | Kotlin | 0 | 0 | 4feef3fa7cd5f3cea1957bed1d1ab5d1eb2bc388 | 6,756 | 2022-aoc-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ProductExceptSelf.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,374 | kotlab | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2015/2015-05.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2015
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
fun main() {
val input = readInputLines(2015, "05-input")
val test1 = readInputLines(2015, "05-test1")
val test2 = readInputLines(2015, "05-test2")
p... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,253 | advent-of-code | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2016/Day22.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2016
import se.saidaspen.aoc.util.*
import kotlin.math.abs
fun main() = Day22.run()
object Day22 : Day(2016, 22) {
override fun part1(): Any {
val disk = mutableMapOf<P<Int, Int>, P<Int, Int>>()
input.lines().drop(2).map {
val (x, y, _, used, avail) = ints... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,496 | adventofkotlin | MIT License |
kotlin/2021/qualification-round/cheating-detection/src/main/kotlin/ConsideringIfCheatingSolution.kts | ShreckYe | 345,946,821 | false | null | import kotlin.math.exp
import kotlin.math.ln
fun main() {
val t = readLine()!!.toInt()
val p = readLine()!!.toInt()
repeat(t, ::testCase)
}
fun testCase(ti: Int) {
val results = List(100) {
readLine()!!.map { it - '0' }
}
// simple estimation by averaging
val ss = results.map {
... | 0 | Kotlin | 1 | 1 | 743540a46ec157a6f2ddb4de806a69e5126f10ad | 1,696 | google-code-jam | MIT License |
src/main/kotlin/adventofcode/y2021/Day04.kt | Tasaio | 433,879,637 | false | {"Kotlin": 117806} | import adventofcode.parseNumbersToSingleInt
import java.lang.RuntimeException
fun main() {
val day = Day04()
println(day.part1())
day.reset()
println(day.part2())
}
class Day04 : Y2021Day(4) {
private val input = fetchInput()
private val numbers = input[0].split(",").map { it.parseNumbersToSi... | 0 | Kotlin | 0 | 0 | cc72684e862a782fad78b8ef0d1929b21300ced8 | 2,997 | adventofcode2021 | The Unlicense |
2023/src/main/kotlin/de/skyrising/aoc2023/day11/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2023.day11
import de.skyrising.aoc.*
val test = TestInput("""
...#......
.......#..
#.........
..........
......#...
.#........
.........#
..........
.......#..
#...#.....
""")
fun sumDistances(grid: CharGrid, scale: Int): Long {
val countRow = IntA... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 1,038 | aoc | MIT License |
src/Day08.kt | zfz7 | 573,100,794 | false | {"Kotlin": 53499} | fun main() {
println(day8A(readFile("Day08")))
println(day8B(readFile("Day08")))
}
fun visibleNorth(forest: List<List<Int>>, i: Int, j: Int): Boolean {
val height = forest[i][j]
var iPos = i -1
while(iPos >= 0){
if(forest[iPos][j] >= height)
return false
iPos--;
}
... | 0 | Kotlin | 0 | 0 | c50a12b52127eba3f5706de775a350b1568127ae | 3,355 | AdventOfCode22 | Apache License 2.0 |
2015/15/kotlin/b.kt | shrivatsas | 583,681,989 | false | {"Kotlin": 17998, "Python": 9402, "Racket": 4669, "Clojure": 2953} | import java.io.File
import kotlin.math.max
data class Ingredient(val name: String, val capacity: Int, val durability: Int, val flavor: Int, val texture: Int, val calories: Int)
fun main() {
val lines: List<String> = File("../15.input").useLines { it.toList() }
// Sugar: capacity 3, durability 0, flavor 0, textu... | 0 | Kotlin | 0 | 1 | 529a72ff55f1d90af97f8e83b6c93a05afccb44c | 1,779 | AoC | MIT License |
src/AOC2022/Day11/Day11.kt | kfbower | 573,519,224 | false | {"Kotlin": 44562} | package AOC2022.Day11
import AOC2022.readInput
fun main(){
fun part1(input: List<String>): Long {
val cycles: Int = 20
val worryDivisor: Long = 3L
val monkeyInfoList = parseMonkeys(input)
var currentWorry: Long = 0L
var newWorry: Long = 0L
var nextMonkeysWorry: Lo... | 0 | Kotlin | 0 | 0 | 48a7c563ebee77e44685569d356a05e8695ae36c | 7,381 | advent-of-code-2022 | Apache License 2.0 |
Code/LetterCombinationsPhoneNumber.kt | Guaidaodl | 26,102,098 | false | {"Java": 20880, "Kotlin": 6663, "C++": 4106, "Python": 1216} | class Solution {
private val letterMap: Map<Int, CharArray> = mapOf(
Pair(2, charArrayOf('a', 'b', 'c')),
Pair(3, charArrayOf('d', 'e', 'f')),
Pair(4, charArrayOf('g', 'h', 'i')),
Pair(5, charArrayOf('j', 'k', 'l')),
Pair(6, charArrayOf('m', 'n', 'o')),
... | 0 | Java | 0 | 0 | a5e9c36d34e603906c06df642231bfdeb0887088 | 1,205 | leetcode | Apache License 2.0 |
src/pl/shockah/aoc/y2015/Day9.kt | Shockah | 159,919,224 | false | null | package pl.shockah.aoc.y2015
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestFactory
import pl.shockah.aoc.AdventTask
import pl.shockah.aoc.UnorderedPair
import pl.shockah.aoc.expects
import pl.shockah.aoc.parse3
import... | 0 | Kotlin | 0 | 0 | 9abb1e3db1cad329cfe1e3d6deae2d6b7456c785 | 2,912 | Advent-of-Code | Apache License 2.0 |
tree/src/main/kotlin/com/seanshubin/code/structure/tree/Tree.kt | SeanShubin | 678,139,745 | false | {"Kotlin": 105240, "CSS": 4128, "Shell": 1423, "HTML": 842} | package com.seanshubin.code.structure.tree
sealed interface Tree<KeyType, ValueType> {
fun setValue(path: List<KeyType>, value: ValueType): Tree<KeyType, ValueType>
fun getValue(path: List<KeyType>): ValueType?
fun toLines(
keyOrder: Comparator<KeyType>,
keyToString: (KeyType) -> String,
... | 0 | Kotlin | 0 | 0 | f83b9e3927d41f290baa25e3ffaeaa0ab53aab47 | 3,447 | code-structure-2 | The Unlicense |
src/Day04.kt | nGoldi | 573,158,084 | false | {"Kotlin": 6839} | fun main() {
fun part1(pairs: List<String>): Int =
pairs.map { pair -> pair.split(",", "-").map { it.toInt() } }.count { (first, second, third, fourth) ->
first >= third && second <= fourth || first <= third && second >= fourth
}
fun part2(pairs: List<String>): Int =
pairs.m... | 0 | Kotlin | 0 | 0 | bc587f433aa38c4d745c09d82b7d231462f777c8 | 569 | advent-of-code | Apache License 2.0 |
src/aoc2022/day10/AoC10.kt | Saxintosh | 576,065,000 | false | {"Kotlin": 30013} | package aoc2022.day10
import readLines
sealed class Instruction {
companion object {
fun from(line: String): Instruction {
val s = line.split(" ")
return when (s[0]) {
"noop" -> Noop
"addx" -> AddX(s[1].toInt())
else -> throw Exception("Unexpected")
}
}
}
}
object Noop : Instruction()
cl... | 0 | Kotlin | 0 | 0 | 877d58367018372502f03dcc97a26a6f831fc8d8 | 1,679 | aoc2022 | Apache License 2.0 |
src/Day02.kt | hadiamin | 572,509,248 | false | null | fun main() {
fun part1(input: List<String>): Int {
var totalScore = 0
for (item in input) {
when (item) {
"A Y" -> totalScore += (2 + 6)
"B Z" -> totalScore += (3 + 6)
"C X" -> totalScore += (1 + 6)
"A Z" -> totalScore += (3... | 0 | Kotlin | 0 | 0 | e63aea2a55b629b9ac3202cdab2a59b334fb7041 | 1,233 | advent-of-code-2022-kotlin | Apache License 2.0 |
archive/2022/Day22.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | private const val EXPECTED_1 = 6032
private const val EXPECTED_2 = 5031
/**
* Very hard problem. I ended up hardcoding the cube face linking edges. Didn't have time anymore
* to clean up.
*/
private class Day22(isTest: Boolean) : Solver(isTest) {
val map = readAsString().split("\n\n")[0].split("\n").let {
... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 5,377 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/at/mpichler/aoc/solutions/year2022/Day24.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2022
import at.mpichler.aoc.lib.*
open class Part24A : PartSolution() {
private var width = 0
var height = 0
var start = 0
var goal = 0
private lateinit var blizzards: List<Blizzard>
private lateinit var blizzardIterator: BlizzardIterator
private latei... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 5,562 | advent-of-code-kotlin | MIT License |
src/main/kotlin/utils/Utils.kt | embuc | 735,933,359 | false | {"Kotlin": 110920, "Java": 60263} | package se.embuc.utils
import java.math.BigInteger
import kotlin.math.abs
import kotlin.math.sqrt
// this one is neat and simple but not fast for many numbers to check
fun isPalindrome(n: Int): Boolean {
return n.toString() == n.toString().reversed()
}
fun isPalindrome(n: String): Boolean {
return n == n.reversed... | 0 | Kotlin | 0 | 1 | 79c87068303f862037d27c1b33ea037ab43e500c | 11,955 | projecteuler | MIT License |
src/main/kotlin/com/jacobhyphenated/day22/Day22.kt | jacobhyphenated | 572,119,677 | false | {"Kotlin": 157591} | package com.jacobhyphenated.day22
import com.jacobhyphenated.Day
import java.io.File
class Day22: Day<List<Instruction>> {
override fun getInput(): List<Instruction> {
return parseInstructions(
this.javaClass.classLoader.getResource("day22/input.txt")!!.readText()
)
}
override... | 0 | Kotlin | 0 | 0 | 1a0b9cb6e9a11750c5b3b5a9e6b3d63649bf78e4 | 3,763 | advent2019 | The Unlicense |
src/main/kotlin/day13/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day13
import java.io.File
fun main() {
var points: Set<Point> = emptySet()
var foldCommands: List<FoldCommand> = emptyList()
File("src/main/kotlin/day13/input.txt").useLines { linesSequence ->
val linesIterator = linesSequence.iterator()
points = linesIterator.asSequence().takeWhi... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 1,607 | aoc-2021 | MIT License |
math/NumberTheoreticTransform.kt | wangchaohui | 737,511,233 | false | {"Kotlin": 36737} | @JvmInline
value class ModInt private constructor(val value: Int) {
operator fun plus(other: ModInt) = plus(other.value)
operator fun plus(other: Int) = from(value + other)
operator fun minus(other: ModInt) = minus(other.value)
operator fun minus(other: Int) = from(value - other)
operator fun times(... | 0 | Kotlin | 0 | 0 | 241841f86fdefa9624e2fcae2af014899a959cbe | 2,378 | kotlin-lib | Apache License 2.0 |
src/y2016/Day13.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2016
import util.Pos
import util.neighborsManhattan
import util.printMatrix
object Day13 {
fun isWall(favorite: Int, x: Int, y: Int): Boolean {
val n = x * x + 3 * x + 2 * x * y + y + y * y + favorite
val binary = n.toString(2)
return binary.count { it == '1' } % 2 == 1
}
... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 2,004 | advent-of-code | Apache License 2.0 |
Problems/Algorithms/1905. Count Sub Islands/CountSubIslands.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 countSubIslands(grid1: Array<IntArray>, grid2: Array<IntArray>): Int {
val n = grid1.size
val m = grid1[0].size
val visited = Array(n) { BooleanArray(m) { false } }
val neighbors = arrayOf(intArrayOf(0, 1), intArrayOf(0, -1), intArrayOf(1, 0), intArrayOf(-1, 0))
... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 1,748 | leet-code | MIT License |
src/main/kotlin/de/consuli/aoc/year2022/days/Day04.kt | ulischulte | 572,773,554 | false | {"Kotlin": 40404} | package de.consuli.aoc.year2022.days
import de.consuli.aoc.common.Day
class Day04 : Day(4, 2022) {
override fun partOne(testInput: Boolean): Any {
return getInput(testInput).count { sectionAssignment ->
val sections = getSections(sectionAssignment)
sections.first.first in sections.... | 0 | Kotlin | 0 | 2 | 21e92b96b7912ad35ecb2a5f2890582674a0dd6a | 1,312 | advent-of-code | Apache License 2.0 |
src/Day10.kt | maximilianproell | 574,109,359 | false | {"Kotlin": 17586} | fun main() {
fun part1(input: List<String>): Int {
var cycles = 0
var currentX = 1
var totalSignalStrength = 0
input.forEach { line ->
val instruction = if (line.contains("noop")) {
Instruction.Noop
} else {
// must be addx inst... | 0 | Kotlin | 0 | 0 | 371cbfc18808b494ed41152256d667c54601d94d | 2,975 | kotlin-advent-of-code-2022 | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/medium/Permute.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode.medium
/**
* 46. 全排列
* 给定一个不含重复数字的数组 nums ,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。
*/
class Permute {
companion object {
@JvmStatic
fun main(args: Array<String>) {
Permute().permute(intArrayOf(1, 2, 3)).forEach {
it.forEach { item ->
... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,071 | daily_algorithm | Apache License 2.0 |
src/leetcode/mayChallenge2020/weekfive/CourseSchedule.kt | adnaan1703 | 268,060,522 | false | null | package leetcode.mayChallenge2020.weekfive
import utils.println
import java.util.*
import kotlin.collections.ArrayList
fun main() {
var courses = arrayOf(intArrayOf(1, 0))
canFinish(2, courses).println() // ans: true
courses = arrayOf(intArrayOf(1, 0), intArrayOf(0, 1))
canFin... | 0 | Kotlin | 0 | 0 | e81915db469551342e78e4b3f431859157471229 | 2,842 | KotlinCodes | The Unlicense |
2023/src/main/kotlin/Day04.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | object Day04 {
fun part1(input: String): Int {
return parseScores(input)
.sumOf { if (it == 0) 0 else 1 shl (it - 1) }
}
fun part2(input: String): Int {
val scores = parseScores(input)
val memo = IntArray(scores.size)
scores.indices.reversed().forEach {
memo[it] = 1 + memo.slice(it +... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 813 | advent-of-code | MIT License |
src/Day05.kt | ChenJiaJian96 | 576,533,624 | false | {"Kotlin": 11529} | fun main() {
fun MutableList<MutableList<Char>>.addOriginChars(originData: String) {
originData.forEachIndexed { index, c ->
if (c == '[') {
this[index / 4].add(originData[index + 1])
}
}
}
fun MutableList<MutableList<Char>>.execAction(moveActions: M... | 0 | Kotlin | 0 | 0 | b1a88f437aee756548ac5ba422e2adf2a43dce9f | 2,861 | Advent-Code-2022 | Apache License 2.0 |
2021/src/test/kotlin/Day12.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import kotlin.test.Test
import kotlin.test.assertEquals
class Day12 {
data class Connection(val from: String, val to: String)
@Test
fun `run part 01`() {
val connections = getCaveConnections()
val path = mutableListOf<List<String>>()
connections.buildAllPaths("start", 1, path)
... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 1,858 | adventofcode | MIT License |
src/main/kotlin/bsu/cc/schedule/ConflictChecking.kt | JordanPaoletti | 167,065,523 | false | null | package bsu.cc.schedule
import bsu.cc.constraints.ClassConstraint
import bsu.cc.constraints.ConstraintPriority
import com.brein.time.timeintervals.collections.ListIntervalCollection
import com.brein.time.timeintervals.indexes.IntervalTree
import com.brein.time.timeintervals.indexes.IntervalTreeBuilder
import com.brein... | 4 | Kotlin | 1 | 0 | 0b17d34f45cb162e82c76546708dca0c739880ae | 4,761 | Conflict_Checker | MIT License |
shared/src/main/kotlin/adventofcode/util/algorithm/AStarSearch.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.util.algorithm
import java.util.*
interface IState {
fun getNeighbors(): Sequence<IState>
val isGoal: Boolean
val heuristic: Int
}
fun aStar(start: IState): PathfinderState? {
val openList = PriorityQueue(compareBy<PathfinderState> { it.expectedCost + it.cost })
openList.... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,814 | advent-of-code | MIT License |
AoC2021day12-PassagePathing/src/main/kotlin/Main.kt | mcrispim | 533,770,397 | false | {"Kotlin": 29888} | import java.io.File
val ways = mutableMapOf<String, MutableList<String>>()
fun main() {
val input = File("data.txt").readLines()
for (line in input) {
val (start, end) = line.split("-")
ways.getOrPut(start) { mutableListOf() }.add(end)
ways.getOrPut(end) { mutableListOf() }.add(start)... | 0 | Kotlin | 0 | 0 | ac4aa71c9b5955fa4077ae40fc7e3fc3d5242523 | 2,555 | AoC2021 | MIT License |
src/advent/of/code/FourthPuzzle.kt | 1nco | 725,911,911 | false | {"Kotlin": 112713, "Shell": 103} | package advent.of.code
class FourthPuzzle {
companion object {
private val day = "4";
private var input: MutableList<String> = arrayListOf();
private var sum = 0;
private var sumSecond = 0;
fun solve() {
input.addAll(Reader.readInput(day));
input.... | 0 | Kotlin | 0 | 0 | 0dffdeba1ebe0b44d24f94895f16f0f21ac8b7a3 | 3,723 | advent-of-code | Apache License 2.0 |
app/src/main/kotlin/com/github/ilikeyourhat/kudoku/solving/deduction/algorithm/HiddenValuesAlgorithm.kt | ILikeYourHat | 139,063,649 | false | {"Kotlin": 166134} | package com.github.ilikeyourhat.kudoku.solving.deduction.algorithm
import com.github.ilikeyourhat.kudoku.model.Region
import com.github.ilikeyourhat.kudoku.model.hint.SudokuHintGrid
import com.github.ilikeyourhat.kudoku.solving.deduction.combinations.CollectionCombinator
import java.util.Collections
class HiddenValue... | 1 | Kotlin | 0 | 0 | b234b2de2edb753844c88ea3cd573444675fc1cf | 2,143 | Kudoku | Apache License 2.0 |
src/main/kotlin/g1001_1100/s1039_minimum_score_triangulation_of_polygon/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1001_1100.s1039_minimum_score_triangulation_of_polygon
// #Medium #Array #Dynamic_Programming #2023_05_26_Time_147_ms_(100.00%)_Space_38.9_MB_(50.00%)
class Solution {
private val dp = Array(101) { IntArray(101) }
fun minScoreTriangulation(values: IntArray): Int {
val n = values.size
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 972 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/tr/emreone/adventofcode/days/Day12.kt | EmRe-One | 726,902,443 | false | {"Kotlin": 95869, "Python": 18319} | package tr.emreone.adventofcode.days
import tr.emreone.adventofcode.CacheSupport.withCaching
import tr.emreone.kotlin_utils.automation.Day
class Day12 : Day(12, 2023, "Hot Springs") {
data class State(
val charIndex: Int,
val lastGroupIndex: Int,
val lastGroupSize: Int,
val isGrou... | 0 | Kotlin | 0 | 0 | c75d17635baffea50b6401dc653cc24f5c594a2b | 3,769 | advent-of-code-2023 | Apache License 2.0 |
src/test/kotlin/be/brammeerten/y2022/Day7Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2022
import be.brammeerten.readFile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import kotlin.math.min
class Day7Test {
@Test
fun `part 1`() {
val root1 = readDirectory("2022/day7/exampleInput.txt")
Assertions.assertEquals(95437, root1.get... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 2,547 | Advent-of-Code | MIT License |
solutions/src/SeachMatrix.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | /**
* https://leetcode.com/problems/search-a-2d-matrix/
*/
class SeachMatrix {
fun searchMatrix(matrix: Array<IntArray>, target: Int) : Boolean {
if (matrix.isEmpty()) {
return false;
}
val rowToSearch = searchColumn(matrix,target,0,matrix.lastIndex)
return binarySearch... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 1,410 | leetcode-solutions | MIT License |
src/main/kotlin/co/csadev/advent2022/Day24.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2022 by <NAME>
* Advent of Code 2022, Day 24
* Problem Description: http://adventofcode.com/2021/day/24
*/
package co.csadev.advent2022
import co.csadev.adventOfCode.BaseDay
import co.csadev.adventOfCode.Resources.resourceAsList
import java.util.*
class Day24(override val input: List<String> =... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 2,909 | advent-of-kotlin | Apache License 2.0 |
Course_Schedule_II_v1.kt | xiekch | 166,329,519 | false | {"C++": 165148, "Java": 103273, "Kotlin": 97031, "Go": 40017, "Python": 22302, "TypeScript": 17514, "Swift": 6748, "Rust": 6579, "JavaScript": 4244, "Makefile": 349} | // Given the total number of courses and a list of prerequisite pairs,
// return the ordering of courses you should take to finish all courses.
class Solution {
fun findOrder(numCourses: Int, prerequisites: Array<IntArray>): IntArray {
val res = ArrayList<Int>()
val indegree = IntArray(numCourses)
... | 0 | C++ | 0 | 0 | eb5b6814e8ba0847f0b36aec9ab63bcf1bbbc134 | 1,688 | leetcode | MIT License |
src/Day14.kt | RobvanderMost-TomTom | 572,005,233 | false | {"Kotlin": 47682} | enum class Material(val char: Char) {
SAND('o'),
ROCK('#'),
AIR('.')
}
// Cave type. Index of Map is x coordinate, index in each List is y coordinate
typealias CaveMap = MutableMap<Int, MutableList<Material>>
fun main() {
fun CaveMap.print() {
println()
val maxDepth = values.maxOf { it... | 5 | Kotlin | 0 | 0 | b7143bceddae5744d24590e2fe330f4e4ba6d81c | 5,316 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | AlaricLightin | 572,897,551 | false | {"Kotlin": 87366} | fun main() {
fun getPriority(c: Char): Int {
return if (c in 'A'..'Z')
c - 'A' + 27
else
c - 'a' + 1
}
fun part1(inputFilename: String): Int {
var result = 0
getInputFile(inputFilename).forEachLine {
val set = mutableSetOf<Char>()
... | 0 | Kotlin | 0 | 0 | ee991f6932b038ce5e96739855df7807c6e06258 | 1,747 | AdventOfCode2022 | Apache License 2.0 |
src/leetcodeProblem/leetcode/editor/en/MinStack.kt | faniabdullah | 382,893,751 | false | null | //Design a stack that supports push, pop, top, and retrieving the minimum
//element in constant time.
//
// Implement the MinStack class:
//
//
// MinStack() initializes the stack object.
// void push(int val) pushes the element val onto the stack.
// void pop() removes the element on the top of the stack.
// int... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,300 | dsa-kotlin | MIT License |
src/main/kotlin/com/github/davio/aoc/y2022/Day7.kt | Davio | 317,510,947 | false | {"Kotlin": 405939} | package com.github.davio.aoc.y2022
import com.github.davio.aoc.general.Day
import com.github.davio.aoc.general.getInputAsSequence
import kotlin.system.measureTimeMillis
fun main() {
println(Day7.getResultPart1())
measureTimeMillis {
println(Day7.getResultPart2())
}.also { println("Took $it ms") }
... | 1 | Kotlin | 0 | 0 | 4fafd2b0a88f2f54aa478570301ed55f9649d8f3 | 4,605 | advent-of-code | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LongestAwesome.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,494 | kotlab | Apache License 2.0 |
src/ca/josue/taxipark/src/TaxiParkTask.kt | josue-lubaki | 428,923,506 | false | {"Kotlin": 171443} | package ca.josue.taxipark.src
/*
* Task #1. Find all the drivers who performed no trips.
*/
fun TaxiPark.findFakeDrivers(): Set<Driver> =
this.allDrivers.subtract(this.trips.map { it.driver }.toSet())
// this.allDrivers.filter {
// it !in trips.map { trip -> trip.driver }
// }.toSet()
// this.... | 0 | Kotlin | 0 | 1 | 847f7af8ba9b5712241c36ca3979e4195766b9ab | 2,848 | TaxiPark | Apache License 2.0 |
year2022/src/main/kotlin/net/olegg/aoc/year2022/day12/Day12.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2022.day12
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.Directions.Companion.NEXT_4
import net.olegg.aoc.utils.Vector2D
import net.olegg.aoc.utils.fit
import net.olegg.aoc.utils.get
import net.olegg.aoc.utils.set
import net.olegg.aoc.year2022.DayOf2022
/**
* See [Year 202... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 2,422 | adventofcode | MIT License |
src/main/kotlin/com/leetcode/random_problems/easy/substract_product_and_sum/Main.kt | frikit | 254,842,734 | false | null | package com.leetcode.random_problems.easy.substract_product_and_sum
fun main() {
println("SOLUTION 1")
println("Test case 1:")
println(Solution().subtractProductAndSum(234)) // 15
println()
println("Test case 2:")
println(Solution().subtractProductAndSum(4421)) // 21
println()
println... | 0 | Kotlin | 0 | 0 | dda68313ba468163386239ab07f4d993f80783c7 | 1,130 | leet-code-problems | Apache License 2.0 |
src/day9/Day9.kt | gautemo | 317,316,447 | false | null | package day9
import shared.getLines
fun xmasWeakness(numbers: List<Long>, preamble: Int = 25): Long{
for(i in preamble until numbers.size){
val toCheck = allPairs(numbers.take(i).takeLast(preamble))
val valid = toCheck.any { it.first + it.second == numbers[i] }
if(!valid) return numbers[i]... | 0 | Kotlin | 0 | 0 | ce25b091366574a130fa3d6abd3e538a414cdc3b | 1,436 | AdventOfCode2020 | MIT License |
src/main/kotlin/dev/austinzhu/algods/containers/util/TreePrinter.kt | AustinZhu | 287,033,539 | false | null | package dev.austinzhu.algods.containers.util
import dev.austinzhu.algods.containers.tree.AbstractBinaryTree
import dev.austinzhu.algods.containers.tree.Tree
import kotlin.math.max
interface TreePrinter<N : Tree.Node<*, *, N>> {
override fun toString(): String
fun MutableList<TreeLine>.getWidth(): Int {
... | 0 | Kotlin | 0 | 0 | e0188bad8a6519e571bdc3ee21c41764c1271f10 | 10,037 | AlgoDS | MIT License |
src/main/kotlin/com/groundsfam/advent/y2021/d02/Day02.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2021.d02
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.Direction
import com.groundsfam.advent.points.Point
import com.groundsfam.advent.asPoint
import com.groundsfam.advent.points.sum
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 1,278 | advent-of-code | MIT License |
2020/src/year2021/day03/Day03.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2021.day03
import util.readAllLines
fun main() {
//part1()
part2()
}
private fun part1() {
val input = readAllLines("test.txt")
val length = input[0].length
val zeroes = mutableListOf<Int>().also { list ->
for(i in 0 until length){
list.add(0)
}
}
... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 2,679 | adventofcode | MIT License |
kotlin/src/main/kotlin/dev/mikeburgess/euler/problems/Problem014.kt | mddburgess | 261,028,925 | false | null | package dev.mikeburgess.euler.problems
import dev.mikeburgess.euler.sequences.CollatzLengthSequence
/**
* The following iterative sequence is defined for the set of positive integers:
*
* n -> n / 2 (n is even)
* n -> 3n + 1 (n is odd)
*
* Using the rule above and starting with 13, we generate the following seq... | 0 | Kotlin | 0 | 0 | 86518be1ac8bde25afcaf82ba5984b81589b7bc9 | 962 | project-euler | MIT License |
aoc2022/aoc2022-kotlin/src/main/kotlin/de/havox_design/aoc2022/day18/BoilingBoulders.kt | Gentleman1983 | 737,309,232 | false | {"Kotlin": 746488, "Java": 441473, "Scala": 33415, "Groovy": 5725, "Python": 3319} | package de.havox_design.aoc2022.day18
import de.havox_design.aoc.utils.kotlin.model.positions.Position3d
class BoilingBoulders(private var filename: String) {
private val data = readFile()
fun processPart1(): Int =
data
.sumOf { point ->
point
.neighbou... | 4 | Kotlin | 0 | 1 | 35ce3f13415f6bb515bd510a1f540ebd0c3afb04 | 2,041 | advent-of-code | Apache License 2.0 |
src/Day20.kt | fmborghino | 573,233,162 | false | {"Kotlin": 60805} | fun main() {
val _day_ = "20"
fun log(message: Any?) {
println(message)
}
data class Node(val start: Long, val value: Long)
fun parse(input: List<String>, key: Long = 1): MutableList<Node> {
return input.mapIndexed { index, s -> Node(index.toLong(), s.toLong() * key) }.toMutableLis... | 0 | Kotlin | 0 | 0 | 893cab0651ca0bb3bc8108ec31974654600d2bf1 | 2,347 | aoc2022 | Apache License 2.0 |
src/main/kotlin/day18/part2/Part2.kt | bagguley | 329,976,670 | false | null | package day18.part2
import day18.data
fun main() {
val result = data.map{calc(it)}.sum()
println(result)
}
fun calc(string: String): Long {
var input = string
while (input.contains("(")) {
input = parse(input)
}
input = calcAdd(input)
input = calcMultiply(input)
return input.t... | 0 | Kotlin | 0 | 0 | 6afa1b890924e9459f37c604b4b67a8f2e95c6f2 | 1,538 | adventofcode2020 | MIT License |
kotlin/misc/MaximumZeroSubmatrix.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package misc
object MaximumZeroSubmatrix {
fun maximumZeroSubmatrix(a: Array<IntArray>): Int {
val R = a.size
val C: Int = a[0].length
var res = 0
val d = IntArray(C)
Arrays.fill(d, -1)
val d1 = IntArray(C)
val d2 = IntArray(C)
val st = IntArray(C)
... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,917 | codelibrary | The Unlicense |
src/Day04.kt | arturradiuk | 571,954,377 | false | {"Kotlin": 6340} | fun main() {
fun partOne(input: List<String>): Int = input.count {
val (first, second) = it.split(",").map(String::toSet)
first.containsAll(second) || second.containsAll(first)
}
fun partTwo(input: List<String>): Int = input.count {
val (first, second) = it.split(",").map(String::to... | 0 | Kotlin | 0 | 0 | 85ef357643e5e4bd2ba0d9a09f4a2d45653a8e28 | 579 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day05.kt | devheitt | 573,207,407 | false | {"Kotlin": 11944} | fun main() {
fun part1(input: List<String>): String {
val stacks = HashMap<Int, ArrayDeque<String>>()
var linesIndex = 0
var line = input[linesIndex]
while (!line.contains("1")) {
val split = line.split("")
var lineIndex = 2
var stackIndex = 0
... | 0 | Kotlin | 0 | 0 | a9026a0253716d36294709a547eaddffc6387261 | 3,209 | advent-of-code-2022-kotlin | Apache License 2.0 |
benchmark/src/test/kotlin/me/leon/translate/IcibaVocabulary.kt | Leon406 | 381,644,086 | false | {"Kotlin": 1392660, "JavaScript": 96128, "Java": 16541, "Batchfile": 4706, "Shell": 259, "CSS": 169} | package me.leon.translate
data class IcibaVocabulary(
val phrase: List<Phrase>?,
val derivation: List<Derivation>?,
val baesInfo: BaesInfo?,
) {
fun phraseInfo() = phrase?.joinToString(System.lineSeparator()) { it.info() }.orEmpty()
data class BaesInfo(
val word_name: String?,
val... | 4 | Kotlin | 236 | 1,218 | dde1cc6e8e589f4a46b89e2e22918e8b789773e4 | 2,990 | ToolsFx | ISC License |
src/main/kotlin/adventofcode/year2020/Day12RainRisk.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2020
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import adventofcode.year2020.Day12RainRisk.Companion.Action.EAST
import adventofcode.year2020.Day12RainRisk.Companion.Action.FORWARD
import adventofcode.year2020.Day12RainRisk.Companion.Action.LEFT
import adventofcode.year2020.Day... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 4,558 | AdventOfCode | MIT License |
src/Day15.kt | erwinw | 572,913,172 | false | {"Kotlin": 87621} | @file:Suppress("MagicNumber")
import kotlin.math.abs
private const val DAY = "15"
private const val PART1_CHECK = 26
private const val PART2_CHECK = 56000011L
fun main() {
data class Coordinate(
val x: Int,
val y: Int,
) {
fun distance(other: Coordinate): Int =
abs(x - ot... | 0 | Kotlin | 0 | 0 | 57cba37265a3c63dea741c187095eff24d0b5381 | 4,261 | adventofcode2022 | Apache License 2.0 |
src/Day02.kt | Sghazzawi | 574,678,250 | false | {"Kotlin": 10945} | enum class MyMove(val value: String) {
Rock("X"),
Paper("Y"),
Scissors("Z");
companion object {
infix fun from(value: String): MyMove = MyMove.values().firstOrNull { it.value == value } ?: throw Exception()
}
}
enum class OpponentMove(val value: String) {
Rock("A"),
Paper("B"),
... | 0 | Kotlin | 0 | 0 | a26111fa1bcfec28cc43a2f48877455b783acc0d | 3,526 | advent-of-code-kotlin | Apache License 2.0 |
implementation/src/main/kotlin/io/github/tomplum/aoc/hash/HashAlgorithm.kt | TomPlum | 724,225,748 | false | {"Kotlin": 141244} | package io.github.tomplum.aoc.hash
import io.github.tomplum.libs.extensions.product
class HashAlgorithm(private val input: String) {
fun run(): Int = input.split(",").sumOf { step -> step.hash() }
fun calculateFocusingPower(): Int {
val boxes = mutableMapOf<Int, MutableList<Pair<String, Int>>>()
... | 0 | Kotlin | 0 | 1 | d1f941a3c5bacd126177ace6b9f576c9af07fed6 | 1,796 | advent-of-code-2023 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.