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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dataStructuresAndAlgorithms/src/main/java/dev/funkymuse/datastructuresandalgorithms/graphs/djikstra/Dijkstra.kt | FunkyMuse | 168,687,007 | false | {"Kotlin": 1728251} | package dev.funkymuse.datastructuresandalgorithms.graphs.djikstra
import dev.funkymuse.datastructuresandalgorithms.graphs.Edge
import dev.funkymuse.datastructuresandalgorithms.graphs.Vertex
import dev.funkymuse.datastructuresandalgorithms.graphs.adjacency.AdjacencyList
import dev.funkymuse.datastructuresandalgorithms.... | 0 | Kotlin | 92 | 771 | e2afb0cc98c92c80ddf2ec1c073d7ae4ecfcb6e1 | 2,679 | KAHelpers | MIT License |
src/main/kotlin/com/sk/set3/347. Top K Frequent Elements.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.set3
import java.util.*
class Solution347 {
fun topKFrequent(nums: IntArray, k: Int): List<Int> {
val frequencyMap: MutableMap<Int, Int> = HashMap()
for (n in nums) {
frequencyMap[n] = frequencyMap.getOrDefault(n, 0) + 1
}
val bucket = Array<MutableList... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 1,634 | leetcode-kotlin | Apache License 2.0 |
src/Day03.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | fun main() {
val testInput = readInput("Day03_test")
check(part1(testInput) == 157)
check(part2(testInput) == 70)
val input = readInput("Day03")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>): Int {
return input
.map { it.chunked(size = it.leng... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 838 | aoc-22 | Apache License 2.0 |
src/main/kotlin/aoc2022/Day14.kt | j4velin | 572,870,735 | false | {"Kotlin": 285016, "Python": 1446} | package aoc2022
import Point
import readInput
private const val MAX_WIDTH = 1000
private val START = Point(500, 0)
private fun getMaxY(input: List<String>): Int {
return input.maxOf { path ->
path.split(" -> ").maxOf { point ->
val (x, y) = point.split(",").map { it.toInt() }
y
... | 0 | Kotlin | 0 | 0 | f67b4d11ef6a02cba5b206aba340df1e9631b42b | 3,018 | adventOfCode | Apache License 2.0 |
src/main/kotlin/org/sjoblomj/adventofcode/day6/Day6.kt | sjoblomj | 225,241,573 | false | null | package org.sjoblomj.adventofcode.day6
import org.sjoblomj.adventofcode.readFile
private const val inputFile = "src/main/resources/inputs/day6.txt"
fun day6(): Pair<Int, Int> {
val content = readFile(inputFile)
val orbitList = getOrbitList(content)
val numberOfOrbits = calculateNumberOfOrbits(orbitList)
val mi... | 0 | Kotlin | 0 | 0 | f8d03f7ef831bc7e26041bfe7b1feaaadcb40e68 | 3,338 | adventofcode2019 | MIT License |
src/main/kotlin/TwoSum.kt | mececeli | 553,346,819 | false | {"Kotlin": 9018} | /**
* Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
* You can return the answer in any order.
*
* Example 1:
* Input: nums = [2... | 0 | Kotlin | 0 | 0 | d05ee9d32c42d11e71e136f4138bb0335114f360 | 1,384 | Kotlin_Exercises | Apache License 2.0 |
src/year2021/06/Day06.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2021.`06`
import readInput
fun main() {
fun cycle(input: Map<Long, Long>): Map<Long, Long> {
val resultMap = mutableMapOf<Long, Long>()
input.keys
.sortedDescending()
.forEach {
when (it) {
0L -> {
re... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 1,722 | KotlinAdventOfCode | Apache License 2.0 |
src/main/kotlin/dev/siller/aoc2023/Day02.kt | chearius | 725,594,554 | false | {"Kotlin": 50795, "Shell": 299} | package dev.siller.aoc2023
data object Day02 : AocDayTask<UInt, UInt>(
day = 2,
exampleInput =
"""
|Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green;... | 0 | Kotlin | 0 | 0 | fab1dd509607eab3c66576e3459df0c4f0f2fd94 | 2,261 | advent-of-code-2023 | MIT License |
2022/src/main/kotlin/day12_imp.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Grid
import utils.Graph
import utils.Parser
import utils.Solution
import utils.Vec2i
import utils.mapParser
import java.lang.IllegalStateException
fun main() {
Day12Imp.run()
}
object Day12Imp : Solution<Grid<Char>>() {
override val name = "day12"
override val parser = Parser(String::trim).mapParse... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,688 | aoc_kotlin | MIT License |
src/Day07.kt | maewCP | 579,203,172 | false | {"Kotlin": 59412} | fun main() {
val verbose = false
fun _process(input: List<String>) : Day07Folder {
val root = Day07Folder("/")
var currentFolder = root
val cdCmd = "\\$ cd (.+)".toRegex()
val folderOutput = "dir (.+)".toRegex()
val fileOutput = "(\\d+) .+".toRegex()
input.forEac... | 0 | Kotlin | 0 | 0 | 8924a6d913e2c15876c52acd2e1dc986cd162693 | 3,805 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day09.kt | sabercon | 648,989,596 | false | null | fun main() {
fun isValid(nums: List<Long>, i: Int): Boolean {
if (i < 25) return true
val preamble = nums.subList(i - 25, i).toSet()
return preamble.any { it * 2 != nums[i] && preamble.contains(nums[i] - it) }
}
tailrec fun findRange(nums: List<Long>, target: Long, start: Int, end: ... | 0 | Kotlin | 0 | 0 | 81b51f3779940dde46f3811b4d8a32a5bb4534c8 | 940 | advent-of-code-2020 | MIT License |
src/day02/Day02.kt | wickenico | 573,158,084 | false | {"Kotlin": 7731} | package day02
import readInput
fun main() {
println(part2(readInput("day02", "input"), strategy1))
println(part2(readInput("day02", "input"), strategy2))
}
private val strategy1 = mapOf(
'A' to mapOf('X' to 1 + 3, 'Y' to 2 + 6, 'Z' to 3 + 0),
'B' to mapOf('X' to 1 + 0, 'Y' to 2 + 3, 'Z' to 3 + 6),
... | 0 | Kotlin | 0 | 0 | bc587f433aa38c4d745c09d82b7d231462f777c8 | 720 | advent-of-code-kotlin | Apache License 2.0 |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[316]去除重复字母.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给你一个字符串 s ,请你去除字符串中重复的字母,使得每个字母只出现一次。需保证 返回结果的字典序最小(要求不能打乱其他字符的相对位置)。
//
// 注意:该题与 1081 https://leetcode-cn.com/problems/smallest-subsequence-of-distinct
//-characters 相同
//
//
//
// 示例 1:
//
//
//输入:s = "bcabc"
//输出:"abc"
//
//
// 示例 2:
//
//
//输入:s = "cbacdcbc"
//输出:"acdb"
//
//
//
// 提示:
//
//
// 1 <= s... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,736 | MyLeetCode | Apache License 2.0 |
src/Day24.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | private val directions = mutableListOf(-1 to 0, 1 to 0, 0 to -1, 0 to 1)
private val charToDir = buildMap(4) { (0..3).forEach { put("^v<>"[it], directions[it]) } }
private data class Blizzard(val dir: Pair<Int, Int>, var pos: Pair<Int, Int>)
private class BlizzardField(map: List<String>) {
val blizzards: MutableL... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 3,399 | advent-of-kotlin-2022 | Apache License 2.0 |
src/Day02.kt | alexdesi | 575,352,526 | false | {"Kotlin": 9824} | import java.io.File
fun main() {
fun value(move: Char): Int {
return when (move) {
'A', 'X' -> 1
'B', 'Y' -> 2
'C', 'Z' -> 3
else -> -1
}
}
fun getScore(move1: Char, move2: Char): Int {
return when ("$move1$move2") {
"AA",... | 0 | Kotlin | 0 | 0 | 56a6345e0e005da09cb5e2c7f67c49f1379c720d | 2,068 | advent-of-code-kotlin | Apache License 2.0 |
src/Day14.kt | TheGreatJakester | 573,222,328 | false | {"Kotlin": 47612} | package day14
import utils.readInputAsText
import utils.runSolver
import utils.string.asLines
private typealias SolutionType = Int
private const val defaultSolution = 0
private const val dayNumber: String = "14"
private val testSolution1: SolutionType? = 24
private val testSolution2: SolutionType? = 93
typealias ... | 0 | Kotlin | 0 | 0 | c76c213006eb8dfb44b26822a44324b66600f933 | 3,292 | 2022-AOC-Kotlin | Apache License 2.0 |
src/day05/Day05.kt | Frank112 | 572,910,492 | false | null | package day05
import assertThat
import readInput
fun main() {
val crateLineRegex: Regex = Regex("( |\\[(?<crate>[A-Z])\\]) ?")
val moveCrateCommandLineRegex = Regex("^move (\\d+) from (\\d+) to (\\d+)$")
fun <T> List<T>.splitBy(element: T): List<List<T>> {
var list = this
val listOfLis... | 0 | Kotlin | 0 | 0 | 1e927c95191a154efc0fe91a7b89d8ff526125eb | 2,471 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/anahoret/aoc2022/day11/main.kt | mikhalchenko-alexander | 584,735,440 | false | null | package com.anahoret.aoc2022.day11
import java.io.File
import java.lang.IllegalArgumentException
import kotlin.math.floor
class Monkey(
startingItems: List<Long>,
val testNumber: Long,
private val operation: (Long) -> Long,
private val throwMap: Map<Boolean, Int>
) {
var inspectCount = 0L
... | 0 | Kotlin | 0 | 0 | b8f30b055f8ca9360faf0baf854e4a3f31615081 | 3,163 | advent-of-code-2022 | Apache License 2.0 |
src/Day13.kt | maciekbartczak | 573,160,363 | false | {"Kotlin": 41932} | // tbh I gave up on this one, solution heavily based on:
// https://github.com/ash42/adventofcode/tree/main/adventofcode2022/src/nl/michielgraat/adventofcode2022/day13
import kotlin.math.min
fun main() {
fun part1(input: List<String>): Int {
return input
.chunked(3)
.map {
... | 0 | Kotlin | 0 | 0 | 53c83d9eb49d126e91f3768140476a52ba4cd4f8 | 3,303 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Blizzards.kt | alebedev | 573,733,821 | false | {"Kotlin": 82424} | import java.util.*
import kotlin.math.abs
fun main() = Blizzards.solve()
private object Blizzards {
fun solve() {
var board = readInput()
val start = Pos(1, 0)
val target = Pos(board.cells.last().indexOfFirst { it is Space }, board.cells.size - 1)
val initialPath = Path(
... | 0 | Kotlin | 0 | 0 | d6ba46bc414c6a55a1093f46a6f97510df399cd1 | 6,086 | aoc2022 | MIT License |
src/main/kotlin/days/aoc2021/Day5.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2021
import days.Day
import java.lang.Integer.max
import kotlin.math.absoluteValue
import kotlin.math.min
class Day5 : Day(2021, 5) {
override fun partOne(): Any {
return calculateMostDangerousPoints(createMapWithNonDiagonals(inputList))
}
override fun partTwo(): Any {
ret... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 3,479 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/Day03.kt | azat-ismagilov | 573,217,326 | false | {"Kotlin": 75114} | fun main() {
fun Char.toNumber(): Int = when (this) {
in 'a' .. 'z' -> this - 'a' + 1
in 'A' .. 'Z' -> this - 'A' + 27
else -> 0
}
fun calcPrice(left: String, right: String) = left.toSet().intersect(right.toSet()).sumOf { it.toNumber() }
fun part1(input: List<String>): Int = in... | 0 | Kotlin | 0 | 0 | abdd1b8d93b8afb3372cfed23547ec5a8b8298aa | 898 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day03.kt | MatthiasDruwe | 571,730,990 | false | {"Kotlin": 47864} |
fun main() {
fun part1(input: List<String>): Int {
val output = input.mapNotNull {
var x: Char? = null
it.substring(0, it.length / 2).forEach { char ->
if (it.substring(it.length / 2).contains(char)) {
x = char
}
}
... | 0 | Kotlin | 0 | 0 | f35f01cea5075cfe7b4a1ead9b6480ffa57b4989 | 1,432 | Advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | cnietoc | 572,880,374 | false | {"Kotlin": 15990} | fun main() {
fun getPairsFrom(input: List<String>) = input.map { line ->
line.split(",").map { rangeRaw ->
rangeRaw.split("-").let { IntRange(it.first().toInt(), it.last().toInt()) }
}.let {
PairOfRanges(it.first(), it.last())
}
}
fun part1(input: List<String... | 0 | Kotlin | 0 | 0 | bbd8e81751b96b37d9fe48a54e5f4b3a0bab5da3 | 1,012 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | wmichaelshirk | 573,031,182 | false | {"Kotlin": 19037} |
val scores2 = mapOf<String, Int>(
"A X" to 3, // Lose = 0, Scissors = 3
"A Y" to 4, // Draw = 3, Rock = 1
"A Z" to 8, // Win = 6, Paper = 2
"B X" to 1, // Lose = 0, Rock = 1
"B Y" to 5, // Draw = 3, Paper = 2
"B Z" to 9, // Win = 6, Scissors = 3
"C X" to 2, // Lose = 0, Paper = 2,
"C Y"... | 0 | Kotlin | 0 | 2 | b748c43e9af05b9afc902d0005d3ba219be7ade2 | 1,285 | 2022-Advent-of-Code | Apache License 2.0 |
src/Day01.kt | Yasenia | 575,276,480 | false | {"Kotlin": 15232} | fun main() {
fun part1(input: List<String>): Int {
var currentCalories = 0
var mostCalories = 0
for ((i, line) in input.withIndex()) {
if (line.isNotBlank()) currentCalories += line.toInt()
if (line.isBlank() || i == input.lastIndex) {
mostCalories = m... | 0 | Kotlin | 0 | 0 | 9300236fa8697530a3c234e9cb39acfb81f913ba | 1,416 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaximumSubsequenceScore.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,267 | kotlab | Apache License 2.0 |
src/Day04.kt | lassebe | 573,423,378 | false | {"Kotlin": 33148} | fun main() {
fun solve(input: List<String>, predicate: (a: Int, b: Int, c: Int, d: Int) -> Boolean): Int {
return input.sumOf { schedule ->
val assignments = schedule.split(",")
val elf1 = assignments.first().split("-").map { it.toInt() }
val elf2 = assignments.last().spl... | 0 | Kotlin | 0 | 0 | c3157c2d66a098598a6b19fd3a2b18a6bae95f0c | 966 | advent_of_code_2022 | Apache License 2.0 |
src/main/kotlin/y2023/day11/Day11.kt | niedrist | 726,105,019 | false | {"Kotlin": 19919} | package y2023.day11
import BasicDay
import util.FileReader
import util.pairs
import kotlin.math.max
import kotlin.math.min
val d = FileReader.asStrings("2023/day11.txt").map { it.toCharArray().toList() }
fun main() = Day11.run()
object Day11 : BasicDay() {
override fun part1() = solve(1)
override fun part2()... | 0 | Kotlin | 0 | 1 | 37e38176d0ee52bef05f093b73b74e47b9011e24 | 2,238 | advent-of-code | Apache License 2.0 |
src/Day03.kt | remidu | 573,452,090 | false | {"Kotlin": 22113} | fun main() {
fun duplicate(list1: List<Char>, list2: List<Char>): Char {
for (char in list1) {
if (list2.contains(char)) return char
}
return 'a' // should never happen
}
fun duplicate(list1: List<Char>, list2: List<Char>, list3: List<Char>): Char {
for (char in... | 0 | Kotlin | 0 | 0 | ecda4e162ab8f1d46be1ce4b1b9a75bb901bc106 | 1,492 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | monsterbrain | 572,819,542 | false | {"Kotlin": 42040} | fun main() {
fun String.firstHalf(): String {
return substring(0 until length/2)
}
fun String.secondHalf(): String {
return substring(length/2 until length)
}
fun findCommon(firstHalf: String, secondHalf: String): Char {
firstHalf.forEach {
if (secondHalf.contai... | 0 | Kotlin | 0 | 0 | 3a1e8615453dd54ca7c4312417afaa45379ecf6b | 1,751 | advent-of-code-kotlin-2022-Solutions | Apache License 2.0 |
solutions/aockt/y2021/Y2021D04.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
object Y2021D04 : Solution {
/**
* A 5x5 BingoBoard.
* @constructor Sets up a new bingo board with these 25 numbers, from left to right, top to bottom.
*/
private class BingoBoard(numbers: List<Int>) {
private val grid: ... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,096 | advent-of-code-kotlin-solutions | The Unlicense |
src/day21/day21.kt | kacperhreniak | 572,835,614 | false | {"Kotlin": 85244} | package day21
import readInput
private fun parse(input: List<String>): Map<String, Operation> {
return input.associate {
val parts = it.split(": ")
val key = parts[0]
val operation = if (parts[1].contains(" + ")) {
val items = parts[1].split(" + ")
Operation.Add(ite... | 0 | Kotlin | 1 | 0 | 03368ffeffa7690677c3099ec84f1c512e2f96eb | 4,000 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/staricka/adventofcode2023/days/Day2.kt | mathstar | 719,656,133 | false | {"Kotlin": 107115} | package com.staricka.adventofcode2023.days
import com.staricka.adventofcode2023.framework.Day
import java.util.regex.Pattern
import kotlin.math.max
class Day2: Day {
data class Game(val id: Int, val reveals: List<Reveal>) {
fun possible(counts: Map<String, Int>): Boolean =
reveals.all { it.pos... | 0 | Kotlin | 0 | 0 | 8c1e3424bb5d58f6f590bf96335e4d8d89ae9ffa | 3,079 | adventOfCode2023 | MIT License |
kotlin/src/katas/kotlin/leetcode/common_parent/CommonParent.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.common_parent
fun main() {
val root = Node("A", Node("B"), Node("C"))
require(find(root, "B", "C")?.name == "A")
val root2 = Node("A",
Node("B",
Node("D"),
Node("E", Node("H"), Node("J"))),
Node("C",
Node("F"),
... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,767 | katas | The Unlicense |
src/main/kotlin/io/github/clechasseur/adventofcode/y2022/Day8.kt | clechasseur | 567,968,171 | false | {"Kotlin": 493887} | package io.github.clechasseur.adventofcode.y2022
import io.github.clechasseur.adventofcode.util.Direction
import io.github.clechasseur.adventofcode.util.Pt
import io.github.clechasseur.adventofcode.y2022.data.Day8Data
object Day8 {
private val input = Day8Data.input
fun part1(): Int {
val grid = inpu... | 0 | Kotlin | 0 | 0 | 7ead7db6491d6fba2479cd604f684f0f8c1e450f | 1,986 | adventofcode2022 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CollectApples.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,785 | kotlab | Apache License 2.0 |
src/Day16.kt | astrofyz | 572,802,282 | false | {"Kotlin": 124466} | fun main(){
class Valve(var flow: Int, var next: List<String>)
fun parseInput(input: List<String>): MutableMap<String, Valve> {
val valves: MutableMap<String, Valve> = mutableMapOf()
for (line in input){
val name = line.split(" ")[1]
val flow = line.filter { it.isDigit()... | 0 | Kotlin | 0 | 0 | a0bc190b391585ce3bb6fe2ba092fa1f437491a6 | 6,808 | aoc22 | Apache License 2.0 |
src/Day05.kt | maewCP | 579,203,172 | false | {"Kotlin": 59412} | fun main() {
fun _process(inputStack: List<String>, inputCmd: List<String>, reverse: Boolean) : String {
val stacks = mutableListOf<MutableList<Char>>()
inputStack.forEachIndexed { lineIdx, line ->
(0 until (line.length + 1) / 4).forEach { i ->
if (lineIdx == 0) {
... | 0 | Kotlin | 0 | 0 | 8924a6d913e2c15876c52acd2e1dc986cd162693 | 1,833 | advent-of-code-2022-kotlin | Apache License 2.0 |
leetcode/UniquePathsTwo.kt | jjrodcast | 175,520,504 | false | null | /*
Enlace al problema:
https://leetcode.com/problems/unique-paths-ii/
La solución se encuentra dentro de la función `uniquePathsWithObstacles`, el resto del código es para
ejecutarlo de manera local.
Explanation:
Given the grid:
[0,0,0]
[0,1,0]
[0,0,0]
Initial informatio... | 0 | Kotlin | 1 | 1 | a91868c3d24ad164fa637a8b3d682ec70d7ed7aa | 2,718 | CompetitiveProblems | MIT License |
src/main/kotlin/de/startat/aoc2023/Day4.kt | Arondc | 727,396,875 | false | {"Kotlin": 194620} | package de.startat.aoc2023
import kotlin.math.pow
data class Scratchcard(
val cardNumber: Int,
val winningNumbers: List<Int>,
val scratchedNumbers: List<Int>,
var numberOfCopiesOwned: Int = 1
) {
val matchingNumbers = winningNumbers.count { wn -> scratchedNumbers.contains(wn) }
fun copiesWon(... | 0 | Kotlin | 0 | 0 | 660d1a5733dd533aff822f0e10166282b8e4bed9 | 26,435 | AOC2023 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/_2022/Day4.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2022
import aoc
import parseInput
import java.util.regex.Pattern
private val REGEX = Pattern.compile("(\\d+)-(\\d+),(\\d+)-(\\d+)")
fun main() {
aoc(2022, 4) {
aocRun { input ->
process(input, ::hasFullyContainedSections)
}
aocRun { input ->
process(input, ::hasOverlappedSections)
}
}
}
pri... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 1,202 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Utils.kt | buczebar | 572,864,830 | false | {"Kotlin": 39213} | import java.io.File
import java.lang.IllegalArgumentException
import kotlin.math.abs
/**
* Reads lines from the given input txt file.
*/
fun readInput(name: String) = File("src", "$name.txt")
.readLines()
/**
* Reads input separated by empty line
*/
fun readGroupedInput(name: String) = File("src", "$name.txt"... | 0 | Kotlin | 0 | 0 | cdb6fe3996ab8216e7a005e766490a2181cd4101 | 2,144 | advent-of-code | Apache License 2.0 |
src/aoc22/Day16.kt | mihassan | 575,356,150 | false | {"Kotlin": 123343} | @file:Suppress("PackageDirectoryMismatch")
package aoc22.day16
import kotlin.math.max
import kotlin.math.min
import lib.Collections.headTail
import lib.Solution
import lib.Strings.extractLongs
typealias RoomLabel = String
typealias Distance = Long
data class Room(val label: RoomLabel, val flowRate: Long, val tunne... | 0 | Kotlin | 0 | 0 | 698316da8c38311366ee6990dd5b3e68b486b62d | 5,146 | aoc-kotlin | Apache License 2.0 |
src/Day03.kt | BjornstadThomas | 572,616,128 | false | {"Kotlin": 9666} | fun main() {
fun getValueOfChar(char: Char): Int {
// println(char)
if (char.toInt() in 97..122)
return char.toInt() - 96 //Fjerner 96 fra verdien, da ASCII for Liten bokstav, starter på 97 (a)
else
return char.toInt() - 38 //Fjerner kun 38, da ASCII for Stor boksta... | 0 | Kotlin | 0 | 0 | 553e3381ca26e1e316ecc6c3831354928cf7463b | 2,499 | AdventOfCode-2022-Kotlin | Apache License 2.0 |
src/Day13.kt | zfz7 | 573,100,794 | false | {"Kotlin": 53499} | import java.lang.Exception
fun main() {
println(day13A(readFile("Day13")))
println(day13B(readFile("Day13")))
}
private fun sort(a: List<Any>, b: List<Any>): Int {
try {
isSmaller(a, b)
} catch (e: Exception) {
if (e.message == "true") {
return -1
}
if (e.me... | 0 | Kotlin | 0 | 0 | c50a12b52127eba3f5706de775a350b1568127ae | 4,059 | AdventOfCode22 | Apache License 2.0 |
src/Day03.kt | undermark5 | 574,819,802 | false | {"Kotlin": 67472} | fun main() {
fun part1(input: List<String>): Int {
val intList = input.flatMap {
val size = it.length / 2
val first = it.take(size).toSet()
val second = it.takeLast(size).toSet()
val intersect = first.intersect(second)
check(intersect.size == 1)
... | 0 | Kotlin | 0 | 0 | e9cf715b922db05e1929f781dc29cf0c7fb62170 | 1,271 | AoC_2022_Kotlin | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2015/Day13.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2015
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.permutations
import com.chriswk.aoc.util.report
class Day13 : AdventDay(2015, 13) {
companion object {
val happinessLine = """(.+) would (lose|gain) (\d+) happiness units by sitting next to (.+).""".toRegex()
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,284 | adventofcode | MIT License |
src/main/kotlin/Excercise03.kt | underwindfall | 433,989,850 | false | {"Kotlin": 55774} | private fun part1() {
val input = getInputAsTest("03") { split("\n") }
val length = input.first().length
val gamma =
(0 until length).map { input.countBits(it) }.joinToString("") { (zeros, ones) ->
if (zeros > ones) "0" else "1"
}
val epsilon = gamma.map { if (it == '0') "1" else "0" }.joinToStri... | 0 | Kotlin | 0 | 0 | 4fbee48352577f3356e9b9b57d215298cdfca1ed | 1,211 | advent-of-code-2021 | MIT License |
codechef/snackdown2021/preelim/decsubk.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codechef.snackdown2021.preelim
private fun solve(): IntArray {
val (_, k) = readInts()
val a = readInts().sorted()
val b = IntArray(a.size)
val used = BooleanArray(a.size)
for (x in a.indices) {
fun isGood(i: Int): Boolean {
b[x] = a[i]
var y = x + 1
for (j in a.indices) if (!used[j] && j != i)... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,154 | competitions | The Unlicense |
src/Day03.kt | Feketerig | 571,677,145 | false | {"Kotlin": 14818} | fun main(){
fun priority(char: Char): Int{
return if (char < 'a') char - 'A' + 1 + 26 else char - 'a' + 1
}
fun findCommonElement(line: String): Int {
val firstHalf = line.subSequence(0, line.length / 2).toSet()
val secondHalf = line.subSequence(line.length / 2, line.length).toSet(... | 0 | Kotlin | 0 | 0 | c65e4022120610d930293788d9584d20b81bc4d7 | 1,301 | Advent-of-Code-2022 | Apache License 2.0 |
src/Day07.kt | emanguy | 573,113,840 | false | {"Kotlin": 17921} | import java.lang.IllegalArgumentException
import java.util.Stack
sealed class FSEntity {
data class Directory(
val name: String,
val parent: Directory? = null,
val children: MutableList<FSEntity> = mutableListOf()
) : FSEntity() {
private var cachedSize: Long? = null
f... | 0 | Kotlin | 0 | 1 | 211e213ec306acc0978f5490524e8abafbd739f3 | 3,898 | advent-of-code-2022 | Apache License 2.0 |
aoc-2022/src/main/kotlin/nerok/aoc/aoc2022/day07/Day07_alt.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 part1(input: String): Long {
val root = Directory("/", null, emptyList<FSNode>().toMutableList())
var pwd = root
input.lines().drop(1).forEach { lin... | 0 | Kotlin | 0 | 0 | 7553c28ac9053a70706c6af98b954fbdda6fb5d2 | 1,933 | AOC | Apache License 2.0 |
src/Day04.kt | mpylypovych | 572,998,434 | false | {"Kotlin": 6455} | fun main() {
fun contains(x: List<Int>, y: List<Int>) = y.all { x.first() <= it && x.last() >= it }
fun containsAny(x: List<Int>, y: List<Int>) = y.any { x.first() <= it && x.last() >= it }
fun solve(input: List<String>, pred : (List<Int>, List<Int>) -> Boolean) =
input.map {
it.split(... | 0 | Kotlin | 0 | 0 | 733b35c3f4eea777a5f666c804f3c92d0cc9854b | 869 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day17.kt | cypressious | 572,898,685 | false | {"Kotlin": 77610} | fun main() {
data class P(val x: Int, val y: Int)
val rocks = listOf(
// -
listOf(P(0, 0), P(1, 0), P(2, 0), P(3, 0)),
// +
listOf(P(1, 0), P(0, 1), P(1, 1), P(2, 1), P(1, 2)),
// reverse L
listOf(P(0, 0), P(1, 0), P(2, 0), P(2, 1), P(2, 2)),
// reverse I... | 0 | Kotlin | 0 | 1 | 7b4c3ee33efdb5850cca24f1baa7e7df887b019a | 3,136 | AdventOfCode2022 | Apache License 2.0 |
src/day11/Code.kt | ldickmanns | 572,675,185 | false | {"Kotlin": 48227} | package day11
import readInput
import java.util.*
fun main() {
val input = readInput("day11/input")
// val input = readInput("day11/input_test")
println(part1(input))
println(part2(input))
}
typealias WorryLevel = Long
data class Monkey(
val items: Deque<WorryLevel>,
val operation: (WorryLev... | 0 | Kotlin | 0 | 0 | 2654ca36ee6e5442a4235868db8174a2b0ac2523 | 4,263 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/day12/Day12.kt | daniilsjb | 572,664,294 | false | {"Kotlin": 69004} | package day12
import java.io.File
fun main() {
val data = parse("src/main/kotlin/day12/Day12.txt")
val answer1 = part1(data)
val answer2 = part2(data)
println("🎄 Day 12 🎄")
println()
println("[Part 1]")
println("Answer: $answer1")
println()
println("[Part 2]")
println("... | 0 | Kotlin | 0 | 0 | 6f0d373bdbbcf6536608464a17a34363ea343036 | 2,573 | advent-of-code-2022 | MIT License |
src/Day03.kt | maewCP | 579,203,172 | false | {"Kotlin": 59412} | fun main() {
fun getPriority(itemType: Char): Int {
return if (itemType >= 'a') itemType - 'a' + 1 else itemType - 'A' + 27
}
fun part1(input: List<String>): Int {
var priorities = 0
input.forEach { line ->
val first = line.substring(0, line.length / 2)
val ... | 0 | Kotlin | 0 | 0 | 8924a6d913e2c15876c52acd2e1dc986cd162693 | 1,285 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day14.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day14_test")
.parseScanReport()
val testInputResult = part1(testInput)
println(testInputResult)
check(testInputResult == 24)
val input = readInput("Day14")
.parseScanRepo... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 3,422 | aoc22-kotlin | Apache License 2.0 |
src/Day03.kt | l8nite | 573,298,097 | false | {"Kotlin": 105683} | fun main() {
fun score(c: Char): Int {
return if (c.isLowerCase()) {
c.code - 'a'.code + 1 // 1-26
} else {
c.code - 'A'.code + 27 // 27-52
}
}
fun shareChar(list: List<String>): Set<Char> {
val frequencyMap = mutableMapOf<Char, Int>()
list.f... | 0 | Kotlin | 0 | 0 | f74331778fdd5a563ee43cf7fff042e69de72272 | 1,202 | advent-of-code-2022 | Apache License 2.0 |
src/day08/Day08.kt | martin3398 | 572,166,179 | false | {"Kotlin": 76153} | package day08
import readInput
fun main() {
fun part1(input: Array<IntArray>): Int {
val width = input.size
val height = input[0].size
val visible = Array(height) {
BooleanArray(width) {
false
}
}
for (i in 0 until height) {
... | 0 | Kotlin | 0 | 0 | 4277dfc11212a997877329ac6df387c64be9529e | 3,605 | advent-of-code-2022 | Apache License 2.0 |
2022/src/day21/Day21.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day21
import java.io.File
fun main() {
val monkeys = Monkey.parse(File("src/day21/day21input.txt").readLines())
val rootMonkey = monkeys["root"]
println("${monkeys.size}")
println(rootMonkey!!.getValue(monkeys))
println(findHumanValue(monkeys))
}
fun findHumanValue(monkeys: Map<String, M... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 2,783 | adventofcode | Apache License 2.0 |
src/Day23.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | import java.util.Set.of as setOf
object Day23 {
private data class Pos(val x: Int, val y: Int) {
fun move(direction: Direction): Pos {
return when (direction) {
Direction.SOUTH -> Pos(x, y + 1)
Direction.WEST -> Pos(x - 1, y)
Direction.NORTH -> Po... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 4,576 | aoc2022 | Apache License 2.0 |
src/Day10.kt | nguyendanv | 573,066,311 | false | {"Kotlin": 18026} | fun main() {
fun part1(input: List<String>): Int {
var cycle = 1
var x = 1
return input
.map { it.split(" ") }
.flatMap { instr ->
val cyclesToExecute = when (instr[0]) {
"noop" -> 1
"addx" -> 2
... | 0 | Kotlin | 0 | 0 | 376512583af723b4035b170db1fa890eb32f2f0f | 2,477 | advent2022 | Apache License 2.0 |
src/Day02.kt | RusticFlare | 574,508,778 | false | {"Kotlin": 78496} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
when (it.last()) {
'X' -> 1 + when (it.first()) {
'A' -> 3
'B' -> 0
'C' -> 6
else -> error("first: ${it.first()}")
... | 0 | Kotlin | 0 | 1 | 10df3955c4008261737f02a041fdd357756aa37f | 1,984 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/2021/Day4_2.kts | Ozsie | 318,802,874 | false | {"Kotlin": 99344, "Python": 1723, "Shell": 975} | import java.io.File
import kotlin.collections.HashMap
import kotlin.collections.ArrayList
class Box(val value: Int, val x: Int, val y: Int, var selected: Boolean = false)
class Board(val boxes: ArrayList<Box>, var order: Int = -1, var winningNumber: Int = 1) {
public var competing = true
fun selectIf(number: ... | 0 | Kotlin | 0 | 0 | d938da57785d35fdaba62269cffc7487de67ac0a | 1,803 | adventofcode | MIT License |
src/main/kotlin/com/github/michaelbull/advent2023/day22/BrickSnapshot.kt | michaelbull | 726,012,340 | false | {"Kotlin": 195941} | package com.github.michaelbull.advent2023.day22
import com.github.michaelbull.advent2023.math.Vector3
fun Sequence<String>.toBrickSnapshot(): BrickSnapshot {
return BrickSnapshot(this.map(String::toBrick).toList())
}
data class BrickSnapshot(
val bricks: List<Brick>,
) {
private val bricksSortedUpwards ... | 0 | Kotlin | 0 | 1 | ea0b10a9c6528d82ddb481b9cf627841f44184dd | 1,814 | advent-2023 | ISC License |
implementation/src/main/kotlin/io/github/tomplum/aoc/map/forest/ForestMap.kt | TomPlum | 724,225,748 | false | {"Kotlin": 141244} | package io.github.tomplum.aoc.map.forest
import io.github.tomplum.libs.math.Direction
import io.github.tomplum.libs.math.map.AdventMap2D
import io.github.tomplum.libs.math.point.Point2D
class ForestMap(data: List<String>): AdventMap2D<ForestTile>() {
private val startingPosition: Point2D
private val targetDe... | 0 | Kotlin | 0 | 1 | d1f941a3c5bacd126177ace6b9f576c9af07fed6 | 4,472 | advent-of-code-2023 | Apache License 2.0 |
advent23-kt/app/src/main/kotlin/dev/rockyj/advent_kt/Day11.kt | rocky-jaiswal | 726,062,069 | false | {"Kotlin": 41834, "Ruby": 2966, "TypeScript": 2848, "JavaScript": 830, "Shell": 455, "Dockerfile": 387} | package dev.rockyj.advent_kt
private fun maxX(symbols: MutableMap<Pair<Int, Int>, String>): Int {
var x = 0
symbols.forEach {
if (it.key.second > x) {
x = it.key.second
}
}
return x
}
private fun maxY(symbols: MutableMap<Pair<Int, Int>, String>): Int {
var y = 0
sym... | 0 | Kotlin | 0 | 0 | a7bc1dfad8fb784868150d7cf32f35f606a8dafe | 2,633 | advent-2023 | MIT License |
src/main/kotlin/day02/Solution.kt | kcchoate | 683,597,644 | false | {"Kotlin": 25162} | package day02
class Solution {
fun navigate(input: List<String>) =
input.map { it.split(' ') }
.map { Instruction(it[0], it[1].toInt()) }
.fold(Result(0, 0)) { acc, instruction ->
when (instruction.direction) {
"up" -> Result(acc.horizontal, acc.d... | 0 | Kotlin | 0 | 1 | 3e7c24bc69a4de168ce0bdff855323c803b9a9a8 | 2,494 | advent-of-kotlin | MIT License |
src/algorithmsinanutshell/LineSweepAlgorithm.kt | realpacific | 234,499,820 | false | null | package algorithmsinanutshell
import kotlin.math.max
import kotlin.math.min
import kotlin.test.assertTrue
/**
* Given a number of lines, find the lines that intersects with each other
*
* Starting from left, sweep a vertical line through each point. Find the intersection of lines with each other
* that the vertic... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 4,492 | algorithms | MIT License |
src/Day07.kt | li-xin-yi | 573,617,763 | false | {"Kotlin": 23422} | import java.util.*
class Dir {
val children = mutableMapOf<String, Dir>()
var size = -1
}
fun main() {
fun getRootDir(input: List<String>): Dir {
val root = Dir()
val stack = Stack<Dir>()
var cur: Dir = root
for (line in input) {
val words = line.split(" ")
... | 0 | Kotlin | 0 | 1 | fb18bb7e462b8b415875a82c5c69962d254c8255 | 2,132 | AoC-2022-kotlin | Apache License 2.0 |
src/main/kotlin/g1201_1300/s1292_maximum_side_length_of_a_square_with_sum_less_than_or_equal_to_threshold/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1201_1300.s1292_maximum_side_length_of_a_square_with_sum_less_than_or_equal_to_threshold
// #Medium #Array #Binary_Search #Matrix #Prefix_Sum #Binary_Search_II_Day_15
// #2023_06_08_Time_376_ms_(100.00%)_Space_50.6_MB_(100.00%)
class Solution {
fun maxSideLength(mat: Array<IntArray>, threshold: Int): Int... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,257 | LeetCode-in-Kotlin | MIT License |
src/Day04.kt | Totwart123 | 573,119,178 | false | null | fun main() {
fun String.getRangeFromElf() : IntRange{
val elf = this.split("-").map { it.toInt() }
return IntRange(elf[0], elf[1])
}
fun part1(input: List<String>): Int {
var doubleCount = 0
input.forEach { pair->
val splitted = pair.split(",").map { it.getRangeF... | 0 | Kotlin | 0 | 0 | 33e912156d3dd4244c0a3dc9c328c26f1455b6fb | 1,411 | AoC | Apache License 2.0 |
src/main/kotlin/day4.kt | danielfreer | 297,196,924 | false | null | import kotlin.time.ExperimentalTime
@ExperimentalTime
fun day4(input: List<String>): List<Solution> {
val range = input.first().split("-").map(String::toInt).let { it.first()..it.last() }
return listOf(
solve(4, 1) { possiblePasswords(range).size },
solve(4, 2) { possiblePasswordsRedux(range).... | 0 | Kotlin | 0 | 0 | 74371d15f95492dee1ac434f0bfab3f1160c5d3b | 1,920 | advent2019 | The Unlicense |
kotlin/src/main/kotlin/com/github/jntakpe/aoc2022/days/Day2.kt | jntakpe | 572,853,785 | false | {"Kotlin": 72329, "Rust": 15876} | package com.github.jntakpe.aoc2022.days
import com.github.jntakpe.aoc2022.shared.Day
import com.github.jntakpe.aoc2022.shared.readInputLines
object Day2 : Day {
override val input: List<Pair<Char, Char>> = readInputLines(2).map { l -> l.split("\\s".toRegex()).let { it.first().first() to it.last().first() } }
... | 1 | Kotlin | 0 | 0 | 63f48d4790f17104311b3873f321368934060e06 | 2,735 | aoc2022 | MIT License |
src/Day15.kt | mikemac42 | 573,071,179 | false | {"Kotlin": 45264} | import java.io.File
import kotlin.math.abs
fun main() {
val testInput = """Sensor at x=2, y=18: closest beacon is at x=-2, y=15
Sensor at x=9, y=16: closest beacon is at x=10, y=16
Sensor at x=13, y=2: closest beacon is at x=15, y=3
Sensor at x=12, y=14: closest beacon is at x=10, y=16
Sensor at x=10, y=20: closest ... | 0 | Kotlin | 1 | 0 | 909b245e4a0a440e1e45b4ecdc719c15f77719ab | 4,609 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/adventofcode2022/solution/day_13.kt | dangerground | 579,293,233 | false | {"Kotlin": 51472} | package adventofcode2022.solution
import adventofcode2022.util.batchedList
import adventofcode2022.util.readDay
fun main() {
Day13("13").solve()
}
class Day13(private val num: String) {
private val inputText = readDay(num)
fun solve() {
println("Day $num Solution")
println("* Part 1: ${... | 0 | Kotlin | 0 | 0 | f1094ba3ead165adaadce6cffd5f3e78d6505724 | 4,745 | adventofcode-2022 | MIT License |
src/main/kotlin/Day002.kt | ruffCode | 398,923,968 | false | null | object Day002 {
val sample = "1-3 b: cdefg"
private val passwordList = PuzzleInput("day002.txt").readLines()
@JvmStatic
fun main(args: Array<String>) {
println(partOne(passwordList))
println(partOneBetter(passwordList))
println(partTwo(passwordList))
println(partTwoBett... | 0 | Kotlin | 0 | 0 | 477510cd67dac9653fc61d6b3cb294ac424d2244 | 3,357 | advent-of-code-2020-kt | MIT License |
src/Day11.kt | cypressious | 572,916,585 | false | {"Kotlin": 40281} | fun main() {
fun parse(input: List<String>) =
input.map { it.toCharArray().mapTo(mutableListOf()) { c -> c - '0' } }
fun runCycle(grid: List<MutableList<Int>>): Int {
var sum = 0
val flashing = grid.map { BooleanArray(it.size) }
fun flash(y: Int, x: Int) {
sum++
... | 0 | Kotlin | 0 | 0 | 169fb9307a34b56c39578e3ee2cca038802bc046 | 2,017 | AdventOfCode2021 | Apache License 2.0 |
src/main/kotlin/Day5.kt | ueneid | 575,213,613 | false | null | class Day5(inputs: String) {
private val parsedInput = parse(inputs)
data class Command(val value: Int, val from: Int, val to: Int)
data class Input(val stackList: List<ArrayDeque<Char>>, val commandList: List<Command>)
private fun parse(inputs: String): Input {
val stackRegex = """(\[[A-Z]\]... | 0 | Kotlin | 0 | 0 | 743c0a7adadf2d4cae13a0e873a7df16ddd1577c | 2,837 | adventcode2022 | MIT License |
src/main/kotlin/com/richodemus/advent_of_code/two_thousand_sixteen/day4_rooms/Main.kt | RichoDemus | 75,489,317 | false | null | package com.richodemus.advent_of_code.two_thousand_sixteen.day4_rooms
import com.richodemus.advent_of_code.two_thousand_sixteen.toFile
import org.assertj.core.api.Assertions.assertThat
fun main(args: Array<String>) {
val validRooms = "day4/rooms.txt".toFile().readLines().map(::Room).filter(Room::valid)
val su... | 0 | Kotlin | 0 | 0 | 32655174f45808eb1530f00c4c49692310036395 | 2,447 | advent-of-code | Apache License 2.0 |
src/Day13.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | fun main() {
fun part1(input: List<Pair<ListOrNumber, ListOrNumber>>): Int {
return input.withIndex()
.filter { (_, p) -> isInRightOrder(p.first, p.second) >= 0
}
.sumOf { it.index + 1 }
}
fun part2(input: List<Pair<ListOrNumber, ListOrNumber>>): Int {
va... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 5,309 | aoc22-kotlin | Apache License 2.0 |
src/main/kotlin/nl/tiemenschut/aoc/y2023/day4.kt | tschut | 723,391,380 | false | {"Kotlin": 61206} | package nl.tiemenschut.aoc.y2023
import nl.tiemenschut.aoc.lib.dsl.aoc
import nl.tiemenschut.aoc.lib.dsl.day
import nl.tiemenschut.aoc.lib.dsl.parser.AsListOfStrings
import java.math.BigDecimal
import java.math.BigInteger
fun main() {
aoc(AsListOfStrings) {
puzzle { 2023 day 4 }
val whitespace = ... | 0 | Kotlin | 0 | 1 | a1ade43c29c7bbdbbf21ba7ddf163e9c4c9191b3 | 1,822 | aoc-2023 | The Unlicense |
2022/Day13/problems.kt | moozzyk | 317,429,068 | false | {"Rust": 102403, "C++": 88189, "Python": 75787, "Kotlin": 72672, "OCaml": 60373, "Haskell": 53307, "JavaScript": 51984, "Go": 49768, "Scala": 46794} | import java.io.File
import kotlin.math.min
fun main(args: Array<String>) {
val lines = File(args[0]).readLines()
println(problem1(lines))
println(problem2(lines))
}
fun problem1(lines: List<String>): Int {
val results = lines.windowed(3, 3).map { runCompare(it[0], it[1]) }
return results
... | 0 | Rust | 0 | 0 | c265f4c0bddb0357fe90b6a9e6abdc3bee59f585 | 4,797 | AdventOfCode | MIT License |
src/main/kotlin/day-05.kt | warriorzz | 434,696,820 | false | {"Kotlin": 16719} | package com.github.warriorzz.aoc
import java.nio.file.Files
import java.nio.file.Path
private fun main() {
println("Day 05:")
val ventMap: VentMap = Files.readAllLines(Path.of("./input/day-05.txt")).map {
val split = it.split(" ")
Vent(
split[0].split(",")[0].toInt(), split[0].spl... | 0 | Kotlin | 1 | 0 | 0143f59aeb8212d4ff9d65ad30c7d6456bf28513 | 2,290 | aoc-21 | MIT License |
src/Day18.kt | schoi80 | 726,076,340 | false | {"Kotlin": 83778} | import java.util.LinkedList
import kotlin.math.abs
data class DigPlan(
val d: Direction,
val v: Long,
val c: String? = null
)
fun String.toDirection(): Direction {
return when (this) {
"L", "2" -> Direction.LEFT
"R", "0" -> Direction.RIGHT
"U", "3" -> Direction.UP
"D", ... | 0 | Kotlin | 0 | 0 | ee9fb20d0ed2471496185b6f5f2ee665803b7393 | 4,098 | aoc-2023 | Apache License 2.0 |
src/main/kotlin/me/grison/aoc/y2021/Day08.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc.y2021
import me.grison.aoc.*
class Day08 : Day(8, 2021) {
override fun title() = "Seven Segment Search"
private val knownSegments = mapOf(2 to 1, 3 to 7, 4 to 4, 7 to 8)
override fun partOne() =
inputList.map { it.after(" | ").words() }
.fold(0) { acc, it ->
... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 2,455 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/questions/SortLinkedList.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import questions.common.LeetNode
import utils.assertIterableSame
/**
* Given the head of a linked list, return the list after sorting it in ascending order.
*
* [Source](https://leetcode.com/problems/sort-list/)
*/
@UseCommentAsDocumentation
private fun s... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 3,773 | algorithms | MIT License |
y2019/src/main/kotlin/adventofcode/y2019/Day19.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2019
import adventofcode.io.AdventSolution
import adventofcode.language.intcode.IntCodeProgram
import adventofcode.util.collections.cartesian
import adventofcode.util.vector.Direction
import adventofcode.util.vector.Vec2
fun main() = Day19.solve()
object Day19 : AdventSolution(2019, 19, "Tracto... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,912 | advent-of-code | MIT License |
src/Day04.kt | wedrychowiczbarbara | 573,185,235 | false | null | fun main() {
fun isOverlapCompletely(r: List<String>): Boolean{
return if (r[0].toInt() >= r[2].toInt() && r[1].toInt() <= r[3].toInt())
true
else
r[2].toInt() >= r[0].toInt() && r[3].toInt() <= r[1].toInt()
}
fun part1(input: List<String>): Int {
var suma=0
... | 0 | Kotlin | 0 | 0 | 04abc035c51649dffe1dde8a115d98640552a99d | 1,133 | AOC_2022_Kotlin | Apache License 2.0 |
src/year_2023/day_03/Day03.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2023.day_03
import readInput
import kotlin.math.max
import kotlin.math.min
data class PartNumber(
val lineNumber: Int,
val startPos: Int,
val endPos: Int,
val number: Int
)
fun String.containsSymbol(): Boolean {
return this.any { !it.isDigit() && it != '.' }
}
object Day03 {
/**... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 4,033 | advent_of_code | Apache License 2.0 |
src/twentytwo/Day09.kt | Monkey-Matt | 572,710,626 | false | {"Kotlin": 73188} | package twentytwo
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInputLines("Day09_test")
val part1 = part1(testInput)
println(part1)
check(part1 == 13)
val part2 = part2(testInput)
println(part2)
check(part2 == 1)
val testInp... | 1 | Kotlin | 0 | 0 | 600237b66b8cd3145f103b5fab1978e407b19e4c | 9,717 | advent-of-code-solutions | Apache License 2.0 |
src/Day20.kt | janbina | 112,736,606 | false | null | package Day20
import getInput
import kotlin.math.abs
import kotlin.test.assertEquals
fun main(args: Array<String>) {
val input = getInput(20).readLines()
.map { Regex("-?\\d+")
.findAll(it)
.map { it.value.toLong() }
.toList()
}
... | 0 | Kotlin | 0 | 0 | 71b34484825e1ec3f1b3174325c16fee33a13a65 | 1,930 | advent-of-code-2017 | MIT License |
src/Day14.kt | brigittb | 572,958,287 | false | {"Kotlin": 46744} |
private val sourceOfSand = Point(x = 500, y = 0)
private const val X_MAX_THRESHOLD = 1000
fun main() {
fun parse(input: List<String>) = input
.filter { it.isNotEmpty() }
.map {
it
.split(" -> ")
.map { coordinates ->
val (x, y) = co... | 0 | Kotlin | 0 | 0 | 470f026f2632d1a5147919c25dbd4eb4c08091d6 | 5,216 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day21/Solution2.kt | janneri | 572,969,955 | false | {"Kotlin": 99028} | package day21
import day21.MonkeyMath.calculateLeftValue
import day21.MonkeyMath.calculateRightValue
import util.readInput
data class MonkeyValue(
var name: String,
var leftName: String? = null,
var rightName: String? = null,
var mathOperation: String? = null,
var number: ULong? = null
)
data cla... | 0 | Kotlin | 0 | 0 | 1de6781b4d48852f4a6c44943cc25f9c864a4906 | 5,406 | advent-of-code-2022 | MIT License |
dataStructuresAndAlgorithms/src/main/java/dev/funkymuse/datastructuresandalgorithms/sort/MergeSortSentinel.kt | FunkyMuse | 168,687,007 | false | {"Kotlin": 1728251} | package dev.funkymuse.datastructuresandalgorithms.sort
/**
* Merge Sort using Sentinels - Int.MAX_VALUE entries when merging lists.
* Allows to eliminate checks for whether the left/right list are fully added to the original list.
* Performs better than plain merge sort at the cost of extra O(2 (log N)) auxiliary m... | 0 | Kotlin | 92 | 771 | e2afb0cc98c92c80ddf2ec1c073d7ae4ecfcb6e1 | 2,462 | KAHelpers | MIT License |
src/main/kotlin/Day8.kt | i-redbyte | 433,743,675 | false | {"Kotlin": 49932} | private const val SHOW_1_COUNT = 2
private const val SHOW_4_COUNT = 4
private const val SHOW_7_COUNT = 3
private const val SHOW_8_COUNT = 7
private typealias Display = Pair<List<String>, List<String>>
fun main() {
val data = readInputFile("day8")
val initialState: List<Display> = data.map { line ->
li... | 0 | Kotlin | 0 | 0 | 6d4f19df3b7cb1906052b80a4058fa394a12740f | 2,146 | AOC2021 | Apache License 2.0 |
src/year2023/day01/Day.kt | tiagoabrito | 573,609,974 | false | {"Kotlin": 73752} | package year2023.day01
import year2023.solveIt
fun main() {
val day = "01"
val expectedTest1 = 142L
val expectedTest2 = 281L
fun part1(input: List<String>): Long {
return input.sumOf { line -> Integer.valueOf(line.first { it in '0'..'9' }.toString() + line.last { it in '0'..'9' }.toString()... | 0 | Kotlin | 0 | 0 | 1f9becde3cbf5dcb345659a23cf9ff52718bbaf9 | 1,297 | adventOfCode | Apache License 2.0 |
src/Day10.kt | aaronbush | 571,776,335 | false | {"Kotlin": 34359} | fun main() {
fun process(input: List<String>): List<Int> {
var xreg = 1
var cycleCount = 0
val regHistory = mutableListOf(xreg)
input.forEach { line ->
when (val op = line.substringBefore(" ")) {
"addx" -> {
val arg = line.substringAfte... | 0 | Kotlin | 0 | 0 | d76106244dc7894967cb8ded52387bc4fcadbcde | 2,477 | aoc-2022-kotlin | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.