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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
archive/src/main/kotlin/com/grappenmaker/aoc/year20/Day08.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year20
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.year20.Opcode.*
import com.grappenmaker.aoc.hasDuplicateBy
import com.grappenmaker.aoc.untilNotDistinctBy
fun PuzzleSet.day8() = puzzle(8) {
val insns = inputLines.map { l ->
val (a, b) = l.split(" ")
... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,083 | advent-of-code | The Unlicense |
src/com/github/crunchynomnom/aoc2022/puzzles/Day07.kt | CrunchyNomNom | 573,394,553 | false | {"Kotlin": 14290, "Shell": 518} | package com.github.crunchynomnom.aoc2022.puzzles
import Puzzle
import java.io.File
class Day07 : Puzzle() {
private var dirHeap: MutableList<Dir> = mutableListOf()
override fun part1(input: File) {
var result = 0
for (line in input.readLines()) {
when {
line.endsW... | 0 | Kotlin | 0 | 0 | 88bae9c0ce7f66a78f672b419e247cdd7374cdc1 | 2,196 | advent-of-code-2022 | Apache License 2.0 |
Dynamic Programming/Primitive Calculator/src/Task.kt | jetbrains-academy | 515,621,972 | false | {"Kotlin": 123026, "TeX": 51581, "Java": 3566, "Python": 1156, "CSS": 671} |
private fun calculateDP(n: Int): IntArray {
val minOp = IntArray(n + 1)
minOp[0] = 0
for (i in 1..n) {
var current = minOp[i - 1] + 1
for (div in 2..3) {
if (i % div == 0) {
current = minOf(current, minOp[i / div] + 1)
}
}
minOp[i] = c... | 2 | Kotlin | 0 | 10 | a278b09534954656175df39601059fc03bc53741 | 861 | algo-challenges-in-kotlin | MIT License |
src/chapter2/section5/ex23_SamplingForSelection.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter2.section5
import chapter2.getCompareTimes
import chapter2.getDoubleArray
import chapter2.less
import chapter2.swap
import extensions.random
import extensions.shuffle
/**
* 选择的取样
* 实验使用取样来改进select()函数的想法。提示:使用中位数可能并不总是有效
*
* 解:可以使用三取样快速排序的思想优化,也可以用更复杂的练习2.3.24来实现
* 这里为简单起见使用了三取样快速排序的思想
* 和标准三取样快速... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 2,809 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/main/kotlin/io/steinh/aoc/day05/AlmanacInputProcessor.kt | daincredibleholg | 726,426,347 | false | {"Kotlin": 25396} | package io.steinh.aoc.day05
class AlmanacInputProcessor {
companion object {
const val LENGTH_POSITION = 3
}
fun transform(input: String): Input {
return Input(
extractSeeds(input),
extractBlockFor("seed-to-soil", input),
extractBlockFor("soil-to-fertil... | 0 | Kotlin | 0 | 0 | 4aa7c684d0e337c257ae55a95b80f1cf388972a9 | 2,232 | AdventOfCode2023 | MIT License |
src/main/kotlin/com/gildedrose/Item.kt | jack-bolles | 424,172,564 | false | {"Kotlin": 10899} | package com.gildedrose
data class Item(val name: String, val sellIn: Int, val quality: Int) {
override fun toString(): String {
return this.name + ", " + this.sellIn + ", " + this.quality
}
}
fun Item.ageBy(days: Int): Item {
return copy(
sellIn = remainingSellInAfter(days),
qualit... | 0 | Kotlin | 0 | 0 | 20362811724367e10e60fcf79b8709e60e9b0dde | 1,540 | GildedRose-Refactoring-Kata-Kotlin | MIT License |
2016/src/main/kotlin/com/koenv/adventofcode/Day4.kt | koesie10 | 47,333,954 | false | null | package com.koenv.adventofcode
import java.util.*
import java.util.regex.Pattern
import kotlin.comparisons.compareValues
object Day4 {
val ROOM_NAME_PATTERN: Pattern = Pattern.compile("([a-z\\-]*)-(\\d+)\\[([a-z]{5})\\]")
fun getRoomName(input: String): RoomName {
val matcher = ROOM_NAME_PATTERN.matc... | 0 | Kotlin | 0 | 0 | 29f3d426cfceaa131371df09785fa6598405a55f | 2,420 | AdventOfCode-Solutions-Kotlin | MIT License |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day11.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwenty
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
class Day11 : Day<Int> {
companion object {
private const val SEAT_EMPTY = 'L'
private const val SEAT_OCCUPIED = '#'
private const val PRINT_DEBUG = false
}
private... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 4,621 | adventofcode | Apache License 2.0 |
src/main/kotlin/leetcode/problem0126/WordLadder2.kt | ayukatawago | 456,312,186 | false | {"Kotlin": 266300, "Python": 1842} | package leetcode.problem0126
class WordLadder2 {
fun findLadders(beginWord: String, endWord: String, wordList: List<String>): List<List<String>> {
if (endWord !in wordList) return emptyList()
val wordSet = setOf(beginWord) + wordList.toSet()
val adjacentWordMap: HashMap<String, List<String... | 0 | Kotlin | 0 | 0 | f9602f2560a6c9102728ccbc5c1ff8fa421341b8 | 2,284 | leetcode-kotlin | MIT License |
advent-of-code/src/main/kotlin/com/akikanellis/adventofcode/year2022/Day03.kt | akikanellis | 600,872,090 | false | {"Kotlin": 142932, "Just": 977} | package com.akikanellis.adventofcode.year2022
object Day03 {
fun sumOfPrioritiesForMisplacedItemTypes(input: String) = lines(input)
.map { Pair(it.take(it.length / 2).toSet(), it.takeLast(it.length / 2).toSet()) }
.map { it.first.intersect(it.second).single() }
.sumOf { priority(it) }
... | 8 | Kotlin | 0 | 0 | 036cbcb79d4dac96df2e478938de862a20549dce | 843 | advent-of-code | MIT License |
src/main/kotlin/day10.kt | mercer | 113,610,628 | false | null | //
// References:
// https://dzone.com/articles/solving-the-josephus-problem-in-kotlin
class CircularHash {
fun calculate(circularListSize: Int, lengths: List<Int>): Pair<Int, Int> {
var circle = generateList(circularListSize)
println(circle); println()
for (length in lengths) {
... | 0 | Kotlin | 0 | 0 | 2bd6a2dc537f7ee44aa6fa23c2bf2804d034b4fc | 3,374 | advent-of-code-2017 | The Unlicense |
src/main/kotlin/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0001_0100.s0017_letter_combinations_of_a_phone_number
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Backtracking
// #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion
// #Big_O_Time_O(4^n)_Space_O(n) #2023_07_03_Time_155_ms_(95.24%)_Space_34.9_MB_(96.... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,368 | LeetCode-in-Kotlin | MIT License |
kotlin/src/katas/kotlin/leetcode/zigzag/ZigZag.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.zigzag
import nonstdlib.printed
import datsok.shouldEqual
import org.junit.Test
import kotlin.system.measureTimeMillis
class ZigZagThreeRowTests {
@Test fun `zigzag first column`() {
"ABC".zigzag() shouldEqual "ABC"
}
@Test fun `zigzag one cycle`() {
// A
... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,682 | katas | The Unlicense |
src/main/kotlin/com/github/bpark/companion/analyzers/TypeFeatureAnalyzer.kt | bpark | 93,539,081 | false | null | /*
* Copyright 2017 bpark
*
* 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 wri... | 0 | Kotlin | 0 | 0 | 56a81b36cbebdb3dfb343fd2a37ee4d227a8c4c4 | 7,069 | companion-classification-micro | Apache License 2.0 |
AdventOfCodeDay11/src/nativeMain/kotlin/Day11.kt | bdlepla | 451,510,571 | false | {"Kotlin": 165771} | class Day11(private val lines:List<String>) {
fun solvePart1():Int {
val cavern = Matrix.create(lines)
return (0 until 100).sumOf { countFlashesWhenStepping(cavern) }
}
fun solvePart2():Int {
val cavern = Matrix.create(lines)
val allPointsNumber = cavern.allPoints().count()... | 0 | Kotlin | 0 | 0 | 1d60a1b3d0d60e0b3565263ca8d3bd5c229e2871 | 2,608 | AdventOfCode2021 | The Unlicense |
src/main/kotlin/day3.kt | Gitvert | 725,292,325 | false | {"Kotlin": 97000} | fun day3 (lines: List<String>) {
val partNumbers = findPartNumbers(lines)
markInvalidPartNumbers(lines, partNumbers)
findAdjacentGears(lines, partNumbers)
val partNumberSum = partNumbers.filter { it.isValidPartNumber }.sumOf { it.number }
val gearRatioSum = calculateGearRatioSum(partNumbe... | 0 | Kotlin | 0 | 0 | f204f09c94528f5cd83ce0149a254c4b0ca3bc91 | 4,100 | advent_of_code_2023 | MIT License |
kotlin/src/katas/kotlin/leetcode/wildcard_matching/v2/WildcardMatching2.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.wildcard_matching.v2
import datsok.*
import org.junit.*
class WildcardMatching2 {
@Test fun `some examples`() {
match("", "") shouldEqual true
match("a", "") shouldEqual false
match("", "a") shouldEqual false
match("a", "a") shouldEqual true
m... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,110 | katas | The Unlicense |
src/main/kotlin/days/Day01.kt | julia-kim | 569,976,303 | false | null | package days
import readInput
fun main() {
fun mapElvesToCaloriesCounted(input: List<String>): HashMap<Int, Int> {
var i = 1
val hm: HashMap<Int, Int> = hashMapOf()
input.forEach { calories ->
if (calories.isBlank()) {
i++
return@forEach
... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 941 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day10/Day10.kt | stoerti | 726,442,865 | false | {"Kotlin": 19680} | package io.github.stoerti.aoc.day10
import io.github.stoerti.aoc.Grid2D
import io.github.stoerti.aoc.Grid2D.Coordinate
import io.github.stoerti.aoc.IOUtils
fun main(args: Array<String>) {
val grid = IOUtils.readInput("day_10_input").let { Grid2D.charGrid(it) }
println(grid)
val result1 = part1(grid)
println... | 0 | Kotlin | 0 | 0 | 05668206293c4c51138bfa61ac64073de174e1b0 | 1,578 | advent-of-code | Apache License 2.0 |
src/aoc_2022/Day02.kt | jakob-lj | 573,335,157 | false | {"Kotlin": 38689} | package aoc_2022
enum class PlayerSymbols(val value: Char) {
ROCK("X".toCharArray()[0]),
PAPER("Y".toCharArray()[0]),
SCISSOR("Z".toCharArray()[0])
}
enum class ElfSymbols(val value: Char) {
ROCK("A".toCharArray()[0]),
PAPER("B".toCharArray()[0]),
SCISSOR("C".toCharArray()[0])
}
enum class Pl... | 0 | Kotlin | 0 | 0 | 3a7212dff9ef0644d9dce178e7cc9c3b4992c1ab | 3,256 | advent_of_code | Apache License 2.0 |
src/main/kotlin/g2801_2900/s2872_maximum_number_of_k_divisible_components/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2801_2900.s2872_maximum_number_of_k_divisible_components
// #Hard #Dynamic_Programming #Depth_First_Search #Tree
// #2023_12_21_Time_780_ms_(100.00%)_Space_79_MB_(100.00%)
class Solution {
private var ans = 0
fun maxKDivisibleComponents(n: Int, edges: Array<IntArray>, values: IntArray, k: Int): Int ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,314 | LeetCode-in-Kotlin | MIT License |
src/Day17.kt | thpz2210 | 575,577,457 | false | {"Kotlin": 50995} | private class Solution17(input: List<String>) {
val jets = input.first().trim().split("").filter { it.isNotBlank() }
val rocks = (0..6).map { MutableCoordinate(it, 0) }.toMutableSet()
var jetCount = 0
fun part1(): Int {
repeat(2022) { count ->
val rock = nextRock(count, MutableCoor... | 0 | Kotlin | 0 | 0 | 69ed62889ed90692de2f40b42634b74245398633 | 4,960 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | Svikleren | 572,637,234 | false | {"Kotlin": 11180} | fun main() {
fun charToValue(char: Char): Int {
if (char > 64.toChar() && char < 91.toChar()) return char.code - 38
if (char > 96.toChar() && char < 123.toChar()) return char.code - 96
return 0
}
fun part1(input: List<String>): Int {
return input
.map { bag -> ba... | 0 | Kotlin | 0 | 0 | e63be3f83b96a73543bf9bc00c22dc71b6aa0f57 | 793 | advent-of-code-2022 | Apache License 2.0 |
lib/src/main/kotlin/com/bloidonia/advent/day05/Day05.kt | timyates | 433,372,884 | false | {"Kotlin": 48604, "Groovy": 33934} | package com.bloidonia.advent.day05
import com.bloidonia.advent.readList
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.File
import java.lang.Math.abs
import javax.imageio.ImageIO
data class Point(val x: Int, val y: Int) {
override fun toString(): String = "($x,$y)"
}
data class Vent(val... | 0 | Kotlin | 0 | 1 | 9714e5b2c6a57db1b06e5ee6526eb30d587b94b4 | 2,736 | advent-of-kotlin-2021 | MIT License |
2023/8/solve-2.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
import kotlin.text.Regex
fun lcmOf(a: Long, b: Long): Long {
val larger = maxOf(a,b)
val maxLcm = a * b
var lcm = larger
while (lcm <= maxLcm) {
if (lcm % a == 0L && lcm % b == 0L) {
return lcm
}
lcm += larger
}
return maxLcm
}
val lines ... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 1,242 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/chapter2/problem4/solution1.kts | neelkamath | 395,940,983 | false | null | /*
Question:
Partition: Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes
greater than or equal to x. If x is contained within the list the values of x only need to be after the elements less
than x (see below). The partition element x can appear anywhere in t... | 0 | Kotlin | 0 | 0 | 4421a061e5bf032368b3f7a4cee924e65b43f690 | 2,646 | ctci-practice | MIT License |
src/Day01.kt | strindberg | 572,685,170 | false | {"Kotlin": 15804} | import java.lang.Integer.max
fun main() {
fun part1(input: List<String>): Int =
input.fold(Pair(0, 0)) { (max, total), line ->
if (line.isEmpty())
Pair(max(total, max), 0)
else
Pair(max, total + line.toInt())
}.first
... | 0 | Kotlin | 0 | 0 | c5d26b5bdc320ca2aeb39eba8c776fcfc50ea6c8 | 843 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/scavi/brainsqueeze/adventofcode/Day2PasswordPhilosophy.kt | Scavi | 68,294,098 | false | {"Java": 1449516, "Kotlin": 59149} | package com.scavi.brainsqueeze.adventofcode
class Day2PasswordPhilosophy {
private val split = """(\d+)-(\d+) (.): (.*)""".toRegex()
fun solveA(input: List<String>, policy: (rule: Rule) -> Boolean): Int {
var validPasswords = 0
for (pwSetup in input) {
val rule = parse(pwSetup)
... | 0 | Java | 0 | 1 | 79550cb8ce504295f762e9439e806b1acfa057c9 | 1,059 | BrainSqueeze | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/PalindromePartitioning4.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,836 | kotlab | Apache License 2.0 |
src/main/kotlin/g2001_2100/s2054_two_best_non_overlapping_events/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2054_two_best_non_overlapping_events
// #Medium #Array #Dynamic_Programming #Sorting #Binary_Search #Heap_Priority_Queue
// #2023_06_25_Time_851_ms_(100.00%)_Space_108.7_MB_(50.00%)
import java.util.Arrays
class Solution {
fun maxTwoEvents(events: Array<IntArray>): Int {
Arrays.sort(e... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,263 | LeetCode-in-Kotlin | MIT License |
src/Day06_part2.kt | abeltay | 572,984,420 | false | {"Kotlin": 91982, "Shell": 191} | fun main() {
fun part2(input: String): Int {
val inArr = input.toCharArray()
val map = mutableMapOf<Char, Int>()
for (i in inArr.indices) {
map[inArr[i]] = map.getOrDefault(inArr[i], 0) + 1
if (i - 14 >= 0) {
map[inArr[i - 14]] = map.getOrDefault(inArr... | 0 | Kotlin | 0 | 0 | a51bda36eaef85a8faa305a0441efaa745f6f399 | 871 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/tasso/adventofcode/_2022/day02/Day02.kt | AndrewTasso | 433,656,563 | false | {"Kotlin": 75030} | package dev.tasso.adventofcode._2022.day02
import dev.tasso.adventofcode.Solution
class Day02 : Solution<Int> {
private val outcomeValueMap = mapOf("loss" to 0, "draw" to 3, "win" to 6)
private val shapeValueMap = mapOf("rock" to 1, "paper" to 2, "scissors" to 3)
override fun part1(input: List<String>):... | 0 | Kotlin | 0 | 0 | daee918ba3df94dc2a3d6dd55a69366363b4d46c | 2,712 | advent-of-code | MIT License |
google/2019/round1_b/1/easy.kt | seirion | 17,619,607 | false | {"C++": 801740, "HTML": 42242, "Kotlin": 37689, "Python": 21759, "C": 3798, "JavaScript": 294} |
fun main(args: Array<String>) {
val t = readLine()!!.toInt()
repeat(t) {
solve(it)
}
}
fun solve(num: Int) {
val (P, Q) = readLine()!!.split(" ").map { it.toInt() }
val xValues = IntArray(Q + 2) { 0 }
val yValues = IntArray(Q + 2) { 0 }
repeat(P) {
val (xx, yy, d) = readLi... | 0 | C++ | 4 | 4 | a59df98712c7eeceabc98f6535f7814d3a1c2c9f | 1,022 | code | Apache License 2.0 |
src/main/kotlin/uk/gov/justice/digital/hmpps/welcometoprison/model/arrivals/search/SearchByNameAndPrisonNumber.kt | ministryofjustice | 397,318,042 | false | {"Kotlin": 442896, "Dockerfile": 1195} | package uk.gov.justice.digital.hmpps.welcometoprison.model.arrivals.search
import uk.gov.justice.digital.hmpps.welcometoprison.model.arrivals.RecentArrival
import uk.gov.justice.digital.hmpps.welcometoprison.model.arrivals.search.Searcher.Result
import uk.gov.justice.digital.hmpps.welcometoprison.model.arrivals.search... | 0 | Kotlin | 0 | 0 | d98ea95ba869e7d922dfe5c1323d8e3b95692ec3 | 2,115 | hmpps-welcome-people-into-prison-api | MIT License |
src/day5/second/Solution.kt | verwoerd | 224,986,977 | false | null | package day5.second
import tools.boolToInt
import tools.timeSolution
fun main() = timeSolution {
executeProgram(readLine()!!.split(",").map { it.toInt() }.toIntArray())
}
fun executeProgram(code: IntArray): Int {
var pointer = 0
loop@ while (true) {
val current = code[pointer]
val startPointer = point... | 0 | Kotlin | 0 | 0 | 554377cc4cf56cdb770ba0b49ddcf2c991d5d0b7 | 2,334 | AoC2019 | MIT License |
src/Day11.kt | tbilou | 572,829,933 | false | {"Kotlin": 40925} | fun main() {
val day = "Day11"
// Hardcode input
fun input(): List<Monkey> {
var monkey0 = Monkey(
ArrayDeque(listOf(89, 84, 88, 78, 70)),
{ a: Long -> a * 5 },
mapOf(true to 6, false to 7),
7
)
var monkey1 = Monkey(
Arra... | 0 | Kotlin | 0 | 0 | de480bb94785492a27f020a9e56f9ccf89f648b7 | 4,759 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/arrays/FrequencyOfMaximumValue.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.arrays
/**
* Given an array ‘nums’ of length N containing positive integers
* and an array ‘query’ of length ‘Q’ containing indexes,
* print/store for each query the count of maximum value in the sub-array starting at index ‘i’
* and ending at index ‘N-1’.
*/
fun m... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 929 | algs4-leprosorium | MIT License |
src/main/kotlin/com/nibado/projects/advent/y2020/Day19.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2020
import com.nibado.projects.advent.*
object Day19 : Day {
private val values = resourceStrings(2020, 19)
private val rules1 = values.first().split("\n")
.map { it.split(":").let { (id, rule) -> id.toInt() to rule.trim() } }
.toMap()
private v... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 1,236 | adventofcode | MIT License |
src/day24/Day24.kt | spyroid | 433,555,350 | false | null | package day24
import kotlinx.coroutines.runBlocking
import readInput
import kotlin.math.floor
import kotlin.system.measureTimeMillis
// Some thoughts about that
// https://docs.google.com/spreadsheets/d/1eSizAHZFgb7XiQsDK7oG2U-f8c0M01F-c8K9nf68akg/edit?usp=sharing
fun calc(ww: Int, zz: Int = 0, p1: Int = 0, p2: Int ... | 0 | Kotlin | 0 | 0 | 939c77c47e6337138a277b5e6e883a7a3a92f5c7 | 3,214 | Advent-of-Code-2021 | Apache License 2.0 |
src/nativeMain/kotlin/Day9.kt | rubengees | 576,436,006 | false | {"Kotlin": 67428} | import kotlin.math.abs
class Day9 : Day {
private data class Point(val x: Int, val y: Int) {
fun distanceTo(other: Point) = Distance(this.x - other.x, this.y - other.y)
fun move(distance: Distance) = copy(x = x + distance.x, y = y + distance.y)
fun moveBehind(other: Point): Point {
... | 0 | Kotlin | 0 | 0 | 21f03a1c70d4273739d001dd5434f68e2cc2e6e6 | 2,282 | advent-of-code-2022 | MIT License |
LeetCode/Nearest Exit from Entrance in Maze/main.kt | thedevelopersanjeev | 112,687,950 | false | null | import java.util.*
class Solution {
private fun isSafe(i: Int, j: Int, m: Int, n: Int): Boolean {
return i >= 0 && j >= 0 && i < m && j < n
}
private fun isBoundary(i: Int, j: Int, m: Int, n: Int): Boolean {
return i == 0 || j == 0 || i == m - 1 || j == n - 1
}
fun nearestExit(maz... | 0 | C++ | 58 | 146 | 610520cc396fb13a03c606b5fb6739cfd68cc444 | 1,392 | Competitive-Programming | MIT License |
kotlin/704. Binary Search.kt | joaoreis | 457,046,710 | false | {"Kotlin": 19374} | import kotlin.math.floor
class Solution {
fun search(nums: IntArray, target: Int): Int {
var initialIndex = 0
var endIndex = nums.size - 1
while (initialIndex <= endIndex) {
val midIndex = (initialIndex + floor((endIndex - initialIndex) / 2f)).toInt()
if (target ==... | 0 | Kotlin | 0 | 0 | d9fc04b95c8a6dc99fbf4bfcf9d36b05b16fa093 | 1,239 | leetcode | MIT License |
src/main/aoc2020/Day10.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2020
class Day10(input: List<String>) {
private val differences = input.map { it.toInt() }
.toMutableList()
.apply { add(0); add(maxOrNull()!! + 3) }
.sorted()
.zipWithNext { a, b -> b - a }
fun solvePart1(): Int {
return differences.groupingB... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,391 | aoc | MIT License |
kotlin/src/2022/Day17_2022.kt | regob | 575,917,627 | false | {"Kotlin": 50757, "Python": 46520, "Shell": 430} | import kotlin.math.*
private typealias Shape = List<Pair<Int, Int>>
private val Width = 7
fun main() {
val d = readInput(17).trim().map {if (it == '<') -1 else 1}
val b = mutableListOf<Array<Int>>()
var ptr = -1
fun next(s: Shape): Shape {
ptr += 1
// left-right movement
var s... | 0 | Kotlin | 0 | 0 | cf49abe24c1242e23e96719cc71ed471e77b3154 | 3,209 | adventofcode | Apache License 2.0 |
src/Day10.kt | psabata | 573,777,105 | false | {"Kotlin": 19953} | fun main() {
val testInput = Day10.Computer(InputHelper("Day10_test.txt").readLines())
check(testInput.part1() == 13140)
check(testInput.part2() == 0)
val input = Day10.Computer(InputHelper("Day10.txt").readLines())
println("Part 1: ${input.part1()}")
println("Part 2: ${input.part2()}")
}
ob... | 0 | Kotlin | 0 | 0 | c0d2c21c5feb4ba2aeda4f421cb7b34ba3d97936 | 2,991 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | casslabath | 573,177,204 | false | {"Kotlin": 27085} | fun main() {
fun part1(input: List<String>): String {
val stacks = mutableListOf(
mutableListOf('R','S','L','F','Q'),
mutableListOf('N','Z','Q','G','P','T'),
mutableListOf('S','M','Q','B'),
mutableListOf('T','G','Z','J','H','C','B','Q'),
mutableLis... | 0 | Kotlin | 0 | 0 | 5f7305e45f41a6893b6e12c8d92db7607723425e | 2,227 | KotlinAdvent2022 | Apache License 2.0 |
src/main/aoc2015/Day17.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2015
class Day17(input: List<String>) {
val parsedInput = input.map { it.toInt() }
private fun fill(capacity: Int, emptyContainers: List<Int>, usedContainers: List<Int>, combinations: MutableList<List<Int>>) {
if (capacity == 0) {
combinations.add(usedContainers)
re... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,429 | aoc | MIT License |
src/leetcodeProblem/leetcode/editor/en/ReshapeTheMatrix.kt | faniabdullah | 382,893,751 | false | null | //In MATLAB, there is a handy function called reshape which can reshape an m x
//n matrix into a new one with a different size r x c keeping its original data.
//
// You are given an m x n matrix mat and two integers r and c representing the
//number of rows and the number of columns of the wanted reshaped matrix.
/... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,054 | dsa-kotlin | MIT License |
src/main/kotlin/adventofcode/year2020/Day04PassportProcessing.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2020
import adventofcode.Puzzle
import adventofcode.PuzzleInput
class Day04PassportProcessing(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val passports by lazy { input.split("\n\n").map { it.replace("\n", " ").split(" ") }.map(::Passport) }
override fun partOne(... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 2,198 | AdventOfCode | MIT License |
src/main/kotlin/Puzzle22.kt | namyxc | 317,466,668 | false | null | object Puzzle22 {
@JvmStatic
fun main(args: Array<String>) {
val input = Puzzle22::class.java.getResource("puzzle22.txt").readText()
val decksNormalPlay = Decks(input)
println(decksNormalPlay.calculateWinnerScoreNormalPlay())
val decksRecursivePlay = Decks(input)
printl... | 0 | Kotlin | 0 | 0 | 60fa6991ac204de6a756456406e1f87c3784f0af | 3,597 | adventOfCode2020 | MIT License |
src/main/kotlin/pl/mrugacz95/aoc/day22/day22.kt | mrugacz95 | 317,354,321 | false | null | package pl.mrugacz95.aoc.day22
fun <T : Comparable<T>> Iterable<T>.argmax(): Int? {
return withIndex().maxByOrNull { it.value }?.index
}
const val withCaching = false // cache slow down execution
val cache = mutableMapOf<Pair<Boolean, Int>, Pair<Int, List<Int>>>()
const val debug = false
fun log(message: String)... | 0 | Kotlin | 0 | 1 | a2f7674a8f81f16cd693854d9f564b52ce6aaaaf | 3,271 | advent-of-code-2020 | Do What The F*ck You Want To Public License |
src/objects/Functions.kt | davidassigbi | 334,302,078 | false | null | package objects
import classes.Func
import kotlin.math.atan
import kotlin.math.cos
import kotlin.math.pow
import kotlin.math.tan
object Functions {
/*
x.pow(3) + 3* x.pow(2) + 3*x+1
2 * tan(x) - 1
*/
val f = Func({ x, _ -> atan((x + 1) / 2) - x }, "x * x - 2 * x + 1")
val g = Func({ x, _ -> f... | 0 | Kotlin | 0 | 1 | 3ed410b4bc72465f8fcb5e753a6a69eb44bb0d36 | 2,050 | numerical-solver | Apache License 2.0 |
src/main/kotlin/extensions/sequences/Middle.kt | swantescholz | 102,711,230 | false | null | package extensions.sequences
import util.astTrue
import java.util.*
fun <T> Sequence<T>.concat(you: Sequence<T>): Sequence<T> {
return AppendSequence<T>(this, you)
}
fun <T> Sequence<T>.append(vararg elements: T): Sequence<T> = this.concat(elements.asSequence())
fun <T> Sequence<T>.prepend(vararg elements: T): Seq... | 0 | Kotlin | 0 | 0 | 20736acc7e6a004c29c328a923d058f85d29de91 | 2,919 | ai | Do What The F*ck You Want To Public License |
src/com/kingsleyadio/adventofcode/y2022/day10/Solution.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2022.day10
import com.kingsleyadio.adventofcode.util.readInput
fun main() {
part1()
part2()
}
fun part1() {
var cycle = 0
var value = 1
var signalSums = 0
fun checksum() {
val interestingCycles = setOf(20, 60, 100, 140, 180, 220)
if (cycl... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 1,206 | adventofcode | Apache License 2.0 |
src/day5/fr/Day05_1.kt | BrunoKrantzy | 433,844,189 | false | {"Kotlin": 63580} | package day5.fr
import java.io.File
fun readInputInt(name: String) = File("src", "$name.txt").readLines()
fun main() {
val testInput = day2.fr.readInputInt("input5")
val regex = "^(\\d+),(\\d+)\\s->\\s(\\d+),(\\d+)".toRegex()
var x1 = 0
var x2 = 0
var y1 = 0
var y2 = 0
var maxX = 0
... | 0 | Kotlin | 0 | 0 | 0d460afc81fddb9875e6634ee08165e63c76cf3a | 1,607 | Advent-of-Code-2021 | Apache License 2.0 |
scripts/Day11.kts | matthewm101 | 573,325,687 | false | {"Kotlin": 63435} | import java.io.File
data class Monkey(val items: MutableList<Long>, val op: (Long) -> Long, val divisor: Long, val trueTarget: Int, val falseTarget: Int, var inspects: Long)
val lines = File("../inputs/11.txt").readLines()
run {
val monkeys = (lines.indices step 7).map { i ->
val items = lines[i + 1].dro... | 0 | Kotlin | 0 | 0 | bbd3cf6868936a9ee03c6783d8b2d02a08fbce85 | 3,370 | adventofcode2022 | MIT License |
Number Base Converter/task/src/converter/Main.kt | jwgibanez | 399,542,486 | false | {"Java": 42892, "HTML": 14987, "Kotlin": 3698} | package converter
import java.math.BigDecimal
import java.math.BigInteger
import java.util.*
import kotlin.math.pow
fun main() {
val scanner = Scanner(System.`in`)
while (true) {
print("Enter two numbers in format: {source base} {target base} (To quit type /exit) ")
when (val input1 = scanner.... | 0 | Java | 0 | 0 | ea76a3c8b709c388873515f50c3051e2c81ad070 | 3,698 | kotlin-number-base-converter | Apache License 2.0 |
src/main/kotlin/days/Day07.kt | TheMrMilchmann | 571,779,671 | false | {"Kotlin": 56525} | /*
* Copyright (c) 2022 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, dis... | 0 | Kotlin | 0 | 1 | 2e01ab62e44d965a626198127699720563ed934b | 4,444 | AdventOfCode2022 | MIT License |
src/graphs/weighted/Main.kt | ArtemBotnev | 136,745,749 | false | {"Kotlin": 79256, "Shell": 292} | package graphs.weighted
import utils.Timer
private const val GRAPH_MAX_SIZE = 10
private const val INFINITY = 10_000L
fun main() {
undirectedWeightedMST()
directedWeightedShortest()
}
private fun undirectedWeightedMST() {
val graph = UndirectedWeightedGraph<Char>(GRAPH_MAX_SIZE, INFINITY).apply {
... | 0 | Kotlin | 0 | 0 | 530c02e5d769ab0a49e7c3a66647dd286e18eb9d | 2,345 | Algorithms-and-Data-Structures | MIT License |
kotlin/src/interview/最长回文子串.kt | yunshuipiao | 179,794,004 | false | null | package interview
//abcdcbe, 比如bcdcb就是结果
//中心法
fun longestPalindrome(s: String): String {
//求位置l为中心的最长回文子串的开始位置和长度
fun expandAroundCenter(s: String, l: Int, r: Int, result: IntArray) {
val len = s.length - 1
var left = l
var right = r
while (left >= 0 && right <= len && s[le... | 29 | Kotlin | 0 | 2 | 6b188a8eb36e9930884c5fa310517be0db7f8922 | 1,203 | rice-noodles | Apache License 2.0 |
src/main/kotlin/days/Day21.kt | TheMrMilchmann | 433,608,462 | false | {"Kotlin": 94737} | /*
* Copyright (c) 2021 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, dis... | 0 | Kotlin | 0 | 1 | dfc91afab12d6dad01de552a77fc22a83237c21d | 3,702 | AdventOfCode2021 | MIT License |
src/main/kotlin/cloud/dqn/leetcode/ValidPalindromeKt.kt | aviuswen | 112,305,062 | false | null | package cloud.dqn.leetcode
/**
* https://leetcode.com/problems/valid-palindrome/description/
Given a string, determine if it is a palindrome, considering only
alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a ... | 0 | Kotlin | 0 | 0 | 23458b98104fa5d32efe811c3d2d4c1578b67f4b | 3,103 | cloud-dqn-leetcode | No Limit Public License |
kotlin/numeric/WalshHadamarTransform.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package numeric
import java.util.Arrays
object WalshHadamarTransform {
// calculates c[k] = sum(a[i]*b[j] | i op j == k), where op = XOR | OR | AND
// complexity: O(n*log(n))
fun convolution(a: IntArray, b: IntArray, op: Operation): IntArray {
transform(a, op, false)
transform(b, op, false... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,866 | codelibrary | The Unlicense |
3/src/symbol/Symbol.kt | ldk123456 | 155,069,463 | false | null | package symbol
fun main(args: Array<String>) {
val list = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
//总数操作符
println("=====总数操作符=====")
println("list.any{it > 10}: ${list.any { it > 10 }}")
println("list.all{it in 1..10}: ${list.all { it in 1..10 }}")
println("list.none { it > 10 }: ${list.none { i... | 0 | Kotlin | 0 | 0 | 8dc6bff0ef47b824bb5861cd6f4a27bdcefa39f3 | 3,487 | Introduction | Apache License 2.0 |
src/commonMain/kotlin/com/github/knok16/regrunch/dfa/LanguageSize.kt | knok16 | 593,302,527 | false | null | package com.github.knok16.regrunch.dfa
import com.github.knok16.regrunch.utils.BigInteger
import com.github.knok16.regrunch.utils.ONE
import com.github.knok16.regrunch.utils.ZERO
import com.github.knok16.regrunch.utils.plus
fun <A, S> isLanguageEmpty(dfa: DFA<A, S>): Boolean {
val visited = HashSet<S>()
fun ... | 0 | Kotlin | 1 | 11 | 87c6a7ab9f6db4e48e9d3caf88b278c59297ed7b | 1,903 | regrunch | MIT License |
aoc-2015/src/main/kotlin/nl/jstege/adventofcode/aoc2015/days/Day06.kt | JStege1206 | 92,714,900 | false | null | package nl.jstege.adventofcode.aoc2015.days
import nl.jstege.adventofcode.aoccommon.days.Day
import nl.jstege.adventofcode.aoccommon.utils.Point
import nl.jstege.adventofcode.aoccommon.utils.extensions.extractValues
import nl.jstege.adventofcode.aoccommon.utils.extensions.sortTo
import nl.jstege.adventofcode.aoccommon... | 0 | Kotlin | 0 | 0 | d48f7f98c4c5c59e2a2dfff42a68ac2a78b1e025 | 2,883 | AdventOfCode | MIT License |
y2017/src/main/kotlin/adventofcode/y2017/Day15.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2017
import adventofcode.io.AdventSolution
object Day15 : AdventSolution(2017, 15, "Dueling Generators") {
override fun solvePartOne(input: String): String {
val (seedA, seedB) = parseInput(input)
val genA = generateSequence(seedA) { it * 16807L % 2147483647L }
val genB = generateSequen... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,296 | advent-of-code | MIT License |
src/main/kotlin/com/jaspervanmerle/aoc2021/day/Day20.kt | jmerle | 434,010,865 | false | {"Kotlin": 60581} | package com.jaspervanmerle.aoc2021.day
class Day20 : Day("4928", "16605") {
private data class Pixel(val x: Int, val y: Int)
private val enhancementAlgorithm = input
.split("\n\n")[0]
.toCharArray()
.map { it == '#' }
private val inputLitPixels = input
.split("\n\n")[1]
... | 0 | Kotlin | 0 | 0 | dcac2ac9121f9bfacf07b160e8bd03a7c6732e4e | 2,253 | advent-of-code-2021 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NextGreatestLetter.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,782 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinMovesToMakePalindrome.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,408 | kotlab | Apache License 2.0 |
src/Utils.kt | mjossdev | 574,439,750 | false | {"Kotlin": 81859} | import java.math.BigInteger
import java.security.MessageDigest
import java.util.EnumMap
import kotlin.io.path.Path
import kotlin.io.path.readLines
/**
* Reads lines from the given input txt file.
*/
fun readInput(name: String) = Path("src", "$name.txt").readLines()
/**
* Converts string to md5 hash.
*/
fun String... | 0 | Kotlin | 0 | 0 | afbcec6a05b8df34ebd8543ac04394baa10216f0 | 1,497 | advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/sortingandsearching/CountOfSmallerNumbersAfterSelf.kt | e-freiman | 471,473,372 | false | {"Kotlin": 78010} | package sortingandsearching
private const val OFFSET = 10000
private const val SIZE = 2 * 10000 + 1
private val segmentTree = IntArray(4 * SIZE) { 0 }
private fun update(vertex: Int, left: Int, right: Int, pos: Int, value: Int) {
if (left == right) {
segmentTree[vertex] += value
return
}
... | 0 | Kotlin | 0 | 0 | fab7f275fbbafeeb79c520622995216f6c7d8642 | 1,565 | LeetcodeGoogleInterview | Apache License 2.0 |
src/day03/Day03Answer2.kt | IThinkIGottaGo | 572,833,474 | false | {"Kotlin": 72162} | package day03
import readInput
/**
* Answers from [Advent of Code 2022 Day 3 | Kotlin](https://youtu.be/IPLfo4zXNjk)
*/
fun main() {
fun part1(input: List<String>): Int {
val sharedItems = input.map {
val first = it.substring(0 until it.length / 2)
val second = it.substring(it.le... | 0 | Kotlin | 0 | 0 | 967812138a7ee110a63e1950cae9a799166a6ba8 | 1,338 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/stores_and_houses/StoresAndHouses.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.stores_and_houses
import datsok.shouldEqual
import org.junit.Test
import kotlin.math.abs
/**
* https://leetcode.com/discuss/interview-question/350248/Google-or-Summer-Intern-OA-2019-or-Stores-and-Houses
*
* You are given 2 arrays representing integer locations of stores and houses (ea... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,014 | katas | The Unlicense |
src/day09/Day09.kt | commanderpepper | 574,647,779 | false | {"Kotlin": 44999} | package day09
import readInput
import kotlin.math.abs
fun main(){
val dayNineInput = readInput("day09")
// println("Tail visited ${partOne(dayNineInput)}")
println("Tail visited ${partTwo(dayNineInput)}")
}
// Failed part two solution
private fun partTwo(dayNineInput: List<String>): Int {
val tailVisi... | 0 | Kotlin | 0 | 0 | fef291c511408c1a6f34a24ed7070ceabc0894a1 | 8,988 | advent-of-code-kotlin-2022 | Apache License 2.0 |
2022/Day07/problems.kt | moozzyk | 317,429,068 | false | {"Rust": 102403, "C++": 88189, "Python": 75787, "Kotlin": 72672, "OCaml": 60373, "Haskell": 53307, "JavaScript": 51984, "Go": 49768, "Scala": 46794} | import java.io.File
import kotlin.collections.mutableListOf
class Node constructor(val name: String, var size: Int, val parent: Node?) {
val childNodes = mutableListOf<Node>()
fun isDir(): Boolean = childNodes.size > 0
}
fun main(args: Array<String>) {
val lines = File(args[0]).readLines()
val fs = bu... | 0 | Rust | 0 | 0 | c265f4c0bddb0357fe90b6a9e6abdc3bee59f585 | 2,465 | AdventOfCode | MIT License |
src/main/kotlin/Day02.kt | luluvia | 576,815,205 | false | {"Kotlin": 7130} | class Day02 {
private val scores1 = mapOf(
'X' to mapOf('A' to 4, 'B' to 1, 'C' to 7),
'Y' to mapOf('A' to 8, 'B' to 5, 'C' to 2),
'Z' to mapOf('A' to 3, 'B' to 9, 'C' to 6)
)
private val scores2 = mapOf(
'X' to mapOf('A' to 3, 'B' to 1, 'C' to 2),
'Y' to mapOf('A' t... | 0 | Kotlin | 0 | 0 | 29ddde3b0d7acbe0ef1295ec743e7d0417cfef53 | 922 | advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/TextJustification.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 | 4,876 | kotlab | Apache License 2.0 |
hexagon/HexagonStandoffSolver.kt | Brinsky | 398,903,731 | false | null | package hexagon
// Solver for Hexagon Standoff from "<NAME>"
// Glossary:
//
// Piece: the individual, moveable game pieces with symbols on them
// Slot: the board locations where pieces may be placed
// Offset: the number of increments by which a piece has been rotated (counterclockwise) from its
// "defa... | 0 | Kotlin | 0 | 0 | 61b528f6fe583b06f57a77c0f2dc90546f35c0b8 | 4,123 | hexagon-standoff | MIT License |
kotlin/410.Split Array Largest Sum(分割数组的最大值).kt | learningtheory | 141,790,045 | false | {"Python": 4025652, "C++": 1999023, "Java": 1995266, "JavaScript": 1990554, "C": 1979022, "Ruby": 1970980, "Scala": 1925110, "Kotlin": 1917691, "Go": 1898079, "Swift": 1827809, "HTML": 124958, "Shell": 7944} | /**
<p>Given an array which consists of non-negative integers and an integer <i>m</i>, you can split the array into <i>m</i> non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these <i>m</i> subarrays.
</p>
<p><b>Note:</b><br />
If <i>n</i> is the length of array, assume the following... | 0 | Python | 1 | 3 | 6731e128be0fd3c0bdfe885c1a409ac54b929597 | 2,496 | leetcode | MIT License |
src/day24/Parser.kt | g0dzill3r | 576,012,003 | false | {"Kotlin": 172121} | package day24
import readInput
import java.lang.IllegalArgumentException
import java.lang.IllegalStateException
enum class Direction (val dx: Int, val dy: Int, val encoded: Char) {
UP (0, -1, '^'), LEFT (-1, 0, '<'), DOWN (0, 1, 'v'), RIGHT (1, 0, '>');
val invert: Direction
get () = values()[(ordina... | 0 | Kotlin | 0 | 0 | 6ec11a5120e4eb180ab6aff3463a2563400cc0c3 | 7,208 | advent_of_code_2022 | Apache License 2.0 |
src/main/kotlin/at/mpichler/aoc/solutions/year2021/Day02.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2021
import at.mpichler.aoc.lib.Day
import at.mpichler.aoc.lib.PartSolution
open class Part2A : PartSolution() {
lateinit var commands: List<Command>
override fun parseInput(text: String) {
val lines = text.trimEnd().split("\n")
commands = lines.map { Com... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 1,733 | advent-of-code-kotlin | MIT License |
src/main/kotlin/icfp2019/analyzers/WeightedBoardGraphAnalyzer.kt | godaddy-icfp | 186,746,222 | false | {"JavaScript": 797310, "Kotlin": 116879, "CSS": 9434, "HTML": 5859, "Shell": 70} | package icfp2019.analyzers
import icfp2019.Cache
import icfp2019.core.Analyzer
import icfp2019.model.*
import org.jgrapht.Graph
import org.jgrapht.graph.DefaultEdge
typealias WeightFunction<V> = (node1: V) -> (node2: V) -> Double
fun <V> byState(boardStates: BoardNodeStates, locationFor: (V) -> Point): WeightFunction... | 13 | JavaScript | 12 | 0 | a1060c109dfaa244f3451f11812ba8228d192e7d | 1,746 | icfp-2019 | The Unlicense |
src/Day03_part2.kt | rosyish | 573,297,490 | false | {"Kotlin": 51693} | fun main() {
fun getElementPriority(ch: Char): Int {
return when (ch) {
in 'a'..'z' -> 1 + (ch - 'a')
in 'A'..'Z' -> 27 + (ch - 'A')
else -> throw IllegalArgumentException("Character not a letter")
}
}
fun findCommonElement(input: List<String>): Char {
... | 0 | Kotlin | 0 | 2 | 43560f3e6a814bfd52ebadb939594290cd43549f | 844 | aoc-2022 | Apache License 2.0 |
test/leetcode/WordSearch.kt | andrej-dyck | 340,964,799 | false | null | package leetcode
import lib.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.*
import org.junit.jupiter.params.*
import org.junit.jupiter.params.converter.*
import org.junit.jupiter.params.provider.*
/**
* https://leetcode.com/problems/word-search/
*
* 79. Word Search
* [Medium]
*... | 0 | Kotlin | 0 | 0 | 3e3baf8454c34793d9771f05f330e2668fda7e9d | 2,648 | coding-challenges | MIT License |
dcp_kotlin/src/main/kotlin/dcp/day312/day312.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day312
// day312.kt
// By <NAME>, 2020.
import kotlin.math.max
/**
* This is sequence A052980 in the Online Encyclopedia of Integer Sequences:
*
* https://oeis.org/A052980
*
* and is a deceptively difficult problem of dynamic programming (i.e. using memoization to make recurrence relations
* feasibl... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 3,175 | daily-coding-problem | MIT License |
src/Day01.kt | alex-rieger | 573,375,246 | false | null | fun getCaloriesPerElfList(input: List<String>): List<Int> {
var buffer = 0
return input.fold(mutableListOf<Int>()) { acc, calories ->
if (calories.isEmpty()) {
acc.add(buffer)
buffer = 0
} else {
buffer = buffer.plus(calories.toInt())
}
acc
... | 0 | Kotlin | 0 | 0 | 77de0265ff76160e7ea49c9b9d31caa1cd966a46 | 804 | aoc-2022-kt | Apache License 2.0 |
src/main/kotlin/com/leetcode/top100LikedQuestions/easy/maxim_depth_of_binary_tree/Main.kt | frikit | 254,842,734 | false | null | package com.leetcode.top100LikedQuestions.easy.maxim_depth_of_binary_tree
fun main() {
println("Test case 1:")
val t1 = TreeNode(1)
run {
val leftFirstLeaf = TreeNode(3)
val rightFirstLeaf = TreeNode(2)
val leftSecondLeaf = TreeNode(5)
val rightSecondLeaf = null
... | 0 | Kotlin | 0 | 0 | dda68313ba468163386239ab07f4d993f80783c7 | 1,372 | leet-code-problems | Apache License 2.0 |
advent-of-code-2022/src/main/kotlin/eu/janvdb/aoc2022/day04/Day04.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2022.day04
import eu.janvdb.aocutil.kotlin.readLines
//const val FILENAME = "input04-test.txt"
const val FILENAME = "input04.txt"
fun main() {
val pairs = readLines(2022, FILENAME)
.map(String::toElfPair)
val part1 = pairs.count { it.fullyOverlaps() }
println(part1)
val part2 = pairs.cou... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,223 | advent-of-code | Apache License 2.0 |
facebook/2019/round1/1/main.kt | seirion | 17,619,607 | false | {"C++": 801740, "HTML": 42242, "Kotlin": 37689, "Python": 21759, "C": 3798, "JavaScript": 294} | import java.util.*
fun main(args: Array<String>) {
val t = readLine()!!.toInt()
repeat(t) {
print("Case #${it + 1}: ")
solve()
}
}
data class T(val a: Int, val b: Int, val c: Int)
fun solve() {
val (n, m) = readLine()!!.split(" ").map { it.toInt() }
val input = ArrayList<T>()
... | 0 | C++ | 4 | 4 | a59df98712c7eeceabc98f6535f7814d3a1c2c9f | 1,008 | code | Apache License 2.0 |
src/main/kotlin/year2022/Day15.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2022
import utils.Direction.*
import utils.Point2D
class Day15(input: String) {
data class Sensor(val position: Point2D, val beacon: Point2D) {
val coverage = position.manhattan(beacon)
}
private val regex = """Sensor at x=(.*), y=(.*): closest beacon is at x=(.*), y=(.*)""".toRegex(... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 2,137 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/days/aoc2022/Day13.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2022
import days.Day
class Day13 : Day(2022,13) {
override fun partOne(): Any {
return calculateSumOfCountOfPairsInCorrectOrder(inputList)
}
override fun partTwo(): Any {
return calculateDecoderKey(inputList)
}
fun calculateSumOfCountOfPairsInCorrectOrder(input: L... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 3,519 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/shtanko/algorithms/leetcode/InterleavingString.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 5,213 | kotlab | Apache License 2.0 |
src/main/kotlin/g2401_2500/s2492_minimum_score_of_a_path_between_two_cities/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2401_2500.s2492_minimum_score_of_a_path_between_two_cities
// #Medium #Depth_First_Search #Breadth_First_Search #Graph #Union_Find
// #2023_07_05_Time_929_ms_(91.67%)_Space_109.9_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
fun minScore(n: Int, roads: Array<IntArray>): Int {
val pare... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,310 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/SudokuSolver.kt | Constanze3 | 749,840,989 | false | {"Kotlin": 12466} | package org.example
/**
* A SudokuSolver can be used to find solutions of a certain sudoku puzzle state.
*
* @constructor creates a new solver for the given sudoku
*/
class SudokuSolver(sudoku: Sudoku) {
private val sudoku = Sudoku(sudoku)
private val workingSudoku = Sudoku(sudoku)
private val solution... | 0 | Kotlin | 0 | 0 | d0543fbf318fcee39691339ec89b3336d5a06b49 | 2,433 | simple-sudoku-solver | MIT License |
src/Day21.kt | asm0dey | 572,860,747 | false | {"Kotlin": 61384} | sealed interface Node21 {
fun calc(): Long
fun shouldEqual(other: Long): Long?
data class Cont(val int: Long) : Node21 {
override fun calc(): Long = int
override fun shouldEqual(other: Long) = null
}
data class Expression(val el1: Node21, val op: String, val el2: Node21) : Node21 {
... | 1 | Kotlin | 0 | 1 | f49aea1755c8b2d479d730d9653603421c355b60 | 4,095 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/de/skyrising/aoc/aoc.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc
import java.util.*
import kotlin.math.sqrt
const val RUNS = 10
const val WARMUP = 5
const val MEASURE_ITERS = 10
const val BENCHMARK = false
fun buildFilter(args: Array<String>): PuzzleFilter {
if (args.isEmpty()) return PuzzleFilter.all().copy(latestOnly = true)
if (args[0] == "all"... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 3,377 | aoc | MIT License |
src/2023/Day15.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2023`
import java.io.File
import java.util.*
fun main() {
Day15().solve()
}
class Day15 {
val input1 = """
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7
""".trimIndent()
val input2 = """
""".trimIndent()
fun hash(s: String): Int {
var r = 0
... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 2,146 | advent-of-code | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year18/Day07.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year18
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.asPair
fun PuzzleSet.day7() = puzzle(day = 7) {
val pairs = inputLines.map {
it.split(" ")
.filter { p -> p.length == 1 }
.map { p -> p.singleOrNull() ?: error("?") }.asPair()
... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 2,014 | advent-of-code | The Unlicense |
src/main/kotlin/Day12.kt | goblindegook | 319,372,062 | false | null | package com.goblindegook.adventofcode2020
import com.goblindegook.adventofcode2020.extension.plus
import com.goblindegook.adventofcode2020.extension.times
import com.goblindegook.adventofcode2020.extension.toIntOr
import com.goblindegook.adventofcode2020.input.load
import kotlin.math.PI
import kotlin.math.absoluteValu... | 0 | Kotlin | 0 | 0 | 85a2ff73899dbb0e563029754e336cbac33cb69b | 2,109 | adventofcode2020 | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.