path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/Day02.kt | pmellaaho | 573,136,030 | false | {"Kotlin": 22024} | enum class Weapon(private val char: Char) {
Rock('A'), // 'X'
Paper('B'), // 'Y'
Scissors('C'); // 'Z'
companion object {
fun getByChar(char: Char): Weapon {
values().forEach {
if (it.char == char) return it
}
return Rock
}
... | 0 | Kotlin | 0 | 0 | cd13824d9bbae3b9debee1a59d05a3ab66565727 | 2,923 | AoC_22 | Apache License 2.0 |
leetcode/src/array/Q350.kt | zhangweizhe | 387,808,774 | false | null | package array
fun main() {
// 350. 两个数组的交集 II
// https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/
println(intersect(intArrayOf(1,2,2,1), intArrayOf(2,2)).contentToString())
}
/**
* 哈希法
*/
fun intersect(nums1: IntArray, nums2: IntArray): IntArray {
val list = ArrayList<Int>(nums1.size)... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,575 | kotlin-study | MIT License |
src/Day05.kt | GreyWolf2020 | 573,580,087 | false | {"Kotlin": 32400} | import java.io.File
import java.util.Stack
typealias Stacks<E> = List<Stack<E>>
typealias StacksOfChar = Stacks<Char>
fun main() {
fun part1(input: String) = findCratesOnTopOfAllStacks(
input,
StacksOfChar::moveOneStackAtTime
)
fun part2(input: String) = findCratesOnTopOfAllStacks(
... | 0 | Kotlin | 0 | 0 | 498da8861d88f588bfef0831c26c458467564c59 | 3,478 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/matrix/BiggestNumberOfLengthFromMatrix.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.matrix
import kotlin.math.max
import kotlin.math.pow
/**
* You are given a matrix of N rows and M columns.
* Each field of the matrix contains a single digit (0-9).
*
* You want to find a path consisting of four neighboring fields.
* Two fields are neighboring if ... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 3,247 | algs4-leprosorium | MIT License |
common/graph/src/main/kotlin/com/curtislb/adventofcode/common/graph/UnweightedGraph.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.common.graph
/**
* A graph consisting of unique nodes of type [V], connected by directed edges.
*/
abstract class UnweightedGraph<V> {
/**
* Returns all nodes in the graph to which there is a directed edge from the given [node].
*/
protected abstract fun getNeighbo... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 4,502 | AdventOfCode | MIT License |
src/Day04.kt | pimts | 573,091,164 | false | {"Kotlin": 8145} | fun main() {
fun String.ranges(): Pair<IntRange, IntRange> {
val (range1Start, range1End) = substringBefore(",").split("-")
val (range2Start, range2End) = substringAfter(",").split("-")
return range1Start.toInt()..range1End.toInt() to range2Start.toInt()..range2End.toInt()
}
fun pa... | 0 | Kotlin | 0 | 0 | dc7abb10538bf6ad9950a079bbea315b4fbd011b | 1,024 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/sorts/SelectionSorts.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <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,426 | kotlab | Apache License 2.0 |
aoc/src/main/kotlin/com/bloidonia/aoc2023/day04/Main.kt | timyates | 725,647,758 | false | {"Kotlin": 45518, "Groovy": 202} | package com.bloidonia.aoc2023.day04
import com.bloidonia.aoc2023.lines
import kotlin.math.pow
private const val example = """Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 ... | 0 | Kotlin | 0 | 0 | 158162b1034e3998445a4f5e3f476f3ebf1dc952 | 1,629 | aoc-2023 | MIT License |
src/Day03.kt | polbins | 573,082,325 | false | {"Kotlin": 9981} | fun main() {
fun part1(input: List<String>): Int {
val charPriority = buildCharPriority()
var result = 0
for (s in input) {
val left = s.substring(0, s.length / 2).toSet()
val right = s.substring(s.length / 2, s.length).toSet()
val intersection = left.intersect(right).first()
resu... | 0 | Kotlin | 0 | 0 | fb9438d78fed7509a4a2cf6c9ea9e2eb9d059f14 | 1,397 | AoC-2022 | Apache License 2.0 |
src/Day04.kt | HenryCadogan | 574,509,648 | false | {"Kotlin": 12228} | fun main() {
fun part1(input: List<String>) = checkRanges(input, IntRange::isInRange)
fun part2(input: List<String>) = checkRanges(input, IntRange::overLapsWith)
val input = readInput("Day04")
println(part1(input))
println(part2(input))
}
fun checkRanges(input: List<String>, func: IntRange.(Int... | 0 | Kotlin | 0 | 0 | 0a0999007cf16c11355fcf32fc8bc1c66828bbd8 | 985 | AOC2022 | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/RegionsBySlashes.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
/**
* 959. 由斜杠划分区域
* 在由 1 x 1 方格组成的 N x N 网格 grid 中,每个 1 x 1 方块由 /、\ 或空格构成。这些字符会将方块划分为一些共边的区域。
*
* (请注意,反斜杠字符是转义的,因此 \ 用 "\\" 表示。)。
*
* 返回区域的数目。
*/
class RegionsBySlashes {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,578 | daily_algorithm | Apache License 2.0 |
advent-of-code/src/main/kotlin/com/akikanellis/adventofcode/year2022/Day18.kt | akikanellis | 600,872,090 | false | {"Kotlin": 142932, "Just": 977} | package com.akikanellis.adventofcode.year2022
object Day18 {
fun surfaceAreaOfScannedLavaDroplet(input: String): Int {
val cubes = cubes(input)
return cubes
.flatMap { cube -> cube.neighbours }
.count { potentialNeighbour -> potentialNeighbour !in cubes }
}
fun sur... | 8 | Kotlin | 0 | 0 | 036cbcb79d4dac96df2e478938de862a20549dce | 2,547 | advent-of-code | MIT License |
hoon/HoonAlgorithm/src/main/kotlin/programmers/lv01/Lv1_86051.kt | boris920308 | 618,428,844 | false | {"Kotlin": 137657, "Swift": 35553, "Java": 1947, "Rich Text Format": 407} | package main.kotlin.programmers.lv01
/**
*
* https://school.programmers.co.kr/learn/courses/30/lessons/86051?language=kotlin
*
* 문제 설명
* 0부터 9까지의 숫자 중 일부가 들어있는 정수 배열 numbers가 매개변수로 주어집니다.
* numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요.
*
* 제한사항
* 1 ≤ numbers의 길이 ≤ 9
* 0 ≤ numbers... | 1 | Kotlin | 1 | 2 | 88814681f7ded76e8aa0fa7b85fe472769e760b4 | 1,313 | HoOne | Apache License 2.0 |
leetcode/src/offer/middle/Offer47.kt | zhangweizhe | 387,808,774 | false | null | package offer.middle
fun main() {
// 剑指 Offer 47. 礼物的最大价值
// https://leetcode.cn/problems/li-wu-de-zui-da-jie-zhi-lcof/
}
fun maxValue(grid: Array<IntArray>): Int {
/**
* 关键点:grid[i][j] 的最大值,只能来自于它上边grid[i][j-1] 的元素,或者它左边grid[i-1][j] 的元素
* 对于首行、首列的元素,上一个礼物最大价值,只能来自于它的左边(首行)、上边(首列)
*/
va... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 2,300 | kotlin-study | MIT License |
src/main/kotlin/de/niemeyer/aoc2022/Day15.kt | stefanniemeyer | 572,897,543 | false | {"Kotlin": 175820, "Shell": 133} | /**
* Advent of Code 2022, Day 15: Beacon Exclusion Zone
* Problem Description: https://adventofcode.com/2022/day/15
*/
package de.niemeyer.aoc2022
import de.niemeyer.aoc.points.Point2D
import de.niemeyer.aoc.utils.Resources.resourceAsList
import de.niemeyer.aoc.utils.getClassName
import de.niemeyer.aoc.utils.inte... | 0 | Kotlin | 0 | 0 | ed762a391d63d345df5d142aa623bff34b794511 | 3,689 | AoC-2022 | Apache License 2.0 |
src/Day14.kt | makohn | 571,699,522 | false | {"Kotlin": 35992} |
fun main() {
val day = "14"
data class Pos(val x: Int, val y: Int)
data class Path(val from: Pos, val to: Pos) {
operator fun contains(other: Pos) =
((other.x in from.x .. to.x) && (other.y in from.y .. to.y)) ||
((other.x in to.x .. from.x) && (other.y in to.y ..... | 0 | Kotlin | 0 | 0 | 2734d9ea429b0099b32c8a4ce3343599b522b321 | 3,385 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/github/davio/aoc/y2023/Day7.kt | Davio | 317,510,947 | false | {"Kotlin": 405939} | package com.github.davio.aoc.y2023
import com.github.davio.aoc.general.Day
import com.github.davio.aoc.general.getInputAsList
import com.github.davio.aoc.y2023.Day7.Card.Companion.toCard
import com.github.davio.aoc.y2023.Day7.Hand.Companion.toHand
/**
* See [Advent of Code 2023 Day 6](https://adventofcode.com/2023/d... | 1 | Kotlin | 0 | 0 | 4fafd2b0a88f2f54aa478570301ed55f9649d8f3 | 6,141 | advent-of-code | MIT License |
src/Day04.kt | halirutan | 575,809,118 | false | {"Kotlin": 24802} | fun getPairOfRange(s: String): Pair<IntRange, IntRange> {
val split = s.split(",").map {
val lowHigh = it.split("-")
IntRange(lowHigh[0].toInt(), lowHigh[1].toInt())
}
return Pair(split[0], split[1])
}
fun IntRange.encloses(other: IntRange): Boolean {
return this.first <= other.first &&... | 0 | Kotlin | 0 | 0 | 09de80723028f5f113e86351a5461c2634173168 | 1,292 | AoC2022 | Apache License 2.0 |
src/main/kotlin/dp/MaxValueWord.kt | yx-z | 106,589,674 | false | null | package dp
import util.OneArray
import util.toCharOneArray
// consider a solitaire game described as follows
// given an array of (Char, Int), and at the start of the game,
// we draw seven such tuples into our hand
// in each turn, we form an English word from some or all of the tuples
// we have in our hand and rec... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 2,612 | AlgoKt | MIT License |
src/main/kotlin/de/nilsdruyen/aoc/Day02.kt | nilsjr | 571,758,796 | false | {"Kotlin": 15971} | package de.nilsdruyen.aoc
fun main() {
fun part1(input: List<String>): Int {
val gameScore = input.map { it.first() to it[2] }.sumOf {
val result = it.first.fight(it.second)
getScore(result, it.second)
}
return gameScore
}
fun part2(input: List<String>): In... | 0 | Kotlin | 0 | 0 | 1b71664d18076210e54b60bab1afda92e975d9ff | 2,322 | advent-of-code-2022 | Apache License 2.0 |
src/DaySeven.kt | P-ter | 572,781,029 | false | {"Kotlin": 18422} | import java.util.*
data class File(val name: String, val size: Int)
data class Folder(val name: String, val files: MutableList<File>, val folders: MutableList<Folder>)
fun main() {
fun parseCommand(commands: List<String>): Folder {
val root = Folder("/", mutableListOf(), mutableListOf())
var cur... | 0 | Kotlin | 0 | 1 | e28851ee38d6de5600b54fb884ad7199b44e8373 | 2,663 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/year_2021/day_10/Day10.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2021.day_10
import readInput
import java.util.Stack
object Day10 {
/**
* @return
*/
fun solutionOne(text: List<String>): Int {
return text.sumOf { line ->
findFirstIllegalCharacter(line)
}
}
/**
* @return
*/
fun solutionTwo(text: List<... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 3,487 | advent_of_code | Apache License 2.0 |
src/Grid2D.kt | jwklomp | 572,195,432 | false | {"Kotlin": 65103} | import kotlin.math.abs
class Grid2D<T>(private val grid: List<List<T>>) {
private val rowLength: Int = grid.size
private val columnLength: Int = grid.first().size
private val surrounding: List<Pair<Int, Int>> =
listOf(Pair(-1, -1), Pair(-1, 0), Pair(-1, 1), Pair(0, -1), Pair(0, 1), Pair(1, -1), Pa... | 0 | Kotlin | 0 | 0 | 1b1121cfc57bbb73ac84a2f58927ab59bf158888 | 2,019 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/aoc2022/Day13.kt | Clausr | 575,584,811 | false | {"Kotlin": 65961} | package aoc2022
class Day13(val input: String) {
sealed class Packets : Comparable<Packets> {
data class Single(val value: Int) : Packets()
data class Multi(val packets: List<Packets>) : Packets()
private fun Single.toList() = Multi(listOf(this))
override fun compareTo(other: Pa... | 1 | Kotlin | 0 | 0 | dd33c886c4a9b93a00b5724f7ce126901c5fb3ea | 4,050 | advent_of_code | Apache License 2.0 |
src/Day07.kt | wgolyakov | 572,463,468 | false | null | fun main() {
fun parse(input: List<String>): Map<List<String>, Int> {
val dirSizes = mutableMapOf<List<String>, Int>()
val path = mutableListOf<String>()
for (line in input) {
if (line[0] == '$') {
if (line.startsWith("\$ cd ")) {
val dir = line.substringAfter("\$ cd ")
if (dir == "..")
pa... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 1,165 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day08.kt | gtruitt | 574,758,122 | false | {"Kotlin": 16663} | @file:Suppress("PackageDirectoryMismatch")
package day08
import head
import tail
fun readForest(input: List<String>) =
input
.filter { it.isNotEmpty() }
.map { trees ->
trees.toCharArray().map { it.digitToInt() }
}
fun isVisible(x: Int, y: Int, forest: List<List<Int>>) =
... | 0 | Kotlin | 0 | 2 | 1c9940faaf7508db275942feeb38d3e57aef413f | 2,112 | aoc-2022-kotlin | MIT License |
src/main/kotlin/de/nosswald/aoc/days/Day07.kt | 7rebux | 722,943,964 | false | {"Kotlin": 34890} | package de.nosswald.aoc.days
import de.nosswald.aoc.Day
// https://adventofcode.com/2023/day/7
object Day07 : Day<Int>(7, "Camel Cards") {
private const val JOKER_PART_TWO = '1'
private data class Hand(val cards: String, val bidAmount: Int): Comparable<Hand> {
var groups = cards
.groupBy ... | 0 | Kotlin | 0 | 1 | 398fb9873cceecb2496c79c7adf792bb41ea85d7 | 2,643 | advent-of-code-2023 | MIT License |
src/aoc2022/Day15_.kt | RobertMaged | 573,140,924 | false | {"Kotlin": 225650} | package aoc2022
import utils.Vertex
import utils.checkEquals
import utils.sendAnswer
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun main() {
fun part1(input: List<String>, y: Int): Int {
val sToBMap = input.associate { line ->
val (s, b) = line.split(" closest ").ta... | 0 | Kotlin | 0 | 0 | e2e012d6760a37cb90d2435e8059789941e038a5 | 9,178 | Kotlin-AOC-2023 | Apache License 2.0 |
src/main/kotlin/org/deafsapps/adventofcode/day15/part02/Main.kt | pablodeafsapps | 733,033,603 | false | {"Kotlin": 6685} | package org.deafsapps.adventofcode.day15.part02
import org.deafsapps.adventofcode.day15.part01.stringHash
import java.io.File
import java.util.HashMap
import java.util.Scanner
fun main() {
val input = Scanner(File("src/main/resources/day15-data.txt"))
val steps = input.nextLine().split(",").map { step -> get... | 0 | Kotlin | 0 | 0 | 3a7ea1084715ab7c2ab1bfa8a1a7e357aa3c4b40 | 2,030 | advent-of-code_2023 | MIT License |
2023/3/solve-2.kts | gugod | 48,180,404 | false | {"Raku": 170466, "Perl": 121272, "Kotlin": 58674, "Rust": 3189, "C": 2934, "Zig": 850, "Clojure": 734, "Janet": 703, "Go": 595} | import java.io.File
class EngineSchemata(
val engineSchematic: List<String>,
) {
private fun CharSequence.indicesOfNextNumOrNull (
startIndex: Int,
) : IntRange? {
if (startIndex > this.lastIndex)
throw IllegalStateException("Your index is not my index.")
val begin = (s... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 2,678 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/bogwalk/batch2/Problem30.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch2
import dev.bogwalk.util.combinatorics.combinationsWithReplacement
import kotlin.math.pow
/**
* Problem 30: Digit Fifth Powers
*
* https://projecteuler.net/problem=30
*
* Goal: Calculate the sum of all numbers that can be written as the sum of the Nth power of
* their digits.
*
* Con... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,535 | project-euler-kotlin | MIT License |
src/Day01/Day01.kt | Nathan-Molby | 572,771,729 | false | {"Kotlin": 95872, "Python": 13537, "Java": 3671} | package Day01
import readInput
fun main() {
class Elf(var calories: MutableList<Int>) {
fun addCalorie(calorie: Int) {
calories.add(calorie)
}
fun totalCalories() = calories.sum()
}
fun readElves(input: List<String>): MutableList<Elf> {
var elves = mutableList... | 0 | Kotlin | 0 | 0 | 750bde9b51b425cda232d99d11ce3d6a9dd8f801 | 1,447 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/RefreshRecord.kt | funfunStudy | 93,757,087 | false | null | fun main(args: Array<String>) {
solve(listOf(10, 5, 20, 20, 4, 5, 2, 25, 1), 9)
solve2(listOf(10, 5, 20, 20, 4, 5, 2, 25, 1))
solve3(listOf(10, 5, 20, 20, 4, 5, 2, 25, 1))
solve3(listOf(3, 4, 21, 36, 10, 28, 35, 5, 24, 42))
}
data class RecordedScore(val minScore: Int = 0, val maxScore: Int = 0, val mi... | 0 | Kotlin | 3 | 14 | a207e4db320e8126169154aa1a7a96a58c71785f | 2,533 | algorithm | MIT License |
src/main/kotlin/TransparentOrigami_13.kt | Flame239 | 433,046,232 | false | {"Kotlin": 64209} | fun getOrigamiInput(): OrigamiInput {
val lines = readFile("TransparentOrigami").split("\n")
val paper = lines.takeWhile { s -> s.isNotEmpty() }.map { s -> s.split(",").map { it.toInt() }.zipWithNext()[0] }
val maxX = paper.maxOf { it.first }
val maxY = paper.maxOf { it.second }
val paperArray = Arr... | 0 | Kotlin | 0 | 0 | ef4b05d39d70a204be2433d203e11c7ebed04cec | 2,422 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/Day02.kt | joostbaas | 573,096,671 | false | {"Kotlin": 45397} | import RockPaperScissors.PAPER
import RockPaperScissors.ROCK
import RockPaperScissors.SCISSORS
enum class RockPaperScissors(
private val scoreForUsing: Int,
) {
ROCK(1),
PAPER(2),
SCISSORS(3);
fun beats() =
when (this) {
ROCK -> SCISSORS
PAPER -> ROCK
SC... | 0 | Kotlin | 0 | 0 | 8d4e3c87f6f2e34002b6dbc89c377f5a0860f571 | 1,686 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day11.kt | hughjdavey | 159,955,618 | false | null | package days
import util.cartesianProduct
class Day11 : Day(11) {
override fun partOne(): Any {
val grid = FuelCell.getFuelCellGrid()
return highestPowerInGrid(grid, inputString.trim().toInt())
}
override fun partTwo(): Any {
val serialNumber = inputString.trim().toInt()
... | 0 | Kotlin | 0 | 0 | 4f163752c67333aa6c42cdc27abe07be094961a7 | 3,527 | aoc-2018 | Creative Commons Zero v1.0 Universal |
day11/src/main/kotlin/App.kt | ascheja | 317,918,055 | false | null | package net.sinceat.aoc2020.day11
import kotlin.math.abs
import kotlin.math.sign
import net.sinceat.aoc2020.day11.Part1EvolutionRules.evolveUntilStable
fun main() {
with (Part1EvolutionRules) {
run {
val fullyEvolvedGrid = readGrid("testinput.txt").evolveUntilStable().last()
Grid.c... | 0 | Kotlin | 0 | 0 | f115063875d4d79da32cbdd44ff688f9b418d25e | 5,450 | aoc2020 | MIT License |
src/Day07.kt | mihansweatpants | 573,733,975 | false | {"Kotlin": 31704} | import kotlin.math.min
private const val PARENT_DIR = ".."
private const val TOTAL_DISK_SPACE = 70000000
private const val SPACE_REQUIRED_FOR_UPDATE = 30000000
fun main() {
fun part1(input: List<String>): Int {
val rootDir = buildFilesystemTree(input)
var sum = 0
rootDir.walkTree {
... | 0 | Kotlin | 0 | 0 | 0de332053f6c8f44e94f857ba7fe2d7c5d0aae91 | 3,899 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2017/Day20.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2017
import se.saidaspen.aoc.util.Day
import se.saidaspen.aoc.util.ints
import kotlin.math.pow
import kotlin.math.sqrt
fun main() = Day20.run()
object Day20 : Day(2017, 20) {
class Tuple<T: Number>(val x: T, val y: T, val z: T)
operator fun Tuple<Int>.plus(a: Tuple<Int>): Tuple<I... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 2,856 | adventofkotlin | MIT License |
src/Day03.kt | baghaii | 573,918,961 | false | {"Kotlin": 11922} | fun main() {
fun part1(input: List<String>): Int {
var totalScore = 0
input.forEach {
val firstHalf = it.substring(0, it.length / 2)
val secondHalf = it.substring(it.length / 2, it.length )
val inBoth = mutableListOf<Char>()
firstHalf.forEach { ch ->
... | 0 | Kotlin | 0 | 0 | 8c66dae6569f4b269d1cad9bf901e0a686437469 | 1,401 | AdventOfCode2022 | Apache License 2.0 |
src/day04/Day04.kt | zoricbruno | 573,440,038 | false | {"Kotlin": 13739} | package day04
import readInput
fun getSetFromInput(input: String): Set<Int> {
val start = input.takeWhile { it != '-' }.toInt()
val end = input.takeLastWhile { it != '-' }.toInt()
return (start..end).toSet()
}
fun isFullOverlap(left: Set<Int>, right: Set<Int>): Boolean {
return left.containsAll(right... | 0 | Kotlin | 0 | 0 | 16afa06aff0b6e988cbea8081885236e4b7e0555 | 1,449 | kotlin_aoc_2022 | Apache License 2.0 |
src/main/kotlin/day19/Day19.kt | TheSench | 572,930,570 | false | {"Kotlin": 128505} | package day19
import runDay
fun main() {
fun part1(input: List<String>) = input
.map(String::toBlueprint)
.mapIndexed { index, blueprint ->
(index + 1) to blueprint.findBest(24)
}.sumOf { (id, best) -> id * best }
fun part2(input: List<String>) = input
.take(3)
.map(String::toBlueprint... | 0 | Kotlin | 0 | 0 | c3e421d75bc2cd7a4f55979fdfd317f08f6be4eb | 5,444 | advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | mandoway | 573,027,658 | false | {"Kotlin": 22353} | fun main() {
fun String.toRange() = split("-")
.map { it.toInt() }
.let { it[0] .. it[1] }
fun String.toRangePair() = split(",")
.let { it[0].toRange() to it[1].toRange() }
infix operator fun IntRange.contains(other: IntRange) = first <= other.first && last >= other.last
infi... | 0 | Kotlin | 0 | 0 | 0393a4a25ae4bbdb3a2e968e2b1a13795a31bfe2 | 1,088 | advent-of-code-22 | Apache License 2.0 |
src/Day17.kt | catcutecat | 572,816,768 | false | {"Kotlin": 53001} | import kotlin.system.measureTimeMillis
fun main() {
measureTimeMillis {
Day17.run {
solve1(3068L) // 3133L
solve2(1514285714288L) // 1547953216393L
}
}.let { println("Total: $it ms") }
}
object Day17 : Day.RowInput<Day17.Data, Long>("17") {
data class Data(private ... | 0 | Kotlin | 0 | 2 | fd771ff0fddeb9dcd1f04611559c7f87ac048721 | 4,505 | AdventOfCode2022 | Apache License 2.0 |
src/Day03.kt | jordanfarrer | 573,120,618 | false | {"Kotlin": 20954} | fun main() {
val day = "Day03"
fun findItemInBoth(first: Iterable<Char>, second: Iterable<Char>): Char {
return first.intersect(second.toSet()).first()
}
fun findCommonItem(groups: List<Iterable<Char>>): Char {
return groups.reduce { a, b -> a.intersect(b.toSet()) }.first()
}
... | 0 | Kotlin | 0 | 1 | aea4bb23029f3b48c94aa742958727d71c3532ac | 1,402 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/twentythree/Day03.kt | Monkey-Matt | 572,710,626 | false | {"Kotlin": 73188} | package twentythree
fun main() {
val day = "03"
// test if implementation meets criteria from the description:
println("Day$day Test Answers:")
val testInput = readInputLines("Day${day}_test")
val part1 = part1(testInput)
part1.println()
check(part1 == 4361)
val part2 = part2(testInput)... | 1 | Kotlin | 0 | 0 | 600237b66b8cd3145f103b5fab1978e407b19e4c | 6,372 | advent-of-code-solutions | Apache License 2.0 |
src/Day02.kt | MSchu160475 | 573,330,549 | false | {"Kotlin": 5456} | fun main() {
fun part1(input: List<String>): Int {
val game = RockPaperScissors()
return input.map {
game.score(it)
}.sum()
}
fun part2(input: List<String>): Int {
val game = RockPaperScissors()
return input.map {
game.scoreFake(it)
}.... | 0 | Kotlin | 0 | 0 | c6f9a0892a28f0f03b95768b6611e520c85db75c | 1,417 | advent-of-code-2022-kotlin | Apache License 2.0 |
2022/src/main/kotlin/day21.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.badInput
import utils.cut
import utils.mapItems
fun main() {
Day21.run()
}
object Day21 : Solution<Map<String, Day21.Expr>>() {
override val name = "day21"
override val parser = Parser.lines.mapItems { line ->
val (name, exprString) = line.cut(": ")
... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,582 | aoc_kotlin | MIT License |
src/main/kotlin/aoc/year2023/Day02.kt | SackCastellon | 573,157,155 | false | {"Kotlin": 62581} | package aoc.year2023
import aoc.Puzzle
/**
* [Day 2 - Advent of Code 2023](https://adventofcode.com/2023/day/2)
*/
object Day02 : Puzzle<Int, Int> {
private val bagContents = mapOf(
"red" to 12,
"green" to 13,
"blue" to 14,
)
override fun solvePartOne(input: String): Int {
... | 0 | Kotlin | 0 | 0 | 75b0430f14d62bb99c7251a642db61f3c6874a9e | 1,565 | advent-of-code | Apache License 2.0 |
graph/MinimumCostMaximumFlow.kt | wangchaohui | 737,511,233 | false | {"Kotlin": 36737} | class MinimumCostMaximumFlow(vertexSize: Int, private val s: Int, private val t: Int) {
data class Edge(
val u: Int,
val v: Int,
var capacity: Int,
var cost: Int,
var flow: Int = 0,
) {
lateinit var reverse: Edge
val remaining: Int
get() = capa... | 0 | Kotlin | 0 | 0 | 241841f86fdefa9624e2fcae2af014899a959cbe | 2,591 | kotlin-lib | Apache License 2.0 |
src/main/kotlin/days/Day12.kt | hughjdavey | 433,597,582 | false | {"Kotlin": 53042} | package days
class Day12 : Day(12) {
private val caveMap = parseInput(inputList)
override fun partOne(): Any {
return getPaths(caveMap, true).size
}
override fun partTwo(): Any {
return getPaths(caveMap, false).size
}
data class Path(val onlyVisitSmallCavesOnce: Boolean, val... | 0 | Kotlin | 0 | 0 | a3c2fe866f6b1811782d774a4317457f0882f5ef | 2,186 | aoc-2021 | Creative Commons Zero v1.0 Universal |
src/day04/Day04.kt | Klaus-Anderson | 572,740,347 | false | {"Kotlin": 13405} | package day04
import readInput
fun main() {
fun parseElfSection(it: String): List<Int> {
return it.split("-").let {
(it[0].toInt() until it[1].toInt() + 1).toList()
}
}
fun part1(input: List<String>): Int {
return input.map {
it.split(",")
}.sumOf ... | 0 | Kotlin | 0 | 0 | faddc2738011782841ec20475171909e9d4cee84 | 1,471 | harry-advent-of-code-kotlin-template | Apache License 2.0 |
src/Day02.kt | jbotuck | 573,028,687 | false | {"Kotlin": 42401} | import java.time.Duration
import java.time.Instant
fun main() {
val started = Instant.now()
val lines = readInput("Day02")
println("part 1 ${lines.sumOf { score1(it) }}")
println("part 2 ${lines.sumOf { score2(it) }}")
println(Duration.between(started, Instant.now()).toMillis())
}
private val rule... | 0 | Kotlin | 0 | 0 | d5adefbcc04f37950143f384ff0efcd0bbb0d051 | 995 | aoc2022 | Apache License 2.0 |
src/day3/Day03.kt | dinoolivo | 573,723,263 | false | null | package day3
import readInput
fun main() {
//subtract the code of 'a' if lowercase or 'A' if uppercase then sum the known priority range (a to z priorities 1 through 26 and A to Z priorities 27 through 52)
fun computePriority(itemType:Char) = if(itemType.isUpperCase()) itemType.code -'A'.code + 27 else itemT... | 0 | Kotlin | 0 | 0 | 6e75b42c9849cdda682ac18c5a76afe4950e0c9c | 1,754 | aoc2022-kotlin | Apache License 2.0 |
src/main/kotlin/adventofcode/year2015/Day06ProbablyAFireHazard.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2015
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import adventofcode.common.cartesianProduct
import adventofcode.year2015.Day06ProbablyAFireHazard.Companion.Action.TOGGLE
import adventofcode.year2015.Day06ProbablyAFireHazard.Companion.Action.TURN_OFF
import adventofcode.year2015... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 2,669 | AdventOfCode | MIT License |
year2021/src/main/kotlin/net/olegg/aoc/year2021/day14/Day14.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2021.day14
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.toPair
import net.olegg.aoc.year2021.DayOf2021
import java.math.BigInteger
/**
* See [Year 2021, Day 14](https://adventofcode.com/2021/day/14)
*/
object Day14 : DayOf2021(14) {
override fun first(): Any? {
ret... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,613 | adventofcode | MIT License |
src/main/kotlin/nl/jackploeg/aoc/_2023/calendar/day23/Day23.kt | jackploeg | 736,755,380 | false | {"Kotlin": 318734} | package nl.jackploeg.aoc._2023.calendar.day23
import nl.jackploeg.aoc.generators.InputGenerator.InputGeneratorFactory
import nl.jackploeg.aoc.utilities.readStringFile
import javax.inject.Inject
import kotlin.math.max
class Day23 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
fun par... | 0 | Kotlin | 0 | 0 | f2b873b6cf24bf95a4ba3d0e4f6e007b96423b76 | 4,455 | advent-of-code | MIT License |
src/main/kotlin/com/ginsberg/advent2023/Day05.kt | tginsberg | 723,688,654 | false | {"Kotlin": 112398} | /*
* Copyoutgoing (c) 2023 by <NAME>
*/
/**
* Advent of Code 2023, Day 5 - If You Give A Seed A Fertilizer
* Problem Description: http://adventofcode.com/2023/day/5
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2023/day5/
*/
package com.ginsberg.advent2023
class Day05(input: List<String>... | 0 | Kotlin | 0 | 12 | 0d5732508025a7e340366594c879b99fe6e7cbf0 | 2,462 | advent-2023-kotlin | Apache License 2.0 |
src/Day02.kt | karlwalsh | 573,854,263 | false | {"Kotlin": 32685} | import Result.*
import Shape.*
fun main() {
fun part1(input: List<String>): Int =
input.asInputForPart1()
.sumOf { (opponentsShape, yourShape) ->
val result = yourShape.against(opponentsShape)
yourShape.score() + result.score()
}
fun part2(input... | 0 | Kotlin | 0 | 0 | f5ff9432f1908575cd23df192a7cb1afdd507cee | 3,026 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Main.kt | xrrocha | 715,337,265 | false | {"Kotlin": 4981} | import info.debatty.java.stringsimilarity.Damerau
import java.io.File
import kotlin.math.max
fun main(args: Array<String>) {
val maxScore = 0.4
val damerau = Damerau()
val baseDir = File("src/test/resources")
val words = File(baseDir, "words.txt")
.bufferedReader()
.lineSequence()
... | 0 | Kotlin | 0 | 0 | c571546a4ab09ec41be737d39524cec06fb9a213 | 4,981 | grappolo-pg | Apache License 2.0 |
src/Day10.kt | MatthiasDruwe | 571,730,990 | false | {"Kotlin": 47864} |
fun main() {
fun calculateValue(cycle:Int, v: Int): Int{
if(cycle%40==20){
return cycle*v
}
return 0
}
fun part1(input: List<String>): Int {
var cycle = 1
var value = 1
var sum = 0
input.forEach {
val split = it.split(" ")
... | 0 | Kotlin | 0 | 0 | f35f01cea5075cfe7b4a1ead9b6480ffa57b4989 | 2,136 | Advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | lsimeonov | 572,929,910 | false | {"Kotlin": 66434} | fun main() {
val az = ('a'..'z').toList() + ('A'..'Z').toList()
fun part1(input: List<String>): Int {
return input.map {
it.chunked(it.length / 2)
.reduce { acc, string -> string.toList().intersect(acc.toList().toSet()).first().toString() }.first()
}.fold(0) { acc:... | 0 | Kotlin | 0 | 0 | 9d41342f355b8ed05c56c3d7faf20f54adaa92f1 | 941 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2021/day20/day20.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2021.day20
import biz.koziolek.adventofcode.*
fun main() {
val inputFile = findInput(object {})
val lines = inputFile.bufferedReader().readLines()
val lookupTable = parseLookupTable(lines)
val image0 = parseInputImage(lines)
val image2 = enhanceNTimes(image0... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 3,536 | advent-of-code | MIT License |
src/Day08.kt | jamie23 | 573,156,415 | false | {"Kotlin": 19195} | import Direction.*
import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
val height = input.size
val width = input[0].length
val set: HashSet<Pair<Int, Int>> = hashSetOf()
for (i in 0 until height) {
var currMaxX = -1
var currMaxY = -1
... | 0 | Kotlin | 0 | 0 | cfd08064654baabea03f8bf31c3133214827289c | 4,414 | Aoc22 | Apache License 2.0 |
src/com/wd/algorithm/leetcode/ALGO0001.kt | WalkerDenial | 327,944,547 | false | null | package com.wd.algorithm.leetcode
import com.wd.algorithm.test
/**
* 1. 两数之和
*
* 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那两个整数,并返回它们的数组下标。
* 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。
* 你可以按任意顺序返回答案。
*/
class ALGO0001 {
/**
* 方式一
* 冒泡方式
* 时间复杂度 T(n²)
*/
fun twoSum1(num: IntArray, t... | 0 | Kotlin | 0 | 0 | 245ab89bd8bf467625901034dc1139f0a626887b | 1,552 | AlgorithmAnalyze | Apache License 2.0 |
src/Day20.kt | wgolyakov | 572,463,468 | false | null | fun main() {
fun part1(input: List<String>): Int {
val numbers = input.map { it.toInt() }.toMutableList()
val indToCurrInd = numbers.indices.associateWith { it }.toMutableMap()
val n = numbers.size
for ((ind, x) in numbers.toList().withIndex()) {
val i = indToCurrInd[ind]!!
numbers.removeAt(i)
for (en... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 1,841 | advent-of-code-2022 | Apache License 2.0 |
src/Day01.kt | diesieben07 | 572,879,498 | false | {"Kotlin": 44432} | import kotlin.math.max
private val file = "Day01"
private fun Sequence<String>.parseInput(): Sequence<Int?> {
return map { it.toIntOrNull() } + null
}
private fun part1() {
data class State(val maxSoFar: Int = Integer.MIN_VALUE, val accumulator: Int = 0)
val max = streamInput(file) { lines ->
li... | 0 | Kotlin | 0 | 0 | 0b9993ef2f96166b3d3e8a6653b1cbf9ef8e82e6 | 1,832 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day-02.kt | warriorzz | 728,357,548 | false | {"Kotlin": 15609, "PowerShell": 237} | package com.github.warriorzz.aoc
class Day2 : Day(2) {
var games: List<Game> = listOf()
var testGames: List<Game> = listOf()
override fun init() {
games = input.map { line ->
val id = line.split(": ")[0].split(" ")[1].toInt()
val sets = line.split(": ")[1].split("; ").map {... | 0 | Kotlin | 0 | 1 | 502993c1cd414c0ecd97cda41475401e40ebb8c1 | 2,419 | aoc-23 | MIT License |
src/year2021/Day2.kt | drademacher | 725,945,859 | false | {"Kotlin": 76037} | package year2021
import readLines
fun main() {
val input = readLines("2021", "day2").map { Movement.fromString(it) }
val testInput = readLines("2021", "day2_test").map { Movement.fromString(it) }
check(part1(testInput) == 150)
println("Part 1:" + part1(input))
check(part2(testInput) == 900)
... | 0 | Kotlin | 0 | 0 | 4c4cbf677d97cfe96264b922af6ae332b9044ba8 | 1,782 | advent_of_code | MIT License |
src/main/aoc2018/Day11.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2018
class Day11(input: String) {
private val serialNumber = input.toInt()
private val grid = List(300) { x -> List(300) { y -> getPowerLevel(x + 1, y + 1) } }
fun getPowerLevel(x: Int, y: Int): Int {
val rackId = x + 10
var powerLevel = rackId * y
powerLevel += serial... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 3,406 | aoc | MIT License |
src/main/kotlin/g2501_2600/s2538_difference_between_maximum_and_minimum_price_sum/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2501_2600.s2538_difference_between_maximum_and_minimum_price_sum
// #Hard #Array #Dynamic_Programming #Depth_First_Search #Tree
// #2023_07_04_Time_1054_ms_(100.00%)_Space_106.6_MB_(100.00%)
class Solution {
private lateinit var tree: Array<ArrayList<Int>?>
private lateinit var price: IntArray
pr... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,171 | LeetCode-in-Kotlin | MIT License |
src/Day04.kt | arnoutvw | 572,860,930 | false | {"Kotlin": 33036} |
fun main() {
fun toRange(str: String): IntRange = str
.split("-")
.let { (a, b) -> a.toInt()..b.toInt() }
fun part1(input: List<String>): Int {
var sum = 0
input.forEach {
val split = it.split(",")
val first = toRange(split.get(0))
val secon... | 0 | Kotlin | 0 | 0 | 0cee3a9249fcfbe358bffdf86756bf9b5c16bfe4 | 1,349 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/org/sjoblomj/adventofcode/day2/Day2.kt | sjoblomj | 161,537,410 | false | null | package org.sjoblomj.adventofcode.day2
import org.sjoblomj.adventofcode.readFile
import java.util.stream.IntStream
import kotlin.system.measureTimeMillis
private const val inputFile = "src/main/resources/inputs/day2.txt"
fun day2() {
println("== DAY 2 ==")
val timeTaken = measureTimeMillis { calculateAndPrintDa... | 0 | Kotlin | 0 | 0 | 80db7e7029dace244a05f7e6327accb212d369cc | 2,249 | adventofcode2018 | MIT License |
src/test/kotlin/nl/dirkgroot/adventofcode/year2022/Day14Test.kt | dirkgroot | 317,968,017 | false | {"Kotlin": 187862} | package nl.dirkgroot.adventofcode.year2022
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import nl.dirkgroot.adventofcode.util.input
import nl.dirkgroot.adventofcode.util.invokedWith
import java.lang.Integer.max
import kotlin.math.min
private fun solution1(input: String) = createCave(... | 1 | Kotlin | 1 | 1 | ffdffedc8659aa3deea3216d6a9a1fd4e02ec128 | 2,686 | adventofcode-kotlin | MIT License |
src/Day03.kt | RobvanderMost-TomTom | 572,005,233 | false | {"Kotlin": 47682} | fun main() {
fun String.splitRucksack() =
toCharArray(0, length / 2) to toCharArray(length / 2)
fun Char.toPriority() =
if (this in 'a'..'z') {
this - 'a' + 1
} else {
this - 'A' + 27
}
fun part1(input: List<String>): Int {
return input.map {... | 5 | Kotlin | 0 | 0 | b7143bceddae5744d24590e2fe330f4e4ba6d81c | 992 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | object Day05 {
const val dayNumber = "05"
const val EXPECTED_PART1_CHECK_ANSWER = "CMZ"
const val EXPECTED_PART2_CHECK_ANSWER = "MCD"
const val STACK_SETUP_ENTRY_WITH_SPACE_SIZE = 4
const val STACK_SETUP_ENTRY_SIZE = 3
}
fun main() {
fun List<String>.parseStackSetup(): List<MutableList<Char>... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 2,947 | aoc-2022-in-kotlin | Apache License 2.0 |
src/year2021/Day11.kt | drademacher | 725,945,859 | false | {"Kotlin": 76037} | package year2021
import Point
import readLines
fun main() {
val input = parseInput(readLines("2021", "day11"))
val testInput = parseInput(readLines("2021", "day11_test"))
check(part1(testInput.clone()) == 1656)
println("Part 1:" + part1(input.clone()))
check(part2(testInput.clone()) == 195)
... | 0 | Kotlin | 0 | 0 | 4c4cbf677d97cfe96264b922af6ae332b9044ba8 | 3,573 | advent_of_code | MIT License |
kotlin/src/katas/kotlin/leetcode/contiguous_sum/ContiguousSum.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.contiguous_sum
import datsok.shouldEqual
import org.junit.Test
/**
* Given an array of integers and a target, check if there is a contiguous sequence that sums to that target.
*/
class ContiguousSumTests {
@Test fun examples() {
findRange(arrayOf(2, 5, 7), target = 2) shoul... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,507 | katas | The Unlicense |
src/day08/Day08.kt | pnavais | 574,712,395 | false | {"Kotlin": 54079} | package day08
import readInput
import kotlin.math.max
typealias Grid = MutableList<List<TreeInfo>>
class TreeInfo(val height: Short, var visible: Boolean, var scenicScore: Long)
fun buildGrid(input: List<String>): Grid {
val grid = mutableListOf<List<TreeInfo>>()
for (line in input) {
grid.add(line.... | 0 | Kotlin | 0 | 0 | ed5f521ef2124f84327d3f6c64fdfa0d35872095 | 3,818 | advent-of-code-2k2 | Apache License 2.0 |
src/Day02.kt | laricchia | 434,141,174 | false | {"Kotlin": 38143} | private const val CMD_FWD = "forward"
private const val CMD_UP = "up"
private const val CMD_DWN = "down"
fun firstPart02(commands : List<Pair<String, Int>>) {
val fwds = commands.filter { it.first == CMD_FWD }
val ups = commands.filter { it.first == CMD_UP }
val downs = commands.filter { it.first == CMD_D... | 0 | Kotlin | 0 | 0 | 7041d15fafa7256628df5c52fea2a137bdc60727 | 1,245 | Advent_of_Code_2021_Kotlin | Apache License 2.0 |
14/kotlin/src/main/kotlin/se/nyquist/Transformer.kt | erinyq712 | 437,223,266 | false | {"Kotlin": 91638, "C#": 10293, "Emacs Lisp": 4331, "Java": 3068, "JavaScript": 2766, "Perl": 1098} | package se.nyquist
class Transformer(private val rules: Rules) {
fun transform(i: Int, input: String): String {
return when (i) {
0 -> {
input
}
1 -> {
next(input)
}
else -> {
transform(i-1, next(inp... | 0 | Kotlin | 0 | 0 | b463e53f5cd503fe291df692618ef5a30673ac6f | 1,880 | adventofcode2021 | Apache License 2.0 |
src/Day02.kt | rtperson | 434,792,067 | false | {"Kotlin": 6811} | fun main() {
fun mapToPairs(input: List<String>) : List<Pair<String, Int>> =
input.map {
val (d, x) = it.split(" ")
Pair(d, x.toInt())
}
fun computeDistance(orders: List<String>): List<Int> {
var horizontalPosition = 0
var depth = 0
for (dir in ... | 0 | Kotlin | 0 | 0 | ae827a46c8aba336a7d46762f4e1a94bc1b9d850 | 1,954 | Advent_of_Code_Kotlin | Apache License 2.0 |
day-23/src/main/kotlin/Amphipod.kt | diogomr | 433,940,168 | false | {"Kotlin": 92651} | import kotlin.math.abs
import kotlin.system.measureTimeMillis
fun main() {
val partOneMillis = measureTimeMillis {
println("Part One Solution: ${partOne()}")
}
println("Part One Solved in: $partOneMillis ms")
val partTwoMillis = measureTimeMillis {
println("Part Two Solution: ${partTwo... | 0 | Kotlin | 0 | 0 | 17af21b269739e04480cc2595f706254bc455008 | 6,576 | aoc-2021 | MIT License |
src/main/kotlin/dk/lessor/Day12.kt | aoc-team-1 | 317,571,356 | false | {"Java": 70687, "Kotlin": 34171} | package dk.lessor
import kotlin.math.absoluteValue
fun main() {
val directions = readFile("day_12.txt").map { parseDirectionInput(it) }
val option1 = navigateStorm(directions, Ship::move)
println(option1.distance)
val option2 = navigateStorm(directions, Ship::moveWithWaypoint)
println(option2.dist... | 0 | Java | 0 | 0 | 48ea750b60a6a2a92f9048c04971b1dc340780d5 | 3,173 | lessor-aoc-comp-2020 | MIT License |
src/Day04.kt | defvs | 572,381,346 | false | {"Kotlin": 16089} | fun main() {
fun part1(input: List<String>) = input.count { assignment ->
val (range1, range2) = assignment.split(",")
val (lower1, upper1) = range1.split("-").map { it.toInt() }
val (lower2, upper2) = range2.split("-").map { it.toInt() }
lower1 <= lower2 && upper1 >= upper2 || lower2 <= lower1 && upper2 >=... | 0 | Kotlin | 0 | 1 | caa75c608d88baf9eb2861eccfd398287a520a8a | 952 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day12.kt | zfz7 | 573,100,794 | false | {"Kotlin": 53499} | import java.util.*
fun main() {
println(day12A(readFile("Day12")))
println(day12B(readFile("Day12")))
}
val heightMap = listOf(
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
... | 0 | Kotlin | 0 | 0 | c50a12b52127eba3f5706de775a350b1568127ae | 5,466 | AdventOfCode22 | Apache License 2.0 |
Taxi Park/src/taxipark/TaxiParkTask.kt | Sharkaboi | 258,941,707 | false | null | package taxipark
/*
* Task #1. Find all the drivers who performed no trips.
*/
fun TaxiPark.findFakeDrivers(): Set<Driver> {
return this.allDrivers.minus(this.trips.map { it.driver }).toSet()
}
/*
* Task #2. Find all the clients who completed at least the given number of trips.
*/
fun TaxiPark.findFaithfulPass... | 0 | Kotlin | 0 | 0 | 977968b41ecc0ed1b62b50784bfebc3fa9d95a11 | 3,000 | Kotlin-for-java-devs-course | MIT License |
src/day02/Day02.kt | Mini-Stren | 573,128,699 | false | null | package day02
import readInputLines
fun main() {
val day = 2
fun part1(input: List<String>): Int {
return Day02_part1.gameRounds(input).sumOf(Day02.GameRound::score)
}
fun part2(input: List<String>): Int {
return Day02_part2.gameRounds(input).sumOf(Day02.GameRound::score)
}
... | 0 | Kotlin | 0 | 0 | 40cb18c29089783c9b475ba23c0e4861d040e25a | 1,680 | aoc-2022-kotlin | Apache License 2.0 |
2021/src/main/kotlin/aoc/day2.kt | daf276 | 433,385,608 | false | null | package aoc.day2
sealed class Instruction {
data class FORWARD(val value: Int) : Instruction()
data class DOWN(val value: Int) : Instruction()
data class UP(val value: Int) : Instruction()
}
fun parseInstructions(input: List<String>): List<Instruction> =
input.map { it.split(" ") }.map { (instruction... | 0 | Rust | 0 | 0 | d397cfe0daab24604615d551cbdb7c6ae145ae74 | 1,495 | AdventOfCode | MIT License |
src/Day04.kt | AlexeyVD | 575,495,640 | false | {"Kotlin": 11056} | fun main() {
fun part1(input: List<String>): Int {
return input.map { toSections(it) }.count { it.fullyCovered() }
}
fun part2(input: List<String>): Int {
return input.map { toSections(it) }.count { it.intersected() }
}
val testInput = readInput("Day04_test")
check(part1(testIn... | 0 | Kotlin | 0 | 0 | ec217d9771baaef76fa75c4ce7cbb67c728014c0 | 1,294 | advent-kotlin | Apache License 2.0 |
src/main/kotlin/io/github/clechasseur/adventofcode2021/Day15.kt | clechasseur | 435,726,930 | false | {"Kotlin": 315943} | package io.github.clechasseur.adventofcode2021
import io.github.clechasseur.adventofcode2021.data.Day15Data
import io.github.clechasseur.adventofcode2021.dij.Dijkstra
import io.github.clechasseur.adventofcode2021.dij.Graph
import io.github.clechasseur.adventofcode2021.util.Direction
import io.github.clechasseur.advent... | 0 | Kotlin | 0 | 0 | 4b893c001efec7d11a326888a9a98ec03241d331 | 2,139 | adventofcode2021 | MIT License |
2015/kt/src/test/kotlin/org/adventofcode/Day21.kt | windmaomao | 225,344,109 | false | {"JavaScript": 538717, "Ruby": 89779, "Kotlin": 58408, "Rust": 21350, "Go": 19106, "TypeScript": 9930, "Haskell": 8908, "Dhall": 3201, "PureScript": 1488, "HTML": 1307, "CSS": 1092} | package org.adventofcode
data class Item(
val name: String,
val cost: Int,
val damage: Int,
val armor: Int
) {}
data class Profile(val items: List<Item>) {
fun name() = items.map { it.name }.joinToString("/")
fun cost() = items.sumBy { it.cost }
fun damage() = items.sumBy { it.damage }
fun armor() = i... | 5 | JavaScript | 0 | 0 | 1d64d7fffa6fcfc6825e6aa9322eda76e790700f | 2,667 | adventofcode | MIT License |
src/main/kotlin/Day8.kt | vw-anton | 574,945,231 | false | {"Kotlin": 33295} | fun main() {
part1()
part2()
}
private fun part1() {
val trees = readFile("input/8.txt")
.map { line -> line.toList().toTypedArray() }
.toTypedArray()
val size = trees.size
val visible = Array(size) { i -> Array(size) { j -> 0 } }
for (row in 1 until size - 1) {
for (c... | 0 | Kotlin | 0 | 0 | a823cb9e1677b6285bc47fcf44f523e1483a0143 | 3,281 | aoc2022 | The Unlicense |
src/Day03.kt | rafael-ribeiro1 | 572,657,838 | false | {"Kotlin": 15675} | fun main() {
fun part1(input: List<String>): Int {
return input.map { it.toList().windowed(it.length / 2, it.length / 2) }
.sumOf { it[0].intersect(it[1]).sumOf { letter -> letter.priority } }
}
fun part2(input: List<String>): Int {
return input.map { it.toList() }
.... | 0 | Kotlin | 0 | 0 | 5cae94a637567e8a1e911316e2adcc1b2a1ee4af | 818 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/aoc2015/ItHangsInTheBalance.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2015
import komu.adventofcode.utils.nonEmptyLines
import komu.adventofcode.utils.product
fun itHangsInTheBalance1(input: String): Long {
val weights = input.nonEmptyLines().map { it.toLong() }.reversed()
val expectedWeight = weights.sum() / 3
var bestSize = Integer.MAX_VALUE
... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 3,864 | advent-of-code | MIT License |
2023/src/main/kotlin/day18_fast.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.Vec2l
import utils.mapItems
import kotlin.math.absoluteValue
fun main() {
Day18Fast.run()
}
object Day18Fast : Solution<List<Day18.Line>>() {
override val name = "day18"
override val parser = Parser.lines.mapItems { Day18.parseLine(it) }
private fun solv... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,335 | aoc_kotlin | MIT License |
src/Day04.kt | WilsonSunBritten | 572,338,927 | false | {"Kotlin": 40606} | fun main() {
fun part1(input: List<String>): Int {
return input.map { row ->
val split = row.split(",").map {
val split = it.split("-")
split[0].toInt() to split[1].toInt()
}
val firstPair = split[0]
val secondPair = split[1]
... | 0 | Kotlin | 0 | 0 | 363252ffd64c6dbdbef7fd847518b642ec47afb8 | 1,648 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/day12/Day12.kt | TheSench | 572,930,570 | false | {"Kotlin": 128505} | package day12
import Lines
import runDay
import utils.Point
fun main() {
fun part1(input: List<String>) = input.toGrid().shortestPath()
fun part2(input: List<String>) = input.toGrid().let { grid ->
grid.shortestPath(
startingPoint = grid.end,
isDestination = { grid[this] == 0... | 0 | Kotlin | 0 | 0 | c3e421d75bc2cd7a4f55979fdfd317f08f6be4eb | 2,754 | advent-of-code-2022 | Apache License 2.0 |
kotlin/problems/src/solution/NumberProblems.kt | lunabox | 86,097,633 | false | {"Kotlin": 146671, "Python": 38767, "JavaScript": 19188, "Java": 13966} | package solution
import java.math.BigInteger
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.HashSet
import kotlin.math.*
class NumberProblems {
/**
* https://leetcode-cn.com/problems/k-diff-pairs-in-an-array/
* 给定一个整数数组和一个整数 k, 你需要在数组里... | 0 | Kotlin | 0 | 0 | cbb2e3ad8f2d05d7cc54a865265561a0e391a9b9 | 35,791 | leetcode | Apache License 2.0 |
aoc-2018/src/main/kotlin/nl/jstege/adventofcode/aoc2018/days/Day12.kt | JStege1206 | 92,714,900 | false | null | package nl.jstege.adventofcode.aoc2018.days
import nl.jstege.adventofcode.aoccommon.days.Day
import nl.jstege.adventofcode.aoccommon.utils.extensions.head
import nl.jstege.adventofcode.aoccommon.utils.extensions.sumBy
class Day12 : Day(title = "Subterranean Sustainability") {
private companion object Configuratio... | 0 | Kotlin | 0 | 0 | d48f7f98c4c5c59e2a2dfff42a68ac2a78b1e025 | 2,119 | AdventOfCode | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.