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/Day03.kt | LesleySommerville-Ki | 577,718,331 | false | {"Kotlin": 9590} | fun main() {
fun getItemPriority(char: Char): Int {
val lowerCase = "abcdefghijklmnopqrstuvwxyz"
val upperCase = "abcdefghijklmnopqrstuvwxyz".toUpperCase()
return if (char.isUpperCase() ) upperCase.indexOf(char) + 27 else {
lowerCase.indexOf(char) + 1
}
}
data cl... | 0 | Kotlin | 0 | 0 | ea657777d8f084077df9a324093af9892c962200 | 1,867 | AoC | Apache License 2.0 |
app/src/main/kotlin/day18/Day18.kt | W3D3 | 572,447,546 | false | {"Kotlin": 159335} | package day18
import common.InputRepo
import common.readSessionCookie
import common.solve
import util.Pos3D
fun main(args: Array<String>) {
val day = 18
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay18Part1, ::solveDay18Part2)
}
fun solveDay18Part1(input: Lis... | 0 | Kotlin | 0 | 0 | 34437876bf5c391aa064e42f5c984c7014a9f46d | 2,249 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/codes/jakob/aoc/solution/Day09.kt | The-Self-Taught-Software-Engineer | 433,875,929 | false | {"Kotlin": 56277} | package codes.jakob.aoc.solution
import codes.jakob.aoc.shared.Grid
object Day09 : Solution() {
override fun solvePart1(input: String): Any {
val grid: Grid<Int> = Grid(parseInput(input))
return grid.getLowPoints().sumOf { 1 + it.value }
}
override fun solvePart2(input: String): Any {
... | 0 | Kotlin | 0 | 6 | d4cfb3479bf47192b6ddb9a76b0fe8aa10c0e46c | 1,562 | advent-of-code-2021 | MIT License |
src/main/kotlin/day24.kt | gautemo | 725,273,259 | false | {"Kotlin": 79259} | import shared.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun main() {
val input = Input.day(24)
println(day24A(input))
println(day24B(input))
}
fun day24A(input: Input, min: Long = 200000000000000, max: Long = 400000000000000): Int {
val hailstones = input.lines.map { line ... | 0 | Kotlin | 0 | 0 | 6862b6d7429b09f2a1d29aaf3c0cd544b779ed25 | 4,011 | AdventOfCode2023 | MIT License |
src/Day07.kt | oleskrede | 574,122,679 | false | {"Kotlin": 24620} | fun main() {
fun part1(input: List<String>): Long {
val maxDirSize = 100_000
val fs = FileSystem()
fs.recreateFromBrowsingHistory(input)
val dirsWithSizeBelowMax = fs.findDirs { it.size < maxDirSize }
return dirsWithSizeBelowMax.sumOf { it.size }
}
fun part2(input: ... | 0 | Kotlin | 0 | 0 | a3484088e5a4200011335ac10a6c888adc2c1ad6 | 3,628 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2015/2015-14.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2015
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
import kotlin.math.min
fun main() {
val input = readInputLines(2015, "14-input")
val test1 = readInputLines(2015, "14-test1")
println("Part1:")
part1... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 2,398 | advent-of-code | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1802/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1802
/**
* LeetCode page: [1802. Maximum Value at a Given Index in a Bounded Array](https://leetcode.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/);
*/
class Solution {
/* Complexity:
* Time O(Log(maxSum)) and Space O(1);
*/
fun maxValue(n: In... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,646 | hj-leetcode-kotlin | Apache License 2.0 |
src/net/sheltem/aoc/y2022/Day02.kt | jtheegarten | 572,901,679 | false | {"Kotlin": 178521} | package net.sheltem.aoc.y2022
import net.sheltem.common.readInput
import net.sheltem.aoc.y2022.RPS.PAPER
import net.sheltem.aoc.y2022.RPS.ROCK
import net.sheltem.aoc.y2022.RPS.SCISSORS
import net.sheltem.aoc.y2022.Result.DRAW
import net.sheltem.aoc.y2022.Result.LOSS
import net.sheltem.aoc.y2022.Result.WIN
import kotli... | 0 | Kotlin | 0 | 0 | ac280f156c284c23565fba5810483dd1cd8a931f | 2,572 | aoc | Apache License 2.0 |
src/Day05/day05.kt | NST-d | 573,224,214 | false | null | package Day05
import utils.*
import java.util.*
fun main() {
fun parseInput(input: String): Pair<Array<Stack<Char>>, List<String>> {
val split = input.split("\n\n".toRegex(), limit = 2)
val cratesString = split[0].split("\n").toMutableList()
val moves = split[1].split("\n")
val a... | 0 | Kotlin | 0 | 0 | c4913b488b8a42c4d7dad94733d35711a9c98992 | 2,094 | aoc22 | Apache License 2.0 |
src/Day06.kt | rod41732 | 572,917,438 | false | {"Kotlin": 85344} | class Multiset<T> {
private val unique: MutableSet<T> = mutableSetOf()
private val count: MutableMap<T, Int> = mutableMapOf()
fun add(v: T) {
count[v] = (count[v] ?: 0) + 1
if (count[v] == 1) unique.add(v)
}
fun remove(v: T) {
count[v] = (count[v] ?: 0) - 1
if (count... | 0 | Kotlin | 0 | 0 | 1d2d3d00e90b222085e0989d2b19e6164dfdb1ce | 1,740 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/se/brainleech/adventofcode/aoc2021/Aoc2021Day10.kt | fwangel | 435,571,075 | false | {"Kotlin": 150622} | package se.brainleech.adventofcode.aoc2021
import se.brainleech.adventofcode.compute
import se.brainleech.adventofcode.readLines
import se.brainleech.adventofcode.verify
import java.util.*
class Aoc2021Day10 {
companion object {
private val BUDDIES = mapOf(
'(' to ')',
'[' to ']',... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 2,634 | adventofcode | MIT License |
solution/kotlin/aoc/src/main/kotlin/codes/jakob/aoc/Day09.kt | loehnertz | 573,145,141 | false | {"Kotlin": 53239} | package codes.jakob.aoc
import codes.jakob.aoc.shared.Coordinates
import codes.jakob.aoc.shared.ExpandedDirection
import codes.jakob.aoc.shared.ExpandedDirection.*
import codes.jakob.aoc.shared.splitMultiline
import codes.jakob.aoc.shared.toPair
class Day09 : Solution() {
override fun solvePart1(input: String): A... | 0 | Kotlin | 0 | 0 | ddad8456dc697c0ca67255a26c34c1a004ac5039 | 2,599 | advent-of-code-2022 | MIT License |
src/main/kotlin/g2201_2300/s2245_maximum_trailing_zeros_in_a_cornered_path/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2201_2300.s2245_maximum_trailing_zeros_in_a_cornered_path
// #Medium #Array #Matrix #Prefix_Sum #2023_06_27_Time_888_ms_(100.00%)_Space_79.6_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
fun maxTrailingZeros(grid: Array<IntArray>): Int {
val m = grid.size
val n = grid[0].size
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,375 | LeetCode-in-Kotlin | MIT License |
src/Day13.kt | bananer | 434,885,332 | false | {"Kotlin": 36979} | data class Dot(
val x: Int,
val y: Int,
)
enum class FoldAxis { X, Y }
data class FoldInstruction(
val axis: FoldAxis,
val coordinate: Int,
)
fun main() {
fun parseInput(input: List<String>): Pair<Set<Dot>, List<FoldInstruction>> {
val dots = mutableSetOf<Dot>()
val foldInstructi... | 0 | Kotlin | 0 | 0 | 98f7d6b3dd9eefebef5fa3179ca331fef5ed975b | 3,121 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/g1901_2000/s1928_minimum_cost_to_reach_destination_in_time/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1901_2000.s1928_minimum_cost_to_reach_destination_in_time
// #Hard #Dynamic_Programming #Graph #2023_06_20_Time_414_ms_(100.00%)_Space_53.3_MB_(100.00%)
import java.util.PriorityQueue
class Solution {
fun minCost(maxTime: Int, edges: Array<IntArray>, passingFees: IntArray): Int {
val pq = Priori... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,950 | LeetCode-in-Kotlin | MIT License |
src/Day10.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | private sealed class Instruction {
object noop : Instruction()
data class addx(val amount: Int) : Instruction()
}
private fun String.toInstruction(): Instruction {
return if (this == "noop") {
Instruction.noop
} else {
this.split(" ").let { (addx, count) ->
if (addx != "addx... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 3,164 | aoc22-kotlin | Apache License 2.0 |
src/day16/Day16.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day16
import com.github.shiguruikai.combinatoricskt.combinations
import readInput
class Graph(lines: List<String>) {
private data class Valve(val name: String, val flowRate: Int) {
override fun toString() = "$name($flowRate)"
}
private val graph = hashMapOf<Valve, List<Valve>>()
priva... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 5,198 | aoc-2022-kotlin | Apache License 2.0 |
src/Day02.kt | nguyendanv | 573,066,311 | false | {"Kotlin": 18026} | fun main() {
val beatsMap = mapOf(
1 to 3,
2 to 1,
3 to 2
)
val losesMap = beatsMap
.map { (k, v) -> v to k }
.toMap()
val pointValues = mapOf(
"A" to 1,
"B" to 2,
"C" to 3,
"X" to 1,
"Y" to 2,
"Z" to 3
)
... | 0 | Kotlin | 0 | 0 | 376512583af723b4035b170db1fa890eb32f2f0f | 1,486 | advent2022 | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2018/Day22.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2018
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
/** https://adventofcode.com/2018/day/22 */
class Day22 : Solver {
override fun solve(lines: List<String>): Result {
val depth = lines[0].substringAfter("depth: ").toInt()
val targetCoords = lines[1].substringAfter("target: "... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 3,601 | euler | Apache License 2.0 |
src/aoc2022/day09/AoC09.kt | Saxintosh | 576,065,000 | false | {"Kotlin": 30013} | package aoc2022.day09
import readLines
import kotlin.math.abs
data class P(val x: Int, val y: Int) {
fun up() = P(x + 1, y)
fun down() = P(x - 1, y)
fun left() = P(x, y - 1)
fun right() = P(x, y + 1)
}
class Board(private val len: Int) {
private var rope = Array(len) { P(0, 0) }
private var head
get() = rope... | 0 | Kotlin | 0 | 0 | 877d58367018372502f03dcc97a26a6f831fc8d8 | 2,199 | aoc2022 | Apache License 2.0 |
aoc21/pathutils/lib.kt | viktormalik | 436,281,279 | false | {"Rust": 227300, "Go": 86273, "OCaml": 82410, "Kotlin": 78968, "Makefile": 13967, "Roff": 9981, "Shell": 2796} | package pathutils
data class Pos(val x: Int, val y: Int)
data class Path(val ps: List<Pos>, val dst: Int) {
fun len(): Int = ps.size - 1
}
fun fourNeighs(
pos: Pos,
xMin: Int? = null,
xMax: Int? = null,
yMin: Int? = null,
yMax: Int? = null
): List<Pos> =
listOf(
Pos(pos.x + 1, pos.... | 0 | Rust | 1 | 0 | f47ef85393d395710ce113708117fd33082bab30 | 2,062 | advent-of-code | MIT License |
src/year2021/Day12.kt | drademacher | 725,945,859 | false | {"Kotlin": 76037} | package year2021
import readLines
private var counter = 0
fun main() {
val input = parseInput(readLines("2021", "day12"))
val testInput = parseInput(readLines("2021", "day12_test"))
check(part1(testInput) == 226)
println("Part 1:" + part1(input))
check(part2(testInput) == 3509)
println("Par... | 0 | Kotlin | 0 | 0 | 4c4cbf677d97cfe96264b922af6ae332b9044ba8 | 1,905 | advent_of_code | MIT License |
src/cn/leetcode/codes/simple105/Simple105.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple105
import cn.leetcode.codes.common.TreeNode
import cn.leetcode.codes.outTreeNote
fun main() {
val preOrder = intArrayOf(3, 9, 20, 15, 7)
val inOrder = intArrayOf(9, 3, 15, 20, 7)
var treeNode:TreeNode? = null
treeNode = buildTree(preOrder, inOrder)
// treeNode = S... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 2,388 | LeetCodeSimple | Apache License 2.0 |
src/day14/Day14.kt | palpfiction | 572,688,778 | false | {"Kotlin": 38770} | package day14
import readInput
data class Coordinate(val x: Int, val y: Int) {
override fun toString() = "($x, $y)"
}
fun main() {
val sandSource = Coordinate(500, 0)
fun getRangeOf(first: Int, second: Int): IntProgression =
if (first < second) first.rangeTo(second) else second.rangeTo(first).... | 0 | Kotlin | 0 | 0 | 5b79ec5fa4116e496cd07f0c7cea7dabc8a371e7 | 3,961 | advent-of-code | Apache License 2.0 |
advent-of-code2016/src/main/kotlin/day04/Advent4.kt | REDNBLACK | 128,669,137 | false | null | package day04
import parseInput
import splitToLines
import java.util.*
/**
--- Day 4: Security Through Obscurity ---
Finally, you come across an information kiosk with a list of rooms. Of course, the list is encrypted and full of decoy data, but the instructions to decode the list are barely hidden nearby. Better re... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 3,672 | courses | MIT License |
src/main/kotlin/_2022/Day2.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2022
import aoc
import parseInput
import java.util.regex.Pattern
private val INPUT_REGEX = Pattern.compile("([A-C]) ([X-Z])")
fun main() {
aoc(2022, 2) {
aocRun { processPart1(it) }
aocRun { processPart2(it) }
}
}
private fun processPart1(input: String): Long {
val parsedInput =... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 2,709 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Day09.kt | slawa4s | 573,050,411 | false | {"Kotlin": 20679} | import kotlin.math.sign
class Coordinates(var x: Int, var y: Int) {
fun plus(other: Coordinates) {
x += other.x
y += other.y
}
fun dist(other: Coordinates): Coordinates {
return Coordinates(this.x - other.x, this.y - other.y)
}
}
private val allMoves = mapOf(
"U" to Coordi... | 0 | Kotlin | 0 | 0 | cd8bbbb3a710dc542c2832959a6a03a0d2516866 | 2,402 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day7.kt | sicruse | 315,469,617 | false | null | package days
class Day7 : Day(7) {
// The target of our investigation is...
private val targetBag = "shiny gold"
// create a "Bag name" lookup map for convenience
private val bags: Map<String, List<Rule>> by lazy {
inputList
.map { description -> bagFromDescription(description) }
... | 0 | Kotlin | 0 | 0 | 9a07af4879a6eca534c5dd7eb9fc60b71bfa2f0f | 2,722 | aoc-kotlin-2020 | Creative Commons Zero v1.0 Universal |
src/Day03.kt | Sghazzawi | 574,678,250 | false | {"Kotlin": 10945} | val priorities = ('a'..'z') + ('A'..'Z')
fun String.getPriority(priorities: List<Char>): Int {
val firstCompartment = substring(0 until (length / 2)).toSet()
val secondCompartment = substring(length / 2 until length)
return priorities.indexOf(secondCompartment.first { firstCompartment.contains(it) }) + 1
}... | 0 | Kotlin | 0 | 0 | a26111fa1bcfec28cc43a2f48877455b783acc0d | 887 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/co/csadev/advent2021/Day14.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2021 by <NAME>
* Advent of Code 2021, Day 14
* Problem Description: http://adventofcode.com/2021/day/14
*/
package co.csadev.advent2021
import co.csadev.adventOfCode.BaseDay
import co.csadev.adventOfCode.Resources.resourceAsList
class Day14(override val input: List<String> = resourceAsList("21... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 2,641 | advent-of-kotlin | Apache License 2.0 |
leetcode/3Sum.kt | migafgarcia | 63,630,233 | false | {"C++": 121354, "Kotlin": 38202, "C": 34840, "Java": 23043, "C#": 10596, "Python": 8343} | import java.util.*
class Solution {
fun threeSum(nums: IntArray): List<List<Int>> {
val solution = HashSet<Triple<Int, Int, Int>>()
for (i in IntRange(0, nums.lastIndex)) {
val sols = twoSum(nums, IntRange(i + 1, nums.lastIndex), -nums[i])
sols.forEach { pair ->
... | 0 | C++ | 3 | 9 | 82f5e482c0c3c03fd39e46aa70cab79391ed2dc5 | 1,603 | programming-challenges | MIT License |
src/day05/Day05.kt | GrinDeN | 574,680,300 | false | {"Kotlin": 9920} | fun main() {
fun parseMovements(input: List<String>): List<Triple<Int, Int, Int>> {
return input
.map { it.split(" ") }
.map { Triple(it[1].toInt(), it[3].toInt(), it[5].toInt()) }
}
fun singleMove(stacks: List<ArrayDeque<Char>>, from: Int, to: Int, numberOfCrates: Int) {
... | 0 | Kotlin | 0 | 0 | f25886a7a3112c330f80ec2a3c25a2ff996d8cf8 | 2,335 | aoc-2022 | Apache License 2.0 |
src/Day05.kt | flex3r | 572,653,526 | false | {"Kotlin": 63192} | import java.util.Stack
fun main() {
val testInput = readInput("Day05_test")
check(part1(testInput) == "CMZ")
check(part2(testInput) == "MCD")
val input = readInput("Day05")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>): String {
val (crateInput, proc... | 0 | Kotlin | 0 | 0 | 8604ce3c0c3b56e2e49df641d5bf1e498f445ff9 | 1,878 | aoc-22 | Apache License 2.0 |
src/Day15.kt | arhor | 572,349,244 | false | {"Kotlin": 36845} | import kotlin.math.abs
import kotlin.math.absoluteValue
import kotlin.streams.asStream
import kotlin.system.measureTimeMillis
//fun main() {
// val input = readInput {}
//
// println("Part 1: ${solvePuzzle2(input)}")
//}
private const val TARGET_Y = 2_000_000
private const val LIMIT = 4_000_000
private val inpu... | 0 | Kotlin | 0 | 0 | 047d4bdac687fd6719796eb69eab2dd8ebb5ba2f | 8,702 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day03.kt | WilsonSunBritten | 572,338,927 | false | {"Kotlin": 40606} | fun main() {
fun part1(input: List<String>): Int {
return input.map { rucksack ->
println(rucksack)
val firstHalf = rucksack.take(rucksack.length / 2).toList()
val secondHalf = rucksack.takeLast(rucksack.length / 2).toList()
val matchingCharacters = firstHalf.... | 0 | Kotlin | 0 | 0 | 363252ffd64c6dbdbef7fd847518b642ec47afb8 | 1,361 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/com/ncorti/aoc2023/Day08.kt | cortinico | 723,409,155 | false | {"Kotlin": 76642} | package com.ncorti.aoc2023
fun main() {
fun play(pattern: CharArray, graph: Map<String, Pair<String, String>>): Int {
var idx = 0
var current = "AAA"
var steps = 0
while (current != "ZZZ") {
current = if (pattern[idx] == 'L') {
graph[current]!!.first
... | 1 | Kotlin | 0 | 1 | 84e06f0cb0350a1eed17317a762359e9c9543ae5 | 2,086 | adventofcode-2023 | MIT License |
src/Day13.kt | michaelYuenAE | 573,094,416 | false | {"Kotlin": 74685} | class Day13(lines: List<String>) {
private val packets = lines.mapNotNull { if (it.isNotEmpty()) it.toPacket() else null }
fun part1(): Int = packets.chunked(2) { (a, b) -> a <= b }.withIndex().filter { it.value }.sumOf { it.index + 1 }
fun part2(): Int {
var x = 1
var y = 1
for (p... | 0 | Kotlin | 0 | 0 | ee521263dee60dd3462bea9302476c456bfebdf8 | 3,207 | advent22 | Apache License 2.0 |
src/day22/Day22.kt | gautemo | 317,316,447 | false | null | package day22
import shared.getLines
fun combat(input: List<String>): Int{
val (player1, player2) = mapPlayers(input)
while (player1.isNotEmpty() && player2.isNotEmpty()){
if(player1.first() > player2.first()){
player1.add(player1.removeAt(0))
player1.add(player2.removeAt(0))
... | 0 | Kotlin | 0 | 0 | ce25b091366574a130fa3d6abd3e538a414cdc3b | 2,430 | AdventOfCode2020 | MIT License |
aoc2022/day12.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2022
import utils.InputRetrieval
fun main() {
Day12.execute()
}
object Day12 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
private fun part1(input: Graph): Int {
calculateShortestPathFromS... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 3,973 | Advent-Of-Code | MIT License |
advent-of-code-2022/src/Day04.kt | osipxd | 572,825,805 | false | {"Kotlin": 141640, "Shell": 4083, "Scala": 693} | fun main() {
val testInput = readInput("Day04_test")
check(part1(testInput) == 2)
val input = readInput("Day04")
println("Part 1: " + part1(input))
println("Part 2: " + part2(input))
}
private fun part1(input: Sequence<List<IntRange>>): Int = input.count { (a, b) -> b in a || a in b }
private fun ... | 0 | Kotlin | 0 | 5 | 6a67946122abb759fddf33dae408db662213a072 | 984 | advent-of-code | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions11.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
fun test11() {
printlnResult(intArrayOf(1, 0, 1))
printlnResult(intArrayOf(1, 1, 0, 1))
printlnResult(intArrayOf(1, 1, 0, 1, 0, 0, 1))
}
/**
* Questions 11: Find the counts of consistent sub-arrays that their counts of
* 1 and 0 equal in an IntArray that just cont... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,408 | Algorithm | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/longest_string_without_consequetive_chars/LongestString.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.longest_string_without_consequetive_chars
import datsok.shouldEqual
import org.junit.Test
import java.util.*
/**
* https://leetcode.com/discuss/interview-question/330356/Amazon-or-Online-Assessment-2019-or-Longest-string-without-3-consecutive-characters
*/
class LongestStringTests {
... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,877 | katas | The Unlicense |
src/main/kotlin/de/jball/aoc2022/day13/Day13.kt | fibsifan | 573,189,295 | false | {"Kotlin": 43681} | package de.jball.aoc2022.day13
import de.jball.aoc2022.Day
class Day13(test: Boolean = false) : Day<Int>(test, 13, 140) {
private val pairs = input.chunked(3).map {Pair(parsePacket(it[0]), parsePacket(it[1])) }
private fun parsePacket(packetString: String): Packet {
var workingString = packetString
... | 0 | Kotlin | 0 | 3 | a6d01b73aca9b54add4546664831baf889e064fb | 3,389 | aoc-2022 | Apache License 2.0 |
code-sample-kotlin/algorithms/src/main/kotlin/com/codesample/leetcode/easy/111_minimumDepthTree.kt | aquatir | 76,377,920 | false | {"Java": 674809, "Python": 143889, "Kotlin": 112192, "Haskell": 57852, "Elixir": 33284, "TeX": 20611, "Scala": 17065, "Dockerfile": 6314, "HTML": 4714, "Shell": 387, "Batchfile": 316, "Erlang": 269, "CSS": 97} | package com.codesample.leetcode.easy
fun main() {
val s = Solution()
//Input: root = [3,9,20,null,null,15,7]
//Output: 2
val root2 = TreeNode(3)
root2.left = TreeNode(9)
root2.right = TreeNode(20)
root2.right!!.left = TreeNode(15)
root2.right!!.right = TreeNode(7)
println(s.minDe... | 1 | Java | 3 | 6 | eac3328ecd1c434b1e9aae2cdbec05a44fad4430 | 2,281 | code-samples | MIT License |
src/Day21.kt | i-tatsenko | 575,595,840 | false | {"Kotlin": 90644} | import java.lang.IllegalArgumentException
private interface Num {
fun eval(): Long
fun init(monkeys: Map<String, Num>) {}
val isHumn: Boolean
fun balance(value: Long): Long
}
private data class ScalarMonkey(val scalar: Long, override val isHumn: Boolean) : Num {
override fun eval(): Long = scala... | 0 | Kotlin | 0 | 0 | 0a9b360a5fb8052565728e03a665656d1e68c687 | 3,231 | advent-of-code-2022 | Apache License 2.0 |
src/Lesson5PrefixSums/MinAvgTwoSlice.kt | slobodanantonijevic | 557,942,075 | false | {"Kotlin": 50634} | /**
* 100/100
* @param A
* @return
*/
fun solution(A: IntArray): Int {
val prefixSums = getPrefixSums(A)
var minAvg = Float.MAX_VALUE
var minPos = 0
for (i in A.indices) {
if (i < A.size - 1) {
val avg = (prefixSums[i + 2] - prefixSums[i]) / 2.0f //((i + 1) - i) + 1 = 2
... | 0 | Kotlin | 0 | 0 | 155cf983b1f06550e99c8e13c5e6015a7e7ffb0f | 2,624 | Codility-Kotlin | Apache License 2.0 |
src/Day07.kt | jorander | 571,715,475 | false | {"Kotlin": 28471} | import java.util.*
import kotlin.collections.ArrayList
fun main() {
val day = "Day07"
data class Directory(val name: String, var size: Int = 0)
fun parseDirectorySizes(input: List<String>): List<Directory> {
fun String.toFileSize() = split(" ")[0].toInt()
data class State(val path: Sta... | 0 | Kotlin | 0 | 0 | 1681218293cce611b2c0467924e4c0207f47e00c | 2,804 | advent-of-code-2022 | Apache License 2.0 |
src/day08/Day08.kt | gr4cza | 572,863,297 | false | {"Kotlin": 93944} | package day08
import readInput
private fun Array<Array<Int>>.checkLeft(column: Int, row: Int): Boolean {
val selectedColumns = (0 until column).map {
this[row][it]
}
return selectedColumns.any { it >= this[row][column] }.not()
}
private fun Array<Array<Int>>.checkRight(column: Int, row: Int): Bo... | 0 | Kotlin | 0 | 0 | ceca4b99e562b4d8d3179c0a4b3856800fc6fe27 | 3,447 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2021/Day19.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2021
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.Point3D
import com.chriswk.aoc.util.pairs
import com.chriswk.aoc.util.report
class Day19 : AdventDay(2021, 19) {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day = Day19... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,821 | adventofcode | MIT License |
src/Day09.kt | ChAoSUnItY | 572,814,842 | false | {"Kotlin": 19036} | import kotlin.math.abs
import kotlin.math.sign
fun main() {
data class Position(val x: Int = 0, val y: Int = 0) {
fun offset(x: Int = 0, y: Int = 0): Position =
copy(x = this.x + x, y = this.y + y)
}
data class Instruction(val direction: Char, val steps: Int)
fun processData(data:... | 0 | Kotlin | 0 | 3 | 4fae89104aba1428820821dbf050822750a736bb | 1,994 | advent-of-code-2022-kt | Apache License 2.0 |
src/Day05_SupplyStacks.kt | raipc | 574,467,742 | false | {"Kotlin": 9511} | fun main() {
checkAndSolve("Day05", "CMZ") { solve(it.iterator(), MoveStrategy.ONE_BY_ONE) }
checkAndSolve("Day05", "MCD") { solve(it.iterator(), MoveStrategy.ALL_AT_ONCE) }
}
private fun solve(lines: Iterator<String>, moveStrategy: MoveStrategy): String {
val stacks = readInitialStacks(lines)
for (lin... | 0 | Kotlin | 0 | 0 | 9068c21dc0acb5e1009652b4a074432000540d71 | 2,745 | adventofcode22 | Apache License 2.0 |
puzzles/kotlin/src/bender2.kt | hitszjsy | 337,974,982 | true | {"Python": 88057, "Java": 79734, "Kotlin": 52113, "C++": 33407, "TypeScript": 20480, "JavaScript": 17133, "PHP": 15544, "Go": 15296, "Ruby": 12722, "Haskell": 12635, "C#": 2600, "Scala": 1555, "Perl": 1250, "Shell": 1220, "Clojure": 753, "C": 598, "Makefile": 58} | import java.util.Scanner
import java.util.PriorityQueue
const val EXIT = -1
const val START = 0
fun main(args : Array<String>) {
val building = Building()
building.readRooms()
building.calcAllMaxDepths()
println(building.maxMoney())
}
class Room(val number: Int, val money: Int, door1: String, door2: String) ... | 0 | null | 0 | 1 | 59d9856e66b1c4a3d660c60bc26a19c4dfeca6e2 | 2,654 | codingame | MIT License |
kotlin/src/main/kotlin/com/github/jntakpe/aoc2021/days/day12/Day12.kt | jntakpe | 433,584,164 | false | {"Kotlin": 64657, "Rust": 51491} | package com.github.jntakpe.aoc2021.days.day12
import com.github.jntakpe.aoc2021.days.day12.Day12.Cave.Companion.END
import com.github.jntakpe.aoc2021.days.day12.Day12.Cave.Companion.START
import com.github.jntakpe.aoc2021.shared.Day
import com.github.jntakpe.aoc2021.shared.readInputLines
object Day12 : Day {
ove... | 0 | Kotlin | 1 | 5 | 230b957cd18e44719fd581c7e380b5bcd46ea615 | 1,566 | aoc2021 | MIT License |
src/Day14.kt | RusticFlare | 574,508,778 | false | {"Kotlin": 78496} | import kotlin.math.sign
fun main() {
infix fun Int.towards(to: Int) = IntProgression.fromClosedRange(
rangeStart = this,
rangeEnd = to,
step = (to - this).sign.takeUnless { it == 0 } ?: 1,
)
fun getCave(input: List<String>) =
input.flatMap { it.splitToSequence(" -> ", ",").... | 0 | Kotlin | 0 | 1 | 10df3955c4008261737f02a041fdd357756aa37f | 1,855 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day05.kt | stcastle | 573,145,217 | false | {"Kotlin": 24899} | import java.util.Stack
data class Move(val numMoves: Int, val from: Int, val to: Int)
data class Crates(val stacks: Map<Int, Stack<Char>>, val moves: List<Move>)
fun parseInput(input: List<String>): Crates {
val stacks: MutableMap<Int, Stack<Char>> = mutableMapOf()
val moves: MutableList<Move> = mutableListOf()
... | 0 | Kotlin | 0 | 0 | 746809a72ea9262c6347f7bc8942924f179438d5 | 2,345 | aoc2022 | Apache License 2.0 |
src/P4LargersPalindromOf3Digits.kt | rhavran | 250,959,542 | false | null | fun main(args: Array<String>) {
println("Res: " + largestLargestPalindromeProduct())
}
/**
* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
* Find the largest palindrome made from the product of two 3-digit numbers.
*/
privat... | 0 | Kotlin | 0 | 0 | 11156745ef0512ab8aee625ac98cb6b7d74c7e92 | 1,081 | ProjectEuler | MIT License |
src/Day04.kt | imavroukakis | 572,438,536 | false | {"Kotlin": 12355} | fun main() {
val regex = "(\\d+)-(\\d+),(\\d+)-(\\d+)".toRegex()
operator fun MatchResult?.component1() = this?.destructured?.let { (start, end, _, _) ->
start.toInt()..end.toInt()
} ?: IntRange.EMPTY
operator fun MatchResult?.component2() = this?.destructured?.let { (_, _, start, end) ->
... | 0 | Kotlin | 0 | 0 | bb823d49058aa175d1e0e136187b24ef0032edcb | 1,405 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/aoc2016/day01_no_time_for_taxi/NoTimeForTaxi.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package aoc2016.day01_no_time_for_taxi
import geom2d.Dir
import geom2d.Point
fun main() {
util.solve(288, ::partOne)
util.solve(111, ::partTwo)
}
data class Heading(val location: Point, val dir: Dir) {
companion object {
val ORIGIN = Heading(Point.ORIGIN, Dir.NORTH)
}
fun turn(turn: Tur... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 2,140 | aoc-2021 | MIT License |
src/main/kotlin/Day13.kt | SimonMarquis | 434,880,335 | false | {"Kotlin": 38178} | class Day13(raw: String) {
private val input = raw.split("\n\n").let { (a, b) ->
val points = a.lines().map {
it.split(",").map { coords -> coords.toInt() }.let { (x, y) -> Point(x, y) }
}.toSet()
val folds = b.lines().map {
it.split(" ", "=").takeLast(2).let { (d, c... | 0 | Kotlin | 0 | 0 | 8fd1d7aa27f92ba352e057721af8bbb58b8a40ea | 1,605 | advent-of-code-2021 | Apache License 2.0 |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day21.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwenty
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
class Day21 : Day<String> {
private data class Food(val ingredients: List<String>, val allergens: List<String>)
private val foodRegex = Regex("^([a-z ]+) \\(contains ([a-z, ]+)\\)$")
priva... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 3,309 | adventofcode | Apache License 2.0 |
src/main/kotlin/solutions/Day15BeaconExclusionZone.kt | aormsby | 571,002,889 | false | {"Kotlin": 80084} | package solutions
import models.Coord2d
import utils.Input
import utils.Solution
import java.text.NumberFormat
import kotlin.math.abs
// run only this day
fun main() {
Day15BeaconExclusionZone()
}
class Day15BeaconExclusionZone : Solution() {
init {
begin("Day 15 - Beacon Exclusion Zone")
va... | 0 | Kotlin | 0 | 0 | 1bef4812a65396c5768f12c442d73160c9cfa189 | 3,896 | advent-of-code-2022 | MIT License |
src/Day03.kt | DeltaSonic62 | 572,718,847 | false | {"Kotlin": 8676} | fun getPriority(ch: Char): Int {
return if (ch.code in 97..122) ch.code - 96 else ch.code - 38
}
fun main() {
fun part1(input: List<String>): Int {
var total = 0
for (line in input) {
val sec1 = line.substring(0 until line.length / 2)
val sec2 = line.substringAfter(sec1... | 0 | Kotlin | 0 | 0 | 7cdf94ad807933ab4769ce4995a43ed562edac83 | 1,464 | aoc-2022-kt | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2022/Day13.kt | tginsberg | 568,158,721 | false | {"Kotlin": 113322} | /*
* Copyright (c) 2022 by <NAME>
*/
/**
* Advent of Code 2022, Day 13 - Distress Signal
* Problem Description: http://adventofcode.com/2022/day/13
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2022/day13/
*/
package com.ginsberg.advent2022
class Day13(input: List<String>) {
private... | 0 | Kotlin | 2 | 26 | 2cd87bdb95b431e2c358ffaac65b472ab756515e | 2,535 | advent-2022-kotlin | Apache License 2.0 |
src/main/kotlin/Day13.kt | ueneid | 575,213,613 | false | null | class Day13(inputs: List<String>) {
private sealed class Packet : Comparable<Packet> {
companion object {
fun of(input: String): Packet {
var listInput = mutableListOf<String>()
var tempNumber = ""
for (c in input) {
if (c.isDig... | 0 | Kotlin | 0 | 0 | 743c0a7adadf2d4cae13a0e873a7df16ddd1577c | 2,855 | adventcode2022 | MIT License |
src/day08/Day08Part1.kt | armanaaquib | 572,849,507 | false | {"Kotlin": 34114} | package day08
import readInput
fun main() {
fun parseInput(input: List<String>) = input.map { row -> row.split("").filter { it.isNotEmpty() }.map { it.toInt() } }
fun lefViewCount(data: List<List<Int>>, visited: MutableList<MutableList<Boolean>>) {
for (r in data.indices) {
var height = -... | 0 | Kotlin | 0 | 0 | 47c41ceddacb17e28bdbb9449bfde5881fa851b7 | 2,444 | aoc-2022 | Apache License 2.0 |
src/Day11_part1.kt | armandmgt | 573,595,523 | false | {"Kotlin": 47774} | fun main() {
data class Monkey(
val id: Int,
var inspections: Int = 0,
val items: MutableList<Int>,
val operation: (Int) -> Int,
val destination: (Int) -> Int
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
i... | 0 | Kotlin | 0 | 1 | 0d63a5974dd65a88e99a70e04243512a8f286145 | 3,629 | advent_of_code_2022 | Apache License 2.0 |
src/Day05.kt | zsmb13 | 572,719,881 | false | {"Kotlin": 32865} | fun main() {
data class Move(val count: Int, val from: Int, val to: Int)
fun parse(testInput: List<String>): Pair<List<MutableList<Char>>, List<Move>> {
val blankIndex = testInput.indexOfFirst(String::isBlank)
val crateCount = testInput[blankIndex - 1]
.last(Char::isDigit)
... | 0 | Kotlin | 0 | 6 | 32f79b3998d4dfeb4d5ea59f1f7f40f7bf0c1f35 | 1,968 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/ikueb/advent18/Day11.kt | h-j-k | 159,901,179 | false | null | package com.ikueb.advent18
import com.ikueb.advent18.model.Point
object Day11 {
private val range = (1..300)
fun getTopSquareTopCorner(input: Int) =
process(input) { point ->
if (point.x < 3 || point.y < 3) emptySequence() else sequenceOf(3)
}.first
fun getTopVar... | 0 | Kotlin | 0 | 0 | f1d5c58777968e37e81e61a8ed972dc24b30ac76 | 2,131 | advent18 | Apache License 2.0 |
src/main/kotlin/day02/cubes.kt | cdome | 726,684,118 | false | {"Kotlin": 17211} | package day02
import java.io.File
data class Game(val number: Int, val hands: List<Hand>) {
fun maxRed() = hands.maxOfOrNull { it.red } ?: 0
fun maxBlue() = hands.maxOfOrNull { it.blue } ?: 0
fun maxGreen() = hands.maxOfOrNull { it.green } ?: 0
}
data class Hand(val red: Int, val blue: Int, val green: In... | 0 | Kotlin | 0 | 0 | 459a6541af5839ce4437dba20019b7d75b626ecd | 1,307 | aoc23 | The Unlicense |
src/main/kotlin/ReactorReboot_22.kt | Flame239 | 433,046,232 | false | {"Kotlin": 64209} | import RebootOperation.ON
import kotlin.math.max
import kotlin.math.min
private val steps: List<RebootStep> by lazy {
readFile("ReactorReboot").split("\n").map {
val (operation, remaining) = it.split(" ")
val (x, y, z) = remaining.split(",").map { parseRange(it) }
RebootStep(RebootOperation... | 0 | Kotlin | 0 | 0 | ef4b05d39d70a204be2433d203e11c7ebed04cec | 2,647 | advent-of-code-2021 | Apache License 2.0 |
src/day03/Day03.kt | martin3398 | 572,166,179 | false | {"Kotlin": 76153} | package day03
import readInput
typealias Day03InputType1 = List<Pair<Set<Char>, Set<Char>>>
typealias Day03InputType2 = List<Set<Char>>
fun main() {
fun getCommonItem(fst: Set<Char>, snd: Set<Char>): Char = fst.intersect(snd).first()
fun getCommonItem(fst: Set<Char>, snd: Set<Char>, trd: Set<Char>): Char =... | 0 | Kotlin | 0 | 0 | 4277dfc11212a997877329ac6df387c64be9529e | 1,424 | advent-of-code-2022 | Apache License 2.0 |
app/src/main/kotlin/advent/of/code/twentytwenty/Day14.kt | obarcelonap | 320,300,753 | false | null | package advent.of.code.twentytwenty
import java.lang.Long.parseLong
import java.lang.Long.toBinaryString
typealias Mask = String
typealias Memory = Map<Long, Long>
typealias MaskedMemory = Pair<Memory, Mask>
fun main() {
val input = getResourceAsText("/day14-input")
val part1Sum = memorySum(input, ::valueBit... | 0 | Kotlin | 0 | 0 | a721c8f26738fe31190911d96896f781afb795e1 | 3,139 | advent-of-code-2020 | MIT License |
src/Utils.kt | arhor | 572,349,244 | false | {"Kotlin": 36845} | import java.io.File
import kotlin.math.absoluteValue
fun readInput(ref: () -> Unit): List<String> {
return ref.javaClass.name.substringBefore("Kt$").let { File("src", "$it.txt") }.readLines()
}
fun <T> flattenTree(item: T, children: T.() -> Sequence<T>): Sequence<T> {
return sequenceOf(item) + item.children()... | 0 | Kotlin | 0 | 0 | 047d4bdac687fd6719796eb69eab2dd8ebb5ba2f | 1,581 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day02.kt | Allagash | 572,736,443 | false | {"Kotlin": 101198} | // Day 02, Advent of Code 2022, Rock Paper Scissors
fun main() {
fun getScore(input: Char) =
when (input) {
'A' -> 1
'B' -> 2
'C' -> 3
'X' -> 1
'Y' -> 2
'Z' -> 3
else -> -100000
}
fun part1(input: List<String>... | 0 | Kotlin | 0 | 0 | 8d5fc0b93f6d600878ac0d47128140e70d7fc5d9 | 2,003 | AdventOfCode2022 | Apache License 2.0 |
src/Day11.kt | catcutecat | 572,816,768 | false | {"Kotlin": 53001} | import kotlin.system.measureTimeMillis
fun main() {
measureTimeMillis {
Day11.run {
solve1(10605L) // 58322L
solve2(2713310158L) // 13937702909L
}
}.let { println("Total: $it ms") }
}
object Day11 : Day.GroupInput<List<Day11.Monkey>, Long>("11") {
data class Monkey... | 0 | Kotlin | 0 | 2 | fd771ff0fddeb9dcd1f04611559c7f87ac048721 | 2,268 | AdventOfCode2022 | Apache License 2.0 |
src/Day07.kt | leeturner | 572,659,397 | false | {"Kotlin": 13839} | fun main() {
class Dir(val parent: Dir?, val name: String, val children: MutableList<Dir> = mutableListOf()) {
var size: Long = 0
val totalSize: Long
get() = size + children.sumOf { it.totalSize }
override fun toString(): String {
return "Dir($name) { size=$size, totalSize=$totalSize }"
... | 0 | Kotlin | 0 | 0 | 8da94b6a0de98c984b2302b2565e696257fbb464 | 1,784 | advent-of-code-2022 | Apache License 2.0 |
src/day-8/part-2/solution-day-8-part-2.kts | d3ns0n | 572,960,768 | false | {"Kotlin": 31665} | import java.io.File
val treeGrid = mutableListOf<String>()
File("../input.txt").readLines().forEach { treeGrid.add(it) }
val treeGridWidth = treeGrid.first().length
val treeGridHeight = treeGrid.size
fun viewingDistanceLeft(x: Int, y: Int): Int {
val height = treeGrid[y][x].code
for ((index, value) in treeG... | 0 | Kotlin | 0 | 0 | 8e8851403a44af233d00a53b03cf45c72f252045 | 1,893 | advent-of-code-22 | MIT License |
src/day15/Code.kt | fcolasuonno | 162,470,286 | false | null | package day15
import java.io.File
import kotlin.math.max
fun main(args: Array<String>) {
val name = if (false) "test.txt" else "input.txt"
val dir = ::main::class.java.`package`.name
val input = File("src/$dir/$name").readLines()
val parsed = parse(input)
println("Part 1 = ${part1(parsed)}")
p... | 0 | Kotlin | 0 | 0 | 24f54bf7be4b5d2a91a82a6998f633f353b2afb6 | 2,264 | AOC2015 | MIT License |
advent-of-code-2020/src/main/kotlin/eu/janvdb/aoc2020/day07/Day07.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2020.day07
import eu.janvdb.aocutil.kotlin.readLines
val SHINY_GOLD = "shiny gold"
fun main() {
val bags = readLines(2020, "input07.txt")
.map(::Bag)
.map { Pair(it.name, it) }
.toMap()
val results = bags.values.filter { bag -> bag.canContain(SHINY_GOLD, bags) }
.map(Bag::name)
print... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,286 | advent-of-code | Apache License 2.0 |
src/Day24.kt | jvmusin | 572,685,421 | false | {"Kotlin": 86453} | import java.util.*
fun main() {
val dx = intArrayOf(0, 1, 0, -1)
val dy = intArrayOf(1, 0, -1, 0)
val dirs = ">v<^"
data class Wind(val p: Pair<Int, Int>, val d: Int)
fun solve(input: List<String>, needCycle: Int): Any {
val n = input.size
val m = input[0].length
fun insid... | 1 | Kotlin | 0 | 0 | 4dd83724103617aa0e77eb145744bc3e8c988959 | 3,127 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/de/tek/adventofcode/y2022/day15/BeaconExclusionZone.kt | Thumas | 576,671,911 | false | {"Kotlin": 192328} | package de.tek.adventofcode.y2022.day15
import de.tek.adventofcode.y2022.util.math.Norm
import de.tek.adventofcode.y2022.util.math.OneNorm
import de.tek.adventofcode.y2022.util.math.Point
import de.tek.adventofcode.y2022.util.readInputLines
import kotlin.math.abs
class SensorAndBeacon(val sensor: Point, private val b... | 0 | Kotlin | 0 | 0 | 551069a21a45690c80c8d96bce3bb095b5982bf0 | 4,046 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Problem11.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | /**
* Largest product in a grid
*
* In the 20×20 grid below, four numbers along a diagonal line have been marked in red.
*
* 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
* 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
* 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
* 5... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 4,756 | project-euler | MIT License |
src/day24/Day24.kt | gautemo | 317,316,447 | false | null | package day24
import shared.getLines
import kotlin.math.abs
val commands = listOf("e", "se", "sw", "w", "nw", "ne")
fun turnedTiles(input: List<String>, days: Int = 0): Int{
val tiles = mutableMapOf<PointDouble, Boolean>()
for(path in input){
var x = 0.0
var y = 0.0
var pathLeft = pat... | 0 | Kotlin | 0 | 0 | ce25b091366574a130fa3d6abd3e538a414cdc3b | 2,795 | AdventOfCode2020 | MIT License |
src/main/kotlin/utils/dijkstra.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package utils
import java.util.*
fun <T> shortestPath(from: T, isTarget: (T) -> Boolean, edges: (T) -> List<T>): List<T>? =
shortestPathWithCost(from, isTarget) { n -> edges(n).map { it to 1 } }?.first
fun <T> shortestPathBetween(from: T, to : T, edges: (T) -> List<T>): List<T>? =
shortestPath(from, { it == ... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 1,710 | advent-of-code | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2016/Day04.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2016
import se.saidaspen.aoc.util.*
fun main() = Day04.run()
object Day04 : Day(2016, 4) {
private var memo = mutableMapOf<P<String, Int>, String>()
class Room(val letters: String, val checksum: String, val sector: Int)
override fun part1(): Any {
val rooms = toRooms... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 1,916 | adventofkotlin | MIT License |
src/Day03.kt | gylee2011 | 573,544,473 | false | {"Kotlin": 9419} | fun main() {
fun part1(input: List<String>): Int = input
.map { it.chunked(it.length / 2) }
.map { (first, second) -> first.toSet() to second.toSet() }
.map { (first, second) -> first.intersect(second).first() }
.sumOf { it.priority }
fun part2(input: List<String>): Int = input
... | 0 | Kotlin | 0 | 0 | 339e0895fd2484b7f712b966a0dae8a4cfebc2fa | 1,154 | aoc2022-kotlin | Apache License 2.0 |
src/day11/Solution.kt | abhabongse | 576,594,038 | false | {"Kotlin": 63915} | /* Solution to Day 11: Monkey in the Middle
* https://adventofcode.com/2022/day/11
*/
package day11
import utils.MathUtil
import utils.largest
import utils.otherwiseThrow
import utils.splitAt
import java.io.File
fun main() {
val fileName =
// "day11_sample.txt"
"day11_input.txt"
val (monkeyAl... | 0 | Kotlin | 0 | 0 | 8a0aaa3b3c8974f7dab1e0ad4874cd3c38fe12eb | 3,421 | aoc2022-kotlin | Apache License 2.0 |
src/Day03.kt | p357k4 | 573,068,508 | false | {"Kotlin": 59696} | fun main() {
fun score(repeated: Char): Int = when (repeated) {
in 'a'..'z' -> 1 + (repeated - 'a')
in 'A'..'Z' -> 27 + (repeated - 'A')
else -> 0
}
fun part1(input: List<String>): Int {
val result = input.sumOf { line ->
val half = line.length / 2
va... | 0 | Kotlin | 0 | 0 | b9047b77d37de53be4243478749e9ee3af5b0fac | 1,158 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/algorithmic_toolbox/week6/PlacingParentheses.kt | eniltonangelim | 369,331,780 | false | null | package algorithmic_toolbox.week6
import java.util.*
import kotlin.math.max
import kotlin.math.min
fun getMaximValue(exp: String): Long {
val n = exp.length / 2 + 1
var min = Array(n){ LongArray(n) }
var max = Array(n){ LongArray(n) }
for (i in 0 until n) {
min[i][i] = (exp[i * 2] - '0').toLo... | 0 | Kotlin | 0 | 0 | 031bccb323339bec05e8973af7832edc99426bc1 | 1,536 | AlgorithmicToolbox | MIT License |
src/main/kotlin/Day04.kt | robfletcher | 724,814,488 | false | {"Kotlin": 18682} | class Day04 : Puzzle {
override fun test() {
val input = """
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
Card 5: 87 83 26 28 32 | 88... | 0 | Kotlin | 0 | 0 | cf10b596c00322ea004712e34e6a0793ba1029ed | 1,585 | aoc2023 | The Unlicense |
advent/src/test/kotlin/org/elwaxoro/advent/y2021/Dec21.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2021
import org.elwaxoro.advent.PuzzleDayTester
/**
* <NAME>
*/
class Dec21 : PuzzleDayTester(21, 2021) {
override fun part1(): Any = GameV1(listOf(Player(1, 6), Player(2, 8))).let { game ->
while (!game.hasWinner()) {
game.players.forEach { player ->
... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 2,820 | advent-of-code | MIT License |
src/Day14.kt | Allagash | 572,736,443 | false | {"Kotlin": 101198} | import java.io.File
import kotlin.math.min
import kotlin.math.max
// Advent of Code 2022, Day 14, Regolith Reservoir
fun main() {
fun readInputAsOneLine(name: String) = File("src", "$name.txt").readText().trim()
fun Array<CharArray>.print() {
for (y in this[0].indices) {
for (element in... | 0 | Kotlin | 0 | 0 | 8d5fc0b93f6d600878ac0d47128140e70d7fc5d9 | 7,513 | AdventOfCode2022 | Apache License 2.0 |
src/Day07.kt | alfr1903 | 573,468,312 | false | {"Kotlin": 9628} | import java.util.ArrayDeque
import java.util.Deque
fun main() {
fun part1(input: List<String>): Int {
return solve(input)
}
fun part2(comingSoon: Any): Int {
TODO()
}
print(part1(testInput.lines())); println(" 48381165")
val input = readInputAsList("Day07Input")
println(pa... | 0 | Kotlin | 0 | 0 | c1d1fbf030ac82c643fa5aea4d9f7c302051c38c | 1,990 | advent-of-code-2022 | Apache License 2.0 |
src/y2022/day07.kt | sapuglha | 573,238,440 | false | {"Kotlin": 33695} | package y2022
import readFileAsLines
enum class EntryType {
DIRECTORY,
FILE,
}
sealed interface Entry {
val type: EntryType
val name: String
data class FileEntry(
val size: Int,
override val name: String,
override val type: EntryType = EntryType.FILE
) : Entry
da... | 0 | Kotlin | 0 | 0 | 82a96ccc8dcf38ae4974e6726e27ddcc164e4b54 | 6,452 | adventOfCode2022 | Apache License 2.0 |
src/main/kotlin/aoc/year2022/Day02.kt | SackCastellon | 573,157,155 | false | {"Kotlin": 62581} | package aoc.year2022
import aoc.Puzzle
/**
* [Day 2 - Advent of Code 2022](https://adventofcode.com/2022/day/2)
*/
object Day02 : Puzzle<Int, Int> {
override fun solvePartOne(input: String): Int =
input.lines().sumOf {
val (shape, response) = it.split(" ").map(String::toShape)
(s... | 0 | Kotlin | 0 | 0 | 75b0430f14d62bb99c7251a642db61f3c6874a9e | 1,780 | advent-of-code | Apache License 2.0 |
src/main/kotlin/day3/Solution.kt | krazyglitch | 573,086,664 | false | {"Kotlin": 31494} | package day3
import util.Utils
import java.time.Duration
import java.time.LocalDateTime
class Solution {
private val offsetLower = 'a'.code
private val offsetUpper = 'A'.code
private val priorityMap: Map<Char, Int>
init {
priorityMap = HashMap()
('a'..'z').forEach { priorityMap.put(i... | 0 | Kotlin | 0 | 0 | db6b25f7668532f24d2737bc680feffc71342491 | 2,848 | advent-of-code2022 | MIT License |
src/Day04.kt | hoppjan | 433,705,171 | false | {"Kotlin": 29015, "Shell": 338} | typealias BingoBoard = List<List<Int>>
fun main() {
fun part1(numbers: List<Int>, bingoBoards: List<BingoBoard>): Int {
val drawnNumbers = mutableListOf<Int>()
numbers.forEach { number ->
drawnNumbers.add(number)
bingoBoards.firstOrNull {
it.hasBingo(drawnN... | 0 | Kotlin | 0 | 0 | 04f10e8add373884083af2a6de91e9776f9f17b8 | 2,387 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2021/2021-14.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2021
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputText
fun main() {
val input = readInputText(2021, "14-input")
val test1 = readInputText(2021, "14-test1")
println("Part1:")
part1(test1).println()
part... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 2,366 | advent-of-code | MIT License |
2015/Day15/src/main/kotlin/Main.kt | mcrispim | 658,165,735 | false | null | import java.io.File
import java.lang.Thread.yield
data class Ingredient(
val name: String,
val capacity: Int,
val durability: Int,
val flavor: Int,
val texture: Int,
val calories: Int
)
fun recipeFactory(ingredients: List<Ingredient>, amount: Int): Sequence<List<Pair<Ingredient, Int>>> {
... | 0 | Kotlin | 0 | 0 | 2f4be35e78a8a56fd1e078858f4965886dfcd7fd | 3,921 | AdventOfCode | MIT License |
src/main/kotlin/year_2022/Day11.kt | krllus | 572,617,904 | false | {"Kotlin": 97314} | package year_2022
import utils.readInputAsText
fun main() {
fun getMonkeys(monkeysStr: List<String>): Map<Int, Monkey> {
return buildMap {
monkeysStr.forEachIndexed { index, s ->
// split by line and remove first "Monkey n"
val lines = s.split("\n").drop(1)
... | 0 | Kotlin | 0 | 0 | b5280f3592ba3a0fbe04da72d4b77fcc9754597e | 5,194 | advent-of-code | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.