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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2021/src/day15/Solution.kt | vadimsemenov | 437,677,116 | false | {"Kotlin": 56211, "Rust": 37295} | package day15
import java.nio.file.Files
import java.nio.file.Paths
import java.util.TreeSet
import kotlin.system.measureTimeMillis
fun main() {
fun part1(input: Input): Int {
val costs = Array(input.size) {
IntArray(input[it].size) { Int.MAX_VALUE }
}
val priorityQueue = TreeSet(
Comparator... | 0 | Kotlin | 0 | 0 | 8f31d39d1a94c862f88278f22430e620b424bd68 | 2,004 | advent-of-code | Apache License 2.0 |
arrays/AddingTwoNegabinaryNumbers/kotlin/Solution.kt | YaroslavHavrylovych | 78,222,218 | false | {"Java": 284373, "Kotlin": 35978, "Shell": 2994} | import kotlin.math.sign
import java.lang.Integer.max
/**
* 1073. Adding Two Negabinary Numbers.
* <br>
* Given two numbers arr1 and arr2 in base -2, return the result
* of adding them together.
* Each number is given in array format: as an array of 0s and 1s,
* from most significant bit to least significant b... | 0 | Java | 0 | 2 | cb8e6f7e30563e7ced7c3a253cb8e8bbe2bf19dd | 2,535 | codility | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1444/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1444
/**
* LeetCode page: [1444. Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza/);
*/
class Solution {
private val mod = 1_000_000_007
/* Complexity:
* Time O(kMN(M+N)) and Space O(MN) where M and N are the numbe... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 4,039 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/java/com/barneyb/aoc/aoc2022/day07/NoSpaceLeftOnDevice.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2022.day07
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toInt
import com.barneyb.aoc.util.toSlice
import java.util.*
fun main() {
Solver.benchmark(
::parse,
::partOne,
::partTwo,
)
}
internal fun parse(input: String): IntArray {
val lis... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 1,742 | aoc-2022 | MIT License |
src/Day2/Day02.kt | lukeqwas | 573,403,156 | false | null | package Day2
import readInput
import java.lang.IllegalArgumentException
val ROCK_POINTS = 1
val PAPER_POINTS = 2
val SCISSORS_POINTS = 3
fun main() {
val testInput = readInput("Day2/Day02")
var totalPoints = 0L
val rockNode = Node("A", null, null)
val paperNode = Node("B", rockNode, null)
val sci... | 0 | Kotlin | 0 | 0 | 6174a8215f8d4dc6d33fce6f8300a4a8999d5431 | 2,264 | aoc-kotlin-2022 | Apache License 2.0 |
src/Day03.kt | zsmb13 | 572,719,881 | false | {"Kotlin": 32865} | fun main() {
fun Char.toPriority(): Int {
return when (this) {
in 'a'..'z' -> this - 'a' + 1
in 'A'..'Z' -> this - 'A' + 27
else -> error("Invalid char $this")
}
}
fun part1(input: List<String>): Int {
return input.sumOf { line ->
val... | 0 | Kotlin | 0 | 6 | 32f79b3998d4dfeb4d5ea59f1f7f40f7bf0c1f35 | 1,086 | advent-of-code-2022 | Apache License 2.0 |
2021/src/day03/Solution.kt | vadimsemenov | 437,677,116 | false | {"Kotlin": 56211, "Rust": 37295} | package day03
import java.nio.file.Files
import java.nio.file.Paths
fun main() {
fun part1(numbers: List<String>): Int {
val count = IntArray(numbers[0].length)
for (num in numbers) {
for ((index, bit) in num.withIndex()) {
count[index] += if (bit == '1') 1 else 0
}
}
val gamma =... | 0 | Kotlin | 0 | 0 | 8f31d39d1a94c862f88278f22430e620b424bd68 | 1,776 | advent-of-code | Apache License 2.0 |
src/Day08.kt | Kbzinho-66 | 572,299,619 | false | {"Kotlin": 34500} | private typealias Forest = List<List<Int>>
private fun List<String>.toForest() = this.map { row -> row.map { it.digitToInt() } }
private fun isVisible(forest: Forest, row: Int, col: Int): Boolean {
// Árvores nas bordas são visíveis
if (row == 0 || row == forest.size - 1 || col == 0 || col == forest[row].size... | 0 | Kotlin | 0 | 0 | e7ce3ba9b56c44aa4404229b94a422fc62ca2a2b | 3,125 | advent_of_code_2022_kotlin | Apache License 2.0 |
year2022/src/main/kotlin/net/olegg/aoc/year2022/day18/Day18.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2022.day18
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.Vector3D
import net.olegg.aoc.utils.parseInts
import net.olegg.aoc.year2022.DayOf2022
/**
* See [Year 2022, Day 18](https://adventofcode.com/2022/day/18)
*/
object Day18 : DayOf2022(18) {
private val DIRS = listOf... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,798 | adventofcode | MIT License |
src/aoc2021/Day12.kt | dayanruben | 433,250,590 | false | {"Kotlin": 79134} | package aoc2021
import readInput
fun main() {
val (year, day) = "2021" to "Day12"
fun buildMap(input: List<String>): Map<String, Set<String>> {
val map = mutableMapOf<String, MutableSet<String>>()
input.forEach { line ->
val (a, b) = line.split("-")
map.getOrPut(a) { m... | 1 | Kotlin | 2 | 30 | df1f04b90e81fbb9078a30f528d52295689f7de7 | 2,089 | aoc-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day15.kt | andilau | 429,557,457 | false | {"Kotlin": 103829} | package days
@AdventOfCodePuzzle(
name = "Science for Hungry People",
url = "https://adventofcode.com/2015/day/15",
date = Date(day = 15, year = 2015)
)
class Day15(input: List<String>) : Puzzle {
private val ingredients = input.map(Ingredient::from)
override fun partOne(): Int =
combinati... | 0 | Kotlin | 0 | 0 | 55932fb63d6a13a1aa8c8df127593d38b760a34c | 2,465 | advent-of-code-2015 | Creative Commons Zero v1.0 Universal |
src/practice1.kt | dustinlewis | 572,792,391 | false | {"Kotlin": 29162} | fun main() {
// Works
fun part1(input: List<String>): Int {
val result: Pair<Int, String> = input.fold(Pair(0, "")) {
acc, el -> Pair(if (el > acc.second) acc.first + 1 else acc.first, el)
}
return result.first
}
// one short
// fun part1(input: List<String>): Int... | 0 | Kotlin | 0 | 0 | c8d1c9f374c2013c49b449f41c7ee60c64ef6cff | 1,206 | aoc-2022-in-kotlin | Apache License 2.0 |
kotlin/largest-series-product/src/main/kotlin/Series.kt | ikr | 147,076,927 | false | {"C++": 22451113, "Kotlin": 136005, "CMake": 90716, "Java": 30028} | data class Series(val s: String) {
init {
require(Regex("^[0-9]*$") matches s)
}
fun getLargestProduct(length: Int): Int {
require(length <= s.length)
val subSeqs = s.split("0").filter {it != ""}
val subSolutions = subSeqs.map {largestProductOfNonZeroes(digits(it), length)}... | 0 | C++ | 0 | 0 | 37f505476ae13dd003c1de24b5113a0d7e94aaf2 | 925 | exercism | MIT License |
leetcode/src/array/Offer11.kt | zhangweizhe | 387,808,774 | false | null | package array
fun main() {
// 剑指 Offer 11. 旋转数组的最小数字
// https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/
// println(minArray3(intArrayOf(3,1,1)))
// println(maxArray(intArrayOf(4,5,6,1,2,3)))
// println(maxArray(intArrayOf(1,2,3,4,5,6)))
// println(maxArray(intArrayOf(3,... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 3,671 | kotlin-study | MIT License |
22.kt | pin2t | 725,922,444 | false | {"Kotlin": 48856, "Go": 48364, "Shell": 54} | import kotlin.math.max
import kotlin.math.min
val bricks = ArrayList<Brick>()
data class Brick (val s: Triple<Int, Int, Int>, val e: Triple<Int, Int, Int>) {
fun intersect(other: Brick): Boolean {
return max(s.first, other.s.first) <= min(e.first, other.e.first) &&
max(s.second, other.s.se... | 0 | Kotlin | 1 | 0 | 7575ab03cdadcd581acabd0b603a6f999119bbb6 | 1,795 | aoc2023 | MIT License |
src/main/kotlin/day5/HydroVents.kt | Arch-vile | 433,381,878 | false | {"Kotlin": 57129} | package day5
import utils.Line
import utils.Point
import utils.Matrix
import utils.pointsInLine
import utils.read
fun main() {
solve()
.let { println(it) }
}
fun solve(): List<Int> {
val lines = read("./src/main/resources/day5Input.txt")
.map { it.split(" ") }
.map { line ->
... | 0 | Kotlin | 0 | 0 | 4cdafaa524a863e28067beb668a3f3e06edcef96 | 1,239 | adventOfCode2021 | Apache License 2.0 |
src/day03/Day03.kt | TheRishka | 573,352,778 | false | {"Kotlin": 29720} | package day03
import readInput
fun main() {
val scoringMap = buildMap {
var scoreChar = 'a'
var score = 1
while (scoreChar <= 'z') {
put(scoreChar, score)
++score
++scoreChar
}
scoreChar = 'A'
while (scoreChar <= 'Z') {
... | 0 | Kotlin | 0 | 1 | 54c6abe68c4867207b37e9798e1fdcf264e38658 | 2,686 | AOC2022-Kotlin | Apache License 2.0 |
src/day04/Day04.kt | jacobprudhomme | 573,057,457 | false | {"Kotlin": 29699} | import java.io.File
fun main() {
fun readInput(name: String) = File("src/day04", name)
.readLines()
fun processInput(line: String): Pair<Pair<Int, Int>, Pair<Int, Int>> {
val (range1, range2, _) = line.split(",").map { range ->
range.split("-").map { it.toInt() }.let { (start, end,... | 0 | Kotlin | 0 | 1 | 9c2b080aea8b069d2796d58bcfc90ce4651c215b | 1,604 | advent-of-code-2022 | Apache License 2.0 |
y2015/src/main/kotlin/adventofcode/y2015/Day09.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2015
import adventofcode.io.AdventSolution
import adventofcode.util.collections.permutations
object Day09 : AdventSolution(2015, 9, "All in a Single Night") {
override fun solvePartOne(input: String) = tryAllRoutes(input).minOrNull().toString()
override fun solvePartTwo(input: String) = try... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,338 | advent-of-code | MIT License |
src/main/kotlin/d22/d22.kt | LaurentJeanpierre1 | 573,454,829 | false | {"Kotlin": 118105} | package d22
import readInput
enum class Direction(val x: Int, val y:Int) {Right(1,0), Down(0,1), Left(-1,0), Up(0,-1);
fun turnRight() : Direction = values()[(ordinal+1) % 4]
fun turnLeft() : Direction = values()[(ordinal+3) % 4]
}
fun part1(input: List<String>): Int {
val (board, instructions) = readPu... | 0 | Kotlin | 0 | 0 | 5cf6b2142df6082ddd7d94f2dbde037f1fe0508f | 7,344 | aoc2022 | Creative Commons Zero v1.0 Universal |
src/Day03.kt | lbilger | 574,227,846 | false | {"Kotlin": 5366} | fun main() {
fun Char.priority() = if (isUpperCase()) this - 'A' + 27 else this - 'a' + 1
fun part1(input: List<String>): Int {
return input.map { it.chunked(it.length / 2) }
.map { it[0].toSet().intersect(it[1].toSet()).single() }
.sumOf { it.priority() }
}
fun part2(i... | 0 | Kotlin | 0 | 0 | 40d94a4bb9621af822722d20675684555cbee877 | 903 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day09.kt | aneroid | 572,802,061 | false | {"Kotlin": 27313} | import kotlin.math.absoluteValue
import kotlin.math.sign
private data class Point(val x: Int, val y: Int) {
override fun toString() = "P($x, $y)"
}
class Day09(private val input: List<String>) {
private val steps = parseInput(input)
private fun Pair<Int, Int>.toPoint() = Point(first, second)
... | 0 | Kotlin | 0 | 0 | cf4b2d8903e2fd5a4585d7dabbc379776c3b5fbd | 3,476 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day16.kt | iam-afk | 572,941,009 | false | {"Kotlin": 33272} | import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
val tunnels = mutableMapOf<String, MutableList<String>>()
val rates = mutableMapOf<String, Int>()
val ids = mutableMapOf<String, Int>()
for ((id, line) in input.withIndex()) {
val t = line.split("... | 0 | Kotlin | 0 | 0 | b30c48f7941eedd4a820d8e1ee5f83598789667b | 4,571 | aockt | Apache License 2.0 |
solutions/aockt/y2021/Y2021D05.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
import kotlin.math.sign
object Y2021D05 : Solution {
/** Represents a discrete point in 2D space. */
private data class Point(val x: Int, val y: Int) {
operator fun plus(delta: Delta): Point = Point(x + delta.dx, y + delta.dy)
}
... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,313 | advent-of-code-kotlin-solutions | The Unlicense |
src/day05/Day05.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day05
import readInput
import java.lang.StringBuilder
fun main() {
fun getMap(input:List<String>):HashMap<Int,ArrayDeque<Char>> {
val crates = input.takeWhile { it.isNotEmpty() }
val stackIndexMap = hashMapOf<Int,Int>().also { map ->
crates.last().forEachIndexed { index, c ->... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 3,084 | aoc-2022-kotlin | Apache License 2.0 |
kotlin/day04.kt | bwestlin | 215,631,956 | false | null | package day04
import java.io.File
data class Room(val name: String, val sectorId: Int, val checkSum: String)
fun validChecksum(r: Room) = r.name
.filter { it >= 'a' }
.groupingBy { it }
.eachCount()
.toList()
.sortedWith(Comparator<Pair<Char, Int>> { (c1, n1), (c2, n2) ->
when {
... | 0 | Rust | 0 | 0 | 0c5d6aba42fbbe0225877d9c84b0c7af85a35c5d | 1,364 | advent-of-code-2016-retro | MIT License |
19.kt | pin2t | 725,922,444 | false | {"Kotlin": 48856, "Go": 48364, "Shell": 54} | data class Workflow (val rules: List<List<String>>, val default: String)
fun main() {
val workflows = HashMap<String, Workflow>()
val parts = ArrayList<Map<String, Int>>()
while (true) {
val l = readlnOrNull() ?: break
if (l.startsWith('{')) {
val part = HashMap<String, Int>()
... | 0 | Kotlin | 1 | 0 | 7575ab03cdadcd581acabd0b603a6f999119bbb6 | 3,080 | aoc2023 | MIT License |
src/main/kotlin/dev/tasso/adventofcode/_2022/day05/Day05.kt | AndrewTasso | 433,656,563 | false | {"Kotlin": 75030} | package dev.tasso.adventofcode._2022.day05
import dev.tasso.adventofcode.Solution
import java.util.ArrayDeque
class Day05 : Solution<String> {
override fun part1(input: List<String>): String {
val stacks = buildStacks(input.subList(0, input.indexOf("")))
val rearrangements = input.subList(input... | 0 | Kotlin | 0 | 0 | daee918ba3df94dc2a3d6dd55a69366363b4d46c | 2,554 | advent-of-code | MIT License |
src/test/kotlin/ch/ranil/aoc/aoc2022/Day08.kt | stravag | 572,872,641 | false | {"Kotlin": 234222} | package ch.ranil.aoc.aoc2022
import ch.ranil.aoc.aoc2022.Day08.Forrest.ViewDirection.*
import ch.ranil.aoc.AbstractDay
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
object Day08 : AbstractDay() {
@Test
fun tests() {
assertEquals(21, compute1(testInput))
assertEquals(1736, c... | 0 | Kotlin | 1 | 0 | dbd25877071cbb015f8da161afb30cf1968249a8 | 4,113 | aoc | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem368/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem368
/**
* LeetCode page: [368. Largest Divisible Subset](https://leetcode.com/problems/largest-divisible-subset/);
*/
class Solution {
/* Complexity:
* Time O(N^2) and Space O(N) where N is the size of nums;
*/
fun largestDivisibleSubset(nums: IntArray): List<I... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,553 | hj-leetcode-kotlin | Apache License 2.0 |
src/com/wd/algorithm/leetcode/ALGO0005.kt | WalkerDenial | 327,944,547 | false | null | package com.wd.algorithm.leetcode
import com.wd.algorithm.test
import kotlin.math.max
import kotlin.math.min
/**
* 5. 最长回文子串
*
* 给你一个字符串 s,找到 s 中最长的回文子串。
*
*/
class ALGO0005 {
/**
* 方式一:暴力解法
* 分别遍历每一个字符,向后找回文字符串,经过所有遍历后,得到最长回文子串
* 时间复杂度 T(n³)
*/
fun longestPalindrome1(s: String): Str... | 0 | Kotlin | 0 | 0 | 245ab89bd8bf467625901034dc1139f0a626887b | 3,867 | AlgorithmAnalyze | Apache License 2.0 |
kotlin/numbertheory/Factorization.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package numbertheory
import java.util.stream.Collectors.summingInt
object Factorization {
// returns prime_divisor -> power
// O(sqrt(n)) complexity
fun factorize(n: Long): Map<Long, Integer> {
var n = n
val factors: List<Long> = ArrayList()
var d: Long = 2
while (d * d <= ... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 2,409 | codelibrary | The Unlicense |
2023/day04-25/src/main/kotlin/Day13.kt | CakeOrRiot | 317,423,901 | false | {"Kotlin": 62169, "Python": 56994, "C#": 20675, "Rust": 10417} | import java.io.File
class Day13 {
val doubleNewLines = "(\r\n\r\n)|(\n\n)"
val newLines = "(\r\n)|(\n)"
fun solve1() {
val blocks = File("inputs/13.txt").inputStream().bufferedReader().use { it.readText() }
.split(doubleNewLines.toRegex()).map { it.split(newLines.toRegex()).filter { it.... | 0 | Kotlin | 0 | 0 | 8fda713192b6278b69816cd413de062bb2d0e400 | 2,357 | AdventOfCode | MIT License |
src/Day11.kt | astrofyz | 572,802,282 | false | {"Kotlin": 124466} | fun main() {
class Monkey(
var items: MutableList<Long> = mutableListOf(), var operation: String = "",
var test: Long = 1, var testTrue: Long = 0, var testFalse: Long = 1,
var business: Long = 0){
}
fun Long.update(operation: String): Long {
return if (('+' in operation)&&(... | 0 | Kotlin | 0 | 0 | a0bc190b391585ce3bb6fe2ba092fa1f437491a6 | 4,300 | aoc22 | Apache License 2.0 |
src/Day07.kt | petoS6 | 573,018,212 | false | {"Kotlin": 14258} | fun main() {
fun part1(lines: List<String>): Long {
val dirs = mutableListOf(Dir(null))
var current: Dir = dirs.first()
lines.drop(1).forEach { line ->
when {
line == "$ cd .." -> current = current.parent!!
line.startsWith("$ cd") -> { Dir(current).also { current.children += it; dir... | 0 | Kotlin | 0 | 0 | 40bd094155e664a89892400aaf8ba8505fdd1986 | 1,371 | kotlin-aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day01.kt | NielsSteensma | 572,641,496 | false | {"Kotlin": 11875} | fun main() {
val input = readInput("Day01")
println("Day 01 Part 1 ${calculateDay01Part1(input)}")
println("Day 01 Part 2 ${calculateDay01Part2(input)}")
}
fun calculateDay01Part1(input: List<String>): Int {
return calculateTotalCaloriesByElve(input)
.maxOf { it } // Grab elve who took most cal... | 0 | Kotlin | 0 | 0 | 4ef38b03694e4ce68e4bc08c390ce860e4530dbc | 963 | aoc22-kotlin | Apache License 2.0 |
src/main/kotlin/com/github/michaelbull/advent2021/day10/Day10.kt | michaelbull | 433,565,311 | false | {"Kotlin": 162839} | package com.github.michaelbull.advent2021.day10
import com.github.michaelbull.advent2021.Puzzle
object Day10 : Puzzle<Sequence<String>, Long>(day = 10) {
override fun parse(input: Sequence<String>): Sequence<String> {
return input
}
override fun solutions() = listOf(
::part1,
::p... | 0 | Kotlin | 0 | 4 | 7cec2ac03705da007f227306ceb0e87f302e2e54 | 2,619 | advent-2021 | ISC License |
src/Day01.kt | ajspadial | 573,864,089 | false | {"Kotlin": 15457} |
data class Elf(var sum: Int = 0) {
}
fun main() {
fun calculateCalories(input: List<String>): List<Elf> {
val elfs: MutableList<Elf> = mutableListOf()
var currentElf = Elf()
elfs.add(currentElf)
for (line in input) {
if (line == "") {
currentElf = Elf(... | 0 | Kotlin | 0 | 0 | ed7a2010008be17fec1330b41adc7ee5861b956b | 1,628 | adventofcode2022 | Apache License 2.0 |
src/Day04.kt | zhiqiyu | 573,221,845 | false | {"Kotlin": 20644} | import kotlin.math.max
import kotlin.math.abs
fun main() {
fun part1(input: List<String>): Int {
var result = 0
for (line in input) {
var pairs = line.split(",").map { it.split("-") }
var s1 = pairs.get(0).get(0).toInt()
var e1 = pairs.get(0).get(1).toInt()
... | 0 | Kotlin | 0 | 0 | d3aa03b2ba2a8def927b94c2b7731663041ffd1d | 1,378 | aoc-2022 | Apache License 2.0 |
dcp_kotlin/src/main/kotlin/dcp/day144/day144.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day144
// day144.kt
// By <NAME>, 2020.
import kotlin.math.abs
/**
* Given a list of elements elems and an index idx of one of the elements, find the index of the nearest element whose
* value is greater than elems[idx]. Ties may be broken arbitrarily.
*
* This algorithm runs in time O(n log n) due to... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 1,805 | daily-coding-problem | MIT License |
src/main/kotlin/days/Day24.kt | andilau | 433,504,283 | false | {"Kotlin": 137815} | package days
@AdventOfCodePuzzle(
name = "Arithmetic Logic Unit",
url = "https://adventofcode.com/2021/day/24",
date = Date(day = 24, year = 2021)
)
class Day24(listing: List<String>) : Puzzle {
private val monad = listing.filter(String::isNotEmpty).map { Instruction.parse(it) }
override fun partO... | 0 | Kotlin | 0 | 0 | b3f06a73e7d9d207ee3051879b83e92b049a0304 | 4,555 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
src/Day11.kt | TheGreatJakester | 573,222,328 | false | {"Kotlin": 47612} | package day11
import utils.readInputAsText
import utils.runSolver
import utils.string.asLines
import utils.string.asParts
private typealias SolutionType = Long
private const val defaultSolution = 0
private const val dayNumber: String = "11"
private val testSolution1: SolutionType? = 10605
private val testSolution2:... | 0 | Kotlin | 0 | 0 | c76c213006eb8dfb44b26822a44324b66600f933 | 3,922 | 2022-AOC-Kotlin | Apache License 2.0 |
2021/src/test/kotlin/Day08.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import kotlin.test.Test
import kotlin.test.assertEquals
class Day08 {
data class Note(val patterns: List<String>, val outputs: List<String>)
data class Display(val digit: Int, val segments: String)
private val displays = arrayOf(
Display(0, "abcefg".sorted()),
Display(1, "cf".sorted()),
... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 4,738 | adventofcode | MIT License |
2022/src/main/kotlin/Day18.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | import kotlin.math.abs
object Day18 {
fun part1(input: String) = surfaceArea(parseInput(input))
fun part2(input: String): Int {
val droplet = parseInput(input)
// Check every location within the droplet's bounds to see if it's in an air pocket or not
//
// This is not particularly efficient (we ... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 2,561 | advent-of-code | MIT License |
src/main/kotlin/leetCode/39.kt | wenvelope | 692,706,194 | false | {"Kotlin": 11474, "Java": 7490} | package leetCode
/**
* 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,
* 并以列表形式返回。你可以按 任意顺序 返回这些组合。
*
* candidates 中的 同一个 数字可以 无限制重复被选取 。如果至少一个数字的被选数量不同,则两种组合是不同的。
*
* 对于给定的输入,保证和为 target 的不同组合数少于 150 个。\
*
* 输入:candidates = [2,3,6,7], target = 7
* 输出:[[2,2,3],[7]]
* ... | 0 | Kotlin | 0 | 1 | 4a5b2581116944c5bf8cf5ab0ed0af410669b9b6 | 1,956 | OnlineJudge | Apache License 2.0 |
src/Day07.kt | davidkna | 572,439,882 | false | {"Kotlin": 79526} | fun main() {
fun parseInput(input: List<String>): HashMap<List<String>, Int> {
val fs = HashMap<List<String>, Int>()
var pwd = ArrayList<String>()
for (line in input) {
if (line.startsWith("$ cd")) {
when (val newLocation = line.removePrefix("$ cd ")) {
... | 0 | Kotlin | 0 | 0 | ccd666cc12312537fec6e0c7ca904f5d9ebf75a3 | 1,656 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/g1801_1900/s1818_minimum_absolute_sum_difference/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1818_minimum_absolute_sum_difference
// #Medium #Array #Sorting #Binary_Search #Ordered_Set #Binary_Search_II_Day_7
// #2023_06_20_Time_447_ms_(100.00%)_Space_53_MB_(100.00%)
import kotlin.math.abs
class Solution {
fun minAbsoluteSumDiff(nums1: IntArray, nums2: IntArray): Int {
var mi... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,623 | LeetCode-in-Kotlin | MIT License |
src/Day08.kt | ChrisCrisis | 575,611,028 | false | {"Kotlin": 31591} | import template.DailyChallenge
import template.InputData
class TreeGrid(
private val trees: Array<Array<Tree>>
){
private val sizeX by lazy { trees.first().size }
private val sizeY by lazy { trees.size }
fun getTreesVisibleFromOutside(): Int {
return trees.sumOf { treeLine ->
treeL... | 1 | Kotlin | 0 | 0 | 732b29551d987f246e12b0fa7b26692666bf0e24 | 3,378 | aoc2022-kotlin | Apache License 2.0 |
src/main/kotlin/year2022/Day11.kt | simpor | 572,200,851 | false | {"Kotlin": 80923} | import AoCUtils
import AoCUtils.test
enum class OperationValue { PLUS, TIMES, SQUARE }
fun main() {
data class Monkey(
val id: Long,
val operation: OperationValue,
val operationValue: Long,
val testValue: Long,
val testTrue: Long,
val testFalse: Long,
var c... | 0 | Kotlin | 0 | 0 | 631cbd22ca7bdfc8a5218c306402c19efd65330b | 5,369 | aoc-2022-kotlin | Apache License 2.0 |
src/Day13.kt | iam-afk | 572,941,009 | false | {"Kotlin": 33272} | sealed interface Packet : Comparable<Packet> {
@JvmInline
value class Integer(val data: Int) : Packet {
override fun compareTo(other: Packet): Int = when (other) {
is Integer -> data compareTo other.data
is List -> List(listOf(this)) compareTo other
}
}
@JvmInli... | 0 | Kotlin | 0 | 0 | b30c48f7941eedd4a820d8e1ee5f83598789667b | 3,466 | aockt | Apache License 2.0 |
src/Day04.kt | gylee2011 | 573,544,473 | false | {"Kotlin": 9419} | import kotlin.math.max
import kotlin.math.min
fun main() {
fun part1(input: List<String>): Int {
return input
.map {
it.split(',')
}
.map { (elf1, elf2) ->
val range1 = elf1.toRange()
val range2 = elf2.toRange()
... | 0 | Kotlin | 0 | 0 | 339e0895fd2484b7f712b966a0dae8a4cfebc2fa | 1,336 | aoc2022-kotlin | Apache License 2.0 |
src/day09/Day09.kt | jacobprudhomme | 573,057,457 | false | {"Kotlin": 29699} | import java.io.File
import java.lang.IllegalArgumentException
import kotlin.math.abs
typealias Pos = Pair<Int, Int>
enum class Direction {
UP,
RIGHT,
DOWN,
LEFT,
}
fun main() {
fun readInput(name: String) = File("src/day09", name)
.readLines()
fun convertToDirection(dirStr: String): ... | 0 | Kotlin | 0 | 1 | 9c2b080aea8b069d2796d58bcfc90ce4651c215b | 3,731 | advent-of-code-2022 | Apache License 2.0 |
2021/src/main/kotlin/day2_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.cut
import utils.mapItems
fun main() {
Day2Func.run()
}
object Day2Func : Solution<List<Pair<Day2Func.Direction, Int>>>() {
override val name = "day2"
override val parser = Parser.lines.mapItems { line -> line.cut(" ", Direction::valueOf, String::toInt) }
... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,374 | aoc_kotlin | MIT License |
src/Day04.kt | calindumitru | 574,154,951 | false | {"Kotlin": 20625} | fun main() {
val part1 = Implementation(
question = "In how many assignment pairs does one range fully contain the other?",
expectedAnswerForExample = 2
) { lines ->
val assignments = lines.map { convert(it) }
return@Implementation assignments.filter { it.fullyOverlaps() }.size
... | 0 | Kotlin | 0 | 0 | d3cd7ff5badd1dca2fe4db293da33856832e7e83 | 1,545 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/model/Oasis.kt | errob37 | 726,532,024 | false | {"Kotlin": 29748, "Shell": 408} | package days.model
class Oasis(
private val input: List<String>,
private val predictionMode: PredictionMode
) {
fun predictionSum() = input
.map { it.split(" ").map { s -> s.toLong() } }
.map { Report(it, predictionMode) }
.sumOf { it.predictValue() }
}
enum class PredictionMode {... | 0 | Kotlin | 0 | 0 | 79db6f0f56d207b68fb89425ad6c91667a84d60f | 1,928 | adventofcode-2023 | Apache License 2.0 |
src/main/kotlin/_2018/Day6.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2018
import aocRun
import forEachPoint
import java.awt.Point
import java.awt.Rectangle
import kotlin.math.abs
fun main() {
aocRun(puzzleInput) { input ->
val locations = processLocations(input)
// Create borders - we'll use border1 but then check against border2 later
val border1... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 3,607 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Day02.kt | juliantoledo | 570,579,626 | false | {"Kotlin": 34375} | fun main() {
/*
A for Rock, B for Paper, and C for Scissors
X for Rock, Y for Paper, and Z for Scissors
1 for Rock, 2 for Paper, and 3 for Scissors) plus the score for the outcome of the round
(0 if you lost, 3 if the round was a draw, and 6 if you won).
X means you need to lose, Y means you need to end the round in ... | 0 | Kotlin | 0 | 0 | 0b9af1c79b4ef14c64e9a949508af53358335f43 | 3,167 | advent-of-code-kotlin-2022 | Apache License 2.0 |
app/src/main/kotlin/de/tobiasdoetzer/aoc2021/Day5.kt | dobbsy | 433,868,809 | false | {"Kotlin": 13636} | package de.tobiasdoetzer.aoc2021
private fun part1(input: List<String>): Int {
val ventMap = VentMap()
for (s in input) {
val (p1String, p2String) = s.split(" -> ")
val (p1X, p1Y) = p1String.split(',').map(String::toInt)
val (p2X, p2Y) = p2String.split(',').map(String::toInt)
i... | 0 | Kotlin | 0 | 0 | 28f57accccb98d8c2949171cd393669e67789d32 | 3,604 | AdventOfCode2021 | Apache License 2.0 |
src/Day09.kt | jwklomp | 572,195,432 | false | {"Kotlin": 65103} | data class Pos(val x: Int, val y: Int)
data class Change(val x: Int, val y: Int)
data class MoveData(val knotPositions: MutableList<Pos>, var visited: MutableList<Pos>)
val directions = listOf("L", "R", "U", "D")
val directionTranslations = listOf(Change(-1, 0), Change(1, 0), Change(0, 1), Change(0, -1))
val sp = Pos(... | 0 | Kotlin | 0 | 0 | 1b1121cfc57bbb73ac84a2f58927ab59bf158888 | 3,668 | aoc-2022-in-kotlin | Apache License 2.0 |
src/2023/Day25.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2023`
import java.io.File
import java.util.*
fun main() {
Day25().solve()
}
class Day25 {
val input1 = """
jqt: rhn xhk nvd
rsh: frs pzl lsr
xhk: hfx
cmg: qnr nvd lhk bvb
rhn: xhk bvb hfx
bvb: xhk hfx
pzl: lsr hfx nvd
qnr: nvd
... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 5,693 | advent-of-code | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/array_to_bst/ArrayToBST.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.array_to_bst
import katas.kotlin.leetcode.TreeNode
import datsok.shouldEqual
import org.junit.Test
/**
* https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
*/
class ArrayToBSTTests {
@Test fun `convert sorted array to balanced BST`() {
arrayOf(1).toBS... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,907 | katas | The Unlicense |
kotlin/src/x2022/day2b/Day02b.kt | freeformz | 573,924,591 | false | {"Kotlin": 43093, "Go": 7781} | package day2b
import readInput
enum class Outcome(val input: Char, val value: Int) {
Lose('X', 0) {
override fun score(op: Play): Int = op.winsAgainst().value + value
},
Draw('Y', 3) {
override fun score(op: Play): Int = op.value + value
},
Win('Z', 6) {
override fun score(... | 0 | Kotlin | 0 | 0 | 5110fe86387d9323eeb40abd6798ae98e65ab240 | 1,464 | adventOfCode | Apache License 2.0 |
src/main/kotlin/dijkstra/dijkstra.kt | vw-anton | 574,945,231 | false | {"Kotlin": 33295} | fun <T, E: Number> shortestPath(graph: Graph<T, E>, from: T, destination: T): Pair<List<T>, Double> {
return dijkstra(graph, from, destination)[destination] ?: (emptyList<T>() to Double.POSITIVE_INFINITY)
}
private fun <T, E : Number> dijkstra(graph: Graph<T, E>, from: T, destination: T? = null): Map<T, Pair<List<... | 0 | Kotlin | 0 | 0 | a823cb9e1677b6285bc47fcf44f523e1483a0143 | 1,436 | aoc2022 | The Unlicense |
day04/src/main/kotlin/Main.kt | ickybodclay | 159,694,344 | false | null | import java.io.File
data class Time(val year:Int, val month: Int, val day: Int, val hour: Int, val min: Int)
data class Record(val time: Time, var guardId: Int, val action: Action)
enum class Action { START, SLEEP, WAKE }
data class Guard(val guardId: Int, var minutesSleeping: Int, val sleepList: ArrayList<Sleep>)
dat... | 0 | Kotlin | 0 | 0 | 9a055c79d261235cec3093f19f6828997b7a5fba | 4,123 | aoc2018 | Apache License 2.0 |
src/Day02.kt | MwBoesgaard | 572,857,083 | false | {"Kotlin": 40623} | import HandType.*
import OutcomeType.*
fun main() {
fun part1(input: List<String>): Int {
/*
* opponent, me
* Rock: A, X
* Paper: B, Y
* Scissors: C, Z
*
* Rock: 1 point
* Paper: 2 points
* Scissors: 3 points
*
... | 0 | Kotlin | 0 | 0 | 3bfa51af6e5e2095600bdea74b4b7eba68dc5f83 | 3,126 | advent_of_code_2022 | Apache License 2.0 |
src/Day04.kt | Jintin | 573,640,224 | false | {"Kotlin": 30591} | import kotlin.math.max
import kotlin.math.min
fun main() {
fun String.toPoints(): Pair<List<Int>, List<Int>> {
val pair = this.split(",")
val a = pair[0].split("-").map { it.toInt() }
val b = pair[1].split("-").map { it.toInt() }
return Pair(a, b)
}
fun part1(input: List<S... | 0 | Kotlin | 0 | 2 | 4aa00f0d258d55600a623f0118979a25d76b3ecb | 841 | AdventCode2022 | Apache License 2.0 |
src/Day05.kt | rinas-ink | 572,920,513 | false | {"Kotlin": 14483} | import java.lang.Character.isUpperCase
fun main() {
fun parseStacks(input: List<String>): Pair<Int, List<ArrayList<Char>>> {
var bottom = 0
while (input[bottom].contains("[")) bottom++
val numberOfStacks = input[bottom].split(' ').filter { it.isNotEmpty() }.size
// assert(numberOf... | 0 | Kotlin | 0 | 0 | 462bcba7779f7bfc9a109d886af8f722ec14c485 | 2,232 | anvent-kotlin | Apache License 2.0 |
src/Day04.kt | frungl | 573,598,286 | false | {"Kotlin": 86423} | fun main() {
fun part1(input: List<String>): Int {
return input.count { str ->
val (l, r) = str.split(',')
val (la, lb) = l.split('-').map { it.toInt() }
val (ra, rb) = r.split('-').map { it.toInt() }
(la <= ra && rb <= lb) || (ra <= la && lb <= rb)
}
... | 0 | Kotlin | 0 | 0 | d4cecfd5ee13de95f143407735e00c02baac7d5c | 814 | aoc2022 | Apache License 2.0 |
calendar/day12/Day12.kt | rocketraman | 573,845,375 | false | {"Kotlin": 45660} | package day12
import Day
import Lines
class Day12 : Day() {
data class Position(val x: Int, val y: Int)
override fun part1(input: Lines): Any {
val graph = input.map { it.toCharArray().asList() }
fun positionOf(c: Char): Position {
val y = graph.indexOfFirst { it.contains(c) }
val x = graph[... | 0 | Kotlin | 0 | 0 | 6bcce7614776a081179dcded7c7a1dcb17b8d212 | 4,474 | adventofcode-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LargestColorValueInDirectedGraph.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,578 | kotlab | Apache License 2.0 |
advent-of-code-2022/src/main/kotlin/year_2022/Day07.kt | rudii1410 | 575,662,325 | false | {"Kotlin": 37749} | package year_2022
import util.Runner
import kotlin.math.min
sealed class Node {
data class Dir(val root: Dir?, val name: String, var totalSize: Int = 0, val child: MutableList<Node>) : Node()
data class File(val name: String, val size: Int) : Node()
}
fun main() {
fun aTraverse(dir: Node.Dir): Int {
... | 1 | Kotlin | 0 | 0 | ab63e6cd53746e68713ddfffd65dd25408d5d488 | 2,551 | advent-of-code | Apache License 2.0 |
src/day04/Day04.kt | apeinte | 574,487,528 | false | {"Kotlin": 47438} | package day04
import readDayInput
private const val RESULT_EXAMPLE_PART_ONE = 2
private const val RESULT_EXAMPLE_PART_TWO = 4
private const val VALUE_OF_THE_DAY = 4
fun main() {
fun parseSectionIntoListInt(section: String): List<Int> {
val result = mutableListOf<Int>()
section.split("-").forEach... | 0 | Kotlin | 0 | 0 | 4bb3df5eb017eda769b29c03c6f090ca5cdef5bb | 2,749 | my-advent-of-code | Apache License 2.0 |
src/Day02.kt | uekemp | 575,483,293 | false | {"Kotlin": 69253} |
@JvmInline
value class RockPaperScissors(val points: Int) {
init {
if (points == -1) error("Invalid input: $points")
}
fun playWith(opponent: RockPaperScissors): Int {
return if (points == opponent.points) {
3 + points
} else if ((points - opponent.points % 3) == 1) {
... | 0 | Kotlin | 0 | 0 | bc32522d49516f561fb8484c8958107c50819f49 | 1,580 | advent-of-code-kotlin-2022 | Apache License 2.0 |
advent23-kt/app/src/main/kotlin/dev/rockyj/advent_kt/Day2.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 buildGames(input: List<String>): MutableMap<Int, List<Pair<String, Int>>> {
val games = mutableMapOf<Int, List<Pair<String, Int>>>()
input.forEach { line ->
val game = mutableListOf<Pair<String, Int>>()
val gameParts = line.trim().split(":")
val... | 0 | Kotlin | 0 | 0 | a7bc1dfad8fb784868150d7cf32f35f606a8dafe | 1,957 | advent-2023 | MIT License |
src/Day03.kt | Vincentvibe3 | 573,202,573 | false | {"Kotlin": 8454} | fun main() {
fun part1(input: List<String>): Int {
var total = 0
val mapping = HashMap<Char, Int>()
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray().forEachIndexed{ i: Int, c: Char ->
mapping[c] = i+1
}
for (line in input){
var comm... | 0 | Kotlin | 0 | 0 | 246c8c43a416023343b3ef518ae3e21dd826ee81 | 2,537 | advent-of-code-2022 | Apache License 2.0 |
src/Day14.kt | jbotuck | 573,028,687 | false | {"Kotlin": 42401} | import kotlin.math.max
import kotlin.math.min
fun main() {
val rockStructures = readInput("Day14").map { line ->
line.split(" -> ").map { pair ->
pair.split(",")
.map { it.toInt() }
.let { it.first() to it.last() }
}
}
val maxY = rockStructures.m... | 0 | Kotlin | 0 | 0 | d5adefbcc04f37950143f384ff0efcd0bbb0d051 | 3,273 | aoc2022 | Apache License 2.0 |
src/main/kotlin/com/dambra/adventofcode2018/day6/Grid.kt | pauldambra | 159,939,178 | false | null | package com.dambra.adventofcode2018.day6
class Grid(private val coordinates: List<Coordinate>) {
private val grid = mutableMapOf<Coordinate, Int>()
private val infiniteAreas = mutableSetOf<Coordinate>()
fun findBiggestUnsafeRegionSize(): Int {
val byX = coordinates
.groupBy { it.x }
... | 0 | Kotlin | 0 | 1 | 7d11bb8a07fb156dc92322e06e76e4ecf8402d1d | 3,161 | adventofcode2018 | The Unlicense |
src/main/kotlin/Day14.kt | lanrete | 244,431,253 | false | null | data class Component(val material: Material, val count: Long) {
override fun toString(): String {
return "$count $material"
}
}
data class Material(val name: String) {
override fun toString(): String {
return name
}
}
object Day14 : Solver() {
override val day: Int = 14
overri... | 0 | Kotlin | 0 | 1 | 15125c807abe53230e8d0f0b2ca0e98ea72eb8fd | 4,158 | AoC2019-Kotlin | MIT License |
src/main/kotlin/g0901_1000/s0952_largest_component_size_by_common_factor/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s0952_largest_component_size_by_common_factor
// #Hard #Array #Math #Union_Find #2023_05_02_Time_538_ms_(100.00%)_Space_95.7_MB_(100.00%)
import kotlin.math.sqrt
class Solution {
fun largestComponentSize(nums: IntArray): Int {
var max = 0
for (a in nums) {
max = Mat... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,789 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/advent/y2018/day7.kt | IgorPerikov | 134,053,571 | false | {"Kotlin": 29606} | package advent.y2018
import misc.readAdventInput
import java.util.*
fun main(args: Array<String>) {
println(buildSequenceOfSteps(parseRawRequirements(readAdventInput(7, 2018))))
}
private fun buildSequenceOfSteps(rawRequirements: List<Requirement>): String {
val resultBuilder = StringBuilder()
val remain... | 0 | Kotlin | 0 | 0 | b30cf179f7b7ae534ee55d432b13859b77bbc4b7 | 1,364 | kotlin-solutions | MIT License |
src/main/kotlin/days/Day05.kt | julia-kim | 569,976,303 | false | null | package days
import readInput
fun main() {
fun makeStacks(input: List<String>): MutableMap<Int?, MutableList<Char>> {
val blankLineIndex = input.indexOfFirst { it.isBlank() }
val stacksIndices =
input[blankLineIndex - 1].mapIndexedNotNull { i, c -> if (c.isDigit()) i to c.digitToInt() ... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 2,563 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | findusl | 574,694,775 | false | {"Kotlin": 6599} | import java.io.File
import java.util.Stack
private fun part1(input: File): String {
val (initialState, steps) = input.readText().split("\n\n")
val tower = parseTower(initialState)
tower.runSteps(steps)
return String(tower.map { it.pop() }.toCharArray())
}
private fun part2(input: File): String {
v... | 0 | Kotlin | 0 | 0 | 035f0667c115b09dc36a475fde779d4b74cff362 | 2,159 | aoc-kotlin-2022 | Apache License 2.0 |
src/year2021/day06/Day06.kt | kingdongus | 573,014,376 | false | {"Kotlin": 100767} | package year2021.day06
import readInputFileByYearAndDay
import readTestFileByYearAndDay
fun main() {
// move each fish one age group farther down
// for each fish that would go below 0, reset them to 6 and add one fish at 8
fun ageFishPopulation(fishByAge: MutableMap<Int, Long>, days: Int) =
repe... | 0 | Kotlin | 0 | 0 | aa8da2591310beb4a0d2eef81ad2417ff0341384 | 1,501 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/adventofcode/day6.kt | Kvest | 163,103,813 | false | null | package adventofcode
import java.io.File
import kotlin.math.abs
import kotlin.math.max
private const val DIST = 10000
fun main(args: Array<String>) {
println(first6(File("./data/day6_1.txt").readLines()))
println(second6(File("./data/day6_2.txt").readLines()))
}
fun first6(lines: List<String>): Int? {
v... | 0 | Kotlin | 0 | 0 | d94b725575a8a5784b53e0f7eee6b7519ac59deb | 2,674 | aoc2018 | Apache License 2.0 |
src/main/kotlin/07_Reccursive_Circus.kt | barta3 | 112,792,199 | false | null | val no = Node("")
class Tower {
fun findBottom(list: ArrayList<Node>): Node {
val root = list.find { n -> n.parent == no }!!
return root
}
fun createNodes(filename: String): ArrayList<Node> {
val list = ArrayList<Node>()
val reader = Tower::class.java.getResource(filename)... | 0 | Kotlin | 0 | 0 | 51ba74dc7b922ac11f202cece8802d23011f34f1 | 3,219 | AdventOfCode2017 | MIT License |
src/main/kotlin/day02/Day02.kt | daniilsjb | 572,664,294 | false | {"Kotlin": 69004} | package day02
import java.io.File
fun main() {
val data = parse("src/main/kotlin/day02/Day02.txt")
val answer1 = part1(data)
val answer2 = part2(data)
println("🎄 Day 02 🎄")
println()
println("[Part 1]")
println("Answer: $answer1")
println()
println("[Part 2]")
println("... | 0 | Kotlin | 0 | 0 | 6f0d373bdbbcf6536608464a17a34363ea343036 | 1,687 | advent-of-code-2022 | MIT License |
calendar/day14/Day14.kt | maartenh | 572,433,648 | false | {"Kotlin": 50914} | package day14
import Day
import Lines
import tools.Parser
import tools.int
import tools.list
import tools.map
import tools.runParser
import tools.seq
import tools.string
class Day14 : Day() {
override fun part1(input: Lines): Any {
val paths = input.map { runParser(path(), it) }
val rocks = paths... | 0 | Kotlin | 0 | 0 | 4297aa0d7addcdc9077f86ad572f72d8e1f90fe8 | 3,179 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | NunoPontes | 572,963,410 | false | {"Kotlin": 7416} | fun main() {
fun part1(input: List<String>): Int {
val partOneSum = input.fold(0) { acc, line ->
val middle = line.length / 2
val compA = line.slice(0 until middle).toSet()
val compB = line.slice(middle..line.lastIndex).toSet()
val commonChar = compA.intersec... | 0 | Kotlin | 0 | 0 | 78b67b952e0bb51acf952a7b4b056040bab8b05f | 941 | advent-of-code-2022 | Apache License 2.0 |
src/day-3.kt | drademacher | 160,820,401 | false | null | import java.io.File
private data class Rectangle(val left: Int, val top: Int, val width: Int, val height: Int)
fun main(args: Array<String>) {
println("part 1: " + partOne())
println("part 2: " + partTwo())
}
private fun partOne(): Int {
val rawFile = File("res/day-3.txt").readText()
val field = Arra... | 0 | Kotlin | 0 | 0 | a7f04450406a08a5d9320271148e0ae226f34ac3 | 2,197 | advent-of-code-2018 | MIT License |
src/Day05.kt | cvb941 | 572,639,732 | false | {"Kotlin": 24794} | import java.io.File
class Crates(columns: Int) {
companion object {
fun from(input: String): Crates {
val rows = input.split("\n")
val columns = rows.last().split(" ").mapNotNull { it.toIntOrNull() }.max()
val crates = Crates(columns)
// Fill out crates
... | 0 | Kotlin | 0 | 0 | fe145b3104535e8ce05d08f044cb2c54c8b17136 | 2,581 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day05.kt | ajmfulcher | 573,611,837 | false | {"Kotlin": 24722} | fun main() {
fun createStacks(input: List<String>): List<ArrayDeque<String>> {
var stackIndex = 0
while (input[stackIndex].substring(1,2) != "1") {
stackIndex += 1
}
val stacks = input[stackIndex]
.trim()
.split("\\s+".toRegex())
.map ... | 0 | Kotlin | 0 | 0 | 981f6014b09e347241e64ba85e0c2c96de78ef8a | 2,696 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day21.kt | hughjdavey | 317,575,435 | false | null | package days
class Day21 : Day(21) {
private val foods = parseFoods()
private val unsafeIngredients = findUnsafeIngredients(foods)
// 2125
override fun partOne(): Any {
return foods.map { it.ingredients }.flatten().count { it !in unsafeIngredients.values }
}
// phc,spnd,zmsdzh,pdt,fq... | 0 | Kotlin | 0 | 1 | 63c677854083fcce2d7cb30ed012d6acf38f3169 | 1,893 | aoc-2020 | Creative Commons Zero v1.0 Universal |
y2022/src/main/kotlin/adventofcode/y2022/Day14.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2022
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Vec2
import kotlin.math.sign
object Day14 : AdventSolution(2022, 14, "<NAME>") {
override fun solvePartOne(input: String): Int {
val walls: Set<Vec2> = parse(input).toSet()
val covered = walls.toMut... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,740 | advent-of-code | MIT License |
src/main/kotlin/org/sjoblomj/adventofcode/day3/Day3.kt | sjoblomj | 225,241,573 | false | null | package org.sjoblomj.adventofcode.day3
import org.sjoblomj.adventofcode.day3.Instruction.Direction.*
import org.sjoblomj.adventofcode.readFile
import kotlin.math.abs
private const val inputFile = "src/main/resources/inputs/day3.txt"
fun day3(): Pair<Int, Int> {
val content = readFile(inputFile)
val coordinates0 = ... | 0 | Kotlin | 0 | 0 | f8d03f7ef831bc7e26041bfe7b1feaaadcb40e68 | 3,038 | adventofcode2019 | MIT License |
solutions/aockt/y2022/Y2022D09.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2022
import io.github.jadarma.aockt.core.Solution
import kotlin.math.absoluteValue
object Y2022D09 : Solution {
/** The valid representation of an orthogonal rope movement. */
private val inputRegex = Regex("""^([LRUD]) ([1-9]\d*)$""")
/** Parses the [input] and returns the sequence of mo... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,748 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/day04/Day04.kt | TheSench | 572,930,570 | false | {"Kotlin": 128505} | package day04
import runDay
import toPair
fun main() {
fun part1(input: List<String>): Int {
return input.mapToPairsOfRanges()
.count { it.oneFullyContainsOther() }
}
fun part2(input: List<String>): Int {
return input.mapToPairsOfRanges()
.count { it.overlap() }
... | 0 | Kotlin | 0 | 0 | c3e421d75bc2cd7a4f55979fdfd317f08f6be4eb | 1,037 | advent-of-code-2022 | Apache License 2.0 |
src/day08/Day08.kt | henrikrtfm | 570,719,195 | false | {"Kotlin": 31473} | package day08
import utils.Resources.resourceAsListOfString
typealias Treemap = Array<IntArray>
typealias Point = Pair<Int, Int>
fun main() {
val input = resourceAsListOfString("src/day08/Day08.txt")
val treemap: Treemap = input
.map { it.chunked(1) }
.map { it -> it.map { it -> it.toInt() }... | 0 | Kotlin | 0 | 0 | 20c5112594141788c9839061cb0de259f242fb1c | 3,224 | aoc2022 | Apache License 2.0 |
src/Day21.kt | Flame239 | 570,094,570 | false | {"Kotlin": 60685} | private fun input(): Map<String, M> {
return readInput("Day21").associate { l ->
val (id, exp) = l.split(": ")
val expS = exp.split(" ")
if (expS.size == 1) {
id to M(id, const = exp.toLong())
} else {
parent[expS[2]] = id
parent[expS[0]] = id
... | 0 | Kotlin | 0 | 0 | 27f3133e4cd24b33767e18777187f09e1ed3c214 | 1,730 | advent-of-code-2022 | Apache License 2.0 |
year2017/src/main/kotlin/net/olegg/aoc/year2017/day24/Day24.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2017.day24
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2017.DayOf2017
import java.util.BitSet
import kotlin.math.max
/**
* See [Year 2017, Day 24](https://adventofcode.com/2017/day/24)
*/
object Day24 : DayOf2017(24) {
override fun first(): Any? {
val ports = lines
... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 3,032 | adventofcode | MIT License |
src/main/kotlin/dev/sirch/aoc/y2022/days/Day07.kt | kristofferchr | 573,549,785 | false | {"Kotlin": 28399, "Mustache": 1231} | package dev.sirch.aoc.y2022.days
import dev.sirch.aoc.Day
class Day07(testing: Boolean = false) : Day(2022, 7, testing) {
override fun part1(): Int {
val tree = constructTree(inputLines)
return tree.getAllDirsWithLessSizeThanUpperLimit(100000)!!
}
override fun part2(): Int {
val t... | 0 | Kotlin | 0 | 0 | 867e19b0876a901228803215bed8e146d67dba3f | 3,437 | advent-of-code-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.