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/Day08.kt | jorander | 571,715,475 | false | {"Kotlin": 28471} | typealias Trees = Grid2D<Char>
typealias TreePosition = Position2D
typealias Direction = (TreePosition, Trees) -> List<TreePosition>
fun main() {
val day = "Day08"
val up: Direction =
{ tp: TreePosition, _: Trees -> (0 until tp.y).map { TreePosition(tp.x, it) }.reversed() }
val down: Direction =
... | 0 | Kotlin | 0 | 0 | 1681218293cce611b2c0467924e4c0207f47e00c | 2,709 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/be/inniger/euler/problems01to10/Problem05.kt | bram-inniger | 135,620,989 | false | {"Kotlin": 20003} | package be.inniger.euler.problems01to10
import be.inniger.euler.util.EratosthenesSieve
import be.inniger.euler.util.pow
private const val MAX_VALUE = 20
/**
* Smallest multiple
*
* 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
* What is the smallest po... | 0 | Kotlin | 0 | 0 | 8fea594f1b5081a824d829d795ae53ef5531088c | 1,866 | euler-kotlin | MIT License |
src/Day08.kt | sebastian-heeschen | 572,932,813 | false | {"Kotlin": 17461} | fun main() {
fun plantTrees(input: List<String>) = input
.map { line -> line.map { it.digitToInt() } }
.let { grid ->
grid.flatMapIndexed { y: Int, row: List<Int> ->
row.mapIndexed { x, height ->
Tree(
x = x,
... | 0 | Kotlin | 0 | 0 | 4432581c8d9c27852ac217921896d19781f98947 | 2,031 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | Soykaa | 576,055,206 | false | {"Kotlin": 14045} | private fun moveToPoints(move: String): Int = when (move) {
"A", "X" -> 1
"B", "Y" -> 2
"C", "Z" -> 3
else -> 0
}
private fun resToPoints(gameResult: String): Int = when (gameResult) {
"X" -> 0
"Y" -> 3
"Z" -> 6
else -> 0
}
private fun currentResult(gameMove: List<Int>): Int = if (game... | 0 | Kotlin | 0 | 0 | 1e30571c475da4db99e5643933c5341aa6c72c59 | 1,576 | advent-of-kotlin-2022 | Apache License 2.0 |
src/Day08.kt | ty-garside | 573,030,387 | false | {"Kotlin": 75779} | // Day 08 - Treetop Tree House
// https://adventofcode.com/2022/day/8
import Direction.*
fun main() {
data class Tree(
val row: Int,
val column: Int,
val height: Int
)
class Trees(input: List<String>) {
private val trees = input.mapIndexed { row, line ->
line.... | 0 | Kotlin | 0 | 0 | 49ea6e3ad385b592867676766dafc48625568867 | 6,718 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day07.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | import kotlin.math.min
fun main() {
val testInput = readInput("Day07_test")
check(part1(testInput) == 95437)
check(part2(testInput) == 24933642)
val input = readInput("Day07")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>): Int {
val rootNode = buildT... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 2,502 | aoc-22 | Apache License 2.0 |
src/main/kotlin/Day4.kt | Filipe3xF | 433,908,642 | false | {"Kotlin": 30093} | import utils.Day
fun main() = Day(4, ::extractBingo,
{
it.play().let { (lastNumberCalled, winningBoard) -> winningBoard.calculateScore(lastNumberCalled) }
},
{
it.playLastManStanding()
.let { (lastNumberCalled, winningBoard) -> winningBoard.calculateScore(lastNumberCalled) }
... | 0 | Kotlin | 0 | 1 | 7df9d17f0ac2b1c103b5618ca676b5a20eb43408 | 2,769 | advent-of-code-2021 | MIT License |
2021/kotlin/src/main/kotlin/nl/sanderp/aoc/aoc2021/day04/Day04.kt | sanderploegsma | 224,286,922 | false | {"C#": 233770, "Kotlin": 126791, "F#": 110333, "Go": 70654, "Python": 64250, "Scala": 11381, "Swift": 5153, "Elixir": 2770, "Jinja": 1263, "Ruby": 1171} | package nl.sanderp.aoc.aoc2021.day04
import nl.sanderp.aoc.common.measureDuration
import nl.sanderp.aoc.common.prettyPrint
import nl.sanderp.aoc.common.readResource
fun main() {
val (numbers, boards) = parse(readResource("Day04.txt").lines())
val (answer1, duration1) = measureDuration<Int> { partOne(numbers,... | 0 | C# | 0 | 6 | 8e96dff21c23f08dcf665c68e9f3e60db821c1e5 | 2,362 | advent-of-code | MIT License |
src/main/kotlin/day8/CrossedWires.kt | Arch-vile | 433,381,878 | false | {"Kotlin": 57129} | package day8
import utils.permutations
import utils.read
import utils.sort
data class SegmentData(val input: List<String>, val output: List<String>)
fun main() {
solve()
.let { println(it) }
}
const val allSegments = "abcdefg"
const val zero = "abcefg"
const val one = "cf"
const val two = "acdeg"
const... | 0 | Kotlin | 0 | 0 | 4cdafaa524a863e28067beb668a3f3e06edcef96 | 2,323 | adventOfCode2021 | Apache License 2.0 |
src/day16/Day16.kt | gautemo | 317,316,447 | false | null | package day16
import shared.getLines
enum class ReadMode{
RULES, MY_TICKET, NEARBY_TICKETS
}
fun ticketInvalid(input: List<String>): Int{
val sections = NotesSections(input)
val invalids = mutableListOf<Int>()
for(ticket in sections.otherTickets){
invalids.addAll(ticket.split(',').map { it.t... | 0 | Kotlin | 0 | 0 | ce25b091366574a130fa3d6abd3e538a414cdc3b | 3,141 | AdventOfCode2020 | MIT License |
src/main/kotlin/days/Day16.kt | mstar95 | 317,305,289 | false | null | package days
import util.groupByEmpty
class Day16 : Day(16) {
override fun partOne(): Any {
val input = prepareInput(inputList)
//println(input)
val (validators, myTicket, otherTickets) = input
val bad = otherTickets.flatMap { getInvalidFields(it, validators) }
//println(... | 0 | Kotlin | 0 | 0 | ca0bdd7f3c5aba282a7aa55a4f6cc76078253c81 | 3,138 | aoc-2020 | Creative Commons Zero v1.0 Universal |
2021/src/main/kotlin/Day15.kt | eduellery | 433,983,584 | false | {"Kotlin": 97092} | import java.util.PriorityQueue
class Day15(val input: Grid) {
private fun cost(grid: Grid): Int {
val dist = Array(grid.size) { Array(grid.first().size) { Int.MAX_VALUE } }.apply { this[0][0] = 0 }
val toVisit = PriorityQueue<Pair<Int, Int>> { (pY, pX), (rY, rX) -> dist[pY][pX].compareTo(dist[rY][... | 0 | Kotlin | 0 | 1 | 3e279dd04bbcaa9fd4b3c226d39700ef70b031fc | 1,872 | adventofcode-2021-2025 | MIT License |
src/main/kotlin/com/briarshore/aoc2022/day12/HillClimbingPuzzle.kt | steveswing | 579,243,154 | false | {"Kotlin": 47151} | package com.briarshore.aoc2022.day12
import com.briarshore.aoc2022.day12.ParcelKind.END
import com.briarshore.aoc2022.day12.ParcelKind.START
import com.briarshore.aoc2022.day12.Terrain.Companion.parse
import println
import readInput
typealias Coordinates = Pair<Int, Int>
enum class ParcelKind {
START, BETWEEN, EN... | 0 | Kotlin | 0 | 0 | a0d19d38dae3e0a24bb163f5f98a6a31caae6c05 | 3,340 | 2022-AoC-Kotlin | Apache License 2.0 |
year2021/src/main/kotlin/net/olegg/aoc/year2021/day8/Day8.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2021.day8
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2021.DayOf2021
/**
* See [Year 2021, Day 8](https://adventofcode.com/2021/day/8)
*/
object Day8 : DayOf2021(8) {
override fun first(): Any? {
return lines
.map { it.split(" | ").last() }
.flatMap { it... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 2,387 | adventofcode | MIT License |
src/Day03.kt | EemeliHeinonen | 574,062,219 | false | {"Kotlin": 6073} | fun splitSack(sack: String): Pair<String, String> {
val split = sack.chunked(sack.length/2)
return Pair(split[0], split[1])
}
fun generatePriorities(): Map<Char, Int> {
var lettersAndPriorities = mutableMapOf<Char, Int>()
var lowerCasePriority = 1
var upperCasePriority = 27
// map lowercase va... | 0 | Kotlin | 0 | 0 | 33775d9e6e848ab0efae0e3f00f43368c036799d | 1,802 | aoc-22-kotlin | Apache License 2.0 |
src/Day08.kt | jalex19100 | 574,686,993 | false | {"Kotlin": 19795} | fun main() {
fun buildGrid(input: List<String>): Array<IntArray> {
val trees = Array(input[0].length) { IntArray(input.size) }
var rowNum = 0
input.forEach { line ->
val rowOfTrees = line.toCharArray().map { c -> c.digitToInt() }
trees[rowNum++] = rowOfTrees.toIntArr... | 0 | Kotlin | 0 | 0 | a50639447a2ef3f6fc9548f0d89cc643266c1b74 | 3,408 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day15.kt | jbotuck | 573,028,687 | false | {"Kotlin": 42401} | import kotlin.math.abs
import kotlin.math.max
fun main() {
val sensors = readInput("Day15")
.map { Sensor.of(it) }
//part1
val row = 2000000
sensors
.map { it.ruleOutForRow(row) }
.run {
(minOf { it.first }..maxOf { it.last })
.count { x ->
... | 0 | Kotlin | 0 | 0 | d5adefbcc04f37950143f384ff0efcd0bbb0d051 | 2,977 | aoc2022 | Apache License 2.0 |
src/main/kotlin/dec16/Main.kt | dladukedev | 318,188,745 | false | null | package dec16
data class ValidationInformation(
val name: String,
val ranges: List<IntRange>
)
data class TicketInformation(
val validation: List<ValidationInformation>,
val myTicket: List<Int>,
val otherTickets: List<List<Int>>
)
fun parseValidation(input: String): List<ValidationInformation> {
... | 0 | Kotlin | 0 | 0 | d4591312ddd1586dec6acecd285ac311db176f45 | 4,112 | advent-of-code-2020 | MIT License |
y2021/src/main/kotlin/adventofcode/y2021/Day12.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2021
import adventofcode.io.AdventSolution
object Day12 : AdventSolution(2021, 12, "Passage Pathing") {
override fun solvePartOne(input: String) = solve(input, Path::visit1)
override fun solvePartTwo(input: String) = solve(input, Path::visit2)
private inline fun solve(input: String... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,889 | advent-of-code | MIT License |
src/main/kotlin/kt/kotlinalgs/app/sorting/crack/AnagramSorter.ws.kts | sjaindl | 384,471,324 | false | null | package kt.kotlinalgs.app.sorting
val strings = listOf(
"lampe", "tor", "hendl", "palme", "ronaldo", "ampel", "rot", "abc", "z"
)
val sorted = sortAnagrams(strings)
println(sorted)
val fast = strings.toMutableList()
sortAnagramsFast(fast)
println(fast)
class AnagramComparator : Comparator<String> {
// O(S) ... | 0 | Java | 0 | 0 | e7ae2fcd1ce8dffabecfedb893cb04ccd9bf8ba0 | 2,163 | KotlinAlgs | MIT License |
app/src/main/kotlin/com/jamjaws/adventofcode/xxiii/day/Day02.kt | JamJaws | 725,792,497 | false | {"Kotlin": 30656} | package com.jamjaws.adventofcode.xxiii.day
import com.jamjaws.adventofcode.xxiii.readInput
class Day02 {
fun part1(text: List<String>): Int = text.map(::parseRow).let(::getPossibleGames).map(Game::id).sum()
fun part2(text: List<String>): Int =
text.map(::parseRow)
.map { game ->
... | 0 | Kotlin | 0 | 0 | e2683305d762e3d96500d7268e617891fa397e9b | 1,853 | advent-of-code-2023 | MIT License |
src/main/kotlin/com/oocode/ScratchCard.kt | ivanmoore | 725,978,325 | false | {"Kotlin": 42155} | package com.oocode
fun scratchCardScoreFrom(input: String): Int =
input.split("\n").mapIndexed { index, line -> scratchCardComparisonFrom(index + 1, line).score() }.sum()
fun scratchCardsFrom(input: String): Map<Int, List<ScratchCardComparison>> {
val scratchCardComparisons =
input.split("\n").mapInde... | 0 | Kotlin | 0 | 0 | 36ab66daf1241a607682e7f7a736411d7faa6277 | 2,151 | advent-of-code-2023 | MIT License |
lib/src/main/kotlin/com/bloidonia/advent/day04/Day04.kt | timyates | 433,372,884 | false | {"Kotlin": 48604, "Groovy": 33934} | package com.bloidonia.advent.day04
import com.bloidonia.advent.BaseDay
import com.bloidonia.advent.readText
import java.util.regex.Pattern
data class Square(val number: Int, var seen: Boolean = false)
data class Board(val grid: List<List<Square>>) {
val width = grid.first().size
private fun transpose() = Boa... | 0 | Kotlin | 0 | 1 | 9714e5b2c6a57db1b06e5ee6526eb30d587b94b4 | 2,181 | advent-of-kotlin-2021 | MIT License |
app/src/main/kotlin/com/jamjaws/adventofcode/xxiii/day/Day05.kt | JamJaws | 725,792,497 | false | {"Kotlin": 30656} | package com.jamjaws.adventofcode.xxiii.day
import com.jamjaws.adventofcode.xxiii.readInput
class Day05 {
fun part1(text: List<String>): Long {
val seeds = text.first().substringAfter("seeds: ").split(' ').map(String::toLong)
val maps = parseMaps(text)
return seeds.minOf { getLocation(maps... | 0 | Kotlin | 0 | 0 | e2683305d762e3d96500d7268e617891fa397e9b | 2,633 | advent-of-code-2023 | MIT License |
src/Day08.kt | robinpokorny | 572,434,148 | false | {"Kotlin": 38009} | class Tree(val value: Int, val i: Int, val j: Int) {}
typealias Forrest = List<List<Tree>>
private fun parse(input: List<String>): Forrest = input.mapIndexed { i, line ->
line.toList().mapIndexed { j, char ->
Tree(char.digitToInt(), i, j)
}
}
private fun findIn1D(seen: MutableSet<Tree>) =
{ highe... | 0 | Kotlin | 0 | 2 | 56a108aaf90b98030a7d7165d55d74d2aff22ecc | 2,341 | advent-of-code-2022 | MIT License |
src/Day09.kt | JanTie | 573,131,468 | false | {"Kotlin": 31854} | import kotlin.math.absoluteValue
fun main() {
fun parseInput(input: List<String>, amountOfNodes: Int): List<List<Point>> {
val initial = listOf(List(amountOfNodes) { Point(0, 0) })
return input.flatMap {
val (direction, moves) = it.split(" ")
List(moves.toInt()) { direction ... | 0 | Kotlin | 0 | 0 | 3452e167f7afe291960d41b6fe86d79fd821a545 | 2,486 | advent-of-code-2022 | Apache License 2.0 |
codeforces/educationalround95/e.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.educationalround95
fun main() {
val M = 998244353
val (n, m) = readInts()
val d = readInts().sorted()
val sum = d.sumOf { it.toLong() }
val ab = List(m) { readInts() }.withIndex().sortedBy { -it.value[1] }
var i = n - 1
var large = 0
var sumLarge = 0L
val ans = IntArray(m)
for (p in ab) {
... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,449 | competitions | The Unlicense |
src/day05/Day05.kt | Harvindsokhal | 572,911,840 | false | {"Kotlin": 11823} | package day05
import readInput
data class Step(val amount: Int, val takeFrom: Int, val moveTo: Int) {
companion object {
fun detail(line: String): Step {
return line.split(" ").filterIndexed { index, _ -> index % 2 == 1 }.map { it.toInt()}.let{ Step(it[0], it[1]-1, it[2]-1) }
}
}
}... | 0 | Kotlin | 0 | 0 | 7ebaee4887ea41aca4663390d4eadff9dc604f69 | 1,783 | aoc-2022-kotlin | Apache License 2.0 |
src/Day13.kt | jimmymorales | 572,156,554 | false | {"Kotlin": 33914} | fun main() {
fun CharArray.parseInput(currentIndex: Int = 0): Pair<Input, Int> {
val current = this[currentIndex]
var nextIndex = currentIndex + 1
return if (current == '[') {
val items = mutableListOf<Input>()
while (this[nextIndex] != ']') {
if (this... | 0 | Kotlin | 0 | 0 | fb72806e163055c2a562702d10a19028cab43188 | 3,561 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | jorgecastrejon | 573,097,701 | false | {"Kotlin": 33669} | fun main() {
fun part1(input: List<String>): String {
val (stacks, movementSet) = input.parse()
movementSet.forEach { (amount, from, to) ->
repeat(amount) { stacks[from]?.removeLast()?.let { stacks[to]?.addLast(it) } }
}
return stacks.values.map(ArrayDeque<Char>::remov... | 0 | Kotlin | 0 | 0 | d83b6cea997bd18956141fa10e9188a82c138035 | 1,736 | aoc-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/year2021/Day08.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2021
private val SEGMENTS_TO_DIGITS = mapOf(
setOf('a', 'b', 'c', 'e', 'f', 'g') to 0,
setOf('c', 'f') to 1,
setOf('a', 'c', 'd', 'e', 'g') to 2,
setOf('a', 'c', 'd', 'f', 'g') to 3,
setOf('b', 'c', 'd', 'f') to 4,
setOf('a', 'b', 'd', 'f', 'g') to 5,
setOf('a', 'b', 'd', 'e', '... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 2,394 | advent-of-code | MIT License |
src/day16/Day16.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day16
import com.github.shiguruikai.combinatoricskt.combinations
import com.github.shiguruikai.combinatoricskt.permutations
import readLines
private data class ValveRoom(val name: String, val flowRate: Int, val paths: List<String>) {
companion object {
fun of(input: String): ValveRoom =
... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 5,294 | aoc2022 | Apache License 2.0 |
src/main/kotlin/dev/paulshields/aoc/Day8.kt | Pkshields | 433,609,825 | false | {"Kotlin": 133840} | /**
* Day 8: Seven Segment Search
*/
package dev.paulshields.aoc
import dev.paulshields.aoc.common.readFileAsStringList
fun main() {
println(" ** Day 8: Seven Segment Search ** \n")
val rawCorruptedDisplays = readFileAsStringList("/Day8CorruptedDisplays.txt")
val corruptedOutputs = rawCorruptedDispla... | 0 | Kotlin | 0 | 0 | e3533f62e164ad72ec18248487fe9e44ab3cbfc2 | 3,167 | AdventOfCode2021 | MIT License |
src/y2021/Day14.kt | Yg0R2 | 433,731,745 | false | null | package y2021
import kotlin.collections.Map.Entry
fun main() {
fun part1(input: List<String>): Long {
return input.runSteps(10)
}
fun part2(input: List<String>): Long {
return input.runSteps(40)
}
// test if implementation meets criteria from the description, like:
val testIn... | 0 | Kotlin | 0 | 0 | d88df7529665b65617334d84b87762bd3ead1323 | 1,966 | advent-of-code | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/word_ladder_2/WordLadderTests.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.word_ladder_2
import datsok.*
import org.junit.*
/**
* https://leetcode.com/problems/word-ladder-ii/
*
* Given two words (beginWord and endWord), and a dictionary's word list,
* find all shortest transformation sequence(s) from beginWord to endWord, such that:
* - Only one letter c... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,252 | katas | The Unlicense |
src/Day13.kt | erikthered | 572,804,470 | false | {"Kotlin": 36722} |
enum class Order {
CORRECT,
INCORRECT,
UNDECIDED
}
fun main() {
fun parsePacketData(line: String): Pair<List<Any>, Int> {
val data = mutableListOf<Any>()
var idx = 1
var buffer = ""
var done = false
while(!done) {
when (val c = line[idx]) {
... | 0 | Kotlin | 0 | 0 | 3946827754a449cbe2a9e3e249a0db06fdc3995d | 3,517 | aoc-2022-kotlin | Apache License 2.0 |
src/day12.kts | miedzinski | 434,902,353 | false | {"Kotlin": 22560, "Shell": 113} | sealed class Cave {
val paths = mutableSetOf<Cave>()
object Start : Cave()
object End : Cave()
data class Small(val id: String) : Cave()
data class Big(val id: String) : Cave()
}
val allCaves = mutableMapOf<String, Cave>(
"start" to Cave.Start,
"end" to Cave.End,
)
generateSequence(::read... | 0 | Kotlin | 0 | 0 | 6f32adaba058460f1a9bb6a866ff424912aece2e | 2,004 | aoc2021 | The Unlicense |
src/Day04.kt | afranken | 572,923,112 | false | {"Kotlin": 15538} | fun main() {
fun part1(input: List<String>): Int {
val overlaps = input
.asSequence()
.filterNot(String::isBlank)
.map { //6-6,4-6
it.split(",") // 6-6 4-6
.map {// 6-6
it.split("-") // 6 6
}.... | 0 | Kotlin | 0 | 0 | f047d34dc2a22286134dc4705b5a7c2558bad9e7 | 1,795 | advent-of-code-kotlin-2022 | Apache License 2.0 |
advent-of-code-2023/src/Day12.kt | osipxd | 572,825,805 | false | {"Kotlin": 141640, "Shell": 4083, "Scala": 693} | import lib.repeat
private const val DAY = "Day12"
private typealias Record = Pair<String, List<Int>>
fun main() {
fun testInput() = readInput("${DAY}_test")
fun input() = readInput(DAY)
"Part 1" {
part1(testInput()) shouldBe 21
measureAnswer { part1(input()) }
}
"Part 2" {
... | 0 | Kotlin | 0 | 5 | 6a67946122abb759fddf33dae408db662213a072 | 2,036 | advent-of-code | Apache License 2.0 |
src/Day04.kt | ranveeraggarwal | 573,754,764 | false | {"Kotlin": 12574} | fun main() {
fun contains(first: String, second: String): Boolean {
return ((first.split("-")[0].toInt() <= second.split("-")[0].toInt()) and
(first.split("-")[1].toInt() >= second.split("-")[1].toInt())) or
((first.split("-")[0].toInt() >= second.split("-")[0].toInt()) ... | 0 | Kotlin | 0 | 0 | c8df23daf979404f3891cdc44f7899725b041863 | 1,423 | advent-of-code-2022-kotlin | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year23/Day19.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year23
import com.grappenmaker.aoc.*
fun PuzzleSet.day19() = puzzle(day = 19) {
val (rules, parts) = input.doubleLines()
val ps = parts.lines().map { l ->
l.drop(1).dropLast(1).split(",").associate { p ->
val (c, d) = p.split("=")
c to d.toLong()
... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 2,834 | advent-of-code | The Unlicense |
src/commonMain/kotlin/advent2020/day22/Day22Puzzle.kt | jakubgwozdz | 312,526,719 | false | null | package advent2020.day22
import advent2020.utils.groups
fun part1(input: String): String {
val (p1, p2) = decks(input)
combat(p1, p2)
return score(p1, p2).toString()
}
fun part2(input: String): String {
val (p1, p2) = decks(input)
games = 0
checks = 0
recursiveCombat(p1, p2)
println("... | 0 | Kotlin | 0 | 2 | e233824109515fc4a667ad03e32de630d936838e | 2,177 | advent-of-code-2020 | MIT License |
src/Day14.kt | AxelUser | 572,845,434 | false | {"Kotlin": 29744} | fun main() {
fun List<String>.getStones(): Set<Point<Int>> {
val map = mutableSetOf<Point<Int>>()
for (path in this.map { it.split("->").map { it.trim().split(",").let { (x, y) -> Point(y.toInt(), x.toInt()) } } }) {
for ((from, to) in path.windowed(2)) {
val points = if... | 0 | Kotlin | 0 | 1 | 042e559f80b33694afba08b8de320a7072e18c4e | 2,061 | aoc-2022 | Apache License 2.0 |
src/Day12.kt | robinpokorny | 572,434,148 | false | {"Kotlin": 38009} | import java.util.PriorityQueue
private fun parse(input: List<String>): Triple<Map<Point, Int>, Point, Point> {
var start = Point(0, 0)
var end = Point(0, 0)
val map = input
.flatMapIndexed { i, row ->
row.mapIndexed { j, item ->
val point = Point(i, j)
v... | 0 | Kotlin | 0 | 2 | 56a108aaf90b98030a7d7165d55d74d2aff22ecc | 2,476 | advent-of-code-2022 | MIT License |
src/Day02.kt | Redstonecrafter0 | 571,787,306 | false | {"Kotlin": 19087} |
enum class Move(val score: Int) {
Rock(1), Paper(2), Scissors(3);
fun vs(other: Move): Result {
return when (this) {
Rock -> when (other) {
Rock -> Result.Draw
Paper -> Result.Lost
Scissors -> Result.Won
}
Paper -> whe... | 0 | Kotlin | 0 | 0 | e5dbabe247457aabd6dd0f0eb2eb56f9e4c68858 | 2,703 | Advent-of-Code-2022 | Apache License 2.0 |
src/Day12.kt | tsschmidt | 572,649,729 | false | {"Kotlin": 24089} |
typealias Coord = Pair<Int,Int>
fun main() {
fun findSList(map: List<List<Char>>): List<Pair<Int, Int>> {
val start = mutableListOf<Pair<Int,Int>>()
for(i in map.indices) {
for (j in 0 until map[i].size) {
if (map[i][j] == 'S' || map[i][j] == 'a') {
... | 0 | Kotlin | 0 | 0 | 7bb637364667d075509c1759858a4611c6fbb0c2 | 2,490 | aoc-2022 | Apache License 2.0 |
src/Day08_optimized.kt | Venkat-juju | 572,834,602 | false | {"Kotlin": 27944} | import kotlin.math.max
//1825
//235200
fun main() {
fun List<Int>.indexOfMax(): Int {
var max = Integer.MIN_VALUE
var maxIndex = -1
forEachIndexed { index, value ->
if (max <= value) {
max = index
maxIndex = index
}
}
... | 0 | Kotlin | 0 | 0 | 785a737b3dd0d2259ccdcc7de1bb705e302b298f | 3,086 | aoc-2022 | Apache License 2.0 |
aoc/src/main/kotlin/com/bloidonia/aoc2023/day02/Main.kt | timyates | 725,647,758 | false | {"Kotlin": 45518, "Groovy": 202} | package com.bloidonia.aoc2023.day02
import com.bloidonia.aoc2023.lines
const val example1 = """Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue... | 0 | Kotlin | 0 | 0 | 158162b1034e3998445a4f5e3f476f3ebf1dc952 | 1,943 | aoc-2023 | MIT License |
src/Day09.kt | nguyendanv | 573,066,311 | false | {"Kotlin": 18026} | import kotlin.math.abs
fun main() {
fun follow(moved: Int, follower: Int, positions: List<IntArray>) {
val touching = abs(positions[moved][0] - positions[follower][0]) <= 1
&& abs(positions[moved][1] - positions[follower][1]) <= 1
when {
touching -> {}
else ... | 0 | Kotlin | 0 | 0 | 376512583af723b4035b170db1fa890eb32f2f0f | 2,223 | advent2022 | Apache License 2.0 |
src/y2021/Day07.kt | Yg0R2 | 433,731,745 | false | null | package y2021
import kotlin.math.abs
fun main() {
fun part1(input: List<String>): Int {
val sortedInput = input.flatMap { it.split(",") }
.toIntList()
.sorted()
val avgHeight = sortedInput.average().toInt()
val avgFuelConsumption = sortedInput.sumOf { abs(avgHeight... | 0 | Kotlin | 0 | 0 | d88df7529665b65617334d84b87762bd3ead1323 | 2,094 | advent-of-code | Apache License 2.0 |
day8/src/main/kotlin/Main.kt | joshuabrandes | 726,066,005 | false | {"Kotlin": 47373} | import java.io.File
fun main() {
println("------ Advent of Code 2023 - Day 8 -----")
val puzzleInput = getPuzzleInput()
val (instructions, nodes) = getInstructionsAndNodes(puzzleInput)
val stepsFromAAAToZZZ = stepsFromTo("AAA", { it.name == "ZZZ" }, instructions, nodes.associateBy { it.name })
pr... | 0 | Kotlin | 0 | 1 | de51fd9222f5438efe9a2c45e5edcb88fd9f2232 | 2,693 | aoc-2023-kotlin | The Unlicense |
src/y2015/Day09.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2015
import util.readInput
object Day09 {
private fun parse(input: List<String>): MutableMap<String, MutableMap<String, Int>> {
val edges = mutableMapOf<String, MutableMap<String, Int>>()
input.forEach { str ->
val (a, _, b, _, d) = str.split(' ')
val distance = d... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 2,816 | advent-of-code | Apache License 2.0 |
src/Day13.kt | ka1eka | 574,248,838 | false | {"Kotlin": 36739} | data class ListOrInt(val list: List<ListOrInt>? = null, val int: Int? = null) {
fun wrap(): ListOrInt = when (int) {
null -> this
else -> ListOrInt(listOf(this))
}
}
fun main() {
fun isCorrectOrder(left: ListOrInt, right: ListOrInt?): Boolean? {
when {
right == null -> r... | 0 | Kotlin | 0 | 0 | 4f7893448db92a313c48693b64b3b2998c744f3b | 3,526 | advent-of-code-2022 | Apache License 2.0 |
y2018/src/main/kotlin/adventofcode/y2018/Day23.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2018
import adventofcode.io.AdventSolution
import kotlin.math.abs
object Day23 : AdventSolution(2018, 23, "Experimental Emergency Teleportation") {
override fun solvePartOne(input: String): Int {
val bots = parse(input)
val best = bots.maxByOrNull(NanoBot::r)!!
ret... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 3,480 | advent-of-code | MIT License |
src/main/kotlin/aoc2020/ex16.kt | noamfree | 433,962,392 | false | {"Kotlin": 93533} | fun main() {
val input = readInputFile("aoc2020/input16")
// val input = """
// class: 1-3 or 5-7
// row: 6-11 or 33-44
// seat: 13-40 or 45-50
//
// your ticket:
// 7,1,14
//
// nearby tickets:
// 7,3,47
// 40,4,50
// 55,2,20
// 38,6,12
// ... | 0 | Kotlin | 0 | 0 | 566cbb2ef2caaf77c349822f42153badc36565b7 | 4,524 | AOC-2021 | MIT License |
src/year2021/day3/Day03.kt | tiagoabrito | 573,609,974 | false | {"Kotlin": 73752} | package year2021.day3
import readInput
fun main() {
fun maxFrequency(eachCount: Map<Char, Int>): Char {
return eachCount.entries.maxByOrNull { it.value }!!.key
}
fun minFrequency(eachCount: Map<Char, Int>): Char {
return eachCount.entries.minByOrNull { it.value }!!.key
}
fun pa... | 0 | Kotlin | 0 | 0 | 1f9becde3cbf5dcb345659a23cf9ff52718bbaf9 | 1,937 | adventOfCode | Apache License 2.0 |
src/Day15.kt | i-tatsenko | 575,595,840 | false | {"Kotlin": 90644} | import java.lang.IllegalArgumentException
import java.util.LinkedList
import java.util.regex.Pattern
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
class IntervalComparator : Comparator<Interval> {
override fun compare(t: Interval, other: Interval): Int {
val startDiff = t.from - othe... | 0 | Kotlin | 0 | 0 | 0a9b360a5fb8052565728e03a665656d1e68c687 | 3,452 | advent-of-code-2022 | Apache License 2.0 |
src/Day16.kt | mikrise2 | 573,939,318 | false | {"Kotlin": 62406} | import com.github.shiguruikai.combinatoricskt.combinations
import java.lang.Integer.min
data class Valve(
val name: String,
val rate: Int,
val ways: List<String>,
var isOpened: Boolean = false,
var waysDistances: MutableMap<String, Int> = mutableMapOf()
)
fun wayDistances(start: String, current: S... | 0 | Kotlin | 0 | 0 | d5d180eaf367a93bc038abbc4dc3920c8cbbd3b8 | 3,942 | Advent-of-code | Apache License 2.0 |
src/Day02.kt | leeturner | 572,659,397 | false | {"Kotlin": 13839} | import DesiredResult.*
import GameChoice.*
typealias Game = Pair<GameChoice, GameChoice>
typealias FixedGame = Pair<GameChoice, DesiredResult>
enum class GameChoice(val score: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3)
}
enum class DesiredResult {
WIN,
DRAW,
LOSE
}
fun String.toGameChoice() =
when (this... | 0 | Kotlin | 0 | 0 | 8da94b6a0de98c984b2302b2565e696257fbb464 | 2,649 | advent-of-code-2022 | Apache License 2.0 |
src/year2023/day02/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2023.day02
import arrow.core.nonEmptyListOf
import kotlin.math.max
import utils.ProblemPart
import utils.readInputs
import utils.runAlgorithm
fun main() {
val (realInput, testInputs) = readInputs(2023, 2, transform = ::parseInput)
runAlgorithm(
realInput = realInput,
testInputs = ... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 2,157 | Advent-of-Code | Apache License 2.0 |
src/Day04.kt | graesj | 572,651,121 | false | {"Kotlin": 10264} | fun IntRange.size(): Int = this.last - this.first
fun stringToSections(it: String): Pair<IntRange, IntRange> {
val split = it.split("-")
return split.first().toInt()..split[1].substringBefore(",").toInt() to
split[1].substringAfter(",").toInt()..split.last().toInt()
}
fun partitionBySize(rangePair... | 0 | Kotlin | 0 | 0 | df7f855a14c532f3af7a8dc86bd159e349cf59a6 | 1,471 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | esp-er | 573,196,902 | false | {"Kotlin": 29675} | package patriker.day02
import patriker.utils.*
operator fun String.component1(): Char { return this[0] }
operator fun String.component2(): Char { return this[1] }
operator fun String.component3(): Char { return this[2] }
enum class GameResult(val score: Int){
LOSS(0), DRAW(3), WIN(6)
}
enum class Hand{
ROCK, P... | 0 | Kotlin | 0 | 0 | f46d09934c33d6e5bbbe27faaf2cdf14c2ba0362 | 2,798 | aoc2022 | Apache License 2.0 |
src/Day07a.kt | palex65 | 572,937,600 | false | {"Kotlin": 68582} | private typealias Device = Map<String,Int>
private fun part1(dev: Device): Int =
dev.values.sumOf { if (it<=100000) it else 0 }
private fun part2(dev: Device): Int {
val toFree = 30000000 - (70000000 - (dev[""]?:0))
return dev.values.filter { it>=toFree }.min()
}
private fun Device(lines: List<String>): ... | 0 | Kotlin | 0 | 2 | 35771fa36a8be9862f050496dba9ae89bea427c5 | 1,567 | aoc2022 | Apache License 2.0 |
2021/src/main/kotlin/day20_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.IntGrid
import utils.Parser
import utils.Solution
fun main() {
Day20Func.run()
}
object Day20Func : Solution<Pair<IntGrid, List<Int>>>() {
override val name = "day20"
override val parser = Parser { input ->
val (lookupString, imageString) = input.split("\n\n", limit = 2)
val lookup = looku... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,914 | aoc_kotlin | MIT License |
src/Day15.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | import kotlin.math.abs
import kotlin.math.absoluteValue
// Lots of inspiration for both parts taken from here: https://nickymeuleman.netlify.app/garden/aoc2022-day15
fun main() {
data class Position(val x: Long, val y: Long) {
fun manhattanDistance(to: Position): Long {
return abs(x - to.x) + a... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 3,045 | aoc-2022 | Apache License 2.0 |
src/Day14meilisearch1.kt | max-zhilin | 573,066,300 | false | {"Kotlin": 114003} | class PathNode(val parent: PathNode?) {
var left: PathNode? = null
var right: PathNode? = null
var name: String? = null
fun path(): String {
return (parent?.path() ?: "") +
when (this) {
parent?.left -> "L"
parent?.right -> "R"
... | 0 | Kotlin | 0 | 0 | d9dd7a33b404dc0d43576dfddbc9d066036f7326 | 2,713 | AoC-2022 | Apache License 2.0 |
2023/src/main/kotlin/net/daams/solutions/7b.kt | Michiel-Daams | 573,040,288 | false | {"Kotlin": 39925, "Nim": 34690} | package net.daams.solutions
import net.daams.Solution
class `7b`(input: String): Solution(input) {
override fun run() {
val hands = mutableListOf<Pair<Hand, Int>>()
input.split("\n").forEach {
val hand = it.split(" ")
hands.add(Pair(Hand(hand[0]), hand[1].toInt()))
... | 0 | Kotlin | 0 | 0 | f7b2e020f23ec0e5ecaeb97885f6521f7a903238 | 3,097 | advent-of-code | MIT License |
src/Day11.kt | joy32812 | 573,132,774 | false | {"Kotlin": 62766} | import java.util.LinkedList
fun main() {
class Monkey(
val items: LinkedList<Long> = LinkedList(),
val ops: Array<String> = Array(3) { "" },
val tests: Array<Int> = Array(3) { 0 },
)
fun List<String>.toMonkeys(): List<Monkey> {
return chunked(7).map { ms ->
val... | 0 | Kotlin | 0 | 0 | 5e87958ebb415083801b4d03ceb6465f7ae56002 | 2,422 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/aoc2015/KnightsOfTheDinnerTable.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2015
import komu.adventofcode.utils.nonEmptyLines
import komu.adventofcode.utils.permutations
private val dinnerTablePattern = Regex("""(.+) would (lose|gain) (\d+) happiness units by sitting next to (.+).""")
private fun dinnerTableScore(permutation: List<String>, rulesByPerson: Map<Str... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 1,945 | advent-of-code | MIT License |
src/main/kotlin/biz/koziolek/adventofcode/year2023/day03/day3.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2023.day03
import biz.koziolek.adventofcode.*
import kotlin.math.log10
fun main() {
val inputFile = findInput(object {})
val engineSchematic = parseEngineSchematic(inputFile.bufferedReader().readLines())
println("Sum of numbers adjacent to a symbol: ${engineSchematic.... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 3,088 | advent-of-code | MIT License |
src/day2/Day02.kt | omarshaarawi | 573,867,009 | false | {"Kotlin": 9725} | package day2
import day2.Move.Companion.relationships
import day2.Move.X
import day2.Move.Y
import day2.Move.Z
import day2.Result.DRAW
import day2.Result.LOSE
import day2.Result.WIN
import readInput
enum class Move(val point: Int, val move: String) {
A(1, "rock"), B(2, "paper"), C(3, "scissors"),
X(1, "rock")... | 0 | Kotlin | 0 | 0 | 4347548045f12793a8693c4d31fe3d3dade5100a | 2,574 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day18/Main.kt | nikwotton | 572,814,041 | false | {"Kotlin": 77320} | package day18
import java.io.File
import kotlin.math.abs
const val workingDir = "src/day18"
data class Position(val x: Int, val y: Int, val z: Int) {
val immediatelyNextTo: List<Position> by lazy { listOf(
Position(x-1, y, z),
Position(x+1, y, z),
Position(x, y-1, z),
Position(x, ... | 0 | Kotlin | 0 | 0 | dee6a1c34bfe3530ae6a8417db85ac590af16909 | 2,810 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc2023/Day24.kt | j4velin | 572,870,735 | false | {"Kotlin": 285016, "Python": 1446} | package aoc2023
import PointL
import readInput
import withEachOf
import java.lang.IllegalArgumentException
import kotlin.math.abs
object Day24 {
private data class Hailstone(val position: PointL, val velocity: PointL) {
companion object {
// 19, 13, 30 @ -2, 1, -2
private val reg... | 0 | Kotlin | 0 | 0 | f67b4d11ef6a02cba5b206aba340df1e9631b42b | 3,229 | adventOfCode | Apache License 2.0 |
src/Day02.kt | Miguel1235 | 726,260,839 | false | {"Kotlin": 21105} | data class Game(val id: Int, val cubes: List<Cubes>) {
fun isGamePossible(): Boolean {
for (cube in cubes) {
val (blue, red, green) = cube
if (red > 12 || green > 13 || blue > 14) return false
}
return true
}
fun maxColor(color: String): Int {
var max... | 0 | Kotlin | 0 | 0 | 69a80acdc8d7ba072e4789044ec2d84f84500e00 | 2,100 | advent-of-code-2023 | MIT License |
src/main/kotlin/Day14.kt | Vampire | 572,990,104 | false | {"Kotlin": 57326} | import kotlin.math.max
typealias Node = Pair<Int, Int>
fun main() {
fun part1(input: List<String>, withFloor: Boolean = false): Int {
val structures = input
.map { structure ->
structure
.split(" -> ")
.map { node ->
... | 0 | Kotlin | 0 | 0 | 16a31a0b353f4b1ce3c6e9cdccbf8f0cadde1f1f | 3,694 | aoc-2022 | Apache License 2.0 |
src/main/day15/day15.kt | rolf-rosenbaum | 572,864,107 | false | {"Kotlin": 80772} | package day15
import Point
import day15.CavePoint.Sensor
import kotlin.math.abs
import readInput
import union
val regex = """.+x=(-?\d+).*y=(-?\d+):.*x=(-?\d+).*y=(-?\d+)""".toRegex()
const val prd_row = 2_000_000
const val test_row = 10
val prd_range = 0..4000000
val test_range = 0..20
typealias Cave = MutableSet... | 0 | Kotlin | 0 | 2 | 59cd4265646e1a011d2a1b744c7b8b2afe482265 | 2,546 | aoc-2022 | Apache License 2.0 |
src/Day08.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | fun main() {
fun part1(input: List<String>): Int {
val grid = input.map { it.toList() }
val size = grid.size
var visibleTrees = (size * 4) - 4
for (x in 1 until size - 1) {
for (y in 1 until size - 1) {
val tree = grid[y][x]
val north = ... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 2,346 | aoc-2022 | Apache License 2.0 |
src/Day12.kt | mihansweatpants | 573,733,975 | false | {"Kotlin": 31704} | import java.lang.RuntimeException
fun main() {
val input = readInput("Day12").lines()
fun part1(input: List<String>): Int {
return shortestPathLength(input, getPoint(input, 'S'), getPoint(input, 'E'))
?: throw RuntimeException("Path not found")
}
fun part2(input: List<String>): In... | 0 | Kotlin | 0 | 0 | 0de332053f6c8f44e94f857ba7fe2d7c5d0aae91 | 2,518 | aoc-2022 | Apache License 2.0 |
src/Day15.kt | Flame239 | 570,094,570 | false | {"Kotlin": 60685} | import kotlin.math.abs
private fun pos(): List<Sensor> {
return readInput("Day15").map { it.split(": ") }.map {
val sensor = parseC(it[0].substring("Sensor at ".length))
val beacon = parseC(it[1].substring("closest beacon is at ".length))
Sensor(sensor, beacon, sensor.manhattan(beacon))
... | 0 | Kotlin | 0 | 0 | 27f3133e4cd24b33767e18777187f09e1ed3c214 | 3,577 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch8/Problem88.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch8
import kotlin.math.sqrt
/**
* Problem 88: Product-Sum Numbers
*
* https://projecteuler.net/problem=88
*
* Goal: Find the sum of all unique product-sum numbers for 2 <= k <= N.
*
* Constraints: 10 <= N <= 2e5
*
* Product-Sum Number: A natural number that can be written as both the s... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,815 | project-euler-kotlin | MIT License |
src/Day11.kt | psy667 | 571,468,780 | false | {"Kotlin": 23245} | fun plus(a: Long, b: String): Long {
return if (b == "old") {
a + a
} else {
a + b.toLong()
}
}
fun prod(a: Long, b: String): Long {
return if (b == "old") {
a * a
} else {
a * b.toLong()
}
}
data class Monkey(val id: Long, var items: MutableList<Long>, val op: ... | 0 | Kotlin | 0 | 0 | 73a795ed5e25bf99593c577cb77f3fcc31883d71 | 3,244 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day7.kt | gautemo | 725,273,259 | false | {"Kotlin": 79259} | import shared.*
fun main() {
val input = Input.day(7)
println(day7A(input))
println(day7B(input))
}
fun day7A(input: Input): Int {
val hands = input.lines.map { Hand(it) }
return totalWinnings(hands)
}
fun day7B(input: Input): Int {
val hands = input.lines.map { Hand(it, true) }
return to... | 0 | Kotlin | 0 | 0 | 6862b6d7429b09f2a1d29aaf3c0cd544b779ed25 | 2,500 | AdventOfCode2023 | MIT License |
src/Day02.kt | Xacalet | 576,909,107 | false | {"Kotlin": 18486} | /**
* ADVENT OF CODE 2022 (https://adventofcode.com/2022/)
*
* Solution to day 2 (https://adventofcode.com/2022/day/2)
*
*/
private enum class Hand(val points: Int) {
ROCK(1), PAPER(2), SCISSORS(3)
}
fun main() {
fun resolveRound(myHand: Hand, opponentsHand: Hand): Int {
val pointsFromChosenHan... | 0 | Kotlin | 0 | 0 | 5c9cb4650335e1852402c9cd1bf6f2ba96e197b2 | 2,727 | advent-of-code-2022 | Apache License 2.0 |
src/day_2/kotlin/Day2.kt | Nxllpointer | 573,051,992 | false | {"Kotlin": 41751} | // AOC Day 2
enum class Move(val score: Int, defeats: () -> Move) {
ROCK(1, { SCISSORS }),
PAPER(2, { ROCK }),
SCISSORS(3, { PAPER });
val defeats by lazy { defeats() }
}
data class Round(val opponentMove: Move, val myMove: Move) {
enum class Result(val score: Int) {
LOOSE(0),
WIN... | 0 | Kotlin | 0 | 0 | b6d7ef06de41ad01a8d64ef19ca7ca2610754151 | 2,183 | AdventOfCode2022 | MIT License |
src/Day08.kt | StephenVinouze | 572,377,941 | false | {"Kotlin": 55719} | data class OuterTrees(
val topTrees: List<Int>,
val leftTrees: List<Int>,
val rightTrees: List<Int>,
val bottomTrees: List<Int>,
)
fun main() {
fun List<String>.toTrees(): List<List<Int>> =
map {
it.toCharArray().toList().map { treeChar ->
treeChar.digitToInt()
... | 0 | Kotlin | 0 | 0 | 11b9c8816ded366aed1a5282a0eb30af20fff0c5 | 3,252 | AdventOfCode2022 | Apache License 2.0 |
src/Day17.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | import java.util.PriorityQueue
import kotlin.math.min
private const val EXPECTED_1 = 102
private const val EXPECTED_2 = 94
private class Day17(isTest: Boolean) : Solver(isTest) {
val field = readAsLines().map { it.toCharArray() }
val Y = field.size
val X = field[0].size
data class Point(val y: Int, v... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 2,589 | advent-of-code-2022 | Apache License 2.0 |
src/Day18.kt | maewCP | 579,203,172 | false | {"Kotlin": 59412} | fun main() {
fun adjacent(coordinate: Triple<Int, Int, Int>): List<Triple<Int, Int, Int>> {
val (x, y, z) = coordinate.toList()
return listOf(
Triple(x - 1, y, z),
Triple(x + 1, y, z),
Triple(x, y - 1, z),
Triple(x, y + 1, z),
Triple(x, y,... | 0 | Kotlin | 0 | 0 | 8924a6d913e2c15876c52acd2e1dc986cd162693 | 2,488 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day12.kt | frungl | 573,598,286 | false | {"Kotlin": 86423} | import java.util.*
fun main() {
fun bfs(graph: List<String>, sX: Int, sY: Int, eX: Int, eY: Int): Int {
val n = graph.size
val m = graph[0].length
val dist = mutableMapOf<Pair<Int, Int>, Int>()
val q = LinkedList<Pair<Int, Int>>()
dist[sX to sY] = 0
q.addFirst(sX to ... | 0 | Kotlin | 0 | 0 | d4cecfd5ee13de95f143407735e00c02baac7d5c | 2,122 | aoc2022 | Apache License 2.0 |
src/Day07.kt | freszu | 573,122,040 | false | {"Kotlin": 32507} | private sealed interface FileSystem {
data class File(val name: String, val size: Int) : FileSystem
data class Dir(val parent: Dir?, val name: String, val content: MutableList<FileSystem>) : FileSystem {
fun contentFromLsOutput(line: List<String>) = line.map { fromLsOutputLine(it) }
private f... | 0 | Kotlin | 0 | 0 | 2f50262ce2dc5024c6da5e470c0214c584992ddb | 3,447 | aoc2022 | Apache License 2.0 |
2k23/aoc2k23/src/main/kotlin/13.kt | papey | 225,420,936 | false | {"Rust": 88237, "Kotlin": 63321, "Elixir": 54197, "Crystal": 47654, "Go": 44755, "Ruby": 24620, "Python": 23868, "TypeScript": 5612, "Scheme": 117} | package d13
import input.raw
import kotlin.math.min
fun main() {
val input = parseInput(raw("13.txt"))
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
fun part1(notes: List<Note>): Int =
notes.sumOf { it.findRowReflection(0) * 100 + it.findColumnReflection(0) }
fun part2(not... | 0 | Rust | 0 | 3 | cb0ea2fc043ebef75aff6795bf6ce8a350a21aa5 | 1,782 | aoc | The Unlicense |
src/Day02.kt | simonitor | 572,972,937 | false | {"Kotlin": 8461} | import GameResult.*
fun main() {
// first
val games = readInput("inputDay2").map { it.split(" ") }.map {
Pair(Move.translateMove(it[1]), Move.translateMove(it[0]))
}
println(calculatePoints(games))
// second
val games2 = readInput("inputDay2").map { it.split(" ") }.map {
val en... | 0 | Kotlin | 0 | 0 | 11d567712dd3aaf3c7dee424a3442d0d0344e1fa | 2,042 | AOC2022 | Apache License 2.0 |
leetcode2/src/leetcode/kth-smallest-element-in-a-sorted-matrix.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* 378. 有序矩阵中第K小的元素
* https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/
* Created by test
* Date 2020/2/2 18:24
* Description
* 给定一个 n x n 矩阵,其中每行和每列元素均按升序排序,找到矩阵中第k小的元素。
请注意,它是排序后的第k小元素,而不是第k个元素。
示例:
matrix = [
[ 1, 5, 9],
[10, 11, 13],
[12, 13, 15]
],
k = 8,
返回 ... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,497 | leetcode | MIT License |
src/Day07.kt | hufman | 573,586,479 | false | {"Kotlin": 29792} | data class Dir(val subdirs: MutableMap<String, Dir>, val filesizes: MutableMap<String, Long>, var size: Long = 0) {
companion object {
fun empty(): Dir = Dir(mutableMapOf(), mutableMapOf()
)
}
fun updateSize() {
size = subdirs.values.fold(0L) {total, dir ->
dir.updateSize()
total + dir.size
} + filesi... | 0 | Kotlin | 0 | 0 | 1bc08085295bdc410a4a1611ff486773fda7fcce | 1,898 | aoc2022-kt | Apache License 2.0 |
src/day12/Day12.kt | xxfast | 572,724,963 | false | {"Kotlin": 32696} | package day12
import readLines
import kotlin.collections.ArrayDeque
typealias Grid<T> = List<List<T>>
operator fun <T> Grid<T>.get(x: Int, y: Int): T? = getOrNull(y)?.getOrNull(x)
fun <T> Grid<T>.firstByDepth(
from: T,
next: Grid<T>.(current: T) -> List<T>,
evaluate: Grid<T>.(current: T, next: T) -> Boolean,
... | 0 | Kotlin | 0 | 1 | a8c40224ec25b7f3739da144cbbb25c505eab2e4 | 2,696 | advent-of-code-22 | Apache License 2.0 |
src/year2023/Day15.kt | drademacher | 725,945,859 | false | {"Kotlin": 76037} | package year2023
import readLines
fun main() {
check(hash("H") == 200)
check(hash("HA") == 153)
check(hash("HAS") == 172)
check(hash("HASH") == 52)
val input = parseInput(readLines("2023", "day15"))
val testInput = parseInput(readLines("2023", "day15_test"))
check(part1(testInput) == 132... | 0 | Kotlin | 0 | 0 | 4c4cbf677d97cfe96264b922af6ae332b9044ba8 | 2,639 | advent_of_code | MIT License |
src/Day11.kt | hijst | 572,885,261 | false | {"Kotlin": 26466} | fun main() {
class Monkey(startingItems: List<Long>, val rule: (Long) -> Long, val targets: Pair<Int, Int>, val modulus: Long ){
val items = startingItems.toMutableList()
var inspectCount = 0L
fun playTurn(monkeys: List<Monkey>) {
items.forEach { item ->
inspectC... | 0 | Kotlin | 0 | 0 | 2258fd315b8933642964c3ca4848c0658174a0a5 | 2,873 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2018/Day6.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2018
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
object Day6 {
data class Point(val x: Int, val y: Int) {
fun dist(other: Point) = abs(x - other.x) + abs(y - other.y)
fun onEdge(topLeft: Point, bottomRight: Point): Boolean {
return... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,614 | adventofcode | MIT License |
kotlin/src/main/kotlin/year2023/Day22.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2023
fun main() {
val input = readInput("Day22")
Day22.part1(input).println()
Day22.part2(input).println()
}
object Day22 {
fun part1(input: List<String>): Int {
val bricks = getBricks(input)
val brickSupportedBy = getSupportedBy(bricks)
return bricks.size - brick... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 3,463 | advent-of-code | MIT License |
src/Day03.kt | BenHopeITC | 573,352,155 | false | null | inline infix fun String.intersect(other: String) = toSet() intersect other.toSet()
inline infix fun Set<Char>.intersect(other: String) = toSet() intersect other.toSet()
fun main() {
fun valueOfItem(item: Char): Int = if (item.isLowerCase()) item - 'a' + 1 else item - 'A' + 27
fun part1(input: List<String>): ... | 0 | Kotlin | 0 | 0 | 851b9522d3a64840494b21ff31d83bf8470c9a03 | 3,198 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day12.kt | dcbertelsen | 573,210,061 | false | {"Kotlin": 29052} | import java.io.File
import kotlin.math.min
fun main() {
val c0 = '`'
fun getNodes(input: List<String>): List<List<Node>> =
input.map { row ->
row.map { c ->
val height = when (c) { 'S' -> 0; 'E' -> 'z' - c0; else -> c - c0 }
Node(height, isStart = c == 'S', i... | 0 | Kotlin | 0 | 0 | 9d22341bd031ffbfb82e7349c5684bc461b3c5f7 | 3,189 | advent-of-code-2022-kotlin | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.