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/Day15.kt | IvanChadin | 576,061,081 | false | {"Kotlin": 26282} | import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun main() {
val inputName = "Day15_test"
data class Pt(val x: Int, val y: Int)
fun distance(a: Pt, b: Pt) = abs(b.x - a.x) + abs(b.y - a.y)
fun part1(): Int {
val ansY = 2000000
var l = Int.MAX_VALUE
var r ... | 0 | Kotlin | 0 | 0 | 2241437e6c3a20de70306a0cb37b6fe2ed8f9e3a | 2,974 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/util/combinatorics/reusable.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.util.combinatorics
import dev.bogwalk.util.maths.factorial
import java.math.BigInteger
/**
* Returns the number of ways to choose [k] items from [n] items without repetition and without
* order, namely C(n, k).
*
* @throws IllegalArgumentException if either Int is negative.
*/
fun binomialCoe... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 9,800 | project-euler-kotlin | MIT License |
src/Day11.kt | gojoel | 573,543,233 | false | {"Kotlin": 28426} |
fun main() {
val input = readInput("11")
// val input = readInput("11_test")
data class Monkey(val id: Int, val items: ArrayList<Long>, var inspections: Long = 0, val op: (old: Long) -> Long,
val mod: Long, val test: (worry: Long) -> Boolean, val recipients: Pair<Int, Int>)
fun o... | 0 | Kotlin | 0 | 0 | 0690030de456dad6dcfdcd9d6d2bd9300cc23d4a | 3,942 | aoc-kotlin-22 | Apache License 2.0 |
src/day08/Code.kt | ldickmanns | 572,675,185 | false | {"Kotlin": 48227} | package day08
import readInput
fun main() {
val input = readInput("day08/input")
// val input = readInput("day08/input_test")
val grid = extractGrid(input)
println(part1(grid))
println(part2(grid))
}
private fun extractGrid(
input: List<String>
): Array<IntArray> = input.map { row: String ->... | 0 | Kotlin | 0 | 0 | 2654ca36ee6e5442a4235868db8174a2b0ac2523 | 4,868 | aoc-kotlin-2022 | Apache License 2.0 |
2020/src/year2021/day05/code.kt | eburke56 | 436,742,568 | false | {"Kotlin": 61133} | package year2021.day05
import util.readAllLines
import kotlin.math.max
import kotlin.math.min
private class Node(initialValue: Int) {
var value: Int = initialValue
private set
fun increment() { value += 1 }
}
private class Board(values: List<String>, val allowDiagonal: Boolean = false) {
private... | 0 | Kotlin | 0 | 0 | 24ae0848d3ede32c9c4d8a4bf643bf67325a718e | 2,074 | adventofcode | MIT License |
src/day03/Day03.kt | Klaus-Anderson | 572,740,347 | false | {"Kotlin": 13405} | package day03
import readInput
fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { bagString ->
val comp1 = bagString.substring(0, bagString.length / 2)
val comp2 = bagString.substring(bagString.length / 2, bagString.length)
val commonLetters = com... | 0 | Kotlin | 0 | 0 | faddc2738011782841ec20475171909e9d4cee84 | 1,397 | harry-advent-of-code-kotlin-template | Apache License 2.0 |
src/Day04.kt | max-zhilin | 573,066,300 | false | {"Kotlin": 114003} | fun main() {
fun contains(a: String, b: String): Boolean {
val (ax, ay) = a.split("-").map { it.toInt() }
val (bx, by) = b.split("-").map { it.toInt() }
if (ax <= bx && ay >= by) return true
if (bx <= ax && by >= ay) return true
return false
}
fun overlaps(a: String,... | 0 | Kotlin | 0 | 0 | d9dd7a33b404dc0d43576dfddbc9d066036f7326 | 1,400 | AoC-2022 | Apache License 2.0 |
src/day10/Day10.kt | GrzegorzBaczek93 | 572,128,118 | false | {"Kotlin": 44027} | package day10
import readInput
import utils.withStopwatch
fun main() {
val testInput = readInput("input10_test")
// withStopwatch { part1(testInput) }
// withStopwatch { part2(testInput) }
val input = readInput("input10")
// withStopwatch { part1(input) }
withStopwatch { part2(input) }
}
privat... | 0 | Kotlin | 0 | 0 | 543e7cf0a2d706d23c3213d3737756b61ccbf94b | 2,201 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/aoc/day7/NoSpaceLeftOnDevice.kt | hofiisek | 573,543,194 | false | {"Kotlin": 17421} | package aoc.day7
import aoc.dropFirst
import aoc.loadInput
import java.io.File
/**
* https://adventofcode.com/2022/day/8
*
* @author <NAME>
*/
val RGX_FILE = "(\\d+) ([\\w.]+)".toRegex()
val RGX_DIR = "dir (\\w+)".toRegex()
val RGX_CD_DIR = "\\$ cd (\\w+)".toRegex()
val RGX_CD_BACK = "\\$ cd ..".toRegex()
val RG... | 0 | Kotlin | 0 | 2 | 5908a665db4ac9fc562c44d6907f81cd3cd8d647 | 2,995 | Advent-of-code-2022 | MIT License |
src/Day03.kt | graesj | 572,651,121 | false | {"Kotlin": 10264} | fun Char.getScore(): Int {
return if (this.isLowerCase()) this - 'a' + 1 else this - 'A' + 27
}
fun main() {
operator fun List<Set<Char>>.component1() = this.first()
operator fun List<Set<Char>>.component2() = this[1]
operator fun List<Set<Char>>.component3() = this[2]
fun part1(input: List<String... | 0 | Kotlin | 0 | 0 | df7f855a14c532f3af7a8dc86bd159e349cf59a6 | 1,233 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | khongi | 572,983,386 | false | {"Kotlin": 24901} | fun main() {
fun Char.getPriority(): Int {
return if (isLowerCase()) {
this - 'a' + 1
} else {
this - 'A' + 27
}
}
fun Set<Char>.findCommon(other: String): Set<Char> {
return toCharArray().intersect(other.asIterable().toSet())
}
fun part1(inp... | 0 | Kotlin | 0 | 0 | 9cc11bac157959f7934b031a941566d0daccdfbf | 1,313 | adventofcode2022 | Apache License 2.0 |
src/Day03.kt | rickbijkerk | 572,911,701 | false | {"Kotlin": 31571} | fun main() {
fun part1(input: List<String>): Int {
val alphabet = "<KEY>"
val duplicateLetters = input.map { line ->
val part1 = line.substring(0, line.length / 2)
val part2 = line.substring(line.length / 2, line.length)
part1.toCharArray().toList().intersect(p... | 0 | Kotlin | 0 | 0 | 817a6348486c8865dbe2f1acf5e87e9403ef42fe | 1,860 | aoc-2022 | Apache License 2.0 |
src/day16/Day16.kt | dkoval | 572,138,985 | false | {"Kotlin": 86889} | package day16
import readInput
import kotlin.system.measureTimeMillis
private const val DAY_ID = "16"
private data class Valve(
val id: String,
val rate: Int,
val adj: List<String>
)
fun main() {
fun parseInput(input: List<String>): Map<String, Valve> {
val valve = """Valve ([A-Z]{2}) has fl... | 0 | Kotlin | 1 | 0 | 791dd54a4e23f937d5fc16d46d85577d91b1507a | 3,795 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2020/Day11.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2020
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.Pos
import com.chriswk.aoc.util.report
import java.lang.IllegalStateException
class Day11 : AdventDay(2020, 11) {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day = Day1... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,756 | adventofcode | MIT License |
src/day02/Day02.kt | elenavuceljic | 575,436,628 | false | {"Kotlin": 5472} | package day02
import java.io.File
enum class MyHand(val hand: Char, val scoreWorth: Int) {
X('R', 1), Y('P', 2), Z('S', 3);
}
enum class OpponentHand(val hand: Char) {
A('R'), B('P'), C('S');
}
fun scoreGame(theirs: OpponentHand, mine: MyHand): Int = when {
mine.hand == theirs.hand -> 3
(mine == MyH... | 0 | Kotlin | 0 | 0 | c5093b111fd02e28823d31f2edddb7e66c295add | 1,565 | advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | arhor | 572,349,244 | false | {"Kotlin": 36845} | fun main() {
val input = readInput {}.map { line ->
line.split(",")
.map { pair -> pair.split("-").map(String::toInt) }
.map { (min, max) -> Range(min, max) }
}
println("Part 1: " + solvePuzzle(input))
println("Part 2: " + solvePuzzle(input, completelyOverlapping = false... | 0 | Kotlin | 0 | 0 | 047d4bdac687fd6719796eb69eab2dd8ebb5ba2f | 886 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day18/first/Solution.kt | verwoerd | 224,986,977 | false | null | package day18.first
import tools.Coordinate
import tools.adjacentCoordinates
import tools.origin
import tools.priorityQueueOf
import tools.timeSolution
/**
* @author verwoerd
* @since 18-12-2019
*/
typealias Maze = MutableMap<Coordinate, MazeTile>
typealias PointsOfInterest = Map<Coordinate, Char>
// key, path,... | 0 | Kotlin | 0 | 0 | 554377cc4cf56cdb770ba0b49ddcf2c991d5d0b7 | 4,988 | AoC2019 | MIT License |
src/Day09.kt | VadimB95 | 574,449,732 | false | {"Kotlin": 19743} | import kotlin.math.absoluteValue
import kotlin.math.sign
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day09_test")
check(part1(testInput) == 13)
check(part2(testInput) == 1)
val input = readInput("Day09")
println(part1(input))
... | 0 | Kotlin | 0 | 0 | 3634d1d95acd62b8688b20a74d0b19d516336629 | 2,397 | aoc-2022 | Apache License 2.0 |
src/Day01.kt | timmiller17 | 577,546,596 | false | {"Kotlin": 44667} | fun main() {
fun part1(input: List<String>): Int {
var elfFoodItems = input
var mostCalories = 0
while (elfFoodItems.isNotEmpty()) {
val endOfItemsIndex = elfFoodItems.indexOfFirst { it.isBlank() }
if (endOfItemsIndex != -1) {
val calories = elfFoodIt... | 0 | Kotlin | 0 | 0 | b6d6b647c7bb0e6d9e5697c28d20e15bfa14406c | 1,907 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | vjgarciag96 | 572,719,091 | false | {"Kotlin": 44399} | import RockPaperScissorsPlayResult.*
import RockPaperScissorsShape.*
private enum class RockPaperScissorsShape {
ROCK,
PAPER,
SCISSORS,
}
private enum class RockPaperScissorsPlayResult {
WIN,
LOSE,
DRAW
}
private fun play(
shapeA: RockPaperScissorsShape,
shapeB: RockPaperScissorsShape... | 0 | Kotlin | 0 | 0 | ee53877877b21166b8f7dc63c15cc929c8c20430 | 3,161 | advent-of-code-2022 | Apache License 2.0 |
jeorg-kotlin-algorithms/jeorg-kotlin-alg-3-weigh-term-frequency/src/main/kotlin/org/jesperancinha/algorithms/weigh/term/frequency/WeighTermFrequency.kt | jesperancinha | 354,756,418 | false | {"Kotlin": 35444, "Java": 14401, "JavaScript": 10140, "Python": 4018, "Makefile": 1258, "Shell": 89} | package org.jesperancinha.algorithms.weigh.term.frequency
import org.jesperancinha.console.consolerizer.console.ConsolerizerComposer
import org.jesperancinha.console.consolerizer.console.ConsolerizerComposer.title
import kotlin.math.sqrt
fun main(args: Array<String>) {
val sentence1 =
"I travelled in Germ... | 1 | Kotlin | 0 | 1 | 7a382ed529ebdc53cc025671a453c7bd5699539e | 2,687 | jeorg-algorithms-test-drives | Apache License 2.0 |
src/Day11.kt | wooodenleg | 572,658,318 | false | {"Kotlin": 30668} | private const val Lcd = 9699690L
class Monkey(
val name: String, // for debugging
var items: List<Long>,
private val inspectionTransformation: (item: Long) -> Long,
private val getTargetIndex: (item: Long) -> Int
) {
var inspectionCounter = 0L
private set
fun inspect(divideByThree: Boo... | 0 | Kotlin | 0 | 1 | ff1f3198f42d1880e067e97f884c66c515c8eb87 | 3,297 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | ds411 | 573,543,582 | false | {"Kotlin": 16415} | fun main() {
fun part1(input: List<String>): Int {
return input.map {
val midpoint = it.length / 2
val sack1 = it.substring(0, midpoint)
val sack2 = it.substring(midpoint)
sack1.toCharArray().first {
sack2.contains(it)
}
}.... | 0 | Kotlin | 0 | 0 | 6f60b8e23ee80b46e7e1262723960af14670d482 | 1,098 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/pl/jpodeszwik/aoc2023/Day11.kt | jpodeszwik | 729,812,099 | false | {"Kotlin": 55101} | package pl.jpodeszwik.aoc2023
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
const val GALAXY = '#'
data class Universe(val lines: List<String>, val expandedRows: Set<Int>, val expandedCols: Set<Int>, val galaxies: List<Coord>)
private fun parseUniverse(lines: List<String>): Universe {
val... | 0 | Kotlin | 0 | 0 | 2b90aa48cafa884fc3e85a1baf7eb2bd5b131a63 | 1,831 | advent-of-code | MIT License |
src/main/kotlin/coursera/algorithms1/week3/classroom/MergeSort.kt | rupeshsasne | 359,696,544 | false | null | package coursera.algorithms1.week3.classroom
inline fun <reified T> mergeWithSmallerAux(arr: Array<T>, lo: Int, mid: Int, hi: Int, comparator: Comparator<T>) {
val aux = Array(((hi - lo) / 2)) { arr[lo + it] }
var i = lo
var j = mid + 1
var k = lo
while (i <= mid && j <= hi) {
if (compar... | 0 | Kotlin | 0 | 0 | e5a9b1f2d1c497ad7925fb38d9e4fc471688298b | 2,030 | algorithms-sedgewick-wayne | MIT License |
src/Day20.kt | l8nite | 573,298,097 | false | {"Kotlin": 105683} | private fun move(index: Int, amounts: MutableList<Pair<Int, Long>>) {
val indexFrom = amounts.indexOfFirst { (initialIndex) -> initialIndex == index }
val value = amounts[indexFrom]
val (_, amount) = value
if (amount == 0L) return
amounts.removeAt(indexFrom)
val indexTo = findIndex(indexFrom, ... | 0 | Kotlin | 0 | 0 | f74331778fdd5a563ee43cf7fff042e69de72272 | 1,697 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | mkulak | 573,910,880 | false | {"Kotlin": 14860} | import java.lang.IllegalArgumentException
import kotlin.math.absoluteValue
import kotlin.math.sign
fun main() {
fun part1(input: List<String>): Int {
val visited = HashSet<Long>()
val rope = List(2) { XY(0, 0) }
input.forEach { line ->
val dir = line[0]
val steps = l... | 0 | Kotlin | 0 | 0 | 3b4e9b32df24d8b379c60ddc3c007d4be3f17d28 | 1,981 | AdventOfKo2022 | Apache License 2.0 |
src/Day04.kt | richardmartinsen | 572,910,850 | false | {"Kotlin": 14993} | fun main() {
fun findPairs(input: List<String>) =
input.map { line ->
line.split(",")
.map { pair ->
pair.split("-")
}.map { values ->
val a = values[0].toInt()
val b = values[1].toInt()
... | 0 | Kotlin | 0 | 0 | bd71e11a2fe668d67d7ee2af5e75982c78cbe193 | 1,284 | adventKotlin | Apache License 2.0 |
src/main/kotlin/days/y2023/day10/Day10.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2023.day10
import util.InputReader
typealias PuzzleLine = String
typealias PuzzleInput = List<PuzzleLine>
class Day10(val input: PuzzleInput) {
val grid = parseGrid(input)
fun partOne(): Int {
val len = findLen()
return len / 2
}
fun partTwo(): Int {
val pipe =... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 5,289 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Day01.kt | seana-zr | 725,858,211 | false | {"Kotlin": 28265} | fun main() {
fun getCalibrationValue(s: String): Int {
// we know there MUST be a first and last digit in the input
val first = s.first { it.isDigit() }.digitToInt()
val last = s.last { it.isDigit() }.digitToInt()
return first.times(10).plus(last)
}
fun part1(input: List<Str... | 0 | Kotlin | 0 | 0 | da17a5de6e782e06accd3a3cbeeeeb4f1844e427 | 1,944 | advent-of-code-kotlin-template | Apache License 2.0 |
src/Day02.kt | joy32812 | 573,132,774 | false | {"Kotlin": 62766} | const val SCORE_WIN = 6
const val SCORE_DRAW = 3
val selectScore = listOf(1, 2, 3)
fun Char.toIntNum() = when (this) {
in "AX" -> 0
in "BY" -> 1
else -> 2
}
fun getScore(a: Int, b: Int): Int {
val matchScore = when {
a == b -> SCORE_DRAW
a + 1 == b || (a == 2 && b == 0) -> SCORE_WIN
else -> 0
}
... | 0 | Kotlin | 0 | 0 | 5e87958ebb415083801b4d03ceb6465f7ae56002 | 879 | aoc-2022-in-kotlin | Apache License 2.0 |
ceria/13/src/main/kotlin/Solution.kt | VisionistInc | 317,503,410 | false | null | import java.io.File
import java.math.BigInteger
fun main(args : Array<String>) {
val input = File(args.first()).readLines()
println("Solution 1: ${solution1(input)}")
println("Solution 2: ${solution2(input)}")
}
private fun solution1(input :List<String>) :Int {
var time = input.first().toInt()
val bus... | 0 | Rust | 0 | 0 | 002734670384aa02ca122086035f45dfb2ea9949 | 2,098 | advent-of-code-2020 | MIT License |
src/main/kotlin/io/github/clechasseur/adventofcode2021/Day19.kt | clechasseur | 435,726,930 | false | {"Kotlin": 315943} | package io.github.clechasseur.adventofcode2021
import io.github.clechasseur.adventofcode2021.data.Day19Data
import io.github.clechasseur.adventofcode2021.util.Pt3D
import io.github.clechasseur.adventofcode2021.util.manhattan
object Day19 {
private val data = Day19Data.data
fun part1(): Int = data.toScanners(... | 0 | Kotlin | 0 | 0 | 4b893c001efec7d11a326888a9a98ec03241d331 | 4,101 | adventofcode2021 | MIT License |
src/Day09.kt | diesieben07 | 572,879,498 | false | {"Kotlin": 44432} | import kotlin.math.abs
import kotlin.math.sign
private val file = "Day09"
//private val file = "Day09Example"
private enum class Direction(val x: Int, val y: Int) {
UP(0, -1), DOWN(0, 1), LEFT(-1, 0), RIGHT(1, 0)
}
private data class Step(val direction: Direction, val amount: Int) {
companion object {
... | 0 | Kotlin | 0 | 0 | 0b9993ef2f96166b3d3e8a6653b1cbf9ef8e82e6 | 2,605 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day02.kt | brigham | 573,127,412 | false | {"Kotlin": 59675} | enum class Outcome {
Loss, Draw, Win;
val score: Int
get() = this.ordinal * 3
fun against(opp: Piece): Piece {
return when (this) {
Loss -> opp.beats
Draw -> opp
Win -> opp.beatenBy
}
}
}
enum class Piece {
Rock {
override val be... | 0 | Kotlin | 0 | 0 | b87ffc772e5bd9fd721d552913cf79c575062f19 | 2,201 | advent-of-code-2022 | Apache License 2.0 |
src/Day11.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | fun main() {
data class Monkey(
val operation: Char,
val operand: Long?,
val divisor: Long,
val trueRecipient: Int,
val falseRecipient: Int,
var items: ArrayDeque<Long> = ArrayDeque(),
var inspectionCount: Long = 0)
// Worry level reduction idea taken fro... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 2,879 | aoc-2022 | Apache License 2.0 |
src/Day16.kt | cypressious | 572,898,685 | false | {"Kotlin": 77610} | import java.util.*
import java.util.stream.IntStream
import kotlin.math.pow
fun main() {
val regex = """Valve (\w+) has flow rate=(\d+); \w+ \w+ to \w+ (.+)""".toRegex()
class Valve(
val name: String,
val rate: Int,
val tunnels: MutableList<Valve> = mutableListOf()
) {
val ... | 0 | Kotlin | 0 | 1 | 7b4c3ee33efdb5850cca24f1baa7e7df887b019a | 4,529 | AdventOfCode2022 | Apache License 2.0 |
src/Day09.kt | WilsonSunBritten | 572,338,927 | false | {"Kotlin": 40606} | import kotlin.math.absoluteValue
fun main() {
fun part1(input: List<String>): Int {
val moves = input.map {
val split = it.split(" ")
Move(positions = split[1].toInt(), direction = directionMap[split[0].first()]!!)
}
val tailPositions = mutableSetOf(Position(0, 0))
... | 0 | Kotlin | 0 | 0 | 363252ffd64c6dbdbef7fd847518b642ec47afb8 | 5,148 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day05.kt | pimts | 573,091,164 | false | {"Kotlin": 8145} | import java.util.Stack
data class MoveInstruction(val amount: Int, val from: Int, val to: Int)
fun main() {
fun parseStacks(input: String): MutableMap<Int, Stack<Char>> {
val stacks = mutableMapOf<Int, Stack<Char>>()
val cratesInput = input.substringBefore("\n\n").lines().dropLast(1)
crat... | 0 | Kotlin | 0 | 0 | dc7abb10538bf6ad9950a079bbea315b4fbd011b | 2,254 | aoc-2022-in-kotlin | Apache License 2.0 |
src/y2016/Day08.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2016
import util.getCol
import util.printMatrix
import util.readInput
import util.set
sealed class LightsInstruction {
companion object {
fun parse(string: String): LightsInstruction {
return when {
string.startsWith("rect") -> Rect.fromString(string)
s... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 3,439 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/jacobhyphenated/advent2022/day8/Day8.kt | jacobhyphenated | 573,603,184 | false | {"Kotlin": 144303} | package com.jacobhyphenated.advent2022.day8
import com.jacobhyphenated.advent2022.Day
/**
* Day 8: Treetop Tree House
*
* A 2d array is a grid of tree sizes (where 9 is the tallest possible tree)
*/
class Day8: Day<List<List<Int>>> {
override fun getInput(): List<List<Int>> {
return readInputFile("day... | 0 | Kotlin | 0 | 0 | 9f4527ee2655fedf159d91c3d7ff1fac7e9830f7 | 4,085 | advent2022 | The Unlicense |
src/Day05.kt | mandoway | 573,027,658 | false | {"Kotlin": 22353} | fun parseStacks(stackLines: List<String>): List<ArrayDeque<Char>> {
val stacks = mutableListOf<ArrayDeque<Char>>()
stackLines.forEach { line ->
line.chunked(4)
.map { it.trim() }
.forEachIndexed { index, crate ->
if (stacks.lastIndex < index) {
... | 0 | Kotlin | 0 | 0 | 0393a4a25ae4bbdb3a2e968e2b1a13795a31bfe2 | 2,540 | advent-of-code-22 | Apache License 2.0 |
src/Day8/Day8.kt | tomashavlicek | 571,148,715 | false | {"Kotlin": 23780} | package Day8
import readInput
fun main() {
fun parseInput(input: List<String>): List<List<Int>> {
return input.map { row ->
row.windowed(1).map { it.toInt() }
}
}
fun part1(input: List<String>): Int {
val map = parseInput(input)
var count = 0
for ((ro... | 0 | Kotlin | 0 | 0 | 899d30e241070903fe6ef8c4bf03dbe678310267 | 2,860 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/adventofcode/year2021/Day14ExtendedPolymerization.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2021
import adventofcode.Puzzle
import adventofcode.PuzzleInput
class Day14ExtendedPolymerization(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val polymerTemplate by lazy { input.lines().first() }
private val pairInsertionRules by lazy { input.lines().drop(2).map... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 2,644 | AdventOfCode | MIT License |
src/main/kotlin/com/staricka/adventofcode2022/Day12.kt | mathstar | 569,952,400 | false | {"Kotlin": 77567} | package com.staricka.adventofcode2022
class Day12 : Day {
override val id = 12
data class Tile(val height: Char) {
fun canStepFrom(other: Tile): Boolean = other.height - height >= -1
fun canStepReverse(other: Tile): Boolean = other.canStepFrom(this)
}
private fun shortestPath(
start: Pair<Int, In... | 0 | Kotlin | 0 | 0 | 2fd07f21348a708109d06ea97ae8104eb8ee6a02 | 2,521 | adventOfCode2022 | MIT License |
src/Day12.kt | Fenfax | 573,898,130 | false | {"Kotlin": 30582} | import java.awt.Point
import java.util.*
import kotlin.collections.ArrayDeque
fun main() {
val alphabet = ('a'..'z').joinToString ("")
fun genPoints(input: List<String>): MapGraph{
val points = mutableMapOf<Point, MapPoint>()
for (x in input.indices){
for (y in input[x].indices){
... | 0 | Kotlin | 0 | 0 | 28af8fc212c802c35264021ff25005c704c45699 | 3,713 | AdventOfCode2022 | Apache License 2.0 |
kotlin/src/Day11.kt | ekureina | 433,709,362 | false | {"Kotlin": 65477, "C": 12591, "Rust": 7560, "Makefile": 386} | import java.lang.Integer.parseInt
fun main() {
val part1Iterations = 100
fun surroundingCells(line: Int, row: Int, constraints: Pair<Int, Int>): Collection<Pair<Int, Int>> {
return ((line-1).coerceAtLeast(0)..(line+1).coerceAtMost(constraints.first)).flatMap { lineNum ->
((row-1).coerceAtL... | 0 | Kotlin | 0 | 1 | 391d0017ba9c2494092d27d22d5fd9f73d0c8ded | 4,089 | aoc-2021 | MIT License |
2021/02/28/jjeda/PrefixSums.kt | Road-of-CODEr | 323,110,862 | false | null | // https://app.codility.com/programmers/lessons/5-prefix_sums/count_div
fun countDiv(A: Int, B: Int, K: Int): Int {
val startNumber = (A..B).firstOrNull {
it % K ==0
} ?: return 0
return (B - startNumber) / K + 1
}
// https://app.codility.com/programmers/lessons/5-prefix_sums/genomic_range_query
/*
// O(N *... | 1 | Java | 25 | 22 | cae1df83ac110519a5f5d6b940fa3e90cebb48c1 | 2,232 | stupid-week-2021 | MIT License |
src/Day21.kt | kenyee | 573,186,108 | false | {"Kotlin": 57550} | import java.lang.IllegalArgumentException
sealed class MonkeyNode(val name: String) {
class ShoutMonkey(name: String, private val value: Long) : MonkeyNode(name) {
override fun compute(monkeys: Map<String, MonkeyNode>): Long {
return value
}
}
class CalcMonkey(
name: St... | 0 | Kotlin | 0 | 0 | 814f08b314ae0cbf8e5ae842a8ba82ca2171809d | 2,265 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/day05/Day05.kt | dkoval | 572,138,985 | false | {"Kotlin": 86889} | package day05
import readInput
import java.util.*
private const val DAY_ID = "05"
private data class Instruction(val quantity: Int, val from: Int, val to: Int)
fun main() {
fun solve(input: List<String>, strategy: (stacks: Array<Deque<Char>>, instruction: Instruction) -> Unit): String {
val data = input... | 0 | Kotlin | 1 | 0 | 791dd54a4e23f937d5fc16d46d85577d91b1507a | 2,382 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day11.kt | adrianforsius | 573,044,406 | false | {"Kotlin": 68131} | import org.assertj.core.api.Assertions.assertThat
data class Monkey(
val items: MutableList<Long> = mutableListOf(),
val worry: (Long) -> Long,
var inspections: Long = 0,
)
data class MonkeyPart1(
val monkey: Monkey,
val next: (Long) -> Int,
)
data class MonkeyPart2(
val monkey: Monkey,
... | 0 | Kotlin | 0 | 0 | f65a0e4371cf77c2558d37bf2ac42e44eeb4bdbb | 5,555 | kotlin-2022 | Apache License 2.0 |
2021/src/Day05.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | import java.lang.Math.abs
// https://adventofcode.com/2021/day/5
fun main() {
fun part1() {
val lines = mutableListOf<Pair<Pair<Int, Int>, Pair<Int, Int>>>()
for (line in readInput("Day05")) {
val points = line.split(" -> ").map { points ->
val values = points.split(",").map { it.toInt() }
... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 3,091 | advent-of-code | Apache License 2.0 |
src/Day05.kt | mjossdev | 574,439,750 | false | {"Kotlin": 81859} | fun main() {
data class Move(val n: Int, val source: Int, val target: Int)
fun String.toMove(): Move {
val (n, source, target) = Regex("""move (\d+) from (\d+) to (\d+)""")
.matchEntire(this)!!
.groupValues
.drop(1)
.map { it.toInt() }
return Move... | 0 | Kotlin | 0 | 0 | afbcec6a05b8df34ebd8543ac04394baa10216f0 | 2,073 | advent-of-code-22 | Apache License 2.0 |
src/Day03.kt | BionicCa | 574,904,899 | false | {"Kotlin": 20039} | fun main() {
fun part1(input: List<String>): Int {
var totalScore = 0
for (rucksack in input) {
val chunks = rucksack.chunked(rucksack.length / 2)
val commonElements = findCommonCharacter(chunks[0].toCharArray(), chunks[1].toCharArray())
val score = commonElement... | 0 | Kotlin | 0 | 0 | ed8bda8067386b6cd86ad9704bda5eac81bf0163 | 1,488 | AdventOfCode2022 | Apache License 2.0 |
src/Day05.kt | ds411 | 573,543,582 | false | {"Kotlin": 16415} | fun main() {
fun part1(input: List<String>): String {
return runCrane(input, reversed = true)
}
fun part2(input: List<String>): String {
return runCrane(input, reversed = false)
}
// test if implementation meets criteria from the description, like:
val testInput = readInput("D... | 0 | Kotlin | 0 | 0 | 6f60b8e23ee80b46e7e1262723960af14670d482 | 1,940 | advent-of-code-2022 | Apache License 2.0 |
src/day14/Day14.kt | bartoszm | 572,719,007 | false | {"Kotlin": 39186} | package day14
import readInput
import toPair
fun main() {
println(solve1(parse(readInput("day14/test")), 500 to 0))
println(solve1(parse(readInput("day14/input")), 500 to 0))
println(solve2(parse(readInput("day14/test")), 500 to 0))
println(solve2(parse(readInput("day14/input")), 500 to 0))
}
typea... | 0 | Kotlin | 0 | 0 | f1ac6838de23beb71a5636976d6c157a5be344ac | 3,321 | aoc-2022 | Apache License 2.0 |
aoc/src/main/kotlin/com/bloidonia/aoc2023/day05/Main.kt | timyates | 725,647,758 | false | {"Kotlin": 45518, "Groovy": 202} | package com.bloidonia.aoc2023.day05
import com.bloidonia.aoc2023.lines
private const val example = """seeds: 79 14 55 13
seed-to-soil map:
50 98 2
52 50 48
soil-to-fertilizer map:
0 15 37
37 52 2
39 0 15
fertilizer-to-water map:
49 53 8
0 11 42
42 0 7
57 7 4
water-to-light map:
88 18 7
18 25 70
light-to-temperat... | 0 | Kotlin | 0 | 0 | 158162b1034e3998445a4f5e3f476f3ebf1dc952 | 2,707 | aoc-2023 | MIT License |
src/Day05.kt | D000L | 575,350,411 | false | {"Kotlin": 23716} | fun main() {
fun process(input: List<String>, withReverse: Boolean): String {
val stacks = input.takeWhile { it.isNotEmpty() }.dropLast(1)
.map {
it.replace(" ", " ")
.replace("[", "")
.replace("]", "")
}
val moves = ... | 0 | Kotlin | 0 | 0 | b733a4f16ebc7b71af5b08b947ae46afb62df05e | 1,341 | adventOfCode | Apache License 2.0 |
src/Day03.kt | mr3y-the-programmer | 572,001,640 | false | {"Kotlin": 8306} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { rucksack ->
rucksack
.chunked(rucksack.length / 2)
.let { it[0].intersect(it[1]) }
.calculatePriority()
}
}
fun part2(input: List<String>): Int {
retur... | 0 | Kotlin | 0 | 0 | 96d1567f38e324aca0cb692be3dae720728a383d | 1,054 | advent-of-code-2022 | Apache License 2.0 |
src/2022/Day07.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2022`
import java.io.File
import java.util.*
fun main() {
Day07().solve()
}
class Day07 {
data class Node (
val name: String,
val isDir: Boolean,
val parent: Node? = null,
val size: Long = 0,
val content: MutableMap<String, Node> = mutableMapOf()
)
{... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 3,160 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/tonnoz/adventofcode23/day4/Four.kt | tonnoz | 725,970,505 | false | {"Kotlin": 78395} | package com.tonnoz.adventofcode23.day4
import com.tonnoz.adventofcode23.day2.COLON
import com.tonnoz.adventofcode23.day2.SPACE
import com.tonnoz.adventofcode23.utils.readInput
import kotlin.math.pow
const val PIPE = "|"
object Four{
@JvmStatic
fun main(args: Array<String>) {
val input = "inputFour.txt".read... | 0 | Kotlin | 0 | 0 | d573dfd010e2ffefcdcecc07d94c8225ad3bb38f | 2,115 | adventofcode23 | MIT License |
src/aoc2023/Day02.kt | dayanruben | 433,250,590 | false | {"Kotlin": 79134} | package aoc2023
import readInput
import checkValue
fun main() {
val (year, day) = "2023" to "Day02"
fun gameSets(game: String) =
game.split(";").map {
it.trim().split(",").map {
val (cubesStr, color) = it.trim().split(" ")
val cubes = cubesS... | 1 | Kotlin | 2 | 30 | df1f04b90e81fbb9078a30f528d52295689f7de7 | 1,762 | aoc-kotlin | Apache License 2.0 |
src/Day04.kt | dragere | 440,914,403 | false | {"Kotlin": 62581} | import java.util.regex.Pattern
class Bingo(fie: String, num: String, var marked: Array<IntArray> = Array(5) { IntArray(5) { 0 } }) {
val field: List<List<Int>>
val numbers: List<Int>
var counter = 0
init {
numbers = num.split(",").map { it.toInt() }
field = fie.split("\r\n").map { it.... | 0 | Kotlin | 0 | 0 | 3e33ab078f8f5413fa659ec6c169cd2f99d0b374 | 2,934 | advent_of_code21_kotlin | Apache License 2.0 |
src/Day04.kt | kaeaton | 572,831,118 | false | {"Kotlin": 7766} | import kotlin.math.min
import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
var nestedRegions = 0
input.forEach {
//split into two
val elves = it.split(",")
// break down into the range for each elf
var elfRegion1 = (elves[0]... | 0 | Kotlin | 0 | 0 | c2a92c68bd5822c72c1075f055fc2163762d6deb | 2,526 | AoC-2022 | Apache License 2.0 |
ratio/src/main/kotlin/com/seanshubin/factor/analysis/ratio/Ratio.kt | SeanShubin | 202,797,257 | false | null | package com.seanshubin.factor.analysis.ratio
data class Ratio(val numerator: Int, val denominator: Int) : Comparable<Ratio> {
init {
require(denominator != 0){
"Denominator must not be zero in $numerator/$denominator"
}
}
operator fun plus(that: Ratio): Ratio {
val lcm =... | 0 | Kotlin | 0 | 0 | a0ae7f3f1a58b8263105a58c5cacfe31849d968f | 3,045 | factor-analysis | The Unlicense |
src/Day07.kt | Miguel1235 | 726,260,839 | false | {"Kotlin": 21105} | private enum class CardNames {
HIGH_CARD,
ONE_PAIR,
TWO_PAIR,
THREE_OF_A_KIND,
FULL_HOUSE,
FOUR_OF_A_KIND,
FIVE_OF_A_KIND
}
private enum class Letters {
T,
J,
Q,
K,
A,
}
private fun determineHandName(card: Map<Char, Int>): CardNames {
if (card.containsValue(5)) retu... | 0 | Kotlin | 0 | 0 | 69a80acdc8d7ba072e4789044ec2d84f84500e00 | 3,433 | advent-of-code-2023 | MIT License |
src/aoc2023/Day11.kt | dayanruben | 433,250,590 | false | {"Kotlin": 79134} | package aoc2023
import checkValue
import readInput
import kotlin.math.abs
fun main() {
val (year, day) = "2023" to "Day11"
fun sumPaths(input: List<String>, expansion: Int): Long {
val galaxies = mutableListOf<Galaxy>()
val galaxyRows = mutableSetOf<Int>()
val galaxyCols = mutableSetO... | 1 | Kotlin | 2 | 30 | df1f04b90e81fbb9078a30f528d52295689f7de7 | 2,064 | aoc-kotlin | Apache License 2.0 |
src/Day02.kt | filipradon | 573,512,032 | false | {"Kotlin": 6146} | import Result.Companion.toRightResult
import Shape.Companion.toLeftShape
import Shape.Companion.toRightShape
sealed interface Shape {
companion object {
fun Char.toLeftShape(): Shape {
return when (this) {
'A' -> Rock
'B' -> Paper
'C' -> Scissors
... | 0 | Kotlin | 0 | 0 | dbac44fe421e29ab2ce0703e5827e4645b38548e | 2,877 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/io/github/clechasseur/adventofcode2021/Day8.kt | clechasseur | 435,726,930 | false | {"Kotlin": 315943} | package io.github.clechasseur.adventofcode2021
import io.github.clechasseur.adventofcode2021.data.Day8Data
import io.github.clechasseur.adventofcode2021.util.permutations
object Day8 {
private val data = Day8Data.data
private val lineInfos = data.lines().map { it.toLineInfo() }
fun part1(): Int = lineIn... | 0 | Kotlin | 0 | 0 | 4b893c001efec7d11a326888a9a98ec03241d331 | 2,154 | adventofcode2021 | MIT License |
2022/src/main/kotlin/de/skyrising/aoc2022/day16/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2022.day16
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.objects.Object2IntMap
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
private fun parseInput(input: PuzzleInput): Triple<Object2IntMap<String>, Object2IntMap<Pair<String, String>>, Set<String>> {
val graph = Graph... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 2,685 | aoc | MIT License |
src/Day10.kt | Xacalet | 576,909,107 | false | {"Kotlin": 18486} | /**
* ADVENT OF CODE 2022 (https://adventofcode.com/2022/)
*
* Solution to day 10 (https://adventofcode.com/2022/day/10)
*
*/
fun main() {
fun part1(instructions: Sequence<Int>): Int {
return instructions
.runningFold(1) { acc, x -> acc + x }
.withIndex()
.filter {... | 0 | Kotlin | 0 | 0 | 5c9cb4650335e1852402c9cd1bf6f2ba96e197b2 | 1,100 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day21.kt | Avataw | 572,709,044 | false | {"Kotlin": 99761} | package aoc
fun solve21A(input: List<String>): Long {
val monkeys = input.parse()
val root = monkeys.first { it.name == "root" }
monkeys.solveRiddle(root)
return root.value!!
}
fun solve21B(input: List<String>): Long {
val monkeys = input.parse()
val root = monkeys.first { it.name == "roo... | 0 | Kotlin | 2 | 0 | 769c4bf06ee5b9ad3220e92067d617f07519d2b7 | 4,504 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/kr/co/programmers/P77485.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://github.com/antop-dev/algorithm/issues/253
class P77485 {
fun solution(rows: Int, columns: Int, queries: Array<IntArray>): IntArray {
// 숫자 채우기
var n = 1
val box = Array(rows + 1) { Array(columns + 1) { 0 } }
for (i in 1 until box.size) {
... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,360 | algorithm | MIT License |
aoc2022/day18.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2022
import utils.InputRetrieval
fun main() {
Day18.execute()
}
object Day18 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
// println("Part 2: ${part2(input)}")
}
private fun part1(input: List<Cube>): Int = input.sumOf { it.countSides... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 2,380 | Advent-Of-Code | MIT License |
src/Day08.kt | oleksandrbalan | 572,863,834 | false | {"Kotlin": 27338} | fun main() {
val input = readInput("Day08")
.filterNot { it.isEmpty() }
val rows = input.size
val columns = input.first().length
val matrix = IntMatrix(rows, columns) { row, column ->
input[row][column].digitToInt()
}
// Matrix with 0 and 1, where 1 represents that the tree is ... | 0 | Kotlin | 0 | 2 | 1493b9752ea4e3db8164edc2dc899f73146eeb50 | 3,538 | advent-of-code-2022 | Apache License 2.0 |
games-impl/src/commonMain/kotlin/net/zomis/games/common/cards/probabilities/CardAnalyze2.kt | Zomis | 125,767,793 | false | {"Kotlin": 1346310, "Vue": 212095, "JavaScript": 43020, "CSS": 4513, "HTML": 1459, "Shell": 801, "Dockerfile": 348} | package net.zomis.games.cards.probabilities
import net.zomis.games.cards.CardZone
import kotlin.math.floor
import kotlin.math.min
typealias CardPredicate<T> = (T) -> Boolean
class ZoneRuleDef<T>(val name: Int, val zone: CardZone<T>, val size: Int, val predicate: CardPredicate<T>) {
override fun toString(): String... | 89 | Kotlin | 5 | 17 | dd9f0e6c87f6e1b59b31c1bc609323dbca7b5df0 | 16,021 | Games | MIT License |
src/main/kotlin/com/jacobhyphenated/advent2023/day6/Day6.kt | jacobhyphenated | 725,928,124 | false | {"Kotlin": 121644} | package com.jacobhyphenated.advent2023.day6
import com.jacobhyphenated.advent2023.Day
import com.jacobhyphenated.advent2023.product
/**
* Day 6: Wait For It
*
* You are participating in a boat race. The boats are charged by pressing a button for a length of time.
* The longer the button is pressed, the faster the... | 0 | Kotlin | 0 | 0 | 90d8a95bf35cae5a88e8daf2cfc062a104fe08c1 | 2,798 | advent2023 | The Unlicense |
src/Day05/Day05.kt | Nathan-Molby | 572,771,729 | false | {"Kotlin": 95872, "Python": 13537, "Java": 3671} | package Day05
import readInput
import java.util.*
fun applyMovesToTowers(towers: List<Stack<Char>>, moves: List<String>, smartCrane: Boolean) {
for (move in moves) {
val moveItems = move.split("move ", " from ", " to ").filter {!it.isEmpty()}.map { it.toInt() }
val itemCountToMove = moveItems[0]
... | 0 | Kotlin | 0 | 0 | 750bde9b51b425cda232d99d11ce3d6a9dd8f801 | 2,757 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/aoc23/day07.kt | asmundh | 573,096,020 | false | {"Kotlin": 56155} | package aoc23
import runTask
import splitToPair
import utils.InputReader
import java.lang.IllegalArgumentException
import java.lang.IllegalStateException
fun day7part1(input: List<String>): Int {
val cards = input.getCards().sorted()
return cards.mapIndexed { idx, card ->
card.bid * (idx + 1)
}.su... | 0 | Kotlin | 0 | 0 | 7d0803d9b1d6b92212ee4cecb7b824514f597d09 | 2,931 | advent-of-code | Apache License 2.0 |
src/aoc2023/Day4.kt | RobertMaged | 573,140,924 | false | {"Kotlin": 225650} | package aoc2023
import utils.checkEquals
import utils.readInput
fun main(): Unit = with(Day4) {
part1(testInput).checkEquals(13)
part1(input)
.checkEquals(21485)
// .sendAnswer(part = 1, day = "4", year = 2023)
part2(testInput).checkEquals(30)
part2(input)
.checkEquals(1102437... | 0 | Kotlin | 0 | 0 | e2e012d6760a37cb90d2435e8059789941e038a5 | 2,320 | Kotlin-AOC-2023 | Apache License 2.0 |
src/Day02.kt | simonbirt | 574,137,905 | false | {"Kotlin": 45762} | fun main() {
val scores = mapOf("A" to 1, "B" to 2, "C" to 3, "X" to 1, "Y" to 2, "Z" to 3)
fun choose(them:Int, req:Int):Int {
return when (them) {
1 -> when (req) { 1 -> 3 2 -> 1 else -> 2}
2 -> when (req) { 1 -> 1 2 -> 2 else -> 3}
3 -> when (req) { 1 -> 2 2 -> 3 ... | 0 | Kotlin | 0 | 0 | 962eccac0ab5fc11c86396fc5427e9a30c7cd5fd | 1,237 | advent-of-code-2022 | Apache License 2.0 |
src/Day07.kt | mikrise2 | 573,939,318 | false | {"Kotlin": 62406} | data class File(val name: String, val size: Int)
class Directory(private val parent: Directory? = null) {
private val files = mutableListOf<File>()
var amountSize = 0
private set
fun addFile(file: File) {
files.add(file)
increaseSize(file.size)
}
private fun increaseSize(s... | 0 | Kotlin | 0 | 0 | d5d180eaf367a93bc038abbc4dc3920c8cbbd3b8 | 2,327 | Advent-of-code | Apache License 2.0 |
src/main/kotlin/tr/emreone/kotlin_utils/extensions/Combinatorics.kt | EmRe-One | 442,916,831 | false | {"Kotlin": 173543} | package tr.emreone.kotlin_utils.extensions
/**
* Generates all combinations of the elements of the given [Iterable] for the requested size.
* Note: combinations do not include all their permutations!
* @receiver the [Iterable] to take elements from
* @param size the size of the combinations to create
* @return a ... | 0 | Kotlin | 0 | 0 | aee38364ca1827666949557acb15ae3ea21881a1 | 3,814 | kotlin-utils | Apache License 2.0 |
src/Day07.kt | Cryosleeper | 572,977,188 | false | {"Kotlin": 43613} | import kotlin.math.min
private const val DISK_SIZE = 70000000
private const val UPDATE_SPACE_REQUIREMENT = 30000000
fun main() {
fun part1(input: List<String>): Int {
val root = input.parse()
return root.sumOfFoldersUnder100000()
}
fun part2(input: List<String>): Int {
val root =... | 0 | Kotlin | 0 | 0 | a638356cda864b9e1799d72fa07d3482a5f2128e | 3,220 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day11.kt | alex859 | 573,174,372 | false | {"Kotlin": 80552} | fun main() {
val testInput = readInput("Day11_test.txt")
check(testInput.day11Part1() == 10605)
// check(testInput.day10Part2() == )
val input = readInput("Day11.txt")
println(input.day11Part1())
// println(input.day10Part2())
}
private fun String.day11Part1(): Int {
val endGame = split("\n\... | 0 | Kotlin | 0 | 0 | fbbd1543b5c5d57885e620ede296b9103477f61d | 3,635 | advent-of-code-kotlin-2022 | Apache License 2.0 |
advent-of-code-2022/src/main/kotlin/eu/janvdb/aoc2022/day15/SensorBeacon.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2022.day15
import eu.janvdb.aocutil.kotlin.point2d.Point2D
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
val PATTERN = Regex("Sensor at x=(-?\\d+), y=(-?\\d+): closest beacon is at x=(-?\\d+), y=(-?\\d+)")
data class SensorBeacon(val sensor: Point2D, val beacon: Point2D) {... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,771 | advent-of-code | Apache License 2.0 |
src/Day01.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | fun main() {
fun splitByEmptyLines(input: List<String>): List<List<String>> {
val emptyLinesPositions = input.mapIndexedNotNull { index, line ->
if (line.isBlank()) index else null
}
return buildList {
var currentStart = 0
for (idx in emptyLinesPositions... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 1,483 | aoc2022 | Apache License 2.0 |
src/test/kotlin/com/igorwojda/list/maxsublistsum/MaxSubListSumSolution.kt | tmdroid | 347,052,411 | true | {"Kotlin": 199701} | package com.igorwojda.list.maxsublistsum
// Time Complexity: O(n)
// Space Complexity: O(1)
// Use "sliding window" - store sum in single variable and with each iteration add (current item)
// and remove (first item before current sub-list)
private object Solution1 {
private fun maxSubListSum(list: List<Int>, n: I... | 0 | Kotlin | 2 | 0 | f82825274ceeaf3bef81334f298e1c7abeeefc99 | 2,232 | kotlin-puzzles | MIT License |
src/Day08.kt | DiamondMiner88 | 573,073,199 | false | {"Kotlin": 26457, "Rust": 4093, "Shell": 188} | fun main() {
val input = readInput("input/day08.txt")
.split("\n")
.filter { it.isNotBlank() }
val map: List<List<Int>> = input.map { row ->
row.toList().map { it.digitToInt() }
}
val size = map.size
val visibleMap = map.mapIndexed { rowI, row ->
row.mapIndexed { c... | 0 | Kotlin | 0 | 0 | 55bb96af323cab3860ab6988f7d57d04f034c12c | 2,556 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Problem5.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | import kotlin.math.floor
import kotlin.math.log10
import kotlin.math.pow
import kotlin.math.sqrt
/**
* Smallest multiple
*
* 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
*
* What is the smallest positive number that is evenly divisible by all of the nu... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 1,883 | project-euler | MIT License |
src/main/kotlin/org/sjoblomj/adventofcode/day8/Visualiser.kt | sjoblomj | 161,537,410 | false | null | package org.sjoblomj.adventofcode.day8
internal fun visualise(licenseFile: String, tree: Tree): String {
val lengthOfOnePosition = 3
val header = licenseFile.split(" ").joinToString("") { it.padStart(lengthOfOnePosition) }
val lines = visualise(tree, 0, lengthOfOnePosition).sortedBy { it.level }
val numberOfL... | 0 | Kotlin | 0 | 0 | 80db7e7029dace244a05f7e6327accb212d369cc | 1,428 | adventofcode2018 | MIT License |
src/Day25.kt | rod41732 | 572,917,438 | false | {"Kotlin": 85344} |
fun main() {
fun part1(input: List<String>): String {
return toSNAFU(
input.map(::parseSNAFU).sum()
)
}
val testInput = readInput("Day25_test")
println(part1(testInput))
check(part1(testInput) == "2=-1=0")
check(parseSNAFU("1121-1110-1=0") == 314159265L)
check... | 0 | Kotlin | 0 | 0 | 1d2d3d00e90b222085e0989d2b19e6164dfdb1ce | 1,459 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day05.kt | hufman | 573,586,479 | false | {"Kotlin": 29792} |
data class Instruction(val count: Int, val src: Int, val dest: Int) {
companion object {
val matcher = Regex("""move (\d+) from (\d+) to (\d+)""")
fun fromString(input: String): Instruction {
val result = matcher.matchEntire(input)!!
return Instruction(result.groupValues[1].toInt(), result.groupValues[2].to... | 0 | Kotlin | 0 | 0 | 1bc08085295bdc410a4a1611ff486773fda7fcce | 1,910 | aoc2022-kt | Apache License 2.0 |
advent-of-code-2022/src/main/kotlin/year_2022/Day09.kt | rudii1410 | 575,662,325 | false | {"Kotlin": 37749} | package year_2022
import util.Runner
fun main() {
fun Pair<Int, Int>.move(move: Pair<Int, Int>): Pair<Int, Int> {
return copy(first = first + move.first, second = second + move.second)
}
fun getDirection(a: Int, b: Int) = if (a > b) 1 else if (a < b) -1 else 0
val zero = Pair(0, 0)
val mo... | 1 | Kotlin | 0 | 0 | ab63e6cd53746e68713ddfffd65dd25408d5d488 | 1,862 | advent-of-code | Apache License 2.0 |
src/y2016/Day07.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2016
import util.readInput
object Day07 {
fun part1(input: List<String>): Int {
return input.count {
supportTls(it)
}
}
private fun supportTls(ip: String): Boolean {
val (supernet, hypernet) = ip.split(Regex("[\\[\\]]"))
.mapIndexed { index, s ->... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 2,118 | advent-of-code | Apache License 2.0 |
src/day07/Day07.kt | zypus | 573,178,215 | false | {"Kotlin": 33417, "Shell": 3190} | package day07
import AoCTask
// https://adventofcode.com/2022/day/7
sealed interface Command
sealed interface TreeNode {
val name: String
val size: Int
}
sealed class CmdLine {
data class CdCommand(val path: String): CmdLine(), Command
object LsCommand: CmdLine(), Command
data class File(overri... | 0 | Kotlin | 0 | 0 | f37ed8e9ff028e736e4c205aef5ddace4dc73bfc | 4,223 | aoc-2022 | Apache License 2.0 |
src/Day01.kt | bin-wang | 573,219,628 | false | {"Kotlin": 4145} | fun main() {
fun findProductWithSum(nums: List<Int>, target: Int): Int? {
var head = 0
var tail = nums.size - 1
while (head < tail) {
val sum = nums[head] + nums[tail]
when {
sum < target -> head++
sum > target -> tail--
... | 0 | Kotlin | 0 | 0 | 929f812efb37d5aea34e741510481ca3fab0c3da | 1,311 | aoc20-kt | Apache License 2.0 |
src/Day09.kt | tomoki1207 | 572,815,543 | false | {"Kotlin": 28654} | import Motion.*
import kotlin.math.abs
import kotlin.math.sign
enum class Motion {
Up, Down, Left, Right;
companion object {
fun from(from: String) = when (from) {
"U" -> Up
"D" -> Down
"L" -> Left
"R" -> Right
else -> throw Error("Unknown mo... | 0 | Kotlin | 0 | 0 | 2ecd45f48d9d2504874f7ff40d7c21975bc074ec | 2,194 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/com/ncorti/aoc2023/Day12.kt | cortinico | 723,409,155 | false | {"Kotlin": 76642} | package com.ncorti.aoc2023
fun main() {
val memo = mutableMapOf<Triple<Int, Int, Int>, Long>()
fun score(pattern: CharArray, numberList: List<Int>, idxPattern: Int, idxNumber: Int, bangCount: Int): Long {
val input = Triple(idxPattern, idxNumber, bangCount)
if (input in memo) {
re... | 1 | Kotlin | 0 | 1 | 84e06f0cb0350a1eed17317a762359e9c9543ae5 | 2,221 | adventofcode-2023 | MIT License |
src/day7/Day07.kt | HGilman | 572,891,570 | false | {"Kotlin": 109639, "C++": 5375, "Python": 400} | package day7
import day7.Day.File.Companion.isFile
import day7.Day.File.Companion.toFile
import day7.Day.Folder.Companion.isFolder
import day7.Day.Folder.Companion.toFolder
import day7.Day.buildTree
import readInput
import java.util.Stack
fun main() {
val testInput = readInput("day7/Day07_test")
val testRoot... | 0 | Kotlin | 0 | 1 | d05a53f84cb74bbb6136f9baf3711af16004ed12 | 5,079 | 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.