path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/main/kotlin/se/saidaspen/aoc/aoc2018/Day06.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2018
import se.saidaspen.aoc.util.*
import kotlin.math.abs
fun main() {
Day06.run()
}
object Day06 : Day(2018, 6) {
override fun part1(): Any {
val grid = Grid(".")
val coords = input.lines().map { ints(it) }.map { P(it[0], it[1]) }.toList()
for ((i, p) in... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 2,036 | adventofkotlin | MIT License |
src/main/kotlin/days/y2023/day05/Day05.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2023.day05
import util.InputReader
typealias Seed = Long
typealias PuzzleInput = String
class Day05(val input: PuzzleInput) {
val seeds = parseSeeds(input)
val seedRanges = parseSeedRanges(input)
val remappers = parseRemappers(input)
fun partOne() = seeds.minOf { mapSeed(it) }
fun... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 4,154 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/design/SearchAutocompleteSystem.kt | e-freiman | 471,473,372 | false | {"Kotlin": 78010} | package design
class AutocompleteSystem(sentences: Array<String>, times: IntArray) {
private class TrieNode {
var leafTimes = 0
val children = mutableMapOf<Char, TrieNode>()
}
private val trieRoot = TrieNode()
private var currentNode: TrieNode
private val prefix = StringBuilder()
... | 0 | Kotlin | 0 | 0 | fab7f275fbbafeeb79c520622995216f6c7d8642 | 3,094 | LeetcodeGoogleInterview | Apache License 2.0 |
src/Day04.kt | davidkna | 572,439,882 | false | {"Kotlin": 79526} | fun main() {
fun Boolean.toInt() = if (this) 1 else 0
fun part1(input: List<String>): Int {
return input.filter { return@filter it.isNotEmpty() }.sumOf {
val (first, second) = it.split(",")
val (x0, y0) = first.split("-").map { n -> n.toInt() }
val (x1, y1) = second.... | 0 | Kotlin | 0 | 0 | ccd666cc12312537fec6e0c7ca904f5d9ebf75a3 | 1,419 | aoc-2022 | Apache License 2.0 |
2022/src/main/kotlin/Day08.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | object Day08 {
fun part1(input: String): Int {
val trees = input.splitNewlines().map { it.toIntList() }
val size = trees.size // Assume square input
return trees.indices.sumOf { y ->
trees[y].indices.count { x ->
val tree = trees[y][x]
return@count (0 until x).all { tree > trees[y]... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 1,370 | advent-of-code | MIT License |
y2020/src/main/kotlin/adventofcode/y2020/Day21.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2020
import adventofcode.io.AdventSolution
fun main() = Day21.solve()
object Day21 : AdventSolution(2020, 21, "Allergen Assessment")
{
override fun solvePartOne(input: String): Int
{
val entries = input.lines().map(::parseEntry)
val allergens = findAllergens(entries).val... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,678 | advent-of-code | MIT License |
src/Day17.kt | schoi80 | 726,076,340 | false | {"Kotlin": 83778} | import java.util.PriorityQueue
fun Direction.isOpposite(d: Direction) = when (this) {
Direction.UP -> d == Direction.DOWN
Direction.DOWN -> d == Direction.UP
Direction.LEFT -> d == Direction.RIGHT
Direction.RIGHT -> d == Direction.LEFT
}
fun getDirection(rc1: RowCol, rc2: RowCol): Direction {
val ... | 0 | Kotlin | 0 | 0 | ee9fb20d0ed2471496185b6f5f2ee665803b7393 | 3,293 | aoc-2023 | Apache License 2.0 |
src/Day08.kt | michaelYuenAE | 573,094,416 | false | {"Kotlin": 74685} | class Day08(private val lines: List<String>) {
val column = lines.first().length - 1
val row = lines.size - 1
val treeSet = mutableSetOf<Tree>()
fun part1(): Int {
println("column $column")
println("row $row")
lookFromWest(lines)
lookFromEast(lines)
lookFromNort... | 0 | Kotlin | 0 | 0 | ee521263dee60dd3462bea9302476c456bfebdf8 | 3,814 | advent22 | Apache License 2.0 |
src/Day02.kt | JohannesPtaszyk | 573,129,811 | false | {"Kotlin": 20483} | enum class Result(val id: String, val score: Int) {
LOOSE(id = "X", score = 0),
DRAW(id = "Y", score = 3),
WIN(id = "Z", score = 6);
companion object {
fun forId(id: String): Result = values().first {it.id == id }
}
}
enum class Shape(val score: Int, val encryptedValues: List<String>) {
... | 0 | Kotlin | 0 | 1 | 6f6209cacaf93230bfb55df5d91cf92305e8cd26 | 2,077 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day16/day16.kt | corneil | 572,437,852 | false | {"Kotlin": 93311, "Shell": 595} | package day16
import main.utils.Edge
import main.utils.Graph
import main.utils.scanInt
import utils.readFile
import utils.readLines
import kotlin.math.max
fun main() {
val test = readLines(
"""Valve AA has flow rate=0; tunnels lead to valves DD, II, BB
Valve BB has flow rate=13; tunnels lead to valves CC, AA
V... | 0 | Kotlin | 0 | 0 | dd79aed1ecc65654cdaa9bc419d44043aee244b2 | 5,086 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day09.kt | skuhtic | 572,645,300 | false | {"Kotlin": 36109} | import kotlin.math.abs
import kotlin.math.max
fun main() {
day09.execute(onlyTests = false, forceBothParts = true)
}
val day09 = object : Day<Int>(9, 88, 36) {
override val testInput: InputData
get() = """
R 5
U 8
L 8
D 3
R 17
D 1... | 0 | Kotlin | 0 | 0 | 8de2933df90259cf53c9cb190624d1fb18566868 | 2,655 | aoc-2022 | Apache License 2.0 |
lib/src/main/kotlin/com/bloidonia/advent/day20/Day20.kt | timyates | 433,372,884 | false | {"Kotlin": 48604, "Groovy": 33934} | package com.bloidonia.advent.day20
import com.bloidonia.advent.readText
data class Position(val x: Int, val y: Int) {
operator fun plus(pos: Position) = Position(x + pos.x, y + pos.y)
}
class TrenchMap(val inverted: Boolean, val lookups: List<Int>, val settings: Set<Position>) {
fun xRange(): IntRange = (set... | 0 | Kotlin | 0 | 1 | 9714e5b2c6a57db1b06e5ee6526eb30d587b94b4 | 2,614 | advent-of-kotlin-2021 | MIT License |
src/Day08.kt | pimtegelaar | 572,939,409 | false | {"Kotlin": 24985} | import kotlin.math.max
fun main() {
data class Tree(
val size: Int,
var visible: Boolean = false,
var up: Int = 0,
var down: Int = 0,
var left: Int = 0,
var right: Int = 0,
) {
val scenicScore get() = up * down * left * right
}
fun part1(input: ... | 0 | Kotlin | 0 | 0 | 16ac3580cafa74140530667413900640b80dcf35 | 3,069 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/adventofcode/year2020/Day11SeatingSystem.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2020
import adventofcode.Puzzle
import adventofcode.PuzzleInput
// Eight directions going up, down, left, right, or diagonal
private val directions = (-1..1).flatMap { dx -> (-1..1).map { dy -> Pair(dx, dy) } }.filter { it != Pair(0, 0) }
class Day11SeatingSystem(customInput: PuzzleInput? = ... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 2,239 | AdventOfCode | MIT License |
src/Day13.kt | tigerxy | 575,114,927 | false | {"Kotlin": 21255} | import TreeNode.ListNode
fun main() {
fun part1(input: List<String>): Int =
input
.parseFile()
.map { Pair(it[0], it[1]) }
.map { it.first < it.second }
.mapIndexed { index, b ->
b.toInt() * (index + 1)
}
.sum()
fu... | 0 | Kotlin | 0 | 1 | d516a3b8516a37fbb261a551cffe44b939f81146 | 3,852 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/day4/Day4.kt | cyril265 | 433,772,262 | false | {"Kotlin": 39445, "Java": 4273} | package day4
import read
import readToList
val input = readToList("day4_input.txt").first().split(',')
val boardLines = read("day4_board.txt").split("\r\n\r\n")
fun main() {
println(play(input, true))
println(play(input, false))
}
private fun play(input: List<String>, matchFirst: Boolean): Int {
val b... | 0 | Kotlin | 0 | 0 | 1ceda91b8ef57b45ce4ac61541f7bc9d2eb17f7b | 1,691 | aoc2021 | Apache License 2.0 |
src/main/day12/day12.kt | rolf-rosenbaum | 572,864,107 | false | {"Kotlin": 80772} | package day12
import Point
import readInput
typealias Grid = MutableMap<Point, Char>
fun main() {
val input = readInput("main/day12/Day12")
println(part1(input))
println(part2(input))
}
fun part1(input: List<String>): Int = input.solveFor('S')
fun part2(input: List<String>): Int = input.solveFor('a')
... | 0 | Kotlin | 0 | 2 | 59cd4265646e1a011d2a1b744c7b8b2afe482265 | 1,953 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | iownthegame | 573,926,504 | false | {"Kotlin": 68002} | class Rucksack(private val input: String) {
private val itemsInFirstCompartment: CharArray
private val itemsInSecondCompartment: CharArray
private val sharedItems: Set<Char>
init {
val halfInputLength = input.length / 2
itemsInFirstCompartment = input.substring(0, halfInputLength).toCha... | 0 | Kotlin | 0 | 0 | 4e3d0d698669b598c639ca504d43cf8a62e30b5c | 2,832 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/advent/week1/ShortestPath.kt | reitzig | 159,310,794 | false | null | package advent.week1
/**
* Reads in a maze/labyrinth/map from stdin, and
* prints it with the shortest path from S to X to stdout.
*/
fun main() {
val maze = readMaze(generateSequence { readLine() })
val path = Dijkstra.shortestPath(maze, maze.start, maze.end)
println(maze + path)
}
interface Shortes... | 0 | Kotlin | 0 | 0 | 38911626f62bce3c59abe893afa8f15dc29dcbda | 1,738 | advent-of-kotlin-2018 | MIT License |
src/aoc2017/kot/Day21.kt | Tandrial | 47,354,790 | false | null | package aoc2017.kot
import java.io.File
object Day21 {
fun solve(start: String, input: List<String>, iter: Int): Int {
val lookUp = parsePatterns(input)
var current = start.split("/").map { it.toCharArray() }.toTypedArray()
repeat(iter) {
val chunkSize = if (current.size % 2 == 0) 2 else 3
v... | 0 | Kotlin | 1 | 1 | 9294b2cbbb13944d586449f6a20d49f03391991e | 3,082 | Advent_of_Code | MIT License |
src/year2023/day03/Day03.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2023.day03
import check
import readInput
fun main() {
val testInput = readInput("2023", "Day03_test")
check(part1(testInput), 4361)
check(part2(testInput), 467835)
val input = readInput("2023", "Day03")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<S... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 2,709 | AdventOfCode | Apache License 2.0 |
src/Day14.kt | cypressious | 572,916,585 | false | {"Kotlin": 40281} | fun main() {
fun parseInsertions(input: List<String>) = input
.drop(2)
.associate { it.split(" -> ").let { (from, to) -> from to to[0] } }
fun part1(input: List<String>): Int {
var template = input.first().toList()
val insertions = parseInsertions(input)
repeat(10) {
... | 0 | Kotlin | 0 | 0 | 169fb9307a34b56c39578e3ee2cca038802bc046 | 2,073 | AdventOfCode2021 | Apache License 2.0 |
src/Day05.kt | hoppjan | 433,705,171 | false | {"Kotlin": 29015, "Shell": 338} | fun main() {
fun part1(input: List<Line>): Int {
var diagram = diagram(input.neededDiagramSize())
input.forEach {
diagram = it.drawHorizontalOrVerticalLine(diagram)
}
return diagram.countDangerousAreas()
}
fun part2(input: List<Line>): Int {
var diagram... | 0 | Kotlin | 0 | 0 | 04f10e8add373884083af2a6de91e9776f9f17b8 | 2,973 | advent-of-code-2021 | Apache License 2.0 |
src/Day04.kt | treegem | 572,875,670 | false | {"Kotlin": 38876} | import common.readInput
fun main() {
val day = "04"
fun part1(input: List<String>) =
input
.map { it.toSectionAssignmentPair() }
.map { it.isOneFullyContainedByOther() }
.count { it }
fun part2(input: List<String>) =
input
.map { it.toSectio... | 0 | Kotlin | 0 | 0 | 97f5b63f7e01a64a3b14f27a9071b8237ed0a4e8 | 1,820 | advent_of_code_2022 | Apache License 2.0 |
src/Day02.kt | eo | 574,058,285 | false | {"Kotlin": 45178} | // https://adventofcode.com/2022/day/2
fun main() {
fun opponentHandShape(symbol: String) = when (symbol) {
"A" -> HandShape.ROCK
"B" -> HandShape.PAPER
"C" -> HandShape.SCISSORS
else -> error("$symbol is invalid!")
}
fun part1(input: List<String>): Int {
fun myHandS... | 0 | Kotlin | 0 | 0 | 8661e4c380b45c19e6ecd590d657c9c396f72a05 | 2,729 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day08.kt | pmellaaho | 573,136,030 | false | {"Kotlin": 22024} | fun Char.height(): Int = toString().toInt()
fun String.tallestBefore(idx: Int): Int {
return substring(0, idx).maxOf { it.height() }
}
fun String.tallestAfter(idx: Int): Int {
return substring(idx + 1).maxOf { it.height() }
}
fun main() {
val treeColums: MutableMap<Int, String> = mutableMapOf()
fun... | 0 | Kotlin | 0 | 0 | cd13824d9bbae3b9debee1a59d05a3ab66565727 | 3,501 | AoC_22 | Apache License 2.0 |
src/Day12.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | fun main() {
fun parseHeight(char: Char): Int {
require(char in 'a'..'z')
return char - 'a'
}
data class Pos(val row: Int, val column: Int) {
fun moveLeft() = Pos(row, column - 1)
fun moveRight() = Pos(row, column + 1)
fun moveUp() = Pos(row + 1, column)
fun... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 3,457 | aoc2022 | Apache License 2.0 |
src/Day11.kt | iam-afk | 572,941,009 | false | {"Kotlin": 33272} | fun main() {
class Monkey(
val items: MutableList<Long>,
val operation: (Long) -> Long,
val divisor: Long,
val ifTrue: Int,
val ifFalse: Int
) {
var inspected: Long = 0
}
fun List<String>.parse() = this.chunked(7)
.map { chunk ->
val ... | 0 | Kotlin | 0 | 0 | b30c48f7941eedd4a820d8e1ee5f83598789667b | 2,606 | aockt | Apache License 2.0 |
kotlin/src/main/kotlin/year2023/Day04.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2023
import kotlin.math.pow
fun main() {
val input = readInput("Day04")
Day04.part1(input).println()
Day04.part2(input).println()
}
object Day04 {
fun part1(input: List<String>): Int {
return input.sumOf { line ->
val (_, numbers) = line.split(":")
val (win... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 2,056 | advent-of-code | MIT License |
src/Day12.kt | andrewgadion | 572,927,267 | false | {"Kotlin": 16973} | import java.util.PriorityQueue
data class MapPos(val point: Pair<Int, Int>, val distance: Int)
fun main() {
fun Char.isEnd(): Boolean = this == 'E'
fun Char.canStep(d: Char): Boolean {
if (this == 'S') return true
if (d.isEnd()) return this == 'z'
return d.code - this.code <= 1
}
... | 0 | Kotlin | 0 | 0 | 4d091e2da5d45a786aee4721624ddcae681664c9 | 1,881 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc2022/Day12.kt | davidsheldon | 565,946,579 | false | {"Kotlin": 161960} | package aoc2022
import utils.InputUtils
import utils.Coordinates
class Maze(val data: List<String>) {
val start = findCoordinate('S')
val end = findCoordinate('E')
private fun findCoordinate(c: Char): Coordinates =
findCoordinates(c).first()
fun findCoordinates(c: Char): Sequence<Coordinates... | 0 | Kotlin | 0 | 0 | 5abc9e479bed21ae58c093c8efbe4d343eee7714 | 2,866 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2023/day15/day15.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2023.day15
import biz.koziolek.adventofcode.findInput
fun main() {
val inputFile = findInput(object {})
val initSeq = parseInitializationSequence(inputFile.bufferedReader().readLines())
println("Hash of initialization sequence is: ${initSeq.sumOf { it.hash() }}")
... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 3,054 | advent-of-code | MIT License |
src/main/kotlin/dev/bogwalk/batch8/Problem86.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch8
import dev.bogwalk.util.maths.pythagoreanTriplet
/**
* Problem 86: Cuboid Route
*
* https://projecteuler.net/problem=86
*
* Goal: Find the number of distinct cuboids (ignoring rotations) that can be formed (with integer
* dimensions and shortest route with integer length) up to a maxi... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 5,963 | project-euler-kotlin | MIT License |
src/main/kotlin/com/ikueb/advent18/Day24.kt | h-j-k | 159,901,179 | false | null | package com.ikueb.advent18
import com.ikueb.advent18.model.*
object Day24 {
private const val DEFINITION =
"(\\d+) units each with (\\d+) hit points (\\(([^)]+)\\) )?with an attack that does (\\d+) ([^ ]+) damage at initiative (\\d+)"
fun getWinningUnits(input: List<String>) =
battle... | 0 | Kotlin | 0 | 0 | f1d5c58777968e37e81e61a8ed972dc24b30ac76 | 4,968 | advent18 | Apache License 2.0 |
src/Day02.kt | maciekbartczak | 573,160,363 | false | {"Kotlin": 41932} | fun main() {
fun part1(input: List<String>): Int {
return input
.map { getRoundInput(it) }
.sumOf { calculateScore(it.first, it.second) }
}
fun part2(input: List<String>): Int {
return input
.map { getRoundInput(it) }
.sumOf {
... | 0 | Kotlin | 0 | 0 | 53c83d9eb49d126e91f3768140476a52ba4cd4f8 | 1,543 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc23/Day05.kt | tahlers | 725,424,936 | false | {"Kotlin": 65626} | package aoc23
import kotlin.math.max
import kotlin.math.min
fun LongRange.overlap(range: LongRange): List<LongRange?> {
val before = if (range.first < first) {
range.first..(min(range.last, first - 1))
} else null
val after = if (range.last > last) {
max(range.first, last + 1)..range.last
... | 0 | Kotlin | 0 | 0 | 0cd9676a7d1fec01858ede1ab0adf254d17380b0 | 4,200 | advent-of-code-23 | Apache License 2.0 |
aoc-2021/src/commonMain/kotlin/fr/outadoc/aoc/twentytwentyone/Day08.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwentyone
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.permutations
import fr.outadoc.aoc.scaffold.readDayInput
class Day08 : Day<Int> {
private companion object {
const val a = 'a'
const val b = 'b'
const val c = 'c'
const val d ... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 3,487 | adventofcode | Apache License 2.0 |
src/main/kotlin/algorithm/other.kt | oQaris | 402,822,990 | false | {"Kotlin": 147623} | package algorithm
import com.github.shiguruikai.combinatoricskt.combinations
import graphs.Graph
fun redo(g: Graph, lambda: (u: Int, v: Int, w: Int) -> Int): Int {
var count = 0
g.getEdges().forEach { edge ->
g.setWeightEdg(
edge.copy(weight = lambda(edge.first, edge.second, edge.weight))
... | 1 | Kotlin | 0 | 2 | 2424cf11cf382c86e4fb40500dd5fded24f1858f | 1,684 | GraphProcessor | Apache License 2.0 |
src/Day12.kt | l8nite | 573,298,097 | false | {"Kotlin": 105683} | class Grid(val width: Int, val src: Int, val dst: Int, val nodes: List<Int>) {
fun neighbors(at: Int): List<Int> {
val list = mutableListOf<Int>()
if ((at % width) > 0) {
list.add(at - 1)
}
if ((at % width) < (width - 1)) {
list.add(at + 1)
}
... | 0 | Kotlin | 0 | 0 | f74331778fdd5a563ee43cf7fff042e69de72272 | 3,852 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/twentytwentytwo/Day15.kt | JanGroot | 317,476,637 | false | {"Kotlin": 80906} | package twentytwentytwo
import twentytwentytwo.Structures.Point2d
import java.math.BigInteger
fun main() {
val input = {}.javaClass.getResource("input-15.txt")!!.readText().linesFiltered { it.isNotEmpty() };
val testInput = {}.javaClass.getResource("input-15-1.txt")!!.readText().linesFiltered { it.isNotEmpty(... | 0 | Kotlin | 0 | 0 | 04a9531285e22cc81e6478dc89708bcf6407910b | 2,233 | aoc202xkotlin | The Unlicense |
src/main/kotlin/day11/Day11.kt | alxgarcia | 435,549,527 | false | {"Kotlin": 91398} | package day11
import java.io.File
import java.util.LinkedList
fun parseMap(rows: List<String>): Array<IntArray> =
rows.map { row -> row.trim().map { it - '0' }.toIntArray() }.toTypedArray()
private fun expandAdjacentWithDiagonals(row: Int, column: Int, map: Array<IntArray>): List<Pair<Int, Int>> =
(-1..1).flatMa... | 0 | Kotlin | 0 | 0 | d6b10093dc6f4a5fc21254f42146af04709f6e30 | 1,908 | advent-of-code-2021 | MIT License |
src/day13/Code.kt | ldickmanns | 572,675,185 | false | {"Kotlin": 48227} | package day13
import readInput
fun main() {
val input = readInput("day13/input")
// val input = readInput("day13/input_test")
println(part1(input))
println(part2(input))
}
fun part1(input: List<String>): Int {
var index = 0
return input.filter { it.isNotEmpty() }.chunked(2) {
val lef... | 0 | Kotlin | 0 | 0 | 2654ca36ee6e5442a4235868db8174a2b0ac2523 | 3,148 | aoc-kotlin-2022 | Apache License 2.0 |
src/Day08.kt | ricardorlg-yml | 573,098,872 | false | {"Kotlin": 38331} | import Day08Solver.Direction.*
class Day08Solver(private val input: List<List<Int>>, private val size: Int = input.size) {
private enum class Direction { LEFT, RIGHT, UP, DOWN }
private fun generateNeighbours(direction: Direction, row: Int, col: Int): Sequence<Int> {
val range = when (direction) {
... | 0 | Kotlin | 0 | 0 | d7cd903485f41fe8c7023c015e4e606af9e10315 | 3,537 | advent_code_2022 | Apache License 2.0 |
kotlin/src/main/kotlin/year2023/Day24.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2023
fun main() {
val input = readInput("Day24")
Day24.part1(input, 200_000_000_000_000L, 400_000_000_000_000L).println()
Day24.part2().println()
}
object Day24 {
fun part1(input: List<String>, atLeast: Long, atMost: Long): Int {
return input
.getHailstones()
... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 2,763 | advent-of-code | MIT License |
src/Day13.kt | RusticFlare | 574,508,778 | false | {"Kotlin": 78496} | import com.github.h0tk3y.betterParse.combinators.*
import com.github.h0tk3y.betterParse.grammar.Grammar
import com.github.h0tk3y.betterParse.grammar.parseToEnd
import com.github.h0tk3y.betterParse.grammar.parser
import com.github.h0tk3y.betterParse.lexer.literalToken
import com.github.h0tk3y.betterParse.lexer.regexToke... | 0 | Kotlin | 0 | 1 | 10df3955c4008261737f02a041fdd357756aa37f | 2,819 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2022/2022-15.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2022
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
import kotlin.math.absoluteValue
import kotlin.math.max
fun main() {
val input = readInputLines(2022, "15-input")
... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 5,745 | advent-of-code | MIT License |
src/Day11.kt | nikolakasev | 572,681,478 | false | {"Kotlin": 35834} | import java.math.BigInteger
fun main() {
fun bothParts(input: String, rounds: Int, worried: Boolean): Long {
val regex =
"""
(Monkey (\d):
Starting items: ([\d,\s]*)
Operation: new = old (\+|\*) (\w+)
Test: divisible by (\d+)
... | 0 | Kotlin | 0 | 1 | 5620296f1e7f2714c09cdb18c5aa6c59f06b73e6 | 3,116 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/commonMain/kotlin/sequences/Distinct.kt | tomuvak | 511,086,330 | false | {"Kotlin": 92304, "Shell": 619} | package com.tomuvak.util.sequences
/**
* Returns a sequence which yields the exact same elements as the receiver sequence [this], in the same order, but
* without repetitions – that is elements which have already appeared before are filtered out, and also stopping as soon
* as [maxConsecutiveAttempts] (which has to... | 0 | Kotlin | 0 | 0 | e20cfae9535fd9968542b901c698fdae1a24abc1 | 4,630 | util | MIT License |
src/Day07.kt | ajmfulcher | 573,611,837 | false | {"Kotlin": 24722} | sealed class Node {
var size = 0
}
data class Directory(
val name: String
): Node() {
val nodes: MutableList<Node> = mutableListOf<Node>()
var parent: Directory? = null
}
data class File(
val name: String,
): Node()
fun main() {
fun Directory.findDirectory(name: String): Directory {
r... | 0 | Kotlin | 0 | 0 | 981f6014b09e347241e64ba85e0c2c96de78ef8a | 2,590 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/aoc2021/Day12.kt | j4velin | 572,870,735 | false | {"Kotlin": 285016, "Python": 1446} | package aoc2021
import readInput
private fun String.isLowerCase() = all { it.isLowerCase() }
private class Graph(input: List<String>) {
private val nodes: Collection<Node>
private val start: Node
private val end: Node
init {
val nodes = mutableMapOf<Node, Node>()
input.forEach { lin... | 0 | Kotlin | 0 | 0 | f67b4d11ef6a02cba5b206aba340df1e9631b42b | 3,885 | adventOfCode | Apache License 2.0 |
src/Day12.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | import java.util.*
private val dirs: List<Pair<Int, Int>> = listOf(0 to 1, 0 to -1, 1 to 0, -1 to 0)
fun main() {
fun bfs(graphHeights: List<List<Int>>, start: List<Pair<Int, Int>>, finish: Pair<Int, Int>): Int {
val n = graphHeights.size
val m = graphHeights[0].size
val q: Queue<Pair<Int,... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 2,215 | advent-of-kotlin-2022 | Apache License 2.0 |
src/y2023/d02/Day02.kt | AndreaHu3299 | 725,905,780 | false | {"Kotlin": 31452} | package y2023.d02
import println
import readInput
fun main() {
val classPath = "y2023/d02"
fun possible(cubes: String): Boolean {
return cubes
.split(",")
.map { it.trim().split(" ") }
.all {
when (it[1]) {
"red" -> it[0].toInt()... | 0 | Kotlin | 0 | 0 | f883eb8f2f57f3f14b0d65dafffe4fb13a04db0e | 1,886 | aoc | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2023/day02/day2.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2023.day02
import biz.koziolek.adventofcode.findInput
fun main() {
val inputFile = findInput(object {})
val games = parseGames(inputFile.bufferedReader().readLines())
val possible = findPossibleGames(games, FULL_SET)
println("Possible games are: ${possible.map { i... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 2,332 | advent-of-code | MIT License |
src/Day07.kt | asm0dey | 572,860,747 | false | {"Kotlin": 61384} | import FSNode07.Dir
import FSNode07.File
fun main() {
fun buildTree(input: List<String>): Dir {
var current = Dir("/", null)
for (line in input.drop(1)) {
if (line.startsWith('$')) {
if (line.startsWith("$ cd")) {
val nextDir = line.split(' ')[2]
... | 1 | Kotlin | 0 | 1 | f49aea1755c8b2d479d730d9653603421c355b60 | 2,700 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | Nplu5 | 572,211,950 | false | {"Kotlin": 15289} | fun main() {
fun part1(input: List<String>): Int {
return input.map { line -> Rucksack.fromLine(line) }
.map { rucksack -> rucksack.getDoubleItem() }
.sumOf { item -> item.mapToPriority() }
}
fun part2(input: List<String>): Int {
return input.map { line -> Rucksack.... | 0 | Kotlin | 0 | 0 | a9d228029f31ca281bd7e4c7eab03e20b49b3b1c | 2,360 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day5Solution.kt | yigitozgumus | 434,108,608 | false | {"Kotlin": 17835} | package days
import BaseSolution
import kotlin.math.abs
data class Point(val x: Int, val y: Int)
fun createPoint(locationList: List<Int>) = Point(locationList[0], locationList[1])
data class Line(val start: Point, val end: Point) {
fun isHorizontalOrVertical(): Boolean = start.x == end.x || start.y == end.y
... | 0 | Kotlin | 0 | 0 | c0f6fc83fd4dac8f24dbd0d581563daf88fe166a | 1,928 | AdventOfCode2021 | MIT License |
src/main/kotlin/io/github/aarjavp/aoc/day15/Day15.kt | AarjavP | 433,672,017 | false | {"Kotlin": 73104} | package io.github.aarjavp.aoc.day15
import io.github.aarjavp.aoc.readFromClasspath
import java.util.*
class Day15 {
enum class Direction(val rowOffset: Int, val colOffset: Int) {
UP(-1, 0), DOWN(1, 0),
LEFT(0, -1), RIGHT(0, 1);
companion object {
val values = values().toList()... | 0 | Kotlin | 0 | 0 | 3f5908fa4991f9b21bb7e3428a359b218fad2a35 | 3,564 | advent-of-code-2021 | MIT License |
kotlin/src/com/s13g/aoc/aoc2020/Day5.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2020
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import kotlin.math.pow
/**
* --- Day 5: Binary Boarding ---
* https://adventofcode.com/2020/day/5
*/
class Day5 : Solver {
override fun solve(lines: List<String>): Result {
return solveFast(lines)
// Note, if I would have... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 1,864 | euler | Apache License 2.0 |
src/Day11.kt | pavlo-dh | 572,882,309 | false | {"Kotlin": 39999} | fun main() {
class Monkey(
val items: ArrayDeque<Long>,
val operation: Long.(Long) -> Long,
val operand: Long?,
val testConstant: Long,
val testPassesMonkeyNumber: Int,
val testFailsMonkeyNumber: Int,
var itemsInspected: Long = 0L
)
fun parseInput(inp... | 0 | Kotlin | 0 | 2 | c10b0e1ce2c7c04fbb1ad34cbada104e3b99c992 | 3,379 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/DivideArrayIntoArraysWithMaxDifference.kt | Codextor | 453,514,033 | false | {"Kotlin": 26975} | /**
* You are given an integer array nums of size n and a positive integer k.
*
* Divide the array into one or more arrays of size 3 satisfying the following conditions:
*
* Each element of nums should be in exactly one array.
* The difference between any two elements in one array is less than or equal to k.
* R... | 0 | Kotlin | 1 | 0 | 68b75a7ef8338c805824dfc24d666ac204c5931f | 2,149 | kotlin-codes | Apache License 2.0 |
src/Day05.kt | cgeesink | 573,018,348 | false | {"Kotlin": 10745} | data class Command(val count: Int, val from: Int, val to: Int) {
companion object {
fun of(line: String): Command {
return line.split(" ")
.filterIndexed { index, _ -> index % 2 == 1 }
.map { it.toInt() }
.let { Command(it[0], it[1] - 1, it[2] - 1)... | 0 | Kotlin | 0 | 0 | 137fb9a9561f5cbc358b7cfbdaf5562c20d6b10d | 2,839 | aoc-2022-in-kotlin | Apache License 2.0 |
kotlin/src/main/kotlin/AoC_Day8.kt | sviams | 115,921,582 | false | null |
object AoC_Day8 {
private val ops = mapOf<String, (Int, Int) -> Int>(
"inc" to { a, b -> a + b },
"dec" to { a, b -> a - b }
)
private val preds = mapOf<String, (Int, Int) -> Boolean>(
"<" to { a, b -> a < b },
">" to { a, b -> a > b },
">=" to ... | 0 | Kotlin | 0 | 0 | 19a665bb469279b1e7138032a183937993021e36 | 1,458 | aoc17 | MIT License |
src/main/kotlin/days/Day8.kt | andilau | 573,139,461 | false | {"Kotlin": 65955} | package days
@AdventOfCodePuzzle(
name = "Treetop Tree House",
url = "https://adventofcode.com/2022/day/8",
date = Date(day = 8, year = 2022)
)
class Day8(input: List<String>) : Puzzle {
private val trees = input.map { line -> line.map { it.digitToInt() } }
override fun partOne(): Int = trees.visi... | 0 | Kotlin | 0 | 0 | da824f8c562d72387940844aff306b22f605db40 | 2,014 | advent-of-code-2022 | Creative Commons Zero v1.0 Universal |
src/Day04.kt | jsebasct | 572,954,137 | false | {"Kotlin": 29119} |
fun main() {
// fun <Int> Pair<Int, Int>.fullyContains(another: Pair<Int, Int>): Boolean {
// return another.first <= first && another.second <= second
// }
fun fullyContains(one: Pair<Int, Int>, another: Pair<Int, Int>): Boolean {
return one.first <= another.first && one.second >= another... | 0 | Kotlin | 0 | 0 | c4a587d9d98d02b9520a9697d6fc269509b32220 | 2,389 | aoc2022 | Apache License 2.0 |
src/main/kotlin/Day24.kt | clechasseur | 267,632,210 | false | null | import org.clechasseur.adventofcode2016.Day24Data
import org.clechasseur.adventofcode2016.Direction
import org.clechasseur.adventofcode2016.Pt
import org.clechasseur.adventofcode2016.dij.Dijkstra
import org.clechasseur.adventofcode2016.dij.Graph
import org.clechasseur.adventofcode2016.math.permutations
import kotlin.ma... | 0 | Kotlin | 0 | 0 | 120795d90c47e80bfa2346bd6ab19ab6b7054167 | 3,282 | adventofcode2016 | MIT License |
src/main/kotlin/aoc2023/day12/day12Solver.kt | Advent-of-Code-Netcompany-Unions | 726,531,711 | false | {"Kotlin": 94973} | package aoc2023.day12
import lib.*
suspend fun main() {
setupChallenge().solveChallenge()
}
fun setupChallenge(): Challenge<List<Pair<String, List<Int>>>> {
return setup {
day(12)
year(2023)
//input("example.txt")
parser {
it.readLines()
.map { it... | 0 | Kotlin | 0 | 0 | a77584ee012d5b1b0d28501ae42d7b10d28bf070 | 3,988 | AoC-2023-DDJ | MIT License |
src/Day13.kt | thorny-thorny | 573,065,588 | false | {"Kotlin": 57129} | sealed class PacketNode: Comparable<PacketNode> {
data class Number(val value: Int): PacketNode()
data class List(val content: kotlin.collections.List<PacketNode>): PacketNode()
override fun compareTo(other: PacketNode): Int {
if (this is Number && other is Number) {
return value.compar... | 0 | Kotlin | 0 | 0 | 843869d19d5457dc972c98a9a4d48b690fa094a6 | 3,170 | aoc-2022 | Apache License 2.0 |
src/Day13.kt | cypressious | 572,916,585 | false | {"Kotlin": 40281} | fun main() {
data class Point(val x: Int, val y: Int)
data class Fold(val horizontal: Boolean, val value: Int)
fun parse(input: List<String>): List<CharArray> {
val points = input
.takeWhile { it.isNotBlank() }
.map { it.split(",").map(String::toInt).let { (x, y) -> Point(x,... | 0 | Kotlin | 0 | 0 | 169fb9307a34b56c39578e3ee2cca038802bc046 | 2,518 | AdventOfCode2021 | Apache License 2.0 |
src/main/kotlin/day22/Day22.kt | alxgarcia | 435,549,527 | false | {"Kotlin": 91398} | package day22
import java.io.File
private const val OFF = false
private const val ON = true
typealias Cube = Triple<Int, Int, Int>
data class RebootStep(val x: IntRange, val y: IntRange, val z: IntRange, val state: Boolean)
data class LitRegion(val x: IntRange, val y: IntRange, val z: IntRange) {
private fun isE... | 0 | Kotlin | 0 | 0 | d6b10093dc6f4a5fc21254f42146af04709f6e30 | 2,356 | advent-of-code-2021 | MIT License |
src/Day08.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} | class Day08 {
private fun linesOfSight(map: List<List<Int>>, x: Int, y: Int) = sequenceOf(
sequenceOf((x - 1 downTo 0), (x + 1 until map[0].size)).map { it.map { x -> x to y } },
sequenceOf((y - 1 downTo 0), (y + 1 until map.size)).map { it.map { y -> x to y } }
).flatten().map { it.map { (x, y)... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 1,273 | aoc-22-kotlin | Apache License 2.0 |
src/Day04.kt | Longtainbin | 573,466,419 | false | {"Kotlin": 22711} | fun main() {
val input = readInput("inputDay04")
fun part1(input: List<String>): Int {
return processPart1(input)
}
fun part2(input: List<String>): Int {
return processPart2(input)
}
println(part1(input))
println(part2(input))
}
// For part_1
private fun processPart1(... | 0 | Kotlin | 0 | 0 | 48ef88b2e131ba2a5b17ab80a0bf6a641e46891b | 1,619 | advent-of-code-2022 | Apache License 2.0 |
src/com/kingsleyadio/adventofcode/y2021/day21/Solution.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2021.day21
import com.kingsleyadio.adventofcode.util.readInput
fun part1(p1: Int, p2: Int): Int {
val scores = intArrayOf(0, 0)
val positions = intArrayOf(p1, p2)
var rolls = 0
var player = 0
while (true) {
val rolled = ++rolls + ++rolls + ++rolls
... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 2,397 | adventofcode | Apache License 2.0 |
src/day02/day02.kt | LostMekka | 574,697,945 | false | {"Kotlin": 92218} | package day02
import day02.Hand.Paper
import day02.Hand.Rock
import day02.Hand.Scissors
import util.readInput
import util.shouldBe
fun main() {
val day = 2
val testInput = readInput(day, testInput = true).parseInput()
part1(testInput) shouldBe 15
part2(testInput) shouldBe 12
val input = readInput... | 0 | Kotlin | 0 | 0 | 58d92387825cf6b3d6b7567a9e6578684963b578 | 2,048 | advent-of-code-2022 | Apache License 2.0 |
src/Day14.kt | floblaf | 572,892,347 | false | {"Kotlin": 28107} | import kotlin.math.max
import kotlin.math.min
fun main() {
fun Grid.add(x: Int, y: Int, material: Grid.Material) {
if (content[x] == null) {
content[x] = mutableMapOf()
}
content[x]!![y] = material
}
fun Grid.findDeepestRock(): Int {
return content.values.maxOf... | 0 | Kotlin | 0 | 0 | a541b14e8cb401390ebdf575a057e19c6caa7c2a | 2,945 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | andydenk | 573,909,669 | false | {"Kotlin": 24096} | fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day02_test")
check(part1(testInput) == 15)
check(part2(testInput) == 12)
val input = readInput("Day02")
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
priva... | 0 | Kotlin | 0 | 0 | 1b547d59b1dc55d515fe8ca8e88df05ea4c4ded1 | 3,169 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/codes/jakob/aoc/solution/Day14.kt | The-Self-Taught-Software-Engineer | 433,875,929 | false | {"Kotlin": 56277} | package codes.jakob.aoc.solution
object Day14 : Solution() {
override fun solvePart1(input: String): Any {
val (polymerTemplate: List<Char>, elementInsertionRules: Map<Pair<Char, Char>, Char>) = parseInput(input)
val processedElementPairFrequencies: Map<Pair<Char, Char>, ULong> =
proces... | 0 | Kotlin | 0 | 6 | d4cfb3479bf47192b6ddb9a76b0fe8aa10c0e46c | 4,481 | advent-of-code-2021 | MIT License |
src/day04/Day04.kt | EndzeitBegins | 573,569,126 | false | {"Kotlin": 111428} | package day04
import readInput
import readTestInput
private fun List<String>.asElfPairSequence(): Sequence<Pair<String, String>> = this
.asSequence()
.map { elfPair ->
val (firstElf, secondElf) = elfPair.split(",")
firstElf to secondElf
}
private fun Sequence<Pair<String, String>>.toSect... | 0 | Kotlin | 0 | 0 | ebebdf13cfe58ae3e01c52686f2a715ace069dab | 1,649 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/eu/michalchomo/adventofcode/year2023/Day03.kt | MichalChomo | 572,214,942 | false | {"Kotlin": 56758} | package eu.michalchomo.adventofcode.year2023
import eu.michalchomo.adventofcode.Day
import eu.michalchomo.adventofcode.main
object Day03 : Day {
override val number: Int = 3
override fun part1(input: List<String>): String = input.addFirstAndLastBlank()
.windowed(3, 1)
.sumOf { window ->
... | 0 | Kotlin | 0 | 0 | a95d478aee72034321fdf37930722c23b246dd6b | 3,246 | advent-of-code | Apache License 2.0 |
src/Day13.kt | wujingwe | 574,096,169 | false | null | import java.util.Stack
object Day13 {
sealed class Node {
object LEFT : Node()
class Sequence(val elements: List<Node>) : Node()
class Digit(val element: Int) : Node()
operator fun compareTo(other: Node): Int {
if (this is Digit && other is Digit) {
ret... | 0 | Kotlin | 0 | 0 | a5777a67d234e33dde43589602dc248bc6411aee | 3,723 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day09.kt | AxelUser | 572,845,434 | false | {"Kotlin": 29744} | import kotlin.math.abs
fun main() {
val diagonal = listOf(1, 1, -1, -1, 1)
val straight = listOf(0, 1, 0, -1, 0)
fun Pair<Int, Int>.plus(other: Pair<Int, Int>): Pair<Int, Int> = first + other.first to second + other.second
fun Pair<Int, Int>.distanceTo(other: Pair<Int, Int>): Int =
maxOf(abs(f... | 0 | Kotlin | 0 | 1 | 042e559f80b33694afba08b8de320a7072e18c4e | 1,758 | aoc-2022 | Apache License 2.0 |
src/Day16-wip.kt | p357k4 | 573,068,508 | false | {"Kotlin": 59696} | fun main() {
fun part1(input: List<String>): Int {
val data = input.map { line ->
val valve = line.substringAfter("Valve ").substringBefore(" ")
val rate = line.substringAfter("rate=").substringBefore(";").toInt()
val valves = if (line.contains("leads to valve ")) {
... | 0 | Kotlin | 0 | 0 | b9047b77d37de53be4243478749e9ee3af5b0fac | 2,790 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day07.kt | uekemp | 575,483,293 | false | {"Kotlin": 69253} | sealed class FileSystemItem {
abstract val name: String
}
class Directory(val parent: Directory?, override val name: String) : FileSystemItem() {
val children = mutableListOf<FileSystemItem>()
var size = 0L
fun add(item: FileSystemItem) = children.add(item)
fun findDirectory(name: String): Dir... | 0 | Kotlin | 0 | 0 | bc32522d49516f561fb8484c8958107c50819f49 | 3,515 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day07.kt | RobvanderMost-TomTom | 572,005,233 | false | {"Kotlin": 47682} | data class File(
val name: String,
val size: Int
)
data class Dir(
val name: String,
val parent: Dir? = null,
val files: MutableList<File> = mutableListOf(),
val dirs: MutableMap<String, Dir> = mutableMapOf()
) {
fun size(): Int =
files.sumOf { it.size } + dirs.values.sumOf { it.siz... | 5 | Kotlin | 0 | 0 | b7143bceddae5744d24590e2fe330f4e4ba6d81c | 2,368 | advent-of-code-2022 | Apache License 2.0 |
solutions/src/Day03.kt | khouari1 | 573,893,634 | false | {"Kotlin": 132605, "HTML": 175} | fun main() {
fun part1(input: List<String>): Int {
return input.map { line ->
val individualChars = line.split("")
val first = individualChars.subList(0, individualChars.size / 2)
val second = individualChars.subList(individualChars.size / 2, individualChars.size - 1)
... | 0 | Kotlin | 0 | 1 | b00ece4a569561eb7c3ca55edee2496505c0e465 | 1,445 | advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/aoc23/Day03.kt | tahlers | 725,424,936 | false | {"Kotlin": 65626} | package aoc23
object Day03 {
data class Pos(val x: Int, val y: Int)
data class Part(val number: Int, val startPos: Pos, val endPos: Pos) {
private val xRange = (startPos.x - 1)..(endPos.x + 1)
val adjacentPositions = xRange.map { Pos(it, startPos.y - 1) } +
listOf(Pos(startPos.... | 0 | Kotlin | 0 | 0 | 0cd9676a7d1fec01858ede1ab0adf254d17380b0 | 2,474 | advent-of-code-23 | Apache License 2.0 |
lib/src/main/kotlin/com/bloidonia/advent/day03/Day03.kt | timyates | 433,372,884 | false | {"Kotlin": 48604, "Groovy": 33934} | package com.bloidonia.advent.day03
import com.bloidonia.advent.readList
data class Diagnostic(val bits: List<Boolean>) {
fun isOn(bit: Int) = bits[bit]
fun isOn(bit: Int, required: Boolean) = bits[bit] == required
fun toInt() = bits.toInt()
override fun toString(): String {
return bits.fold(""... | 0 | Kotlin | 0 | 1 | 9714e5b2c6a57db1b06e5ee6526eb30d587b94b4 | 1,767 | advent-of-kotlin-2021 | MIT License |
src/Day05.kt | Fenfax | 573,898,130 | false | {"Kotlin": 30582} | fun main() {
fun part1(input: Map<Int, MutableList<Char>>, commands: List<List<Int>>): String {
commands.forEach { number ->
input[number[1]]?.let {
input[number[2]]?.addAll((1..number[0]).map { _ -> it.removeLast() })
}
}
return input.map { it.value.... | 0 | Kotlin | 0 | 0 | 28af8fc212c802c35264021ff25005c704c45699 | 1,502 | AdventOfCode2022 | Apache License 2.0 |
src/Day16.kt | frango9000 | 573,098,370 | false | {"Kotlin": 73317} | import kotlin.math.max
fun main() {
val input = readInput("Day16")
printTime { print(Day16.part1(input)) }
printTime { print(Day16.part2(input)) }
}
class Day16 {
companion object {
fun part1(input: List<String>): Int {
val valves = input.map {
it.split(
... | 0 | Kotlin | 0 | 0 | 62e91dd429554853564484d93575b607a2d137a3 | 5,406 | advent-of-code-22 | Apache License 2.0 |
src/aoc2022/Day12.kt | nguyen-anthony | 572,781,123 | false | null | package aoc2022
import utils.readInputAsList
data class Step(val point: Pair<Int,Int>, val distance: Int, val parent: Step?)
fun main() {
fun letter(ch: Char): Char {
return when (ch) {
'S' -> 'a'
'E' -> 'z'
else -> ch
}
}
fun findShortest(start: Pair<I... | 0 | Kotlin | 0 | 0 | 9336088f904e92d801d95abeb53396a2ff01166f | 2,538 | AOC-2022-Kotlin | Apache License 2.0 |
src/year2023/day05/Day05.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2023.day05
import check
import readInput
import kotlin.math.max
import kotlin.math.min
fun main() {
val testInput = readInput("2023", "Day05_test")
check(part1(testInput), 35)
check(part2(testInput), 46)
val input = readInput("2023", "Day05")
println(part1(input))
println(part2(in... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 3,959 | AdventOfCode | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2023/Day07.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2023
import se.saidaspen.aoc.util.*
import java.lang.RuntimeException
fun main() = Day07.run()
object Day07 : Day(2023, 7) {
private const val RANKS = "A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2, *"
override fun part1() = input.lines()
.sortedWith(handComparator).reversed()
... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,944 | adventofkotlin | MIT License |
src/main/Day16.kt | ssiegler | 572,678,606 | false | {"Kotlin": 76434} | package day16
import utils.readInput
import java.util.*
import kotlin.math.max
data class Valves(
private val flows: Map<String, Int>,
private val tunnels: Map<String, List<String>>
) {
private val flowValves =
flows.entries.filter { (_, flow) -> flow > 0 }.map { (valve, _) -> valve }
private... | 0 | Kotlin | 0 | 0 | 9133485ca742ec16ee4c7f7f2a78410e66f51d80 | 4,436 | aoc-2022 | Apache License 2.0 |
src/year2023/day06/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2023.day06
import arrow.core.nonEmptyListOf
import utils.ProblemPart
import utils.product
import utils.readInputs
import utils.runAlgorithm
fun main() {
val (realInput, testInputs) = readInputs(2023, 6)
runAlgorithm(
realInput = realInput,
testInputs = testInputs,
part1 = ... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 1,828 | Advent-of-Code | Apache License 2.0 |
src/year_2021/day_02/Day02.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2021.day_02
import readInput
enum class Heading(val text: String) {
FORWARD("forward"),
DOWN("down"),
UP("up"),
;
companion object {
fun fromText(text: String): Heading {
return Heading.values().first { it.text == text }
}
}
}
data class Direction(
... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 2,644 | advent_of_code | Apache License 2.0 |
src/Day15.kt | makohn | 571,699,522 | false | {"Kotlin": 35992} | import kotlin.math.abs
fun main() {
val day = "15"
fun List<List<Vec2>>.scanArea(row: Int) = this.map { (scanner, beacon) ->
val yDistance = abs(scanner.y - row)
val distance = manhattanDistance(scanner, beacon)
if (yDistance <= distance) {
(scanner.x - distance) + yDistan... | 0 | Kotlin | 0 | 0 | 2734d9ea429b0099b32c8a4ce3343599b522b321 | 2,139 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/g2601_2700/s2662_minimum_cost_of_a_path_with_special_roads/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2601_2700.s2662_minimum_cost_of_a_path_with_special_roads
// #Medium #Array #Heap_Priority_Queue #Graph #Shortest_Path
// #2023_07_25_Time_690_ms_(100.00%)_Space_59.5_MB_(50.00%)
import java.util.PriorityQueue
class Solution {
fun minimumCost(start: IntArray, target: IntArray, specialRoads: Array<IntArr... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,227 | LeetCode-in-Kotlin | MIT License |
src/Day03.kt | thorny-thorny | 573,065,588 | false | {"Kotlin": 57129} | class PriorityFlags {
companion object {
private fun itemPriority(item: Char) = when (item) {
in 'a'..'z' -> item - 'a' + 1
in 'A'..'Z' -> item - 'A' + 27
else -> throw Exception("Unknown item")
}
fun allRaised() = PriorityFlags().apply { value = ULong.MA... | 0 | Kotlin | 0 | 0 | 843869d19d5457dc972c98a9a4d48b690fa094a6 | 2,108 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day12.kt | gijs-pennings | 573,023,936 | false | {"Kotlin": 20319} | fun main() {
val lines = readInput(12)
val w = lines[0].length
val h = lines.size
val grid = Array(w) { x -> Array(h) { y -> Node(x, y, lines[y][x]) } }
val nodes = grid.flatten()
for (n in nodes) {
if (n.x-1 >= 0 && n.h <= grid[n.x-1][n.y].h + 1) n.adjRev.add(grid[n.x-1][n.y])
i... | 0 | Kotlin | 0 | 0 | 8ffbcae744b62e36150af7ea9115e351f10e71c1 | 1,287 | aoc-2022 | ISC License |
src/day21/Day21.kt | EndzeitBegins | 573,569,126 | false | {"Kotlin": 111428} | package day21
import readInput
import readTestInput
private sealed interface MonkeyTask {
class SolvedTask(val solution: Long) : MonkeyTask
class OpenTask(
val lhs: String,
val rhs: String,
val operation: Char
) : MonkeyTask {
fun solve(lhsValue: Long, rhsValue: Long): So... | 0 | Kotlin | 0 | 0 | ebebdf13cfe58ae3e01c52686f2a715ace069dab | 6,294 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day02/Day02.kt | dkoval | 572,138,985 | false | {"Kotlin": 86889} | package day02
import readInput
private const val DAY_ID = "02"
private enum class Shape(val score: Int) {
// rock
A(1) {
override fun wins(): Shape = C
override fun loses(): Shape = B
},
// paper
B(2) {
override fun wins(): Shape = A
override fun loses(): Shape = ... | 0 | Kotlin | 1 | 0 | 791dd54a4e23f937d5fc16d46d85577d91b1507a | 2,264 | aoc-2022-in-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.