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/day07/Day07.kt | martin3398 | 572,166,179 | false | {"Kotlin": 76153} | package day07
import readInput
import kotlin.math.min
abstract class Node(var size: Int = 0)
class InnerNode(val parent: InnerNode?) : Node() {
val successors: MutableMap<String, Node> = mutableMapOf()
}
class Leaf(size: Int): Node(size)
fun main() {
fun buildTree(input: List<String>): InnerNode {
... | 0 | Kotlin | 0 | 0 | 4277dfc11212a997877329ac6df387c64be9529e | 2,951 | advent-of-code-2022 | Apache License 2.0 |
src/y2023/Day17.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2023
import util.Cardinal
import util.Pos
import util.get
import util.plus
import util.readInput
import util.timingStatistics
import y2022.Day15.manhattanDist
import y2023.Day14.coerce
import java.util.PriorityQueue
object Day17 {
data class Block(
val pos: Pos,
val heatLoss: Int,
)
... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 4,516 | advent-of-code | Apache License 2.0 |
src/main/kotlin/ru/timakden/aoc/year2015/Day15.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2015
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 15: Science for Hungry People](https://adventofcode.com/2015/day/15).
*/
object Day15 {
@JvmStatic
fun main(args: Array<String>) {
measure {
val input = readInput("year20... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 3,041 | advent-of-code | MIT License |
src/main/kotlin/aoc2023/Day04.kt | Ceridan | 725,711,266 | false | {"Kotlin": 110767, "Shell": 1955} | package aoc2023
import kotlin.math.pow
class Day04 {
fun part1(input: List<String>): Int = input
.sumOf { Card.fromString(it).calculatePoints() }
fun part2(input: List<String>): Int {
val cards = input.map { line -> Card.fromString(line) }
val counts = IntArray(cards.size) { _ -> 1 }
... | 0 | Kotlin | 0 | 0 | 18b97d650f4a90219bd6a81a8cf4d445d56ea9e8 | 1,752 | advent-of-code-2023 | MIT License |
src/com/kingsleyadio/adventofcode/y2022/day07/Solution.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2022.day07
import com.kingsleyadio.adventofcode.util.readInput
fun main() {
val fs = buildFs()
part1(fs)
part2(fs)
}
fun part1(root: Fs) {
var partialSum = 0
root.sumWithATwist(100_000, true) { partialSum += it }
println(partialSum)
}
fun part2(root: Fs... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 2,393 | adventofcode | Apache License 2.0 |
solutions/aockt/y2021/Y2021D15.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
import java.util.PriorityQueue
object Y2021D15 : Solution {
/** Represents a discrete point in 2D space. */
private data class Point(val x: Int, val y: Int)
/** A 2D map of risk levels, used for navigation. */
private class ChironRiskM... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 4,276 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/day15/Chiton.kt | Arch-vile | 433,381,878 | false | {"Kotlin": 57129} | package day15
import utils.Cursor
import utils.Matrix
import utils.graphs.Node
import utils.graphs.shortestPath
import utils.read
fun main() {
solve().let { println(it) }
}
fun solve(): List<Long> {
val data = read("./src/main/resources/day15Input.txt")
.map { it.windowed(1, 1).map { it.toInt() } }
... | 0 | Kotlin | 0 | 0 | 4cdafaa524a863e28067beb668a3f3e06edcef96 | 2,024 | adventOfCode2021 | Apache License 2.0 |
src/day04/Day04.kt | lpleo | 572,702,403 | false | {"Kotlin": 30960} | package day04
import readInput
fun main() {
fun part1(input: List<String>): Int {
return input
.asSequence()
.map { row -> row.split(",") }
.map { assignments -> assignments.map { assignment -> assignment.split("-") } }
.map { assignments ->... | 0 | Kotlin | 0 | 0 | 115aba36c004bf1a759b695445451d8569178269 | 1,799 | advent-of-code-2022 | Apache License 2.0 |
src/Day07.kt | Redstonecrafter0 | 571,787,306 | false | {"Kotlin": 19087} |
class VFile(val name: String, val size: Int = -1) {
val children: MutableMap<String, VFile> = mutableMapOf()
val isDir: Boolean
get() = size < 0
val dirSize: Int
get() = if (isDir) children.values.sumOf { it.dirSize } else size
override fun toString(): String {
return "VFile... | 0 | Kotlin | 0 | 0 | e5dbabe247457aabd6dd0f0eb2eb56f9e4c68858 | 2,347 | Advent-of-Code-2022 | Apache License 2.0 |
y2015/src/main/kotlin/adventofcode/y2015/Day15.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2015
import adventofcode.io.AdventSolution
object Day15 : AdventSolution(2015, 15, "Science for Hungry People") {
override fun solvePartOne(input: String): Int {
val ingredients = parseInput(input)
return partition(100)
.map { ingredients.zip(it, Ingredient::sca... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 2,186 | advent-of-code | MIT License |
src/Day07.kt | zfz7 | 573,100,794 | false | {"Kotlin": 53499} | val sizes = mutableMapOf<String, Int>()
val folders = mutableMapOf<String, List<String>>()
fun main() {
setUp(readFile("Day07"))
println(folders)
println(sizes)
println(day7A())
println(day7B())
}
fun day7A(): Int = sizes.toList().sumOf {if(!it.first.contains("FILE") && it.second<=100000) it.second... | 0 | Kotlin | 0 | 0 | c50a12b52127eba3f5706de775a350b1568127ae | 2,124 | AdventOfCode22 | Apache License 2.0 |
src/Day02.kt | astrofyz | 572,802,282 | false | {"Kotlin": 124466} | fun main() {
fun part1(input: List<String>): Int {
val scoreMap = mapOf("X" to 1, "Y" to 2, "Z" to 3)
val gameMap = mapOf("A Y" to 6, "B Z" to 6, "C X" to 6, "A X" to 3, "B Y" to 3, "C Z" to 3)
var totalSum = 0
for (game in input){
totalSum += gameMap.getOrDefault(game, ... | 0 | Kotlin | 0 | 0 | a0bc190b391585ce3bb6fe2ba092fa1f437491a6 | 1,486 | aoc22 | Apache License 2.0 |
src/Day15.kt | ricardorlg-yml | 573,098,872 | false | {"Kotlin": 38331} | import kotlin.math.abs
val numberRegex = """(-?\d+)""".toRegex()
class Day15Solver(private val data: List<String>) {
private var minX = 0L
private var maxX = 0L
private val sensors = parseInput()
class Sensor(
val sensorX: Long,
val sensorY: Long,
private val closestBeacon... | 0 | Kotlin | 0 | 0 | d7cd903485f41fe8c7023c015e4e606af9e10315 | 3,441 | advent_code_2022 | Apache License 2.0 |
src/poyea/aoc/mmxxii/day12/Day12.kt | poyea | 572,895,010 | false | {"Kotlin": 68491} | package poyea.aoc.mmxxii.day12
import kotlin.Int.Companion.MAX_VALUE
import kotlin.collections.ArrayDeque
import kotlin.collections.HashSet
import poyea.aoc.utils.readInput
fun find_start(grid: List<CharArray>, pred: (c: Char) -> Boolean): List<Pair<Int, Int>> {
val start_points = mutableListOf<Pair<Int, Int>>()
... | 0 | Kotlin | 0 | 1 | fd3c96e99e3e786d358d807368c2a4a6085edb2e | 2,689 | aoc-mmxxii | MIT License |
src/Day15.kt | Kvest | 573,621,595 | false | {"Kotlin": 87988} | import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.time.ExperimentalTime
@ExperimentalTime
fun main() {
val testInput = readInput("Day15_test")
val (testSensors, testBeacons) = parseInput(testInput)
check(part1(testSensors, testBeacons, targetLine = 10) == 26)
check(part2(te... | 0 | Kotlin | 0 | 0 | 6409e65c452edd9dd20145766d1e0ea6f07b569a | 3,001 | AOC2022 | Apache License 2.0 |
src/year2021/Day15.kt | drademacher | 725,945,859 | false | {"Kotlin": 76037} | package year2021
import Point
import readLines
import java.util.PriorityQueue
fun main() {
val input = parseInput(readLines("2021", "day15"))
val testInput = parseInput(readLines("2021", "day15_test"))
check(part1(testInput) == 40)
println("Part 1:" + part1(input))
check(part2(testInput) == 315)... | 0 | Kotlin | 0 | 0 | 4c4cbf677d97cfe96264b922af6ae332b9044ba8 | 2,438 | advent_of_code | MIT License |
src/Day14.kt | bigtlb | 573,081,626 | false | {"Kotlin": 38940} | fun main() {
class Scan(input: List<String>, val withFloor:Boolean=false) {
init {
rocks = input.flatMap {
it.split(" -> ").map {
it.split(",").let { (x, y) -> Loc(x.toInt(), y.toInt()) }
}
.windowed(2).flatMap { (from, to) ... | 0 | Kotlin | 0 | 0 | d8f76d3c75a30ae00c563c997ed2fb54827ea94a | 3,574 | aoc-2022-demo | Apache License 2.0 |
src/2022/Day24.kt | ttypic | 572,859,357 | false | {"Kotlin": 94821} | package `2022`
import readInput
fun main() {
fun part1(input: List<String>): Int {
return Maze.readMaze(input).solve()
}
fun part2(input: List<String>): Int {
var maze = Maze.readMaze(input)
val startToGoal = maze.solve()
maze = maze.reverse()
val backToStart = maz... | 0 | Kotlin | 0 | 0 | b3e718d122e04a7322ed160b4c02029c33fbad78 | 4,564 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/dev/tasso/adventofcode/_2022/day10/Day10.kt | AndrewTasso | 433,656,563 | false | {"Kotlin": 75030} | package dev.tasso.adventofcode._2022.day10
import dev.tasso.adventofcode.Solution
class Day10 : Solution<Int> {
override fun part1(input: List<String>): Int =
input.asSequence()
.map { inputLine -> inputLine.split(" ") }
.map{ splitLine ->
Instruction(splitLine[... | 0 | Kotlin | 0 | 0 | daee918ba3df94dc2a3d6dd55a69366363b4d46c | 2,259 | advent-of-code | MIT License |
solutions/aockt/y2023/Y2023D13.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2023
import aockt.util.parse
import io.github.jadarma.aockt.core.Solution
object Y2023D13 : Solution {
/**
* Notes on the terrain of Lava Island, but without any lava...
* @param data The terrain reading, first element is first row, then going upwards. Should only contain `[#.]`.
*/... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,718 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/day16.kt | p88h | 317,362,882 | false | null | internal data class Range(val name: String, val a: Pair<Int, Int>, val b: Pair<Int, Int>) {
var invalid = HashSet<Int>()
var pos = -1
}
internal val pattern = "([a-z ]+): ([0-9]+)-([0-9]+) or ([0-9]+)-([0-9]+)".toRegex()
internal fun parseRange(input: String): Range {
pattern.matchEntire(input)!!.destructu... | 0 | Kotlin | 0 | 5 | 846ad4a978823563b2910c743056d44552a4b172 | 2,176 | aoc2020 | The Unlicense |
src/day07/Day07.kt | TimberBro | 572,681,059 | false | {"Kotlin": 20536} | package day07
import readInput
data class File(val name: String, val size: Int)
class Directory(private val name: String) {
var parentDirectory: Directory? = null
val files = ArrayList<File>()
var directories = ArrayList<Directory>()
fun addChild(directory: Directory) {
directories.add(dire... | 0 | Kotlin | 0 | 0 | 516a98e5067d11f0e6ff73ae19f256d8c1bfa905 | 3,749 | AoC2022 | Apache License 2.0 |
src/main/kotlin/day12/Day12.kt | jakubgwozdz | 571,298,326 | false | {"Kotlin": 85100} | package day12
import bfs
import execute
import readAllText
fun part1(input: String): Int = input.lineSequence().filterNot(String::isBlank)
.toList()
.let { lines ->
val start = lines.indexOfFirst { it.contains("S") }.let { r -> r to lines[r].indexOf('S') }
val end = lines.indexOfFirst { it.con... | 0 | Kotlin | 0 | 0 | 7589942906f9f524018c130b0be8976c824c4c2a | 2,343 | advent-of-code-2022 | MIT License |
src/day1/puzzle01.kt | brendencapps | 572,821,792 | false | {"Kotlin": 70597} | package day1
import Puzzle
import PuzzleInput
import java.io.File
import java.util.PriorityQueue
fun day1Puzzle() {
Day1PuzzleSolution1(1).solve(Day1PuzzleInput("inputs/day1/exampleData.txt", 24000))
Day1PuzzleSolution1(2).solve(Day1PuzzleInput("inputs/day1/exampleData.txt", 35000))
Day1PuzzleSolution1(3)... | 0 | Kotlin | 0 | 0 | 00e9bd960f8bcf6d4ca1c87cb6e8807707fa28f3 | 2,290 | aoc_2022 | Apache License 2.0 |
src/main/kotlin/org/elm/workspace/solver/Solver.kt | klazuka | 104,530,474 | false | null | package org.elm.workspace.solver
import org.elm.workspace.Constraint
import org.elm.workspace.Version
import org.elm.workspace.solver.SolverResult.DeadEnd
import org.elm.workspace.solver.SolverResult.Proceed
typealias PkgName = String
interface Pkg {
val name: PkgName
val version: Version
val elmConstrai... | 167 | Kotlin | 61 | 371 | 1d9f3d4578f89e7f26b3e7ded63b29fd18790f1e | 3,564 | intellij-elm | MIT License |
advent-of-code-2022/src/main/kotlin/Day08.kt | jomartigcal | 433,713,130 | false | {"Kotlin": 72459} | //Day 08: Treetop Tree House
//https://adventofcode.com/2022/day/8
import java.io.File
data class Tree(val index: Pair<Int, Int>, val height: Int)
fun main() {
val trees = mutableListOf<Tree>()
val input = File("src/main/resources/Day08.txt").readLines()
input.forEachIndexed { x, line ->
line.to... | 0 | Kotlin | 0 | 0 | 6b0c4e61dc9df388383a894f5942c0b1fe41813f | 2,717 | advent-of-code | Apache License 2.0 |
archive/2022/Day18.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | import kotlin.collections.ArrayDeque
private const val EXPECTED_1 = 64
private const val EXPECTED_2 = 58
private class Day18(isTest: Boolean) : Solver(isTest) {
val data = readAsLines().map { line ->
line.split(",").map { it.toInt() }
}.toSet()
val dirs = listOf(
listOf(1, 0, 0),
... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 1,955 | advent-of-code-2022 | Apache License 2.0 |
src/Day11.kt | p357k4 | 573,068,508 | false | {"Kotlin": 59696} | import java.math.BigInteger
data class Monkey(
val starting: List<Long>,
val operation: List<String>,
val divisor: Long,
val monkeyTrue: Int,
val monkeyFalse: Int
)
fun main() {
fun simulation(
monkeys: Array<Monkey>,
state: Array<List<Long>>,
inspections: Array<Long>,
... | 0 | Kotlin | 0 | 0 | b9047b77d37de53be4243478749e9ee3af5b0fac | 3,038 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day04/Day04.kt | spyroid | 433,555,350 | false | null | package day04
import readInput
fun main() {
data class Cell(var value: Int = 0, var marked: Boolean = false)
class Board(data: List<String>) {
val cells: Array<Array<Cell>> = Array(5) { Array(5) { Cell() } }
init {
data.forEachIndexed { idx1, line ->
line.trim()... | 0 | Kotlin | 0 | 0 | 939c77c47e6337138a277b5e6e883a7a3a92f5c7 | 2,288 | Advent-of-Code-2021 | Apache License 2.0 |
src/main/kotlin/days/y2023/day17_a/Day17.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2023.day17_a
import util.InputReader
import kotlin.math.abs
typealias PuzzleLine = String
typealias PuzzleInput = List<PuzzleLine>
class Day17(val input: PuzzleInput) {
val grid = input.toGrid()
fun partOne(): Int {
return minOf(
grid.bestDistanceTo(grid.end, Direction.X),
... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 3,974 | AdventOfCode | Creative Commons Zero v1.0 Universal |
solutions/aockt/y2021/Y2021D09.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
object Y2021D09 : Solution {
/** Represents a discrete point in 2D space. */
private data class Point(val x: Int, val y: Int)
/** Represents the scanning of the lava tubes inside the cave system. */
private class LavaTubesMap(val width... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,213 | advent-of-code-kotlin-solutions | The Unlicense |
src/Day21.kt | SimoneStefani | 572,915,832 | false | {"Kotlin": 33918} | // FIXME improve name with better namespacing
data class Monkey21(
val name: String,
val number: Long? = null,
val left: String? = null,
val operator: String? = null,
val right: String? = null,
) {
fun resolve(left: Long, right: Long): Long = when (operator) {
"+" -> left + right
... | 0 | Kotlin | 0 | 0 | b3244a6dfb8a1f0f4b47db2788cbb3d55426d018 | 2,655 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day14/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day14
import java.io.File
import java.util.*
fun main() {
var template: List<Char> = LinkedList()
var pairInsertionsRules: Map<Pair<Char, Char>, Char> = emptyMap()
File("src/main/kotlin/day14/input.txt").useLines { linesSequence ->
val linesIterator = linesSequence.iterator()
temp... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 2,436 | aoc-2021 | MIT License |
src/main/kotlin/twentytwentytwo/Day24.kt | JanGroot | 317,476,637 | false | {"Kotlin": 80906} | package twentytwentytwo
fun main() {
val tinput = {}.javaClass.getResource("input-24-1.txt")!!.readText().linesFiltered { it.isNotEmpty() };
val input = {}.javaClass.getResource("input-24.txt")!!.readText().linesFiltered { it.isNotEmpty() };
val test = Day24(tinput)
val day = Day24(input)
println(... | 0 | Kotlin | 0 | 0 | 04a9531285e22cc81e6478dc89708bcf6407910b | 2,638 | aoc202xkotlin | The Unlicense |
src/Day11.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | fun main() {
val testInput = readInput("Day11_test")
check(part1(testInput) == 10605L)
check(part2(testInput) == 2713310158L)
val input = readInput("Day11")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>): Long = run(input, rounds = 20) { level, _ -> level ... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 2,258 | aoc-22 | Apache License 2.0 |
src/year2023/Day12.kt | drademacher | 725,945,859 | false | {"Kotlin": 76037} | package year2023
import readLines
fun main() {
val input = readLines("2023", "day12")
val testInput = readLines("2023", "day12_test")
check(part1(testInput) == 21L)
println("Part 1:" + part1(input))
check(part2(testInput) == 525152L)
println("Part 2:" + part2(input))
}
private fun part1(inp... | 0 | Kotlin | 0 | 0 | 4c4cbf677d97cfe96264b922af6ae332b9044ba8 | 3,358 | advent_of_code | MIT License |
src/day02/Day02.kt | MaxBeauchemin | 573,094,480 | false | {"Kotlin": 60619} | package day02
import readInput
enum class RPSChoice(val defaultPoints: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3);
fun beats(other: RPSChoice): Boolean {
return when (this) {
ROCK -> other == SCISSORS
PAPER -> other == ROCK
SCISSORS -> other == PAPER
}
... | 0 | Kotlin | 0 | 0 | 38018d252183bd6b64095a8c9f2920e900863a79 | 3,461 | advent-of-code-2022 | Apache License 2.0 |
src/Day12.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | fun main() {
val testInput = readInput("Day12_test")
check(part1(testInput) == 31)
check(part2(testInput) == 29)
val input = readInput("Day12")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>): Int {
val (start, end, hills) = parseHills(input)
return... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 1,637 | aoc-22 | Apache License 2.0 |
src/Day05.kt | Redstonecrafter0 | 571,787,306 | false | {"Kotlin": 19087} |
fun main() {
fun parse(input: List<String>): Pair<List<MutableList<Char>>, List<Triple<Int, Int, Int>>> {
val gapIndex = input.indexOf("")
val cratesRange = 0 until input[gapIndex - 1].split(" ").last().toInt()
val cratesVertical = input
.subList(0, gapIndex - 1)
... | 0 | Kotlin | 0 | 0 | e5dbabe247457aabd6dd0f0eb2eb56f9e4c68858 | 1,946 | Advent-of-Code-2022 | Apache License 2.0 |
src/day24/Day24.kt | Volifter | 572,720,551 | false | {"Kotlin": 65483} | package day24
import utils.*
val DIRECTIONS = listOf(
Coords(0, 0),
Coords(1, 0),
Coords(-1, 0),
Coords(0, 1),
Coords(0, -1)
)
data class Coords(var x: Int, var y: Int) {
fun wrapIn(size: Coords): Coords =
Coords(
Math.floorMod(x, size.x),
Math.floorMod(y, size... | 0 | Kotlin | 0 | 0 | c2c386844c09087c3eac4b66ee675d0a95bc8ccc | 3,217 | AOC-2022-Kotlin | Apache License 2.0 |
graph/LowestCommonAncestor.kt | wangchaohui | 737,511,233 | false | {"Kotlin": 36737} | class SparseTable<T>(list: List<T>, private val merge: (T, T) -> T) {
private val n = list.size
private val logN = n.takeHighestOneBit().countTrailingZeroBits()
private val table = mutableListOf(list.toList()).apply {
for (i in 1..logN) {
val lastRangeSize = 1 shl i - 1
add(L... | 0 | Kotlin | 0 | 0 | 241841f86fdefa9624e2fcae2af014899a959cbe | 2,257 | kotlin-lib | Apache License 2.0 |
src/main/kotlin/com/hjk/advent22/Day15.kt | h-j-k | 572,485,447 | false | {"Kotlin": 26661, "Racket": 3822} | package com.hjk.advent22
import kotlin.math.abs
object Day15 {
fun part1(input: List<String>, row: Int): Long = noBeaconsOn(input.mapNotNull(Sensor::parse), row)
.fold(0L to Long.MIN_VALUE) { (count, last), range ->
if (count == 0L) (range.last - last.coerceAtLeast(range.first)) to range.last... | 0 | Kotlin | 0 | 0 | 20d94964181b15faf56ff743b8646d02142c9961 | 1,974 | advent22 | Apache License 2.0 |
advent-of-code-2021/src/main/kotlin/eu/janvdb/aoc2021/day22/Day22.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2021.day22
import eu.janvdb.aocutil.kotlin.readLines
import kotlin.math.max
import kotlin.math.min
const val FILENAME = "input22.txt"
fun main() {
val instructions = readLines(2021, FILENAME).map(Instruction::parse)
part(instructions.filter { it.region.xMin>=-50 && it.region.xMax<=50 && it.re... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,840 | advent-of-code | Apache License 2.0 |
dcp_kotlin/src/main/kotlin/dcp/day200/day200.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day200
// day200.kt
// By <NAME>, 2019.
import kotlin.math.max
import kotlin.math.min
data class Interval(val start: Double, val end: Double): Comparable<Interval> {
operator fun contains(that: Interval): Boolean = start <= that.start && end >= that.end
operator fun contains(value: Double): Boole... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 3,156 | daily-coding-problem | MIT License |
src/Day05.kt | ThijsBoehme | 572,628,902 | false | {"Kotlin": 16547} | /*
Followed along with the Kotlin by JetBrains livestream, with some personal adjustments
*/
private data class Move(
val quantity: Int,
val source: Int,
val target: Int,
) {
companion object {
fun of(line: String): Move {
return line.split(" ")
.filterIndexed { ind... | 0 | Kotlin | 0 | 0 | 707e96ec77972145fd050f5c6de352cb92c55937 | 2,668 | Advent-of-Code-2022 | Apache License 2.0 |
day12/day12.kt | carolhmj | 231,454,053 | false | null | import kotlin.math.*
import java.io.File
data class Moon(val position : IntArray, val velocity : IntArray = intArrayOf(0,0,0))
data class IndexAndValue<T>(val index : Int, val value : T)
fun <T, U> cartesianProductIndexed(c1: Collection<T>, c2: Collection<U>): List<Pair<IndexAndValue<T>, IndexAndValue<U>>> {
retu... | 0 | Rust | 0 | 0 | a10106877f180e989360b80c76048b2d4161b370 | 2,312 | aoc2019 | MIT License |
src/Day07.kt | buczebar | 572,864,830 | false | {"Kotlin": 39213} | private const val TOTAL_DISK_SPACE = 70000000L
private const val SPACE_NEEDED_FOR_UPDATE = 30000000L
fun main() {
fun part1(fileTree: TreeNode): Long {
return fileTree.getAllSubdirectories().filter { it.totalSize <= 100_000 }.sumOf { it.totalSize }
}
fun part2(fileTree: TreeNode): Long {
va... | 0 | Kotlin | 0 | 0 | cdb6fe3996ab8216e7a005e766490a2181cd4101 | 3,150 | advent-of-code | Apache License 2.0 |
src/day05/Day05.kt | Ciel-MC | 572,868,010 | false | {"Kotlin": 55885} | package day05
import readInput
import java.util.*
fun main() {
fun parseCrateStack(input: List<String>): Map<Int, Stack<Char>> {
return buildMap {
input.reversed().forEach { row ->
row.chunked(4).map { it.trim().removeSurrounding("[", "]") }
.map { i... | 0 | Kotlin | 0 | 0 | 7eb57c9bced945dcad4750a7cc4835e56d20cbc8 | 2,645 | Advent-Of-Code | Apache License 2.0 |
src/year2023/day15/Day15.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2023.day15
import check
import readInput
fun main() {
val testInput = readInput("2023", "Day15_test")
check(part1(testInput), 1320)
check(part2(testInput), 145)
val input = readInput("2023", "Day15")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<Stri... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 1,493 | AdventOfCode | Apache License 2.0 |
src/main/kotlin/com/dmc/advent2022/Day02.kt | dorienmc | 576,916,728 | false | {"Kotlin": 86239} | // --- Day 2: Rock Paper Scissors ---
package com.dmc.advent2022
class Day02 : Day<Int> {
override val index = 2
override fun part1(input: List<String>): Int {
return input.sumOf { calcScore1(it.split(" ")) }
}
override fun part2(input: List<String>): Int {
return input.sumOf { calcSc... | 0 | Kotlin | 0 | 0 | 207c47b47e743ec7849aea38ac6aab6c4a7d4e79 | 2,634 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/面试题 17.24. 最大子矩阵.kts | ShreckYe | 206,086,675 | false | null | import kotlin.test.assertContentEquals
class Solution {
data class SumFromC1(val c1: Int, val sum: Long)
fun getMaxMatrix(matrix: Array<IntArray>): IntArray {
val m = matrix.size
val n = matrix.first().size
// empty submatrices not allowed
val prefixSumsAtC = Array(n) { c ->
... | 0 | Kotlin | 0 | 0 | 20e8b77049fde293b5b1b3576175eb5703c81ce2 | 2,653 | leetcode-solutions-kotlin | MIT License |
src/Day02.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | private enum class GameMove {
ROCK, PAPER, SCISSORS;
val winsOver: GameMove
get() = when (this) {
ROCK -> SCISSORS
PAPER -> ROCK
SCISSORS -> PAPER
}
val loosesTo: GameMove
get() = when (this) {
SCISSORS -> ROCK
ROCK -> PAP... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 2,825 | aoc2022 | Apache License 2.0 |
src/day12/Day12.kt | iulianpopescu | 572,832,973 | false | {"Kotlin": 30777} | package day12
import readInput
import kotlin.math.min
private const val DAY = "12"
private const val DAY_TEST = "day${DAY}/Day${DAY}_test"
private const val DAY_INPUT = "day${DAY}/Day${DAY}"
fun main() {
val directions = listOf(0 to 1, 0 to -1, 1 to 0, -1 to 0)
fun findShortestPaths(
input: List<Stri... | 0 | Kotlin | 0 | 0 | 4ff5afb730d8bc074eb57650521a03961f86bc95 | 3,165 | AOC2022 | Apache License 2.0 |
src/Day11.kt | ambrosil | 572,667,754 | false | {"Kotlin": 70967} | import kotlin.math.floor
fun main() {
data class Monkey(
val items: MutableList<Long>,
val operation: String,
val divisor: Long,
val trueMonkey: Int,
val falseMonkey: Int,
var inspections: Long = 0
)
fun parse(input: List<String>) =
input
... | 0 | Kotlin | 0 | 0 | ebaacfc65877bb5387ba6b43e748898c15b1b80a | 3,021 | aoc-2022 | Apache License 2.0 |
src/Day07/Day07.kt | brhliluk | 572,914,305 | false | {"Kotlin": 16006} | fun main() {
val TOTAL_SPACE = 70000000
val REQUIRED_SPACE = 30000000
fun parseFs(input: List<String>): Folder {
val root = Folder("/", null)
var currentFolder = root
input.forEach { line ->
if (line.startsWith("$")) {
val command = line.trimStart('$').tr... | 0 | Kotlin | 0 | 0 | 96ac4fe0c021edaead8595336aad73ef2f1e0d06 | 3,108 | kotlin-aoc | Apache License 2.0 |
src/Day05.kt | muellerml | 573,601,715 | false | {"Kotlin": 14872} | import com.sun.org.apache.xpath.internal.operations.Bool
fun main() {
fun part1(input: List<String>): String {
return performMoves(input, reversed = true)
}
fun part2(input: List<String>): String {
return performMoves(input, reversed = false)
}
// test if implementation meets crit... | 0 | Kotlin | 0 | 0 | 028ae0751d041491009ed361962962a64f18e7ab | 2,193 | aoc-2022 | Apache License 2.0 |
src/day12/Day12.kt | EndzeitBegins | 573,569,126 | false | {"Kotlin": 111428} | package day12
import readInput
import readTestInput
private data class Node(
val elevation: Int,
val rawElevation: Char,
)
private data class Coordinate(val x: Int, val y: Int)
private infix fun Int.to(y: Int) = Coordinate(x = this, y = y)
private fun List<String>.toNodeMap(): Map<Coordinate, Node> =
f... | 0 | Kotlin | 0 | 0 | ebebdf13cfe58ae3e01c52686f2a715ace069dab | 3,835 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/briarshore/aoc2022/day03/Puzzle.kt | steveswing | 579,243,154 | false | {"Kotlin": 47151} | package com.briarshore.aoc2022.day03
import println
import readInput
import kotlin.streams.asSequence
fun main() {
val lowerRange = IntRange('a'.code, 'z'.code) // 97 - 122 -> 1 - 26 = c - 96
val upperRange = IntRange('A'.code, 'Z'.code) // 65 - 90 -> 27 - 52 = c - 38
fun translateToPriority(item: Int)... | 0 | Kotlin | 0 | 0 | a0d19d38dae3e0a24bb163f5f98a6a31caae6c05 | 2,335 | 2022-AoC-Kotlin | Apache License 2.0 |
src/Day02.kt | sushovan86 | 573,586,806 | false | {"Kotlin": 47064} | interface CalculateScore {
fun moveScore(): Int
fun outcome(): Int
fun totalScore(): Int = moveScore() + outcome()
}
data class Round(
val opponentMove: String,
val selfMove: String
)
class Strategy1Score(private val round: Round) : CalculateScore {
override fun moveScore(): Int = when (round.... | 0 | Kotlin | 0 | 0 | d5f85b6a48e3505d06b4ae1027e734e66b324964 | 1,975 | aoc-2022 | Apache License 2.0 |
app/src/main/kotlin/codes/jakob/aoc/solution/Day04.kt | loehnertz | 725,944,961 | false | {"Kotlin": 59236} | package codes.jakob.aoc.solution
import codes.jakob.aoc.shared.splitByLines
object Day04 : Solution() {
private val numbersPattern = Regex("\\b\\d{1,2}\\b")
override fun solvePart1(input: String): Any {
return parseScratchCards(input)
.map { card ->
card.matchingNumbers.fo... | 0 | Kotlin | 0 | 0 | 6f2bd7bdfc9719fda6432dd172bc53dce049730a | 2,289 | advent-of-code-2023 | MIT License |
src/jvmMain/kotlin/day04/initial/Day04.kt | liusbl | 726,218,737 | false | {"Kotlin": 109684} | package day04.initial
import java.io.File
fun main() {
// solvePart1() // Solution: 21138, time: 07:09
solvePart2() // Solution: 7185540, time: 08:21
}
fun solvePart2() {
// val input = File("src/jvmMain/kotlin/day04/input/input_part1_test.txt")
val input = File("src/jvmMain/kotlin/day04/input/input.tx... | 0 | Kotlin | 0 | 0 | 1a89bcc77ddf9bc503cf2f25fbf9da59494a61e1 | 2,698 | advent-of-code | MIT License |
src/main/kotlin/_2022/Day13.kt | novikmisha | 572,840,526 | false | {"Kotlin": 145780} | package _2022
import readGroupedInput
import kotlin.math.max
fun main() {
fun parseListFromString(str: String): List<Any> {
val trimmedStr = str.removePrefix("[")
.removeSuffix("]")
.trim()
val resultList = mutableListOf<Any>()
var elementStartPosition = 0
... | 0 | Kotlin | 0 | 0 | 0c78596d46f3a8bf977bf356019ea9940ee04c88 | 3,705 | advent-of-code | Apache License 2.0 |
codeforces/vk2021/qual/e3_slow.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.vk2021.qual
import kotlin.math.log2
import kotlin.math.roundToInt
private fun permutation(comparisons: List<Boolean>, n: Int): Pair<Int, List<Int>> {
var pos = 0
fun permutation(m: Int): List<Int> {
if (m <= 1) return List(m) { 0 }
val left = m / 2
val right = m - left
val permutationLeft... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,746 | competitions | The Unlicense |
src/Day03.kt | cypressious | 572,916,585 | false | {"Kotlin": 40281} | fun main() {
fun bitSums(input: List<String>): IntArray {
val sums = IntArray(input[0].length)
for (s in input) {
for ((index, c) in s.withIndex()) {
if (c == '1') {
sums[index]++
}
}
}
return sums
}
... | 0 | Kotlin | 0 | 0 | 169fb9307a34b56c39578e3ee2cca038802bc046 | 1,908 | AdventOfCode2021 | Apache License 2.0 |
advent-of-code-2021/src/main/kotlin/eu/janvdb/aoc2021/day14/Day14.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2021.day14
import eu.janvdb.aocutil.kotlin.readGroupedLines
const val FILENAME = "input14.txt"
const val NUMBER_OF_STEPS = 40
fun main() {
val lines = readGroupedLines(2021, FILENAME)
val template = PolymerizationTemplate.parse(lines[0][0])
template.printValues()
val rules = lines[1].map(I... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,774 | advent-of-code | Apache License 2.0 |
src/Day08.kt | hoppjan | 433,705,171 | false | {"Kotlin": 29015, "Shell": 338} | fun main() {
fun part1(input: List<SevenSegmentDisplayPuzzle>) =
input.sumOf { puzzle ->
puzzle.output.filter { display ->
display.isOne() || display.isFour() || display.isSeven() || display.isEight()
}.size
}
fun part2(input: List<SevenSegmentDisplayPuz... | 0 | Kotlin | 0 | 0 | 04f10e8add373884083af2a6de91e9776f9f17b8 | 2,582 | advent-of-code-2021 | Apache License 2.0 |
advent-of-code-2022/src/main/kotlin/eu/janvdb/aoc2022/day03/Day03.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2022.day03
import eu.janvdb.aocutil.kotlin.assertTrue
import eu.janvdb.aocutil.kotlin.readLines
//const val FILENAME = "input03-test.txt"
const val FILENAME = "input03.txt"
fun main() {
val priorityLists = readLines(2022, FILENAME)
.map(::toPriorities)
.toList()
part1(priorityLists)
part... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,396 | advent-of-code | Apache License 2.0 |
src/Day08.kt | nordberg | 573,769,081 | false | {"Kotlin": 47470} | fun main() {
data class Tree(val x: Int, val y: Int)
fun findVisibleTreesInRow(treeRow: List<Int>): Set<Int> {
val visibleTrees = mutableSetOf(0, treeRow.indices.max())
var highestSoFar = Int.MIN_VALUE
treeRow.forEachIndexed { index, height ->
if (height > highestSoFar) {
... | 0 | Kotlin | 0 | 0 | 3de1e2b0d54dcf34a35279ba47d848319e99ab6b | 3,822 | aoc-2022 | Apache License 2.0 |
src/Day05.kt | tomoki1207 | 572,815,543 | false | {"Kotlin": 28654} | data class Operation(val move: Int, val from: Int, val to: Int)
fun main() {
fun buildStacks(input: List<String>, stackCount: Int): List<ArrayDeque<Char>> {
return input.map { line ->
(1..stackCount).map { stackNo ->
line.getOrElse(1 + (stackNo - 1) * 4) { ' ' }
}
... | 0 | Kotlin | 0 | 0 | 2ecd45f48d9d2504874f7ff40d7c21975bc074ec | 2,434 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day15.kt | dakr0013 | 572,861,855 | false | {"Kotlin": 105418} | import java.awt.Point
import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.min
import kotlin.test.assertEquals
fun main() {
fun part1(input: List<String>, testRow: Int = 2_000_000): Int {
val sensors = parseSensors(input)
val beaconCountInTestRow = sensors.map { it.closestBeacon }.toS... | 0 | Kotlin | 0 | 0 | 6b3adb09f10f10baae36284ac19c29896d9993d9 | 3,845 | aoc2022 | Apache License 2.0 |
src/day12/Day12.kt | molundb | 573,623,136 | false | {"Kotlin": 26868} | package day12
import readInput
// Copied from online https://github.com/zanmagerl/advent-of-code/blob/master/2022/src/twentytwo/days/Day12.kt
fun main() {
val input = readInput(parent = "src/day12", name = "Day12_input").map {
it.toCharArray().toList()
}
println(partOne(input))
println(part... | 0 | Kotlin | 0 | 0 | a4b279bf4190f028fe6bea395caadfbd571288d5 | 2,936 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/briarshore/aoc2022/day13/DistressSignalPuzzle.kt | steveswing | 579,243,154 | false | {"Kotlin": 47151} | package com.briarshore.aoc2022.day13
import kotlinx.serialization.json.*
import println
import kotlin.math.max
import readInput
fun <L, R> List<L>.zipWithPadding(that: List<R>): List<Pair<L?, R?>> =
buildList { for (i in 0 until max(this@zipWithPadding.size, that.size)) add(this@zipWithPadding.getOrNull(i) to tha... | 0 | Kotlin | 0 | 0 | a0d19d38dae3e0a24bb163f5f98a6a31caae6c05 | 3,030 | 2022-AoC-Kotlin | Apache License 2.0 |
src/day8/day8.kt | bienenjakob | 573,125,960 | false | {"Kotlin": 53763} | package day8
import inputTextOfDay
import testTextOfDay
val heights = mutableListOf<MutableList<Int>>()
val visibility = mutableListOf<MutableList<Boolean>>()
val scenicScore = mutableListOf<MutableList<Int>>()
fun parseInput(text: String) {
heights.clear()
visibility.clear()
scenicScore.clear()
tex... | 0 | Kotlin | 0 | 0 | 6ff34edab6f7b4b0630fb2760120725bed725daa | 2,883 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/day09.kt | tobiasae | 434,034,540 | false | {"Kotlin": 72901} | class Day09 : Solvable("09") {
override fun solveA(input: List<String>): String {
val grid = getGrid(input)
val lowPoints = getLowPoints(grid).map { grid[it.first][it.second] }
return (lowPoints.size + lowPoints.sum()).toString()
}
override fun solveB(input: List<String>): String... | 0 | Kotlin | 0 | 0 | 16233aa7c4820db072f35e7b08213d0bd3a5be69 | 2,403 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/day07/Day07.kt | taer | 573,051,280 | false | {"Kotlin": 26121} | package day07
import readInput
sealed class FS(){
class Directory(val name: String, val parent: Directory?, val children: MutableList<FS> = mutableListOf()): FS(){
override fun toString(): String {
return "dir: $name"
}
}
class File(val name: String, val size: Int): FS(){
... | 0 | Kotlin | 0 | 0 | 1bd19df8949d4a56b881af28af21a2b35d800b22 | 2,990 | aoc2022 | Apache License 2.0 |
gcj/y2020/round1a/c.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2020.round1a
private fun solve(): Long {
val (hei, wid) = readInts()
val a = List(hei) { readInts().toMutableList() }
val nei = List(DX.size) { d -> List(hei) { x -> MutableList(wid) { y ->
val xx = x + DX[d]; val yy = y + DY[d]
a.getOrNull(xx)?.getOrNull(yy)?.let { xx to yy }
} } }
var ans = 0L
... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,297 | competitions | The Unlicense |
src/Day08.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | fun main() {
fun part1(input: List<List<Int>>): Int {
return input.indices.sumOf { y ->
input[y].indices.count { x ->
input.isVisible(x, y)
}
}
}
fun part2(input: List<List<Int>>): Int {
return input.indices.maxOf { y ->
input[y].i... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 2,233 | aoc22-kotlin | Apache License 2.0 |
src/main/kotlin/apoy2k/aoc2023/problem2/Problem2.kt | ApoY2k | 725,965,251 | false | {"Kotlin": 2769} | package apoy2k.aoc2023.problem2
import apoy2k.aoc2023.readInput
import java.util.regex.Pattern
import kotlin.math.max
fun main() {
val games = readInput("problem2.txt")
val part1 = part1(games)
val part2 = part2(games)
println("Part 1: $part1")
println("Part 2: $part2")
}
private fun part1(games:... | 0 | Kotlin | 0 | 0 | 4d428feac36813acb8541b69d6fb821669714882 | 1,615 | aoc2023 | The Unlicense |
src/Day09.kt | juliantoledo | 570,579,626 | false | {"Kotlin": 34375} | import kotlin.math.abs
fun main() {
data class Point(var x: Int, var y: Int)
fun printMatrix(points: Set<Point>) {
val maxX = points.maxBy{point -> point.x}
val minX = points.minBy{point -> point.x}
val maxY = points.maxBy{point -> point.y}
val minY = points.minBy{point -> poin... | 0 | Kotlin | 0 | 0 | 0b9af1c79b4ef14c64e9a949508af53358335f43 | 2,404 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day02.kt | hrach | 572,585,537 | false | {"Kotlin": 32838} | enum class G(val score: Int) {
Rock(1),
Paper(2),
Scissor(3),
}
fun main() {
fun points(b: G, a: G): Int {
return when {
a == b -> 3
(a == G.Rock && b == G.Scissor) || (a == G.Paper && b == G.Rock) || (a == G.Scissor && b == G.Paper) -> 6
else -> 0
}
}
fun part1(input: List<String>): Int {
return... | 0 | Kotlin | 0 | 1 | 40b341a527060c23ff44ebfe9a7e5443f76eadf3 | 1,374 | aoc-2022 | Apache License 2.0 |
src/Day09.kt | ricardorlg-yml | 573,098,872 | false | {"Kotlin": 38331} | import kotlin.math.abs
import kotlin.math.sign
class Day09Solver(input: List<String>) {
data class Knot(val isTail: Boolean, var knotX: Int = 0, var knotY: Int = 0) {
infix fun moveTo(direction: String) {
when (direction) {
"U" -> knotY -= 1
"D" -> knotY += 1
... | 0 | Kotlin | 0 | 0 | d7cd903485f41fe8c7023c015e4e606af9e10315 | 2,179 | advent_code_2022 | Apache License 2.0 |
src/main/kotlin/mkuhn/aoc/Day15.kt | mtkuhn | 572,236,871 | false | {"Kotlin": 53161} | package mkuhn.aoc
import mkuhn.aoc.util.Point
import mkuhn.aoc.util.overlaps
import mkuhn.aoc.util.readInput
import kotlin.math.abs
fun main() {
val input = readInput("Day15")
println(day15part1(input, 2000000))
println(day15part2(input, 0..4000000, 0..4000000))
}
fun day15part1(input: List<String>, yToC... | 0 | Kotlin | 0 | 1 | 89138e33bb269f8e0ef99a4be2c029065b69bc5c | 3,175 | advent-of-code-2022 | Apache License 2.0 |
src/Day08.kt | jordan-thirus | 573,476,470 | false | {"Kotlin": 41711} | fun main() {
fun parseTrees(input: List<String>): List<List<Tree>> {
return input.map { row ->
row.map { tree ->
Tree(tree.digitToInt())
}
}
}
fun isTreeVisibleFromDirection(trees: List<List<Tree>>, rangeX: IntProgression, rangeY: IntProgression) {
... | 0 | Kotlin | 0 | 0 | 59b0054fe4d3a9aecb1c9ccebd7d5daa7a98362e | 4,885 | advent-of-code-2022 | Apache License 2.0 |
src/day15/Day15.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day15
import readInput
import java.awt.Point
import kotlin.math.abs
fun main() {
data class SensorBeacon(
val sensor: Point,
val beacon: Point,
val manhattanDistance: Int
)
fun parseInput(input: List<String>): List<SensorBeacon> {
val sensorBeacons = mutableListOf... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 2,936 | aoc-2022-kotlin | Apache License 2.0 |
src/Day03.kt | afranken | 572,923,112 | false | {"Kotlin": 15538} | fun main() {
/**
* Lower case letters start at 97. a -> 1, so a -> ASCII-code - 96 since values start at 1
* Upper case letter start at 65. A -> 65, so A -> ASCII-code - 38 since values start at 28
* https://www.ascii-code.com/
*/
fun codeFromChar(it: Char) = if (it.isUpperCase()) it.code - ... | 0 | Kotlin | 0 | 0 | f047d34dc2a22286134dc4705b5a7c2558bad9e7 | 1,907 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/advent/day9/SmokeBasin.kt | hofiisek | 434,171,205 | false | {"Kotlin": 51627} | package advent.day9
import advent.*
import java.io.File
data class Point(val height: Int, val position: Position)
/**
* Just calculate the risk level for all points that are lower than all of their adjacent point
*/
fun part1(input: File) = loadHeightmap(input)
.let { heightmap ->
heightmap.flatten()
... | 0 | Kotlin | 0 | 2 | 3bd543ea98646ddb689dcd52ec5ffd8ed926cbbb | 3,289 | Advent-of-code-2021 | MIT License |
src/Day04.kt | fonglh | 573,269,990 | false | {"Kotlin": 48950, "Ruby": 1701} | fun main() {
fun fullyContains(firstElf: List<Int>, secondElf: List<Int>): Boolean {
val min1 = firstElf[0]
val max1 = firstElf[1]
val min2 = secondElf[0]
val max2 = secondElf[1]
return (min1 <= min2 && max1 >= max2) ||
(min2 <= min1 && max2 >= max1)
}
... | 0 | Kotlin | 0 | 0 | ef41300d53c604fcd0f4d4c1783cc16916ef879b | 2,153 | advent-of-code-2022 | Apache License 2.0 |
src/problems/day8/part2/part2.kt | klnusbaum | 733,782,662 | false | {"Kotlin": 43060} | package problems.day8.part2
import java.io.File
//private const val test3 = "input/day8/test3.txt"
private const val inputFile = "input/day8/input.txt"
fun main() {
val stepsCount = File(inputFile).bufferedReader().useLines { numSteps(it) }
println("Number of steps $stepsCount")
}
private fun numSteps(lines... | 0 | Kotlin | 0 | 0 | d30db2441acfc5b12b52b4d56f6dee9247a6f3ed | 3,221 | aoc2023 | MIT License |
src/main/kotlin/day15/Day15.kt | daniilsjb | 434,765,082 | false | {"Kotlin": 77544} | package day15
import java.io.File
import java.util.*
fun main() {
val data = parse("src/main/kotlin/day15/Day15.txt")
val answer1 = part1(data)
val answer2 = part2(data)
println("🎄 Day 15 🎄")
println()
println("[Part 1]")
println("Answer: $answer1")
println()
println("[Part... | 0 | Kotlin | 0 | 1 | bcdd709899fd04ec09f5c96c4b9b197364758aea | 2,560 | advent-of-code-2021 | MIT License |
src/main/kotlin/com/ginsberg/advent2022/Day12.kt | tginsberg | 568,158,721 | false | {"Kotlin": 113322} | /*
* Copyright (c) 2022 by <NAME>
*/
/**
* Advent of Code 2022, Day 12 - Hill Climbing Algorithm
* Problem Description: http://adventofcode.com/2022/day/12
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2022/day12/
*/
package com.ginsberg.advent2022
import java.util.PriorityQueue
class D... | 0 | Kotlin | 2 | 26 | 2cd87bdb95b431e2c358ffaac65b472ab756515e | 2,638 | advent-2022-kotlin | Apache License 2.0 |
aoc-2023/src/main/kotlin/nerok/aoc/aoc2023/day02/Day02.kt | nerok | 572,862,875 | false | {"Kotlin": 113337} | package nerok.aoc.aoc2023.day02
import nerok.aoc.utils.Input
import kotlin.time.DurationUnit
import kotlin.time.measureTime
data class RGB(
val red: Long,
val green: Long,
val blue: Long
) {
fun mergeMax(other: RGB): RGB {
return RGB(
red = maxOf(this.red, other.red),
g... | 0 | Kotlin | 0 | 0 | 7553c28ac9053a70706c6af98b954fbdda6fb5d2 | 2,564 | AOC | Apache License 2.0 |
2021/src/main/kotlin/day8_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.cut
import utils.mapItems
fun main() {
Day8Func.run()
}
object Day8Func : Solution<List<Day8Func.Key>>() {
override val name = "day8"
override val parser = Parser.lines.mapItems {
it.cut("|") { input, output -> Key(input.split(' '), output.split(' ')) }... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,842 | aoc_kotlin | MIT License |
src/main/de/ddkfm/Day5.kt | DDKFM | 433,861,159 | false | {"Kotlin": 13522} | package de.ddkfm
import kotlin.math.*
data class Point(
val x : Int,
val y : Int
)
data class Line(
val p1 : Point,
val p2 : Point
) {
val directionVektor = Point(p2.x - p1.x, p2.y - p1.y)
val unitVektor = Point(directionVektor.x.divideOr0(directionVektor.x.absoluteValue), directionVektor.y.di... | 0 | Kotlin | 0 | 0 | 6e147b526414ab5d11732dc32c18ad760f97ff59 | 2,784 | AdventOfCode21 | MIT License |
src/Day03.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | fun main() {
fun itemPriority(itemType: Char): Int = when (itemType) {
in 'a'..'z' -> (itemType - 'a') + 1
in 'A'..'Z' -> (itemType - 'A') + 27
else -> error("Unexpected item type '$itemType'")
}
fun findCommonItems(left: String, right: String): String {
val commonItems = l... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 1,675 | aoc2022 | Apache License 2.0 |
facebook/y2020/round1/a2.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package facebook.y2020.round1
import java.util.*
private fun solve(M: Int = 1_000_000_007): Int {
val (n, k) = readInts()
val (L, w, h) = List(3) { readInts().toMutableList().also { list ->
val (a, b, c, d) = readInts()
for (i in k until n) {
list.add(((a.toLong() * list[i - 2] + b.toLong() * list[i - 1] + c... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,439 | competitions | The Unlicense |
src/main/kotlin/biz/koziolek/adventofcode/year2021/day08/day8.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2021.day08
import biz.koziolek.adventofcode.findInput
fun main() {
val inputFile = findInput(object {})
val lines = inputFile.bufferedReader().readLines()
println("There are ${countEasyDigitsInOutput(lines)} digits 1,4,7,8 in output")
val notes = parseNotes(line... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 3,362 | advent-of-code | MIT License |
src/main/kotlin/com/github/wakingrufus/aoc/Day6.kt | wakingrufus | 159,674,364 | false | null | package com.github.wakingrufus.aoc
import kotlin.math.absoluteValue
data class Coordinate(val x: Int, val y: Int) {
fun manhattanDistance(other: Coordinate): Int =
(this.x - other.x).absoluteValue + (this.y - other.y).absoluteValue
}
class Day6 {
fun part1(input: List<String>): Int {
retu... | 0 | Kotlin | 0 | 0 | bdf846cb0e4d53bd8beda6fdb3e07bfce59d21ea | 2,331 | advent-of-code-2018 | MIT License |
day-14/src/main/kotlin/ExtendedPolymerization.kt | diogomr | 433,940,168 | false | {"Kotlin": 92651} | fun main() {
println("Part One Solution: ${partOne()}")
println("Part Two Solution: ${partTwo()}")
println("Part Two Solution Non Recursive: ${partTwoNonRecursive()}")
}
private fun partOne(): Int {
var template = readInputLines()[0].toCharArray().toList()
val rules = readRules()
for (step in ... | 0 | Kotlin | 0 | 0 | 17af21b269739e04480cc2595f706254bc455008 | 4,270 | aoc-2021 | MIT License |
src/main/day21/day21.kt | rolf-rosenbaum | 572,864,107 | false | {"Kotlin": 80772} | package day21
import readInput
fun main() {
val input = readInput("main/day21/Day21")
println(part1(input))
println(part2(input))
}
fun part1(input: List<String>): Long {
val monkeys = input.map { it.toMonkey() }.associateBy { it.name }
return solvePart1(monkeys.toMutableMap(), monkeys["root"]!!... | 0 | Kotlin | 0 | 2 | 59cd4265646e1a011d2a1b744c7b8b2afe482265 | 3,006 | aoc-2022 | Apache License 2.0 |
src/day12/Day12.kt | ayukatawago | 572,742,437 | false | {"Kotlin": 58880} | package day12
import readInput
fun main() {
val testInput = readInput("day12/test")
val elevationMap = testInput.map { it.map { c -> c.toElevation() } }
val startRow = testInput.indexOfFirst { it.contains('S') }
val startColumn = testInput[startRow].indexOfFirst { it == 'S' }
val endRow = testInpu... | 0 | Kotlin | 0 | 0 | 923f08f3de3cdd7baae3cb19b5e9cf3e46745b51 | 3,469 | advent-of-code-2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.