path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
kotlin/src/katas/kotlin/leetcode/regex_matching/v3/RegexMatching.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.regex_matching.v3
import datsok.shouldEqual
import org.junit.jupiter.api.Test
class RegexMatching {
@Test fun `some examples`() {
"".matchesRegex("") shouldEqual true
"".matchesRegex("a") shouldEqual false
"a".matchesRegex("") shouldEqual false
"a".ma... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,194 | katas | The Unlicense |
src/main/kotlin/se/saidaspen/aoc/aoc2022/Day23.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2022
import se.saidaspen.aoc.util.*
import se.saidaspen.aoc.util.COMPASS.*
import kotlin.math.absoluteValue
fun main() = Day23.run()
object Day23 : Day(2022, 23) {
class World(val map: MutableMap<P<Int, Int>, Char>, var hasMoved: Boolean = false) {
private var considerDir = l... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 2,418 | adventofkotlin | MIT License |
src/Day03.kt | Totwart123 | 573,119,178 | false | null | fun main() {
fun Char.getValueOfItem() = if(this.isUpperCase()) this.code - 38 else this.code - 96
fun part1(input: List<String>): Int {
var sum = 0
input.forEach {items ->
val compartment1 = items.substring(0, items.length / 2)
val compartment2 = items.substring(items.l... | 0 | Kotlin | 0 | 0 | 33e912156d3dd4244c0a3dc9c328c26f1455b6fb | 988 | AoC | Apache License 2.0 |
calendar/day07/Day7.kt | polarene | 572,886,399 | false | {"Kotlin": 17947} | package day07
import Day
import Lines
class Day7 : Day() {
override fun part1(input: Lines): Any {
val fs = Filesystem.init(input)
return fs.findDirsBySize { it <= 100_000 }.sum()
}
override fun part2(input: Lines): Any {
val totalSpace = 70_000_000
val updateSpace = 30_00... | 0 | Kotlin | 0 | 0 | 0b2c769174601b185227efbd5c0d47f3f78e95e7 | 3,105 | advent-of-code-2022 | Apache License 2.0 |
src/Day07.kt | weberchu | 573,107,187 | false | {"Kotlin": 91366} | private interface FileDescriptor {
val name: String
}
private data class Directory(
override val name: String,
val parent: Directory?,
val children: MutableMap<String, FileDescriptor>
): FileDescriptor
private data class File(
override val name: String,
val size: Long
): FileDescriptor
privat... | 0 | Kotlin | 0 | 0 | 903ff33037e8dd6dd5504638a281cb4813763873 | 4,136 | advent-of-code-2022 | Apache License 2.0 |
src/day02/Day02.kt | iammohdzaki | 573,280,588 | false | {"Kotlin": 2028} | package day02
import readInput
fun main() {
val part1Scores: Map<String, Int> =
mapOf(
"A X" to 1 + 3,
"A Y" to 2 + 6,
"A Z" to 3 + 0,
"B X" to 1 + 0,
"B Y" to 2 + 3,
"B Z" to 3 + 6,
"C X" to 1 + 6,
"C Y" to 2 ... | 0 | Kotlin | 0 | 0 | 70fae2770ae91467b5663fdc69135da0baa3e352 | 939 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/hopkins/aoc/day22/main.kt | edenrox | 726,934,488 | false | {"Kotlin": 88215} | package com.hopkins.aoc.day22
import java.io.File
import java.lang.IllegalStateException
const val debug = true
const val part = 1
/** Advent of Code 2023: Day 22 */
fun main() {
// Step 1: Read the file input
val lines: List<String> = File("input/input22.txt").readLines()
if (debug) {
println("S... | 0 | Kotlin | 0 | 0 | 45dce3d76bf3bf140d7336c4767e74971e827c35 | 5,593 | aoc2023 | MIT License |
src/main/kotlin/com/github/michaelbull/advent2023/day10/PipeMap.kt | michaelbull | 726,012,340 | false | {"Kotlin": 195941} | package com.github.michaelbull.advent2023.day10
import com.github.michaelbull.advent2023.math.Vector2
import com.github.michaelbull.advent2023.math.Vector2CharMap
import com.github.michaelbull.advent2023.math.toVector2CharMap
fun Sequence<String>.toPipeMap(): PipeMap {
val tiles = this.toVector2CharMap()
val ... | 0 | Kotlin | 0 | 1 | ea0b10a9c6528d82ddb481b9cf627841f44184dd | 3,232 | advent-2023 | ISC License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DistributeCookies.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,365 | kotlab | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/Search.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
/**
* 81. 搜索旋转排序数组 II
* 已知存在一个按非降序排列的整数数组 nums ,数组中的值不必互不相同。
*
* 在传递给函数之前,nums 在预先未知的某个下标 k(0 <= k < nums.length)上进行了 旋转 ,使数组变为 [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]](下标 从 0 开始 计数)。例如, [0,1,2,4,4,4,5,6,6,7] 在下标 5 处经旋转后可能变为 [4,5,6,6,7,0,1,2,4,4] 。... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,168 | daily_algorithm | Apache License 2.0 |
src/main/kotlin/com/jacobhyphenated/advent2023/day12/Day12.kt | jacobhyphenated | 725,928,124 | false | {"Kotlin": 121644} | package com.jacobhyphenated.advent2023.day12
import com.jacobhyphenated.advent2023.Day
import com.jacobhyphenated.advent2023.product
class Day12: Day<List<Pair<List<Char>, List<Int>>>> {
override fun getInput(): List<Pair<List<Char>, List<Int>>> {
return parseInput(readInputFile("12"))
}
override fun part1... | 0 | Kotlin | 0 | 0 | 90d8a95bf35cae5a88e8daf2cfc062a104fe08c1 | 4,394 | advent2023 | The Unlicense |
src/Day23.kt | Kvest | 573,621,595 | false | {"Kotlin": 87988} | import kotlin.math.max
import kotlin.math.min
fun main() {
val testInput = readInput("Day23_test")
check(part1(testInput) == 110)
check(part2(testInput) == 20)
val input = readInput("Day23")
println(part1(input))
println(part2(input))
}
private val DIRECTIONS = listOf(
//N, NE, NW
lis... | 0 | Kotlin | 0 | 0 | 6409e65c452edd9dd20145766d1e0ea6f07b569a | 3,648 | AOC2022 | Apache License 2.0 |
src/main/kotlin/days/Day2.kt | mstar95 | 317,305,289 | false | null | package days
class Day2 : Day(2) {
override fun partOne(): Any {
val input = inputList.map { splitFirst(it) }
return input.filter { run(it) }.size
}
override fun partTwo(): Any {
val input = inputList.map { splitSecond(it) }
return input.filter { runSecond(it) }.size
... | 0 | Kotlin | 0 | 0 | ca0bdd7f3c5aba282a7aa55a4f6cc76078253c81 | 1,611 | aoc-2020 | Creative Commons Zero v1.0 Universal |
advent-of-code/src/main/kotlin/DayEight.kt | pauliancu97 | 518,083,754 | false | {"Kotlin": 36950} | class DayEight {
private fun getNumMemoryCharacters(string: String): Int {
var currentString = string
var result = 0
while (currentString.isNotEmpty()) {
val firstChar = currentString.first()
if (firstChar != '"') {
result++
}
i... | 0 | Kotlin | 0 | 0 | 3ba05bc0d3e27d9cbfd99ca37ca0db0775bb72d6 | 1,868 | advent-of-code-2015 | MIT License |
src/Day11.kt | HylkeB | 573,815,567 | false | {"Kotlin": 83982} | fun main() {
class Operation(
val leftValue: String,
val operator: String,
val rightValue: String,
) {
fun execute(oldValue: Long): Long {
val left = if (leftValue == "old") oldValue else leftValue.toLong()
val right = if (rightValue == "old") oldValue el... | 0 | Kotlin | 0 | 0 | 8649209f4b1264f51b07212ef08fa8ca5c7d465b | 4,701 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/aoc2019/Day7.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2019
class Day7(input: List<String>) {
private val parsedInput = input.map { it.toLong() }.toList()
data class Amplifier(val program: List<Long>, val setting: Long) {
private val computer = Intcode(program, mutableListOf(setting))
fun isDone() = computer.computerState == Intcode.Co... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,838 | aoc | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2022/Day19.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2022
import se.saidaspen.aoc.util.*
import java.lang.Integer.max
import kotlin.math.min
fun main() = Day19.run()
object Day19 : Day(2022, 19) {
private val bps = input.lines().map { ints(it) }.map {
Pair(
it[0], // id of blueprint
listOf(listOf(it[1], ... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 3,817 | adventofkotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/PathsWithMaxScore.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,261 | kotlab | Apache License 2.0 |
app/src/main/kotlin/advent_of_code/year_2022/day3/RucsackReorganization.kt | mavomo | 574,441,138 | false | {"Kotlin": 56468} | package advent_of_code.year_2022.day3
import com.google.common.collect.ImmutableList
class RucsackReorganization {
private val alphabetsInLowerCase = ('a'..'z').toSet()
private val alphabetsInUpperCase = ('A'..'Z').toSet()
fun computeSumOfAllPriorities(sample: List<String>): Any {
var totalPriori... | 0 | Kotlin | 0 | 0 | b7fec100ea3ac63f48046852617f7f65e9136112 | 2,726 | advent-of-code | MIT License |
src/main/java/Day9.kt | mattyb678 | 319,195,903 | false | null | class Day9 : Day {
override fun asInt(): Int = 9
override fun part1InputName(): String = "day9"
override fun part1(input: List<String>): String {
val preamble = 25
return firstNonMatch(preamble, input).toString()
}
private fun List<Long>.sums(): Sequence<Long> {
val result... | 0 | Kotlin | 0 | 1 | f677d61cfd88e18710aafe6038d8d59640448fb3 | 2,194 | aoc-2020 | MIT License |
src/Day05.kt | nordberg | 573,769,081 | false | {"Kotlin": 47470} | fun main() {
fun part1(input: List<String>): String {
// [P] [L] [T]
// [L] [M] [G] [G] [S]
// [M] [Q] [W] [H] [R] [G]
// [N] [F] [M] [D] [V] [R] [N]
// [W] [G] [Q] [P] [J] [F] [M] [C]
// [V] [H] [B] [F] [H] [M] [B] [H] [B]
// ... | 0 | Kotlin | 0 | 0 | 3de1e2b0d54dcf34a35279ba47d848319e99ab6b | 2,476 | aoc-2022 | Apache License 2.0 |
solutions/src/CherryPickup.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | import java.util.*
/**
* https://leetcode.com/problems/cherry-pickup/
*/
class CherryPickup {
fun cherryPickup(grid: Array<IntArray>): Int {
val n = grid.size
val dp = Array(n + 1) { Array(n + 1) { IntArray(n + 1) } }
for (i in 0..n) {
for (j in 0..n) {
Arrays... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 1,338 | leetcode-solutions | MIT License |
src/Day04.kt | PascalHonegger | 573,052,507 | false | {"Kotlin": 66208} | fun main() {
fun String.toCleaningRange() = split('-').let { (from, to) -> from.toInt()..to.toInt() }
fun String.toCleaningRanges() = split(',').map { it.toCleaningRange() }
operator fun IntRange.contains(other: IntRange) = first <= other.first && last >= other.last
fun part1(input: List<String>): Int ... | 0 | Kotlin | 0 | 0 | 2215ea22a87912012cf2b3e2da600a65b2ad55fc | 875 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g1701_1800/s1722_minimize_hamming_distance_after_swap_operations/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1701_1800.s1722_minimize_hamming_distance_after_swap_operations
// #Medium #Array #Depth_First_Search #Union_Find
// #2023_06_16_Time_843_ms_(100.00%)_Space_87.9_MB_(100.00%)
class Solution {
fun minimumHammingDistance(source: IntArray, target: IntArray, allowedSwaps: Array<IntArray>): Int {
var ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,973 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/g2801_2900/s2809_minimum_time_to_make_array_sum_at_most_x/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2801_2900.s2809_minimum_time_to_make_array_sum_at_most_x
// #Hard #Array #Dynamic_Programming #Sorting
// #2023_12_06_Time_325_ms_(100.00%)_Space_42.6_MB_(100.00%)
import kotlin.math.max
class Solution {
fun minimumTime(nums1: List<Int?>, nums2: List<Int?>, x: Int): Int {
val n = nums1.size
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,161 | LeetCode-in-Kotlin | MIT License |
src/Day02.kt | NunoPontes | 572,963,410 | false | {"Kotlin": 7416} | fun main() {
val rock = 1
val paper = 2
val scissors = 3
val win = 6
val draw = 3
val lost = 0
fun part1(input: List<String>): Int {
return input.sumOf {
when (it) {
"A X" -> rock + draw
"A Y" -> paper + win
"A Z" -> sciss... | 0 | Kotlin | 0 | 0 | 78b67b952e0bb51acf952a7b4b056040bab8b05f | 1,293 | advent-of-code-2022 | Apache License 2.0 |
2023/10/solve-1.kts | gugod | 48,180,404 | false | {"Raku": 170466, "Perl": 121272, "Kotlin": 58674, "Rust": 3189, "C": 2934, "Zig": 850, "Clojure": 734, "Janet": 703, "Go": 595} | import java.io.File
enum class Dir { NORTH, EAST, SOUTH, WEST }
data class Coord (val y: Int, val x: Int)
class PipeNetwork (val sketch: List<String>) {
val rows = sketch.indices
val cols = sketch[0].indices
private val dirsOfPipe = mapOf<Char,List<Dir>>(
'|' to listOf(Dir.NORTH, Dir.SOUTH),
... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 2,398 | advent-of-code | Creative Commons Zero v1.0 Universal |
dcp_kotlin/src/main/kotlin/dcp/day231/day231.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day231
// day231.kt
// By <NAME>, 2019.
import kotlin.math.ceil
/**
* Interleave letters of s if possible in a way that no two adjacent letters are the same.
* Returns null if cannot be done, and otherwise one method of doing so.
*/
fun interleave(s: String): String? {
// Check if feasible.
if ... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 1,984 | daily-coding-problem | MIT License |
src/Day02.kt | RickShaa | 572,623,247 | false | {"Kotlin": 34294} | fun main() {
val fileName = "day02.txt"
val testFileName = "day02_test.txt"
val input:String = FileUtil.getTrimmedText(fileName);
val testInput:String = FileUtil.getTrimmedText(testFileName);
val WON = 6;
val DRAW =3;
val LOSS = 0;
//Create Lookup map to store
val choiceMap = ma... | 0 | Kotlin | 0 | 1 | 76257b971649e656c1be6436f8cb70b80d5c992b | 1,877 | aoc | Apache License 2.0 |
2020/src/year2021/day10/code.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2021.day10
import util.readAllLines
import java.util.*
fun main() {
part1()
part2()
}
private val OPENERS = setOf('(', '{', '[', '<')
private val CLOSERS = setOf(')', '}', ']', '>')
private val OPENTOCLOSE = mapOf(
'(' to ')',
'{' to '}',
'[' to ']',
'<' to '>'
)
private fun part... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 2,072 | adventofcode | MIT License |
src/main/kotlin/eu/michalchomo/adventofcode/Utils.kt | MichalChomo | 572,214,942 | false | {"Kotlin": 56758} | package eu.michalchomo.adventofcode
import java.io.File
private const val ROOT_PATH = "src/main/kotlin/eu/michalchomo/adventofcode/year"
fun readInput(year: Int, name: String) =
File("$ROOT_PATH$year", "$name.txt").readText()
/**
* Reads lines from the given input txt file.
*/
fun readInputLines(year: Int, na... | 0 | Kotlin | 0 | 0 | a95d478aee72034321fdf37930722c23b246dd6b | 2,331 | advent-of-code | Apache License 2.0 |
2022/src/day21/day21.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day21
import GREEN
import RESET
import printTimeMillis
import readInput
sealed class Job {
data class Number(val nb: Long): Job()
data class Operation(val left: String, val right: String, val operation: Ope): Job()
}
interface Ope {
fun doOp(a: Long, b: Long): Long
fun fromResult(result: Long... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 4,106 | advent-of-code | Apache License 2.0 |
src/Day06.kt | iartemiev | 573,038,071 | false | {"Kotlin": 21075} | fun findUnique(line: String, sequenceLength: Int): Int {
var startIdx = 0
var found = false
while (!found) {
val countSet = line.subSequence(startIdx, startIdx + sequenceLength).toSet()
if (countSet.size == sequenceLength) {
found = true
} else {
startIdx++
}
}
return startIdx + ... | 0 | Kotlin | 0 | 0 | 8d2b7a974c2736903a9def65282be91fbb104ffd | 1,008 | advent-of-code | Apache License 2.0 |
murdle_solver.main.kts | dfings | 739,242,704 | false | {"Kotlin": 1574} | #!/usr/bin/env kotlin
@file:Repository("https://repo1.maven.org/maven2/")
@file:DependsOn("com.google.guava:guava:33.0.0-jre")
import com.google.common.collect.Collections2.permutations
typealias Combo = List<Int>
typealias Solution = List<Combo>
class Constraint(val values: Combo) {
val isNegative = values.any... | 0 | Kotlin | 0 | 0 | c4e727bb71437ffa7d785688b84bdc5b76420685 | 1,574 | murdle | The Unlicense |
src/Day03.kt | fmborghino | 573,233,162 | false | {"Kotlin": 60805} | // as an extension property, note ext props can't be local
val Char.scoreProp: Int
get() = if (this.isLowerCase()) {
this.code - 96
} else {
this.code - 64 + 26
}
fun main() {
fun log(message: Any?) {
// println(message)
}
fun Char.score(): Int {
... | 0 | Kotlin | 0 | 0 | 893cab0651ca0bb3bc8108ec31974654600d2bf1 | 1,326 | aoc2022 | Apache License 2.0 |
src/main/kotlin/net/voldrich/aoc2021/Day20.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2021
import net.voldrich.BaseDay
// link to task
fun main() {
Day20().run()
}
class Day20 : BaseDay() {
override fun task1() : Int {
val image = ImageEnhancement()
image.print()
val enhanced = image.enhance()
enhanced.print()
val twiceEnhanced =... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 3,137 | advent-of-code | Apache License 2.0 |
src/Day16Part1.kt | underwindfall | 573,471,357 | false | {"Kotlin": 42718} | fun main() {
val dayId = "16"
val input = readInput("Day${dayId}")
class VD(val id: Int, val r: Int, val us: List<String>)
var cnt = 0
val vs = HashMap<String, VD>()
for (s in input) {
val (v, r, t) = Regex("Valve ([A-Z][A-Z]) has flow rate=(\\d+); tunnel[s]? lead[s]? to valve[s]? ([A-Z,... | 0 | Kotlin | 0 | 0 | 0e7caf00319ce99c6772add017c6dd3c933b96f0 | 1,223 | aoc-2022 | Apache License 2.0 |
advent2021/src/main/kotlin/year2021/Day02.kt | bulldog98 | 572,838,866 | false | {"Kotlin": 132847} | package year2021
import AdventDay
private typealias Direction = Pair<String, Int>
private fun List<String>.toDirections() = map {
val (a, b) = it.split(' ')
a to b.toInt()
}
private fun Direction.toMovement() = when (first) {
"forward" -> 0 to second
"up" -> -second to 0
"down" -> second to 0
... | 0 | Kotlin | 0 | 0 | 02ce17f15aa78e953a480f1de7aa4821b55b8977 | 1,223 | advent-of-code | Apache License 2.0 |
src/main/kotlin/shortestpath/개선된_다익스트라_알고리즘.kt | CokeLee777 | 614,704,937 | false | null | package shortestpath
import java.util.*
import kotlin.Comparator
import kotlin.math.*
private const val INF = 1e9.toInt()
fun main(){
val sc = Scanner(System.`in`)
//노드의 개수와 간선의 개수 입력받기
val n = sc.nextInt()
val m = sc.nextInt()
//시작노드 번호 입력받기
val start = sc.nextInt()
//최단거리 테이블 초기화
va... | 0 | Kotlin | 0 | 0 | 919d6231c87fe4ee7fda6c700099e212e8da833f | 2,000 | algorithm | MIT License |
src/Day05.kt | fmborghino | 573,233,162 | false | {"Kotlin": 60805} | fun main() {
fun log(message: Any?) {
// println(message)
}
// ugly-ish "matrix rotate" of the stacks, removing the junk columns and "leading" spaces
// so the test stacks come back looking like...
// NZ
// DCM
// P
// TODO switch this to return Array<ArrayDeque<Char>>, but for n... | 0 | Kotlin | 0 | 0 | 893cab0651ca0bb3bc8108ec31974654600d2bf1 | 5,260 | aoc2022 | Apache License 2.0 |
src/main/kotlin/days/y22/Day05.kt | kezz | 572,635,766 | false | {"Kotlin": 20772} | package days.y22
import util.Day
import util.mapInner
import util.splitAroundBlankStrings
public fun main() {
Day5().run()
}
public class Day5 : Day(22, 5) {
override fun part1(input: List<String>): Any = input
.splitAroundBlankStrings()
.toList()
.let { (startState, instructions) -> ... | 0 | Kotlin | 0 | 0 | 1cef7fe0f72f77a3a409915baac3c674cc058228 | 2,588 | aoc | Apache License 2.0 |
src/day13/Day13.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day13
import readInput
fun findClosingBracket(input: String, start: Int): Int {
var i = start
var nestLevel = 1
while (nestLevel != 0) {
when(input[i]) {
'[' -> nestLevel += 1
']' -> nestLevel -= 1
}
i += 1
}
return i
}
abstract class S... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 5,916 | AdventOfCode2022 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions10.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
fun test10() {
printlnResult(intArrayOf(1, 1, 1), 2)
printlnResult(intArrayOf(1, 3, 5, 4, -2, 2, 7), 9)
}
/**
* Questions 10: Give an IntArray and an integer k, find the count of consistent sub-arrays in the IntArray that sum equals k
*/
private infix fun IntArray.fin... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 886 | Algorithm | Apache License 2.0 |
kotlin/src/main/kotlin/com/github/jntakpe/aoc2022/days/Day18.kt | jntakpe | 572,853,785 | false | {"Kotlin": 72329, "Rust": 15876} | package com.github.jntakpe.aoc2022.days
import com.github.jntakpe.aoc2022.shared.Day
import com.github.jntakpe.aoc2022.shared.readInputLines
object Day18 : Day {
override val input = readInputLines(18)
.map { l -> l.split(',').map { it.toInt() }.let { (x, y, z) -> Position(x, y, z) } }
override fun ... | 1 | Kotlin | 0 | 0 | 63f48d4790f17104311b3873f321368934060e06 | 1,597 | aoc2022 | MIT License |
src/main/kotlin/branchandbound/examples/ContinuousKnapsackSolver.kt | sujeevraja | 196,775,908 | false | null | package branchandbound.examples
import branchandbound.api.INode
import branchandbound.api.ISolver
import kotlin.math.min
/**
* Implementation of greedy algorithm to solve continuous knapsack problems to optimality. Given
* [profits] (item utilities) and [weights] (item weights) and the knapsack [capacity], the
* a... | 2 | Kotlin | 1 | 1 | 6a2b0899aa216d2697082ceb62004b7676f26b75 | 2,479 | fixed-wing-drone-orienteering | MIT License |
src/Day05.kt | rosyish | 573,297,490 | false | {"Kotlin": 51693} | fun simulatePart1(stacks: List<MutableList<Char>>, n: Int, from: Int, to: Int): Unit {
for (i in 1..n) {
if (!stacks[from - 1].isEmpty()) stacks[to - 1].add(stacks[from - 1].removeLast())
}
}
fun simulatePart2(stacks: List<MutableList<Char>>, n: Int, from: Int, to: Int): Unit {
stacks[to - 1].addAl... | 0 | Kotlin | 0 | 2 | 43560f3e6a814bfd52ebadb939594290cd43549f | 1,301 | aoc-2022 | Apache License 2.0 |
src/Day11.kt | Kbzinho-66 | 572,299,619 | false | {"Kotlin": 34500} | import java.lang.Exception
private data class WorryOperation(val operator: String, val value: String) {
fun apply(starting: Long): Long {
val actualValue = if (value == "old") starting else value.toLong()
val result = when (operator) {
"*" -> starting * actualValue
"+" -> st... | 0 | Kotlin | 0 | 0 | e7ce3ba9b56c44aa4404229b94a422fc62ca2a2b | 5,195 | advent_of_code_2022_kotlin | Apache License 2.0 |
LeetCode/Kotlin/src/main/kotlin/org/redquark/tutorials/leetcode/LongestPalindromeSubstring.kt | ani03sha | 297,402,125 | false | null | package org.redquark.tutorials.leetcode
fun longestPalindrome(s: String): String {
// Update the string to put hash "#" at the beginning, end and in between each character
val updatedString = getUpdatedString(s)
// Length of the array that will store the window of palindromic substring
val length = 2 *... | 2 | Java | 40 | 64 | 67b6ebaf56ec1878289f22a0324c28b077bcd59c | 2,216 | RedQuarkTutorials | MIT License |
src/main/kotlin/ru/timakden/aoc/year2016/Day07.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2016
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 7: Internet Protocol Version 7](https://adventofcode.com/2016/day/7).
*/
object Day07 {
@JvmStatic
fun main(args: Array<String>) {
measure {
val input = readInput("year20... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 2,473 | advent-of-code | MIT License |
src/nativeMain/kotlin/Day11.kt | rubengees | 576,436,006 | false | {"Kotlin": 67428} | class Day11 : Day {
private data class Monkey(
val items: List<Long>,
val operation: (Long) -> Long,
val divisor: Long,
val trueTarget: Int,
val falseTarget: Int
) {
fun targetFor(value: Long): Int {
return if (value.mod(divisor) == 0L) trueTarget else... | 0 | Kotlin | 0 | 0 | 21f03a1c70d4273739d001dd5434f68e2cc2e6e6 | 2,902 | advent-of-code-2022 | MIT License |
src/year2020/day3/Solution.kt | Niallfitzy1 | 319,123,397 | false | null | package year2020.day3
import java.io.File
import java.nio.charset.Charset
fun main() {
val mapData: List<String> =
File("src/year2020/day3/input").readLines(Charset.defaultCharset())
val map = Map(mapData)
val productOfSlopes = listOf<Long>(
findNumberOfTreesForDirection(map, Vector(1, 1)... | 0 | Kotlin | 0 | 0 | 67a69b89f22b7198995d5abc19c4840ab2099e96 | 1,949 | AdventOfCode | The Unlicense |
src/main/kotlin/aoc/year2022/Day05.kt | SackCastellon | 573,157,155 | false | {"Kotlin": 62581} | package aoc.year2022
import aoc.Puzzle
import java.util.*
import kotlin.collections.ArrayDeque
private typealias Rearrange = (stacks: Map<Int, ArrayDeque<Char>>, amount: Int, from: Int, to: Int) -> Unit
/**
* [Day 5 - Advent of Code 2022](https://adventofcode.com/2022/day/5)
*/
object Day05 : Puzzle<String, String... | 0 | Kotlin | 0 | 0 | 75b0430f14d62bb99c7251a642db61f3c6874a9e | 2,149 | advent-of-code | Apache License 2.0 |
year2023/src/cz/veleto/aoc/year2023/Day16.kt | haluzpav | 573,073,312 | false | {"Kotlin": 164348} | package cz.veleto.aoc.year2023
import cz.veleto.aoc.core.AocDay
import cz.veleto.aoc.core.Pos
import cz.veleto.aoc.core.get
import cz.veleto.aoc.core.plus
class Day16(config: Config) : AocDay(config) {
override fun part1(): String = countEnergizedTiles(startBeam = Pos(0, 0) to Direction.Right).toString()
ov... | 0 | Kotlin | 0 | 1 | 32003edb726f7736f881edc263a85a404be6a5f0 | 3,516 | advent-of-pavel | Apache License 2.0 |
src/Lesson8Leader/Dominator.kt | slobodanantonijevic | 557,942,075 | false | {"Kotlin": 50634} |
import java.util.HashMap
/**
* 100/100
* @param A
* @return
*/
fun solution(A: IntArray): Int {
if (A.size == 0) return -1
val count: HashMap<Int, Int> = HashMap<Int, Int>()
for (i in A.indices) {
if (count.containsKey(A[i])) {
count[A[i]] = (count[A[i]] ?: 0) + 1
} else {... | 0 | Kotlin | 0 | 0 | 155cf983b1f06550e99c8e13c5e6015a7e7ffb0f | 1,614 | Codility-Kotlin | Apache License 2.0 |
src/questions/SingleElementInSortedArray.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
/**
* You are given a sorted array consisting of only integers where every element appears exactly twice,
* except for one element which appears exactly once.
* Return the single element that appears only once.
* Your solution must r... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,864 | algorithms | MIT License |
src/main/kotlin/nl/tiemenschut/aoc/y2023/day11.kt | tschut | 723,391,380 | false | {"Kotlin": 61206} | package nl.tiemenschut.aoc.y2023
import nl.tiemenschut.aoc.lib.dsl.aoc
import nl.tiemenschut.aoc.lib.dsl.day
import nl.tiemenschut.aoc.lib.util.grid.CharGridParser
import nl.tiemenschut.aoc.lib.util.grid.Grid
import nl.tiemenschut.aoc.lib.util.points.by
import kotlin.math.max
import kotlin.math.min
fun main() {
a... | 0 | Kotlin | 0 | 1 | a1ade43c29c7bbdbbf21ba7ddf163e9c4c9191b3 | 1,943 | aoc-2023 | The Unlicense |
src/main/kotlin/Day09.kt | SimonMarquis | 570,868,366 | false | {"Kotlin": 50263} | import kotlin.math.absoluteValue
import kotlin.math.sign
class Day09(input: List<String>) {
private val operations = input.asSequence()
.map { it.split(" ") }
.flatMap { (direction, number) -> List(number.toInt()) { direction } }
fun part1(): Int {
var head = origin
var tail =... | 0 | Kotlin | 0 | 0 | a2129cc558c610dfe338594d9f05df6501dff5e6 | 1,627 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | catcutecat | 572,816,768 | false | {"Kotlin": 53001} | import java.util.*
import kotlin.system.measureTimeMillis
fun main() {
measureTimeMillis {
Day05.run {
solve1("CMZ") // "CWMTGHBDW"
solve2("MCD") // "SSCGWJCRB"
}
}.let { println("Total: $it ms") }
}
object Day05 : Day.RowInput<Day05.SupplyStacks, String>("05") {
d... | 0 | Kotlin | 0 | 2 | fd771ff0fddeb9dcd1f04611559c7f87ac048721 | 2,315 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/com/nibado/projects/advent/y2020/Day18.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2020
import com.nibado.projects.advent.*
import com.nibado.projects.advent.collect.Stack
object Day18 : Day {
private val values = resourceLines(2020, 18).map {
it.replace(" ", "").split("").filterNot(String::isBlank)
}
override fun part1() = values.map { eval(... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 1,772 | adventofcode | MIT License |
src/Day20.kt | AlaricLightin | 572,897,551 | false | {"Kotlin": 87366} | fun main() {
fun mixList(list: MutableList<ListElement>) {
val listSizeMinus1 = list.size - 1
for (i in 0..list.lastIndex) {
val currentIndex: Int = list.indexOfFirst { it.initialOrder == i }
if (currentIndex < 0)
throw IllegalArgumentException()
... | 0 | Kotlin | 0 | 0 | ee991f6932b038ce5e96739855df7807c6e06258 | 1,847 | AdventOfCode2022 | Apache License 2.0 |
module-tool/src/main/kotlin/de/twomartens/adventofcode/day17/graph/GraphWalker.kt | 2martens | 729,312,999 | false | {"Kotlin": 89431} | package de.twomartens.adventofcode.day17.graph
import mu.KotlinLogging
import java.util.*
data class VisitedNode(val row: Int, val column: Int, var direction: Direction?, var directionCount: Int = 0)
data class PathNode(val visitedNode: VisitedNode, val distanceToStart: Int) : Comparable<PathNode> {
override fun ... | 0 | Kotlin | 0 | 0 | 03a9f7a6c4e0bdf73f0c663ff54e01daf12a9762 | 4,822 | advent-of-code | Apache License 2.0 |
src/Day03.kt | thelmstedt | 572,818,960 | false | {"Kotlin": 30245} | import java.io.File
fun main() {
fun part1(file: File): Int {
val priorities = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
val priorityMap = priorities.mapIndexed { index, c -> c to index + 1 }.toMap()
return file
.readText()
.lineSequence()
... | 0 | Kotlin | 0 | 0 | e98cd2054c1fe5891494d8a042cf5504014078d3 | 1,478 | advent2022 | Apache License 2.0 |
kotlin/src/main/kotlin/com/github/fstaudt/aoc2021/day2/Day2.kt | fstaudt | 433,733,254 | true | {"Kotlin": 9482, "Rust": 1574} | package com.github.fstaudt.aoc2021.day2
import com.github.fstaudt.aoc2021.day2.Day2.Step.Companion.toCommand
import com.github.fstaudt.aoc2021.shared.Day
import com.github.fstaudt.aoc2021.shared.readInputLines
fun main() {
Day2().run()
}
class Day2 : Day {
override val input: List<String> = readInputLines(2)... | 0 | Kotlin | 0 | 0 | f2ee9bca82711bc9aae115400ecff6db5d683c9e | 1,608 | aoc2021 | MIT License |
src/Day10.kt | mjossdev | 574,439,750 | false | {"Kotlin": 81859} | private sealed interface Instruction {
val cycles: Int
}
private class Addx(val value: Int) : Instruction {
override val cycles
get() = 2
}
private object Noop : Instruction {
override val cycles: Int
get() = 1
}
private const val ROW_WIDTH = 40
fun main() {
class Cpu {
priva... | 0 | Kotlin | 0 | 0 | afbcec6a05b8df34ebd8543ac04394baa10216f0 | 2,355 | advent-of-code-22 | Apache License 2.0 |
src/day11/Day11.kt | pocmo | 433,766,909 | false | {"Kotlin": 134886} | package day11
import java.io.File
data class Position(
val x: Int,
val y: Int
)
data class Octopus(
var energy: Int,
var flashed: Boolean = false
) {
fun canFlash(): Boolean = energy > 9 && !flashed
fun flash() {
energy = 0
flashed = true
}
fun reset() {
if (... | 0 | Kotlin | 1 | 2 | 73bbb6a41229e5863e52388a19108041339a864e | 3,451 | AdventOfCode2021 | Apache License 2.0 |
src/main/kotlin/aoc2020/CrabCombat.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2020
import komu.adventofcode.utils.nonEmptyLines
fun crabCombat1(s: String): Int {
val (deck1, deck2) = parseDecks(s)
while (deck1.isNotEmpty() && deck2.isNotEmpty()) {
val top1 = deck1.removeAt(0)
val top2 = deck2.removeAt(0)
if (top1 > top2) {
... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 1,962 | advent-of-code | MIT License |
src/day8/Day8.kt | blundell | 572,916,256 | false | {"Kotlin": 38491} | package day8
import readInput
data class Height(
val value: Int,
val westHeights: List<Int>,
val eastHeights: List<Int>,
val northHeights: List<Int>,
val southHeights: List<Int>,
) {
val visible by lazy {
return@lazy listOf(
northHeights,
southHeights,
... | 0 | Kotlin | 0 | 0 | f41982912e3eb10b270061db1f7fe3dcc1931902 | 4,177 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/Day13.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | private abstract class Packet {
fun compareTo(other: Packet): Int {
if (this is IntPacket && other is IntPacket) return this.compareTo(other)
if (this is IntPacket && other is ListPacket) return this.compareTo(other)
if (this is ListPacket && other is ListPacket) return this.compareTo(other)... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 4,049 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | roxanapirlea | 572,665,040 | false | {"Kotlin": 27613} | fun main() {
fun Char.getPriority(): Long {
return if (this.isUpperCase()) {
code - 'A'.code + 27L
} else {
code - 'a'.code + 1L
}
}
fun part1(input: List<String>): Long {
return input.map { backpack ->
val (compartment1, compartment2) =
... | 0 | Kotlin | 0 | 0 | 6c4ae6a70678ca361404edabd1e7d1ed11accf32 | 1,247 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2017/grid/FractalGrid.kt | tginsberg | 112,672,087 | false | null | package com.ginsberg.advent2017.grid
import kotlin.math.sqrt
fun List<FractalGrid>.join(): FractalGrid {
val rows = sqrt(this.size.toFloat()).toInt()
return this.chunked(rows).map {
it.reduce { a, b -> a nextTo b }
}.reduce { a, b -> a over b }
}
data class FractalGrid(val grid: List<List<Char>>)... | 0 | Kotlin | 0 | 15 | a57219e75ff9412292319b71827b35023f709036 | 2,063 | advent-2017-kotlin | MIT License |
src/Day02.kt | kecolk | 572,819,860 | false | {"Kotlin": 22071} | fun main() {
fun evalRound(input: String): Int {
return when (input) {
"A X" -> 4
"A Y" -> 8
"A Z" -> 3
"B X" -> 1
"B Y" -> 5
"B Z" -> 9
"C X" -> 7
"C Y" -> 2
"C Z" -> 6
else -> 0
... | 0 | Kotlin | 0 | 0 | 72b3680a146d9d05be4ee209d5ba93ae46a5cb13 | 998 | kotlin_aoc_22 | Apache License 2.0 |
src/main/java/com/booknara/problem/union/EarliestMomentWhenEveryoneBecomeFriendsKt.kt | booknara | 226,968,158 | false | {"Java": 1128390, "Kotlin": 177761} | package com.booknara.problem.union
/**
* 1101. The Earliest Moment When Everyone Become Friends (Medium)
* https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends/
*/
class EarliestMomentWhenEveryoneBecomeFriendsKt {
// T:O(nlogn), S:O(n)
fun earliestAcq(logs: Array<IntArray>, n: Int): In... | 0 | Java | 1 | 1 | 04dcf500ee9789cf10c488a25647f25359b37a53 | 1,163 | playground | MIT License |
src/main/kotlin/day9.kt | Arch-vile | 572,557,390 | false | {"Kotlin": 132454} | package day9
import aoc.utils.Cursor
import aoc.utils.firstPart
import aoc.utils.readInput
import aoc.utils.secondPart
import kotlin.math.abs
fun part1(): Int {
var head = Cursor(0, 0)
val directions = readInput("day9-input.txt")
.map { Pair(it.firstPart(), it.secondPart().toInt()) }
val headLoc... | 0 | Kotlin | 0 | 0 | e737bf3112e97b2221403fef6f77e994f331b7e9 | 3,227 | adventOfCode2022 | Apache License 2.0 |
leetcode/snakes-and-ladders/main.kt | seirion | 17,619,607 | false | {"C++": 801740, "HTML": 42242, "Kotlin": 37689, "Python": 21759, "C": 3798, "JavaScript": 294} | // https://leetcode.com/problems/snakes-and-ladders
import java.util.*
class Solution {
data class Data(val cost: Int, val index: Int)
fun snakesAndLadders(board: Array<IntArray>): Int {
val size = board.size * board.size
val jump = board.reversed()
.mapIndexed { i, b -> if (i %... | 0 | C++ | 4 | 4 | a59df98712c7eeceabc98f6535f7814d3a1c2c9f | 1,941 | code | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ClosestDessertCost.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,136 | kotlab | Apache License 2.0 |
src/main/kotlin/year_2022/Day06.kt | krllus | 572,617,904 | false | {"Kotlin": 97314} | package year_2022
import utils.readInput
fun main() {
fun processLine(line: String): Int {
for (index in 4..line.length - 4) {
val a = line[index - 4]
val b = line[index - 3]
val c = line[index - 2]
val d = line[index - 1]
if (a != b && a != c &... | 0 | Kotlin | 0 | 0 | b5280f3592ba3a0fbe04da72d4b77fcc9754597e | 1,913 | advent-of-code | Apache License 2.0 |
src/main/java/challenges/leetcode/MergeSortedArray.kt | ShabanKamell | 342,007,920 | false | null | package challenges.leetcode
/**
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.
Merge nums1 and nums2 into a single array sorted in non-decreasing order.
The final sorted array should not be... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 2,183 | CodingChallenges | Apache License 2.0 |
src/Day10.kt | wlghdu97 | 573,333,153 | false | {"Kotlin": 50633} | import java.util.*
private class CPU constructor(private val instructions: List<Instruction>) {
fun run(onCycle: (cycle: Int, x: Int) -> Unit) {
val instQueue: Queue<Instruction> = LinkedList()
instructions.forEach {
instQueue.add(it)
}
var x = 1
var cycle = 1
... | 0 | Kotlin | 0 | 0 | 2b95aaaa9075986fa5023d1bf0331db23cf2822b | 3,051 | aoc-2022 | Apache License 2.0 |
src/chapter3/section2/ex32_Certification.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter3.section2
/**
* 验证
* 编写一个方法isBST(),接受一个结点Node为参数,若该结点是一个二叉查找树的根节点则返回true,否则返回false
* 提示:这个任务比看起来要困难,它和你调用前三题中各个方法的顺序有关
*
* 解:isBinaryTree必须第一个判断,否则有环的数据结构会导致后面的死循环
* 在我的实现中isOrdered()和hasNoDuplicates()方法的顺序并不重要
* hasNoDuplicates()不通过则isOrdered()也无法通过
*/
fun <K : Comparable<K>> isBST(node: Binar... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,709 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/Day03.kt | sd2000usr | 573,123,353 | false | {"Kotlin": 21846} |
val abc = "abcdefghijklmnopqrstuvwxyz"
val alphabet = "$abc${abc.uppercase()}"
fun main()
{
fun part1(input: List<String>)
{
var scoreAcc = 0
input.forEach ()
{ string ->
val map0 = mutableMapOf<Char, Int>() // char, times appear
val map1 = mutableMapOf... | 0 | Kotlin | 0 | 0 | fe5307af5dd8620ae8dee0ad5244466b5332e535 | 4,434 | cfgtvsizedxr8jubhy | Apache License 2.0 |
src/main/kotlin/adventofcode/year2020/Day22CrabCombat.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2020
import adventofcode.Puzzle
import adventofcode.PuzzleInput
class Day22CrabCombat(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val player1 by lazy { input.split("\n\n").first().lines().drop(1).map(String::toInt) }
private val player2 by lazy { input.split("\n\... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 2,794 | AdventOfCode | MIT License |
src/main/kotlin/year_2022/Day05.kt | krllus | 572,617,904 | false | {"Kotlin": 97314} | package year_2022
import utils.readInputAsText
fun main() {
fun createStorage(cargos: List<String>): MutableMap<Int, ElfStack> {
val storage: MutableMap<Int, ElfStack> = HashMap()
for (index in 0..cargos.size - 2) {
val row = cargos[index]
val elements = row.toCharArray()... | 0 | Kotlin | 0 | 0 | b5280f3592ba3a0fbe04da72d4b77fcc9754597e | 3,830 | advent-of-code | Apache License 2.0 |
src/algorithmdesignmanualbook/datastructures/MultiplicativeArray.kt | realpacific | 234,499,820 | false | null | package algorithmdesignmanualbook.datastructures
import _utils.UseCommentAsDocumentation
import algorithmdesignmanualbook.print
import algorithmdesignmanualbook.withPrint
import utils.assertArraysSame
/**
* You have an unordered array X of n integers. Find the array M containing
* n elements where Mi is the product... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 3,860 | algorithms | MIT License |
src/Day20.kt | LauwiMeara | 572,498,129 | false | {"Kotlin": 109923} | import kotlin.math.abs
const val DECRYPTION_KEY = 811589153
fun main() {
fun createSequence(input: List<Int>, isPart2: Boolean = false): MutableList<Pair<Int, Long>> {
val sequence = mutableListOf<Pair<Int, Long>>()
for (i in input.indices) {
if (isPart2) {
sequence.add... | 0 | Kotlin | 0 | 1 | 34b4d4fa7e562551cb892c272fe7ad406a28fb69 | 2,064 | AoC2022 | Apache License 2.0 |
src/Day01.kt | kecolk | 572,819,860 | false | {"Kotlin": 22071} | fun main() {
fun elvesCalories(input: List<Int?>): Collection<Int> {
return input
.scan(
Pair<Int, Int?>(
0,
0
)
) { acc, value -> Pair(if (value == null) acc.first + 1 else acc.first, value) }
.group... | 0 | Kotlin | 0 | 0 | 72b3680a146d9d05be4ee209d5ba93ae46a5cb13 | 893 | kotlin_aoc_22 | Apache License 2.0 |
src/main/kotlin/util/Dijkstra.kt | Flame239 | 433,046,232 | false | {"Kotlin": 64209} | import java.util.*
class Edge(val v1: String, val v2: String, val dist: Int)
class Vertex(val name: String) : Comparable<Vertex> {
var dist = Int.MAX_VALUE // MAX_VALUE assumed to be infinity
var previous: Vertex? = null
val neighbours = HashMap<Vertex, Int>()
fun printPath() {
when (previou... | 0 | Kotlin | 0 | 0 | ef4b05d39d70a204be2433d203e11c7ebed04cec | 3,251 | advent-of-code-2021 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round0/Questions60.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round0
import kotlin.math.*
/**
* 求 n 个骰子的和的所有可能值出现的概率
*/
fun test60() {
printProbability1(6)
printProbability2(6)
}
const val MAX_VALUE = 6
// 基于递归
fun printProbability1(number: Int) {
if (number < 1) return
val array = IntArray(number) { 1 }
val sumArray = IntArray(MAX_VALU... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,571 | Algorithm | Apache License 2.0 |
src/main/kotlin/adventofcode2022/solution/day_5.kt | dangerground | 579,293,233 | false | {"Kotlin": 51472} | package adventofcode2022.solution
import adventofcode2022.util.readDay
private const val DAY_NUM = 5
fun main() {
val stacks = mapOf(
1 to "DBJV",
2 to "PVBWRDF",
3 to "RGFLDCWQ",
4 to "WJPMLNDB",
5 to "HNBPCSQ",
6 to "RDBSNG",
7 to "ZBPMQFSH",
8 to... | 0 | Kotlin | 0 | 0 | f1094ba3ead165adaadce6cffd5f3e78d6505724 | 2,017 | adventofcode-2022 | MIT License |
src/Day20.kt | asm0dey | 572,860,747 | false | {"Kotlin": 61384} | fun main() {
class Container<T : Number>(val value: T)
fun <T : Number> ArrayDeque<Container<T>>.mix(containers: List<Container<T>>) {
for (cont in containers) {
val oldIndex = indexOf(cont)
removeAt(oldIndex)
val newIndex = oldIndex.toLong() + cont.value.toLong()
... | 1 | Kotlin | 0 | 1 | f49aea1755c8b2d479d730d9653603421c355b60 | 1,789 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/endredeak/aoc2022/Day18.kt | edeak | 571,891,076 | false | {"Kotlin": 44975} | package endredeak.aoc2022
fun main() {
solve("Boiling Boulders") {
fun Triple<Int, Int, Int>.neighbours() = run {
val (x, y, z) = this
setOf(
Triple(0, 0, 1),
Triple(0, 1, 0),
Triple(1, 0, 0),
Triple(0, 0, -1),
... | 0 | Kotlin | 0 | 0 | e0b95e35c98b15d2b479b28f8548d8c8ac457e3a | 1,936 | AdventOfCode2022 | Do What The F*ck You Want To Public License |
src/main/kotlin/aoc/year2023/Day16.kt | SackCastellon | 573,157,155 | false | {"Kotlin": 62581} | package aoc.year2023
import aoc.Puzzle
/**
* [Day 16 - Advent of Code 2023](https://adventofcode.com/2023/day/16)
*/
object Day16 : Puzzle<Int, Int> {
override fun solvePartOne(input: String): Int {
val layout = input.toLayout()
val beam = Beam(Point(0, 0), Direction.RIGHT)
return getEne... | 0 | Kotlin | 0 | 0 | 75b0430f14d62bb99c7251a642db61f3c6874a9e | 5,775 | advent-of-code | Apache License 2.0 |
src/day10/Solution.kt | abhabongse | 576,594,038 | false | {"Kotlin": 63915} | /* Solution to Day 10: Cathode-Ray Tube
* https://adventofcode.com/2022/day/10
*/
package day10
import utils.accumulate
import java.io.File
import kotlin.math.absoluteValue
fun main() {
val fileName =
// "day10_sample_a.txt"
// "day10_sample_b.txt"
"day10_input.txt"
val cpuInstructions... | 0 | Kotlin | 0 | 0 | 8a0aaa3b3c8974f7dab1e0ad4874cd3c38fe12eb | 1,697 | aoc2022-kotlin | Apache License 2.0 |
solutions/aockt/y2015/Y2015D13.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2015
import aockt.util.generatePermutations
import io.github.jadarma.aockt.core.Solution
object Y2015D13 : Solution {
private val inputRegex = Regex("""^(\w+) would (lose|gain) (\d+) happiness units by sitting next to (\w+).$""")
/**
* Parses a single line of input and returns a triple c... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 2,659 | advent-of-code-kotlin-solutions | The Unlicense |
src/Day13.kt | MartinsCode | 572,817,581 | false | {"Kotlin": 77324} | enum class CompareResults {
LESS,
EQUAL,
GREATER
}
fun main() {
fun decompose(a: String): MutableList<String> {
val aList = mutableListOf<String>()
// parse the string
// since it's ment to be an array, remove outer brackets:
check(a[0] == '[')
check(a[a.lastInd... | 0 | Kotlin | 0 | 0 | 1aedb69d80ae13553b913635fbf1df49c5ad58bd | 5,564 | AoC-2022-12-01 | Apache License 2.0 |
src/main/aoc2022/Day2.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2022
class Day2(input: List<String>) {
// Represent the shapes (and desired outcomes) as the numbers 0-2.
// rock -> paper -> scissors -> rock
// 0 -> 1 -> 2 -> 0
val parsedInput = input.map { line ->
line.split(" ").let { it.first().first() - 'A' to it.last().first() -... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,908 | aoc | MIT License |
src/twentytwentytwo/day8/Day08.kt | colinmarsch | 571,723,956 | false | {"Kotlin": 65403, "Python": 6148} | package twentytwentytwo.day8
import readInput
fun main() {
fun part1(input: List<String>): Int {
val trees = mutableListOf<List<Int>>()
input.forEach { trees.add(it.chunked(1).map { it.toInt() }) }
var visibleTrees = trees.size * 4 - 4
for (i in 1 until trees.size - 1) {
... | 0 | Kotlin | 0 | 0 | bcd7a08494e6db8140478b5f0a5f26ac1585ad76 | 2,765 | advent-of-code | Apache License 2.0 |
puzzles/src/main/kotlin/com/kotlinground/puzzles/graph/reorderroutes/reorderRoutes.kt | BrianLusina | 113,182,832 | false | {"Kotlin": 483489, "Shell": 7283, "Python": 1725} | package com.kotlinground.puzzles.graph.reorderroutes
/**
* Reorders the edges of the directed graph represented as an adjacency list in connections such that each vertex
* is connected and has a path to the first vertex marked with 0. n represents the number of vertices.
*
* Complexity:
* n is the number of verti... | 1 | Kotlin | 1 | 0 | 5e3e45b84176ea2d9eb36f4f625de89d8685e000 | 2,945 | KotlinGround | MIT License |
src/Day08.kt | fouksf | 572,530,146 | false | {"Kotlin": 43124} | import java.io.File
import java.util.Arrays
import java.util.Deque
fun main() {
fun generateTallnessMapLeft(forest: List<List<Int>>): List<List<Int>> {
val tallnessMap = ArrayList<MutableList<Int>>()
for (i in forest.indices) {
tallnessMap.add(mutableListOf())
for (j in for... | 0 | Kotlin | 0 | 0 | 701bae4d350353e2c49845adcd5087f8f5409307 | 4,809 | advent-of-code-2022 | Apache License 2.0 |
src/y2022/day10.kt | sapuglha | 573,238,440 | false | {"Kotlin": 33695} | package y2022
import readFileAsLines
import kotlin.text.StringBuilder
fun main() {
fun part1(input: List<String>): Int {
val cycleOfInterest = listOf(20, 60, 100, 140, 180, 220)
var cycle = 0
var signal = 1
val collectedSignals = mutableListOf<Int>()
fun computeCycle() {
... | 0 | Kotlin | 0 | 0 | 82a96ccc8dcf38ae4974e6726e27ddcc164e4b54 | 2,352 | adventOfCode2022 | Apache License 2.0 |
src/main/kotlin/com/sk/set16/1685. Sum of Absolute Differences in a Sorted Array.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.set16
class Solution1685 {
/**
* res[i] = (nums[i] - nums[0]) + (nums[i] - nums[1]) + ... + (nums[i] - nums[i - 1]) <--- absolute difference of nums[i] with first i numbers
* + (nums[i] - nums[i]) + (nums[i + 1] - nums[i]) + (nums[i + 2] - nums[i]) + ... + (nums[n - 1] - nums[i... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,636 | leetcode-kotlin | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.