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/Day04.kt | chasebleyl | 573,058,526 | false | {"Kotlin": 15274} |
// Formatted "N-N", where input is string and N represents an Integer
fun String.toAssignment() = this.split("-").let { splitSections ->
Assignment(splitSections[0].toInt(), splitSections[1].toInt())
}
data class Assignment(
val lowerSection: Int,
val upperSection: Int,
) {
fun encapsulates(assignment... | 0 | Kotlin | 0 | 1 | f2f5cb5fd50fb3e7fb9deeab2ae637d2e3605ea3 | 2,162 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | b0n541 | 571,797,079 | false | {"Kotlin": 17810} | fun main() {
fun parsePlayerGesture(move: String) = when (move) {
"A", "X" -> Move.ROCK
"B", "Y" -> Move.PAPER
"C", "Z" -> Move.SCISSORS
else -> error("Unknown gesture $move")
}
fun findMoveFollowingStrategy(strategy: String, firstPlayerMove: Move) = when (strategy) {
... | 0 | Kotlin | 0 | 0 | d451f1aee157fd4d47958dab8a0928a45beb10cf | 2,620 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | Olivki | 573,156,936 | false | {"Kotlin": 11297} | import RoundResult.DRAW
import RoundResult.LOSS
import RoundResult.WIN
import RpsShape.PAPER
import RpsShape.ROCK
import RpsShape.SCISSORS
fun main() {
val opponentShapeMap = mapOf("A" to ROCK, "B" to PAPER, "C" to SCISSORS)
val desiredShapeMap = mapOf("X" to ROCK, "Y" to PAPER, "Z" to SCISSORS)
val desire... | 0 | Kotlin | 0 | 1 | 51c408f62589eada3d8454740c9f6fc378e2d09b | 2,298 | aoc-2022 | Apache License 2.0 |
src/Day10.kt | thpz2210 | 575,577,457 | false | {"Kotlin": 50995} | private class Solution10(input: List<String>) {
val states = input.fold(mutableListOf(1)) { acc, command -> executeCommand(command, acc) }
private fun executeCommand(command: String, acc: MutableList<Int>): MutableList<Int> {
val split = command.split(" ")
acc.addAll(
when (split[0... | 0 | Kotlin | 0 | 0 | 69ed62889ed90692de2f40b42634b74245398633 | 1,556 | aoc-2022 | Apache License 2.0 |
src/nativeMain/kotlin/xyz/justinhorton/aoc2022/Day11.kt | justinhorton | 573,614,839 | false | {"Kotlin": 39759, "Shell": 611} | package xyz.justinhorton.aoc2022
/**
* https://adventofcode.com/2022/day/11
*/
class Day11(override val input: String) : Day() {
override fun part1(): String {
val monkeys = parseMonkeyInput()
return calcMonkeyBizLevel(monkeys, 20) { it / 3 }.toString()
}
override fun part2(): String {
... | 0 | Kotlin | 0 | 1 | bf5dd4b7df78d7357291c7ed8b90d1721de89e59 | 3,823 | adventofcode2022 | MIT License |
src/main/kotlin/days/aoc2021/Day8.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2021
import days.Day
class Day8 : Day(2021, 8) {
override fun partOne(): Any {
return calculateFrequencyOfCertainOutputs(inputList)
}
override fun partTwo(): Any {
return calculateOutputValueSum(inputList)
}
fun calculateFrequencyOfCertainOutputs(inputLines: List<... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 2,544 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/Day15.kt | jvmusin | 572,685,421 | false | {"Kotlin": 86453} | import kotlin.math.abs
fun main() {
data class Position(val x: Int, val y: Int) {
fun distance(p: Position) = abs(x - p.x) + abs(y - p.y)
}
data class SensorBeacon(val sensor: Position, val beacon: Position) {
fun distance() = sensor.distance(beacon)
}
fun parse(input: List<String... | 1 | Kotlin | 0 | 0 | 4dd83724103617aa0e77eb145744bc3e8c988959 | 3,147 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | bigtlb | 573,081,626 | false | {"Kotlin": 38940} | fun main() {
fun score(round: String, strategy: Int = 1): Int {
var score = 0
var (them, you) = round.uppercase().toCharArray().filterNot { it == ' ' }
//For strategy 2, choos what you throw by seeing if you should win, lose, or draw
if (strategy == 2){
you = when (you){... | 0 | Kotlin | 0 | 0 | d8f76d3c75a30ae00c563c997ed2fb54827ea94a | 1,653 | aoc-2022-demo | Apache License 2.0 |
src/main/kotlin/com/colinodell/advent2023/Day07.kt | colinodell | 726,073,391 | false | {"Kotlin": 114923} | package com.colinodell.advent2023
class Day07(private val input: List<String>) {
class Hand(private val cards: List<Char>, val bid: Int, private val joker: Char) : Comparable<Hand> {
// Number of jokers in this hand
private val jokerCount = cards.count { it == joker }
// The strength of th... | 0 | Kotlin | 0 | 0 | 97e36330a24b30ef750b16f3887d30c92f3a0e83 | 2,819 | advent-2023 | MIT License |
src/Day07.kt | wooodenleg | 572,658,318 | false | {"Kotlin": 30668} | sealed interface SystemItem {
val name: String
val size: Int
}
data class Directory(
override val name: String,
val parent: Directory?,
) : SystemItem {
override val size: Int get() = contents.sumOf(SystemItem::size)
val contents: MutableList<SystemItem> = mutableListOf()
val nestedContent... | 0 | Kotlin | 0 | 1 | ff1f3198f42d1880e067e97f884c66c515c8eb87 | 2,893 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/hopkins/aoc/day7/main.kt | edenrox | 726,934,488 | false | {"Kotlin": 88215} | package com.hopkins.aoc.day7
import java.io.File
const val debug = true
const val part = 2
val defaultCardOrder: List<String> =
listOf("A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2", "1")
val allCards =
if (part == 1) {
defaultCardOrder
} else {
// In part 2, "J" is a jo... | 0 | Kotlin | 0 | 0 | 45dce3d76bf3bf140d7336c4767e74971e827c35 | 3,667 | aoc2023 | MIT License |
y2018/src/main/kotlin/adventofcode/y2018/Day16.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2018
import adventofcode.io.AdventSolution
import adventofcode.language.elfcode.*
object Day16 : AdventSolution(2018, 16, "Chronal Classification") {
override fun solvePartOne(input: String) =
parse(input).first.count { example ->
allOperations.count { operation ... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 3,680 | advent-of-code | MIT License |
src/main/kotlin/me/shutkin/assur/samples/Grouping.kt | shutkin | 135,262,745 | false | {"Kotlin": 58266} | package me.shutkin.assur.samples
import me.shutkin.assur.HistogramData
import me.shutkin.assur.getHistogramMedianValue
import me.shutkin.assur.logger.assurLog
fun grouping(samples: List<DoubleArray>, groupsNumber: Int, diffFunction: (DoubleArray, DoubleArray) -> Double = ::evalArraysDiff): List<Reference> {
val ave... | 0 | Kotlin | 0 | 0 | c867705ff97ca18ea1f26f1f69b085711d0a9bd1 | 2,938 | assur | Apache License 2.0 |
src/day12/day12.kt | Eynnzerr | 576,874,345 | false | {"Kotlin": 23356} | package day12
import java.io.File
import kotlin.math.min
val matrix = readAsMatrix("src/day12/input.txt")
val start = locate('S', matrix)
val end = locate('E', matrix)
val visited = Array(matrix.size) { BooleanArray(matrix[0].size) { false } }
var result = Int.MAX_VALUE
var steps = 0
fun main() {
// Obviously a... | 0 | Kotlin | 0 | 0 | 92e85d65f62900d98284cbc9f6f9a3010efb21b7 | 2,020 | advent-of-code-2022 | Apache License 2.0 |
2020/src/year2021/day09/code.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2021.day09
import util.readAllLines
data class Cell(val row: Int, val col: Int)
fun main() {
part1()
part2()
}
private fun part1() {
val grid = readGrid("input.txt")
val lows = findLows(grid).sumOf { grid[it.row][it.col] + 1 }
println(lows)
}
private fun part2() {
val grid = rea... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 2,951 | adventofcode | MIT License |
2k23/aoc2k23/src/main/kotlin/02.kt | papey | 225,420,936 | false | {"Rust": 88237, "Kotlin": 63321, "Elixir": 54197, "Crystal": 47654, "Go": 44755, "Ruby": 24620, "Python": 23868, "TypeScript": 5612, "Scheme": 117} | package d02
import input.read
import java.util.*
fun main() {
println("Part 1: ${part1(read("02.txt"))}")
println("Part 2: ${part2(read("02.txt"))}")
}
class Game(input: String) {
enum class Color {
BLUE, RED, GREEN
}
private val id: Int
private var rounds: List<Map<Color, Int>>
... | 0 | Rust | 0 | 3 | cb0ea2fc043ebef75aff6795bf6ce8a350a21aa5 | 2,336 | aoc | The Unlicense |
src/Day13.kt | thpz2210 | 575,577,457 | false | {"Kotlin": 50995} | import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ArrayNode
import com.fasterxml.jackson.databind.node.IntNode
import com.fasterxml.jackson.databind.node.JsonNodeFactory
import java.lang.Integer.max
private class Solution13(inpu... | 0 | Kotlin | 0 | 0 | 69ed62889ed90692de2f40b42634b74245398633 | 3,294 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/days/Day08.kt | julia-kim | 569,976,303 | false | null | package days
import readInput
fun main() {
fun createTreeGrid(input: List<String>) = input.map {
it.map(Character::getNumericValue).toIntArray()
}.toTypedArray()
fun part1(input: List<String>): Int {
val array = createTreeGrid(input)
val cols = input[0].length
val rows = i... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 2,582 | advent-of-code-2022 | Apache License 2.0 |
src/main/java/com/ncorti/aoc2021/Exercise14.kt | cortinico | 433,486,684 | false | {"Kotlin": 36975} | package com.ncorti.aoc2021
object Exercise14 {
private fun getInput(): Pair<Map<String, Char>, MutableMap<String, Long>> {
val input = getInputAsTest("14") { split("\n") }
val rules =
input.drop(2).map { it.split(" -> ") }.associate { (key, value) ->
key to value.toChar... | 0 | Kotlin | 0 | 4 | af3df72d31b74857201c85f923a96f563c450996 | 1,962 | adventofcode-2021 | MIT License |
src/main/kotlin/Day08.kt | todynskyi | 573,152,718 | false | {"Kotlin": 47697} | fun main() {
fun part1(input: List<String>): Int {
val data: List<List<Int>> = input.map { line ->
line.toCharArray().map { it.toString().toInt() }
}
fun top(rowIndex: Int, colIndex: Int): Boolean {
return (0 until rowIndex).map { data[it][colIndex] }.all { data[row... | 0 | Kotlin | 0 | 0 | 5f9d9037544e0ac4d5f900f57458cc4155488f2a | 3,932 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/year_2022/day_08/Day08.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2022.day_08
import readInput
object Day08 {
/**
* @return
*/
fun solutionOne(text: List<String>): Int {
val forest = parseForest(text)
var visibleCount = text.first().length * 2 + (text.size - 2) * 2
for (i in 1..forest.first().size -2 ) {
for (j in ... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 3,142 | advent_of_code | Apache License 2.0 |
src/com/mrxyx/algorithm/UnionFindAlg.kt | Mrxyx | 366,778,189 | false | null | package com.mrxyx.algorithm
/**
* 并查集 算法
*/
class UnionFindAlg {
/**
* 并查集查询算法
*/
internal class UF(private var count: Int) {
// 存储若干棵树
private val parent = IntArray(count)
// 记录树的“重量”
private val size = IntArray(count)
/**
* 将 p 和 q 连通
... | 0 | Kotlin | 0 | 0 | b81b357440e3458bd065017d17d6f69320b025bf | 2,590 | algorithm-test | The Unlicense |
src/main/kotlin/dev/bogwalk/batch4/Problem50.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch4
import dev.bogwalk.util.maths.isPrimeMRBI
import dev.bogwalk.util.maths.primeNumbers
import dev.bogwalk.util.search.binarySearch
/**
* Problem 50: Consecutive Prime Sum
*
* https://projecteuler.net/problem=50
*
* Goal: Return the smallest prime <= N that can be represented as the sum o... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 3,592 | project-euler-kotlin | MIT License |
Algorithms/src/main/kotlin/MinimumAreaRectangle.kt | ILIYANGERMANOV | 557,496,216 | false | {"Kotlin": 74485} | import kotlin.math.pow
import kotlin.math.sqrt
typealias Point = IntArray
/**
* # Minimum Area Rectangle
*
* _Note: Time Limit Exceeded (not optimal)_
*
* Problem:
* https://leetcode.com/problems/minimum-area-rectangle/
*/
class MinimumAreaRectangle {
fun minAreaRect(points: Array<Point>): Int {
v... | 0 | Kotlin | 0 | 1 | 4abe4b50b61c9d5fed252c40d361238de74e6f48 | 2,847 | algorithms | MIT License |
src/main/kotlin/aoc2023/Day18.kt | Ceridan | 725,711,266 | false | {"Kotlin": 110767, "Shell": 1955} | package aoc2023
class Day18 {
fun part1(input: List<String>): Long {
val instructions = parseInput(input).map { it.instruction }
return calculateInterior(instructions)
}
fun part2(input: List<String>): Long {
val instructions = parseInput(input).map { it.decodeColor() }
ret... | 0 | Kotlin | 0 | 0 | 18b97d650f4a90219bd6a81a8cf4d445d56ea9e8 | 3,122 | advent-of-code-2023 | MIT License |
2021/src/main/kotlin/day17_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
fun main() {
Day17Func.run()
}
object Day17Func : Solution<Day17Func.Rectangle>() {
override val name = "day17"
override val parser = Parser { input ->
val (xeq, yeq) = input.removePrefix("target area: ")
.split(", ")
val (xs, xe) = xeq.removePrefix("x=")... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,121 | aoc_kotlin | MIT License |
gcj/y2022/round2/c_small.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2022.round2
private fun solve(): String {
val n = readInt()
val kids = List(n) { readInts() }
val sweets = List(n + 1) { readInts() }
fun sqr(x: Int) = x.toLong() * x
fun dist(i: Int, j: Int) = sqr(kids[i][0] - sweets[j][0]) + sqr(kids[i][1] - sweets[j][1])
val dist = List(n) { i -> LongArray(n + 1)... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,886 | competitions | The Unlicense |
src/Day04.kt | riFaulkner | 576,298,647 | false | {"Kotlin": 9466} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { assignments ->
val assignmentPair = getAssignmentPair(assignments)
isFullyInclusivePair(assignmentPair)
}
}
fun part2(input: List<String>): Int {
return input.sumOf { assignments ->
... | 0 | Kotlin | 0 | 0 | 33ca7468e17c47079fe2e922a3b74fd0887e1b62 | 1,766 | aoc-kotlin-2022 | Apache License 2.0 |
src/aoc2022/day11/AoC11.kt | Saxintosh | 576,065,000 | false | {"Kotlin": 30013} | package aoc2022.day11
import readLines
var isDivisor = true
var allDivisor = 1L
class Monkey(
private val items: MutableList<Long>,
val op: (Long) -> Long,
val divisor: Long,
val test: (Long) -> Int,
) {
var inspection = 0L
fun round(monkeys: List<Monkey>) {
items.forEach { item ->
inspection++
var wl... | 0 | Kotlin | 0 | 0 | 877d58367018372502f03dcc97a26a6f831fc8d8 | 1,772 | aoc2022 | Apache License 2.0 |
src/main/kotlin/cc/stevenyin/leetcode/_0150_EvaluateReversePolishNotation.kt | StevenYinKop | 269,945,740 | false | {"Kotlin": 107894, "Java": 9565} | package cc.stevenyin.leetcode
import java.util.*
/**
* https://leetcode.com/problems/evaluate-reverse-polish-notation/
* You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation (http://en.wikipedia.org/wiki/Reverse_Polish_notation).
*
* Evaluate the expressio... | 0 | Kotlin | 0 | 1 | 748812d291e5c2df64c8620c96189403b19e12dd | 2,225 | kotlin-demo-code | MIT License |
aoc-2023/src/main/kotlin/nerok/aoc/aoc2023/day06/Day06.kt | nerok | 572,862,875 | false | {"Kotlin": 113337} | package nerok.aoc.aoc2023.day06
import nerok.aoc.utils.Input
import kotlin.time.DurationUnit
import kotlin.time.measureTime
fun main() {
fun distances(time: Long): List<Long> {
val returnList = emptyList<Long>().toMutableList()
for (i in 0..time) {
returnList.add((time-i) * i)
... | 0 | Kotlin | 0 | 0 | 7553c28ac9053a70706c6af98b954fbdda6fb5d2 | 1,742 | AOC | Apache License 2.0 |
y2017/src/main/kotlin/adventofcode/y2017/Day20.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2017
import adventofcode.io.AdventSolution
import kotlin.math.abs
fun main()
{
Day20.solve()
}
object Day20 : AdventSolution(2017, 20, "Particle Swarm")
{
//this comparator is not correct, but works for my input :S
override fun solvePartOne(input: String): Int
{
val par... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,614 | advent-of-code | MIT License |
2021/src/day19/Day19.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day19
import readInput
import java.lang.Math.abs
import java.util.*
import kotlin.math.pow
typealias BeaconPairList = List<Pair<Pair<Point, Point>, Pair<Point, Point>>>
data class Point(val x: Int, val y: Int, val z: Int) {
override fun toString() = "($x,$y,$z)"
// https://stackoverflow.com/questio... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 7,395 | advent-of-code | Apache License 2.0 |
src/Day07.kt | zhiqiyu | 573,221,845 | false | {"Kotlin": 20644} | import kotlin.math.min
class InputParser(var input: List<String>, var root: DirTree) {
var cursor: DirTree
init {
cursor = root
}
fun parse() {
for (line in input) {
if (line.startsWith('$')) {
// command
var commands = line.split(" ")
... | 0 | Kotlin | 0 | 0 | d3aa03b2ba2a8def927b94c2b7731663041ffd1d | 3,174 | aoc-2022 | Apache License 2.0 |
2022/src/test/kotlin/Day15.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.min
private data class Position15(val x: Int, val y: Int)
private data class Sensor(val position: Position15, val beacon: Position15) {
val distanceToBeacon: Int... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 2,309 | adventofcode | MIT License |
src/main/kotlin/aoc2023/Day11.kt | Ceridan | 725,711,266 | false | {"Kotlin": 110767, "Shell": 1955} | package aoc2023
import kotlin.math.abs
class Day11 {
fun part1(input: String): Long = calculateDistances(input, 2)
fun part2(input: String, expansionModifier: Int): Long = calculateDistances(input, expansionModifier)
private fun calculateDistances(input: String, expansionModifier: Int = 2): Long {
... | 0 | Kotlin | 0 | 0 | 18b97d650f4a90219bd6a81a8cf4d445d56ea9e8 | 1,834 | advent-of-code-2023 | MIT License |
src/Day03.kt | yalematta | 572,668,122 | false | {"Kotlin": 8442} |
fun main() {
fun findCommonItems(sacks: List<String>): Set<Char> {
return sacks
.map { it.toSet() }
.reduce { init, item -> init.intersect(item) }
}
fun getPriority(commonChars: Set<Char>): Int {
val items = ('a'..'z') + ('A'..'Z')
var priority = 0
... | 0 | Kotlin | 0 | 0 | 2b43681cc2bd02e4838b7ad1ba04ff73c0422a73 | 1,501 | advent-of-code-2022 | Apache License 2.0 |
src/Day07.kt | zodiia | 573,067,225 | false | {"Kotlin": 11268} | package day07
import readInput
enum class FsNodeType { FILE, DIR }
data class FsNode(
var size: Long,
val type: FsNodeType,
val childNodes: HashMap<String, FsNode> = HashMap(),
) {
fun getNode(path: ArrayDeque<String>): FsNode {
if (path.size == 0) {
return this
}
... | 0 | Kotlin | 0 | 1 | 4f978c50bb7603adb9ff8a2f0280f8fdbc652bf2 | 2,528 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/aoc2021/Day03.kt | j4velin | 572,870,735 | false | {"Kotlin": 285016, "Python": 1446} | package aoc2021
import readInput
import kotlin.math.ceil
/**
* Given a list of binary numbers, this method creates a binary number by selecting the most common bit at each position
* of the input numbers
*
* @param input a list of equally width binary numbers as string
* @return a string representation of the bi... | 0 | Kotlin | 0 | 0 | f67b4d11ef6a02cba5b206aba340df1e9631b42b | 2,782 | adventOfCode | Apache License 2.0 |
src/main/kotlin/problems/Day22.kt | PedroDiogo | 432,836,814 | false | {"Kotlin": 128203} | package problems
class Day22(override val input: String) : Problem {
override val number: Int = 22
private val inputRegex = """(on|off) x=(-?\d*)..(-?\d*),y=(-?\d*)..(-?\d*),z=(-?\d*)..(-?\d*)""".toRegex()
private val intervals = input.lines()
.map { inputRegex.find(it)!!.groupValues.drop(1) }
... | 0 | Kotlin | 0 | 0 | 93363faee195d5ef90344a4fb74646d2d26176de | 4,303 | AdventOfCode2021 | MIT License |
src/main/kotlin/_2019/Day3.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2019
import aocRun
import range
import kotlin.math.abs
fun main() {
aocRun(puzzleInput) { input ->
val wiresRaw = input.split("\n")
val wire1 = parseWire(wiresRaw[0])
val wire2 = parseWire(wiresRaw[1])
val intersections = intersections(wire1, wire2)
return@aocRun i... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 6,264 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Day13.kt | PascalHonegger | 573,052,507 | false | {"Kotlin": 66208} | import kotlin.math.max
private sealed interface Packet : Comparable<Packet>
private data class ListPacket(val children: List<Packet>) : Packet {
override fun toString() = "[${children.joinToString()}]"
override fun compareTo(other: Packet): Int {
return when (other) {
is ListPacket -> {
... | 0 | Kotlin | 0 | 0 | 2215ea22a87912012cf2b3e2da600a65b2ad55fc | 3,291 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | orirabi | 574,124,632 | false | {"Kotlin": 14153} |
val calc = mapOf(
Choice.ROCK to mapOf(
Choice.ROCK to Result.DRAW,
Choice.PAPER to Result.LOSS,
Choice.SCISSORS to Result.WIN,
),
Choice.PAPER to mapOf(
Choice.ROCK to Result.WIN,
Choice.PAPER to Result.DRAW,
Choice.SCISSORS to Result.LOSS,
),
Choice... | 0 | Kotlin | 0 | 0 | 41cb10eac3234ae77ed7f3c7a1f39c2f9d8c777a | 2,892 | AoC-2022 | Apache License 2.0 |
kotlin/08.kt | NeonMika | 433,743,141 | false | {"Kotlin": 68645} | class Day8 : Day<List<Day8.Input>>("08") {
data class Input(val segments: List<String>, val outputs: List<String>)
enum class SegmentNumber(val segments: String, val int: Int) {
ZERO("abcefg", 0),
ONE("cf", 1),
TWO("acdeg", 2),
THREE("acdfg", 3),
FOUR("bcdf", 4),
... | 0 | Kotlin | 0 | 0 | c625d684147395fc2b347f5bc82476668da98b31 | 3,001 | advent-of-code-2021 | MIT License |
src/Day09.kt | wooodenleg | 572,658,318 | false | {"Kotlin": 30668} | import kotlin.math.absoluteValue
val String.asDirection get() = Direction.values().first { it.name.first().toString() == this }
class Knot(
startOffset: IntOffset,
private val childKnot: Knot? = null
) {
private var location: IntOffset = startOffset
private val visitedPositions = mutableListOf(locatio... | 0 | Kotlin | 0 | 1 | ff1f3198f42d1880e067e97f884c66c515c8eb87 | 2,878 | advent-of-code-2022 | Apache License 2.0 |
src/Day07.kt | iartemiev | 573,038,071 | false | {"Kotlin": 21075} | class Node(val name: String, var size: Int = 0, val parent: Node? = null) {
val children: MutableList<Node> = mutableListOf()
}
fun cd(rootNode: Node, currentNode: Node, arg: String): Node {
val toAncestor = ".."
val toRoot = "/"
return when (arg) {
toRoot -> rootNode
toAncestor -> currentNode.parent ... | 0 | Kotlin | 0 | 0 | 8d2b7a974c2736903a9def65282be91fbb104ffd | 2,531 | advent-of-code | Apache License 2.0 |
src/main/kotlin/twenty/three/02.kt | itsabdelrahman | 726,503,458 | false | {"Kotlin": 8123} | package twenty.three
import java.io.File
fun main() {
val games = File("src/main/resources/twenty/three/02/1.txt")
.readLines()
.map(Game::from)
val output1 = games.filter {
it.isPossibleWith(
totalRed = 12,
totalGreen = 13,
totalBlue = 14,
... | 0 | Kotlin | 0 | 0 | 81765d658ca1dd77b5e5418167ee519460baa4a5 | 2,944 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/SmokeBasin_9.kt | Flame239 | 433,046,232 | false | {"Kotlin": 64209} | val cave: Array<IntArray> by lazy {
readFile("SmokeBasin").split("\n").map { it.map { it.digitToInt() }.toIntArray() }.toTypedArray()
}
fun findLowestPoints(): List<Pair<Int, Int>> {
val h = cave.size
val w = cave[0].size
val lowestPoints = mutableListOf<Pair<Int, Int>>()
for (i in 0 until h) {
... | 0 | Kotlin | 0 | 0 | ef4b05d39d70a204be2433d203e11c7ebed04cec | 2,978 | advent-of-code-2021 | Apache License 2.0 |
src/Day03.kt | maximilianproell | 574,109,359 | false | {"Kotlin": 17586} | fun main() {
fun part1(input: List<String>): Int {
return input.mapNotNull { items ->
val rucksack = Rucksack.createRucksack(items)
val sharedItem = rucksack.findDuplicateItem()
sharedItem?.priority
}.sum()
}
fun part2(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | 371cbfc18808b494ed41152256d667c54601d94d | 2,403 | kotlin-advent-of-code-2022 | Apache License 2.0 |
solutions/aockt/y2022/Y2022D12.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2022
import io.github.jadarma.aockt.core.Solution
import java.util.*
object Y2022D12 : Solution {
/** Parse the [input] and return the map and the coordinates of the start and end [Point]s. */
private fun parseInput(input: String): Triple<HeightMap, Point, Point> {
lateinit var start: ... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 4,451 | advent-of-code-kotlin-solutions | The Unlicense |
2015/src/main/kotlin/day21.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parse
import utils.Parser
import utils.Solution
import utils.selections
fun main() {
Day21.run()
}
object Day21 : Solution<Day21.Entity>() {
override val name = "day21"
override val parser = Parser { parseEntity(it) }
@Parse("Hit Points: {hp}\nDamage: {dmg}\nArmor: {armor}")
data class Entity(... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,458 | aoc_kotlin | MIT License |
src/Day05.kt | TrevorSStone | 573,205,379 | false | {"Kotlin": 9656} | fun main() {
fun createStacks(input: List<String>) =
input
.filter { it.contains('[') }
.fold(mutableListOf<ArrayDeque<Char>>()) { stacks, line ->
val blocks = line.windowed(3, 4)
if (stacks.isEmpty()) {
repeat(blocks.size) { stacks.add(ArrayDeque()) }
... | 0 | Kotlin | 0 | 0 | 2a48776f8bc10fe1d7e2bbef171bf65be9939400 | 1,836 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/y2016/Day24.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2016
import util.Pos
import util.neighborsManhattan
import util.readInput
import util.timingStatistics
object Day24 {
data class Ducts(
val start: Pos,
val targets: List<Pos>,
val passages: Set<Pos>
) {
fun distance(p1: Pos, p2: Pos): Int {
var steps = 0
... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 4,137 | advent-of-code | Apache License 2.0 |
advent-of-code/src/main/kotlin/DayFifteen.kt | pauliancu97 | 518,083,754 | false | {"Kotlin": 36950} | import kotlin.math.max
typealias Qualities = List<Int>
class DayFifteen {
private fun getQuantitiesHelper(
ingredients: List<Qualities>,
remainingQuantity: Int,
quantitiesPerIngredient: List<Int>,
evaluator: (List<Int>) -> Unit
) {
if (quantitiesPerIngredient.size == i... | 0 | Kotlin | 0 | 0 | 3ba05bc0d3e27d9cbfd99ca37ca0db0775bb72d6 | 2,868 | advent-of-code-2015 | MIT License |
src/Day07.kt | dustinlewis | 572,792,391 | false | {"Kotlin": 29162} | fun main() {
fun part1(input: List<String>): Int {
val maxDirectorySize = 100000
val root = parseDirectoryTree(input)
return root.dirs.filter { it.dirSize < maxDirectorySize }.sumOf { it.dirSize }
}
fun part2(input: List<String>): Int {
val maxSystemSize = 70000000
v... | 0 | Kotlin | 0 | 0 | c8d1c9f374c2013c49b449f41c7ee60c64ef6cff | 1,993 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/dr206/2022/Day04.kt | dr206 | 572,377,838 | false | {"Kotlin": 9200} | fun main() {
fun checkOverlapBasedOnPredicate(
pairOfIdRanges: String,
predicate: (Set<Int>, Set<Int>) -> Boolean
): Boolean {
val (idRange1, idRange2) = pairOfIdRanges.split(',')
val integers1 = idRange1.split('-').map { it.toInt() }
val range1 = (integers1[0]..integer... | 0 | Kotlin | 0 | 0 | 57b2e7227d992de87a51094a971e952b3774fd11 | 1,290 | advent-of-code-in-kotlin | Apache License 2.0 |
src/Day12.kt | rbraeunlich | 573,282,138 | false | {"Kotlin": 63724} | fun main() {
fun parseInput(input: List<String>): ElevationMap {
val elevationMap = ElevationMap(-1 to -1, -1 to -1, mutableListOf())
input.forEachIndexed { index, line ->
elevationMap.grid.add(index, line.toCharArray())
if (line.contains("S", false)) {
elevat... | 0 | Kotlin | 0 | 1 | 3c7e46ddfb933281be34e58933b84870c6607acd | 5,048 | advent-of-code-2022 | Apache License 2.0 |
src/main/year_2018/day18/day18.kt | rolf-rosenbaum | 572,864,107 | false | {"Kotlin": 80772} | package year_2018.day18
import Point
import findPattern
import readInput
typealias Forest = Map<Point, Char>
private const val TREE = '|'
private const val OPEN = '.'
private const val LUMBER_YARD = '#'
fun main() {
val input = readInput("main/year_2018/day18/Day18")
println(part1(input))
println(part2(... | 0 | Kotlin | 0 | 2 | 59cd4265646e1a011d2a1b744c7b8b2afe482265 | 1,825 | aoc-2022 | Apache License 2.0 |
kotlin/src/katas/kotlin/hackerrank/FormingMagicSquare.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.hackerrank
import nonstdlib.permutations
import nonstdlib.printed
import java.util.*
/**
* https://www.hackerrank.com/challenges/magic-square-forming
*/
fun main() {
val scanner = Scanner(System.`in`)
val i = generateSequence { scanner.nextLine() }.iterator()
main({ i.next() })
}
p... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 3,191 | katas | The Unlicense |
src/main/kotlin/net/hiddevb/advent/advent2019/day06/main.kt | hidde-vb | 224,606,393 | false | null | package net.hiddevb.advent.advent2019.day06
import net.hiddevb.advent.common.initialize
import kotlin.math.floor
/**
* --- Day 6: Universal Orbit Map ---
*/
private val entry = "COM"
fun main() {
val fileStrings = initialize("Day 6: Universal Orbit Map", arrayOf("day6.txt"))
// println("Part 1: Basic")
//... | 0 | Kotlin | 0 | 0 | d2005b1bc8c536fe6800f0cbd05ac53c178db9d8 | 2,123 | advent-of-code-2019 | MIT License |
src/main/kotlin/aoc2023/Day08.kt | Ceridan | 725,711,266 | false | {"Kotlin": 110767, "Shell": 1955} | package aoc2023
class Day08 {
fun part1(input: List<String>): Int {
val (directions, network) = parseInput(input)
var node = "AAA"
var steps = 0
var directionIndex = 0
while (node != "ZZZ") {
node =
if (directions[directionIndex] == 'L') network[n... | 0 | Kotlin | 0 | 0 | 18b97d650f4a90219bd6a81a8cf4d445d56ea9e8 | 2,197 | advent-of-code-2023 | MIT License |
src/Day02.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | import HandShape.*
import RoundResult.*
enum class HandShape(val shapeScore: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3)
}
enum class RoundResult(val score: Int) {
LOST(0), DRAW(3), WON(6)
}
fun HandShape.roundResultAgainst(opponentShape: HandShape): RoundResult {
return when (shapeScore - opponentShap... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 2,482 | aoc22-kotlin | Apache License 2.0 |
src/Day12.kt | CrazyBene | 573,111,401 | false | {"Kotlin": 50149} | fun main() {
data class Node(val xPos: Int, val yPos: Int, val height: Char, val isStart: Boolean, val isEnd: Boolean) {
val neighbours = mutableListOf<Node>()
}
fun Char.isNextTo(otherChar: Char) = otherChar.code - code <= 1
fun List<String>.toHill(): List<List<Node>> {
val hill = t... | 0 | Kotlin | 0 | 0 | dfcc5ba09ca3e33b3ec75fe7d6bc3b9d5d0d7d26 | 4,180 | AdventOfCode2022 | Apache License 2.0 |
src/Day03.kt | drothmaler | 572,899,837 | false | {"Kotlin": 15196} | import ElfGroup.Companion.groupBadges
import Rucksack.Companion.groupElves
import Rucksack.Companion.toRucksacks
@JvmInline
value class Item(private val char: Char) {
val priority: Int
get() = when (char) {
in 'a'..'z' -> char.code - 97 + 1
in 'A'..'Z' -> char.code - 65 + 27
... | 0 | Kotlin | 0 | 0 | 1fa39ebe3e4a43e87f415acaf20a991c930eae1c | 3,040 | aoc-2022-in-kotlin | Apache License 2.0 |
src/algorithmsinanutshell/spatialtree/KDTree.kt | realpacific | 234,499,820 | false | null | package algorithmsinanutshell.spatialtree
import algorithmdesignmanualbook.print
import kotlin.math.pow
import kotlin.math.sqrt
/**
* K-d tree is a binary search tree with more than 1 dimensions (i.e k dimensions).
*
* A 2-d tree looks like given points ((3, 6), (17, 15), (13, 15), (6, 12), (9, 1), (2, 7), (10, 19... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,494 | algorithms | MIT License |
app/src/main/kotlin/day08/Day08.kt | W3D3 | 433,748,408 | false | {"Kotlin": 72893} | package day08
import common.InputRepo
import common.readSessionCookie
import common.solve
import kotlin.math.pow
fun main(args: Array<String>) {
val day = 8
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay08Part1, ::solveDay08Part2)
}
data class InputLine(val p... | 0 | Kotlin | 0 | 0 | df4f21cd99838150e703bcd0ffa4f8b5532c7b8c | 2,998 | AdventOfCode2021 | Apache License 2.0 |
src/Day12.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | import java.util.LinkedList
object Day12 {
const val EXPECTED_PART1_CHECK_ANSWER = 31
const val EXPECTED_PART2_CHECK_ANSWER = 29
const val CHAR_START = 'S'
const val CHAR_DESTINATION = 'E'
const val CHAR_LOWEST = 'a'
}
fun main() {
fun List<String>.parseData(): Array<CharArray> =
map... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 3,715 | aoc-2022-in-kotlin | Apache License 2.0 |
jk/src/main/kotlin/leetcode/Solution_LeetCode_912_215_347_Quick_Sort_Related.kt | lchang199x | 431,924,215 | false | {"Kotlin": 86230, "Java": 23581} | package leetcode
import common.swap
import java.util.*
/**
* 快速排序相关的一些题目解法
*/
class Solution_LeetCode_912_215_347_Quick_Sort_Related {
/**
* 排序数组: LeetCode_912
* [](https://leetcode-cn.com/problems/sort-an-array/)
*/
fun sortArray(nums: IntArray): IntArray {
quickSort(nums, 0, nums.si... | 0 | Kotlin | 0 | 0 | 52a008325dd54fed75679f3e43921fcaffd2fa31 | 3,817 | Codelabs | Apache License 2.0 |
src/AoC3.kt | Pi143 | 317,631,443 | false | null | import java.io.File
fun main() {
println("Starting Day 3 A Test 1")
calculateDay3PartA("Input/2020_Day3_A_Test1")
println("Starting Day 3 A Real")
calculateDay3PartA("Input/2020_Day3_A")
println("Starting Day 3 B Test 1")
calculateDay3PartB("Input/2020_Day3_A_Test1")
println("Starting Day... | 0 | Kotlin | 0 | 1 | fa21b7f0bd284319e60f964a48a60e1611ccd2c3 | 2,263 | AdventOfCode2020 | MIT License |
src/Day02.kt | tblechmann | 574,236,696 | false | {"Kotlin": 5756} | fun main() {
fun part1(input: List<String>): Int {
val scores = mapOf(
"A X" to 3 + 1,
"A Y" to 6 + 2,
"A Z" to 0 + 3,
"B X" to 0 + 1,
"B Y" to 3 + 2,
"B Z" to 6 + 3,
"C X" to 6 + 1,
"C Y" to 0 + 2,
"... | 0 | Kotlin | 0 | 0 | 4a65f6468a0cddd8081f2f0e3c1a96935438755f | 1,262 | aoc2022 | Apache License 2.0 |
src/Day04.kt | ivancordonm | 572,816,777 | false | {"Kotlin": 36235} | fun main() {
fun part1(input: List<String>) =
input.map {
it.split(",").map { pairs -> pairs.split("-") }.map { pair -> pair.first().toInt() to pair.last().toInt() }
.let { pairs -> pairs.first().isFully(pairs.last()) }
}.count { it }
fun part2(input: List<String>)... | 0 | Kotlin | 0 | 2 | dc9522fd509cb582d46d2d1021e9f0f291b2e6ce | 1,107 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/day-09.kt | warriorzz | 434,696,820 | false | {"Kotlin": 16719} | package com.github.warriorzz.aoc
import java.nio.file.Files
import java.nio.file.Path
private fun main() {
println("Day 9:")
val positions: List<List<Point>> = Files.readAllLines(Path.of("./input/day-09.txt"))
.map { it.toCharArray().map { Point(it.digitToInt(), it.digitToInt() + 1) } }
positio... | 0 | Kotlin | 1 | 0 | 0143f59aeb8212d4ff9d65ad30c7d6456bf28513 | 2,847 | aoc-21 | MIT License |
src/aoc2022/Day11.kt | RobertMaged | 573,140,924 | false | {"Kotlin": 225650} | package aoc2022
private typealias MonkeyId = Int
private data class Monkey(
val id: Int,
val holdingItems: ArrayDeque<Long>,
val operation: Pair<Char, Int>,
val divisibleBy: Int,
val decision: Pair<Int, Int>,
var inspectedItems: Long = 0
)
private fun List<String>.parseMonkeys(): Map<Monkey... | 0 | Kotlin | 0 | 0 | e2e012d6760a37cb90d2435e8059789941e038a5 | 3,482 | Kotlin-AOC-2023 | Apache License 2.0 |
src/Day05.kt | richardmartinsen | 572,910,850 | false | {"Kotlin": 14993} | import java.util.Stack
fun main() {
fun part1(input: List<String>): String {
val chunks = input.first().split("\n").map { line ->
val chunk = line.chunked(4)
chunk
}
val rows = chunks.last()
val stacks = rows.map { Stack<String>() }
val c = chunks.fil... | 0 | Kotlin | 0 | 0 | bd71e11a2fe668d67d7ee2af5e75982c78cbe193 | 2,361 | adventKotlin | Apache License 2.0 |
src/main/kotlin/net/navatwo/adventofcode2023/day4/Day4Solution.kt | Nava2 | 726,034,626 | false | {"Kotlin": 100705, "Python": 2640, "Shell": 28} | package net.navatwo.adventofcode2023.day4
import net.navatwo.adventofcode2023.framework.ComputedResult
import net.navatwo.adventofcode2023.framework.Solution
sealed class Day4Solution : Solution<List<Day4Solution.Card>> {
data object Part1 : Day4Solution() {
override fun solve(input: List<Card>): ComputedResult... | 0 | Kotlin | 0 | 0 | 4b45e663120ad7beabdd1a0f304023cc0b236255 | 2,480 | advent-of-code-2023 | MIT License |
2021/src/main/kotlin/Day08.kt | eduellery | 433,983,584 | false | {"Kotlin": 97092} | class Day08(private val input: List<String>) {
private fun List<String>.entries(): List<Entry> = this.map { it.split(" | ") }.map { (patterns, output) ->
patterns.split(" ").map { it.toSet() } to output.split(" ").map { it.toSet() }
}
private fun countUnique(entries: List<Entry>): Int =
en... | 0 | Kotlin | 0 | 1 | 3e279dd04bbcaa9fd4b3c226d39700ef70b031fc | 1,631 | adventofcode-2021-2025 | MIT License |
src/day07/Day07.kt | iulianpopescu | 572,832,973 | false | {"Kotlin": 30777} | package day07
import readInput
private const val DAY = "07"
private const val DAY_TEST = "day${DAY}/Day${DAY}_test"
private const val DAY_INPUT = "day${DAY}/Day${DAY}"
fun main() {
fun parseInput(commands: List<String>): Directory {
val queue = ArrayDeque<Directory>()
queue.add(Directory("/")) //... | 0 | Kotlin | 0 | 0 | 4ff5afb730d8bc074eb57650521a03961f86bc95 | 3,211 | AOC2022 | Apache License 2.0 |
src/day4/main.kt | DonaldLika | 434,183,449 | false | {"Kotlin": 11805} | package day4
import assert
import readLines
fun main() {
fun part1(bingoBoard: Lottery): Int {
return bingoBoard.firstWinner()
}
fun part2(bingoBoard: Lottery): Int {
return bingoBoard.lastWinner()
}
// example
val testInput = readData("day4/test")
assert(part1(testInpu... | 0 | Kotlin | 0 | 0 | b288f16ee862c0a685a3f9e4db34d71b16c3e457 | 3,132 | advent-of-code-2021 | MIT License |
src/Day18.kt | arhor | 572,349,244 | false | {"Kotlin": 36845} | import kotlin.math.abs
/*
# Notes
number of sides for N-dimensional figure is N * 2
point (x=2, y=2, z=5) adjacent points:
by x: (x=1, y=2, z=5)
(x=3, y=2, z=5)
by y: (x=2, y=1, z=5)
(x=2, y=3, z=5)
by z: (x=2, y=2, z=4)
(x=2, y=2, z=6)
for each point
try to find 4 diagonal points... | 0 | Kotlin | 0 | 0 | 047d4bdac687fd6719796eb69eab2dd8ebb5ba2f | 3,253 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day15/Day15.kt | MaxBeauchemin | 573,094,480 | false | {"Kotlin": 60619} | package day15
import readInput
import java.math.BigInteger
import kotlin.math.abs
data class Coordinate(val x: Int, val y: Int) {
fun distanceFrom(other: Coordinate) = abs(this.x - other.x) + abs(this.y - other.y)
fun upRight() = Coordinate(x + 1, y - 1)
fun upLeft() = Coordinate(x - 1, y - 1)
fun dow... | 0 | Kotlin | 0 | 0 | 38018d252183bd6b64095a8c9f2920e900863a79 | 4,557 | advent-of-code-2022 | Apache License 2.0 |
src/com/kingsleyadio/adventofcode/y2021/day14/Alternative.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2021.day14
import com.kingsleyadio.adventofcode.util.readInput
private fun solution(template: String, map: Map<String, Char>, steps: Int): Long {
fun tick(input: Map<String, Long>): Map<String, Long> = buildMap {
for ((pair, count) in input) {
val product... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 1,335 | adventofcode | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2022/day05/day5.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2022.day05
import biz.koziolek.adventofcode.findInput
fun main() {
val inputFile = findInput(object {})
val (stacks, instructions) = parseCargo(inputFile.bufferedReader().readLines())
val movedStacks = moveCargo(stacks, instructions)
println(movedStacks)
val... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 3,099 | advent-of-code | MIT License |
src/Day07.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | fun main() {
class Node(var name: String, var isFile: Boolean = false, var size: Int = 0) {
var parent: Node? = null
var children = mutableListOf<Node>()
fun add(node: Node) {
if (isFile) return
children.add(node)
node.parent = this
}
fun... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 3,388 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/de/jball/aoc2022/day11/Day11.kt | fibsifan | 573,189,295 | false | {"Kotlin": 43681} | package de.jball.aoc2022.day11
import de.jball.aoc2022.Day
class Day11(test: Boolean = false) : Day<Long>(test, 10605L, 2713310158L) {
private val monkeys = input
.chunked(7)
.map { parseMonkey(it) }
private val monkeys2 = input
.chunked(7)
.map { parseMonkey(it) }
private ... | 0 | Kotlin | 0 | 3 | a6d01b73aca9b54add4546664831baf889e064fb | 3,059 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day24.kt | gautemo | 572,204,209 | false | {"Kotlin": 78294} | import shared.Point
import shared.getText
fun main() {
val input = getText("day24.txt")
println(day24A(input))
println(day24B(input))
}
fun day24A(input: String) = bfsSearch(input) - 1
fun day24B(input: String) = bfsSearch(input, Triple(false, false, false))
private fun bfsSearch(input: String, goals: Tr... | 0 | Kotlin | 0 | 0 | bce9feec3923a1bac1843a6e34598c7b81679726 | 3,258 | AdventOfCode2022 | MIT License |
src/main/kotlin/aoc2022/Day07.kt | j4velin | 572,870,735 | false | {"Kotlin": 285016, "Python": 1446} | package aoc2022
import readInput
import java.util.*
sealed class FileSystemElement(val name: String, val parent: Directory?) {
abstract val size: Int
override fun hashCode() = Objects.hash(name, parent)
override fun equals(other: Any?) = other is FileSystemElement && this::class.isInstance(other) &&
... | 0 | Kotlin | 0 | 0 | f67b4d11ef6a02cba5b206aba340df1e9631b42b | 3,879 | adventOfCode | Apache License 2.0 |
src/main/kotlin/day07_treachery_of_whales/TreacheryOfWhales.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package day07_treachery_of_whales
import java.util.*
import kotlin.math.abs
/**
* Now for (efficient) optimization. Clearly the best position is between the
* min and max initial positions, and a brute force search of every position
* will get you an answer. There must be exactly one minimum. It's probably
* clos... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 1,655 | aoc-2021 | MIT License |
src/Day12.kt | LauwiMeara | 572,498,129 | false | {"Kotlin": 109923} | const val START_LETTER = 'S'
const val END_LETTER = 'E'
const val MIN_ELEVATION_LETTER = 'a'
const val MAX_ELEVATION_LETTER = 'z'
const val NUM_START_NODES = 989 // Found by running part2() once and looking at the size of startNodes.
data class Node(val pos: Point, val letter: Char)
fun main() {
fun initialiseUnv... | 0 | Kotlin | 0 | 1 | 34b4d4fa7e562551cb892c272fe7ad406a28fb69 | 4,749 | AoC2022 | Apache License 2.0 |
src/year_2023/day_18/Day18.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2023.day_18
import readInput
import util.*
interface IDig {
val direction: Direction
val distance: Int
}
data class DigStep(
override val direction: Direction,
override val distance: Int,
val color: String
): IDig
data class UpdatedDig(
override val direction: Direction,
ov... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 2,462 | advent_of_code | Apache License 2.0 |
src/Day18.kt | jstapels | 572,982,488 | false | {"Kotlin": 74335} |
private data class Cube(val x: Int, val y:Int, val z:Int) {
val adjacents get() = listOf(
Cube(x - 1, y, z),
Cube(x + 1, y, z),
Cube(x, y - 1, z),
Cube(x, y + 1, z),
Cube(x, y, z - 1),
Cube(x, y, z + 1),
)
}
private typealias Grid = MutableMap<Int, MutableMap<In... | 0 | Kotlin | 0 | 0 | 0d71521039231c996e2c4e2d410960d34270e876 | 3,217 | aoc22 | Apache License 2.0 |
2021/src/main/kotlin/day19.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Mat4i
import utils.Parser
import utils.Point3i
import utils.ROTS
import utils.Solution
import utils.Vec4i
import utils.product
import utils.productIndexed
import utils.withCounts
fun main() {
Day19.run()
}
object Day19 : Solution<List<Day19.Scanner>>() {
override val name = "day19"
override val par... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 3,980 | aoc_kotlin | MIT License |
src/main/kotlin/com/github/freekdb/aoc2019/Day04.kt | FreekDB | 228,241,398 | false | null | package com.github.freekdb.aoc2019
import java.io.File
// https://adventofcode.com/2019/day/4
fun main() {
val bounds =
File("input/day-04--input.txt")
.readLines()
.first()
.split("-")
val lowerBound = bounds[0].toInt()
val upperBound = bounds[1].toInt()
... | 0 | Kotlin | 0 | 1 | fd67b87608bcbb5299d6549b3eb5fb665d66e6b5 | 2,905 | advent-of-code-2019 | Apache License 2.0 |
src/Day07.kt | Xacalet | 576,909,107 | false | {"Kotlin": 18486} | /**
* ADVENT OF CODE 2022 (https://adventofcode.com/2022/)
*
* Solution to day 7 (https://adventofcode.com/2022/day/7)
*
*/
private sealed interface Node
private data class FileNode(
val size: Long,
val name: String,
): Node
private data class DirectoryNode(
val name: String,
val parentNode: Di... | 0 | Kotlin | 0 | 0 | 5c9cb4650335e1852402c9cd1bf6f2ba96e197b2 | 3,183 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/AoC_Day14.kt | sviams | 115,921,582 | false | null | object AoC_Day14 {
val initialKnotState = (0..255).toList()
fun parseHashes(input: String) : List<String> {
val rows = (0 until 128).map { input + "-" + it }
return rows.map { AoC_Day10.solvePt2(it, initialKnotState) }
}
fun solvePt1(input: String) : Int {
val hashes = pars... | 0 | Kotlin | 0 | 0 | 19a665bb469279b1e7138032a183937993021e36 | 2,960 | aoc17 | MIT License |
src/Day05.kt | anisch | 573,147,806 | false | {"Kotlin": 38951} | val regexOps = """move \d from \d to \d""".toRegex()
data class Ops(val move: Int, val from: Int, val to: Int)
fun createStack(list: List<String>): MutableMap<Int, MutableList<Char>> {
val stack = mutableMapOf<Int, MutableList<Char>>()
list
.takeWhile { it.isNotBlank() }
.dropLast(1)
... | 0 | Kotlin | 0 | 0 | 4f45d264d578661957800cb01d63b6c7c00f97b1 | 2,391 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/kotlin/net/voldrich/aoc2021/Day9.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2021
import net.voldrich.BaseDay
// https://adventofcode.com/2021/day/9/
fun main() {
Day9().run()
}
class Day9 : BaseDay() {
override fun task1() : Int {
val inputNums = input.lines().map { line -> line.trim().toCharArray().map { it.digitToInt() }.toList() }
val heig... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 2,797 | advent-of-code | Apache License 2.0 |
src/Day08.kt | rinas-ink | 572,920,513 | false | {"Kotlin": 14483} | import java.lang.IllegalArgumentException
import java.lang.Integer.max
fun main() {
fun checkRow(row: List<Int>, res: MutableList<Boolean>) {
var highest = -1
for (i in row.indices) {
if (row[i] > highest) res[i] = true
highest = max(row[i], highest)
}
high... | 0 | Kotlin | 0 | 0 | 462bcba7779f7bfc9a109d886af8f722ec14c485 | 3,044 | anvent-kotlin | Apache License 2.0 |
src/Day09.kt | cisimon7 | 573,872,773 | false | {"Kotlin": 41406} | import kotlin.math.abs
import kotlin.math.sign
fun main() {
fun part1(commands: List<Pair<Direction, Int>>): Int {
val head = Knot.Head()
val tail = Knot.Tail()
commands.forEach { command ->
val (direction, count) = command
repeat(count) {
head.step(d... | 0 | Kotlin | 0 | 0 | 29f9cb46955c0f371908996cc729742dc0387017 | 3,199 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day04/Day04.kt | mdenburger | 433,731,891 | false | {"Kotlin": 8573} | package day04
import java.io.File
fun main() {
val lines = File("src/main/kotlin/day04/day04-input.txt").readLines().toMutableList()
val numbers = lines.removeAt(0).split(",").map { it.toInt() }
val boards = mutableListOf<Board>()
while (lines.isNotEmpty()) {
boards.add(parseBoard(lines))
... | 0 | Kotlin | 0 | 0 | e890eec2acc2eea9c0432d092679aeb9de3f51b4 | 2,239 | aoc-2021 | MIT License |
src/Day11.kt | wgolyakov | 572,463,468 | false | null | fun main() {
class Monkey(val items: MutableList<Long>, val operation: (Long) -> Long,
val throwOper: (Long) -> Int, val divisible: Int) {
var inspectCount = 0L
}
fun parse(input: List<String>): List<Monkey> {
val monkeys = mutableListOf<Monkey>()
var i = 0
while (i < input.size) {
i++
val items ... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 2,399 | 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.