path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/main/kotlin/Day9.kt | noamfreeman | 572,834,940 | false | {"Kotlin": 30332} | import kotlin.math.abs
private val exampleInput = """
R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2
""".trimIndent()
private val largeExample = """
R 5
U 8
L 8
D 3
R 17
D 10
L 25
U 20
""".trimIndent()
fun main() {
println("day8")
println()
println("part... | 0 | Kotlin | 0 | 0 | 1751869e237afa3b8466b213dd095f051ac49bef | 2,502 | advent_of_code_2022 | MIT License |
src/Day12.kt | rweekers | 573,305,041 | false | {"Kotlin": 38747} | fun main() {
fun part1(input: List<String>): Int {
val grid = determineGrid(input)
val start: Point = input.determinePointFor("S")
val end: Point = input.determinePointFor("E")
return grid.shortestPathBFS(
begin = start,
end = end,
goalReached =... | 0 | Kotlin | 0 | 1 | 276eae0afbc4fd9da596466e06866ae8a66c1807 | 1,863 | adventofcode-2022 | Apache License 2.0 |
hoon/HoonAlgorithm/src/main/kotlin/programmers/lv01/Lv1_12928_divisors.kt | boris920308 | 618,428,844 | false | {"Kotlin": 137657, "Swift": 35553, "Java": 1947, "Rich Text Format": 407} | package main.kotlin.programmers.lv01
import kotlin.math.ceil
import kotlin.math.sqrt
/**
*
* https://school.programmers.co.kr/learn/courses/30/lessons/12928
*
* 문제 설명
* 정수 n을 입력받아 n의 약수를 모두 더한 값을 리턴하는 함수, solution을 완성해주세요.
*
* 제한 사항
* n은 0 이상 3000이하인 정수입니다.
* 입출력 예
* n return
* 12 28
* 5 6
* 입출력 예 설명
* ... | 1 | Kotlin | 1 | 2 | 88814681f7ded76e8aa0fa7b85fe472769e760b4 | 2,023 | HoOne | Apache License 2.0 |
src/main/kotlin/_2019/Day12.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2019
import aocRun
import java.util.regex.Pattern
import kotlin.math.abs
private val pattern = Pattern.compile("<x=(?<x>-?\\d+), y=(?<y>-?\\d+), z=(?<z>-?\\d+)>")
fun main() {
aocRun(puzzleInput) { input ->
val moons = parseMoons(input)
repeat(1000) {
moveMoons(moons)
// ... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 4,211 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/day3.kt | kevinrobayna | 436,414,545 | false | {"Ruby": 195446, "Kotlin": 42719, "Shell": 1288} | import java.util.stream.Collectors
// https://adventofcode.com/2020/day/3
class Day3(
private val forest: List<List<String>>,
private val down: Int,
private val right: Int,
) {
companion object {
const val TREE = "#"
}
fun solve(): Long {
var position = Pair(0, 0)
var t... | 0 | Ruby | 0 | 0 | 9e48ecdebdb4c479ef00f0fd3b1a44a211fb6577 | 2,064 | adventofcode_2020 | MIT License |
src/Day10.kt | EdoFanuel | 575,561,680 | false | {"Kotlin": 80963} | import java.util.*
fun main() {
fun readState(input: List<String>): TreeMap<Int, Int> {
var cycle = 0
var signal = 1
val state = TreeMap<Int, Int>()
for (line in input) {
when {
line == "noop" -> cycle++
line.startsWith("addx") -> {
... | 0 | Kotlin | 0 | 0 | 46a776181e5c9ade0b5e88aa3c918f29b1659b4c | 1,349 | Advent-Of-Code-2022 | Apache License 2.0 |
src/day07/Day07.kt | devEyosiyas | 576,863,541 | false | null | package day07
import println
import readInput
fun main() {
fun String.isDigit() = all { it in '0'..'9' }
fun processFileSystem(input: List<String>): Map<String, Long> {
val sizes = mutableMapOf<String, Long>()
var path = mutableListOf<String>()
input.forEach {
val split = ... | 0 | Kotlin | 0 | 0 | 91d94b50153bdab1a4d972f57108d6c0ea712b0e | 1,651 | advent_of_code_2022 | Apache License 2.0 |
src/day2/Day02.kt | mmilenkov | 573,101,780 | false | {"Kotlin": 9427} | package day2
import readText
sealed class Shape(val score: Int) {
object Rock: Shape(1)
object Paper: Shape(2)
object Scissors: Shape(3)
companion object {
fun toShape(input: String): Shape {
return if (isPaper(input)) {
Paper
} else if (isRock(input)) ... | 0 | Kotlin | 0 | 0 | 991df03f2dcffc9fa4596f6dbbc4953c95fcd17c | 3,275 | AdventOfCode2022 | Apache License 2.0 |
app/src/main/java/com/employees/domain/BusinessLogic.kt | nicolegeorgieva | 621,254,848 | false | null | package com.employees.domain
import com.employees.domain.data.Employee
import com.employees.domain.data.TaskResult
import java.time.LocalDate
import java.time.temporal.ChronoUnit
/**
* Finds the pair of employees who have worked together on common projects
* for the longest period of time.
*
* @param employees A ... | 0 | Kotlin | 0 | 0 | 227c7ef3c7b56b70cd37f666c22a3ac47cb086bb | 3,209 | nicole-georgieva-employees | MIT License |
src/main/kotlin/com/groundsfam/advent/y2023/d12/Day12.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2023.d12
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
// e.g. SpringRecord(".??..??...?##.", listOf(1, 1, 3))
data class SpringRecord(val row: String, val brokenCounts: List<Int>)
fun SpringRecord.unfo... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 3,432 | advent-of-code | MIT License |
src/day-8.kt | drademacher | 160,820,401 | false | null | import java.io.File
fun main(args: Array<String>) {
println("part 1: " + partOne())
println("part 2: " + partTwo())
}
private data class Node(val children: List<Node>, val metadata: List<Int>)
private fun partOne(): Int {
val rawFile = File("res/day-8.txt").readText()
val numbers = rawFile
... | 0 | Kotlin | 0 | 0 | a7f04450406a08a5d9320271148e0ae226f34ac3 | 1,840 | advent-of-code-2018 | MIT License |
src/main/kotlin/dev/paulshields/aoc/day10/AdapterArray.kt | Pkshields | 318,658,287 | false | null | package dev.paulshields.aoc.day10
import dev.paulshields.aoc.common.readFileAsStringList
fun main() {
println(" ** Day 10: Adapter Array ** \n")
val joltageAdapters = readFileAsStringList("/day10/JoltageAdapters.txt")
.mapNotNull { it.toIntOrNull() }
.let { compileListOfJoltageAdaptors(it) }
... | 0 | Kotlin | 0 | 0 | a7bd42ee17fed44766cfdeb04d41459becd95803 | 2,360 | AdventOfCode2020 | MIT License |
src/day09/Day09_functional.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day09
import readLines
import kotlin.math.absoluteValue
import kotlin.math.sign
/**
* Credit goes to tginsberg (https://github.com/tginsberg/advent-2022-kotlin)
* I'm experimenting with his solutions to better learn functional programming in Kotlin.
* Files without the _functional suffix are my original... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 2,190 | aoc2022 | Apache License 2.0 |
src/main/kotlin/me/camdenorrb/timorforest/tree/DecisionTree3.kt | camdenorrb | 202,772,314 | false | null | package me.camdenorrb.timorforest.tree
/*
import kotlin.math.pow
val trainingData0 = listOf(
listOf("Green", 3, "Apple"),
listOf("Yellow", 3, "Apple"),
listOf("Red", 1, "Grape"),
listOf("Red", 1, "Grape"),
listOf("Yellow", 3, "Lemon")
)
val trainingData1 = listOf(
listOf("Black", 2, "Cat"),
... | 0 | Kotlin | 0 | 0 | b746f0ca27b587fbff4dcc08d97051f463cac53e | 4,184 | TimorForest | MIT License |
src/Day03.kt | andyludeveloper | 573,249,939 | false | {"Kotlin": 7818} | fun main() {
val ansChar = listOf(('a'..'z').toList(), ('A'..'Z').toList()).flatten()
fun part1(input: List<String>): Int {
return input.sumOf {
it.chunked(it.length / 2)
.let { compartment ->
compartment[0].filter { c: Char -> compartment[1].contains(c) ... | 0 | Kotlin | 0 | 1 | 684cf9ff315f15bf29914ca25b44cca87ceeeedf | 1,384 | Kotlin-in-Advent-of-Code-2022 | Apache License 2.0 |
src/d13.main.kts | cjfuller | 317,725,797 | false | null | import java.io.File
data class Bus(val number: Long, val offset: Long) {
fun arrivesAtCorrectOffset(t: Long): Boolean =
(t + offset) % number == 0L
}
fun parseInput(): Pair<Long, List<Bus>> {
val lines = File("./data/d13.txt").readLines()
val departureTime = lines[0].toLong()
val busses = line... | 0 | Kotlin | 0 | 0 | c3812868da97838653048e63b4d9cb076af58a3b | 1,568 | adventofcode2020 | MIT License |
src/exercises/Day04.kt | Njko | 572,917,534 | false | {"Kotlin": 53729} | // ktlint-disable filename
package exercises
import readInput
fun main() {
fun isRangeIncludedInOther(
elf1: IntRange,
elf2: IntRange
): Boolean {
if (elf2.first < elf1.first) {
if (elf2.last >= elf1.last) {
return true
}
} else {
... | 0 | Kotlin | 0 | 2 | 68d0c8d0bcfb81c183786dfd7e02e6745024e396 | 2,501 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/headlessideas/adventofcode/december8/Counter.kt | Nandi | 113,094,752 | false | null | package com.headlessideas.adventofcode.december8
import com.headlessideas.adventofcode.utils.readFile
import kotlin.math.max
fun registerCounter(instructions: List<Instruction>) {
val register = mutableMapOf<String, Int>()
var maxValue = 0
instructions.forEach {
it.run(register)
maxValue =... | 0 | Kotlin | 0 | 0 | 2d8f72b785cf53ff374e9322a84c001e525b9ee6 | 2,678 | adventofcode-2017 | MIT License |
src/day08/solution.kt | bohdandan | 729,357,703 | false | {"Kotlin": 80367} | package day08
import println
import readInput
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun main() {
class Puzzle {
var commands: String
var network: MutableMap<String, Pair<String, String>>
constructor(input: List<String>) {
commands = input[0]
... | 0 | Kotlin | 0 | 0 | 92735c19035b87af79aba57ce5fae5d96dde3788 | 2,854 | advent-of-code-2023 | Apache License 2.0 |
src/Day19.kt | max-zhilin | 573,066,300 | false | {"Kotlin": 114003} | import java.util.*
data class Blueprint(val ore4Ore: Int, val ore4Clay: Int, val ore4Obsidian: Int, val clay4Obsidian: Int, val ore4Geode: Int, val obsidian4Geode: Int) {
companion object {
fun parse(s: String): Blueprint {
// Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 or... | 0 | Kotlin | 0 | 0 | d9dd7a33b404dc0d43576dfddbc9d066036f7326 | 10,123 | AoC-2022 | Apache License 2.0 |
src/Day5.kt | HenryCadogan | 574,509,648 | false | {"Kotlin": 12228} | fun main() {
val input = readInput("Day05")
fun part1(input: List<String>): String {
val structure = getStructure(input)
val actions = getActions(input)
return structure.performActions(actions).getTopElements()
}
fun part2(input: List<String>): String {
val structure =... | 0 | Kotlin | 0 | 0 | 0a0999007cf16c11355fcf32fc8bc1c66828bbd8 | 2,278 | AOC2022 | Apache License 2.0 |
src/main/kotlin/com/colinodell/advent2022/Day19.kt | colinodell | 572,710,708 | false | {"Kotlin": 105421} | package com.colinodell.advent2022
class Day19(input: List<String>) {
private val blueprints = input.map {
val tokens = it.split(" ")
mapOf(
MaterialType.ORE to Materials(tokens[6].toInt(), 0, 0, 0),
MaterialType.CLAY to Materials(tokens[12].toInt(), 0, 0, 0),
Mat... | 0 | Kotlin | 0 | 1 | 32da24a888ddb8e8da122fa3e3a08fc2d4829180 | 5,031 | advent-2022 | MIT License |
y2018/src/main/kotlin/adventofcode/y2018/Day11.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2018
import adventofcode.io.AdventSolution
object Day11 : AdventSolution(2018, 11, "Chronal Charge") {
override fun solvePartOne(input: String): String {
val g = CumulativeGrid(300) { x, y -> power(x + 1, y + 1, input.toInt()) }
var maxP = 0
var answer = ""
... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,806 | advent-of-code | MIT License |
src/year2022/day02/Solution.kt | LewsTherinTelescope | 573,240,975 | false | {"Kotlin": 33565} | package year2022.day02
import utils.runIt
fun main() = runIt(
testInput = """
A Y
B X
C Z
""".trimIndent(),
::part1,
testAnswerPart1 = 15,
::part2,
testAnswerPart2 = 12,
)
fun part1(input: String) = splitInput(input).fold(0) { acc, (them, you) ->
acc + playRound(them, xyzToAbc[you]!!)
}
fun part2(input... | 0 | Kotlin | 0 | 0 | ee18157a24765cb129f9fe3f2644994f61bb1365 | 1,127 | advent-of-code-kotlin | Do What The F*ck You Want To Public License |
src/main/kotlin/dev/kosmx/aoc23/poker/WellItsNot.kt | KosmX | 726,056,762 | false | {"Kotlin": 32011} | package dev.kosmx.aoc23.poker
import java.io.File
import java.math.BigInteger
fun main() {
val games = File("poker.txt").readLines().map {
var (cards, score) = it.split(" ")
//cards = cards.replace("J", "X") Uncomment it to solve Part1
Hand(cards) to score.toInt()
}.sortedByDescending... | 0 | Kotlin | 0 | 0 | ad01ab8e9b8782d15928a7475bbbc5f69b2416c2 | 3,969 | advent-of-code23 | MIT License |
facebook/y2021/qual/a2.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package facebook.y2021.qual
private fun solve(from: Char = 'A', toInclusive: Char = 'Z'): Int {
val s = readLn()
val letters = toInclusive - from + 1
val inf = letters + 1
val e = List(letters) { IntArray(letters) { inf } }
repeat(readInt()) {
val (u, v) = readLn().map { it - from }
e[u][v] = 1
}
for (k in ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 779 | competitions | The Unlicense |
src/main/kotlin/Day03.kt | todynskyi | 573,152,718 | false | {"Kotlin": 47697} | fun main() {
fun List<String>.findCommonChar(): Char = map { it.toSet() }
.reduce { left, right -> left.intersect(right) }
.first()
fun Char.priority(): Int = when (this) {
in 'a'..'z' -> (this - 'a') + 1
in 'A'..'Z' -> (this - 'A') + 27
else -> 0
}
fun part1(in... | 0 | Kotlin | 0 | 0 | 5f9d9037544e0ac4d5f900f57458cc4155488f2a | 967 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/aoc/utils/graphs/Graph.kt | Arch-vile | 572,557,390 | false | {"Kotlin": 132454} | package aoc.utils.graphs
import aoc.utils.SortedLookup
import day16.Valve
// Not immutable by any means
data class Node<T>(var value: T) {
val edges: MutableSet<Edge<T>> = mutableSetOf()
fun link(distance: Long, target: Node<T>) {
edges.add(Edge(distance, target))
}
fun link(distance: Long... | 0 | Kotlin | 0 | 0 | e737bf3112e97b2221403fef6f77e994f331b7e9 | 6,315 | adventOfCode2022 | Apache License 2.0 |
src/shreckye/coursera/algorithms/GraphShortestPathAlgorithms.kt | ShreckYe | 205,871,625 | false | {"Kotlin": 72136} | package shreckye.coursera.algorithms
import kotlin.math.min
/* A number representing positive infinity in all these algorithms
When running algorithms, assuming all path distances in the graph are strictly smaller than this value */
const val POSITIVE_INFINITY_INT = Int.MAX_VALUE / 2
data class VertexDistance(val ve... | 0 | Kotlin | 1 | 2 | 1746af789d016a26f3442f9bf47dc5ab10f49611 | 5,650 | coursera-stanford-algorithms-solutions-kotlin | MIT License |
src/main/kotlin/com/nibado/projects/advent/y2016/Day04.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2016
import com.nibado.projects.advent.Day
import com.nibado.projects.advent.resourceRegex
object Day04 : Day {
val comp : Comparator<Pair<Char, Int>> = compareByDescending<Pair<Char, Int>>{ it.second }.thenBy { it.first }
private val regex = Regex("([a-z-]+)-([0-9]+)\\[([a... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 1,126 | adventofcode | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimumTime.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,839 | kotlab | Apache License 2.0 |
src/main/kotlin/graph/variation/RemoveAddOneVertex.kt | yx-z | 106,589,674 | false | null | package graph.variation
import graph.core.Vertex
import graph.core.WeightedEdge
import graph.core.WeightedGraph
import graph.core.warshall
import util.*
// given a directed and weighted graph G = (V, E), with weights being either
// > 0, 0, or < 0
// 1. now given a specific vertex v in V, construct another directed ... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 4,517 | AlgoKt | MIT License |
src/Day05.kt | jgodort | 573,181,128 | false | null | fun main() {
val inputData = readInput("Day5_input")
val (crates, moves) = inputData.split("\n\n")
val cratesStacks = crates.lines().dropLast(1).reversed().map { it.convertToCrate() }
val workingCrates = List(9) { ArrayDeque<Char>() }
cratesStacks.forEach { row ->
for ((index, letter) in ro... | 0 | Kotlin | 0 | 0 | 355f476765948c79bfc61367c1afe446fe9f6083 | 2,081 | aoc2022Kotlin | Apache License 2.0 |
Advent-of-Code-2023/src/Day08.kt | Radnar9 | 726,180,837 | false | {"Kotlin": 93593} | private const val AOC_DAY = "Day08"
private const val PART1_TEST_FILE = "${AOC_DAY}_test_part1"
private const val PART2_TEST_FILE = "${AOC_DAY}_test_part2"
private const val INPUT_FILE = AOC_DAY
private data class Direction(val left: String, val right: String)
/**
* Counts the number of steps until finding a positio... | 0 | Kotlin | 0 | 0 | e6b1caa25bcab4cb5eded12c35231c7c795c5506 | 2,743 | Advent-of-Code-2023 | Apache License 2.0 |
src/Day04.kt | timmiller17 | 577,546,596 | false | {"Kotlin": 44667} | fun main() {
fun part1(input: List<String>): Int {
val pairs = input.map { it.split(',') }
var count = 0
for (pair in pairs) {
val low1 = pair[0].substring(0, pair[0].indexOf('-')).toInt()
val high1 = pair[0].substring(pair[0].indexOf('-') + 1).toInt()
val... | 0 | Kotlin | 0 | 0 | b6d6b647c7bb0e6d9e5697c28d20e15bfa14406c | 1,753 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day11/Solution.kt | TestaDiRapa | 573,066,811 | false | {"Kotlin": 50405} | package day11
import java.io.File
import java.lang.Exception
data class Monkey(
val id: Int,
val items: List<Long>,
val operation: (Long) -> Long,
val nextMonkey: (Long) -> Int,
val monkeyActivity: Int = 0
) {
fun doATurn(monkeys: List<Monkey>, reduceLevel: Int = 1, verbose: Boolean = false):... | 0 | Kotlin | 0 | 0 | b5b7ebff71cf55fcc26192628738862b6918c879 | 4,045 | advent-of-code-2022 | MIT License |
src/com/kingsleyadio/adventofcode/y2022/day09/Solution.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2022.day09
import com.kingsleyadio.adventofcode.util.readInput
import kotlin.math.abs
import kotlin.math.sign
fun main() {
solution(2)
solution(10)
}
fun solution(knotCount: Int) {
val grid = Array(1000) { BooleanArray(1000) }
val knots = List(knotCount) { intAr... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 1,383 | adventofcode | Apache License 2.0 |
src/Day04.kt | akleemans | 574,937,934 | false | {"Kotlin": 5797} | fun main() {
fun part1(input: List<String>): Int {
var score = 0
for (line in input) {
val (a, b) = line.split(",")
val (a1, a2) = a.split("-").map { s -> s.toInt() }
val (b1, b2) = b.split("-").map { s -> s.toInt() }
if ((a1 >= b1 && a2 <= b2) || (a1... | 0 | Kotlin | 0 | 0 | fa4281772d89a6d1cda071db4b6fb92fff5b42f5 | 1,048 | aoc-2022-kotlin | Apache License 2.0 |
src/Day03.kt | fercarcedo | 573,142,185 | false | {"Kotlin": 60181} | private const val FIRST_LOWERCASE_PRIORITY = 1
private const val FIRST_UPPERCASE_PRIORITY = 27
fun List<String>.calculateCommonItemsPriorities() = map { it.toSet() }
.intersect()
.map { it.priority }
fun <T> List<Set<T>>.intersect() = fold(this[0]) { acc, next ->
acc intersect next
}
val Char.priority: I... | 0 | Kotlin | 0 | 0 | e34bc66389cd8f261ef4f1e2b7f7b664fa13f778 | 972 | Advent-of-Code-2022-Kotlin | Apache License 2.0 |
src/day24/solution.kt | bohdandan | 729,357,703 | false | {"Kotlin": 80367} | package day24
import assert
import println
import readInput
import kotlin.math.*
data class Velocity(val x: Long, val y: Long, val z: Long)
data class Hailstone(val x: Long, val y: Long, val z: Long, val velocity: Velocity) {
}
class NeverTellMeTheOdds(input: List<String>) {
private val hailstones = input.map { ... | 0 | Kotlin | 0 | 0 | 92735c19035b87af79aba57ce5fae5d96dde3788 | 3,363 | advent-of-code-2023 | Apache License 2.0 |
kotlin/src/2022/Day13_2022.kt | regob | 575,917,627 | false | {"Kotlin": 50757, "Python": 46520, "Shell": 430} | private typealias Item = Any
private fun parse(s: String): Item {
val path = mutableListOf<MutableList<Item>>()
var acc = mutableListOf<Char>()
fun closeAcc() {
if (acc.isNotEmpty())
path.last().add(acc.joinToString("").toInt())
acc = mutableListOf()
}
for (c in s) {
... | 0 | Kotlin | 0 | 0 | cf49abe24c1242e23e96719cc71ed471e77b3154 | 1,911 | adventofcode | Apache License 2.0 |
src/year2023/23/Day23.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2023.`23`
import readInput
private const val CURRENT_DAY = "23"
private data class Point(
val x: Int,
val y: Int,
) {
override fun toString(): String {
return "[$x,$y]"
}
}
private fun Point.neighbours(
currentValue: String,
): Set<Point> {
return when (currentValue) {
... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 2,983 | KotlinAdventOfCode | Apache License 2.0 |
src/Day07.kt | LauwiMeara | 572,498,129 | false | {"Kotlin": 109923} | const val MAX_SIZE_PART_1 = 100000
const val MAX_USED_SPACE = 70000000 - 30000000
fun main() {
fun getListPerDirectory(input: List<String>): Map<String, List<String>> {
val listPerDirectory = mutableMapOf<String, MutableList<String>>()
var currentDirectory = ""
for (line in input) {
... | 0 | Kotlin | 0 | 1 | 34b4d4fa7e562551cb892c272fe7ad406a28fb69 | 2,968 | AoC2022 | Apache License 2.0 |
src/day12/b/day12b.kt | pghj | 577,868,985 | false | {"Kotlin": 94937} | package day12.b
import readInputLines
import shouldBe
import util.IntGrid
import util.IntVector
import vec2
import java.lang.Integer.min
fun main() {
val map = day12.a.readInput()
val dist = IntGrid(map.width, map.height)
dist.compute { Integer.MAX_VALUE }
val (_, end) = findStartAndEnd(map)
val m... | 0 | Kotlin | 0 | 0 | 4b6911ee7dfc7c731610a0514d664143525b0954 | 1,791 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g2901_3000/s2973_find_number_of_coins_to_place_in_tree_nodes/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2901_3000.s2973_find_number_of_coins_to_place_in_tree_nodes
// #Hard #Dynamic_Programming #Sorting #Depth_First_Search #Tree #Heap_Priority_Queue
// #2024_01_19_Time_1134_ms_(90.91%)_Space_73.7_MB_(90.91%)
import java.util.PriorityQueue
import kotlin.math.max
class Solution {
private lateinit var result... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,741 | LeetCode-in-Kotlin | MIT License |
2023/src/main/kotlin/Day05.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | object Day05 {
data class Almanac(val seeds: List<Long>, val steps: List<List<Transformer>>)
data class Transformer(val range: LongRange, val transform: Long)
fun part1(input: String): Long {
val almanac = parseAlmanac(input)
return almanac.seeds.minOf { seed ->
almanac.steps.fold(seed) { value, ... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 3,226 | advent-of-code | MIT License |
day10/src/main/kotlin/Main.kt | rstockbridge | 159,586,951 | false | null | import java.io.File
fun main() {
val points = parseInput(readInputFile())
val board = Board(points)
println("Part I: the solution is\n")
val numberOfSeconds = solveProblem(board)
println("Part II: the solution is $numberOfSeconds.")
}
fun readInputFile(): List<String> {
return File(ClassLoa... | 0 | Kotlin | 0 | 0 | c404f1c47c9dee266b2330ecae98471e19056549 | 2,713 | AdventOfCode2018 | MIT License |
src/main/kotlin/day3/main.kt | janneri | 572,969,955 | false | {"Kotlin": 99028} | package day3
import util.readTestInput
data class Rucksack(val part1Chars: CharArray, val part2Chars: CharArray) {
fun getDuplicateChar(): Char {
return part1Chars.find { part2Chars.contains(it) }!!
}
companion object {
fun parse(str: String): Rucksack {
val partLength = str.le... | 0 | Kotlin | 0 | 0 | 1de6781b4d48852f4a6c44943cc25f9c864a4906 | 1,473 | advent-of-code-2022 | MIT License |
src/year2023/day18/Day.kt | tiagoabrito | 573,609,974 | false | {"Kotlin": 73752} | package year2023.day18
import year2023.solveIt
fun main() {
val day = "18"
val expectedTest1 = 62L
val expectedTest2 = 952408144115L
data class Coordinate(val x: Long, val y: Long) {
fun add(other: Coordinate): Coordinate = Coordinate(x + other.x, y + other.y)
}
fun move(len: Long,... | 0 | Kotlin | 0 | 0 | 1f9becde3cbf5dcb345659a23cf9ff52718bbaf9 | 1,489 | adventOfCode | Apache License 2.0 |
src/main/kotlin/y2022/day09/Day09.kt | TimWestmark | 571,510,211 | false | {"Kotlin": 97942, "Shell": 1067} | package y2022.day09
import java.lang.IllegalStateException
import kotlin.math.abs
fun main() {
AoCGenerics.printAndMeasureResults(
part1 = { part1() },
part2 = { part2() }
)
}
enum class Direction {
LEFT,
RIGHT,
UP,
DOWN
}
data class Move(
val direction: Direction,
va... | 0 | Kotlin | 0 | 0 | 23b3edf887e31bef5eed3f00c1826261b9a4bd30 | 3,490 | AdventOfCode | MIT License |
src/kotlin2022/Day05.kt | egnbjork | 571,981,366 | false | {"Kotlin": 18156} | package kotlin2022
import readInput
fun main() {
val gameInput = readInput("Day05_test")
val part1 = executePart1(normalizeCrates(gameInput), normalizeActions(gameInput))
val part2 = executePart2(normalizeCrates(gameInput), normalizeActions(gameInput))
printSolution(part1)
printSolution(part2)
}... | 0 | Kotlin | 0 | 0 | 1294afde171a64b1a2dfad2d30ff495d52f227f5 | 2,745 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/Day2.kt | ueneid | 575,213,613 | false | null | class Day2(inputs: List<String>) {
private val matches = parse(inputs)
private fun parse(inputs: List<String>): List<Pair<String, String>> {
return inputs.map { it.split(" ").toPair() }
}
enum class Choice(s: String, val point: Int) {
A("Rock", 1) {
override fun judgeAgains... | 0 | Kotlin | 0 | 0 | 743c0a7adadf2d4cae13a0e873a7df16ddd1577c | 3,044 | adventcode2022 | MIT License |
src/main/kotlin/net/wrony/aoc2023/a11/11.kt | kopernic-pl | 727,133,267 | false | {"Kotlin": 52043} | package net.wrony.aoc2023.a11
import kotlin.io.path.Path
import kotlin.io.path.readLines
import kotlin.math.absoluteValue
fun discreteDistance(p: Pair<Position, Position>): Long {
return discreteDistance(p.first, p.second)
}
fun discreteDistance(first: Position, second: Position): Long {
return discreteDist... | 0 | Kotlin | 0 | 0 | 1719de979ac3e8862264ac105eb038a51aa0ddfb | 2,186 | aoc-2023-kotlin | MIT License |
2023/src/main/kotlin/Day15.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | object Day15 {
fun part1(input: String) = input.splitCommas().sumOf(::hash)
fun part2(input: String): Int {
val operations = parse(input)
val boxes = Array(256) { mutableListOf<Lens>() }
operations.forEach { op ->
val box = boxes[hash(op.label)]
when (op) {
is Operation.Put -> {
... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 1,597 | advent-of-code | MIT License |
kotlin/2022/qualification-round/chain-reactions/src/main/kotlin/Solution.kt | ShreckYe | 345,946,821 | false | null | fun main() {
val t = readLine()!!.toInt()
repeat(t, ::testCase)
}
fun testCase(ti: Int) {
val nn = readLine()!!.toInt()
val ffs = readLine()!!.splitToSequence(' ').map { it.toInt() }.toList()
val pps = readLine()!!.splitToSequence(' ').map { it.toInt() }.toList()
val outs = pps.map { if (it !=... | 0 | Kotlin | 1 | 1 | 743540a46ec157a6f2ddb4de806a69e5126f10ad | 1,456 | google-code-jam | MIT License |
src/main/kotlin/aoc2021/Day08.kt | davidsheldon | 565,946,579 | false | {"Kotlin": 161960} | package aoc2021
import utils.InputUtils
fun main() {
val testInput = """be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdca... | 0 | Kotlin | 0 | 0 | 5abc9e479bed21ae58c093c8efbe4d343eee7714 | 3,495 | aoc-2022-kotlin | Apache License 2.0 |
src/Day05.kt | roxspring | 573,123,316 | false | {"Kotlin": 9291} | fun main() {
class State {
val instructionRegex = "move (\\d+) from (\\d+) to (\\d+)".toRegex()
val stacks: MutableList<MutableList<Char>> = mutableListOf()
fun push(stackIndex: Int, content: Char): State {
if (content == ' ') {
return this
}
... | 0 | Kotlin | 0 | 0 | 535beea93bf84e650d8640f1c635a430b38c169b | 3,098 | advent-of-code-2022 | Apache License 2.0 |
src/leetcode_study_badge/dynamic_programming/Day6.kt | faniabdullah | 382,893,751 | false | null | package leetcode_study_badge.dynamic_programming
class Day6 {
fun maxProduct(nums: IntArray): Int {
if (nums.isEmpty()) return 0
var min = nums[0]
var max = nums[0]
var res = nums[0]
for (i in 1 until nums.size) {
val tmp = max
val n = nums[i]
... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,060 | dsa-kotlin | MIT License |
kotlin/src/katas/kotlin/leetcode/course_schedule/CourseSchedule.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.course_schedule
import datsok.shouldEqual
import org.junit.Test
/**
* https://leetcode.com/problems/course-schedule/
*/
class CourseScheduleTests {
@Test fun `determine if it's possible to finish all courses`() {
canFinish(n = 0, deps = emptyList()) shouldEqual true
... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,714 | katas | The Unlicense |
src/Day09.kt | YunxiangHuang | 572,333,905 | false | {"Kotlin": 20157} | fun main() {
fun calDistance(head: Pair<Int, Int>, tail: Pair<Int, Int>): Int {
return kotlin.math.abs(head.first - tail.first) +
kotlin.math.abs(head.second - tail.second)
}
fun needMove(head: Pair<Int, Int>, tail: Pair<Int, Int>): Boolean {
if (head.first != tail.first && ... | 0 | Kotlin | 0 | 0 | f62cc39dd4881f4fcf3d7493f23d4d65a7eb6d66 | 2,516 | AoC_2022 | Apache License 2.0 |
kotlin-advent-of-code/src/main/kotlin/advent/twenty_sixteen/Day01NoTimeForATaxicab.kt | AKiwiCoder | 162,471,091 | false | {"Java": 531288, "Scala": 463157, "C#": 15266, "Python": 14164, "Kotlin": 11280, "Shell": 1566, "C++": 1206, "Makefile": 157} | package advent.twenty_sixteen
import advent.common.DailyProblem
import kotlin.math.abs
data class Position(val x: Int, val y: Int)
enum class Facing {
North {
override fun left(): Facing = West
override fun right(): Facing = East
override fun move(pos: Position, steps: Int): Position = Po... | 0 | Java | 0 | 1 | 07d0f496d9efd620a21c906dd55f097326ab8b5f | 2,851 | advent-of-code | MIT License |
kotlin/src/com/s13g/aoc/aoc2021/Day13.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2021
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
/**
* --- Day 13: Transparent Origami ---
* https://adventofcode.com/2021/day/13
*/
class Day13 : Solver {
override fun solve(lines: List<String>): Result {
val positions = lines.filter { it.contains(',') }
.map { it.spl... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 1,656 | euler | Apache License 2.0 |
advent-of-code/src/main/kotlin/com/akikanellis/adventofcode/year2022/Day02.kt | akikanellis | 600,872,090 | false | {"Kotlin": 142932, "Just": 977} | package com.akikanellis.adventofcode.year2022
import com.akikanellis.adventofcode.year2022.Day02.RoundResult.DRAW
import com.akikanellis.adventofcode.year2022.Day02.RoundResult.LOSE
import com.akikanellis.adventofcode.year2022.Day02.RoundResult.WIN
object Day02 {
fun totalScoreForHands(input: String) = firstColum... | 8 | Kotlin | 0 | 0 | 036cbcb79d4dac96df2e478938de862a20549dce | 2,991 | advent-of-code | MIT License |
src/Day14.kt | thorny-thorny | 573,065,588 | false | {"Kotlin": 57129} | sealed class Line(val topY: Int) {
data class HorizontalInfinite(val y: Int): Line(y)
data class Horizontal(val y: Int, val xMin: Int, val xMax: Int): Line(y)
data class Vertical(val x: Int, val yMin: Int, val yMax: Int): Line(yMin)
fun hasX(value: Int) = when (this) {
is HorizontalInfinite -> ... | 0 | Kotlin | 0 | 0 | 843869d19d5457dc972c98a9a4d48b690fa094a6 | 4,101 | aoc-2022 | Apache License 2.0 |
src/Day12.kt | wbars | 576,906,839 | false | {"Kotlin": 32565} | import kotlin.math.min
fun main() {
fun solve(
input: List<String>,
iStart: Int,
jStart: Int,
iEnd: Int,
jEnd: Int
): Int {
val a = Array(input.size) { IntArray(input[0].length) { Int.MAX_VALUE } }
a[iStart][jStart] = 0
val v = Array(input.size) {... | 0 | Kotlin | 0 | 0 | 344961d40f7fc1bb4e57f472c1f6c23dd29cb23f | 3,464 | advent-of-code-2022 | Apache License 2.0 |
2021/src/main/kotlin/Day23.kt | eduellery | 433,983,584 | false | {"Kotlin": 97092} | import java.util.PriorityQueue
import kotlin.math.abs
class Day23(val input: List<String>) {
private val initialState = State.from(input)
private val extendedState = State.from(input.take(3) + " #D#C#B#A# " + " #D#B#A#C# " + input.takeLast(2))
fun solve1() = organizePods(initialState)
fun solve2... | 0 | Kotlin | 0 | 1 | 3e279dd04bbcaa9fd4b3c226d39700ef70b031fc | 4,831 | adventofcode-2021-2025 | MIT License |
src/main/kotlin/dev/bogwalk/batch8/Problem82.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch8
import java.util.PriorityQueue
/**
* Problem 82: Path Sum 3 Ways
*
* https://projecteuler.net/problem=82
*
* Goal: Find the minimum path sum for an NxN grid, by starting at any cell in the leftmost column
* and ending at any cell in the rightmost column, while only being able to move ... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 3,272 | project-euler-kotlin | MIT License |
src/com/kingsleyadio/adventofcode/y2021/day05/Solution.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2021.day05
import com.kingsleyadio.adventofcode.util.readInput
import kotlin.math.abs
fun main() {
println(solution(useDiagonals = false))
println(solution(useDiagonals = true))
}
fun solution(useDiagonals: Boolean): Int {
val points = hashSetOf<String>()
val re... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 1,223 | adventofcode | Apache License 2.0 |
src/Day14.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | import kotlin.math.sign
fun main() {
data class Pos(val row: Int, val column: Int) {
fun moveLeft() = Pos(row, column - 1)
fun moveRight() = Pos(row, column + 1)
fun moveDown() = Pos(row + 1, column)
}
fun parseWall(wallLine: String): List<Pos> =
wallLine
.split... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 3,334 | aoc2022 | Apache License 2.0 |
kotlin/reader-monad/src/main/kotlin/Main.kt | enolive | 65,559,078 | false | {"Java": 150911, "Kotlin": 130819, "TypeScript": 121966, "Groovy": 76917, "JavaScript": 53147, "C#": 40972, "Haskell": 36546, "Python": 14709, "Scala": 12193, "HTML": 11513, "Clojure": 8840, "Gherkin": 8730, "Dart": 6755, "Ruby": 5800, "CSS": 3279, "Elm": 2803, "PHP": 2211, "Svelte": 1783, "Rust": 821, "Swift": 404, "P... | fun main() {
println("\nFunctor\n")
val inc = { n: Int -> n + 1 }
val mult2 = { n: Int -> n * 2 }
val g1 = mult2.map(inc)
explain("g1(5)", g1(5))
println("\nApplicative\n")
val isValidCommand = { c: Char -> c in "fblr" }
val isInvalidCommand = isValidCommand.map(Boolean::not)
val any = { p: (Char)... | 88 | Java | 3 | 9 | f01141469ac86352f8dc511579ead10dc7563413 | 2,109 | learning | MIT License |
src/year2022/04/Day04.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2022.`04`
import readInput
fun main() {
fun List<Int>.asRange(): IntRange {
return first()..get(1)
}
fun IntRange.contains(range: IntRange): Boolean {
return first >= range.first && last <= range.last
}
fun IntRange.overlaps(range: IntRange): Boolean {
return... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 1,380 | KotlinAdventOfCode | Apache License 2.0 |
src/main/kotlin/day14/Day14.kt | Mee42 | 433,459,856 | false | {"Kotlin": 42703, "Java": 824} | package dev.mee42.day14
import dev.mee42.*
fun main(part: Part): Long {
val rawInput = input(day = 14, year = 2021)
val (start, lookup) = rawInput.trim().split("\n\n").let { (a, b) ->
a.map(::id) to b.lines().map { s ->
s.split(" -> ")
}.associate { (a, b) -> (a[0] to a[1]) to (b[0... | 0 | Kotlin | 0 | 0 | db64748abc7ae6a92b4efa8ef864e9bb55a3b741 | 1,573 | aoc-2021 | MIT License |
src/day17.kt | miiila | 725,271,087 | false | {"Kotlin": 77215} | import java.io.File
import java.util.*
import kotlin.system.exitProcess
private const val DAY = 17
fun main() {
if (!File("./day${DAY}_input").exists()) {
downloadInput(DAY)
println("Input downloaded")
exitProcess(0)
}
val transformer = { x: String -> x.toList().map { it.digitToInt... | 0 | Kotlin | 0 | 1 | 1cd45c2ce0822e60982c2c71cb4d8c75e37364a1 | 2,965 | aoc2023 | MIT License |
day12/src/main/kotlin/Day12.kt | bzabor | 160,240,195 | false | null |
class Day12(private val input: List<String>) {
val initialState = input[0].split(" ").takeLast(1)[0]
val rules = input.drop(2).map{ it.split(" => ")}.map{ it[0] to it[1]}.toMap()
val gens = 500
var prefixCount = 0
var initialPrefixLength = 20
fun part1(): Int {
println("Initial st... | 0 | Kotlin | 0 | 0 | 14382957d43a250886e264a01dd199c5b3e60edb | 3,026 | AdventOfCode2018 | Apache License 2.0 |
kotlin/src/main/kotlin/adventofcode/day12/Day12_2.kt | thelastnode | 160,586,229 | false | null | package adventofcode.day12
import java.io.File
import java.lang.Exception
import java.lang.IllegalArgumentException
object Day12_2 {
data class Rule(val condition: String, val result: Char)
fun parse(lines: List<String>): Pair<String, List<Rule>> {
val initialState = lines[0].split(": ")[1].trim()
... | 0 | Kotlin | 0 | 0 | 8c9a3e5a9c8b9dd49eedf274075c28d1ebe9f6fa | 2,425 | adventofcode | MIT License |
src/com/mrxyx/algorithm/BinarySearchTree.kt | Mrxyx | 366,778,189 | false | null | package com.mrxyx.algorithm
import com.mrxyx.algorithm.model.TreeNode
import kotlin.math.max
/**
* 二叉搜索树
*/
class BinarySearchTree {
/**
* 寻找第 K 小的元素
* https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/
* point: BST(二叉搜索树)中序遍历就是升序排列
*/
fun kthSmallest(root: TreeNode, k: In... | 0 | Kotlin | 0 | 0 | b81b357440e3458bd065017d17d6f69320b025bf | 8,471 | algorithm-test | The Unlicense |
plugin/src/main/kotlin/com/jraska/module/graph/DependencyGraph.kt | dafi | 230,582,038 | true | {"Kotlin": 20110} | package com.jraska.module.graph
class DependencyGraph() {
private val nodes = mutableMapOf<String, Node>()
fun findRoot(): Node {
require(nodes.isNotEmpty()) { "Dependency Tree is empty" }
val rootCandidates = nodes().toMutableSet()
nodes().flatMap { it.dependsOn }
.forEach { rootCandidates.re... | 0 | Kotlin | 0 | 0 | eee1159f56e7f8389f411b415b3a390c341e9dec | 2,572 | modules-graph-assert | Apache License 2.0 |
src/Day04.kt | achugr | 573,234,224 | false | null | fun main() {
class Interval(val left: Int, val right: Int) {
fun contain(interval: Interval): Boolean {
return (interval.left in left..right) and (interval.right in left..right)
}
fun overlap(interval: Interval): Boolean {
return (interval.left <= right) and (left <... | 0 | Kotlin | 0 | 0 | d91bda244d7025488bff9fc51ca2653eb6a467ee | 1,184 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day07/Day07.kt | gr4cza | 572,863,297 | false | {"Kotlin": 93944} | package day07
import readInput
fun main() {
val dirs = """(\$ cd [a-zA-Z/.]+)""".toRegex()
val files = """(\d+ .*)""".toRegex()
fun parseDirContent(input: List<String>): MutableMap<String, Long> {
val dirContent = mutableMapOf<String, Long>()
val currentDirs = mutableListOf<String>()
... | 0 | Kotlin | 0 | 0 | ceca4b99e562b4d8d3179c0a4b3856800fc6fe27 | 1,818 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/hopkins/aoc/day8/main.kt | edenrox | 726,934,488 | false | {"Kotlin": 88215} | package com.hopkins.aoc.day8
import java.io.File
const val debug = true
const val part = 2
/** Advent of Code 2023: Day 8 */
fun main() {
val inputFile = File("input/input8.txt")
val lines: List<String> = inputFile.readLines()
val directions = lines[0]
val nodes: List<Node> = lines.drop(2).map { pa... | 0 | Kotlin | 0 | 0 | 45dce3d76bf3bf140d7336c4767e74971e827c35 | 2,933 | aoc2023 | MIT License |
src/main/kotlin/graph/variation/ShortestPathInc.kt | yx-z | 106,589,674 | false | null | package graph.variation
import graph.core.Vertex
import graph.core.WeightedEdge
import graph.core.WeightedGraph
import graph.core.dijkstra
import util.INF
import util.Tuple2
import java.util.*
import kotlin.collections.set
// given a weighted graph G = (V, E) with each vertex having an int
// find a shortest path fro... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 2,632 | AlgoKt | MIT License |
src/Day05.kt | AxelUser | 572,845,434 | false | {"Kotlin": 29744} | import java.util.Stack
private data class Command(val quantity: Int, val from: Int, val to: Int)
fun main() {
fun List<String>.parseStacks(): Array<Stack<Char>> {
val indices = Regex("\\d").findAll(last()).map { it.range.first }.toList()
val stacks = Array(indices.size) { Stack<Char>() }
... | 0 | Kotlin | 0 | 1 | 042e559f80b33694afba08b8de320a7072e18c4e | 2,155 | aoc-2022 | Apache License 2.0 |
2021/kotlin/src/main/kotlin/com/pietromaggi/aoc2021/day12/Day12.kt | pfmaggi | 438,378,048 | false | {"Kotlin": 113883, "Zig": 18220, "C": 7779, "Go": 4059, "CMake": 386, "Awk": 184} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in wr... | 0 | Kotlin | 0 | 0 | 7c4946b6a161fb08a02e10e99055a7168a3a795e | 2,358 | AdventOfCode | Apache License 2.0 |
src/Day07/Day07.kt | Nathan-Molby | 572,771,729 | false | {"Kotlin": 95872, "Python": 13537, "Java": 3671} | package Day07
import readInput
class Node(val name: String, val parentNode: Node?, val size: Int?, val isDirectory: Boolean) {
var childNodes = mutableListOf<Node>()
fun addNode(node: Node) {
childNodes.add(node)
}
fun getSize(): Int {
if (size != null) {
return size
... | 0 | Kotlin | 0 | 0 | 750bde9b51b425cda232d99d11ce3d6a9dd8f801 | 3,115 | advent-of-code-2022 | Apache License 2.0 |
src/day9.kt | miiila | 725,271,087 | false | {"Kotlin": 77215} | import java.io.File
import kotlin.system.exitProcess
import kotlin.time.measureTime
private const val DAY = 9
fun main() {
if (!File("./day${DAY}_input").exists()) {
downloadInput(DAY)
println("Input downloaded")
exitProcess(0)
}
val transformer = { x: String -> x.split(" ").map(St... | 0 | Kotlin | 0 | 1 | 1cd45c2ce0822e60982c2c71cb4d8c75e37364a1 | 4,966 | aoc2023 | MIT License |
src/Day01.kt | emersonf | 572,870,317 | false | {"Kotlin": 17689} |
fun main() {
fun part1(input: List<String>): Int {
var maxTotal = 0
var currentTotal = 0
for (calories in input) {
if (calories.isBlank()) {
if (currentTotal > maxTotal) {
maxTotal = currentTotal
}
currentTotal ... | 0 | Kotlin | 0 | 0 | 0e97351ec1954364648ec74c557e18ccce058ae6 | 1,576 | advent-of-code-2022-kotlin | Apache License 2.0 |
app/src/main/kotlin/day15/Day15.kt | KingOfDog | 433,706,881 | false | {"Kotlin": 76907} | package day15
import common.InputRepo
import common.readSessionCookie
import common.solve
import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.math.sqrt
fun main(args: Array<String>) {
val day = 15
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay15... | 0 | Kotlin | 0 | 0 | 576e5599ada224e5cf21ccf20757673ca6f8310a | 4,146 | advent-of-code-kt | Apache License 2.0 |
src/poyea/aoc/mmxxii/day02/Day02.kt | poyea | 572,895,010 | false | {"Kotlin": 68491} | package poyea.aoc.mmxxii.day02
import poyea.aoc.utils.readInput
import kotlin.Int.Companion.MIN_VALUE
fun part1(input: String): Int {
return input.split("\n").map { it.split(" ") }.sumOf { info ->
when (info[1]) {
"X" -> {
when (info[0]) {
"A" -> 3 + 1
... | 0 | Kotlin | 0 | 1 | fd3c96e99e3e786d358d807368c2a4a6085edb2e | 1,887 | aoc-mmxxii | MIT License |
src/Day04.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | object Day04 {
const val EXPECTED_PART1_CHECK_ANSWER = 2
const val EXPECTED_PART2_CHECK_ANSWER = 4
}
fun main() {
fun String.parseToIntRangePerElf(): Pair<IntRange, IntRange> =
this
.split(",")
.map { it.split("-") }
.map { (it[0].toInt())..(it[1].toInt()) }
... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 1,328 | aoc-2022-in-kotlin | Apache License 2.0 |
year2023/src/cz/veleto/aoc/year2023/Day07.kt | haluzpav | 573,073,312 | false | {"Kotlin": 164348} | package cz.veleto.aoc.year2023
import cz.veleto.aoc.core.AocDay
import kotlin.math.pow
class Day07(config: Config) : AocDay(config) {
@Suppress("SpellCheckingInspection")
private val cards = "23456789TJQKA"
@Suppress("SpellCheckingInspection")
private val jokerCards = "J23456789TQKA"
private va... | 0 | Kotlin | 0 | 1 | 32003edb726f7736f881edc263a85a404be6a5f0 | 2,929 | advent-of-pavel | Apache License 2.0 |
2022/Day18/problems.kt | moozzyk | 317,429,068 | false | {"Rust": 102403, "C++": 88189, "Python": 75787, "Kotlin": 72672, "OCaml": 60373, "Haskell": 53307, "JavaScript": 51984, "Go": 49768, "Scala": 46794} | import java.io.File
import kotlin.math.*
typealias Position = Triple<Int, Int, Int>
fun main(args: Array<String>) {
val lines = File(args[0]).readLines()
val cubes =
lines.map { it.split(",").map { it.toInt() }.toList() }.map {
Position(it[0], it[1], it[2])
}
printl... | 0 | Rust | 0 | 0 | c265f4c0bddb0357fe90b6a9e6abdc3bee59f585 | 2,056 | AdventOfCode | MIT License |
src/main/kotlin/hexogen/algorithms/Graph.kt | MiloszKrajewski | 72,345,942 | false | null | package hexogen.algorithms
import hexogen.collections.DisjointSet
interface Edge<N> {
val A: N
val B: N
}
class Hybrid<N, E : Edge<N>>(edges: Sequence<E>, threshold: Double, rng: () -> Double) {
private val rng = rng
private val threshold = threshold
private val map = mapEdges(edges)
private ... | 0 | Kotlin | 0 | 0 | ea8437f50f0a4512b95404fa2d0780fd2ff1b924 | 2,455 | kotlinjs-hexagen-hybrid | MIT License |
src/main/kotlin/g1501_1600/s1584_min_cost_to_connect_all_points/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1501_1600.s1584_min_cost_to_connect_all_points
// #Medium #Array #Union_Find #Minimum_Spanning_Tree
// #2023_06_14_Time_331_ms_(95.12%)_Space_44.5_MB_(95.12%)
import java.util.PriorityQueue
class Solution {
fun minCostConnectPoints(points: Array<IntArray>): Int {
val v = points.size
if (... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,225 | LeetCode-in-Kotlin | MIT License |
src/Day05.kt | mkulak | 573,910,880 | false | {"Kotlin": 14860} | fun main() {
val regex = "move ([0-9]+) from ([0-9]+) to ([0-9]+)".toRegex()
fun part1(input: List<String>): String {
val part1 = input.takeWhile { it.startsWith("[") || it.startsWith(" ") }
val part2 = input.drop(part1.size + 2)
val stacks = List((input[part1.size].length + 2) / 4) {... | 0 | Kotlin | 0 | 0 | 3b4e9b32df24d8b379c60ddc3c007d4be3f17d28 | 1,946 | AdventOfKo2022 | Apache License 2.0 |
src/shreckye/coursera/algorithms/Course 2 Programming Assignment #3.kts | ShreckYe | 205,871,625 | false | {"Kotlin": 72136} | package shreckye.coursera.algorithms
import java.io.File
import java.util.*
import kotlin.random.Random
import kotlin.test.assertEquals
val NUM_INTEGERS = 10000
val filename = args[0]
val integers = File(filename).useLines { it.map(String::toInt).toIntArray(NUM_INTEGERS) }
fun medianSum(integers: IntArray): Int {
... | 0 | Kotlin | 1 | 2 | 1746af789d016a26f3442f9bf47dc5ab10f49611 | 1,668 | coursera-stanford-algorithms-solutions-kotlin | MIT License |
src/Day12.kt | buongarzoni | 572,991,996 | false | {"Kotlin": 26251} | import java.util.*
fun solveDay12() {
val input = readInput("Day12_test")
solve(input)
}
private fun solve(
input: List<String>,
) {
val grid = Grid.parse(input)
println("part 1 solution: ${grid.findShortedPath('S')}")
println("part 2 solution: ${grid.findShortedPath('a')}")
}
@JvmInline
valu... | 0 | Kotlin | 0 | 0 | 96aadef37d79bcd9880dbc540e36984fb0f83ce0 | 1,992 | AoC-2022 | Apache License 2.0 |
Problems/Algorithms/934. Shortest Bridge/ShortestBridge.kt | xuedong | 189,745,542 | false | {"Kotlin": 332182, "Java": 294218, "Python": 237866, "C++": 97190, "Rust": 82753, "Go": 37320, "JavaScript": 12030, "Ruby": 3367, "C": 3121, "C#": 3117, "Swift": 2876, "Scala": 2868, "TypeScript": 2134, "Shell": 149, "Elixir": 130, "Racket": 107, "Erlang": 96, "Dart": 65} | class Solution {
fun shortestBridge(grid: Array<IntArray>): Int {
val n = grid.size
val m = grid[0].size
val neighbors = arrayOf(intArrayOf(0, 1), intArrayOf(0, -1), intArrayOf(1, 0), intArrayOf(-1, 0))
val queue = ArrayDeque<IntArray>()
var flag = false
... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 2,245 | leet-code | MIT License |
src/Day03.kt | shoresea | 576,381,520 | false | {"Kotlin": 29960} | fun main() {
fun part1(inputs: List<String>): Int {
var sum = 0
for (input in inputs) {
sum += getPriority(input)
}
return sum
}
fun part2(inputs: List<String>): Int {
var sum = 0
var i = 0
while (i < inputs.size) {
sum += calc... | 0 | Kotlin | 0 | 0 | e5d21eac78fcd4f1c469faa2967a4fd9aa197b0e | 1,311 | AOC2022InKotlin | Apache License 2.0 |
src/main/kotlin/days/Day5.kt | hughjdavey | 725,972,063 | false | {"Kotlin": 76988} | package days
import xyz.hughjd.aocutils.Collections.split
class Day5 : Day(5) {
private val almanac = parseAlmanac()
override fun partOne(): Any {
return seedToLocationSequence()
.filter { almanac.hasInitialSeed(it.seed, false) }
.first().location
}
override fun part... | 0 | Kotlin | 0 | 0 | 330f13d57ef8108f5c605f54b23d04621ed2b3de | 2,496 | aoc-2023 | Creative Commons Zero v1.0 Universal |
untitled/src/main/kotlin/Day8.kt | jlacar | 572,845,298 | false | {"Kotlin": 41161} | class Day8(private val fileName: String) : AocSolution {
override val description: String get() = "Day 8 - Treetop Tree House ($fileName)"
override fun part1() = visibleTrees()
override fun part2() = scenicScores().max()
private val forestRows = InputReader(fileName).lines.map { it.toCharArray() }
... | 0 | Kotlin | 0 | 2 | dbdefda9a354589de31bc27e0690f7c61c1dc7c9 | 2,520 | adventofcode2022-kotlin | The Unlicense |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.