path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/main/kotlin/Calculator.kt | alebedev | 573,733,821 | false | {"Kotlin": 82424} | fun main() = Calculator.solve()
private object Calculator {
fun solve() {
val expressions = readInput()
println("Part 1: root value ${calcValue(expressions, "root")}")
println("Part 2, humn requires value ${matchValuesAt(expressions, "root")}")
}
private fun readInput(): Map<String... | 0 | Kotlin | 0 | 0 | d6ba46bc414c6a55a1093f46a6f97510df399cd1 | 4,831 | aoc2022 | MIT License |
src/twentytwo/Day12.kt | Monkey-Matt | 572,710,626 | false | {"Kotlin": 73188} | package twentytwo
/**
* I used brute force (marking the route on the input) to solve this one initially :|
* Took just under an hour. I really didn't know how to solve it in code
*/
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInputLines("Day12_test")... | 1 | Kotlin | 0 | 0 | 600237b66b8cd3145f103b5fab1978e407b19e4c | 1,586 | advent-of-code-solutions | Apache License 2.0 |
2022/kotlin/app/src/main/kotlin/day05/Day05.kt | jghoman | 726,228,039 | false | {"Kotlin": 15309, "Rust": 14555, "Scala": 1804, "Shell": 737} | package day05
import java.util.ArrayDeque
import kotlin.math.ceil
typealias Stacks = Array<ArrayDeque<Char>>
data class MoveInstruction(val quantity: Int, val from: Int, val to: Int)
fun parseMove(s: String): MoveInstruction {
val parts = s.split(" ")
return MoveInstruction(parts[1].toInt(), parts[3].toInt... | 0 | Kotlin | 0 | 0 | 2eb856af5d696505742f7c77e6292bb83a6c126c | 2,923 | aoc | Apache License 2.0 |
src/year2021/12/Day12.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2021.`12`
import readInput
private sealed class Place {
data object Start : Place() {
override fun toString(): String = "start"
}
data class LargePlace(val key: String) : Place() {
override fun toString(): String = key
}
data class SmallPlace(val key: String) : Pla... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 4,361 | KotlinAdventOfCode | Apache License 2.0 |
src/main/kotlin/aoc2022/Day11.kt | davidsheldon | 565,946,579 | false | {"Kotlin": 161960} | package aoc2022
import utils.InputUtils
sealed interface Operation {
fun apply(old: Long): Long
}
object Square : Operation {
override fun apply(old: Long): Long {
return old * old
}
}
class Add(private val add: Int) : Operation {
override fun apply(old: Long): Long {
return old + ad... | 0 | Kotlin | 0 | 0 | 5abc9e479bed21ae58c093c8efbe4d343eee7714 | 4,035 | aoc-2022-kotlin | Apache License 2.0 |
src/Day03.kt | tstellfe | 575,291,176 | false | {"Kotlin": 8536} | fun main() {
val alphabetLow = 'a'..'z'
val alphabetBig = 'A'..'Z'
val alphabet = alphabetLow.toMutableList().also { it.addAll(alphabetBig.toList()) }
fun part1(input: List<String>): Int {
return input.sumOf { backpack ->
val half = backpack.length / 2
val comp1 = backpack.substring(0 until hal... | 0 | Kotlin | 0 | 0 | e100ba705c8e2b83646b172d6407475c27f02eff | 1,105 | adventofcode-2022 | Apache License 2.0 |
2023/day04-25/src/main/kotlin/Day07.kt | CakeOrRiot | 317,423,901 | false | {"Kotlin": 62169, "Python": 56994, "C#": 20675, "Rust": 10417} | import java.io.File
class Day07 {
fun solve1() {
var hands = File("inputs/7.txt").inputStream().bufferedReader().lineSequence().map { x ->
val split = x.split(' ')
val highCardsMapping = mapOf('A' to 14, 'K' to 13, 'Q' to 12, 'J' to 11, 'T' to 10)
val cards = split[0].... | 0 | Kotlin | 0 | 0 | 8fda713192b6278b69816cd413de062bb2d0e400 | 3,662 | AdventOfCode | MIT License |
src/Day14.kt | vjgarciag96 | 572,719,091 | false | {"Kotlin": 44399} | import kotlin.math.abs
fun main() {
data class Point(val x: Int, val y: Int)
fun part1(input: List<String>): Int {
val rocks = input.flatMap { line ->
val rockPathPoints = line.split(" -> ").map { rawPoint ->
val (x, y) = rawPoint.split(",")
Point(x.toInt(),... | 0 | Kotlin | 0 | 0 | ee53877877b21166b8f7dc63c15cc929c8c20430 | 4,350 | advent-of-code-2022 | Apache License 2.0 |
src/Day24.kt | wgolyakov | 572,463,468 | false | null | fun main() {
class Cell {
val obstacles = mutableListOf<Char>()
var distance = -1
}
class Point(val x: Int, val y: Int, val t: Int)
fun parse(input: List<String>): List<List<Cell>> {
val map = List(input.size) { List(input[0].length) { Cell() } }
for (y in input.indices)
for (x in input[y].indices)
... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 2,916 | advent-of-code-2022 | Apache License 2.0 |
src/adventofcode/blueschu/y2017/day20/solution.kt | blueschu | 112,979,855 | false | null | package adventofcode.blueschu.y2017.day20
import java.io.File
import kotlin.math.abs
import kotlin.test.assertEquals
val input: List<String> by lazy {
File("resources/y2017/day20.txt")
.bufferedReader()
.use { r -> r.readLines() }
}
fun main(args: Array<String>) {
println("Part 1: ${part1(inp... | 0 | Kotlin | 0 | 0 | 9f2031b91cce4fe290d86d557ebef5a6efe109ed | 2,771 | Advent-Of-Code | MIT License |
src/main/kotlin/aoc2020/ex13.kt | noamfree | 433,962,392 | false | {"Kotlin": 93533} | import kotlin.math.max
fun main() {
//part1()
part2()
}
private fun part2() {
val input = "7,13,x,x,59,x,31,19"
// require(findFirstTimeFor("17,x,13,19") == 3417L)
// require(findFirstTimeFor("7,13,x,x,59,x,31,19") == 1068781L)
// require(findFirstTimeFor("67,7,59,61") == 754018L)
// require(f... | 0 | Kotlin | 0 | 0 | 566cbb2ef2caaf77c349822f42153badc36565b7 | 4,208 | AOC-2021 | MIT License |
src/main/kotlin/fp/algorithm/programmers_42785.kt | treetory | 238,101,549 | true | {"Kotlin": 312666} | package fp.algorithm
import fp.kotlin.example.head
import fp.kotlin.example.tail
fun main() {
val answer = make(arrayOf(1,5,2,6,3,7,4), arrayOf(arrayOf(2,5,3), arrayOf(4,4,1), arrayOf(1,7,3)), listOf())
answer.forEach { e -> println(e) }
}
// 자르고
private fun cut(start: Int, end: Int, arr: Array<Int>): List<I... | 0 | Kotlin | 0 | 0 | a4f323b1e6ca24644185e834eed17cf447baee78 | 1,212 | fp-kotlin-example | MIT License |
src/Day19.kt | wgolyakov | 572,463,468 | false | null | typealias Cost = MutableList<Int>
fun main() {
fun cost(ore: Int, clay: Int, obsidian: Int, geode: Int = 0) = mutableListOf(ore, clay, obsidian, geode)
class State(val t: Int = 0,
val resources: Cost = cost(0, 0, 0, 0),
val robots: Cost = cost(1, 0, 0, 0))
class Blueprint(val num: Int, val robotCosts: Lis... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 3,594 | advent-of-code-2022 | Apache License 2.0 |
src/day24.kt | miiila | 725,271,087 | false | {"Kotlin": 77215} | import java.io.File
import kotlin.system.exitProcess
private const val DAY = 24
fun main() {
if (!File("./day${DAY}_input").exists()) {
downloadInput(DAY)
println("Input downloaded")
exitProcess(0)
}
val transformer = { x: String ->
x.split(" @ ").let {
Pair(
... | 0 | Kotlin | 0 | 1 | 1cd45c2ce0822e60982c2c71cb4d8c75e37364a1 | 2,797 | aoc2023 | MIT License |
src/Day03.kt | kmes055 | 577,555,032 | false | {"Kotlin": 35314} | fun main() {
fun calcPriority(c: Char) = when {
c.isUpperCase() -> c - 'A' + 27
c.isLowerCase() -> c - 'a' + 1
else -> 0
}
fun part1(input: List<String>): Int {
return input.sumOf {
val size = it.length / 2
it.take(size)
.toSet()
... | 0 | Kotlin | 0 | 0 | 84c2107fd70305353d953e9d8ba86a1a3d12fe49 | 860 | advent-of-code-kotlin | Apache License 2.0 |
src/Day03.kt | dmdrummond | 573,289,191 | false | {"Kotlin": 9084} | fun main() {
fun priorityForCharacter(char: Char): Int {
val code = char.code
return if (code > 96 ) {
code - 96
} else {
code - 38
}
}
fun splitAndFindCommonCharacter(input: String): Char {
val first = input.substring(0 until input.length / ... | 0 | Kotlin | 0 | 0 | 2493256124c341e9d4a5e3edfb688584e32f95ec | 1,370 | AoC2022 | Apache License 2.0 |
leetcode/src/main/kotlin/com/artemkaxboy/leetcode/p08/Leet886.kt | artemkaxboy | 513,636,701 | false | {"Kotlin": 547181, "Java": 13948} | package com.artemkaxboy.leetcode.p08
import com.artemkaxboy.leetcode.LeetUtils.toIntArray
import java.util.*
import kotlin.system.measureTimeMillis
class Leet886 {
class Solution {
fun possibleBipartition(n: Int, dislikes: Array<IntArray>): Boolean {
val dislikeMap = HashMap<Int, LinkedList... | 0 | Kotlin | 0 | 0 | 516a8a05112e57eb922b9a272f8fd5209b7d0727 | 2,684 | playground | MIT License |
src/Day05.kt | befrvnk | 574,229,637 | false | {"Kotlin": 15788} | data class Movement(
val count: Int,
val from: Int,
val to: Int,
)
fun main() {
fun part1(input: List<String>): String {
val separatorLineIndex = input.indexOfFirst { it.isEmpty() }
val stackLines = input.subList(0, separatorLineIndex - 1)
val stackNames = input[separatorLineInd... | 0 | Kotlin | 0 | 0 | 68e5dd5656c052d8c8a2ea9e03c62f4cd2438dd7 | 2,698 | aoc-2022-kotlin | Apache License 2.0 |
src/day04/Day04.kt | molundb | 573,623,136 | false | {"Kotlin": 26868} | package day04
import readInput
fun main() {
val input = readInput(parent = "src/day04", name = "Day04_input")
println(solvePartOne(input))
println(solvePartTwo(input))
}
private fun solvePartOne(input: List<String>): Int = solve(input, partOneOverlapCheck())
private fun solvePartTwo(input: List<String>)... | 0 | Kotlin | 0 | 0 | a4b279bf4190f028fe6bea395caadfbd571288d5 | 1,499 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/io/matrix/WallsAndGates.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.matrix
import io.utils.runTests
// https://leetcode.com/problems/walls-and-gates/
class WallsAndGates {
fun execute(input: Array<IntArray>) {
if (input.isEmpty() || input.first().isEmpty()) return
val gates = mutableListOf<Pair<Int, Int>>()
input.forEachIndexed { row, column ->
column.... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 2,846 | coding | MIT License |
src/Day15.kt | Allagash | 572,736,443 | false | {"Kotlin": 101198} | import java.io.File
import kotlin.math.abs
import kotlin.math.min
import kotlin.math.max
// Advent of Code 2022, Day 15, Beacon Exclusion Zone
typealias Pt = Pair<Int, Int>
fun main() {
// Manhattan distance
fun Pt.distance(other: Pt) = abs(this.first - other.first) + abs(this.second - other.second)
fu... | 0 | Kotlin | 0 | 0 | 8d5fc0b93f6d600878ac0d47128140e70d7fc5d9 | 4,863 | AdventOfCode2022 | Apache License 2.0 |
src/Day04.kt | gillyobeast | 574,413,213 | false | {"Kotlin": 27372} | import utils.appliedTo
import utils.readInput
fun main() {
fun toPair(it: String, delimiter: String): Pair<String, String> {
val halves = it.split(delimiter)
return halves[0] to halves[1]
}
fun Pair<String, String>.toRange(): IntRange = first.toInt()..second.toInt()
fun String.toRan... | 0 | Kotlin | 0 | 0 | 8cdbb20c1a544039b0e91101ec3ebd529c2b9062 | 1,534 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/hopkins/aoc/day13/main.kt | edenrox | 726,934,488 | false | {"Kotlin": 88215} | package com.hopkins.aoc.day13
import java.io.File
const val debug = false
const val part = 2
/** Advent of Code 2023: Day 13 */
fun main() {
// Read the file input
val lines: List<String> = File("input/input13.txt").readLines()
if (debug) {
println("Num lines: ${lines.size}")
}
// Parse ... | 0 | Kotlin | 0 | 0 | 45dce3d76bf3bf140d7336c4767e74971e827c35 | 2,688 | aoc2023 | MIT License |
src/main/kotlin/com/colinodell/advent2021/Day04.kt | colinodell | 433,864,377 | true | {"Kotlin": 111114} | package com.colinodell.advent2021
class Day04 (val input: String) {
fun solvePart1(): Int {
val result = BingoGame(input).findWinner().first()
return result.number * result.board.sumOfUnusedSquares()
}
fun solvePart2(): Int {
val result = BingoGame(input).findWinner().last()
... | 0 | Kotlin | 0 | 1 | a1e04207c53adfcc194c85894765195bf147be7a | 2,555 | advent-2021 | Apache License 2.0 |
src/Day15.kt | acrab | 573,191,416 | false | {"Kotlin": 52968} | import com.google.common.truth.Truth.assertThat
import java.lang.Integer.max
import java.lang.Integer.min
import kotlin.math.abs
data class Sensor(val sensorX: Int, val sensorY: Int, val beaconX: Int, val beaconY: Int)
fun String.toSensor(): Sensor {
val parts = split(" ")
return Sensor(
sensorX = par... | 0 | Kotlin | 0 | 0 | 0be1409ceea72963f596e702327c5a875aca305c | 5,210 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | SimoneStefani | 572,915,832 | false | {"Kotlin": 33918} | fun main() {
fun computeScoreFromGame(game: String) = when (game) {
"A X" -> 1 + 3 // rock x rock
"A Y" -> 2 + 6 // rock x paper
"A Z" -> 3 + 0 // rock x scissors
"B X" -> 1 + 0 // paper x rock
"B Y" -> 2 + 3 // paper x paper
"B Z" -> 3 + 6 // paper x scissors
... | 0 | Kotlin | 0 | 0 | b3244a6dfb8a1f0f4b47db2788cbb3d55426d018 | 1,473 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/g1501_1600/s1594_maximum_non_negative_product_in_a_matrix/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1501_1600.s1594_maximum_non_negative_product_in_a_matrix
// #Medium #Array #Dynamic_Programming #Matrix
// #2023_06_14_Time_224_ms_(100.00%)_Space_35_MB_(100.00%)
class Solution {
private class Tuple(var max: Long, var min: Long)
fun maxProductPath(grid: Array<IntArray?>?): Int {
// DP
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,832 | LeetCode-in-Kotlin | MIT License |
src/2022/Day21.kt | ttypic | 572,859,357 | false | {"Kotlin": 94821} | package `2022`
import readInput
fun main() {
fun calculate(phrase: MonkeyPhrase, nameToResult: MutableMap<String, Long>, nameToPhrase: Map<String, MonkeyPhrase>): Long {
if (nameToResult.contains(phrase.name)) {
return nameToResult[phrase.name]!!
}
when (phrase) {
... | 0 | Kotlin | 0 | 0 | b3e718d122e04a7322ed160b4c02029c33fbad78 | 8,497 | aoc-2022-in-kotlin | Apache License 2.0 |
kotlin/src/Day02.kt | ekureina | 433,709,362 | false | {"Kotlin": 65477, "C": 12591, "Rust": 7560, "Makefile": 386} | import java.lang.IllegalArgumentException
import java.lang.Long.parseLong
data class PositionWithAim(val position: Long, val depth: Long, val aim: Long)
data class Position(val position: Long, val depth: Long)
sealed class Command(protected val magnitude: Long) {
abstract fun move(position: Position): Position
... | 0 | Kotlin | 0 | 1 | 391d0017ba9c2494092d27d22d5fd9f73d0c8ded | 3,107 | aoc-2021 | MIT License |
src/Day07.kt | arhor | 572,349,244 | false | {"Kotlin": 36845} | fun main() {
val root = readInput {}.let(::buildFilesystemTree)
val size = root.size
println("Part 1: " + root.allDirs.map { it.size }.filter { it <= 100_000 }.sum())
println("Part 2: " + root.allDirs.map { it.size }.sorted().first { TOTAL - (size - it) >= NEEDS })
}
private fun buildFilesystemTree(in... | 0 | Kotlin | 0 | 0 | 047d4bdac687fd6719796eb69eab2dd8ebb5ba2f | 1,926 | aoc-2022-in-kotlin | Apache License 2.0 |
src/questions/LongestAbsoluteFilePath.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
/**
* Suppose we have a file system that stores both files and directories.
*
* <img src="https://assets.leetcode.com/uploads/2020/08/28/mdir.jpg" height="150" width="150"/>
* Every file and directory has a unique absolute path in the... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,731 | algorithms | MIT License |
src/day03/Day03.kt | jacobprudhomme | 573,057,457 | false | {"Kotlin": 29699} | import java.io.File
fun main() {
fun readInput(name: String) = File("src/day03", name)
.readLines()
fun getItemPriority(item: Char): Int =
if (item.isLowerCase()) {
item.code - 96
} else {
item.code - 38
}
fun part1(input: List<String>): Int {
... | 0 | Kotlin | 0 | 1 | 9c2b080aea8b069d2796d58bcfc90ce4651c215b | 1,583 | advent-of-code-2022 | Apache License 2.0 |
src/adventOfCode/day13Problem.kt | cunrein | 159,861,371 | false | null | package adventOfCode
import kotlin.system.measureTimeMillis
data class Cart(var x: Int, var y: Int, var dir: Char, var isDead: Boolean = false) {
var turnCount = 0
fun move(trackSection: Char) {
when (trackSection) {
'+' -> makeTurn()
'\\' -> if (dir == '<' || dir == '>') right... | 0 | Kotlin | 0 | 0 | 3488ccb200f993a84f1e9302eca3fe3977dbfcd9 | 27,109 | ProblemOfTheDay | Apache License 2.0 |
src/main/kotlin/day17.kt | Gitvert | 725,292,325 | false | {"Kotlin": 97000} | fun day17 (lines: List<String>) {
val map = parseFactoryMap(lines)
val maxX = map[0].indices.last
val maxY = map.indices.last
val leastHeatPart1 = dijkstra(map, maxX, maxY, false)
println("Day 17 part 1: $leastHeatPart1")
val leastHeatPart2 = dijkstra(map, maxX, maxY, true)
println("Da... | 0 | Kotlin | 0 | 0 | f204f09c94528f5cd83ce0149a254c4b0ca3bc91 | 3,441 | advent_of_code_2023 | MIT License |
src/main/kotlin/com/anahoret/aoc2022/day22/BoardSolver.kt | mikhalchenko-alexander | 584,735,440 | false | null | package com.anahoret.aoc2022.day22
import com.anahoret.aoc2022.calculateEndIndex
import java.lang.RuntimeException
class BoardSolver(private val input: String) {
fun solve(): List<Int> {
val (board, path) = parseInputToBoard(input)
val startRow = 1
val startCol = board.rows.getValue(star... | 0 | Kotlin | 0 | 0 | b8f30b055f8ca9360faf0baf854e4a3f31615081 | 5,550 | advent-of-code-2022 | Apache License 2.0 |
src/Day02/Day02.kt | NST-d | 573,224,214 | false | null | package Day02
import utils.*
enum class RPS(val score: Int){
ROCK(1),
PAPER(2),
SCISSOR (3),
}
fun winScore(opponent: RPS, player: RPS): Int {
if(opponent == player) return 3
if((opponent.ordinal+1)%3 == player.ordinal ) return 6
return 0
}
fun getRPS(input:Char, base:Char) =
when( input... | 0 | Kotlin | 0 | 0 | c4913b488b8a42c4d7dad94733d35711a9c98992 | 1,436 | aoc22 | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2022/Day24.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2022
import se.saidaspen.aoc.util.*
fun main() = Day24.run()
object Day24 : Day(2022, 24) {
val map = toMap(input).entries.associate { it.key to it.value.toString() }
private val yMax = map.entries.maxOf { it.key.y }
private val xMax = map.entries.maxOf { it.key.x }
priva... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 3,549 | adventofkotlin | MIT License |
app/src/y2021/day09/Day09SmokeBasin.kt | henningBunk | 432,858,990 | false | {"Kotlin": 124495} | package y2021.day09
import common.*
import common.annotations.AoCPuzzle
typealias CaveMap = List<MutableList<Int>>
typealias CaveQueue = MutableList<Pair<Int, Int>>
fun main(args: Array<String>) {
Day09SmokeBasin().solveThem()
}
@AoCPuzzle(2021, 9)
class Day09SmokeBasin : AocSolution {
override val answers ... | 0 | Kotlin | 0 | 0 | 94235f97c436f434561a09272642911c5588560d | 2,712 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem1498/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1498
/**
* LeetCode page: [1498. Number of Subsequences That Satisfy the Given Sum Condition](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/);
*/
class Solution {
/* Complexity:
* Time O(NLogN) and Space O(N) where N is the si... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,357 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2021/2021-13.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2021
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputText
fun main() {
val input = readInputText(2021, "13-input")
val test1 = readInputText(2021, "13-test1")
prin... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 2,161 | advent-of-code | MIT License |
src/main/kotlin/day23.kt | gautemo | 572,204,209 | false | {"Kotlin": 78294} | import shared.Point
import shared.getText
fun main() {
val input = getText("day23.txt")
println(day23A(input))
println(day23B(input))
}
fun day23A(input: String): Int {
val elves = toElves(input)
val proposeOrder = mutableListOf('N', 'S', 'W', 'E')
repeat(10) {
moveElves(elves, propose... | 0 | Kotlin | 0 | 0 | bce9feec3923a1bac1843a6e34598c7b81679726 | 3,606 | AdventOfCode2022 | MIT License |
src/main/kotlin/pl/klemba/aoc/day5/Main.kt | aklemba | 726,935,468 | false | {"Kotlin": 16373} | package pl.klemba.aoc.day5
import java.io.File
fun main() {
// ----- PART 1 -----
val almanac = File(inputPath)
.readLines()
val seeds: List<Long> = getSeeds(almanac)
println("Seeds: $seeds")
val mappings = getMappings(almanac)
mappings
.forEach { println(it) }
seeds
.map { seed -> seed.m... | 0 | Kotlin | 0 | 1 | 2432d300d2203ff91c41ffffe266e19a50cca944 | 3,382 | adventOfCode2023 | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/max_distance/MaxDistance.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.max_distance
import nonstdlib.tail
import datsok.shouldEqual
import org.junit.Test
/**
* https://leetcode.com/discuss/interview-question/350363/Google-or-OA-2018-or-Max-Distance
*/
class MaxDistanceTests {
@Test fun examples() {
maxDistance("1011000", "1011110") shouldEqual... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,637 | katas | The Unlicense |
src/exercises/Day09.kt | Njko | 572,917,534 | false | {"Kotlin": 53729} | // ktlint-disable filename
package exercises
import readInput
import kotlin.math.pow
import kotlin.math.sqrt
data class Vec2(val x: Int, val y: Int)
operator fun Vec2.plus(minusVec2: Vec2): Vec2 = Vec2(this.x + minusVec2.x, this.y + minusVec2.y)
operator fun Vec2.minus(minusVec2: Vec2): Vec2 = Vec2(this.x - minusVec... | 0 | Kotlin | 0 | 2 | 68d0c8d0bcfb81c183786dfd7e02e6745024e396 | 3,718 | advent-of-code-2022 | Apache License 2.0 |
src/day08/Day08.kt | lpleo | 572,702,403 | false | {"Kotlin": 30960} | package day08
import readInput
import kotlin.math.max
private const val FILES_DAY_08_TEST = "files/Day08_test"
private const val FILES_DAY_08 = "files/Day08"
fun main() {
fun part1(input: List<String>): Int {
val wood = createWood(input)
var counter = 0;
for (i in wood.indices) {
... | 0 | Kotlin | 0 | 0 | 115aba36c004bf1a759b695445451d8569178269 | 4,176 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | akunowski | 573,109,101 | false | {"Kotlin": 5413} | fun main() {
fun roundResult(pair: Pair<Char, Char>) =
when (pair) {
'A' to 'B', 'B' to 'C', 'C' to 'A' -> 6
'A' to 'A', 'B' to 'B', 'C' to 'C' -> 3
else -> 0
}
fun shapeValue(shape: Char): Int =
when (shape) {
'A' -> 1
'B' ->... | 0 | Kotlin | 0 | 0 | b306b779386c793f5bf9d8a86a59a7d0755c6159 | 1,600 | aoc-2022 | Apache License 2.0 |
2022/src/day24/day24.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day24
import GREEN
import RESET
import printTimeMillis
import readInput
import java.util.*
import kotlin.math.abs
typealias Iter = (Point, Int) -> Point
data class Point(val x: Int, val y: Int) {
fun neighbors() = listOf(
Point(x + 1, y), Point(x, y + 1), Point(x - 1, y), Point(x, y - 1),
)
}... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 3,910 | advent-of-code | Apache License 2.0 |
y2022/src/main/kotlin/adventofcode/y2022/Day24.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2022
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Direction
import adventofcode.util.vector.Vec2
import adventofcode.util.vector.neighbors
object Day24 : AdventSolution(2022, 24, "<NAME>") {
override fun solvePartOne(input: String): Int {
val initialBlizzard... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 4,792 | advent-of-code | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year19/Day24.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year19
import com.grappenmaker.aoc.*
fun PuzzleSet.day24() = puzzle(day = 24) {
val initial = inputLines.asGrid { it == '#' }
val emptyGrid = initial.mapElements { false }
val center = Point(initial.width / 2, initial.height / 2)
fun rule(curr: Boolean, adj: Int) = when {... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 2,576 | advent-of-code | The Unlicense |
src/Day01.kt | euphonie | 571,665,044 | false | {"Kotlin": 23344} | fun main() {
fun buildSumArray(input: List<String>) : List<Int> {
val sums = ArrayList<Int>()
var currSum = 0;
for (food in input) {
if (food == "") {
sums.add(currSum);
currSum = 0;
} else {
currSum += food.toInt()
... | 0 | Kotlin | 0 | 0 | 82e167e5a7e9f4b17f0fbdfd01854c071d3fd105 | 1,202 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/kr/co/programmers/P150368.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://github.com/antop-dev/algorithm/issues/488
class P150368 {
fun solution(users: Array<IntArray>, emoticons: IntArray): IntArray {
val answer = intArrayOf(0, 0)
// 모든 조합으로 구매를 계산한다.
val combinations = combinations(emoticons.size)
for (comb in combin... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 2,153 | algorithm | MIT License |
src/main/kotlin/adventofcode/year2022/Day12HillClimbingAlgorithm.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2022
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import adventofcode.common.neighbors
class Day12HillClimbingAlgorithm(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val grid by lazy { input.lines().map(String::toList) }
override fun partOne() = grid... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 1,904 | AdventOfCode | MIT License |
src/Day08.kt | euphonie | 571,665,044 | false | {"Kotlin": 23344} | fun main() {
fun buildMatrix(input: List<String>) : Array<IntArray> {
return input.map {
it.map { v -> v.digitToInt() }.toIntArray()
}.toTypedArray()
}
fun printMatrix(matrix: Array<IntArray>) {
println(
matrix.map {
it.contentToStri... | 0 | Kotlin | 0 | 0 | 82e167e5a7e9f4b17f0fbdfd01854c071d3fd105 | 1,835 | advent-of-code-kotlin | Apache License 2.0 |
2021/kotlin/src/main/kotlin/nl/sanderp/aoc/aoc2021/day17/Day17.kt | sanderploegsma | 224,286,922 | false | {"C#": 233770, "Kotlin": 126791, "F#": 110333, "Go": 70654, "Python": 64250, "Scala": 11381, "Swift": 5153, "Elixir": 2770, "Jinja": 1263, "Ruby": 1171} | package nl.sanderp.aoc.aoc2021.day17
import nl.sanderp.aoc.common.*
private val targetX = 29..73
private val targetY = -248..-194
fun main() {
val (answer1, duration1) = measureDuration<Int> { partOne() }
println("Part one: $answer1 (took ${duration1.prettyPrint()})")
val (answer2, duration2) = measureD... | 0 | C# | 0 | 6 | 8e96dff21c23f08dcf665c68e9f3e60db821c1e5 | 1,617 | advent-of-code | MIT License |
src/Day03.kt | hubikz | 573,170,763 | false | {"Kotlin": 8506} | fun main() {
// a..z -> 1..25
// A..Z -> 26..52
fun charToPriority(char: Char): Int {
return Character.getNumericValue(char) - 9 + if (Character.isUpperCase(char)) 26 else 0
}
fun part1(input: List<String>): Int {
return input.sumOf { items ->
val halfIndex = items.leng... | 0 | Kotlin | 0 | 0 | 902c6c3e664ad947c38c8edcb7ffd612b10e58fe | 1,158 | AoC2022 | Apache License 2.0 |
src/Day07.kt | chrisjwirth | 573,098,264 | false | {"Kotlin": 28380} | fun main() {
class Dir(
val name: String,
val parentDir: Dir? = null,
val childrenDirs: MutableMap<String, Dir> = mutableMapOf(),
var sizeOfDirectFiles: Int = 0,
var totalSize: Int? = null
)
fun linePurpose(line: String): String {
return if (line.substring(0,... | 0 | Kotlin | 0 | 0 | d8b1f2a0d0f579dd23fa1dc1f7b156f728152c2d | 3,226 | AdventOfCode2022 | Apache License 2.0 |
archive/2022/Day05.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | private const val EXPECTED_1 = "CMZ"
private const val EXPECTED_2 = "MCD"
private class Day05(isTest: Boolean) : Solver(isTest) {
fun part1(): Any {
val data = readAsString()
val parts = data.split("\n\n")
val stacks = readInitialState(parts[0])
applyCommands(stacks, parts[1], true... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 2,203 | advent-of-code-2022 | Apache License 2.0 |
2022/src/main/kotlin/day20_attempt3.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.badInput
import utils.mapItems
import kotlin.math.absoluteValue
fun main() {
Day20_3.run()
}
object Day20_3 : Solution<List<Long>>() {
override val name = "day20"
override val parser = Parser.lines.mapItems { it.toLong() }
data class Item(
val origIn... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,804 | aoc_kotlin | MIT License |
src/year2023/day10/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2023.day10
import arrow.core.nonEmptyListOf
import io.kotest.matchers.collections.shouldHaveSize
import utils.Point
import utils.ProblemPart
import utils.get
import utils.neighbors
import utils.print
import utils.readInputs
import utils.runAlgorithm
import utils.x
import utils.y
fun main() {
val (real... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 4,831 | Advent-of-Code | Apache License 2.0 |
src/main/kotlin/day12.kt | kevinrobayna | 436,414,545 | false | {"Ruby": 195446, "Kotlin": 42719, "Shell": 1288} | import kotlin.math.abs
fun day12ProblemReader(text: String): List<Pair<String, Int>> {
return text
.split('\n')
.map { line ->
Pair(line.trim().filter { !it.isDigit() }, line.trim().filter { it.isDigit() }.toInt())
}
}
// https://adventofcode.com/2020/day/12
class Day12(
pr... | 0 | Kotlin | 0 | 0 | 9e48ecdebdb4c479ef00f0fd3b1a44a211fb6577 | 2,812 | adventofcode_2020 | MIT License |
src/Day03.kt | GreyWolf2020 | 573,580,087 | false | {"Kotlin": 32400} | fun main() {
fun itemPriority(c: Char): Int = when {
c.isLowerCase() -> c.code - 96
c.isUpperCase() -> c.code - 64 + 26
else -> 0
}
fun part1(input: List<String>): Int = input.foldRight(0) { rucksack, prioritySum ->
rucksack
.chunked(rucksack.length / 2)
... | 0 | Kotlin | 0 | 0 | 498da8861d88f588bfef0831c26c458467564c59 | 1,312 | aoc-2022-in-kotlin | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2022/Day18.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.resultFrom
/**
* --- Day 18: Boiling Boulders ---
* https://adventofcode.com/2022/day/18
*/
class Day18 : Solver {
private val deltas = setOf(
XYZ(-1, 0, 0),
XYZ(1, 0, 0),
XYZ(0, -1, 0),
XYZ(0, ... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 2,335 | euler | Apache License 2.0 |
src/day01/Day01.kt | idle-code | 572,642,410 | false | {"Kotlin": 79612} | package day01
import readInput
data class CalorieEntry(val elfId: Int, val calories: Int)
fun parseInput(inputLines: List<String>): Iterable<CalorieEntry> {
val caloriesPerItem = mutableListOf<CalorieEntry>()
var elfId = 0
for (line in inputLines) {
if (line.isEmpty()) {
++elfId
... | 0 | Kotlin | 0 | 0 | 1b261c399a0a84c333cf16f1031b4b1f18b651c7 | 1,321 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2022/Day13.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2022
import se.saidaspen.aoc.util.Day
import se.saidaspen.aoc.util.P
fun main() = Day13.run()
object Day13 : Day(2022, 13) {
class Packet(private val fixed: Int? = null, val values: MutableList<Packet> = mutableListOf()) : Comparable<Packet> {
override fun toString() = fixed... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 2,853 | adventofkotlin | MIT License |
src/Day13.kt | frozbiz | 573,457,870 | false | {"Kotlin": 124645} |
fun main() {
fun CharSequence.toList(): List<Any> {
fun listHelper(s: CharSequence, startIx: Int): Pair<List<Any>, Int> {
var ix = startIx
if (s[ix++] != '[') throw IllegalArgumentException("Not a list: $s")
val ret = mutableListOf<Any>()
while (ix < this.le... | 0 | Kotlin | 0 | 0 | 4feef3fa7cd5f3cea1957bed1d1ab5d1eb2bc388 | 4,314 | 2022-aoc-kotlin | Apache License 2.0 |
src/Day05.kt | jamesrobert | 573,249,440 | false | {"Kotlin": 13069} | fun main() {
fun loadCrates(crateInput: List<String>): MutableMap<Int, String> {
val crates = mutableMapOf<Int, String>()
for (line in crateInput) {
for ((index, chunk) in line.chunked(4).withIndex()) {
val stackNumber = index + 1
if (crates[stackNumber] =... | 0 | Kotlin | 0 | 0 | d0b49770fc313ae42d802489ec757717033a8fda | 2,361 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | Jintin | 573,640,224 | false | {"Kotlin": 30591} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { line ->
val a = line.substring(0, line.length / 2).toSet().toMutableSet()
val b = line.substring(line.length / 2).toSet()
a.retainAll(b)
a.sumOf {
if (it in 'A'..'Z') {
... | 0 | Kotlin | 0 | 2 | 4aa00f0d258d55600a623f0118979a25d76b3ecb | 1,110 | AdventCode2022 | Apache License 2.0 |
src/Day02.kt | davidkna | 572,439,882 | false | {"Kotlin": 79526} | fun main() {
fun part1(input: List<String>): Int {
return input.filter { return@filter it.isNotEmpty() }.sumOf {
var myChoice = it[2].code - 'X'.code
var win = when (it[0].code - 'A'.code) {
(myChoice + 1) % 3 -> 0
myChoice -> 3
else ->... | 0 | Kotlin | 0 | 0 | ccd666cc12312537fec6e0c7ca904f5d9ebf75a3 | 973 | aoc-2022 | Apache License 2.0 |
src/Day01.kt | qmchenry | 572,682,663 | false | {"Kotlin": 22260} | fun main() {
fun sums(input: List<String>): List<Int> {
return input
.flatMapIndexed { index, x ->
when {
index == 0 || index == input.lastIndex -> listOf(index)
x.isEmpty() -> listOf(index - 1, index + 1)
else -> empty... | 0 | Kotlin | 0 | 0 | 2813db929801bcb117445d8c72398e4424706241 | 1,103 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/io/github/clechasseur/adventofcode/y2022/Day23.kt | clechasseur | 567,968,171 | false | {"Kotlin": 493887} | package io.github.clechasseur.adventofcode.y2022
import io.github.clechasseur.adventofcode.util.Pt
import io.github.clechasseur.adventofcode.y2022.data.Day23Data
object Day23 {
private val input = Day23Data.input
fun part1(): Int = groveSequence(input.toGrove()).elementAt(10).groundCount
fun part2(): In... | 0 | Kotlin | 0 | 0 | 7ead7db6491d6fba2479cd604f684f0f8c1e450f | 3,602 | adventofcode2022 | MIT License |
2023/11/solve-2.kts | gugod | 48,180,404 | false | {"Raku": 170466, "Perl": 121272, "Kotlin": 58674, "Rust": 3189, "C": 2934, "Zig": 850, "Clojure": 734, "Janet": 703, "Go": 595} | import java.io.File
import kotlin.math.abs
class Cosmos (
val observation: List<String>,
val expansionFactor: Long,
) {
private fun String.allIndicesOf(c: Char) = indices.filter { this[it] == c }
val observedEmptyRows : List<Int> = observation.indices
.filter { j -> observation[j].all { it == ... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 1,389 | advent-of-code | Creative Commons Zero v1.0 Universal |
2022/Day17.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | import java.util.*
fun main() {
val rocks = arrayOf(
arrayOf(
"####"
),
arrayOf(
".#.",
"###",
".#.",
),
arrayOf(
"..#",
"..#",
"###",
).reversed().toTypedArray(),
arrayOf(
... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 3,447 | advent-of-code-kotlin | Apache License 2.0 |
kata/src/main/kotlin/kata/ColorChoice.kt | gualtierotesta | 129,613,223 | false | null | package kata
import java.math.BigInteger
/*
You know combinations: for example, if you take 5 cards from a 52 cards deck you have 2,598,960
different combinations.
In mathematics the number of x combinations you can take from a set of n elements is called the
binomial coefficient of n and x, or more often n choose x... | 0 | Kotlin | 0 | 0 | 8366bb3aed765fff7fb5203abce9a20177529a8e | 2,741 | PlayWithKotlin | Apache License 2.0 |
aoc-2022/src/main/kotlin/nerok/aoc/aoc2022/day07/Day07.kt | nerok | 572,862,875 | false | {"Kotlin": 113337} | package nerok.aoc.aoc2022.day07
import nerok.aoc.utils.Input
import kotlin.time.DurationUnit
import kotlin.time.measureTime
fun main() {
fun treeWriter(tree: MutableMap<String, Any>, key: String, values: MutableMap<String, Any>, separator: Char = '/'): MutableMap<String, Any> {
if (key == "/") return valu... | 0 | Kotlin | 0 | 0 | 7553c28ac9053a70706c6af98b954fbdda6fb5d2 | 6,127 | AOC | Apache License 2.0 |
src/main/kotlin/day20/day20.kt | corneil | 572,437,852 | false | {"Kotlin": 93311, "Shell": 595} | package day20
import main.utils.measureAndPrint
import main.utils.scanInt
import utils.checkNumber
import utils.readFile
import utils.readLines
import utils.separator
import java.util.*
fun main() {
val test = readLines(
"""1
2
-3
3
-2
0
4"""
)
val lines = readFile("day20")
class EncryptedFile(val inpu... | 0 | Kotlin | 0 | 0 | dd79aed1ecc65654cdaa9bc419d44043aee244b2 | 2,918 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2021/Day20.kt | tginsberg | 432,766,033 | false | {"Kotlin": 92813} | /*
* Copyright (c) 2021 by <NAME>
*/
/**
* Advent of Code 2021, Day 20 - Trench Map
* Problem Description: http://adventofcode.com/2021/day/20
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2021/day20/
*/
package com.ginsberg.advent2021
class Day20(input: List<String>) {
private val... | 0 | Kotlin | 2 | 34 | 8e57e75c4d64005c18ecab96cc54a3b397c89723 | 2,145 | advent-2021-kotlin | Apache License 2.0 |
src/Day23.kt | rod41732 | 572,917,438 | false | {"Kotlin": 85344} | data class Elf(var currentCoord: Coord2D, var nextCoord: Coord2D? = null)
operator fun Coord2D.plus(other: Coord2D) = Coord2D(x + other.x, y + other.y)
fun makeStrat(dirs: List<Int>, outDir: Int) = fun(cur: Coord2D, existing: Set<Coord2D>) =
if (dirs.all { it.toDirection() + cur !in existing }) cur + outDir.toDire... | 0 | Kotlin | 0 | 0 | 1d2d3d00e90b222085e0989d2b19e6164dfdb1ce | 3,269 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day08.kt | thelmstedt | 572,818,960 | false | {"Kotlin": 30245} | import java.io.File
fun main() {
fun rays(
grid: List<List<Int>>,
x: Int,
y: Int,
excludeSelf: Boolean = true,
): List<List<Pair<Int, Int>>> {
val height = grid.size
val width = grid.first().size
val d = if (excludeSelf) 1 else 0
val up = (y - d... | 0 | Kotlin | 0 | 0 | e98cd2054c1fe5891494d8a042cf5504014078d3 | 1,878 | advent2022 | Apache License 2.0 |
src/day5/Day05.kt | dean95 | 571,923,107 | false | {"Kotlin": 21240} | package day5
import readInput
private fun main() {
fun part1(input: List<String>): String {
val crates = input.takeWhile { it.contains(']') }
val cratesToStack = mutableListOf<Pair<Char, Int>>()
crates.forEach {
for (i in 1..it.lastIndex step 4) {
if (it[i].is... | 0 | Kotlin | 0 | 0 | 0ddf1bdaf9bcbb45116c70d7328b606c2a75e5a5 | 3,450 | advent-of-code-2022 | Apache License 2.0 |
day14/src/main/kotlin/App.kt | ascheja | 317,918,055 | false | null | package net.sinceat.aoc2020.day14
import kotlin.properties.Delegates
fun main() {
println(part1InstructionProcessor(readInstructions("testinput.txt")))
println(part1InstructionProcessor(readInstructions("input.txt")))
println(part2InstructionProcessor(readInstructions("testinput2.txt")))
println(part... | 0 | Kotlin | 0 | 0 | f115063875d4d79da32cbdd44ff688f9b418d25e | 3,844 | aoc2020 | MIT License |
src/test/kotlin/be/brammeerten/y2022/Day13Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2022
import be.brammeerten.readFile
import be.brammeerten.readFileSplitted
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import kotlin.math.min
class Day13Test {
@Test
fun `part 1a`() {
val pairs = readPairs("2022/day13/exampleInput.txt")
As... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 4,982 | Advent-of-Code | MIT License |
src/Day04.kt | nguyendanv | 573,066,311 | false | {"Kotlin": 18026} | fun main() {
fun part1(input: List<String>): Int {
return input
.filter { pair ->
val numbers = pair.split(",", "-").map { it.toInt() }
val first = (numbers[0]..numbers[1]).toSet()
val second = (numbers[2]..numbers[3]).toSet()
first... | 0 | Kotlin | 0 | 0 | 376512583af723b4035b170db1fa890eb32f2f0f | 1,056 | advent2022 | Apache License 2.0 |
2020/src/main/kotlin/Day1.kt | osipxd | 388,214,845 | false | null | /**
* # Day 1: Report Repair
*
* The Elves in accounting just need you to fix your **expense report** (your puzzle input); apparently,
* something isn't quite adding up. Specifically, they need you to find the two entries that sum to 2020
* and then multiply those two numbers together.
*
* For example, suppose y... | 0 | Kotlin | 0 | 0 | 66553923d8d221bcd1bd108f701fceb41f4d1cbf | 2,922 | advent-of-code | MIT License |
advanced-algorithms/kotlin/src/bO2CMax.kt | nothingelsematters | 135,926,684 | false | {"Jupyter Notebook": 7400788, "Java": 512017, "C++": 378834, "Haskell": 261217, "Kotlin": 251383, "CSS": 45551, "Vue": 37772, "Rust": 34636, "HTML": 22859, "Yacc": 14912, "PLpgSQL": 10573, "JavaScript": 9741, "Makefile": 8222, "TeX": 7166, "FreeMarker": 6855, "Python": 6708, "OCaml": 5977, "Nix": 5059, "ANTLR": 4802, "... | import java.io.File
import java.util.Scanner
fun scheduleO2CMax(p1: List<Long>, p2: List<Long>): Pair<Long, List<List<Long>>> {
fun fill(schedule: MutableList<Long>, times: List<Long>, indices: Sequence<Int>, init: Long = 0) =
indices.fold(init) { sum, index ->
schedule[index] = sum
... | 0 | Jupyter Notebook | 3 | 5 | d442a3d25b579b96c6abda13ed3f7e60d1747b53 | 1,796 | university | Do What The F*ck You Want To Public License |
src/y2023/Day18.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2023
import util.Cardinal
import util.minus
import util.neighborsManhattan
import util.readInput
import util.times
import util.timingStatistics
import util.toLong
object Day18 {
data class DigInstruction(
val direction: Cardinal,
val distance: Long
)
val dirMap = mapOf(
'... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 5,548 | advent-of-code | Apache License 2.0 |
leetcode/src/offer/middle/Offer14_1.kt | zhangweizhe | 387,808,774 | false | null | package offer.middle
fun main() {
// 剑指 Offer 14- I. 剪绳子
// https://leetcode.cn/problems/jian-sheng-zi-lcof/
for (i in 2..10) {
println("$i -> ${cuttingRope1(i)}")
}
}
private fun cuttingRope(n: Int): Int {
/**
* 如果是剪 1 刀,那么可以剪出的长度是 1、2、3...n-1
* 则剩下的长度是 n-1、n-2、n-3...1
* 一... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 2,471 | kotlin-study | MIT License |
src/Day03.kt | wgolyakov | 572,463,468 | false | null | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
val a = it.substring(0, it.length / 2).toSet()
val b = it.substring(it.length / 2, it.length).toSet()
val c = a.intersect(b).first()
c.code + if (c.isLowerCase()) 1 - 'a'.code else 27 - 'A'.code
}
}
fun part2(input: List<String>... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 715 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day09.kt | joostbaas | 573,096,671 | false | {"Kotlin": 45397} | import Direction.*
import kotlin.math.abs
enum class Direction {
UP, DOWN, RIGHT, LEFT
}
fun String.toDirection() =
when (this) {
"R" -> RIGHT
"U" -> UP
"L" -> LEFT
"D" -> DOWN
else -> throw IllegalArgumentException()
}
fun List<String>.parseRopeMoves() =
flatM... | 0 | Kotlin | 0 | 0 | 8d4e3c87f6f2e34002b6dbc89c377f5a0860f571 | 2,164 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/13.kts | reitzig | 318,492,753 | false | null | import java.io.File
data class BusLine(val frequency: Long, val contestOffset: Long) {
val id: Long = frequency
fun nextDepartureAfter(timestamp: Long): Long =
((timestamp / frequency) * frequency).let {
if (it < timestamp) {
it + frequency
} else {
... | 0 | Kotlin | 0 | 0 | f17184fe55dfe06ac8897c2ecfe329a1efbf6a09 | 2,749 | advent-of-code-2020 | The Unlicense |
src/main/kotlin/day18/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day18
import java.io.File
fun main() {
val lines = File("src/main/kotlin/day18/input.txt").readLines()
val snailFishNumbers = lines.map { parseSnailFish(it) }
println(snailFishNumbers.reduce { acc, snailFishNumber -> acc.copy() + snailFishNumber.copy() }.magnitude())
var highestMagnitude = 0
... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 5,577 | aoc-2021 | MIT License |
gcj/y2019/round3/a.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2019.round3
import java.util.TreeSet
private const val M = 1_000_000_000_000L
private const val S = 10_000_000_000L
private fun play() {
val ranges = mutableSetOf(1..M)
fun makeMove(p: Long) {
val removed = ranges.first { p in it }
ranges.remove(removed)
val added = listOf(removed.first until p,... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 2,657 | competitions | The Unlicense |
Problems/Algorithms/1091. Shortest Path in Binary Matrix/ShortestPathBinaryMatrix.kt | xuedong | 189,745,542 | false | {"Kotlin": 332182, "Java": 294218, "Python": 237866, "C++": 97190, "Rust": 82753, "Go": 37320, "JavaScript": 12030, "Ruby": 3367, "C": 3121, "C#": 3117, "Swift": 2876, "Scala": 2868, "TypeScript": 2134, "Shell": 149, "Elixir": 130, "Racket": 107, "Erlang": 96, "Dart": 65} | class Solution {
fun shortestPathBinaryMatrix(grid: Array<IntArray>): Int {
val n = grid.size
val m = grid[0].size
if (n == 1 && m == 1) {
if (grid[0][0] == 0) return 1
return -1
}
if (grid[0][0] == 1 || grid[n-1][m-1] == 1) return -1
... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 1,582 | leet-code | MIT License |
src/Day03.kt | alfr1903 | 573,468,312 | false | {"Kotlin": 9628} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { commonCompartmentLetter(it).toPriority() }
}
fun part2(input: List<String>): Any {
return input.chunked(3).sumOf { commonBadgeLetter(it).toPriority() }
}
val input = readInputAsList("Day03Input")
println(pa... | 0 | Kotlin | 0 | 0 | c1d1fbf030ac82c643fa5aea4d9f7c302051c38c | 854 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | tsschmidt | 572,649,729 | false | {"Kotlin": 24089} |
fun main() {
fun parseDequed(input: List<String>): List<ArrayDeque<Char>> {
val numStacks = input[0].length / 3
val stacks = mutableListOf<ArrayDeque<Char>>()
repeat(numStacks) { stacks.add(ArrayDeque()) }
input.takeWhile { it.contains('[') }.forEach {
it.chunked(4).for... | 0 | Kotlin | 0 | 0 | 7bb637364667d075509c1759858a4611c6fbb0c2 | 1,782 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | stephenkao | 572,205,897 | false | {"Kotlin": 14623} | fun main() {
// indices and scores
val shapeIndices = mapOf(
// rock
"A" to 0,
"X" to 0,
// paper
"B" to 1,
"Y" to 1,
// scissors
"C" to 2,
"Z" to 2
)
fun part1(input: List<String>): Int {
fun getOutcomeScore(opponentChoice... | 0 | Kotlin | 0 | 0 | 7a1156f10c1fef475320ca985badb4167f4116f1 | 2,264 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day13.kt | fmborghino | 573,233,162 | false | {"Kotlin": 60805} | import org.json.JSONArray
import org.json.JSONTokener
fun main() {
fun log(message: Any?) {
println(message)
}
fun String.toJSONArray() = JSONTokener(this).nextValue() as JSONArray
fun String.toListViaJSONArray() = this.toJSONArray().toList()
val marker2 = "[[2]]".toListViaJSONArray()
... | 0 | Kotlin | 0 | 0 | 893cab0651ca0bb3bc8108ec31974654600d2bf1 | 3,387 | aoc2022 | Apache License 2.0 |
src/day4/result.kt | davidcurrie | 437,645,413 | false | {"Kotlin": 37294} | package day4
import java.io.File
data class Board(val numbers: Map<Int, Pair<Int, Int>>) {
private val rows = numbers.values.maxOf { it.first } + 1
private val cols = numbers.values.maxOf { it.second } + 1
private val matches = mutableListOf<Int>()
private val rowCounts = MutableList(rows) { 0 }
p... | 0 | Kotlin | 0 | 0 | dd37372420dc4b80066efd7250dd3711bc677f4c | 1,744 | advent-of-code-2021 | MIT License |
src/Day02.kt | mikemac42 | 573,071,179 | false | {"Kotlin": 45264} | fun String.sumCharScores(charScores: Map<Char, Int>): Int =
sumOf { charScores[it] ?: 0 }
fun String.sumLineScores(lineScores: Map<String, Int>): Int =
lines().sumOf { lineScores[it] ?: 0 }
/**
* The first column is what your opponent is going to play:
* A for Rock, B for Paper, and C for Scissors
* The seco... | 0 | Kotlin | 1 | 0 | 909b245e4a0a440e1e45b4ecdc719c15f77719ab | 1,519 | advent-of-code-2022 | Apache License 2.0 |
src/Day08.kt | diesieben07 | 572,879,498 | false | {"Kotlin": 44432} | import java.util.BitSet
import kotlin.math.max
private val file = "Day08"
//private val file = "Day08Example"
private fun readInput(): Pair<Int, List<IntArray>> {
val lines = readInput(file)
val gridSize = lines.size
check(lines.all { it.length == gridSize })
val grid = lines.map { it.map { c -> c.d... | 0 | Kotlin | 0 | 0 | 0b9993ef2f96166b3d3e8a6653b1cbf9ef8e82e6 | 2,602 | aoc-2022 | Apache License 2.0 |
kotlin/0072-edit-distance.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} | /*
* DP Time O(m*n) and space O(m*n)
*/
class Solution {
fun minDistance(word1: String, word2: String): Int {
val cache = Array(word1.length + 1) {
IntArray(word2.length + 1){ Integer.MAX_VALUE }
}
for(j in 0..word2.length)
cache[word1.length][j] = word2.len... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 2,559 | leetcode | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.