path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/Day19.kt | LauwiMeara | 572,498,129 | false | {"Kotlin": 109923} | enum class Element {
ORE,
CLAY,
OBSIDIAN,
GEODE
}
data class Blueprint (val id: Int, val costs: Map<Element, List<Material>>)
data class Material (val quantity: Int, val element: Element)
data class ElementInfo (var collected: Int, var numRobots: Int, val maxNeededRobots: Int)
const val MINUTES_DAY_19... | 0 | Kotlin | 0 | 1 | 34b4d4fa7e562551cb892c272fe7ad406a28fb69 | 6,177 | AoC2022 | Apache License 2.0 |
src/main/kotlin/championofgoats/advent/utils/functions.kt | ChampionOfGoats | 225,446,764 | false | null | package championofgoats.advent.utils
// Get the greatest common divisor of two digits
fun gcd(a: Int, b: Int) : Int = if (b == 0) a else gcd(b, a % b)
// Get an identity matrix
// Points P where the 1-dimensional index i = (i % size) * size (i % size) have value 1.0
// All other points Q are 0.0
fun identity(size: In... | 0 | Kotlin | 0 | 0 | 4f69de1579f40928c1278c3cea4e23e0c0e3b742 | 2,081 | advent-of-code | MIT License |
src/main/kotlin/com/colinodell/advent2016/Day03.kt | colinodell | 495,627,767 | false | {"Kotlin": 80872} | package com.colinodell.advent2016
class Day03(private val input: String) {
fun solvePart1() = parsePart1(input).count { it.isValid() }
fun solvePart2() = parsePart2(input).count { it.isValid() }
private fun parseRow(row: String): List<Int> = row.trim().split("\\s+".toRegex()).map { it.toInt() }
priv... | 0 | Kotlin | 0 | 0 | 8a387ddc60025a74ace8d4bc874310f4fbee1b65 | 985 | advent-2016 | Apache License 2.0 |
src/day11/Main.kt | nikwotton | 572,814,041 | false | {"Kotlin": 77320} | package day11
import java.io.File
const val workingDir = "src/day11"
fun main() {
val sample = File("$workingDir/sample.txt")
val input1 = File("$workingDir/input_1.txt")
println("Step 1a: ${runStep1(sample)}")
println("Step 1b: ${runStep1(input1)}")
println("Step 2a: ${runStep2(sample)}")
pr... | 0 | Kotlin | 0 | 0 | dee6a1c34bfe3530ae6a8417db85ac590af16909 | 5,015 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | RogozhinRoman | 572,915,906 | false | {"Kotlin": 28985} | fun main() {
fun getCrates(input: List<String>): List<ArrayDeque<String>> {
val cratesTemp = input.takeWhile { !it.startsWith("move") }.dropLast(1)
val stacks = List<ArrayDeque<String>>(cratesTemp.last().last().toString().toInt()) { ArrayDeque() }
val crates = cratesTemp.dropLast(1)
... | 0 | Kotlin | 0 | 1 | 6375cf6275f6d78661e9d4baed84d1db8c1025de | 2,455 | AoC2022 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch6/Problem67.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch6
import dev.bogwalk.util.custom.PyramidTree
/**
* Problem 67: Maximum Path Sum 2
*
* https://projecteuler.net/problem=67
*
* Goal: Find the maximum sum from tree root to leaf node of an N-rowed tree, which contains i
* integers on each ith row, by moving to an adjacent number on the ro... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,291 | project-euler-kotlin | MIT License |
aoc2022/day23.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2022
import utils.InputRetrieval
fun main() {
Day23.execute()
}
object Day23 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
private fun part1(input: List<Point>): Int {
var board = input
... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 4,662 | Advent-Of-Code | MIT License |
src/Day03.kt | Oktosha | 573,139,677 | false | {"Kotlin": 110908} | fun main() {
fun getPriorityOfAnItem(item: Char): Int {
if (item.isLowerCase())
return item.code - 'a'.code + 1
return item.code - 'A'.code + 27
}
fun getPriorityOf1Rucksack(items: String): Int {
val compartment1 = items.subSequence(0, items.length / 2).toSet()
v... | 0 | Kotlin | 0 | 0 | e53eea61440f7de4f2284eb811d355f2f4a25f8c | 1,002 | aoc-2022 | Apache License 2.0 |
2022/src/Day11.kt | Saydemr | 573,086,273 | false | {"Kotlin": 35583, "Python": 3913} | package src
open class Monkey {
var id: Int = 0
var items: MutableList<Long> = mutableListOf()
var operator: String = ""
var operand : String = ""
var test : Long = 0
var passAction: Int = 0
var failAction: Int = 0
var numInspected: Long = 0
@Override
override fun toString(): S... | 0 | Kotlin | 0 | 1 | 25b287d90d70951093391e7dcd148ab5174a6fbc | 2,793 | AoC | Apache License 2.0 |
src/aoc2023/Day07.kt | anitakar | 576,901,981 | false | {"Kotlin": 124382} | package aoc2023
import readInput
fun main() {
fun isFiveOfAKind(hand: String): Boolean {
val grouped = hand.groupBy { it }.mapValues { it.value.size }
return grouped.size == 1
}
fun isFiveOfAKindWithJoker(hand: String): Boolean {
if (isFiveOfAKind(hand)) return true
val g... | 0 | Kotlin | 0 | 1 | 50998a75d9582d4f5a77b829a9e5d4b88f4f2fcf | 6,864 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/solutions/Main.kt | Dr-Horv | 570,666,285 | false | {"Kotlin": 115643} | package solutions
import solutions.day01.Day1
import solutions.day02.Day2
import solutions.day03.Day3
import solutions.day04.Day4
import solutions.day05.Day5
import solutions.day06.Day6
import solutions.day07.Day7
import solutions.day08.Day8
import solutions.day09.Day9
import solutions.day10.Day10
import solutions.day... | 0 | Kotlin | 0 | 2 | 975695cc49f19a42c0407f41355abbfe0cb3cc59 | 2,497 | Advent-of-Code-2022 | MIT License |
src/Day02.kt | yalematta | 572,668,122 | false | {"Kotlin": 8442} | fun main() {
fun getRounds(input: List<String>): List<List<CharArray>> {
return input.windowed(1).map { round ->
round.map {
it.toCharArray()
}
}
}
fun part1(input: List<String>): Int {
var score = 0
val rounds = getRounds(input)
... | 0 | Kotlin | 0 | 0 | 2b43681cc2bd02e4838b7ad1ba04ff73c0422a73 | 2,361 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/mytechtoday/aoc/year2022/Day2.kt | mytechtoday | 572,836,399 | false | {"Kotlin": 15268, "Java": 1717} | package mytechtoday.aoc.year2022
import mytechtoday.aoc.util.readInput
fun main() {
fun getValue(inputChar: Char):Int = when (inputChar) {
'X' -> 1
'Y' -> 2
else -> 3
}
fun getValueProblem2(inputChar: String):Int = when (inputChar) {
// Rock 1 , paper- 2, sessior 3
... | 0 | Kotlin | 0 | 0 | 3f25cb010e6367af20acaa2906aff17a80f4e623 | 1,653 | aoc2022 | Apache License 2.0 |
src/Day09.kt | aaronbush | 571,776,335 | false | {"Kotlin": 34359} | import java.lang.Integer.max
import kotlin.math.abs
fun main() {
val moveFuns = mapOf(
"R" to fun(h: RopePoint) = h.copy(first = h.first + 1),
"L" to fun(h: RopePoint) = h.copy(first = h.first - 1),
"U" to fun(h: RopePoint) = h.copy(second = h.second + 1),
"D" to fun(h: RopePoint) ... | 0 | Kotlin | 0 | 0 | d76106244dc7894967cb8ded52387bc4fcadbcde | 5,679 | aoc-2022-kotlin | Apache License 2.0 |
src/test/kotlin/year2015/Day15.kt | abelkov | 47,995,527 | false | {"Kotlin": 48425} | package year2015
import kotlin.math.max
import kotlin.test.*
private data class Ingredient(
val capacity: Int,
val durability: Int,
val flavor: Int,
val texture: Int,
val calories: Int
)
private const val MAX_SPOONS = 100
class Day15 {
@Test
fun part1() {
// Sugar: capacity 3, du... | 0 | Kotlin | 0 | 0 | 0e4b827a742322f42c2015ae49ebc976e2ef0aa8 | 5,671 | advent-of-code | MIT License |
year2023/src/main/kotlin/net/olegg/aoc/year2023/day4/Day4.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2023.day4
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.parseInts
import net.olegg.aoc.utils.parseLongs
import net.olegg.aoc.utils.toPair
import net.olegg.aoc.year2023.DayOf2023
/**
* See [Year 2023, Day 4](https://adventofcode.com/2023/day/4)
*/
object Day4 : DayOf2023(4... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,290 | adventofcode | MIT License |
src/Day08.kt | er453r | 572,440,270 | false | {"Kotlin": 69456} | fun main() {
fun part1(input: List<String>): Int {
val grid = Grid(input.map { it.toCharArray().asList().map(Char::digitToInt) })
val outside = 2 * grid.width + 2 * (grid.height - 2)
var otherVisible = 0
for (x in 1 until grid.width - 1)
for (y in 1 until grid.height - ... | 0 | Kotlin | 0 | 0 | 9f98e24485cd7afda383c273ff2479ec4fa9c6dd | 2,181 | aoc2022 | Apache License 2.0 |
src/main/kotlin/leet/1-array.kt | dzca | 581,929,762 | false | {"Kotlin": 75573} | package leet
/**
* - hard
* Given two strings s and t of lengths m and n respectively,
* return the minimum window substring of s such that
* every character in t (including duplicates) is included in the window.
* If there is no such substring, return the empty string "".
*/
fun minWindow(a: String, b: String):... | 0 | Kotlin | 0 | 0 | b1e7d1cb739e21ed7e8b7484d6efcd576857830f | 2,809 | kotlin-algrithm | MIT License |
src/main/day07/Day07.kt | rolf-rosenbaum | 543,501,223 | false | {"Kotlin": 17211} | package day07
import readInput
typealias Steps = MutableMap<String, MutableList<String>>
fun part1(input: List<String>): String {
val steps = parseSteps(input)
val done = mutableListOf<String>()
while (true) {
val nextStep = steps.filter { (_, pres) ->
pres.isEmpty()
}.keys.... | 0 | Kotlin | 0 | 0 | dfd7c57afa91dac42362683291c20e0c2784e38e | 1,345 | aoc-2018 | Apache License 2.0 |
src/Day02.kt | makobernal | 573,037,099 | false | {"Kotlin": 16467} | enum class OpponentChoice(val code: String) {
Rock("A"),
Paper("B"),
Scissors("C");
companion object {
infix fun from(value: String): OpponentChoice = OpponentChoice.values().firstOrNull { it.code == value }!!
}
}
enum class ResponseChoice(val code: String) {
Rock("X"),
Paper("Y"),... | 0 | Kotlin | 0 | 0 | 63841809f7932901e97465b2dcceb7cec10773b9 | 4,371 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day05.kt | N-Silbernagel | 573,145,327 | false | {"Kotlin": 118156} | import java.util.*
fun main() {
fun parseCrates(
stackChunks: List<String>,
stacks: TreeMap<Int, Stack<Char>>
): Boolean {
for ((index, stackChunk) in stackChunks.withIndex()) {
if (stackChunk.trim() == "1") {
return true
}
if (stackC... | 0 | Kotlin | 0 | 0 | b0d61ba950a4278a69ac1751d33bdc1263233d81 | 3,066 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2022/2022-10.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2022
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
import com.github.ferinagy.adventOfCode.toBooleanGrid
fun main() {
val input = readInputLines(2022, "10-input")
val testInput1 = readInputLines(2022, "10-test... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,452 | advent-of-code | MIT License |
src/main/kotlin/kt/kotlinalgs/app/sorting/RadixSort.ws.kts | sjaindl | 384,471,324 | false | null | package kt.kotlinalgs.app.sorting
import kotlin.math.pow
println("test")
val array1 = intArrayOf(2, 6, 4)
val array2 = intArrayOf(15, 13, 1, 10, 17, 0, 2, 2, 100)
RadixSort().sort(array1)
RadixSort().sort(array2)
// runtime: O(D*(N + B)), for finite ranges where N = array size, B = base (decimal=10), D = # of 10's... | 0 | Java | 0 | 0 | e7ae2fcd1ce8dffabecfedb893cb04ccd9bf8ba0 | 2,772 | KotlinAlgs | MIT License |
src/main/kotlin/day09/Day09.kt | dustinconrad | 572,737,903 | false | {"Kotlin": 100547} | package day09
import geometry.Coord
import geometry.distance
import geometry.plus
import readResourceAsBufferedReader
import kotlin.math.sign
fun main() {
println("part 1: ${part1(readResourceAsBufferedReader("9_1.txt").readLines())}")
println("part 2: ${part2(readResourceAsBufferedReader("9_1.txt").readLines... | 0 | Kotlin | 0 | 0 | 1dae6d2790d7605ac3643356b207b36a34ad38be | 3,046 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/staricka/adventofcode2023/days/Day18.kt | mathstar | 719,656,133 | false | {"Kotlin": 107115} | package com.staricka.adventofcode2023.days
import com.staricka.adventofcode2023.days.DigInstruction.Companion.toDigInstruction
import com.staricka.adventofcode2023.days.DigInstruction.Companion.toDigInstructionFromHex
import com.staricka.adventofcode2023.framework.Day
import com.staricka.adventofcode2023.util.Directio... | 0 | Kotlin | 0 | 0 | 8c1e3424bb5d58f6f590bf96335e4d8d89ae9ffa | 3,086 | adventOfCode2023 | MIT License |
2021/src/main/kotlin/day24_real.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
fun main() {
Day24Real.run(skipTest = true)
}
object Day24Real : Solution<String>() {
override val name = "day24"
override val parser = Parser { it }
data class Regs(var x: Int = 0, var y: Int = 0, var z: Int = 0, var w: Int = 0)
fun checkDigit(input: Int, args: A... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,284 | aoc_kotlin | MIT License |
leetcode2/src/leetcode/SortArrayByParityII.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* 922. 按奇偶排序数组 II
* https://leetcode-cn.com/problems/sort-array-by-parity-ii/
* Created by test
* Date 2019/6/3 1:27
* Description
* 给定一个非负整数数组 A, A 中一半整数是奇数,一半整数是偶数。
对数组进行排序,以便当 A[i] 为奇数时,i 也是奇数;当 A[i] 为偶数时, i 也是偶数。
你可以返回任何满足上述条件的数组作为答案。
示例:
输入:[4,2,5,7]
输出:[4,5,2,7]
解释:[4,7,2,5],[2,5... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,789 | leetcode | MIT License |
src/Day03.kt | spaikmos | 573,196,976 | false | {"Kotlin": 83036} | fun main() {
fun getScore(input: Char) : Int {
val value: Int
if(input > 'Z') {
value = input - 'a' + 1
} else {
value = input - 'A' + 27
}
return value
}
fun part1(input: List<String>): Int {
var total = 0
for (i in input) {
... | 0 | Kotlin | 0 | 0 | 6fee01bbab667f004c86024164c2acbb11566460 | 1,175 | aoc-2022 | Apache License 2.0 |
src/Day05.kt | ostersc | 572,991,552 | false | {"Kotlin": 46059} | enum class States { READING_CRATES, READY_FOR_INSTRUCTIONS, READING_INSTRUCTIONS }
fun main() {
fun processInput(input: List<String>, usePopForMove: Boolean): String {
val stacks = arrayListOf<ArrayDeque<Char>>()
var state = States.READING_CRATES
for (line in input) {
if (state... | 0 | Kotlin | 0 | 1 | 3eb6b7e3400c2097cf0283f18b2dad84b7d5bcf9 | 2,348 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch3/Problem37.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch3
import dev.bogwalk.util.maths.primeNumbers
import dev.bogwalk.util.search.binarySearch
/**
* Problem 37: Truncatable Primes
*
* https://projecteuler.net/problem=37
*
* Goal: Find the sum of all primes less than N that are truncatable both from left to right and
* from right to left (s... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,453 | project-euler-kotlin | MIT License |
src/main/kotlin/kr/co/programmers/P92341.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
import kotlin.math.ceil
// https://github.com/antop-dev/algorithm/issues/396
class P92341 {
fun solution(fees: IntArray, records: Array<String>): IntArray {
// 차량의 마지막 입차 시간을 가지고 있는 맵
val inMap = mutableMapOf<String, Int>()
// 차량의 누적 주차 시간을 가지고 있는 맵
val ti... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,917 | algorithm | MIT License |
AlgorithmSamples/src/com/frewen/algorithm/demo/binarytree/DiameterOfBinaryTree.kt | FrewenWang | 278,597,737 | false | {"Java": 341763, "Kotlin": 3400} | package com.frewen.algorithm.demo.binarytree
import com.frewen.algorithm.demo.binarytree.base.TreeNode
/**
* LeetCode第543题目. 二叉树的直径
* https://leetcode-cn.com/problems/diameter-of-binary-tree/
*
* 给定一棵二叉树,你需要计算它的直径长度。
* 一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过根结点。
*
* 示例 :
* 给定二叉树
* 1
* / \
* 2 3
* / \
* 4 ... | 0 | Java | 0 | 0 | 41d3ef56dea45599bdf5b27122787b4a08f9c7f4 | 1,399 | AliceJava | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem81/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem81
/**
* LeetCode page: [81. Search in Rotated Sorted Array II](https://leetcode.com/problems/search-in-rotated-sorted-array-ii/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(1) where N is the size of nums;
*/
fun search(nums: IntArray, target: I... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,777 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/com/groundsfam/advent/y2020/d12/Day12.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2020.d12
import com.groundsfam.advent.DATAPATH
import kotlin.io.path.div
import kotlin.io.path.useLines
import kotlin.math.abs
private enum class Direction {
NORTH,
SOUTH,
EAST,
WEST,
LEFT,
RIGHT,
FORWARD;
fun turnLeft(): Direction = when (this) {
... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 3,497 | advent-of-code | MIT License |
src/main/kotlin/days/Day10.kt | hughjdavey | 433,597,582 | false | {"Kotlin": 53042} | package days
import java.util.Stack
class Day10 : Day(10) {
override fun partOne(): Any {
return inputList.mapNotNull { getFirstIllegalChar(it) }.sumOf { it.getIllegalScore() }
}
override fun partTwo(): Any {
val missing = inputList.filter { getFirstIllegalChar(it) == null }
... | 0 | Kotlin | 0 | 0 | a3c2fe866f6b1811782d774a4317457f0882f5ef | 1,622 | aoc-2021 | Creative Commons Zero v1.0 Universal |
src/day01/Day01.kt | CodeLock85 | 573,182,143 | false | {"Kotlin": 1766} | package day01
import readInput
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("day01/Day01_test")
check(part1(testInput) == 24000)
check(part2(testInput) == 45000)
val input = readInput("day01/Day01")
println(part1(input))
print... | 0 | Kotlin | 0 | 0 | 1381b8e39cba25dec23776d3fe2a25b6f77351ff | 1,131 | aoc221 | Apache License 2.0 |
src/main/kotlin/ru/timakden/aoc/year2022/Day16.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2022
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
import java.util.concurrent.atomic.AtomicInteger
/**
* [Day 16:... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 5,689 | advent-of-code | MIT License |
src/main/java/Exercise13-part2.kt | cortinico | 317,667,457 | false | null | import kotlin.math.absoluteValue
fun main() {
val input = object {}.javaClass.getResource("input-13.txt").readText().split("\n")
val busses = input[1].split(",")
var indexes =
busses
.mapIndexed { index, code -> index to code }
.filter { (_, code) -> code != "x" }
... | 1 | Kotlin | 0 | 4 | a0d980a6253ec210433e2688cfc6df35104aa9df | 1,124 | adventofcode-2020 | MIT License |
src/main/kotlin/g1801_1900/s1803_count_pairs_with_xor_in_a_range/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1803_count_pairs_with_xor_in_a_range
// #Hard #Array #Bit_Manipulation #Trie #2023_06_19_Time_427_ms_(100.00%)_Space_40.6_MB_(100.00%)
class Solution {
fun countPairs(nums: IntArray, low: Int, high: Int): Int {
val root = Trie()
var pairsCount = 0
for (num in nums) {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,721 | LeetCode-in-Kotlin | MIT License |
src/tree/LeetCode208.kt | Alex-Linrk | 180,918,573 | false | null | package tree
import java.io.File
/**
* 实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个操作。
*
* 示例:
*
* Trie trie = new Trie();
*
* trie.insert("apple");
* trie.search("apple"); // 返回 true
* trie.search("app"); // 返回 false
* trie.startsWith("app"); // 返回 true
* trie.insert("app");
*... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 1,990 | LeetCode | Apache License 2.0 |
src/Day02.kt | richardmartinsen | 572,910,850 | false | {"Kotlin": 14993} | import java.util.IllegalFormatException
// rules
// A = Rock
// B = Paper
// C = SCissors
//
// X = Rock 1
// Y = Paper 2
// Z = Scissors 3
// looses = 0
// draw = 3
// win = 6
fun main() {
val ROCK = 1
val PAPER = 2
val SCISSORS = 3
val L... | 0 | Kotlin | 0 | 0 | bd71e11a2fe668d67d7ee2af5e75982c78cbe193 | 2,987 | adventKotlin | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions17.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
fun test17() {
printlnResult("ADDBANCAD", "ABC")
printlnResult("ADDBANCADCBA", "ABC")
printlnResult("ADDBANCADCBAXY", "ABC")
}
/**
* Given two strings s and t, find the shortest substring in s that contains all alphabets in t
*/
private fun findShortestSubstring(s... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,882 | Algorithm | Apache License 2.0 |
src/main/kotlin/leetcode/Problem2013.kt | fredyw | 28,460,187 | false | {"Java": 1280840, "Rust": 363472, "Kotlin": 148898, "Shell": 604} | package leetcode
import kotlin.math.abs
/**
* https://leetcode.com/problems/detect-squares/
*/
class Problem2013 {
class DetectSquares() {
private val map = mutableMapOf<Int, MutableMap<Int, Int>>()
fun add(point: IntArray) {
val x = point[0]
val y = point[1]
... | 0 | Java | 1 | 4 | a59d77c4fd00674426a5f4f7b9b009d9b8321d6d | 1,275 | leetcode | MIT License |
src/main/kotlin/co/csadev/advent2021/Day19.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2021 by <NAME>
* Advent of Code 2021, Day 19
* Problem Description: http://adventofcode.com/2021/day/19
*/
package co.csadev.advent2021
import co.csadev.advent2021.Day19.Beacon.Companion.minus
import co.csadev.advent2021.Day19.Beacon.Companion.plus
import co.csadev.adventOfCode.BaseDay
import c... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 3,662 | advent-of-kotlin | Apache License 2.0 |
src/Day02.kt | haitekki | 572,959,197 | false | {"Kotlin": 24688} | fun main() {
fun part1(input: String): Int {
return input.lines().map {
it.split(" ")
.zipWithNext()
.first()
.let { pair ->
when (pair.second) {
"X" -> {
when (pair.first) {
... | 0 | Kotlin | 0 | 0 | b7262133f9115f6456aa77d9c0a1e9d6c891ea0f | 2,560 | aoc2022 | Apache License 2.0 |
src/main/kotlin/y2022/Day03.kt | jforatier | 432,712,749 | false | {"Kotlin": 44692} | package y2022
class Day03(private val data: List<String>) {
// region Letter values
private val abc = "abcdefghijklmnopqrstuvwxyz"
private fun Char.letterValue(): Int {
val index = abc.indexOf(this.lowercase())
return if (this.isUpperCase()) {
index + 27
} else {
... | 0 | Kotlin | 0 | 0 | 2a8c0b4ccb38c40034c6aefae2b0f7d4c486ffae | 1,543 | advent-of-code-kotlin | MIT License |
src/com/kingsleyadio/adventofcode/y2022/day17/Solution.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2022.day17
import com.kingsleyadio.adventofcode.util.readInput
fun main() {
val input = parseInput()
part1(input)
part2(input)
}
fun part1(input: String) {
println(simulation(input, 2022))
}
fun part2(input: String) {
println(simulation(input, 1_000_000_000... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 3,430 | adventofcode | Apache License 2.0 |
src/main/kotlin/days/Day10.kt | julia-kim | 435,257,054 | false | {"Kotlin": 15771} | package days
import readInput
import java.util.*
fun main() {
fun part1(input: List<String>): Int {
var syntaxErrorScore = 0
val map = mapOf('(' to ')', '[' to ']', '{' to '}', '<' to '>')
var illegalChars: MutableList<Char> = mutableListOf()
input.forEach line@{ line ->
... | 0 | Kotlin | 0 | 0 | 5febe0d5b9464738f9a7523c0e1d21bd992b9302 | 2,583 | advent-of-code-2021 | Apache License 2.0 |
2018/kotlin/day6p1/src/main.kt | sgravrock | 47,810,570 | false | {"Rust": 1263100, "Swift": 1167766, "Ruby": 641843, "C++": 529504, "Kotlin": 466600, "Haskell": 339813, "Racket": 264679, "HTML": 200276, "OpenEdge ABL": 165979, "C": 89974, "Objective-C": 50086, "JavaScript": 40960, "Shell": 33315, "Python": 29781, "Elm": 22980, "Perl": 10662, "BASIC": 9264, "Io": 8122, "Awk": 5701, "... | import java.util.*
import kotlin.math.abs
data class Coord(val x: Int, val y: Int)
sealed class Area {
object Infinite : Area()
data class Finite(val coords: Set<Coord>) : Area()
}
fun main(args: Array<String>) {
val start = Date()
val input = "292, 73\n" +
"204, 176\n" +
"106... | 0 | Rust | 0 | 0 | ea44adeb128cf1e3b29a2f0c8a12f37bb6d19bf3 | 4,309 | adventofcode | MIT License |
src/main/kotlin/day4/day4part2.kts | avrilfanomar | 433,723,983 | false | null | import java.io.File
val matrixSize = 5
val lines = File("input.txt").readLines()
val integers = lines[0].split(',').map { it.toInt() }
val matrixList = ArrayList<Array<IntArray>>()
val selectionMatrixList = ArrayList<Array<IntArray>>()
readMatrixList()
var wonMatrixSet = mutableSetOf<Int>()
var finalMatrixIdx = 0... | 0 | Kotlin | 0 | 0 | 266131628b7a58e9b577b7375d3ad6ad88a00954 | 2,758 | advent-of-code-2021 | Apache License 2.0 |
src/Day03/Day03.kt | SelenaChen123 | 573,253,480 | false | {"Kotlin": 14884} | import java.io.File
fun main() {
fun part1(input: List<String>): Int {
var priorities = 0
for (line in input) {
val firstHalf = line.substring(0..line.length / 2 - 1).toSet()
val secondHalf = line.substring(line.length / 2).toSet()
val intersect = (firstHalf int... | 0 | Kotlin | 0 | 0 | 551af4f0efe11744f918d1ff5bb2259e34c5ecd3 | 1,590 | AdventOfCode2022 | Apache License 2.0 |
numberTheory.kt | mikhail-dvorkin | 93,333,859 | false | {"Java": 99023, "Kotlin": 10032, "Python": 1664} | private fun largestPrimeDivisors(n: Int): IntArray {
val largestPrimeDivisors = IntArray(n + 1) { it }
for (i in 2..n) {
if (largestPrimeDivisors[i] < i) continue
var j = i * i
if (j > n) break
do {
largestPrimeDivisors[j] = i
j += i
} while (j <= n)
}
return largestPrimeDivisors
}
private fun divi... | 0 | Java | 0 | 12 | 5ad1705636322d642d1fbc515e9254e6f979f154 | 822 | algorithms | The Unlicense |
advent-of-code-2022/src/test/kotlin/Day 23 Unstable Diffusion.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | import io.kotest.matchers.shouldBe
import kotlinx.collections.immutable.persistentListOf
import org.junit.jupiter.api.Test
class `Day 23 Unstable Diffusion` {
fun Point.around(): List<Point> =
listOf(
up().left(), down().left(), up().right(), down().right(), up(), left(), down(), right())
fun Point... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 3,291 | advent-of-code | MIT License |
src/lib/Grid.kt | djleeds | 572,720,298 | false | {"Kotlin": 43505} | package lib
import kotlin.math.max
import kotlin.math.min
class Grid<T>(private val cells: MutableMap<Coordinates, T>, private val default: T) {
private val flat get() = cells.map { (key, value) -> Cell(key, value) }
private val xMin get() = flat.minOf { it.coordinates.x }
private val xMax get() = flat.m... | 0 | Kotlin | 0 | 4 | 98946a517c5ab8cbb337439565f9eb35e0ce1c72 | 3,918 | advent-of-code-in-kotlin-2022 | Apache License 2.0 |
src/test/kotlin/ch/ranil/aoc/aoc2023/Day08.kt | stravag | 572,872,641 | false | {"Kotlin": 234222} | package ch.ranil.aoc.aoc2023
import ch.ranil.aoc.AbstractDay
import ch.ranil.aoc.aoc2023.Day08.Direction.*
import ch.ranil.aoc.lcm
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
class Day08 : AbstractDay() {
@Test
fun part1Test() {
assertEquals(2, compute1(testInput))
}
@T... | 0 | Kotlin | 1 | 0 | dbd25877071cbb015f8da161afb30cf1968249a8 | 2,812 | aoc | Apache License 2.0 |
src/main/kotlin/eu/michalchomo/adventofcode/year2022/Day04.kt | MichalChomo | 572,214,942 | false | {"Kotlin": 56758} | package eu.michalchomo.adventofcode.year2022
import eu.michalchomo.adventofcode.toInt
fun main() {
fun String.getPairOfRanges() =
this.split(",")
.map { r -> r.split("-") }
.map { r -> IntRange(r[0].toInt(), r[1].toInt()) }
.zipWithNext()
.single()
fu... | 0 | Kotlin | 0 | 0 | a95d478aee72034321fdf37930722c23b246dd6b | 1,038 | advent-of-code | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaxScoreOfGoodSubarray.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 | 4,027 | kotlab | Apache License 2.0 |
src/main/kotlin/ch/petikoch/examples/tictactoe_fp/TicTacToe.kt | Petikoch | 288,920,597 | false | null | package ch.petikoch.examples.tictactoe_fp
import ch.petikoch.examples.tictactoe_fp.Field.*
fun main() {
var gameState = GameState() // "store"
while (gameState.winner == null && !gameState.board.values.any { it == null }) {
println(gameState) // "view"
val ... | 0 | Kotlin | 0 | 0 | f24fa2ec39d85509bfa6eec69ac5277d955bd3c8 | 1,764 | TicTacToe_FP_CTDD_Kotlin | The Unlicense |
src/main/kotlin/biz/koziolek/adventofcode/year2022/day22/day22.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2022.day22
import biz.koziolek.adventofcode.Coord
import biz.koziolek.adventofcode.findInput
fun main() {
val inputFile = findInput(object {})
val forceFieldNotes = parseForceFieldNotes(inputFile.bufferedReader().readLines())
val (position, facing) = followPath(forceF... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 5,134 | advent-of-code | MIT License |
src/commonMain/kotlin/chriscoomber/manydice/Theory.kt | chriscoomber | 342,409,431 | false | {"Kotlin": 136477} | package chriscoomber.manydice
/**
* A probability is close enough to another one if it's within this threshold.
*/
const val PROBABILITY_FLOAT_THRESHOLD = 0.0000001f
/**
* A probability is a real number between 0 and 1 inclusive. Users of this type
* should check it is within those bounds.
*/
typealias Probabil... | 0 | Kotlin | 0 | 0 | 88b482384989bb877142cec1ba5b51133c75916d | 2,910 | manydice | MIT License |
src/org/aoc2021/Day14.kt | jsgroth | 439,763,933 | false | {"Kotlin": 86732} | package org.aoc2021
import java.nio.file.Files
import java.nio.file.Path
object Day14 {
private const val iterationsPart1 = 10
private const val iterationsPart2 = 40
private fun solve(lines: List<String>, iterations: Int): Long {
val start = lines[0]
val rules = lines.drop(2).map { it.sp... | 0 | Kotlin | 0 | 0 | ba81fadf2a8106fae3e16ed825cc25bbb7a95409 | 2,155 | advent-of-code-2021 | The Unlicense |
codeforces/deltix2021summer/b.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.deltix2021summer
import kotlin.math.abs
private fun solve(a: List<Int>, first: Int): Long {
val aIndices = a.indices.filter { a[it] == 1 }
val neededIndices = a.indices.filter { it % 2 == 1 - first }
return aIndices.zip(neededIndices) { x, y -> abs(x - y).toLong() }.sum()
}
private fun solve(): ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 813 | competitions | The Unlicense |
src/main/kotlin/Day12.kt | Walop | 573,012,840 | false | {"Kotlin": 53630} | import java.io.InputStream
data class HeightMap(val start: List<Int>, val end: Int, val width: Int, val graph: List<List<Boolean>>)
class Day12 {
companion object {
private fun readMap(input: InputStream?, startTile: Char, endTile: Char): HeightMap {
if (input == null) {
throw ... | 0 | Kotlin | 0 | 0 | 7a13f6500da8cb2240972fbea780c0d8e0fde910 | 4,285 | AdventOfCode2022 | The Unlicense |
src/main/kotlin/dev/claudio/adventofcode2021/Day11Part2.kt | ClaudioConsolmagno | 434,559,159 | false | {"Kotlin": 78336} | package dev.claudio.adventofcode2021
fun main() {
Day11Part2().main()
}
private class Day11Part2 {
fun main() {
val input: List<String> = Support.readFileAsListString("day11-input.txt")
val map: MutableList<MutableList<Int>> = input
.map { it.toCharArray().map { it2 -> it2.titlecas... | 0 | Kotlin | 0 | 0 | 5f1aff1887ad0a7e5a3af9aca7793f1c719e7f1c | 2,939 | adventofcode-2021 | Apache License 2.0 |
2021/src/main/kotlin/aoc2016/Day20.kt | dkhawk | 433,915,140 | false | {"Kotlin": 170350} | package aoc2016
import java.io.File
import kotlin.math.max
import kotlin.math.min
import kotlin.system.measureTimeMillis
class Day20 {
companion object {
fun run() {
val time = measureTimeMillis {
// Day20().part1()
Day20().part2()
}
println("millis: $time")
}
}
privat... | 0 | Kotlin | 0 | 0 | 64870a6a42038acc777bee375110d2374e35d567 | 1,941 | advent-of-code | MIT License |
src/Day10_02.kt | michaelYuenAE | 573,094,416 | false | {"Kotlin": 74685} | fun d10t1(lines: List<String>) {
var registerX = 1
var sum = 0
var cycle = 0
for (line in 1 .. lines.size ) {
val op = lines[line - 1].split(" ")
sum += executeCycle1(++cycle, registerX)
if (op[0] == "addx") {
sum += executeCycle1(++cycle, registerX)
regi... | 0 | Kotlin | 0 | 0 | ee521263dee60dd3462bea9302476c456bfebdf8 | 1,417 | advent22 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ShortestPathAllKeys.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 | 4,278 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SumSubarrayMins.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,328 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch7/Problem78.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch7
import kotlin.math.pow
import kotlin.math.sign
/**
* Problem 78: Coin Partitions
*
* https://projecteuler.net/problem=78
*
* Goal: Count the number of ways (mod 1e9 + 7) that N coins can be separated into piles.
*
* Constraints: 2 <= N <= 6e4
*
* e.g.: N = 5
* count = 7
* ... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 3,740 | project-euler-kotlin | MIT License |
src/Day02.kt | buongarzoni | 572,991,996 | false | {"Kotlin": 26251} | fun solveDay02() {
val input = readInput("Day02").map { ElveMatch.parse(it) }
println(input.sumOf { it.points })
val input2 = readInput("Day02").map { NewElveMatch.parse(it) }
println(input2.sumOf { it.points })
}
data class ElveMatch(val first: String, val second: String) {
val points = getResult(... | 0 | Kotlin | 0 | 0 | 96aadef37d79bcd9880dbc540e36984fb0f83ce0 | 1,741 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/problems/Day21.kt | PedroDiogo | 432,836,814 | false | {"Kotlin": 128203} | package problems
import kotlin.math.max
class Day21(override val input: String) : Problem {
override val number: Int = 21
private val startingPositions = input.lines().map { it.split(": ")[1].toInt() - 1 }
override fun runPartOne(): String {
var currentPlayer = 0
val scores = mutableListO... | 0 | Kotlin | 0 | 0 | 93363faee195d5ef90344a4fb74646d2d26176de | 4,580 | AdventOfCode2021 | MIT License |
aoc_2023/src/main/kotlin/problems/day8/DesertMap.kt | Cavitedev | 725,682,393 | false | {"Kotlin": 228779} | package problems.day8
import problems.utils.Utils
class DesertMap(val directions: List<Int>, val connections: Map<String, Pair<String, String>>) {
companion object {
val inputRegex = Regex("""(.*) = \((.*), (.*)\)""")
}
constructor(lines: List<String>) : this(lines[0].map {
when (it) {
... | 0 | Kotlin | 0 | 1 | aa7af2d5aa0eb30df4563c513956ed41f18791d5 | 2,188 | advent-of-code-2023 | MIT License |
src/day05/Day05.kt | voom | 573,037,586 | false | {"Kotlin": 12156} | package day05
import readInput
/**
* --- Day 5: Supply Stacks ---
*/
fun main() {
val p = Regex("\\d+")
fun parseMoves(input: List<String>): List<List<Int>> {
return input
.map { record ->
p.findAll(record)
.map { it.value.toInt() - 1 }
... | 0 | Kotlin | 0 | 1 | a8eb7f7b881d6643116ab8a29177d738d6946a75 | 2,986 | aoc2022 | Apache License 2.0 |
src/main/kotlin/year2022/day16/Problem.kt | Ddxcv98 | 573,823,241 | false | {"Kotlin": 154634} | package year2022.day16
import IProblem
import sublst
import substr
import kotlin.math.max
class Problem : IProblem {
private val valves = linkedMapOf<String, Valve>()
private val dist: Array<IntArray>
init {
val parents = mutableMapOf<String, MutableSet<Valve>>()
var i = 0
javaCl... | 0 | Kotlin | 0 | 0 | 455bc8a69527c6c2f20362945b73bdee496ace41 | 3,819 | advent-of-code | The Unlicense |
src/Day09.kt | nordberg | 573,769,081 | false | {"Kotlin": 47470} | import java.lang.IllegalArgumentException
import kotlin.math.abs
enum class Direction {
UP,
UPRIGHT,
UPLEFT,
DOWN,
DOWNRIGHT,
DOWNLEFT,
LEFT,
RIGHT
}
data class Move(val direction: Direction, val steps: Int)
data class Point(val x: Int, val y: Int) {
fun distanceTo(otherPoint: Poi... | 0 | Kotlin | 0 | 0 | 3de1e2b0d54dcf34a35279ba47d848319e99ab6b | 8,861 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/aoc2020/day1.kt | sodaplayer | 434,841,315 | false | {"Kotlin": 31068} | package aoc2020.day1
import aoc2020.utils.loadInput
fun main() {
val numbers = loadInput("/2020/day1")
.bufferedReader()
.readLines()
.map(String::toInt)
val complements = numbers.associateBy { 2020 - it }
val allPairs = sequence {
for ((i, m) in numbers.withIndex()) {
... | 0 | Kotlin | 0 | 0 | 2d72897e1202ee816aa0e4834690a13f5ce19747 | 1,066 | aoc-kotlin | Apache License 2.0 |
day21/src/main/kotlin/de/havox_design/aoc2023/day21/Day21.kt | Gentleman1983 | 715,778,541 | false | {"Kotlin": 163912, "Python": 1048} | package de.havox_design.aoc2023.day21
import kotlin.math.pow
class Day21(private var filename: String) {
private val ICON_ROCK = '#'
private val ICON_START = 'S'
fun solvePart1(steps: Int = 64): Long {
val rocks = HashSet<Pair<Int, Int>>()
var start = Pair(0, 0)
for ((row, inputR... | 1 | Kotlin | 0 | 0 | eac8ff77420f061f5cef0fd4b8d05e7805c4cc5a | 5,538 | aoc2023 | Apache License 2.0 |
solutions/src/CountLuck.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | /**
* https://www.hackerrank.com/challenges/count-luck/problem
*/
class CountLuck {
// Complete the countLuck function below.
fun countLuck(matrix: Array<String>, k: Int): String {
return if (determineStepDirectionSwitches(matrix, k)) "Impressed" else "Oops!"
}
private fun determineStepDi... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 3,077 | leetcode-solutions | MIT License |
src/main/kotlin/days/Day10.kt | andilau | 429,206,599 | false | {"Kotlin": 113274} | package days
import kotlin.math.PI
import kotlin.math.atan2
import kotlin.math.sqrt
@AdventOfCodePuzzle(
name = "Monitoring Station",
url = "https://adventofcode.com/2019/day/10",
date = Date(day = 10, year = 2019)
)
class Day10(input: List<String>) : Puzzle {
private val asteroids: List<Asteroid> = ... | 2 | Kotlin | 0 | 0 | f51493490f9a0f5650d46bd6083a50d701ed1eb1 | 2,359 | advent-of-code-2019 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/championofgoats/advent/2019/day3/day3.kt | ChampionOfGoats | 225,446,764 | false | null | package championofgoats.advent.twentynineteen.day3
import java.io.File
import java.util.*
import championofgoats.advent.Problem
import championofgoats.advent.utils.Point
import championofgoats.advent.utils.logging.Logger
object Day3 : Problem {
override fun solve(inputDir: String, outputDir: String, log: Logger) ... | 0 | Kotlin | 0 | 0 | 4f69de1579f40928c1278c3cea4e23e0c0e3b742 | 3,537 | advent-of-code | MIT License |
src/main/kotlin/QuicksortDualPivot.kt | Codextor | 453,514,033 | false | {"Kotlin": 26975} | /**
* Swap two elements in an array.
*/
private fun swap(arr: Array<Int>, i: Int, j: Int) {
val temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
}
/**
* Partition the array around two pivots.
* Return the indices of the pivots.
*/
private fun partition(arr: Array<Int>, left: Int, right: Int): Pair<Int, Int... | 0 | Kotlin | 1 | 0 | 68b75a7ef8338c805824dfc24d666ac204c5931f | 1,842 | kotlin-codes | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2022/Day15.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2022
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import com.s13g.aoc.XY
import com.s13g.aoc.manhattan
import com.s13g.aoc.resultFrom
import com.s13g.aoc.subtract
import kotlin.math.abs
import kotlin.math.max
/**
* --- Day 15: Beacon Exclusion Zone ---
* https://adventofcode.com/202... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 2,345 | euler | Apache License 2.0 |
scratch/src/main/kotlin/x/scratch/problem6.kt | binkley | 184,655,460 | false | null | package x.scratch
import com.github.ajalt.mordant.AnsiCode
import com.github.ajalt.mordant.TermColors
import x.scratch.Problem6.Companion.problem6
import kotlin.math.log
import kotlin.math.round
import kotlin.math.sqrt
/**
* Empirically, the first 50 are quickly computable before becoming too
* sparse.
*/
private ... | 0 | Kotlin | 1 | 2 | 4787a43f8e27dbde3a967b35f5a3363864cbd51f | 4,005 | spikes | The Unlicense |
src/main/kotlin/Day02.kt | bent-lorentzen | 727,619,283 | false | {"Kotlin": 68153} | import java.time.LocalDateTime
import java.time.ZoneOffset
fun main() {
fun gameNumber(line: String) = line.substringBefore(":").substringAfter("Game ").toInt()
fun games(line: String) = line.substringAfter(": ").split("; ")
fun cubeCounts(gameStrings: List<String>) = gameStrings.map { game ->
gam... | 0 | Kotlin | 0 | 0 | 41f376bd71a8449e05bbd5b9dd03b3019bde040b | 1,665 | aoc-2023-in-kotlin | Apache License 2.0 |
2015/src/main/kotlin/com/koenv/adventofcode/Day17.kt | koesie10 | 47,333,954 | false | null | package com.koenv.adventofcode
import java.util.*
object Day17 {
public fun getCombinationsThatFit(required: Int, buckets: List<Int>): Int {
return findValidCombinations(required, buckets).size
}
public fun getCombinationsThatFit(required: Int, buckets: String): Int {
return getCombinatio... | 0 | Kotlin | 0 | 0 | 29f3d426cfceaa131371df09785fa6598405a55f | 1,735 | AdventOfCode-Solutions-Kotlin | MIT License |
src/Day05.kt | remidu | 573,452,090 | false | {"Kotlin": 22113} | fun main() {
var map: HashMap<Int, ArrayList<Char>> = HashMap()
fun parseStacks(input: List<String>) {
for (line in input) {
if (line.contains('[')) {
var id = 1
for (i in 1..line.length step 4) {
if (!map.contains(id)) {
... | 0 | Kotlin | 0 | 0 | ecda4e162ab8f1d46be1ce4b1b9a75bb901bc106 | 2,857 | advent-of-code-2022 | Apache License 2.0 |
Day 12/src/main/kotlin/main.kt | TimBo93 | 434,023,800 | false | {"C": 662683, "Objective-C": 18803, "TypeScript": 17001, "C++": 16492, "Dart": 11944, "Cuda": 10189, "C#": 9276, "Visual Basic .NET": 8923, "JavaScript": 8261, "Scala": 7729, "Fortran": 6947, "Groovy": 6001, "PHP": 4984, "Java": 4945, "Lua": 4694, "MATLAB": 4594, "F#": 4309, "Haskell": 3884, "Python": 3704, "Kotlin": 3... | import java.io.File
class Route (
val from: String,
val to: String
){
fun reverse(): Route {
return Route(to, from)
}
}
class Transitions {
private var allTransitions = mutableMapOf<String, MutableList<String>>()
fun addTransition (r: Route) {
addRoute(r)
addRoute(... | 0 | C | 0 | 0 | 69950107dfb96681020f3e27cc3e762d762945c6 | 3,006 | AdventOfCode2021 | MIT License |
src/main/java/leetcode/binarytreefromstring/Solution.kt | thuytrinh | 106,045,038 | false | null | package leetcode.binarytreefromstring
import leetcode.binarytreeboundary.TreeNode
import java.util.*
typealias NextIndex = Int
typealias IntValue = Int
/**
* https://leetcode.com/problems/construct-binary-tree-from-string/description/
*/
class Solution {
private fun String.nextInt(index: Int): Pair<IntValue, Nex... | 0 | Kotlin | 0 | 1 | 23da0286a88f855dcab1999bcd7174343ccc1164 | 1,594 | algorithms | MIT License |
kotlin/src/katas/kotlin/leetcode/first_missing_positive/FirstMissingPositive.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.first_missing_positive
import datsok.shouldEqual
import org.junit.jupiter.api.Test
//
// https://leetcode.com/problems/first-missing-positive
//
// Given an unsorted integer array, find the smallest missing positive integer.
//
// Example 1:
// Input: [1,2,0]
// Output: 3
//
// Example 2... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,907 | katas | The Unlicense |
src/main/kotlin/sk/mkiss/algorithms/generator/PermutationsGenerator.kt | marek-kiss | 430,858,906 | false | {"Kotlin": 85343} | package sk.mkiss.algorithms.generator
object PermutationsGenerator {
/**
* Generate all permutations of elements in the given set
*
* @param T - the type of elements in the input set
* @param input - the input set
* @return list containing all permutations
*/
fun <T> generateAll(... | 0 | Kotlin | 0 | 0 | 296cbd2e04a397597db223a5721b6c5722eb0c60 | 1,656 | algo-in-kotlin | MIT License |
src/main/kotlin/io/github/clechasseur/adventofcode/y2015/Day6.kt | clechasseur | 568,233,589 | false | {"Kotlin": 242914} | package io.github.clechasseur.adventofcode.y2015
import io.github.clechasseur.adventofcode.util.Pt
import io.github.clechasseur.adventofcode.y2015.data.Day6Data
import kotlin.math.max
object Day6 {
private val input = Day6Data.input
private val commandRegex = """(turn (?:on|off)|toggle) (\d+),(\d+) through (... | 0 | Kotlin | 0 | 0 | e5a83093156cd7cd4afa41c93967a5181fd6ab80 | 2,468 | adventofcode2015 | MIT License |
src/aoc2023/Day01.kt | dayanruben | 433,250,590 | false | {"Kotlin": 79134} | package aoc2023
import checkValue
import readInput
fun main() {
val (year, day) = "2023" to "Day01"
val digitsMap = mapOf(
"one" to "1",
"two" to "2",
"three" to "3",
"four" to "4",
"five" to "5",
"six" to "6",
"seven" to "7"... | 1 | Kotlin | 2 | 30 | df1f04b90e81fbb9078a30f528d52295689f7de7 | 1,804 | aoc-kotlin | Apache License 2.0 |
src/Day05.kt | flexable777 | 571,712,576 | false | {"Kotlin": 38005} | import java.util.*
fun main() {
fun loadStack(stackNumber: Int, crate: Char, arrayOfStacks: Array<Stack<Char>>) {
arrayOfStacks[stackNumber].add(0, crate)
}
fun moveFromStack(stackNumberFrom: Int, stackNumberTo: Int, arrayOfStacks: Array<Stack<Char>>) {
arrayOfStacks[stackNumberTo].push(a... | 0 | Kotlin | 0 | 0 | d9a739eb203c535a3d83bc5da1b6a6a90a0c7bd6 | 3,328 | advent-of-code-2022 | Apache License 2.0 |
2021/src/Day20.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | import kotlin.math.abs
import kotlin.math.max
// https://adventofcode.com/2021/day/20
fun main() {
class Image(cols: Int, rows: Int, numbers: Array<Int>, mask: String) {
val cols = cols
val rows = rows
var numbers = numbers
val mask = mask
fun getMaskAt(index : Int) : Int {
val point = i... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 3,932 | advent-of-code | Apache License 2.0 |
src/main/kotlin/codes/hanno/adventofcode/day2/Day2.kt | hannotify | 572,944,980 | false | {"Kotlin": 7464} | import Day2.Choice.ChoiceCategory.*
import Day2.Outcome.WDL.*
import java.nio.file.Files
import java.nio.file.Path
fun main(args: Array<String>) {
Day2().run(Path.of("src/main/resources/day2/input.txt"))
}
class Day2 {
fun run(input: Path) {
val scores = Files.lines(input).map {
val split... | 0 | Kotlin | 0 | 0 | ccde130e52f5637f140b331416634b8ce86bc401 | 1,760 | advent-of-code | Apache License 2.0 |
src/main/kotlin/me/circuitrcay/euler/challenges/oneToTwentyFive/Problem12.kt | adamint | 134,989,381 | false | null | package me.circuitrcay.euler.challenges.oneToTwentyFive
import me.circuitrcay.euler.Problem
class Problem12 : Problem<String>() {
override fun calculate(): Any {
return factorsOfNumber()
}
private fun factorsOfNumber(): Long {
var numFactors: Int
var counter = 2L
while (tr... | 0 | Kotlin | 0 | 0 | cebe96422207000718dbee46dce92fb332118665 | 3,210 | project-euler-kotlin | Apache License 2.0 |
src/main/kotlin/aoc/day5/SupplyStacks.kt | moosolutions | 571,461,075 | false | {"Kotlin": 12616} | package aoc.day5
class SupplyStacks(private val input: List<String>) {
val stacks = mutableListOf<Stack>()
init {
val rawStacks = input.slice(0..input.indexOf(""))
.filter { line -> line.isNotEmpty() }
.map {
it.split(",")
}
.flatten()
... | 0 | Kotlin | 0 | 0 | 6ef815df5c196ccf86041fcb0b76e3a2c14584af | 2,339 | advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | samorojy | 572,624,502 | false | {"Kotlin": 5094} | fun main() {
fun part1(input: List<String>) =
input.parsedPairs().count { (p1, p2) ->
(p1.first in p2 && p1.last in p2) || (p2.first in p1 && p2.last in p1)
}
fun part2(input: List<String>) =
input.parsedPairs().count { (p1, p2) ->
p1.first in p2 || p1.last in p2... | 0 | Kotlin | 0 | 0 | 7a38657c4ff7b42c5d49379014f88d054183bd2b | 649 | advent-of-code | Apache License 2.0 |
lib/src/main/kotlin/utils/math.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | package utils
import kotlin.math.sqrt
fun solveQuadratic(a: Double, b: Double, c: Double): Pair<Double, Double> {
val x1 = (-b + sqrt(b * b - 4 * a * c)) / 2 * a
val x2 = (-b - sqrt(b * b - 4 * a * c)) / 2 * a
return minOf(x1, x2) to maxOf(x1, x2)
}
val Int.prime: Boolean get() {
return (2 .. sqrt(this.toDou... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 852 | aoc_kotlin | MIT License |
src/year_2023/day_05/Day05.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2023.day_05
import readInput
data class SourceToDestination(
val source: Long,
val destination: Long,
val length: Long
) {
fun containsSource(source: Long): Boolean {
return source >= this.source && source < this.source + length
}
fun containsDestination(destination: Lon... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 5,917 | advent_of_code | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.