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/Day02.kt | rickbijkerk | 572,911,701 | false | {"Kotlin": 31571} | fun main() {
fun part1(input: List<String>): Int {
val draw = 3
val win = 6
val choiceValue = mapOf(
"A" to 1,
"B" to 2,
"C" to 3,
)
val result = input.map {
val opponentPlay = it.split(" ")[0]
val myChoice = it.s... | 0 | Kotlin | 0 | 0 | 817a6348486c8865dbe2f1acf5e87e9403ef42fe | 3,176 | aoc-2022 | Apache License 2.0 |
src/solutionsForBookCrackingTheCodingInterview/stacksAndQueues/MinArrayStack.kt | mrkostua | 120,207,236 | false | null | package solutionsForBookCrackingTheCodingInterview.stacksAndQueues
/**
* @author <NAME>
* @created on 3/21/2018
* "Cracking the Coding Interview" task 3.1, 3.2
*/
/**
* Task 1 :
* Describe how you could use a single array to implement three stacks.
*/
/**
* Solution :
* Fixed-size stack
* If it is fixed-si... | 0 | Kotlin | 0 | 0 | bfb7124e93e485bee5ee8c4b69bf9c0a0a532ecf | 2,829 | Cracking-the-Coding-Interview-solutions | MIT License |
kotlin/src/katas/kotlin/leetcode/course_schedule_2/CourseSchedule2.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.course_schedule_2
import datsok.shouldEqual
import org.junit.Test
/**
* https://leetcode.com/problems/course-schedule-ii
*/
class CourseSchedule2Tests {
@Test fun `find the ordering of courses you should take to finish all courses`() {
findOrder(0, emptyArray()) shouldEqual... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,198 | katas | The Unlicense |
src/Day16.kt | Kvest | 573,621,595 | false | {"Kotlin": 87988} | import java.util.*
import kotlin.math.max
fun main() {
val testInput = readInput("Day16_test")
check(part1(testInput) == 1651)
check(part2(testInput) == 1707)
val input = readInput("Day16")
println(part1(input))
println(part2(input))
}
private const val PART1_MINUTES = 30
private const val PA... | 0 | Kotlin | 0 | 0 | 6409e65c452edd9dd20145766d1e0ea6f07b569a | 5,177 | AOC2022 | Apache License 2.0 |
src/day7.kt | eldarbogdanov | 577,148,841 | false | {"Kotlin": 181188} | class Node(val name: String, val folders: MutableMap<String, Node>, val files: MutableMap<String, Long>);
val parents: MutableMap<Node, Node> = mutableMapOf<Node, Node>();
val folderSizes: MutableMap<Node, Long> = mutableMapOf();
fun sumFiles(cur: Node, limit: Long): Pair<Long, Long> {
var size: Long = cur.files.v... | 0 | Kotlin | 0 | 0 | bdac3ab6cea722465882a7ddede89e497ec0a80c | 2,089 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day7.kt | ivan-gusiev | 726,608,707 | false | {"Kotlin": 34715, "Python": 2022, "Makefile": 50} | import util.AocDay
import util.AocInput
import util.AocSequence
typealias Day7InputType = List<String>;
class Day7 : Runner {
val TEST_INPUT: String = """
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483
""".trimIndent()
override fun run() {
val day = AocDa... | 0 | Kotlin | 0 | 0 | 5585816b435b42b4e7c77ce9c8cabc544b2ada18 | 5,459 | advent-of-code-2023 | MIT License |
src/Day03.kt | janbina | 157,854,025 | false | null | import kotlin.test.assertEquals
object Day03 {
private fun createArea(input: List<Claim>): Array<IntArray> {
val area = Array(1000) { IntArray(1000) { 0 } }
input.forEach {
for (i in it.left until it.left+it.width) {
for (j in it.top until it.top+it.height) {
... | 0 | Kotlin | 0 | 0 | 522d93baf9ff4191bc2fc416d95b06208be32325 | 1,555 | advent-of-code-2018 | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round0/MergeSort.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round0
import kotlin.math.*
/**
* 归并排序
*/
fun testMergeSort() {
val array1 = intArrayOf(5, 7, 2, 9, 3, 1, 4, 0, 8, 6)
array1.mergeSort1()
array1.forEach { print("$it ") }
println()
val array2 = intArrayOf(5, 7, 2, 9, 3, 1, 4, 0, 8, 6)
array2.mergeSort2()
array2.forEach { prin... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,230 | Algorithm | Apache License 2.0 |
src/main/kotlin/org/flightofstairs/ctci/treesAndGraphs/NumberOfIslands.kt | FlightOfStairs | 509,587,102 | false | {"Kotlin": 38930} | package org.flightofstairs.ctci.treesAndGraphs
data class Position(val x: Int, val y: Int) {
// Supports diagonals
fun adjacentPositions() = (-1..1).flatMap { dx ->
(-1..1).map { dy ->
Position(x + dx, y + dy)
}
}.filter { it != this }
}
private fun positionExists(position: Po... | 0 | Kotlin | 0 | 0 | 5f4636ac342f0ee5e4f3517f7b5771e5aabe5992 | 1,551 | FlightOfStairs-ctci | MIT License |
src/Day12.kt | spaikmos | 573,196,976 | false | {"Kotlin": 83036} | import java.util.Deque
fun main() {
fun part1(input: List<String>): Int {
val yLen = input[0].length
val xLen = input.size
val visited = Array(xLen) { IntArray(yLen){0} }
val nodes = input.map{it.toCharArray()}
val end = nodes.find { it.contains('E') }
val endX = no... | 0 | Kotlin | 0 | 0 | 6fee01bbab667f004c86024164c2acbb11566460 | 5,189 | aoc-2022 | Apache License 2.0 |
src/Day07.kt | pavlo-dh | 572,882,309 | false | {"Kotlin": 39999} | fun main() {
class Directory(val name: String, val parent: Directory?) {
var size = 0
}
fun processFiles(currentCommandIndex: Int, input: List<String>, currentDirectory: Directory): Int {
val nextCommandIndex =
(currentCommandIndex + 1 until input.size).firstOrNull { index -> in... | 0 | Kotlin | 0 | 2 | c10b0e1ce2c7c04fbb1ad34cbada104e3b99c992 | 3,943 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/adventofcode/y2021/Day21.kt | Tasaio | 433,879,637 | false | {"Kotlin": 117806} | import adventofcode.BigIntegerMap
import adventofcode.RotatingNumber
import adventofcode.parseNumbersToIntList
import adventofcode.runDay
import java.math.BigInteger
fun main() {
val testInput = """
Player 1 starting position: 4
Player 2 starting position: 8
""".trimIndent()
runDay(
... | 0 | Kotlin | 0 | 0 | cc72684e862a782fad78b8ef0d1929b21300ced8 | 3,476 | adventofcode2021 | The Unlicense |
generator/src/main/kotlin/com/kylemayes/generator/generate/support/Struct.kt | KyleMayes | 305,287,877 | false | {"Rust": 6654307, "Kotlin": 153555, "GLSL": 3759, "Python": 2709, "Shell": 1142, "Makefile": 800, "PowerShell": 721} | // SPDX-License-Identifier: Apache-2.0
package com.kylemayes.generator.generate.support
import com.kylemayes.generator.registry.Identifier
import com.kylemayes.generator.registry.PointerType
import com.kylemayes.generator.registry.Registry
import com.kylemayes.generator.registry.Structure
import com.kylemayes.generat... | 12 | Rust | 29 | 216 | c120c156dc5a6ebcfd8870d8688001f4accfb373 | 5,065 | vulkanalia | Apache License 2.0 |
src/main/kotlin/week1/SupplyStacks.kt | waikontse | 572,850,856 | false | {"Kotlin": 63258} | package week1
import shared.Puzzle
class SupplyStacks : Puzzle(5) {
override fun solveFirstPart(): Any {
val sections = splitSections(puzzleInput)
val startStacks = sections[0].map { parseStack(it) }
.map { it.filter { pair -> pair.second != ' ' } }
.let { createStacks(it)... | 0 | Kotlin | 0 | 0 | 860792f79b59aedda19fb0360f9ce05a076b61fe | 3,031 | aoc-2022-in-kotllin | Creative Commons Zero v1.0 Universal |
src/Day04.kt | jmorozov | 573,077,620 | false | {"Kotlin": 31919} | fun main() {
val inputData = readInput("Day04")
part1(inputData)
part2(inputData)
}
private fun part1(inputData: List<String>) {
var oneRangeFullyContainTheOtherTimes = 0
for (line in inputData) {
val trimmedLine = line.trim()
val parts = trimmedLine.split(",")
val range1 ... | 0 | Kotlin | 0 | 0 | 480a98838949dbc7b5b7e84acf24f30db644f7b7 | 1,403 | aoc-2022-in-kotlin | Apache License 2.0 |
src/year2021/10/Day10.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2021.`10`
import readInput
val entryBrackets = setOf<Char>(
'{',
'[',
'(',
'<',
)
val closingBracket = setOf<Char>(
'}',
']',
')',
'>',
)
fun charToValue(bracket: Char): Int {
return when (bracket) {
')' -> 3
']' -> 57
'}' -> 1197
'>' ... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 3,864 | KotlinAdventOfCode | Apache License 2.0 |
src/main/kotlin/Day12.kt | lanrete | 244,431,253 | false | null | import mathUti.lcm
import kotlin.math.abs
enum class Axis {
X,
Y,
Z,
ALL
}
data class Moon(var x: Int, var y: Int, var z: Int) {
private var vx = 0
private var vy = 0
private var vz = 0
val potentialEnergy: Int
get() {
return abs(x) + abs(y) + abs(z)
}
... | 0 | Kotlin | 0 | 1 | 15125c807abe53230e8d0f0b2ca0e98ea72eb8fd | 2,993 | AoC2019-Kotlin | MIT License |
src/main/kotlin/mirecxp/aoc23/day07/Day07.kt | MirecXP | 726,044,224 | false | {"Kotlin": 42343} | package mirecxp.aoc23.day07
import mirecxp.aoc23.readInput
//https://adventofcode.com/2023/day/7
class Day07(private val inputPath: String) {
private var hands: List<Hand> = readInput(inputPath).map { line ->
with(line.split(" ")) {
Hand(get(0), get(1).toInt())
}
}
fun mapCar... | 0 | Kotlin | 0 | 0 | 6518fad9de6fb07f28375e46b50e971d99fce912 | 5,060 | AoC-2023 | MIT License |
src/Day01.kt | RobvanderMost-TomTom | 572,005,233 | false | {"Kotlin": 47682} | fun main() {
fun foodPerElf(input: List<String>): List<List<String>> {
val separators = input.withIndex().filter { it.value.isEmpty() }.map { it.index }
return (listOf(-1) + separators + listOf(input.size)).zipWithNext().map { input.subList(it.first + 1, it.second) }
}
fun part1(input: List... | 5 | Kotlin | 0 | 0 | b7143bceddae5744d24590e2fe330f4e4ba6d81c | 903 | advent-of-code-2022 | Apache License 2.0 |
src/day04/Code.kt | ldickmanns | 572,675,185 | false | {"Kotlin": 48227} | package day04
import readInput
fun main() {
val input = readInput("day04/input")
// val input = readInput("day04/input_test")
println(part1(input))
println(part2(input))
}
typealias IntPair = Pair<Int, Int>
val IntPair.lowerBound: Int get() = first
val IntPair.upperBound: Int get() = second
infix ... | 0 | Kotlin | 0 | 0 | 2654ca36ee6e5442a4235868db8174a2b0ac2523 | 1,607 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/g1101_1200/s1170_compare_strings_by_frequency_of_the_smallest_character/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1101_1200.s1170_compare_strings_by_frequency_of_the_smallest_character
// #Medium #Array #String #Hash_Table #Sorting #Binary_Search
// #2023_05_25_Time_221_ms_(50.00%)_Space_44_MB_(50.00%)
class Solution {
fun numSmallerByFrequency(queries: Array<String>, words: Array<String>): IntArray {
val qu... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,578 | LeetCode-in-Kotlin | MIT License |
src/Day11.kt | zt64 | 572,594,597 | false | null | import java.math.BigInteger
private object Day11 : Day(11) {
private val monkeys = input.split("\n\n").map(String::lines).map {
val operationString = it[2].substringAfter("= ")
val (_, op, b) = operationString.split(" ")
Monkey(
startingItems = it[1].substringAfter("Starting it... | 0 | Kotlin | 0 | 0 | 4e4e7ed23d665b33eb10be59670b38d6a5af485d | 3,382 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/cz/tomasbublik/Day03.kt | tomasbublik | 572,856,220 | false | {"Kotlin": 21908} | package cz.tomasbublik
fun main() {
fun getSameChar(firstHalf: CharSequence, secondHalf: CharSequence): Char {
for (firstChar in firstHalf) {
for (secondChar in secondHalf) {
if (firstChar == secondChar) {
return firstChar
}
}
... | 0 | Kotlin | 0 | 0 | 8c26a93e8f6f7ab0f260c75a287608dd7218d0f0 | 2,692 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day03.kt | wedrychowiczbarbara | 573,185,235 | false | null | fun main() {
fun countPriority(letter: Char): Int{
val v = letter.code
if (v in 65..90) {
return v - 38
}
if (v in 95..126) {
return v - 96
}
return 0
}
fun part1(input: List<String>): Int {
var suma=0
input.forEach{
... | 0 | Kotlin | 0 | 0 | 04abc035c51649dffe1dde8a115d98640552a99d | 1,183 | AOC_2022_Kotlin | Apache License 2.0 |
src/Day25.kt | spaikmos | 573,196,976 | false | {"Kotlin": 83036} | fun main() {
fun snafuToDecimal(snafu: String): Long {
var num = 0L
for (c in snafu) {
num *= 5
when (c) {
'2' -> num += 2
'1' -> num += 1
'0' -> num += 0
'-' -> num -= 1
'=' -> num -= 2
... | 0 | Kotlin | 0 | 0 | 6fee01bbab667f004c86024164c2acbb11566460 | 1,549 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/problems/Day3.kt | PedroDiogo | 432,836,814 | false | {"Kotlin": 128203} | package problems
class Day3(override val input: String) : Problem {
override val number: Int = 3
private val inputList = input.lines()
.map { line -> line.toCharArray().map { c -> c.digitToInt() }.toList() }
override fun runPartOne(): String {
val gammaRate = mostCommonBitPerPosition(input... | 0 | Kotlin | 0 | 0 | 93363faee195d5ef90344a4fb74646d2d26176de | 2,318 | AdventOfCode2021 | MIT License |
src/main/kotlin/y2022/day14/Day14.kt | TimWestmark | 571,510,211 | false | {"Kotlin": 97942, "Shell": 1067} | package y2022.day14
import Coord
fun main() {
AoCGenerics.printAndMeasureResults(
part1 = { part1() },
part2 = { part2() }
)
}
enum class Element {
ROCK,
SAND,
AIR,
SAND_SOURCE
}
fun input(): Pair<MutableMap<Int, MutableMap<Int, Element>>, Int> {
val allPaths = AoCGeneric... | 0 | Kotlin | 0 | 0 | 23b3edf887e31bef5eed3f00c1826261b9a4bd30 | 4,506 | AdventOfCode | MIT License |
aoc21/day_16/main.kt | viktormalik | 436,281,279 | false | {"Rust": 227300, "Go": 86273, "OCaml": 82410, "Kotlin": 78968, "Makefile": 13967, "Roff": 9981, "Shell": 2796} | import java.io.File
data class Packet(val version: Int, val id: Int) {
var value: Long = 0
val innerPackets = mutableListOf<Packet>()
var len = 0
fun versionSum(): Int = version + innerPackets.map { it.versionSum() }.sum()
fun eval(): Long = when (id) {
0 -> innerPackets.map { it.eval() }... | 0 | Rust | 1 | 0 | f47ef85393d395710ce113708117fd33082bab30 | 2,240 | advent-of-code | MIT License |
src/org/aoc2021/Day19.kt | jsgroth | 439,763,933 | false | {"Kotlin": 86732} | package org.aoc2021
import java.nio.file.Files
import java.nio.file.Path
import kotlin.math.abs
typealias Vector = List<Int>
typealias Matrix = List<List<Int>>
private fun Vector.vectorAdd(vector: Vector): Vector {
return this.mapIndexed { i, value ->
value + vector[i]
}
}
private fun Vector.vectorS... | 0 | Kotlin | 0 | 0 | ba81fadf2a8106fae3e16ed825cc25bbb7a95409 | 6,791 | advent-of-code-2021 | The Unlicense |
src/main/kotlin/com/ginsberg/advent2021/Day24.kt | tginsberg | 432,766,033 | false | {"Kotlin": 92813} | /*
* Copyright (c) 2021 by <NAME>
*/
/**
* Advent of Code 2021, Day 24 - Arithmetic Logic Unit
* Problem Description: http://adventofcode.com/2021/day/24
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2021/day24/
*/
package com.ginsberg.advent2021
class Day24(input: List<String>) {
... | 0 | Kotlin | 2 | 34 | 8e57e75c4d64005c18ecab96cc54a3b397c89723 | 2,006 | advent-2021-kotlin | Apache License 2.0 |
src/Day12.kt | rosyish | 573,297,490 | false | {"Kotlin": 51693} | private data class Cell(val x: Int, val y: Int, val elevation: Char, val steps: Int)
fun main() {
fun elevation(input: Char): Char {
return when (input) {
'S' -> 'a'
'E' -> 'z'
else -> input
}
}
fun solve(input: List<String>, isStartingCell: (Char) -> Boo... | 0 | Kotlin | 0 | 2 | 43560f3e6a814bfd52ebadb939594290cd43549f | 1,868 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/leetcode/uber/StringCompressionII.kt | Magdi | 390,731,717 | false | null | package leetcode.uber
/**
* 1531. String Compression II
* https://leetcode.com/problems/string-compression-ii/
*/
typealias Length = Int
class StringCompressionII {
fun getLengthOfOptimalCompression(s: String, k: Int): Int {
if (s.isEmpty()) return 0
val compressions = mutableListOf<Compressio... | 0 | Kotlin | 0 | 0 | 63bc711dc8756735f210a71454144dd033e8927d | 2,260 | ProblemSolving | Apache License 2.0 |
src/Day06.kt | papichulo | 572,669,466 | false | {"Kotlin": 16864} | fun main() {
fun solve(input: String, distinct: Int): Int {
var result = distinct
input.windowed(distinct).forEach {
if (it.toCharArray().distinct().size == distinct) {
return result
}
result++
}
return result
}
fun part2(... | 0 | Kotlin | 0 | 0 | e277ee5bca823ce3693e88df0700c021e9081948 | 1,249 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/PerfectRectangle.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 | 4,823 | kotlab | Apache License 2.0 |
src/Day08.kt | KarinaCher | 572,657,240 | false | {"Kotlin": 21749} | fun main() {
/*
A tree is visible if all of the other trees between it and an edge of the grid are shorter than it
*/
fun isVisibleTree(x: Int, y: Int, forest: List<String>): Boolean {
val line = forest.get(x).toCharArray().toMutableList()
val column = forest.map { it.get(y) }.toMutable... | 0 | Kotlin | 0 | 0 | 17d5fc87e1bcb2a65764067610778141110284b6 | 3,657 | KotlinAdvent | Apache License 2.0 |
src/Day04.kt | wmichaelshirk | 573,031,182 | false | {"Kotlin": 19037} | import kotlin.math.max
fun main() {
fun inputToRangePairs (input: String): Pair<IntRange, IntRange> {
val pairList = input.split(",")
.map { p ->
p.split("-")
.map { p -> p.toInt() }
}
.map { p ->
p.first()..p.last()
... | 0 | Kotlin | 0 | 2 | b748c43e9af05b9afc902d0005d3ba219be7ade2 | 1,074 | 2022-Advent-of-Code | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2021/Day11.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2021
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.Pos
import com.chriswk.aoc.util.report
class Day11 : AdventDay(2021, 11) {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day = Day11()
report {
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,923 | adventofcode | MIT License |
year2023/src/main/kotlin/net/olegg/aoc/year2023/day15/Day15.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2023.day15
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.toPair
import net.olegg.aoc.year2023.DayOf2023
import net.olegg.aoc.year2023.day15.Day15.Step.Companion.toStep
/**
* See [Year 2023, Day 15](https://adventofcode.com/2023/day/15)
*/
object Day15 : DayOf2023(15) {
... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,467 | adventofcode | MIT License |
kotlin/src/main/kotlin/com/github/jntakpe/aoc2021/days/day25/Day25.kt | jntakpe | 433,584,164 | false | {"Kotlin": 64657, "Rust": 51491} | package com.github.jntakpe.aoc2021.days.day25
import com.github.jntakpe.aoc2021.shared.Day
import com.github.jntakpe.aoc2021.shared.readInputLines
object Day25 : Day {
override val input = parseInput()
override fun part1(): Number {
var steps = 0
var seafloor = input
while (true) {
... | 0 | Kotlin | 1 | 5 | 230b957cd18e44719fd581c7e380b5bcd46ea615 | 2,056 | aoc2021 | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2023/Day05.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2023
import se.saidaspen.aoc.util.*
fun main() = Day05.run()
object Day05 : Day(2023, 5) {
private val maps = input.split("\n\n").drop(1)
.map { it.lines().drop(1)
.associate {
l -> longs(l).let { (dst, src, len) -> src..(src + len) to dst..(dst + ... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,557 | adventofkotlin | MIT License |
advent-of-code2016/src/main/kotlin/day20/Advent20.kt | REDNBLACK | 128,669,137 | false | null | package day20
import parseInput
import splitToLines
import java.util.stream.LongStream
/**
--- Day 20: Firewall Rules ---
You'd like to set up a small hidden computer here so you can use it to get back into the network later. However, the corporate firewall only allows communication with certain external IP addresse... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 2,121 | courses | MIT License |
kotlin/src/main/kotlin/com/pbh/soft/day2/Day2Solver.kt | phansen314 | 579,463,173 | false | {"Kotlin": 105902} | package com.pbh.soft.day2
import cc.ekblad.konbini.*
import com.pbh.soft.common.Solver
import com.pbh.soft.common.parsing.ParsingUtils.onSuccess
import com.pbh.soft.common.parsing.ParsingUtils.parseLines
import com.pbh.soft.day2.Color.*
import com.pbh.soft.day2.Parsing.gameP
import mu.KLogging
import kotlin.math.max
... | 0 | Kotlin | 0 | 0 | 7fcc18f453145d10aa2603c64ace18df25e0bb1a | 2,407 | advent-of-code | MIT License |
src/Day07.kt | an4 | 575,331,225 | false | {"Kotlin": 117105} | fun main() {
fun printTree(root: Node) {
val currNode = root.getName()
var children = ""
if (root.isFile() || root.getChildren().isEmpty()) {
return
}
for (child in root.getChildren()) {
children = children + ", " + child.value.getName()
p... | 0 | Kotlin | 0 | 0 | df64adcc5d1ccab370acef01a7ed4d480ffbe2be | 15,812 | aoc22 | Apache License 2.0 |
src/main/kotlin/kt/kotlinalgs/app/searching/SortedMatrixSearch.ws.kts | sjaindl | 384,471,324 | false | null | package kt.kotlinalgs.app.searching
println("test")
val matrix = arrayOf(
intArrayOf(15, 20, 40, 85),
intArrayOf(20, 35, 80, 95),
intArrayOf(30, 55, 95, 105),
intArrayOf(40, 80, 100, 120)
)
Solution().sortedMatrixSearch(matrix, 30)
for (row in matrix.indices) {
for (col in matrix[0].indices) {
... | 0 | Java | 0 | 0 | e7ae2fcd1ce8dffabecfedb893cb04ccd9bf8ba0 | 3,655 | KotlinAlgs | MIT License |
src/day04/Day04.kt | andreas-eberle | 573,039,929 | false | {"Kotlin": 90908} | package day04
import readInput
const val day = "04"
fun main() {
fun calculatePart1Score(input: List<String>): Int {
return input.asSequence()
.map { row -> row.split(",", "-").map { num -> num.toInt() } }
.map { (it[0]..it[1]).toSet() to (it[2]..it[3]).toSet() }
.fil... | 0 | Kotlin | 0 | 0 | e42802d7721ad25d60c4f73d438b5b0d0176f120 | 1,401 | advent-of-code-22-kotlin | Apache License 2.0 |
src/main/kotlin/year2022/day-19.kt | ppichler94 | 653,105,004 | false | {"Kotlin": 182859} | package year2022
import lib.Traversal
import lib.TraversalDijkstra
import lib.aoc.Day
import lib.aoc.Part
import year2022.PartA19.Materials.Type.*
import kotlin.math.max
fun main() {
Day(19, 2022, PartA19(), PartB19()).run()
}
open class PartA19 : Part() {
protected data class Materials(val ore: Int = 0, va... | 0 | Kotlin | 0 | 0 | 49dc6eb7aa2a68c45c716587427353567d7ea313 | 6,827 | Advent-Of-Code-Kotlin | MIT License |
src/main/kotlin/no/chriswk/aoc2019/Day14.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2019
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.dayInputAsLines
import com.chriswk.aoc.util.fileToLines
import com.chriswk.aoc.util.report
import kotlin.math.ceil
import kotlin.math.sign
class Day14(val cost : Map<String, Pair<Long, List<Pair<Long, String>>>> = parseInp... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,912 | adventofcode2019 | MIT License |
src/main/kotlin/io/github/pshegger/aoc/y2020/Y2020D12.kt | PsHegger | 325,498,299 | false | null | package io.github.pshegger.aoc.y2020
import io.github.pshegger.aoc.common.BaseSolver
import io.github.pshegger.aoc.common.Coordinate
import kotlin.math.absoluteValue
class Y2020D12 : BaseSolver() {
override val year = 2020
override val day = 12
override fun part1(): Int =
parseInput().fold(Pair(C... | 0 | Kotlin | 0 | 0 | 346a8994246775023686c10f3bde90642d681474 | 3,225 | advent-of-code | MIT License |
src/Day02.kt | LukasAnda | 572,878,230 | false | {"Kotlin": 3190} | fun main() {
val input = readInput("Day02_test")
// check(processRockPaperScissors(input) == 15)
println(processRockPaperScissors2(readInput("Day02")))
}
fun processRockPaperScissors(input: List<String>) = input.sumOf { processMatch(it) }
fun processRockPaperScissors2(input: List<String>) = input.sumOf { pr... | 0 | Kotlin | 0 | 0 | 20ccddd7b0517cbaf7590364333201e33bd5c0d6 | 1,739 | AdventOfCode2022 | Apache License 2.0 |
src/Day23.kt | Allagash | 572,736,443 | false | {"Kotlin": 101198} | import java.io.File
// Advent of Code 2022, Day 23: Unstable Diffusion
class Day23(input: String) {
data class Pt(val x: Int, val y: Int) {
fun generateNeighbors() : List<Pt> =
listOf( Pt(x-1, y-1), Pt(x-1, y), Pt (x-1, y+1),
Pt(x, y-1),Pt(x, y+1),
Pt(x+1, y-1), Pt(x+1... | 0 | Kotlin | 0 | 0 | 8d5fc0b93f6d600878ac0d47128140e70d7fc5d9 | 3,923 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/com/dmc/advent2022/Day05.kt | dorienmc | 576,916,728 | false | {"Kotlin": 86239} | // --- Day 5: Supply Stacks ---
package com.dmc.advent2022
class Day05 : Day<String> {
override val index = 5
var crates = Crates(mutableListOf())
fun setCrates(input: List<String>) {
crates = Crates(input.toMutableList())
}
private fun String.parseInstruction() : Instruction {
va... | 0 | Kotlin | 0 | 0 | 207c47b47e743ec7849aea38ac6aab6c4a7d4e79 | 2,896 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/ru/timakden/aoc/year2023/Day02.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2023
import arrow.core.fold
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 2: Cube Conundrum](https://adventofcode.com/2023/day/2).
*/
object Day02 {
@JvmStatic
fun main(args: Array<String>) {
measure {
val input = readInp... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 1,708 | advent-of-code | MIT License |
src/test/kotlin/Day02.kt | christof-vollrath | 317,635,262 | false | null | import io.kotest.core.datatest.forAll
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
/*
--- Day 2: Password Philosophy ---
See https://adventofcode.com/2020/day/2
*/
fun String.validatePasswordInput(): Boolean {
val (policy, password) = parsePolicyAndPassword(this)
val count = ... | 1 | Kotlin | 0 | 0 | 8ad08350aa4bd1a29b7e18765fc7a2d6de8021e8 | 3,707 | advent_of_code_2020 | Apache License 2.0 |
src/Day07.kt | chasegn | 573,224,944 | false | {"Kotlin": 29978} |
/**
* Day 07 for Advent of Code 2022
* https://adventofcode.com/2022/day/7
*/
class Day07 : Day {
override val inputFileName: String = "Day07"
override val test1Expected: Int = 95437
override val test2Expected: Int = 24933642
/**
* Accepted solution: 1642503
*/
override fun part1(inpu... | 0 | Kotlin | 0 | 0 | 2b9a91f083a83aa474fad64f73758b363e8a7ad6 | 2,737 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day05.kt | TheMrMilchmann | 725,205,189 | false | {"Kotlin": 61669} | /*
* Copyright (c) 2023 <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 | f94ff8a4c9fefb71e3ea183dbc3a1d41e6503152 | 4,627 | AdventOfCode2023 | MIT License |
src/day06/Day06.kt | dkoval | 572,138,985 | false | {"Kotlin": 86889} | package day06
import readInputAsString
private const val DAY_ID = "06"
fun main() {
fun solve(input: String, windowSize: Int): Int {
// sliding window [start : start + k - 1]
var start = 0
while (start + windowSize < input.length) {
// starting from `start` index, check next k... | 0 | Kotlin | 1 | 0 | 791dd54a4e23f937d5fc16d46d85577d91b1507a | 1,962 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Utils.kt | FuKe | 433,722,611 | false | {"Kotlin": 19825} | import models.BinaryNumber
import models.BingoPlate
import models.Bit
import java.io.File
/**
* Reads lines from the given input file.
*/
fun readInput(name: String) = File("src", name).readLines()
fun String.toBinaryNumber(): BinaryNumber {
val bits: List<Bit> = map {
Bit(it.toString().toInt())
}
... | 0 | Kotlin | 0 | 0 | 1cfe66aedd83ea7df8a2bc26c453df257f349b0e | 2,674 | advent-of-code-2021 | Apache License 2.0 |
src/Day04.kt | dmarcato | 576,511,169 | false | {"Kotlin": 36664} | fun main() {
fun String.toRange(): IntRange {
val (start, end) = split("-").map { it.toInt() }
return IntRange(start, end)
}
fun IntRange.contains(other: IntRange): Boolean {
return contains(other.first) && contains(other.last)
}
fun IntRange.overlap(other: IntRange): Boole... | 0 | Kotlin | 0 | 0 | 6abd8ca89a1acce49ecc0ca8a51acd3969979464 | 1,286 | aoc2022 | Apache License 2.0 |
src/main/kotlin/_2020/Day16.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2020
import aocRun
import splitToInts
private val RULE_REGEX = Regex("^([\\w\\s]+): (\\d+)-(\\d+) or (\\d+)-(\\d+)$")
fun main() {
aocRun(puzzleInput) { input ->
val parts = input.split("\n\n")
val rules = parseRules(parts[0])
val tickets = parseTickets(parts[2])
var invalidTotal = 0
tickets.forE... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 21,685 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/year2022/day14/Day14.kt | kingdongus | 573,014,376 | false | {"Kotlin": 100767} | package year2022.day14
import Point2D
import readInputFileByYearAndDay
import readTestFileByYearAndDay
import kotlin.math.max
import kotlin.math.min
class Cave(val dimension: Point2D) {
// we go cheap and model the field as characters, similar to the visualization on the page
private var fieldState: Array<Ch... | 0 | Kotlin | 0 | 0 | aa8da2591310beb4a0d2eef81ad2417ff0341384 | 3,988 | advent-of-code-kotlin | Apache License 2.0 |
src/com/mrxyx/algorithm/ArrayAlg.kt | Mrxyx | 366,778,189 | false | null | package com.mrxyx.algorithm
/**
* 数组
*/
class ArrayAlg {
/**
* 吃香蕉
* https://leetcode-cn.com/problems/koko-eating-bananas/
*/
fun minEatingSpeed(piles: IntArray, h: Int): Int {
val max = getMax(piles)
var left = 1
var right = max + 1
while (left < right) {
... | 0 | Kotlin | 0 | 0 | b81b357440e3458bd065017d17d6f69320b025bf | 2,182 | algorithm-test | The Unlicense |
src/main/kotlin/io/github/clechasseur/adventofcode2021/Day3.kt | clechasseur | 435,726,930 | false | {"Kotlin": 315943} | package io.github.clechasseur.adventofcode2021
import io.github.clechasseur.adventofcode2021.data.Day3Data
object Day3 {
private val data = Day3Data.data
fun part1(): Int {
val gamma = data.lines().first().indices.map { i ->
data.lines().map { it[i] }.groupBy { it }.mapValues { it.value.s... | 0 | Kotlin | 0 | 0 | 4b893c001efec7d11a326888a9a98ec03241d331 | 1,492 | adventofcode2021 | MIT License |
kotlin/1846-maximum-element-after-decreasing-and-rearranging.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | // 1. O(nlogn) solution using sorting
class Solution {
fun maximumElementAfterDecrementingAndRearranging(arr: IntArray): Int {
arr.sort()
var prev = 0
for (n in arr) {
prev = minOf(prev + 1, n)
}
return prev
}
}
// 2. O(n) solution but at the cost of O(1) -... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,526 | leetcode | MIT License |
y2022/src/main/kotlin/adventofcode/y2022/Day18.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2022
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Vec3
object Day18 : AdventSolution(2022, 18, "Boiling Boulders") {
override fun solvePartOne(input: String): Int {
val lava = parse(input).toList()
val internalFaces = lava.flatMap { l -> directions... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 2,002 | advent-of-code | MIT License |
advent-of-code-2021/src/code/day6/Main.kt | Conor-Moran | 288,265,415 | false | {"Kotlin": 53347, "Java": 14161, "JavaScript": 10111, "Python": 6625, "HTML": 733} | package code.day6
import java.io.File
fun main() {
doIt("Day 6 Part 1: Test Input", "src/code/day6/test.input", part1);
doIt("Day 6 Part 1: Real Input", "src/code/day6/part1.input", part1);
doIt("Day 6 Part 2: Test Input", "src/code/day6/test.input", part2);
doIt("Day 6 Part 2: Real Input", "src/code/... | 0 | Kotlin | 0 | 0 | ec8bcc6257a171afb2ff3a732704b3e7768483be | 1,651 | misc-dev | MIT License |
src/kotlin2022/Day09.kt | egnbjork | 571,981,366 | false | {"Kotlin": 18156} | package kotlin2022
import readInput
import kotlin.math.abs
fun main() {
val gameInput = readInput("Day09_test")
val parsedInput = parseSteps(gameInput)
println(parsedInput)
val rope = Rope()
parsedInput.forEach { move(rope, it) }
println(rope.positionVisited.size)
}
fun move(rope: Rope, dir... | 0 | Kotlin | 0 | 0 | 1294afde171a64b1a2dfad2d30ff495d52f227f5 | 2,624 | advent-of-code-kotlin | Apache License 2.0 |
advent-of-code/src/main/kotlin/com/akikanellis/adventofcode/year2022/Day23.kt | akikanellis | 600,872,090 | false | {"Kotlin": 142932, "Just": 977} | package com.akikanellis.adventofcode.year2022
import com.akikanellis.adventofcode.year2022.utils.Point
import com.akikanellis.adventofcode.year2022.utils.circularListIterator
object Day23 {
fun numberOfEmptyGroundTiles(input: String): Int {
var grove = Grove.of(input)
val directions = Direction.or... | 8 | Kotlin | 0 | 0 | 036cbcb79d4dac96df2e478938de862a20549dce | 5,741 | advent-of-code | MIT License |
src/test/kotlin/days/y2022/Day09Test.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2022
import days.Day
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.Is.`is`
import org.junit.jupiter.api.Test
import kotlin.math.absoluteValue
class Day09 : Day(2022, 9) {
override fun partOne(input: String): Any {
val directions = parseInput(input)
val visit... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 3,931 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/year2022/day12/Problem.kt | Ddxcv98 | 573,823,241 | false | {"Kotlin": 154634} | package year2022.day12
import IProblem
class Problem : IProblem {
private lateinit var source: Node
private lateinit var dest: Node
private val matrix = javaClass
.getResource("/2022/12.txt")!!
.readText()
.lines()
.filter(String::isNotEmpty)
.mapIndexed { i, line ... | 0 | Kotlin | 0 | 0 | 455bc8a69527c6c2f20362945b73bdee496ace41 | 2,167 | advent-of-code | The Unlicense |
src/main/kotlin/year_2022/Day02.kt | krllus | 572,617,904 | false | {"Kotlin": 97314} | package year_2022
import utils.readInput
fun main() {
fun part1(input: List<String>): Int {
var sum = 0
for (round in input) {
val plays = round.split(" ")
val one = plays[0]
val two = plays[1]
val rockPaperScissorPart1 = RockPaperScissor.fromPart... | 0 | Kotlin | 0 | 0 | b5280f3592ba3a0fbe04da72d4b77fcc9754597e | 4,441 | advent-of-code | Apache License 2.0 |
src/main/kotlin/cc/stevenyin/leetcode/_0881_BoatsToSavePeople.kt | StevenYinKop | 269,945,740 | false | {"Kotlin": 107894, "Java": 9565} | package cc.stevenyin.leetcode
/**
* https://leetcode.com/problems/boats-to-save-people/
* You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two people at the same time, provided... | 0 | Kotlin | 0 | 1 | 748812d291e5c2df64c8620c96189403b19e12dd | 1,618 | kotlin-demo-code | MIT License |
src/main/kotlin/aoc2023/day15/day15Solver.kt | Advent-of-Code-Netcompany-Unions | 726,531,711 | false | {"Kotlin": 94973} | package aoc2023.day15
import lib.*
suspend fun main() {
setupChallenge().solveChallenge()
}
fun setupChallenge(): Challenge<List<String>> {
return setup {
day(15)
year(2023)
//input("example.txt")
parser {
it.readText().trim().split(",")
}
partOn... | 0 | Kotlin | 0 | 0 | a77584ee012d5b1b0d28501ae42d7b10d28bf070 | 1,792 | AoC-2023-DDJ | MIT License |
src/main/kotlin/cc/stevenyin/leetcode/_0003_LengthOfLongestSubstring.kt | StevenYinKop | 269,945,740 | false | {"Kotlin": 107894, "Java": 9565} | package cc.stevenyin.leetcode
/**
* https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
* Given a string s, find the length of the longest substring without repeating characters.
*
*
* Example 1:
* Input: s = "abcabcbb"
* Output: 3
* Explanation: The answer is "abc", with... | 0 | Kotlin | 0 | 1 | 748812d291e5c2df64c8620c96189403b19e12dd | 2,370 | kotlin-demo-code | MIT License |
src/Day01.kt | jaldhar | 573,188,501 | false | {"Kotlin": 14191} | fun main() {
// convert the entries in [input[ to integers, provide the total calories
// for each elf and return the top [upto] elves
fun countCalories(input: List<String>, upto: Int): Int {
val elves = mutableMapOf<Int, Int>()
var elf = 1
elves[elf] = 0
for (line in input)... | 0 | Kotlin | 0 | 0 | b193df75071022cfb5e7172cc044dd6cff0f6fdf | 1,256 | aoc2022-kotlin | Apache License 2.0 |
src/Day04.kt | D000L | 575,350,411 | false | {"Kotlin": 23716} | fun main() {
fun part1(input: List<String>): Int {
return input.map {
val (a, b, x, y) = it.split(",", "-").map { it.toInt() }
val ra = IntRange(a, b)
val rb = IntRange(x, y)
if (ra.all { it in rb } || rb.all { it in ra }) 1
else 0
}.sumO... | 0 | Kotlin | 0 | 0 | b733a4f16ebc7b71af5b08b947ae46afb62df05e | 735 | adventOfCode | Apache License 2.0 |
src/Day06.kt | Misano9699 | 572,108,457 | false | null | fun main() {
fun isUnique(substring: String, markerLength: Int): Boolean {
val setOfStrings = mutableSetOf<Char>()
substring.forEach {
setOfStrings.add(it)
}
return setOfStrings.size == markerLength
}
fun process(input: List<String>, markerLength: Int): String {... | 0 | Kotlin | 0 | 0 | adb8c5e5098fde01a4438eb2a437840922fb8ae6 | 1,327 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ConstrainedSubsequenceSum.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 | 3,548 | kotlab | Apache License 2.0 |
2023/src/main/kotlin/com/github/akowal/aoc/Day02.kt | akowal | 573,170,341 | false | {"Kotlin": 36572} | package com.github.akowal.aoc
import java.io.File
class Day02(input: File) : Problem<Int> {
private val games = loadGames(input)
override fun solve1(): Int {
return games
.filter { game -> game.grabs.all { it.r <= 12 && it.g <= 13 && it.b <= 14 } }
.sumOf { it.n }
}
o... | 0 | Kotlin | 0 | 0 | 02e52625c1c8bd00f8251eb9427828fb5c439fb5 | 1,475 | advent-of-kode | Creative Commons Zero v1.0 Universal |
src/Day11.kt | dmarmelo | 573,485,455 | false | {"Kotlin": 28178} | private typealias Operation = (old: Long) -> Long
private data class MonkeyTest(
val value: Long,
val ifTrue: Int,
val ifFalse: Int
) {
operator fun invoke(value: Long) =
if (value % this.value == 0L) ifTrue else ifFalse
}
private data class Monkey(
val id: Int,
val items: List<Long>,
... | 0 | Kotlin | 0 | 0 | 5d3cbd227f950693b813d2a5dc3220463ea9f0e4 | 3,766 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/2022/Day23_2022.kt | regob | 575,917,627 | false | {"Kotlin": 50757, "Python": 46520, "Shell": 430} | fun main() {
data class P(val x: Int, val y: Int)
val init = mutableSetOf<P>()
readInput(23).trim()
.lines().withIndex().forEach {
it.value.withIndex().forEach {itc ->
if (itc.value == '#') init.add(P(itc.index, it.index))
}
}
var e = init.toMutabl... | 0 | Kotlin | 0 | 0 | cf49abe24c1242e23e96719cc71ed471e77b3154 | 2,109 | adventofcode | Apache License 2.0 |
src/test/kotlin/nl/dirkgroot/adventofcode/year2022/Day20Test.kt | dirkgroot | 317,968,017 | false | {"Kotlin": 187862} | package nl.dirkgroot.adventofcode.year2022
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import nl.dirkgroot.adventofcode.util.input
import nl.dirkgroot.adventofcode.util.invokedWith
import kotlin.math.abs
private fun solution1(input: String) = parse(input, 1L).let { file ->
file.... | 1 | Kotlin | 1 | 1 | ffdffedc8659aa3deea3216d6a9a1fd4e02ec128 | 2,809 | adventofcode-kotlin | MIT License |
src/main/kotlin/Day10.kt | ueneid | 575,213,613 | false | null | class Day10(inputs: List<String>) {
private val commandSets = parse(inputs)
private fun parse(inputs: List<String>): List<CommandSet> {
return inputs.asSequence().map { line ->
line.split(" ").let {
CommandSet(Command.valueOf(it[0].uppercase()), it.getOrElse(1) { "0" }.toInt... | 0 | Kotlin | 0 | 0 | 743c0a7adadf2d4cae13a0e873a7df16ddd1577c | 2,046 | adventcode2022 | MIT License |
src/test/kotlin/ch/ranil/aoc/aoc2022/Day02.kt | stravag | 572,872,641 | false | {"Kotlin": 234222} | package ch.ranil.aoc.aoc2022
import ch.ranil.aoc.aoc2022.Day02.Outcome.*
import ch.ranil.aoc.aoc2022.Day02.Shape.*
import ch.ranil.aoc.AbstractDay
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
object Day02 : AbstractDay() {
@Test
fun tests() {
assertEquals(15, compute1(testInput))
... | 0 | Kotlin | 1 | 0 | dbd25877071cbb015f8da161afb30cf1968249a8 | 2,646 | aoc | Apache License 2.0 |
src/day03/Day03Answer1.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 {
return input.map { rucksack ->
rucksack.substring(0 until rucksack.length / 2) to rucksack.substring(rucksack.length / 2)... | 0 | Kotlin | 0 | 0 | 967812138a7ee110a63e1950cae9a799166a6ba8 | 1,528 | advent-of-code-2022 | Apache License 2.0 |
src/main/java/com/barneyb/aoc/aoc2022/day13/DistressSignal.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2022.day13
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toSlice
import com.barneyb.util.Stack
fun main() {
Solver.benchmark(
::parse,
::partOne, // 4809
::decoderKey, // 22600
)
}
typealias Packet = List<*> // List<Int | Packet>
internal f... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 2,883 | aoc-2022 | MIT License |
src/main/kotlin/days/Day21.kt | andilau | 429,557,457 | false | {"Kotlin": 103829} | package days
import days.Day21.Item.ItemType
import kotlin.math.max
@AdventOfCodePuzzle(
name = "RPG Simulator 20XX",
url = "https://adventofcode.com/2015/day/21",
date = Date(day = 21, year = 2015)
)
class Day21(val input: List<String>) : Puzzle {
private val items = parseItems()
private val boss... | 0 | Kotlin | 0 | 0 | 55932fb63d6a13a1aa8c8df127593d38b760a34c | 4,593 | advent-of-code-2015 | Creative Commons Zero v1.0 Universal |
src/Day01.kt | paulgrugnale | 573,105,050 | false | {"Kotlin": 6378} | fun main() {
fun part1(input: List<String>): Int {
var answer = 0
var runningTotal = 0
input.forEach {
if (it.isNotEmpty()) {
runningTotal += it.toInt()
} else {
answer = answer.coerceAtLeast(runningTotal)
runningTotal ... | 0 | Kotlin | 0 | 0 | e62edc817a8b75e401d6c8a0a66243d009c31fbd | 1,060 | advent2022 | Apache License 2.0 |
src/Day09.kt | GreyWolf2020 | 573,580,087 | false | {"Kotlin": 32400} | import java.lang.Math.abs
fun main() {
fun part1(headKnotMotionsData: List<String>): Int {
val tail = Knot("tail")
val head = Knot("head")
tail `join to follow` head
headKnotMotionsData
.map { it.split(" ") }
.forEach {
val direction = it.fir... | 0 | Kotlin | 0 | 0 | 498da8861d88f588bfef0831c26c458467564c59 | 6,132 | aoc-2022-in-kotlin | Apache License 2.0 |
2020/src/main/kotlin/org/suggs/adventofcode/Day07HandyHaversacks.kt | suggitpe | 321,028,552 | false | {"Kotlin": 156836} | package org.suggs.adventofcode
class Day07HandyHaversacks {
companion object {
data class BagRule(val parent: String, val number: Int, val child: String)
fun buildRulesFromRulesSet(rules: List<String>): List<BagRule> {
fun createRuleFrom(parent: String, number: Int, contains: String... | 0 | Kotlin | 0 | 0 | 9485010cc0ca6e9dff447006d3414cf1709e279e | 2,593 | advent-of-code | Apache License 2.0 |
codeforces/vk2022/qual/d1.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.vk2022.qual
const val VALUES = "6789TJQKA"
const val SUITS = "CDSH"
val INIT = VALUES.indexOf('9')
fun main() {
val totalCards = VALUES.length * SUITS.length
val allCardsList = (0 until totalCards).toList()
val aliceList = readStrings().map { parseCard(it) }
val bobList = allCardsList - aliceLi... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,886 | competitions | The Unlicense |
solutions/aockt/y2021/Y2021D21.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
object Y2021D21 : Solution {
/**
* Simulates a practice round of the Dirac Dice game with a 100-sided deterministic die and a winning score of 1000.
* @return The number of times the dice was rolled, and the scores of each player.
*/... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 4,009 | advent-of-code-kotlin-solutions | The Unlicense |
src/Day04.kt | zhtk | 579,137,192 | false | {"Kotlin": 9893} | data class Assignment(val start: Int, val end: Int)
fun main() {
val input = readInput("Day04").map {
it.split(',').map {
val range = it.split('-').map { it.toInt() }
Assignment(range[0], range[1])
}
}
input.count { assignmentsContained(it[0], it[1]) }.println()
... | 0 | Kotlin | 0 | 0 | bb498e93f9c1dd2cdd5699faa2736c2b359cc9f1 | 1,045 | aoc2022 | Apache License 2.0 |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[395]至少有 K 个重复字符的最长子串.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给你一个字符串 s 和一个整数 k ,请你找出 s 中的最长子串, 要求该子串中的每一字符出现次数都不少于 k 。返回这一子串的长度。
//
//
//
// 示例 1:
//
//
//输入:s = "aaabb", k = 3
//输出:3
//解释:最长子串为 "aaa" ,其中 'a' 重复了 3 次。
//
//
// 示例 2:
//
//
//输入:s = "ababbc", k = 2
//输出:5
//解释:最长子串为 "ababb" ,其中 'a' 重复了 2 次, 'b' 重复了 3 次。
//
//
//
// 提示:
//
//
// 1 <= s.length <= 104
/... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,348 | MyLeetCode | Apache License 2.0 |
src/Day22.kt | abeltay | 572,984,420 | false | {"Kotlin": 91982, "Shell": 191} | fun main() {
val right = 0
val down = 1
val left = 2
val up = 3
fun parseDirections(input: String): MutableList<String> {
val output = mutableListOf<String>()
var buffer = ""
for (it in input) {
if (it.isDigit()) {
buffer += it
} else ... | 0 | Kotlin | 0 | 0 | a51bda36eaef85a8faa305a0441efaa745f6f399 | 4,036 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch0/Problem6.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch0
import dev.bogwalk.util.maths.gaussSum
/**
* Problem 6: Sum Square Difference
*
* https://projecteuler.net/problem=6
*
* Goal: Find the absolute difference between the sum of the squares & the square of the sum
* of the first N natural numbers.
*
* Constraints: 1 <= N <= 1e4
*
* e... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 1,820 | project-euler-kotlin | MIT License |
src/day03/Day03.kt | spyroid | 433,555,350 | false | null | package day03
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import readInput
enum class Type(val order: Int) {
OXY(1), CO2(-1)
}
fun main() = runBlocking {
fun part1(seq: List<String>): Int {
val counts = IntArray(seq.first().length) {
idx -> if (seq.sumOf { (... | 0 | Kotlin | 0 | 0 | 939c77c47e6337138a277b5e6e883a7a3a92f5c7 | 1,542 | Advent-of-Code-2021 | Apache License 2.0 |
src/Day03.kt | gojoel | 573,543,233 | false | {"Kotlin": 28426} | fun main() {
val input = readInput("03")
// val input = readInput("03_test")
val types = ('a'..'z').toMutableList()
types.addAll(('A'..'Z'))
fun getPriority(char: Char?) : Int {
return char?.let {
types.indexOf(it) + 1 // offset index from 0
} ?: run {
0
... | 0 | Kotlin | 0 | 0 | 0690030de456dad6dcfdcd9d6d2bd9300cc23d4a | 1,935 | aoc-kotlin-22 | Apache License 2.0 |
src/Day06.kt | stcastle | 573,145,217 | false | {"Kotlin": 24899} | import java.util.*
class SizedQueue<T>(val maxSize: Int) : LinkedList<T>() {
override fun add(element: T): Boolean {
if (super.size >= maxSize) {
super.remove()
}
return super.add(element)
}
}
fun <T> SizedQueue<T>.allDifferent(): Boolean {
// For this use case, return false if size is not max... | 0 | Kotlin | 0 | 0 | 746809a72ea9262c6347f7bc8942924f179438d5 | 1,256 | aoc2022 | Apache License 2.0 |
src/Day04.kt | tsdenouden | 572,703,357 | false | {"Kotlin": 8295} | fun main() {
fun List<Int>.swap(index1: Int, index2: Int): MutableList<Int> {
val copy = this.toMutableList()
val tmp = copy[index1]
copy[index1] = copy[index2]
copy[index2] = tmp
return copy
}
fun part1(input: List<String>): Int {
var contains = 0
i... | 0 | Kotlin | 0 | 0 | 68982ebffc116f3b49a622d81e725c8ad2356fed | 1,375 | aoc-2022-kotlin | Apache License 2.0 |
src/main/java/com/barneyb/aoc/aoc2020/day01/ReportRepair.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2020.day01
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toLong
fun main() {
Solver.benchmark(
::parse,
::productOfTwo,
::productOfThree,
)
}
internal fun parse(input: String) =
input.trim()
.lines()
.map(CharSequence::to... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 935 | aoc-2022 | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.