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/dev/shtanko/algorithms/leetcode/MaximumsSplicedArray.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,703 | kotlab | Apache License 2.0 |
codechef/snackdown2021/preelim/guessrow.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codechef.snackdown2021.preelim
import java.util.*
@Suppress("UNUSED_PARAMETER") // Kotlin 1.2
fun main(args: Array<String>) {
val (tests, n) = readInts()
val desired = n / 2
val all = 1..n
val cnk = List(n + 1) { LongArray(it + 1) { 1 } }
for (i in 2..n) for (j in 1 until i) cnk[i][j] = cnk[i - 1][j - 1... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,546 | competitions | The Unlicense |
src/Day01.kt | akleemans | 574,937,934 | false | {"Kotlin": 5797} | fun main() {
fun part1(input: List<String>): Int {
var highest = 0
var currentCounter = 0
for (line in input) {
if (line.isNotEmpty()) {
currentCounter += line.toInt()
} else {
if (highest < currentCounter) {
highest... | 0 | Kotlin | 0 | 0 | fa4281772d89a6d1cda071db4b6fb92fff5b42f5 | 1,153 | aoc-2022-kotlin | Apache License 2.0 |
src/Day06.kt | emanguy | 573,113,840 | false | {"Kotlin": 17921} | fun main() {
fun firstUniqueWindowIndex(input: String, windowSize: Int): Int {
for (window in input.asSequence().withIndex().windowed(windowSize)) {
val uniqueCharacterSet = window.map { it.value }.toSet()
if (uniqueCharacterSet.size == windowSize) {
return window.las... | 0 | Kotlin | 0 | 1 | 211e213ec306acc0978f5490524e8abafbd739f3 | 1,185 | advent-of-code-2022 | Apache License 2.0 |
leetcode/src/main/kotlin/com/artemkaxboy/leetcode/p00/Leet48.kt | artemkaxboy | 513,636,701 | false | {"Kotlin": 547181, "Java": 13948} | package com.artemkaxboy.leetcode.p00
import com.artemkaxboy.leetcode.LeetUtils
private class Leet48 {
fun rotate(matrix: Array<IntArray>) {
val size = matrix.size
for (layerNumber in 0 until size / 2) {
rotateLayer(matrix, layerNumber)
}
}
fun rotateLayer(matrix: Array... | 0 | Kotlin | 0 | 0 | 516a8a05112e57eb922b9a272f8fd5209b7d0727 | 1,920 | playground | MIT License |
src/test/kotlin/com/eugenenosenko/coding/problems/arrays/compose_from_old/ComposeArrayFromOldSolution.kt | eugenenosenko | 303,183,289 | false | null | package com.eugenenosenko.coding.problems.arrays.compose_from_old
// brute force approach
fun createArray(arr: IntArray): IntArray {
val result = mutableListOf<Int>()
for (i in arr.indices) {
result.add(
arr.foldIndexed(1) { index: Int, acc: Int, item: Int ->
// ign... | 0 | Kotlin | 0 | 0 | 673cc3ef6aa3c4f55b9156d14d64d47588610600 | 1,698 | coding-problems | MIT License |
codeforces/globalround20/f1.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.globalround20
private fun solve() {
val n = readInt()
val a = readInts()
val count = IntArray(n + 1)
val pos = List(n + 1) { mutableListOf<Int>() }
for (i in a.indices) {
count[a[i]]++
pos[a[i]].add(i)
}
val often = count.indices.sortedBy { count[it] }
val mostOften = often.last()
val a... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 809 | competitions | The Unlicense |
src/main/kotlin/dev/bogwalk/batch2/Problem21.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch2
import dev.bogwalk.util.maths.sumProperDivisors
/**
* Problem 21: Amicable Numbers
*
* https://projecteuler.net/problem=21
*
* Goal: Return the sum of all amicable numbers less than N.
*
* Constraints: 1 <= N <= 1e5
*
* Proper Divisor: A number x that evenly divides N, where x != N... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 1,509 | project-euler-kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinCostConnectPoints.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,662 | kotlab | Apache License 2.0 |
src/Day10.kt | RogozhinRoman | 572,915,906 | false | {"Kotlin": 28985} | fun main() {
fun part1(input: List<String>): Int {
var cycles = 1
var x = 1
var signalsSum = 0
val frames = listOf(20, 60, 100, 140, 180, 220)
for (command in input) {
var dx = 0
if (!command.startsWith("noop")) {
cycles++
... | 0 | Kotlin | 0 | 1 | 6375cf6275f6d78661e9d4baed84d1db8c1025de | 2,049 | AoC2022 | Apache License 2.0 |
src/main/kotlin/g1801_1900/s1847_closest_room/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1847_closest_room
// #Hard #Array #Sorting #Binary_Search #2023_06_22_Time_1179_ms_(100.00%)_Space_92.1_MB_(100.00%)
import java.util.Arrays
import java.util.TreeSet
class Solution {
fun closestRoom(rooms: Array<IntArray>, queries: Array<IntArray>): IntArray {
val numRoom = rooms.size... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,942 | LeetCode-in-Kotlin | MIT License |
hackerrank/max-array-sum/Solution.kts | shengmin | 5,972,157 | false | null | import java.io.*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.f... | 0 | Java | 18 | 20 | 08e65546527436f4bd2a2014350b2f97ac1367e7 | 1,639 | coding-problem | MIT License |
src/main/kotlin/com/colinodell/advent2021/Day18.kt | colinodell | 433,864,377 | true | {"Kotlin": 111114} | package com.colinodell.advent2021
class Day18 (private val input: List<String>) {
fun solvePart1() = sumAndFindMagnitude(input)
fun solvePart2() = getHighestMagnitudeOfTwo(input)
data class SnailfishPairElement(var value: Int, var depth: Int)
private fun parse(input: String): MutableList<SnailfishPa... | 0 | Kotlin | 0 | 1 | a1e04207c53adfcc194c85894765195bf147be7a | 3,566 | advent-2021 | Apache License 2.0 |
src/Day03.kt | aemson | 577,677,183 | false | {"Kotlin": 7385} | fun main() {
val inputData = readInput("Day03_input")
val commonItems = inputData.map { item ->
val numberOfItems = item.toCharArray().size
val firstSet = item.substring(0, numberOfItems / 2).toCharArray().toList()
val secondSet = item.substring(numberOfItems / 2, numberOfItems).toCharAr... | 0 | Kotlin | 0 | 0 | ffec4b848ed5c2ba9b2f2bfc5b991a2019c8b3d4 | 1,161 | advent-of-code-22 | Apache License 2.0 |
day04/main.kt | LOZORD | 441,007,912 | false | {"Kotlin": 29367, "Python": 963} | import java.util.Scanner
fun main() {
val isPart1 = false // true => Part 1; false => Part 2
data class Position(val row: Int, val col: Int, var stamped: Boolean)
class BingoBoard {
val positionMap = HashMap<Int, Position>(25)
val rowStamps = IntArray(5, { _ -> 5})
val colStamps = ... | 0 | Kotlin | 0 | 0 | 17dd266787acd492d92b5ed0d178ac2840fe4d57 | 3,307 | aoc2021 | MIT License |
src/Day04.kt | RaspiKonk | 572,875,045 | false | {"Kotlin": 17390} | /**
* Day 4: den Strand aufräumen
*
* Part 1: Wie viele Assignments liegen vollständig in einem anderen Assignment?
* Part 2: Wie viele Assignments überlappen?
*/
fun main()
{
val start = System.currentTimeMillis()
val DAY: String = "04"
println("Advent of Code 2022 - Day $DAY")
// Solve part 1.
fun part1(i... | 0 | Kotlin | 0 | 1 | 7d47bea3a5e8be91abfe5a1f750838f2205a5e18 | 2,343 | AoC_Kotlin_2022 | Apache License 2.0 |
ahp-base/src/main/kotlin/pl/poznan/put/ahp/ahp-utils.kt | sbigaret | 164,424,298 | true | {"Kotlin": 93061, "R": 67629, "Shell": 24899, "Groovy": 24559} | package pl.poznan.put.ahp
data class RelationValue(
val firstID: String,
val secondID: String,
val value: Double
) {
fun reversed() = RelationValue(secondID, firstID, 1 / value)
}
fun AhpAlternative.relation() = name.relation()
fun String.relation() = RelationValue(this, this, 1.0)
data c... | 0 | Kotlin | 0 | 0 | 96c182d7e37b41207dc2da6eac9f9b82bd62d6d7 | 2,411 | DecisionDeck | MIT License |
src/main/kotlin/io/trie/MapSumPairs.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.trie
import java.util.*
// https://leetcode.com/explore/learn/card/trie/148/practical-application-i/1058/
class MapSumPairs {
private val root = TrieNodeSum(null, "")
fun insert(key: String, value: Int) {
var current = root
key.forEach { char ->
current = current.getOrAdd(char)
}
... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,997 | coding | MIT License |
src/test/kotlin/be/brammeerten/y2022/Day9Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2022
import be.brammeerten.Co
import be.brammeerten.extractRegexGroups
import be.brammeerten.readFile
import be.brammeerten.toCharList
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import kotlin.math.abs
import kotlin.math.sign
class Day9Test {
@Test
fun `p... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 3,307 | Advent-of-Code | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimumKnightMoves.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 | 6,102 | kotlab | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round0/Questions48.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round0
/**
* 一个只包含小写字母的字符串的最大非重复子字符串的长度
*/
fun test48() {
val str = "arabcacfr"
println("字符串:$str,最大子字符串的长度是:${longestSubstringWithoutDuplication(str)}")
}
fun longestSubstringWithoutDuplication(str: String): Int {
// 检查字符是否合法
fun Char.isLegal(): Boolean = code in 97..122
// 获取... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 937 | Algorithm | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch7/Problem80.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch7
import java.math.BigDecimal
import java.math.MathContext
import java.math.RoundingMode
import kotlin.math.sqrt
/**
* Problem 80: Square Root Digital Expansion
*
* https://projecteuler.net/problem=80
*
* Goal: For the first N natural numbers, find the total of the digit sums of the firs... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 5,761 | project-euler-kotlin | MIT License |
src/main/kotlin/com/jaspervanmerle/aoc2021/day/Day03.kt | jmerle | 434,010,865 | false | {"Kotlin": 60581} | package com.jaspervanmerle.aoc2021.day
class Day03 : Day("3959450", "7440311") {
private val numbers = input.lines()
override fun solvePartOne(): Any {
val gammaRate = getRate { zeros, ones -> zeros > ones }
val epsilonRate = getRate { zeros, ones -> zeros < ones }
return gammaRate * e... | 0 | Kotlin | 0 | 0 | dcac2ac9121f9bfacf07b160e8bd03a7c6732e4e | 1,486 | advent-of-code-2021 | MIT License |
src/day4/Day04.kt | dinoolivo | 573,723,263 | false | null | package day4
import day3.Interval
import readInput
fun main() {
fun convertToIntervals(input: String):Pair<Interval, Interval>{
val rowParts = input.split(",")
return Pair(Interval.fromString(rowParts[0]), Interval.fromString(rowParts[1]))
}
fun part1(input: List<Pair<Interval, Interval... | 0 | Kotlin | 0 | 0 | 6e75b42c9849cdda682ac18c5a76afe4950e0c9c | 1,080 | aoc2022-kotlin | Apache License 2.0 |
src/leetcode_study_badge/algorithm/Day6.kt | faniabdullah | 382,893,751 | false | null | package leetcode_study_badge.algorithm
class Day6 {
fun checkInclusion(s1: String, s2: String): Boolean {
if (s1.length > s2.length) return false
val s1map = IntArray(26)
val s2map = IntArray(26)
for (i in s1.indices) {
s1map[s1[i] - 'a']++
s2map[s2[i] - 'a'... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 1,513 | dsa-kotlin | MIT License |
src/Day01.kt | rounakdatta | 570,368,613 | false | {"Kotlin": 1801} | import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
return input.fold(Pair(0, 0)) { (currentSum, maxSum), it ->
if (it != "") {
Pair(currentSum + it.toInt(), max(maxSum, currentSum + it.toInt()))
} else {
Pair(0, maxSum)
... | 0 | Kotlin | 0 | 1 | 2a253d33c103d885f423a1046138d1dbc4216cec | 935 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/lain/Range.kt | liminalitythree | 269,473,503 | false | null | package lain
import kotlin.math.abs
data class Range(val min:Int, val max: Int) {
init {
if (min > max) {
throw Exception("Range created with min greater than max, min: $min max: $max")
}
}
companion object {
fun and(a:Range, b:Range):Range {
val min = if (... | 2 | Kotlin | 0 | 0 | 6d5fbcc29da148fd72ecb58b164fc5c845267e5c | 1,947 | bakadesu | Creative Commons Zero v1.0 Universal |
y2019/src/main/kotlin/adventofcode/y2019/Day04.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2019
import adventofcode.io.AdventSolution
fun main() = Day04.solve()
object Day04 : AdventSolution(2019, 4, "Secure Container") {
override fun solvePartOne(input: String) = parseFast(input).count { c ->
c.toString().zipWithNext().any { (a, b) -> a == b }
}
override fun so... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,124 | advent-of-code | MIT License |
src/Day08.kt | icoffiel | 572,651,851 | false | {"Kotlin": 29350} | private const val DAY = "Day08"
fun main() {
fun <T> Iterable<T>.takeWhileInclusive(
predicate: (T) -> Boolean
): List<T> {
var shouldContinue = true
return takeWhile {
val result = shouldContinue
shouldContinue = predicate(it)
result
}
}
... | 0 | Kotlin | 0 | 0 | 515f5681c385f22efab5c711dc983e24157fc84f | 5,288 | advent-of-code-2022 | Apache License 2.0 |
src/day10/Day10ToddGinsbergSolution.kt | commanderpepper | 574,647,779 | false | {"Kotlin": 44999} | package day10
import readInput
import kotlin.math.absoluteValue
fun main() {
val day10Input = readInput("day10")
val signals = parseInput(day10Input).runningReduce(Int::plus)
val dayOneSolution = solvePart1(signals)
println(dayOneSolution)
solvePart2(signals)
}
fun parseInput(input: List<String>... | 0 | Kotlin | 0 | 0 | fef291c511408c1a6f34a24ed7070ceabc0894a1 | 1,112 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2023/day16/day16.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2023.day16
import biz.koziolek.adventofcode.*
fun main() {
val inputFile = findInput(object {})
val mirrors = parseMirrorContraption(inputFile.bufferedReader().readLines())
val beamPath = simulateBeam(mirrors)
println("Energized tiles: ${countEnergizedTiles(beamPa... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 4,954 | advent-of-code | MIT License |
src/day7/Day7.kt | ZsemberiDaniel | 159,921,870 | false | null | package day7
import RunnablePuzzleSolver
import java.lang.StringBuilder
import java.util.*
import kotlin.collections.HashMap
class Day7 : RunnablePuzzleSolver {
private val instructions: HashMap<Char, Instruction> = hashMapOf()
private val workerCount = 5
override fun readInput1(lines: Array<String>) {
... | 0 | Kotlin | 0 | 0 | bf34b93aff7f2561f25fa6bd60b7c2c2356b16ed | 5,980 | adventOfCode2018 | MIT License |
src/day3.kt | miiila | 725,271,087 | false | {"Kotlin": 77215} | import java.io.File
import kotlin.system.exitProcess
private const val DAY = 3
fun main() {
if (!File("./day${DAY}_input").exists()) {
downloadInput(DAY)
println("Input downloaded")
exitProcess(0)
}
val transformer = { x: String -> x }
val input = loadInput(DAY, false, transfor... | 0 | Kotlin | 0 | 1 | 1cd45c2ce0822e60982c2c71cb4d8c75e37364a1 | 2,836 | aoc2023 | MIT License |
src/day13/Day13.kt | pocmo | 433,766,909 | false | {"Kotlin": 134886} | package day13
import java.io.File
data class Point(
val x: Int,
val y: Int
)
data class Paper(
val points: Map<Point, Boolean>
) {
fun fold(instruction: Instruction): Paper {
return when (instruction) {
is Instruction.FoldUp -> foldUp(instruction.y)
is Instruction.Fold... | 0 | Kotlin | 1 | 2 | 73bbb6a41229e5863e52388a19108041339a864e | 4,372 | AdventOfCode2021 | Apache License 2.0 |
src/day10/Day10.kt | gautemo | 317,316,447 | false | null | package day10
import shared.getLinesAsInt
fun adaptersDifferenceCalculation(adapters: List<Int>): Int{
val joltDiff = sortedWithChargerAndDevice(adapters).zipWithNext().map { it.second - it.first }
return joltDiff.count { it == 1 } * joltDiff.count { it == 3 }
}
fun adaptersCombination(adapters: List<Int>): ... | 0 | Kotlin | 0 | 0 | ce25b091366574a130fa3d6abd3e538a414cdc3b | 1,424 | AdventOfCode2020 | MIT License |
src/main/kotlin/days/day1/Day1.kt | Stenz123 | 725,707,248 | false | {"Kotlin": 123279, "Shell": 862} | package days.day1
import days.Day
class Day1 : Day(false) {
override fun partOne() = readInput().map { it.filter (Char::isDigit) }.sumOf {
(it.first() + "" + it.last()).toInt()
}
override fun partTwo(): Any {
val inputDigits = readInput().map { convertStringWithSpelledOutDigitsToDigits(it... | 0 | Kotlin | 1 | 0 | 3de47ec31c5241947d38400d0a4d40c681c197be | 2,446 | advent-of-code_2023 | The Unlicense |
src/test/kotlin/leetcode/mock/MockInterview5.kt | Magdi | 390,731,717 | false | null | package leetcode.mock
import org.junit.Assert
import org.junit.Test
class MockInterview5 {
@Test
fun `test case 1`() {
// Assert.assertEquals(1, Solution().expressiveWords("heeellooo", arrayOf("hello", "hi", "helo")))
Assert.assertEquals(0, Solution().expressiveWords("lee", arrayOf("le")))
... | 0 | Kotlin | 0 | 0 | 63bc711dc8756735f210a71454144dd033e8927d | 3,282 | ProblemSolving | Apache License 2.0 |
src/main/kotlin/com/nibado/projects/advent/y2018/Day10.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2018
import com.nibado.projects.advent.Day
import com.nibado.projects.advent.Point
import com.nibado.projects.advent.Rectangle
import com.nibado.projects.advent.resourceLines
import kotlin.math.max
import kotlin.math.min
object Day10 : Day {
private val input = resourceLines(20... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 2,170 | adventofcode | MIT License |
src/day7/Day07.kt | behnawwm | 572,034,416 | false | {"Kotlin": 11987} | package day7
import readInput
fun main() {
val fileLines = readInput("day07-test", "day7")
// val fileLines = readInput("day07", "day7")
fun updateDirsCurrentDir(newDirName: String, storage: Dir) {
// if (dirName in currentDir.dirs.map { it.relativePath })
// return
val current ... | 0 | Kotlin | 0 | 2 | 9d1fee54837cfae38c965cc1a5b267d7d15f4b3a | 3,445 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/_2022/Day5.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2022
import PATTERN_LINE_SEPARATOR
import REGEX_LINE_SEPARATOR
import aoc
import java.util.regex.Pattern
private val EMPTY_LINE_REGEX = Pattern.compile("^${PATTERN_LINE_SEPARATOR}", Pattern.MULTILINE)
private val STACK_REGEX = Pattern.compile("\\[(\\w)]")
private val INSTRUCTION_REGEX = Pattern.compile("move... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 2,490 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/AoC16.kt | Pi143 | 317,631,443 | false | null | import java.io.File
fun main() {
println("Starting Day 16 A Test 1")
calculateDay16PartA(
"Input/2020_Day16_Rules_Test1",
"Input/2020_Day16_myTicket_Test1",
"Input/2020_Day16_nearbyTickets_Test1"
)
println("Starting Day 16 A Real")
calculateDay16PartA("Input/2020_Day16_Rules... | 0 | Kotlin | 0 | 1 | fa21b7f0bd284319e60f964a48a60e1611ccd2c3 | 5,044 | AdventOfCode2020 | MIT License |
src/test/kotlin/days/y2022/Day05Test.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2052
import days.Day
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.Is.`is`
import org.junit.jupiter.api.Test
class Day05 : Day(2022, 5) {
override fun partOne(input: String): Any {
val crates = Crates.from(input)
instructions(input).forEach { instruction ->
... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 6,844 | AdventOfCode | Creative Commons Zero v1.0 Universal |
ceria/16/src/main/kotlin/Solution.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File;
var versions = mutableListOf<Int>()
var packets = mutableListOf<Pair<Int, List<Long>>>()
fun main(args : Array<String>) {
val input = File(args.first()).readLines().first().trim()
println("Solution 1: ${solution1(convertHexToBinary(input))}")
// println("Solution 2: ${solution2(conver... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 5,411 | advent-of-code-2021 | MIT License |
2022/src/main/kotlin/day20.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.badInput
import utils.mapItems
fun main() {
Day20.run(skipTest = true)
}
class Node(val value: Int, var head: Boolean = false) {
lateinit var prev: Node
lateinit var next: Node
}
object Day20 : Solution<List<Int>>() {
override val name = "day20"
overri... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,765 | aoc_kotlin | MIT License |
sort/merge_sort/kotlin/merge_sort.kt | ZoranPandovski | 93,438,176 | false | {"Jupyter Notebook": 21909905, "C++": 1692994, "Python": 1158220, "Java": 806066, "C": 560110, "JavaScript": 305918, "Go": 145277, "C#": 117882, "PHP": 85458, "Kotlin": 72238, "Rust": 53852, "Ruby": 43243, "MATLAB": 34672, "Swift": 31023, "Processing": 22089, "HTML": 18961, "Haskell": 14298, "Dart": 11842, "CSS": 10509... | fun mergeSortIA(array: IntArray) : IntArray {
val arrayCopy = array.copyOf()
val arrayCopy2 = array.copyOf()
sortSectionIA(arrayCopy, arrayCopy2, 0, arrayCopy.size)
return arrayCopy2
}
/**
* Sorts the specified section of the array.
*
* @param workA Should contain identical values as workB in the ... | 62 | Jupyter Notebook | 1,994 | 1,298 | 62a1a543b8f3e2ca1280bf50fc8a95896ef69d63 | 1,626 | al-go-rithms | Creative Commons Zero v1.0 Universal |
src/main/kotlin/adventofcode/year2022/Day21MonkeyMath.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2022
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import adventofcode.common.String.containsOnlyDigits
import adventofcode.year2022.Day21MonkeyMath.Companion.Operation.DIV
import adventofcode.year2022.Day21MonkeyMath.Companion.Operation.MINUS
import adventofcode.year2022.Day21Mon... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 2,779 | AdventOfCode | MIT License |
2017/day-10/solution.kt | bertptrs | 47,429,580 | false | {"Rust": 605086, "Python": 92178, "Java": 3238, "C#": 2880, "Lua": 2480, "Clojure": 2454, "Shell": 1957, "CoffeeScript": 1765, "C": 1729, "Kotlin": 1589, "Groovy": 1457, "JavaScript": 1210, "Julia": 1144, "Makefile": 983, "Go": 856, "Scala": 776, "Ruby": 738, "MATLAB": 646, "PHP": 622, "Haskell": 603, "Perl": 589, "R":... | fun valArray(): IntArray
{
val arr = IntArray(256)
for (i in arr.indices) {
arr[i] = i
}
return arr
}
fun hash(input: IntArray, values: IntArray, index: Int, skip: Int): Pair<Int, Int> {
var curIndex = index
var curSkip = skip
for (range in input) {
val halfRange = range / ... | 0 | Rust | 1 | 12 | 1f41f4b35ae94f8be7eed3832c2ccb273059399d | 1,589 | adventofcode | MIT License |
src/main/kotlin/Day04.kt | attilaTorok | 573,174,988 | false | {"Kotlin": 26454} | import kotlin.streams.toList
fun main() {
fun getFullyContainedPairsCount(fileName: String): Int {
var sumOfFullyContainedPairs = 0
readInputWithStream(fileName).useLines {
val iterator = it.iterator()
while (iterator.hasNext()) {
val assignmentPairs = iter... | 0 | Kotlin | 0 | 0 | 1799cf8c470d7f47f2fdd4b61a874adcc0de1e73 | 2,246 | AOC2022 | Apache License 2.0 |
src/day07/Day07.kt | Frank112 | 572,910,492 | false | null | package day07
import assertThat
import readInput
fun main() {
val cdCommandRegex = Regex("^\\$ cd (.+)$")
val lsCommandRegex = Regex("^\\$ ls$")
val directoryListingRegex = Regex("^dir (.+)$")
val fileListingRegex = Regex("^(\\d+) (.+)$")
fun parseInput(input: List<String>): Directory {
... | 0 | Kotlin | 0 | 0 | 1e927c95191a154efc0fe91a7b89d8ff526125eb | 2,148 | advent-of-code-2022 | Apache License 2.0 |
src/Day01.kt | novotnyradekcz | 579,767,169 | false | {"Kotlin": 11517} | fun main() {
fun part1(input: List<String>): Int {
var calories = 0
val maxima = mutableListOf<Int>()
for (line in input) {
if (line == "") {
maxima.add(calories)
calories = 0
} else {
calories += line.toInt()
... | 0 | Kotlin | 0 | 0 | 2f1907dc63344cf536f5031bc7e1c61db03fc570 | 1,310 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/pl/pjagielski/punkt/melody/Scale.kt | Syknapse | 255,642,812 | true | {"Kotlin": 38347, "SuperCollider": 4251, "Java": 237} | package pl.pjagielski.punkt.melody
import pl.pjagielski.punkt.pattern.Step
import pl.pjagielski.punkt.pattern.StepSequence
import kotlin.math.absoluteValue
val C = 60
val D = 62
val E = 64
val F = 65
val G = 67
val A = 69
val B = 71
fun Int.sharp() = inc()
fun Int.flat() = dec()
sealed class Intervals(val intervals... | 0 | null | 0 | 0 | 2db710a726b31106ae09c5317a1521b9d84ea20c | 2,817 | punkt | Apache License 2.0 |
src/main/kotlin/days/Solution16.kt | Verulean | 725,878,707 | false | {"Kotlin": 62395} | package days
import adventOfCode.InputHandler
import adventOfCode.Solution
import adventOfCode.util.PairOf
import adventOfCode.util.Point2D
import adventOfCode.util.plus
object Solution16 : Solution<CharGrid>(AOC_YEAR, 16) {
override fun getInput(handler: InputHandler) = handler.getInput("\n").map(String::toCharA... | 0 | Kotlin | 0 | 1 | 99d95ec6810f5a8574afd4df64eee8d6bfe7c78b | 2,130 | Advent-of-Code-2023 | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions49.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import kotlin.math.min
fun test49() {
printlnResult(1)
printlnResult(2)
printlnResult(3)
printlnResult(4)
printlnResult(5)
printlnResult(6)
printlnResult(7)
printlnResult(8)
printlnResult(9)
printlnResult(10)
printlnResult(1500)
}
/**... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,334 | Algorithm | Apache License 2.0 |
day13/src/main/kotlin/App.kt | ascheja | 317,918,055 | false | null | package net.sinceat.aoc2020.day13
fun main() {
run {
val (currentTime, busIds) = readInputPart1("testinput.txt")
val (busId, nextDeparture) = busIds.nextDepartures(currentTime).minByOrNull { (_, nextDeparture) ->
nextDeparture
}!!
println("$busId x ($nextDeparture - $cu... | 0 | Kotlin | 0 | 0 | f115063875d4d79da32cbdd44ff688f9b418d25e | 2,073 | aoc2020 | MIT License |
src/Day01.kt | kthun | 572,871,866 | false | {"Kotlin": 17958} | fun main() {
fun createElves(input: List<String>): MutableList<List<Int>> {
val elvesStrings = mutableListOf<List<Int>>()
var thisElfStrings = mutableListOf<Int>()
for (s in input) {
if (s == "") {
elvesStrings.add(thisElfStrings)
thisElfStrings =... | 0 | Kotlin | 0 | 0 | 5452702e4e20ef2db3adc8112427c0229ebd1c29 | 1,137 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | samo1 | 573,449,853 | false | {"Kotlin": 4045} | fun main() {
// A for Rock, B for Paper, and C for Scissors
// X for Rock, Y for Paper, and Z for Scissors
fun part1(input: List<String>) = input.sumOf {
val shapeScore = when (it[2]) {
'X' -> 1
'Y' -> 2
'Z' -> 3
else -> throw IllegalArgumentException(... | 0 | Kotlin | 0 | 0 | 77e32453ba45bd4f9088f34be91939b94161cf13 | 2,124 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/kr/co/programmers/P68936.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://github.com/antop-dev/algorithm/issues/240
class P68936 {
fun solution(arr: Array<IntArray>): IntArray {
return recursive(arr, 0, 0, arr.size)
}
private fun recursive(arr: Array<IntArray>, y: Int, x: Int, size: Int): IntArray {
val count = intArrayOf(0,... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,446 | algorithm | MIT License |
src/main/kotlin/no/quist/aoc18/days/Day3.kt | haakonmt | 159,945,133 | false | null | package no.quist.aoc18.days
import no.quist.aoc18.Day
object Day3 : Day<List<Rectangle>, Any>() {
override fun createInput(): List<Rectangle> = inputLines.map { line ->
val (id, x, y, width, height) = line groupBy Regex("""#(\d*) @ (\d*),(\d*): (\d*)x(\d*)""")
Rectangle(id, x.toInt(), y.toInt(), w... | 0 | Kotlin | 0 | 1 | 4591ae7aa9cbb70e26ae2c3a65ec9e55559c2690 | 1,369 | aoc18 | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year15/Day13.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year15
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.permutations
fun PuzzleSet.day13() = puzzle {
val exclusiveSeatings = inputLines.map { l ->
val split = l.split(" ")
val type = when (split[2]) {
"gain" -> 1
"lose" -> -1
... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,499 | advent-of-code | The Unlicense |
day14/src/main/kotlin/ver_b.kt | jabbalaci | 115,397,721 | false | null | package b
import java.io.File
class Matrix(val matrix: List<List<Int>>) {
private var groupCounter = 0
private val visited = mutableSetOf<Pair<Int, Int>>()
override fun toString(): String {
val sb = StringBuilder()
for (row in matrix) {
sb.append(row.joinToString(""))
... | 0 | Kotlin | 0 | 0 | bce7c57fbedb78d61390366539cd3ba32b7726da | 2,362 | aoc2017 | MIT License |
src/Day06.kt | george-theocharis | 573,013,076 | false | {"Kotlin": 10656} | fun main() {
fun List<String>.splitListPerSegments(size: Int) = flatMap { it.windowed(size, 1) }
fun List<String>.findDistinctSegment() =
first { packet -> packet.all { character -> packet.count { it == character } == 1 } }
fun List<String>.indexOfDistinctSegment(
firstDistinctPacket: Stri... | 0 | Kotlin | 0 | 0 | 7971bea39439b363f230a44e252c7b9f05a9b764 | 1,028 | aoc-2022 | Apache License 2.0 |
common/src/main/kotlin/combo/sat/optimizers/ObjectiveFunction.kt | rasros | 148,620,275 | false | null | package combo.sat.optimizers
import combo.math.EMPTY_VECTOR
import combo.math.VectorView
import combo.model.EffectCodedVector
import combo.model.Model
import combo.sat.Instance
import combo.sat.literal
import combo.sat.not
import combo.sat.toIx
interface ObjectiveFunction {
/**
* Value to minimize evaluated... | 0 | Kotlin | 1 | 2 | 2f4aab86e1b274c37d0798081bc5500d77f8cd6f | 4,122 | combo | Apache License 2.0 |
src/main/kotlin/Day06.kt | Vampire | 572,990,104 | false | {"Kotlin": 57326} | fun main() {
fun part1(input: List<String>, amountOfDistinct: Int = 4) = input[0]
.toCharArray()
.asSequence()
.withIndex()
.windowed(amountOfDistinct)
.find { markerCandidate -> markerCandidate.distinctBy { it.value }.size == amountOfDistinct }!!
.let { it.last().ind... | 0 | Kotlin | 0 | 0 | 16a31a0b353f4b1ce3c6e9cdccbf8f0cadde1f1f | 1,088 | aoc-2022 | Apache License 2.0 |
kotlin/src/2023/Day01_2023.kt | regob | 575,917,627 | false | {"Kotlin": 50757, "Python": 46520, "Shell": 430} | private val sdigits = mapOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"five" to 5,
"six" to 6,
"seven" to 7,
"eight" to 8,
"nine" to 9,
)
private fun digitAtStart(s: String, i: Int): Int? {
val seq = s.subSequence(i until s.length)
for ((sdig, dig) in sdigits.entri... | 0 | Kotlin | 0 | 0 | cf49abe24c1242e23e96719cc71ed471e77b3154 | 1,134 | adventofcode | Apache License 2.0 |
src/leetcode_study_badge/data_structure/Day3.kt | faniabdullah | 382,893,751 | false | null | package leetcode_study_badge.data_structure
class Day3 {
fun getRowBrute(rowIndex: Int): List<Int> {
val dp = Array(rowIndex + 1) { IntArray(rowIndex + 1) }
dp[0][0] = 1
dp[rowIndex][rowIndex] = 1
var indexRow = 1
while (indexRow <= rowIndex) {
repeat(rowIndex) ... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 3,902 | dsa-kotlin | MIT License |
src/aoc2022/Day07.kt | NoMoor | 571,730,615 | false | {"Kotlin": 101800} | package aoc2022
import utils.*
internal class Day07(lines: List<String>) {
data class Directory(var size: Long = 0, val name: String, val parent: Directory?) // Container to be able to change the value in dirs and path
val dirs = mutableListOf<Directory>() // A list containing the sizes of all directories
val ... | 0 | Kotlin | 1 | 2 | d561db73c98d2d82e7e4bc6ef35b599f98b3e333 | 1,883 | aoc2022 | Apache License 2.0 |
src/Day13/December13.kt | Nandi | 47,216,709 | false | null | package Day13
import org.jgrapht.experimental.permutation.CollectionPermutationIter
import org.jgrapht.graph.DefaultWeightedEdge
import org.jgrapht.graph.SimpleWeightedGraph
import java.nio.file.Files
import java.nio.file.Paths
import java.util.stream.Stream
/**
* In years past, the holiday feast with your family ha... | 0 | Kotlin | 0 | 0 | 34a4b4c0926b5ba7e9b32ca6eeedd530f6e95bdc | 4,059 | adventofcode | MIT License |
domain/src/main/kotlin/com/seanshubin/condorcet/domain/Ballot.kt | SeanShubin | 126,547,543 | false | null | package com.seanshubin.condorcet.domain
data class Ballot(val id: String,
val confirmation: String,
val rankings: List<Ranking>) {
init {
if (candidates().distinct().size != rankings.size)
throw RuntimeException("Ballots for $id has duplicate candidates: ${ca... | 0 | Kotlin | 0 | 0 | a5f887e9ab2281a9c15240a314a6de489ce42f76 | 2,062 | condorcet | The Unlicense |
src/Day23.kt | frungl | 573,598,286 | false | {"Kotlin": 86423} | fun main() {
fun parseToSet(input: List<String>): Set<Pair<Int, Int>> {
val set = mutableSetOf<Pair<Int, Int>>()
input.forEachIndexed { i, s ->
s.forEachIndexed { j, c ->
if (c == '#')
set.add(Pair(i, j))
}
}
return set
... | 0 | Kotlin | 0 | 0 | d4cecfd5ee13de95f143407735e00c02baac7d5c | 5,567 | aoc2022 | Apache License 2.0 |
src/main/kotlin/year2021/day-11.kt | ppichler94 | 653,105,004 | false | {"Kotlin": 182859} | package year2021
import lib.MutableGrid2d
import lib.Position
import lib.aoc.Day
import lib.aoc.Part
import lib.math.Itertools
fun main() {
Day(11, 2021, PartA11(), PartB11()).run()
}
open class PartA11 : Part() {
protected lateinit var energyLevels: MutableGrid2d<Int>
override fun parse(text: String) {... | 0 | Kotlin | 0 | 0 | 49dc6eb7aa2a68c45c716587427353567d7ea313 | 2,029 | Advent-Of-Code-Kotlin | MIT License |
src/year2023/day06/Day.kt | tiagoabrito | 573,609,974 | false | {"Kotlin": 73752} | package year2023.day06
import java.util.stream.LongStream
import kotlin.streams.toList
import year2023.solveIt
fun main() {
val day = "06"
val expectedTest1 = 288L
val expectedTest2 = 71503L
fun isNotRecord(v: Long, duration: Long, record: Long) =
v * (duration - v) <= record
fun getI... | 0 | Kotlin | 0 | 0 | 1f9becde3cbf5dcb345659a23cf9ff52718bbaf9 | 1,135 | adventOfCode | Apache License 2.0 |
src/day08/Day08.kt | molundb | 573,623,136 | false | {"Kotlin": 26868} | package day08
import readInput
import java.lang.Integer.max
fun main() {
val input = readInput(parent = "src/day08", name = "Day08_input")
println(solvePartOne(input))
println(solvePartTwo(input))
}
private fun solvePartTwo(input: List<String>): Int {
val treeRows = mutableListOf<MutableList<Int>>()... | 0 | Kotlin | 0 | 0 | a4b279bf4190f028fe6bea395caadfbd571288d5 | 3,633 | advent-of-code-2022 | Apache License 2.0 |
src/Day06.kt | hottendo | 572,708,982 | false | {"Kotlin": 41152} |
fun main() {
fun isMarker(marker: String, markerSize: Int): Boolean {
/* takes a 4 character string as input and checks for duplicate chars.
No duplicates -> marker found.
*/
if(marker.toSet().size == markerSize) {
return true
}
return false
}
... | 0 | Kotlin | 0 | 0 | a166014be8bf379dcb4012e1904e25610617c550 | 1,666 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/kLoops/examples/island.kt | Onuchin-Artem | 231,309,462 | false | {"Kotlin": 59394, "JavaScript": 4465} | package kLoops.examples
typealias Point = Pair<Int, Int>
data class World(val landPoints: Set<Point>, val height: Int, val width: Int) {
fun print() {
(0 until height).forEach { row ->
(0 until width).forEach { column ->
val value = if (landPoints.contains(Point(row, column))) ... | 0 | Kotlin | 1 | 10 | ee076b3ca539e8d5c7abc60f310b9624ba187dbf | 2,785 | k-Loops | MIT License |
advent-of-code-2021/src/main/kotlin/eu/janvdb/aoc2021/day25/Day25.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2021.day25
import eu.janvdb.aocutil.kotlin.readLines
const val FILENAME = "input25.txt"
fun main() {
val board = Board.create()
var currentBoard = board
var nextBoard = board.move()
var step = 1
while(currentBoard != nextBoard) {
currentBoard = nextBoard
nextBoard = currentBoard.move()... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,724 | advent-of-code | Apache License 2.0 |
src/Day20.kt | palex65 | 572,937,600 | false | {"Kotlin": 68582} | @file:Suppress("PackageDirectoryMismatch")
package day20
import readInput
import kotlin.math.*
fun mix(numbers: List<Long>, times: Int = 1): List<Long> {
val ns = numbers.withIndex().toMutableList()
repeat(times) {
for (idx in 0..numbers.lastIndex) {
var i = ns.indexOfFirst { it.index == id... | 0 | Kotlin | 0 | 2 | 35771fa36a8be9862f050496dba9ae89bea427c5 | 1,155 | aoc2022 | Apache License 2.0 |
src/main/java/ir/toolki/ganmaz/classification/DataSet.kt | shahrivari | 134,160,197 | false | {"Kotlin": 10064} | package ir.toolki.ganmaz.classification
import com.google.common.collect.HashMultiset
import com.google.common.collect.Multiset
import com.google.common.collect.Multisets
import java.util.*
class DataSet(documents: List<Document>) {
private val digestedDocs: MutableList<DigestedDoc> = arrayListOf()
private va... | 0 | Kotlin | 1 | 0 | e069145faf2cd2e042368ad71b26969f2d64e041 | 2,187 | slstest | MIT License |
kotlin/2019/qualification-round/cryptopangrams/src/main/kotlin/Solution.kt | ShreckYe | 345,946,821 | false | null | import java.math.BigInteger
fun main() {
val T = readLine()!!.toInt()
repeat(T) { t ->
val line = readLine()!!.split(' ')
val N = line[0].toBigInteger()
val L = line[1].toInt()
val ciphertext =
readLine()!!.splitToSequence(' ')/*.filter(String::isNotEmpty)*/.map(Stri... | 0 | Kotlin | 1 | 1 | 743540a46ec157a6f2ddb4de806a69e5126f10ad | 2,458 | google-code-jam | MIT License |
src/main/kotlin/Day01.kt | brigham | 573,127,412 | false | {"Kotlin": 59675} | fun main() {
fun solve(input: List<String>, n: Int = 1): List<Int> {
val calHeap = descendingHeap<Int>()
input.asSequence()
.chunkedBy { it.isNotBlank() }
.map { block -> block.sumOf { it.toInt() } }
.forEach { calHeap.add(it) }
return (0 until n).map { c... | 0 | Kotlin | 0 | 0 | b87ffc772e5bd9fd721d552913cf79c575062f19 | 764 | advent-of-code-2022 | Apache License 2.0 |
src/main/day14/Part1.kt | ollehagner | 572,141,655 | false | {"Kotlin": 80353} | package day14
import common.Direction
import common.Direction.*
import common.Grid
import common.Point
import common.Vector
import day14.CaveContent.*
import readInput
import java.util.function.Predicate
val SAND_SOURCE_POINT = Point(500,0)
fun main() {
val cave = parseInput(readInput("day14/input.txt"))
val... | 0 | Kotlin | 0 | 0 | 6e12af1ff2609f6ef5b1bfb2a970d0e1aec578a1 | 1,632 | aoc2022 | Apache License 2.0 |
src/main/kotlin/adventofcode/PuzzleDay03.kt | MariusSchmidt | 435,574,170 | false | {"Kotlin": 28290} | package adventofcode
import java.io.File
class PuzzleDay03(significantBits: Int) {
private val histogramSize = significantBits * 2
fun readGammaAndEpsilon(input: File): Pair<Int, Int> =
input.useLines { bitsSequence ->
val gammaBits = bitsSequence.deriveBitmask(true)
val gamm... | 0 | Kotlin | 0 | 0 | 2b7099350fa612cb69c2a70d9e57a94747447790 | 2,526 | adventofcode2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/d16/d16b.kt | LaurentJeanpierre1 | 573,454,829 | false | {"Kotlin": 118105} | package d16
import readInput
import java.util.PriorityQueue
data class Node(val valve: Valve, val time: Int, val flow: Int, val opened: Set<Valve>, val pression: Int, val opening : Boolean) : Comparable<Node> {
private fun score(): Float = (pression-(31-time)*flow)/time.toFloat()
override fun compareTo(other:... | 0 | Kotlin | 0 | 0 | 5cf6b2142df6082ddd7d94f2dbde037f1fe0508f | 2,138 | aoc2022 | Creative Commons Zero v1.0 Universal |
kotlin/src/katas/kotlin/leetcode/twosum/TwoSum.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... | @file:Suppress("DuplicatedCode")
package katas.kotlin.leetcode.twosum
import nonstdlib.printed
import datsok.shouldEqual
import org.junit.Test
import kotlin.random.Random
/**
* https://leetcode.com/problems/two-sum
*/
class TwoSum {
@Test fun `find indices of numbers that add up to the target number (with loop... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,877 | katas | The Unlicense |
src/array/LeetCode240.kt | Alex-Linrk | 180,918,573 | false | null | package array
/**
* 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target。该矩阵具有以下特性:
每行的元素从左到右升序排列。
每列的元素从上到下升序排列。
示例:
现有矩阵 matrix 如下:
[
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]
给定 target = 5,返回 true。
给定 target = 20,返回 false。
*/
class Solution240 {
... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 1,852 | LeetCode | Apache License 2.0 |
src/main/kotlin/days/Day22.kt | nuudles | 316,314,995 | false | null | package days
class Day22 : Day(22) {
override fun partOne(): Any {
val (player1, player2) = inputString.split("\n\n").let { decks ->
decks.first().split("\n").drop(1).map { it.toLong() }.toMutableList() to
decks.last().split("\n").drop(1).map { it.toLong() }.toMutableList()
... | 0 | Kotlin | 0 | 0 | 5ac4aac0b6c1e79392701b588b07f57079af4b03 | 2,889 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
2021/kotlin/src/main/kotlin/com/codelicia/advent2021/Day12.kt | codelicia | 627,407,402 | false | {"Kotlin": 49578, "PHP": 554, "Makefile": 293} | package com.codelicia.advent2021
import java.util.Stack
class Day12(mapOfTheRemainingCaves: List<String>) {
data class Vertex(val label: String)
private val map = mapOfTheRemainingCaves
.map { cave -> cave.split("-") }
.map { cave -> cave.first() to cave.last() }
private val graph = bui... | 2 | Kotlin | 0 | 0 | df0cfd5c559d9726663412c0dec52dbfd5fa54b0 | 2,232 | adventofcode | MIT License |
src/shreckye/coursera/algorithms/StronglyConnectedComponents.kt | ShreckYe | 205,871,625 | false | {"Kotlin": 72136} | package shreckye.coursera.algorithms
import java.util.*
import kotlin.collections.ArrayList
data class Scc(val sccLeader: Int, val sccVertices: SimpleIntArrayList)
private inline fun searchSccs(
numVertices: Int, graph: IndexGraph, inverseGraph: IndexGraph,
beforeSearchingScc: (Int) -> Unit, crossinline sear... | 0 | Kotlin | 1 | 2 | 1746af789d016a26f3442f9bf47dc5ab10f49611 | 1,685 | coursera-stanford-algorithms-solutions-kotlin | MIT License |
src/Day10.kt | xNakero | 572,621,673 | false | {"Kotlin": 23869} | object Day10 {
fun part1(): Int =
with(readInput()) {
generateSequence(20) { it + 40 }.take(6).toList()
.map { (1 + this.take(it - 1).sum()) * it }
}.sum()
fun part2() {
val registryByTime = readInput().let { commands ->
commands.indices.map { co... | 0 | Kotlin | 0 | 0 | c3eff4f4c52ded907f2af6352dd7b3532a2da8c5 | 963 | advent-of-code-2022 | Apache License 2.0 |
implementation/src/main/kotlin/io/github/tomplum/aoc/game/cards/CamelCards.kt | TomPlum | 724,225,748 | false | {"Kotlin": 141244} | package io.github.tomplum.aoc.game.cards
class CamelCards(cardsData: List<String>) {
private val hands = cardsData.associate { line ->
val (hands, bid) = line.trim().split(" ")
hands to bid
}
private val suits = listOf('A', 'K', 'Q', 'J', 'T') + (9 downTo 2).map { number -> number.toStrin... | 0 | Kotlin | 0 | 1 | d1f941a3c5bacd126177ace6b9f576c9af07fed6 | 5,665 | advent-of-code-2023 | Apache License 2.0 |
src/main/kotlin/Day20.kt | Avataw | 572,709,044 | false | {"Kotlin": 99761} | package aoc
import java.lang.Math.floorMod
fun solve20A(input: List<String>): Long {
val numbers = input.mapIndexed { index, s -> Number(s.toLong(), index) }.toMutableList()
numbers.mix()
return numbers.extractGroveCoordinates()
}
fun solve20B(input: List<String>): Long {
val decryptionKey = 811589... | 0 | Kotlin | 2 | 0 | 769c4bf06ee5b9ad3220e92067d617f07519d2b7 | 1,294 | advent-of-code-2022 | Apache License 2.0 |
2015/src/main/kotlin/com/koenv/adventofcode/Day19.kt | koesie10 | 47,333,954 | false | null | package com.koenv.adventofcode
class Day19(input: CharSequence) {
private val replacements: Map<String, List<String>>
private val lexer: Lexer
init {
this.replacements = input.lines().map {
val parts = it.split(" => ")
parts[0] to parts[1]
}.groupBy { it.first }.map... | 0 | Kotlin | 0 | 0 | 29f3d426cfceaa131371df09785fa6598405a55f | 3,213 | AdventOfCode-Solutions-Kotlin | MIT License |
src/main/kotlin/g2001_2100/s2048_next_greater_numerically_balanced_number/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2048_next_greater_numerically_balanced_number
// #Medium #Math #Backtracking #Enumeration
// #2023_06_23_Time_138_ms_(100.00%)_Space_33.4_MB_(100.00%)
class Solution {
fun nextBeautifulNumber(n: Int): Int {
val arr = intArrayOf(0, 1, 2, 3, 4, 5, 6)
val select = BooleanArray(7)
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,426 | LeetCode-in-Kotlin | MIT License |
src/Day22.kt | wgolyakov | 572,463,468 | false | null | import javafx.geometry.Point3D
import javafx.scene.transform.Rotate
import javafx.scene.transform.Transform
import kotlin.math.min
import kotlin.math.roundToInt
fun main() {
val right = 0
val down = 1
val left = 2
val up = 3
val positionToMove = mapOf(
right to (1 to 0),
down to (0 to 1),
left to (-1 to 0)... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 7,194 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/wtf/log/xmas2021/day/day13/Day13.kt | damianw | 434,043,459 | false | {"Kotlin": 62890} | package wtf.log.xmas2021.day.day13
import com.google.common.collect.HashBasedTable
import com.google.common.collect.Table
import wtf.log.xmas2021.Day
import wtf.log.xmas2021.util.collect.set
import wtf.log.xmas2021.util.math.Point
import java.io.BufferedReader
object Day13 : Day<Input, Int, String> {
override fu... | 0 | Kotlin | 0 | 0 | 1c4c12546ea3de0e7298c2771dc93e578f11a9c6 | 3,244 | AdventOfKotlin2021 | BSD Source Code Attribution |
src/main/kotlin/g0601_0700/s0648_replace_words/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0601_0700.s0648_replace_words
// #Medium #Array #String #Hash_Table #Trie #2023_02_11_Time_392_ms_(100.00%)_Space_62.4_MB_(25.00%)
import java.util.function.Consumer
class Solution {
fun replaceWords(dictionary: List<String>, sentence: String): String {
val trie = Trie()
dictionary.forEa... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,000 | LeetCode-in-Kotlin | MIT License |
src/Day12.kt | mcrispim | 573,449,109 | false | {"Kotlin": 46488} | import java.security.InvalidParameterException
fun main() {
data class Pos(val line: Int, val col: Int)
data class Node(val elevation: Char, val possibleWays: List<Pos>) {
var distance: Int = Int.MAX_VALUE
var comeFrom: Pos? = null
}
fun elevationOk(input: List<String>, pos: Pos): Char... | 0 | Kotlin | 0 | 0 | 5fcacc6316e1576a172a46ba5fc9f70bcb41f532 | 4,154 | AoC2022 | Apache License 2.0 |
src/heap/LeetCode378.kt | Alex-Linrk | 180,918,573 | false | null | package heap
import kotlin.math.max
/**
* 给定一个 n x n 矩阵,其中每行和每列元素均按升序排序,找到矩阵中第k小的元素。
*请注意,它是排序后的第k小元素,而不是第k个元素。
*
*示例:
*
*matrix = [
*[ 1, 5, 9],
*[10, 11, 13],
*[12, 13, 15]
*],
*k = 8,
*
*返回 13。
*说明:
*你可以假设 k 的值永远是有效的, 1 ≤ k ≤ n2 。
*/
class LeetCode378 {
fun kthSmallest(matrix: Array<IntArray>... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 2,201 | LeetCode | Apache License 2.0 |
src/jvmMain/kotlin/day09/initial/Day09.kt | liusbl | 726,218,737 | false | {"Kotlin": 109684} | package day09.initial
import util.add
import util.set
import java.io.File
fun main() {
// solvePart1() // Solution: 2175229206, time: 09:56
solvePart2() // Solution: 942, time: 10:06
}
fun solvePart2() {
// val input = File("src/jvmMain/kotlin/day09/input/input_part1_test.txt")
val input = File("src/jv... | 0 | Kotlin | 0 | 0 | 1a89bcc77ddf9bc503cf2f25fbf9da59494a61e1 | 2,509 | advent-of-code | MIT License |
src/y2015/Day24.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2015
import util.generateTakes
import util.product
import util.readInput
object Day24 {
private fun parse(input: List<String>): List<Long> {
return input.map { it.toLong() }
}
fun part1(input: List<String>, compartments: Int): Long {
val weights = parse(input)
val total =... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 1,396 | advent-of-code | Apache License 2.0 |
2023/src/main/kotlin/Day06.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.pow
import kotlin.math.sqrt
object Day06 {
private data class Race(val time: Long, val distance: Long)
fun part1(input: String): Long {
val (times, distances) = input.splitNewlines().map { it.splitWhitespace().drop(1).toLongList() }
val ... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 1,242 | advent-of-code | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.