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 | dakr0013 | 572,861,855 | false | {"Kotlin": 105418} | import kotlin.streams.toList
import kotlin.test.assertEquals
fun main() {
fun part1(input: List<String>): Int {
return input
.map { rucksack ->
val firstCompartment =
rucksack.subSequence(0, rucksack.length / 2).chars().toList().toSet()
val secondCompartment =
... | 0 | Kotlin | 0 | 0 | 6b3adb09f10f10baae36284ac19c29896d9993d9 | 1,508 | aoc2022 | Apache License 2.0 |
src/Day07_part2.kt | abeltay | 572,984,420 | false | {"Kotlin": 91982, "Shell": 191} | fun main() {
fun part2(input: List<String>): Int {
data class Directory(
val name: String,
var size: Int = 0,
val subDirectories: MutableList<Directory> = mutableListOf()
)
fun changeDirectory(directory: Directory, name: String): Directory {
r... | 0 | Kotlin | 0 | 0 | a51bda36eaef85a8faa305a0441efaa745f6f399 | 2,278 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/kr/co/programmers/P72413.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
import java.util.*
class P72413 {
companion object {
const val INF = (100_000 * 200) + 1
}
fun solution(n: Int, s: Int, a: Int, b: Int, fares: Array<IntArray>): Int {
// 지점 → (지점들,택시요금)
val paths = paths(n, fares)
// 다익스트라
val office = dij... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,670 | algorithm | MIT License |
kotlin/src/com/s13g/aoc/aoc2020/Day16.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2020
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import com.s13g.aoc.mul
/**
* --- Day 16: Ticket Translation ---
* https://adventofcode.com/2020/day/16
*/
val rangeRegEx = """(.+): (\d+)-(\d+) or (\d+)-(\d+)""".toRegex()
class Day16 : Solver {
override fun solve(lines: List<S... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 3,810 | euler | Apache License 2.0 |
2021/src/day13/Solution.kt | vadimsemenov | 437,677,116 | false | {"Kotlin": 56211, "Rust": 37295} | package day13
import java.nio.file.Files
import java.nio.file.Paths
fun main() {
fun log(field: Array<BooleanArray>) = buildString {
for (y in field[0].indices) {
for (x in field.indices) {
append(if (field[x][y]) '#' else '.')
}
append('\n')
}
}.let { System.err.println(it) }
... | 0 | Kotlin | 0 | 0 | 8f31d39d1a94c862f88278f22430e620b424bd68 | 2,865 | advent-of-code | Apache License 2.0 |
2022/src/test/kotlin/Day08.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
class Day08 : StringSpec({
"puzzle part 01" {
val (trees, maxX, maxY) = getTreesWithSizing()
val countOfVisibleTrees = (0..maxX).sumOf { x ->
(0..maxY).count { y ->
val height = trees[x][y]
... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 1,623 | adventofcode | MIT License |
src/main/kotlin/dp/LIBFS.kt | yx-z | 106,589,674 | false | null | package dp
import util.OneArray
import util.max
import util.oneArrayOf
import util.toOneArray
// longest increasing back and forth subsequence
// given A[1..n], an array of (Int, Color) pair
// its ibfs, I[1..l] follows:
// 1 <= I[j] <= n
// A[I[j]] < A[I[j + 1]]
// If A[I[j]] is Red, then I[j + 1] > I[j]
// If A[I[j... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 2,271 | AlgoKt | MIT License |
src/Day04.kt | zdenekobornik | 572,882,216 | false | null | fun main() {
fun part1(input: List<String>): Int {
return input.map {
it.split(',', limit = 2)
.map {
it.split('-', limit = 2).map(String::toInt)
}
}.count { (l, r) ->
(l[0] >= r[0] && l[1] <= r[1]) || (r[0] >= l[0] && r[1... | 0 | Kotlin | 0 | 0 | f73e4a32802fa43b90c9d687d3c3247bf089e0e5 | 1,047 | advent-of-code-2022 | Apache License 2.0 |
src/questions/SummaryRanges.kt | realpacific | 234,499,820 | false | null | package questions
import utils.shouldBe
/**
* You are given a sorted unique integer array nums.
*
* Return the smallest sorted list of ranges that cover all the numbers in the array exactly.
* That is, each element of nums is covered by exactly one of the ranges,
* and there is no integer x such that x is in one... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,263 | algorithms | MIT License |
src/main/kotlin/Day02.kt | robfletcher | 724,814,488 | false | {"Kotlin": 18682} | class Day02 : Puzzle {
override fun test() {
val testInput = """
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green,... | 0 | Kotlin | 0 | 0 | cf10b596c00322ea004712e34e6a0793ba1029ed | 1,549 | aoc2023 | The Unlicense |
solutions/aockt/y2023/Y2023D12.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2023
import aockt.util.parse
import aockt.y2023.Y2023D12.Condition.Damaged
import aockt.y2023.Y2023D12.Condition.Operational
import aockt.y2023.Y2023D12.Condition.Unknown
import io.github.jadarma.aockt.core.Solution
object Y2023D12 : Solution {
/** The condition record of a spring. If unknown, can... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 5,255 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/dev/paulshields/aoc/day5/BinaryBoarding.kt | Pkshields | 318,658,287 | false | null | package dev.paulshields.aoc.day5
import dev.paulshields.aoc.common.readFileAsStringList
private const val lowerRowRegionId = 'F'
private const val lowerColumnRegionId = 'L'
private val rows = 0..127
private val columns = 0..7
fun main() {
println(" ** Day 5: Binary Boarding ** \n")
val boardingPasses = read... | 0 | Kotlin | 0 | 0 | a7bd42ee17fed44766cfdeb04d41459becd95803 | 2,253 | AdventOfCode2020 | MIT License |
src/aoc2022/Day02.kt | FluxCapacitor2 | 573,641,929 | false | {"Kotlin": 56956} | package aoc2022
import Day
object Day02 : Day(2022, 2) {
// Read input from a file
private val split = input.lines()
// Split each line into a player and opponent move; they are separated by one space
.map { it.split(' ') }
override fun part1() {
val totalPointValue1 = split
... | 0 | Kotlin | 0 | 0 | a48d13763db7684ee9f9129ee84cb2f2f02a6ce4 | 3,394 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | PauliusRap | 573,434,850 | false | {"Kotlin": 20299} | private const val CHAR_CODE_OFFSET_UPPERCASE = 64
private const val CHAR_CODE_OFFSET_LOWERCASE = 96
private const val POINTS_OFFSET_UPPERCASE = 26
fun main() {
fun getValueFromChar(char: Char) =
if (char.isUpperCase()) {
char.code - CHAR_CODE_OFFSET_UPPERCASE + POINTS_OFFSET_UPPERCASE
... | 0 | Kotlin | 0 | 0 | df510c3afb104c03add6cf2597c433b34b3f7dc7 | 1,839 | advent-of-coding-2022 | Apache License 2.0 |
src/main/kotlin/ch/uzh/ifi/seal/bencher/prioritization/Prioritizer.kt | chrstphlbr | 227,602,878 | false | {"Kotlin": 918163, "Java": 29153} | package ch.uzh.ifi.seal.bencher.prioritization
import arrow.core.Either
import ch.uzh.ifi.seal.bencher.Benchmark
import kotlin.random.Random
interface Prioritizer {
// takes an Iterable of benchmarks and returns a prioritized list of these methods sorted by their priority (descending)
// might not include ben... | 0 | Kotlin | 2 | 4 | 06601fb4dda3b2996c2ba9b2cd612e667420006f | 3,006 | bencher | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2023/2023-13.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2023
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputText
fun main() {
val input = readInputText(2023, "13-input")
val test1 = readInputText(2023, "13-test1")
print... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,652 | advent-of-code | MIT License |
src/day20/Day20.kt | Volifter | 572,720,551 | false | {"Kotlin": 65483} | package day20
import utils.*
const val KEY = 811589153
class Element<T>(val value: T) {
private var prev: Element<T> = this
private var next: Element<T> = this
private val sequence get() = generateSequence(this) { it.next }
private val reverseSequence get() = generateSequence(this) { it.prev }
... | 0 | Kotlin | 0 | 0 | c2c386844c09087c3eac4b66ee675d0a95bc8ccc | 2,395 | AOC-2022-Kotlin | Apache License 2.0 |
src/Day02.kt | ochim | 579,680,353 | false | {"Kotlin": 3652} | fun main() {
val baseScores = mapOf(
'X' to 1, //Rock
'Y' to 2, //Paper
'Z' to 3 //Scissors
)
val roundScores = mapOf(
"A X" to 3,
"A Y" to 6,
"A Z" to 0,
"B X" to 0,
"B Y" to 3,
"B Z" to 6,
"C X" to 6,
"C Y" to 0,
... | 0 | Kotlin | 0 | 0 | b5d34a8f0f3000c8ad4afd7726dd93171baee76e | 1,287 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day09.kt | konclave | 573,548,763 | false | {"Kotlin": 21601} | import kotlin.math.abs
class Dot {
private var x: Int = 0
private var y: Int = 0
private var visited: MutableSet<String> = mutableSetOf("0,0")
val visitedCount: Int
get() {
return visited.size
}
fun move(command: String): Pair<Int, Int> {
when (command) {
... | 0 | Kotlin | 0 | 0 | 337f8d60ed00007d3ace046eaed407df828dfc22 | 2,107 | advent-of-code-2022 | Apache License 2.0 |
leetcode-75-kotlin/src/main/kotlin/FindTheDifferenceOfTwoArrays.kt | Codextor | 751,507,040 | false | {"Kotlin": 49566} | /**
* Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:
*
* answer[0] is a list of all distinct integers in nums1 which are not present in nums2.
* answer[1] is a list of all distinct integers in nums2 which are not present in nums1.
* Note that the integers in the lists may... | 0 | Kotlin | 0 | 0 | 0511a831aeee96e1bed3b18550be87a9110c36cb | 1,602 | leetcode-75 | Apache License 2.0 |
src/Day05.kt | hiteshchalise | 572,795,242 | false | {"Kotlin": 10694} | fun main() {
fun part1(input: List<String>): String {
val splitIndex = input.indexOfFirst { it.isEmpty() }
val stackInput = input.subList(0, splitIndex - 1)
val instructionInput = input.subList(splitIndex + 1, input.size)
val sanitizedStackInput = stackInput.map { line -> line.windo... | 0 | Kotlin | 0 | 0 | e4d66d8d1f686570355b63fce29c0ecae7a3e915 | 2,383 | aoc-2022-kotlin | Apache License 2.0 |
src/com/kingsleyadio/adventofcode/y2022/day07/Alternative.kt | kingsleyadio | 435,430,807 | false | {"Kotlin": 134666, "JavaScript": 5423} | package com.kingsleyadio.adventofcode.y2022.day07
import com.kingsleyadio.adventofcode.util.readInput
fun main() {
val fsMap = buildFs()
part1(fsMap)
part2(fsMap)
}
fun part1(fs: Map<String, Int>) {
val result = fs.values.filter { it <= 100_000 }.sum()
println(result)
}
fun part2(fs: Map<String,... | 0 | Kotlin | 0 | 1 | 9abda490a7b4e3d9e6113a0d99d4695fcfb36422 | 1,503 | adventofcode | Apache License 2.0 |
src/adventofcode/day07/Day07.kt | bstoney | 574,187,310 | false | {"Kotlin": 27851} | package adventofcode.day07
import adventofcode.AdventOfCodeSolution
import adventofcode.peek
import java.util.Stack
fun main() {
Solution.solve()
}
object Solution : AdventOfCodeSolution<Int>() {
override fun solve() {
solve(7, 95437, 24933642)
}
override fun part1(input: List<String>): Int ... | 0 | Kotlin | 0 | 0 | 81ac98b533f5057fdf59f08940add73c8d5df190 | 3,480 | fantastic-chainsaw | Apache License 2.0 |
src/main/kotlin/de/tek/adventofcode/y2022/day12/HillClimbingAlgorithm.kt | Thumas | 576,671,911 | false | {"Kotlin": 192328} | package de.tek.adventofcode.y2022.day12
import de.tek.adventofcode.y2022.util.math.Direction
import de.tek.adventofcode.y2022.util.math.Graph
import de.tek.adventofcode.y2022.util.math.Grid
import de.tek.adventofcode.y2022.util.math.Point
import de.tek.adventofcode.y2022.util.readInputLines
class HeightMap(map: Array... | 0 | Kotlin | 0 | 0 | 551069a21a45690c80c8d96bce3bb095b5982bf0 | 4,254 | advent-of-code-2022 | Apache License 2.0 |
src/aoc2017/kot/Day14.kt | Tandrial | 47,354,790 | false | null | package aoc2017.kot
import toHexString
import java.math.BigInteger
object Day14 {
fun solve(input: String): Pair<Int, Int> {
val hashList = genHashList(input)
val partOne = hashList.sumBy { it.count { it == '1' } }
val hashArray = hashList.map { it.map { (it - '0') }.toIntArray() }.toTypedArray()
... | 0 | Kotlin | 1 | 1 | 9294b2cbbb13944d586449f6a20d49f03391991e | 1,792 | Advent_of_Code | MIT License |
src/main/kotlin/mkuhn/aoc/Day18.kt | mtkuhn | 572,236,871 | false | {"Kotlin": 53161} | package mkuhn.aoc
fun day18part1(input: List<String>): Int {
val cubeField = input.map { Point3D.fromString(it) }.toSet()
return cubeField.countExposedFaces()
}
fun day18part2(input: List<String>): Int {
val cubeField = input.map { Point3D.fromString(it) }.toSet()
val airCubes = cubeField.invertCubes... | 0 | Kotlin | 0 | 1 | 89138e33bb269f8e0ef99a4be2c029065b69bc5c | 2,253 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | pimts | 573,091,164 | false | {"Kotlin": 8145} | fun main() {
fun part1(input: List<String>): Int {
/*
A = X = ROCK = 1
B = Y = PAPER = 2
C = Z = SCISSORS = 3
*/
val finalScoresMap = mapOf(
"AX" to 4, "AY" to 8, "AZ" to 3,
"BX" to 1, "BY" to 5, "BZ" to 9,
"CX" to 7, "... | 0 | Kotlin | 0 | 0 | dc7abb10538bf6ad9950a079bbea315b4fbd011b | 1,236 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day04/Day04.kt | Mini-Stren | 573,128,699 | false | null | package day04
import readInputLines
fun main() {
val day = 4
fun part1(input: List<String>): Int {
return input.elvesAssignments.count { (firstElfAssignment, secondElfAssignment) ->
fullyContainsOneAnother(firstElfAssignment, secondElfAssignment)
}
}
fun part2(input: Lis... | 0 | Kotlin | 0 | 0 | 40cb18c29089783c9b475ba23c0e4861d040e25a | 1,428 | aoc-2022-kotlin | Apache License 2.0 |
src/Day21.kt | Kvest | 573,621,595 | false | {"Kotlin": 87988} | fun main() {
val testInput = readInput("Day21_test")
val testOperations = testInput.toOperations()
check(part1(testOperations) == 152L)
check(part2(testOperations) == 301L)
val input = readInput("Day21")
val operations = input.toOperations()
println(part1(operations))
println(part2(oper... | 0 | Kotlin | 0 | 0 | 6409e65c452edd9dd20145766d1e0ea6f07b569a | 5,664 | AOC2022 | Apache License 2.0 |
src/main/kotlin/Day07.kt | robfletcher | 724,814,488 | false | {"Kotlin": 18682} | import Day07.HandType.*
import java.util.Comparator
class Day07 : Puzzle {
override fun test() {
val input = """
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483""".trimIndent()
assert(part1(input.lineSequence()) == 6440)
assert(part2(input.lineSequence()) == 5905)
}
f... | 0 | Kotlin | 0 | 0 | cf10b596c00322ea004712e34e6a0793ba1029ed | 2,420 | aoc2023 | The Unlicense |
src/Day05.kt | BionicCa | 574,904,899 | false | {"Kotlin": 20039} | private fun getVerticalStacks(input: List<String>): List<ArrayDeque<Char>> {
val strLen = input.last().length
val stackRows = input.map { line ->
val padLine = line.padEnd(strLen, ' ')
val row = mutableListOf<Char>()
for (i in 1 until strLen step 4) {
val c = padLine[i]
... | 0 | Kotlin | 0 | 0 | ed8bda8067386b6cd86ad9704bda5eac81bf0163 | 2,515 | AdventOfCode2022 | Apache License 2.0 |
src/Day02.kt | hijst | 572,885,261 | false | {"Kotlin": 26466} | fun main() {
fun calculateScore(game: Pair<String, String>): Int =
when (game) {
Pair("A", "X") -> 4
Pair("A", "Y") -> 8
Pair("A", "Z") -> 3
Pair("B", "X") -> 1
Pair("B", "Y") -> 5
Pair("B", "Z") -> 9
Pair("C", "X") -> 7
... | 0 | Kotlin | 0 | 0 | 2258fd315b8933642964c3ca4848c0658174a0a5 | 1,515 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/com/staricka/adventofcode2023/days/Day7.kt | mathstar | 719,656,133 | false | {"Kotlin": 107115} | package com.staricka.adventofcode2023.days
import com.staricka.adventofcode2023.framework.Day
class Day7: Day {
enum class CardRank {
A, K, Q, J, T, `9`, `8`, `7`, `6`, `5`, `4`, `3`, `2`, `1`
}
enum class CardRankWithJokers {
A, K, Q, T, `9`, `8`, `7`, `6`, `5`, `4`, `3`, `2`, `1`, J
... | 0 | Kotlin | 0 | 0 | 8c1e3424bb5d58f6f590bf96335e4d8d89ae9ffa | 3,906 | adventOfCode2023 | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2016/Day11.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2016
import se.saidaspen.aoc.util.Day
import se.saidaspen.aoc.util.bfs
import se.saidaspen.aoc.util.pairWise
fun main() = Day11.run()
object Day11 : Day(2016, 11) {
private val itemsLocs = input.lines().map {
it.substring(it.indexOf("contains") + 8)
.split(",|and"... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 4,077 | adventofkotlin | MIT License |
src/main/kotlin/dev/paulshields/aoc/day1/ReportRepair.kt | Pkshields | 318,658,287 | false | null | package dev.paulshields.aoc.day1
import dev.paulshields.aoc.common.readFileAsString
fun main() {
println(" ** Day 1: Report Repair ** \n")
val expenseReport = readFileAsString("/day1/ExpenseReport.txt")
.lines()
.mapNotNull { it.toIntOrNull() }
val validPair = findSum(expenseReport, 2020... | 0 | Kotlin | 0 | 0 | a7bd42ee17fed44766cfdeb04d41459becd95803 | 2,107 | AdventOfCode2020 | MIT License |
src/Day08.kt | xNakero | 572,621,673 | false | {"Kotlin": 23869} | object Day08 {
fun part1() = parseInput().filterTreesWithVisibility().count()
fun part2() = parseInput().scenicScores().max()
private fun parseInput(): Forest = readInput("day08")
.let {
Forest(it[0].length, it.joinToString("").chunked(1).map { e -> e.toInt() })
}
}
data clas... | 0 | Kotlin | 0 | 0 | c3eff4f4c52ded907f2af6352dd7b3532a2da8c5 | 1,860 | advent-of-code-2022 | Apache License 2.0 |
src/Day14.kt | ked4ma | 573,017,240 | false | {"Kotlin": 51348} | import kotlin.math.max
import kotlin.math.min
/**
* [Day14](https://adventofcode.com/2022/day/14)
*/
private class Day14 {
data class Point(val x: Int, val y: Int)
}
fun main() {
fun toPathList(input: List<String>): List<List<Day14.Point>> = input.map { line ->
line.split(" -> ").map {
... | 1 | Kotlin | 0 | 0 | 6d4794d75b33c4ca7e83e45a85823e828c833c62 | 3,137 | aoc-in-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch9/Problem94.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch9
import java.math.BigDecimal
import java.math.MathContext
import java.math.RoundingMode
/**
* Problem 94: Almost Equilateral Triangles
*
* https://projecteuler.net/problem=94
*
* Goal: Find the sum of the perimeters of all almost equilateral triangles with integral side
* lengths and i... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 3,398 | project-euler-kotlin | MIT License |
src/day18/Code.kt | fcolasuonno | 162,470,286 | false | null | package day18
import java.io.File
private val Coord.neighbours: List<Coord>
get() = listOf(
(first - 1) to (second - 1),
(first - 1) to (second),
(first - 1) to (second + 1),
(first) to (second - 1),
(first) to (second + 1),
(first + 1) to (second - 1),
(fir... | 0 | Kotlin | 0 | 0 | 24f54bf7be4b5d2a91a82a6998f633f353b2afb6 | 2,162 | AOC2015 | MIT License |
src/day4/Day04_B.kt | HGilman | 572,891,570 | false | {"Kotlin": 109639, "C++": 5375, "Python": 400} | package day4
import readInput
fun main() {
val testInput = readInput("day4/Day04_test")
check(Day4B.part1(testInput) == 2)
val input = readInput("day4/Day04")
println(Day4B.part1(input))
println(Day4B.part2(input))
}
object Day4B {
fun part1(input: List<String>) = getState(input).count { s... | 0 | Kotlin | 0 | 1 | d05a53f84cb74bbb6136f9baf3711af16004ed12 | 1,473 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | kenyee | 573,186,108 | false | {"Kotlin": 57550} |
fun main() { // ktlint-disable filename
val winningRoundValue = 6
val tieRoundValue = 3
val elfShapeValue = mapOf(
'A' to 1, // rock
'B' to 2, // paper
'C' to 3 // scissors
)
val myShapeValue = mapOf(
'X' to 1,
'Y' to 2,
'Z' to 3
)
val winVal... | 0 | Kotlin | 0 | 0 | 814f08b314ae0cbf8e5ae842a8ba82ca2171809d | 2,265 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/be/twofold/aoc2021/Day04.kt | jandk | 433,510,612 | false | {"Kotlin": 10227} | package be.twofold.aoc2021
object Day04 {
fun part1(boards: List<Board>, inputs: IntArray): Int {
for (input in inputs) {
for (board in boards) {
val mark = board.mark(input)
if (mark != -1) {
return mark
}
}
... | 0 | Kotlin | 0 | 0 | 2408fb594d6ce7eeb2098bc2e38d8fa2b90f39c3 | 2,280 | aoc2021 | MIT License |
src/Day08.kt | mkulak | 573,910,880 | false | {"Kotlin": 14860} | fun main() {
fun part1(input: List<String>): Int {
val originalData = input.map { line -> line.map { it.code - '0'.code }.toIntArray() }
val visible = HashSet<Int>()
val width = originalData[0].size
val height = originalData.size
var data = originalData.map { it.clone() }
... | 0 | Kotlin | 0 | 0 | 3b4e9b32df24d8b379c60ddc3c007d4be3f17d28 | 2,699 | AdventOfKo2022 | Apache License 2.0 |
src/Day09.kt | rweekers | 573,305,041 | false | {"Kotlin": 38747} | import kotlin.math.sign
fun main() {
fun part1(headSteps: List<Point>): Int {
return determineTailSteps(headSteps).distinct().size
}
fun part2(headSteps: List<Point>): Int {
return (1..9).fold(headSteps) { acc, _ ->
determineTailSteps(acc)
}.distinct().size
}
// t... | 0 | Kotlin | 0 | 1 | 276eae0afbc4fd9da596466e06866ae8a66c1807 | 3,083 | adventofcode-2022 | Apache License 2.0 |
src/main/kotlin/day11/part2/Part2.kt | bagguley | 329,976,670 | false | null | package day11.part2
import day11.data
fun main() {
var seats = data.map { it.toCharArray() }
while (true) {
val x = process2(seats)
if (compare2(x, seats)) break
seats = x
}
val z = seats.map { it.count { it == '#' } }.sum()
println(z)
}
fun process2(seats: List<CharArray... | 0 | Kotlin | 0 | 0 | 6afa1b890924e9459f37c604b4b67a8f2e95c6f2 | 2,348 | adventofcode2020 | MIT License |
src/Day07.kt | ricardorlg-yml | 573,098,872 | false | {"Kotlin": 38331} | class Directory(
val name: String,
val parent: Directory? = null,
private val isDirectory: Boolean = true,
private val fileSize: Int = 0,
val subDirectories: MutableMap<String, Directory> = mutableMapOf(),
) {
val size: Int by lazy {
fileSize + subDirectories.values.sumOf { it.size }
... | 0 | Kotlin | 0 | 0 | d7cd903485f41fe8c7023c015e4e606af9e10315 | 2,968 | advent_code_2022 | Apache License 2.0 |
2023/src/day03/day03.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day03
import GREEN
import RESET
import printTimeMillis
import readInput
private fun isSymbol(input: List<String>, y: Int, x: Int) : Boolean {
if (y < 0 || y >= input.size) return false
if (x < 0 || x >= input[y].length) return false
val c = input[y][x]
return !c.isDigit() && c != '.'
}
priva... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 3,542 | advent-of-code | Apache License 2.0 |
src/Day07.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | data class File(
val name: String,
val size: Long
)
class Node(
val name: String,
var parent: Node?,
val dirs: MutableMap<String, Node> = mutableMapOf(),
val files: MutableList<File> = mutableListOf()
) {
val size: Long
get() {
val fileSize = files.map(File::size).sum()
... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 3,608 | aoc22-kotlin | Apache License 2.0 |
src/year_2022/day_09/Day09.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2022.day_09
import readInput
import kotlin.math.abs
enum class Direction(val letter: String, val xMod: Int, val yMod: Int) {
UP("U", 0, 1),
DOWN("D", 0, -1),
LEFT("L", -1, 0),
RIGHT("R", 1, 0),
;
}
data class Movement(
val direction: Direction,
val quantity: Int
)
data class... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 3,463 | advent_of_code | Apache License 2.0 |
src/main/kotlin/year2022/Day02.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2022
class Day02 {
enum class Move(private val points: Int) {
ROCK(1), PAPER(2), SCISSORS(3);
fun score(other: Move): Int = when {
this == other -> Outcome.DRAW
this.ordinal == (other.ordinal + 1) % Move.entries.size -> Outcome.WIN
else -> Outcome... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 1,787 | aoc-2022 | Apache License 2.0 |
src/Day10.kt | vi-quang | 573,647,667 | false | {"Kotlin": 49703} | import kotlin.math.abs
import kotlin.streams.asSequence
/**
* It's one line solution day for a change of pace.
*/
fun main() {
fun getSequence(input: List<String>): Map<Int, List<Pair<Int, Int>>> {
return input.stream().map { it.replace("addx ", "noop noop,noop") }
.asSequence()
... | 0 | Kotlin | 0 | 2 | ae153c99b58ba3749f16b3fe53f06a4b557105d3 | 1,634 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | jgodort | 573,181,128 | false | null | import HandShape.*
import RoundResult.*
enum class HandShape(val points: Int) {
Rock(1),
Paper(2),
Scissors(3)
}
enum class RoundResult(val points: Int) {
WIN(6),
LOSE(0),
DRAW(3)
}
fun main() {
val inputData = readInput("Day2_input")
println("""Result 1 ${part1(inputData)}""")
... | 0 | Kotlin | 0 | 0 | 355f476765948c79bfc61367c1afe446fe9f6083 | 2,745 | aoc2022Kotlin | Apache License 2.0 |
src/Day07.kt | oleksandrbalan | 572,863,834 | false | {"Kotlin": 27338} | fun main() {
val input = readInput("Day07")
.drop(1)
.filterNot { it.isEmpty() }
val root = Directory("/")
var node = root
input.forEach { row ->
when {
row.startsWith(COMMAND_CD) -> {
val dirName = row.drop(COMMAND_CD.length)
node = i... | 0 | Kotlin | 0 | 2 | 1493b9752ea4e3db8164edc2dc899f73146eeb50 | 2,138 | advent-of-code-2022 | Apache License 2.0 |
src/utils/NeighbourFunction.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package utils
import java.util.PriorityQueue
/**
* Thanks to [https://github.com/Mistborn94/advent-of-code-2023/blob/master/src/main/kotlin/day17/Day17.kt]
*/
typealias NeighbourFunction<K> = (K) -> Iterable<K>
typealias CostFunction<K> = (K, K) -> Int
typealias HeuristicFunction<K> = (K) -> Int
/**
* Implements ... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 3,173 | KotlinAdventOfCode | Apache License 2.0 |
ceria/19/src/main/kotlin/Solution.kt | VisionistInc | 317,503,410 | false | null | import java.io.File
fun main(args : Array<String>) {
val input = File(args.first()).readLines()
println("Solution 1: ${solution1(input)}")
println("Solution 2: ${solution2(input)}")
}
private fun solution1(input :List<String>) :Int {
var rulesMap = mutableMapOf<String, String>()
val rules = input.subList(0,... | 0 | Rust | 0 | 0 | 002734670384aa02ca122086035f45dfb2ea9949 | 4,347 | advent-of-code-2020 | MIT License |
src/main/kotlin/pl/jpodeszwik/aoc2023/Day13.kt | jpodeszwik | 729,812,099 | false | {"Kotlin": 55101} | package pl.jpodeszwik.aoc2023
private fun findAnagram(ints: List<Int>, notEqualTo: Int? = null): Int? {
var biggestAnagram: Int? = null
var biggestAnagramLength = 0
for (i in 1..<ints.size) {
val toLeft = ints.subList(0, i).asReversed()
val toRight = ints.subList(i, ints.size)
var ... | 0 | Kotlin | 0 | 0 | 2b90aa48cafa884fc3e85a1baf7eb2bd5b131a63 | 3,386 | advent-of-code | MIT License |
2023/src/main/kotlin/Day08.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | object Day08 {
private data class Data(val directions: String, val nodes: Map<String, Node>)
private data class Node(val label: String, val left: String, val right: String)
fun part1(input: String): Int {
return cycleLength(parseInput(input), "AAA", "ZZZ")
}
fun part2(input: String): Long {
val ma... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 1,492 | advent-of-code | MIT License |
src/Day02.kt | f1qwase | 572,888,869 | false | {"Kotlin": 33268} | enum class RpsFigure(val value: Int) {
ROCK(1),
PAPER(2),
SCISSORS(3);
fun play(other: RpsFigure): PlayResult {
return when ((this.ordinal - other.ordinal + 3) % 3) {
0 -> PlayResult.DRAW
1 -> PlayResult.WIN
2 -> PlayResult.LOSE
else -> throw Ille... | 0 | Kotlin | 0 | 0 | 3fc7b74df8b6595d7cd48915c717905c4d124729 | 1,908 | aoc-2022 | Apache License 2.0 |
src/day05/Day05_functional.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day05
import readLines
/**
* 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 solutions.
*/
private fun Iterable<Iterable<Char>>.tops()... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 2,725 | aoc2022 | Apache License 2.0 |
2022/src/day04/day04.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day04
import GREEN
import RESET
import printTimeMillis
import readInput
data class Bound(val min: Int, val max: Int) {
fun contains(other: Bound) = min <= other.min && max >= other.max
fun overlap(other: Bound) = (min >= other.min && min <= other.max) || (max <= other.max && max >= other.min)
}
fun p... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 1,447 | advent-of-code | Apache License 2.0 |
05/part_two.kt | ivanilos | 433,620,308 | false | {"Kotlin": 97993} | import java.io.File
import kotlin.math.*
fun readInput() : List<Line> {
val inputLines = File("input.txt")
.readLines()
.map { it.split("\n") }
val intRegex = """\d+""".toRegex()
val lines = inputLines.map{ inputLine -> Line(intRegex.findAll(inputLine[0])
.map{ it.valu... | 0 | Kotlin | 0 | 3 | a24b6f7e8968e513767dfd7e21b935f9fdfb6d72 | 1,561 | advent-of-code-2021 | MIT License |
aoc-day8/src/Day8.kt | rnicoll | 438,043,402 | false | {"Kotlin": 90620, "Rust": 1313} | import java.nio.file.Files
import java.nio.file.Path
import java.util.*
fun main() {
val scenarios = Files.readAllLines(Path.of("input")).map {
Scenario.parse(it)
}.toList()
part1(scenarios)
part2(scenarios)
}
fun part1(scenarios: List<Scenario>) {
val uniqueDigits = EnumSet.of(Digit.ONE, ... | 0 | Kotlin | 0 | 0 | 8c3aa2a97cb7b71d76542f5aa7f81eedd4015661 | 3,105 | adventofcode2021 | MIT License |
2022/src/main/kotlin/com/github/akowal/aoc/Day14.kt | akowal | 573,170,341 | false | {"Kotlin": 36572} | package com.github.akowal.aoc
import kotlin.math.max
import kotlin.math.min
class Day14 {
private val map = inputFile("day14").readLines()
.map { line ->
line.split(" -> ").map { point ->
point.split(",").map(String::toInt).let { (x, y) -> Point(x, y) }
}
}
... | 0 | Kotlin | 0 | 0 | 02e52625c1c8bd00f8251eb9427828fb5c439fb5 | 1,874 | advent-of-kode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/aoc2020/ConwayCubes.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2020
import komu.adventofcode.utils.nonEmptyLines
fun conwayCubes(input: String, fourDee: Boolean): Int {
var grid = ConwayGrid.parse(input)
repeat(6) {
grid = grid.step(fourDee)
}
return grid.activeCells.size
}
private data class ConwayPoint(val x: Int, val y: ... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 2,450 | advent-of-code | MIT License |
src/year2023/15/Day15.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2023.`15`
import readInput
import utils.printlnDebug
private const val CURRENT_DAY = "15"
data class Label(
val data: String,
val operation: String,
val number: Int?,
) {
override fun toString(): String = "[$data $number]"
}
private fun parseLineInto(
line: String
): List<String> = ... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 3,854 | KotlinAdventOfCode | Apache License 2.0 |
src/Day14.kt | JanTie | 573,131,468 | false | {"Kotlin": 31854} | fun main() {
fun Pair<Int, Int>.bottom() = this.copy(second = second + 1)
fun Pair<Int, Int>.bottomLeft() = this.copy(first = first - 1, second = second + 1)
fun Pair<Int, Int>.bottomRight() = this.copy(first = first + 1, second = second + 1)
fun Pair<Int, Int>.move(blockedFields: Set<Pair<Int, Int>>) ... | 0 | Kotlin | 0 | 0 | 3452e167f7afe291960d41b6fe86d79fd821a545 | 2,993 | advent-of-code-2022 | Apache License 2.0 |
konfork-predicates/src/commonMain/kotlin/io/github/konfork/predicates/CheckDigits.kt | konfork | 557,451,504 | false | {"Kotlin": 142473, "Java": 904} | package io.github.konfork.predicates
fun isMod10(evenWeight: Int, oddWeight: Int): (String) -> Boolean {
val weightSequence = alternatingSequence(evenWeight, oddWeight)
return { isMod10(it, weightSequence, Int::times) }
}
fun isEan(length: Int): (String) -> Boolean {
val mod10Fn = isMod10(1, 3)
return... | 1 | Kotlin | 0 | 4 | b75e6b96aa7c80efa5095a7763a22fcf614b10d8 | 2,753 | konfork | MIT License |
src/Day07.kt | kuolemax | 573,740,719 | false | {"Kotlin": 21104} | fun main() {
fun part1(input: List<String>): Int {
return findLessThanSizeDirectoryTotalSize(input)
}
fun part2(input: List<String>): Int {
val needSpace = 30_000_000
val totalSize = 70_000_000
return findTheSmallestDirectoryThatShouldBeDeleted(parseToDirectories(input), ne... | 0 | Kotlin | 0 | 0 | 3045f307e24b6ca557b84dac18197334b8a8a9bf | 3,089 | aoc2022--kotlin | Apache License 2.0 |
src/Day09.kt | jwalter | 573,111,342 | false | {"Kotlin": 19975} | import kotlin.math.absoluteValue
fun main() {
data class Knot(var x: Int, var y: Int)
val down = 0 to -1
val up = 0 to 1
val right = 1 to 0
val left = -1 to 0
val visited = mutableSetOf<Pair<Int, Int>>()
fun moveInDirection(direction: Pair<Int, Int>, knots: List<Knot>) {
val h = k... | 0 | Kotlin | 0 | 0 | 576aeabd297a7d7ee77eca9bb405ec5d2641b441 | 2,427 | adventofcode2022 | Apache License 2.0 |
src/Day04.kt | BjornstadThomas | 572,616,128 | false | {"Kotlin": 9666} | fun main() {
fun splitString(input: String): List<Pair<Pair<Int, Int>, Pair<Int, Int>>> {
// val inputSplit = input.split("\r\n")
val inputSplit = input.lines().map {
val list = it.split(",").map { it.split("-") }
// println(list)
(list[0][0].toInt() to list[0][1... | 0 | Kotlin | 0 | 0 | 553e3381ca26e1e316ecc6c3831354928cf7463b | 1,973 | AdventOfCode-2022-Kotlin | Apache License 2.0 |
src/day05.kts | miedzinski | 434,902,353 | false | {"Kotlin": 22560, "Shell": 113} | data class Point(val x: Int, val y: Int)
class Line(val from: Point, val to: Point) {
fun isHorizontalOrVertical(): Boolean =
from.x == to.x || from.y == to.y
fun points(): Sequence<Point> {
fun diff(selector: (Point) -> Int): Int {
val from = selector(from)
val to = se... | 0 | Kotlin | 0 | 0 | 6f32adaba058460f1a9bb6a866ff424912aece2e | 1,502 | aoc2021 | The Unlicense |
2021/src/day22/Solution.kt | vadimsemenov | 437,677,116 | false | {"Kotlin": 56211, "Rust": 37295} | package day22
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.system.measureTimeMillis
fun main() {
fun MutableList<Int>.inPlaceDistinct() {
sort()
var ptr = 1
for (i in 1 until this.size) {
if (this[i] != this[i - 1]) {
this[ptr++] = this[i]
}
}
while (si... | 0 | Kotlin | 0 | 0 | 8f31d39d1a94c862f88278f22430e620b424bd68 | 2,486 | advent-of-code | Apache License 2.0 |
src/Day08.kt | joshpierce | 573,265,121 | false | {"Kotlin": 46425} | import java.io.File
fun main() {
var lines: List<String> = File("Day08.txt").readLines()
// Setup our Forest List of Lists
var forest = lines.map { it.chunked(1) }
// Variable for Tracking Tree Score in Part Two
var maxTreeScore = 0
// Prints out your forest for you to see
/... | 0 | Kotlin | 0 | 1 | fd5414c3ab919913ed0cd961348c8644db0330f4 | 3,735 | advent-of-code-22 | Apache License 2.0 |
kotlin/src/main/kotlin/year2023/Day01.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2023
fun main() {
val input = readInput("Day01")
Day01.part1(input).println()
Day01.part2(input).println()
}
object Day01 {
fun part1(input: List<String>): Int {
return input.sumOf { line ->
val results = "[0-9]".toRegex().findAll(line)
val firstDigit = res... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 2,118 | advent-of-code | MIT License |
src/Day02.kt | kpilyugin | 572,573,503 | false | {"Kotlin": 60569} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
val (a, b) = it.split(" ")
val their = a[0] - 'A'
val our = b[0] - 'X'
val score = when ((our - their + 3) % 3) {
1 -> 6
2 -> 0
else -> 3
... | 0 | Kotlin | 0 | 1 | 7f0cfc410c76b834a15275a7f6a164d887b2c316 | 1,073 | Advent-of-Code-2022 | Apache License 2.0 |
grind-75-kotlin/src/main/kotlin/BinarySearch.kt | Codextor | 484,602,390 | false | {"Kotlin": 27206} | /**
* Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums.
* If target exists, then return its index. Otherwise, return -1.
*
* You must write an algorithm with O(log n) runtime complexity.
*
*
*
* Example 1:
*
* Input: nums = [-... | 0 | Kotlin | 0 | 0 | 87aa60c2bf5f6a672de5a9e6800452321172b289 | 1,260 | grind-75 | Apache License 2.0 |
src/Day04.kt | Derrick-Mwendwa | 573,947,669 | false | {"Kotlin": 8707} | fun main() {
val regex = Regex("""([0-9]+)-([0-9]+),([0-9]+)-([0-9]+)""")
fun part1(input: List<String>): Int {
val sections = input.map {
val (m1, m2, m3, m4) = regex.matchEntire(it)!!.destructured
IntRange(m1.toInt(), m2.toInt()) to IntRange(m3.toInt(), m4.toInt())
}
... | 0 | Kotlin | 0 | 1 | 7870800afa54c831c143b5cec84af97e079612a3 | 1,230 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day03.kt | aaronbush | 571,776,335 | false | {"Kotlin": 34359} | import java.util.stream.Collectors.toSet
fun main() {
val priority = ('a'..'z').withIndex().associate { it.value to it.index + 1 } +
('a'..'z').withIndex().associate { it.value.uppercaseChar() to it.index + 27 }
fun String.bisect() = this.chunked(this.length / 2)
fun part1(input: List<String>... | 0 | Kotlin | 0 | 0 | d76106244dc7894967cb8ded52387bc4fcadbcde | 1,643 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2021/2021-21.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.readInputLines
import kotlin.math.max
fun main() {
val input = readInputLines(2021, "21-input")
val test1 = readInputLines(2021, "21-test1")
println("Part1:")
part1... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 3,342 | advent-of-code | MIT License |
src/main/kotlin/dev/bogwalk/batch4/Problem41.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch4
import dev.bogwalk.util.combinatorics.permutations
import dev.bogwalk.util.maths.isPrime
import dev.bogwalk.util.strings.isPandigital
import kotlin.math.pow
/**
* Problem 41: Pandigital Prime
*
* https://projecteuler.net/problem=41
*
* Goal: Find the largest pandigital prime <= N or re... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,954 | project-euler-kotlin | MIT License |
src/Day07.kt | pmellaaho | 573,136,030 | false | {"Kotlin": 22024} | sealed class Node(val id: String) {
var parent: Folder? = null
var children: MutableList<Node> = mutableListOf()
fun addNode(node: Node) {
children.add(node)
}
fun findRoot(): Node {
var root = this
while (root.parent != null) {
root = root.parent!!
}
... | 0 | Kotlin | 0 | 0 | cd13824d9bbae3b9debee1a59d05a3ab66565727 | 3,926 | AoC_22 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem1061/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1061
/**
* LeetCode page: [1061. Lexicographically Smallest Equivalent String](https://leetcode.com/problems/lexicographically-smallest-equivalent-string/);
*/
class Solution {
/* Complexity:
* Time O(M+N) and Space O(1) where M and N are the length of s1 and baseStr;
... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,476 | hj-leetcode-kotlin | Apache License 2.0 |
src/cn/leetcode/codes/simple1/SimpleKotlin1.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple1
import java.util.*
/*
*
* 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。
示例:
给定 nums = [2, 7, 11, 15], target = 9
因为 nums[0] + nums[1] = 2 + 7 = 9
所以返回 [0, 1]
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/two-sum
著作权归领扣... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 1,867 | LeetCodeSimple | Apache License 2.0 |
src/_2022/Day03.kt | albertogarrido | 572,874,945 | false | {"Kotlin": 36434} | package _2022
import readInput
import java.lang.IllegalArgumentException
fun main() {
runTests(readInput("2022", "day03_test"))
runScenario(readInput("2022", "day03"))
}
private fun runScenario(input: List<String>) {
val rucksacks = input.map { buildRucksacks(it) }
println(part1(rucksacks))
print... | 0 | Kotlin | 0 | 0 | ef310c5375f67d66f4709b5ac410d3a6a4889ca6 | 1,451 | AdventOfCode.kt | Apache License 2.0 |
src/year_2021/day_06/Day06.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2021.day_06
import readInput
import java.math.BigInteger
data class LanternFish(
val spawnTimer: Int,
val quantity: BigInteger,
) {
fun advance(): List<LanternFish> {
val newTime = spawnTimer - 1
return if (newTime < 0) {
listOf(
LanternFish(6, qua... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 2,126 | advent_of_code | Apache License 2.0 |
y2017/src/main/kotlin/adventofcode/y2017/Day25.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2017
import adventofcode.io.AdventSolution
object Day25 : AdventSolution(2017, 25, "The Halting Problem") {
override fun solvePartOne(input: String): String {
val (stepsUntilDiagnostic, turingMachine) = parseInstructions(input)
repeat(stepsUntilDiagnostic) {
turingMachine.step()
}
... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 2,528 | advent-of-code | MIT License |
src/main/kotlin/aoc23/Day12.kt | tom-power | 573,330,992 | false | {"Kotlin": 254717, "Shell": 1026} | package aoc23
import aoc23.Day12Domain.SpringRecord
import aoc23.Day12Parser.toSpringRecords
import aoc23.Day12Parser.unfoldFiveTimes
import common.Strings.replaceFirst
import common.Year23
object Day12 : Year23 {
fun List<String>.part1(): Long =
toSpringRecords()
.sumOf(SpringRecord::possible... | 0 | Kotlin | 0 | 0 | baccc7ff572540fc7d5551eaa59d6a1466a08f56 | 3,974 | aoc | Apache License 2.0 |
src/Day02.kt | Arclights | 574,085,358 | false | {"Kotlin": 11490} | fun main() {
fun shapeScore(shape: SHAPE) = when (shape) {
SHAPE.ROCK -> 1
SHAPE.PAPER -> 2
SHAPE.SCISSORS -> 3
}
fun beatingShape(shape: SHAPE) = when (shape) {
SHAPE.ROCK -> SHAPE.PAPER
SHAPE.PAPER -> SHAPE.SCISSORS
SHAPE.SCISSORS -> SHAPE.ROCK
}
f... | 0 | Kotlin | 0 | 0 | 121a81ba82ba0d921bd1b689241ffa8727bc806e | 2,815 | advent_of_code_2022 | Apache License 2.0 |
src/main/kotlin/aoc/Day3.kt | dtsaryov | 573,392,550 | false | {"Kotlin": 28947} | package aoc
/**
* [AoC 2022: Day 3](https://adventofcode.com/2022/day/3)
*/
fun getRucksackPrioritiesSum(): Int {
val input = readInput("day3.txt") ?: return Int.MIN_VALUE
var sum = 0
for (s in input) {
sum += collectDuplicates(s).fold(0) { acc, ch -> acc + getCharPriority(ch) }
}
retur... | 0 | Kotlin | 0 | 0 | 549f255f18b35e5f52ebcd030476993e31185ad3 | 1,948 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/days/Day16.kt | andilau | 399,220,768 | false | {"Kotlin": 85768} | package days
@AdventOfCodePuzzle(
name = "<NAME>",
url = "https://adventofcode.com/2020/day/16",
date = Date(day = 16, year = 2020)
)
class Day16(lines: List<String>) : Puzzle {
private val rules = lines.takeWhile(String::isNotEmpty).map(TicketRule.Companion::parse)
private val ownTicket = lines.dr... | 7 | Kotlin | 0 | 0 | 2809e686cac895482c03e9bbce8aa25821eab100 | 2,708 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
app/src/main/kotlin/day04/Day04.kt | W3D3 | 433,748,408 | false | {"Kotlin": 72893} | package day04
import common.InputRepo
import common.readSessionCookie
import common.solve
import java.util.function.Consumer
fun main(args: Array<String>) {
val day = 4
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay04Part1, ::solveDay04Part2)
}
data class Bin... | 0 | Kotlin | 0 | 0 | df4f21cd99838150e703bcd0ffa4f8b5532c7b8c | 2,561 | AdventOfCode2021 | Apache License 2.0 |
2023/src/main/kotlin/day17.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Graph
import utils.Grid
import utils.Parser
import utils.Solution
import utils.Vec2i
fun main() {
Day17.run()
}
object Day17 : Solution<Grid<Char>>() {
override val name = "day17"
override val parser = Parser.charGrid
data class Node(
val location: Vec2i,
val entryDirection: Vec2i,
)
... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,543 | aoc_kotlin | MIT License |
src/main/kotlin/com/briarshore/aoc2022/day05/SupplyStacksPuzzle.kt | steveswing | 579,243,154 | false | {"Kotlin": 47151} | package com.briarshore.aoc2022.day05
import println
import readInput
// [D]
// [N] [C]
// [Z] [M] [P]
// 1 2 3
//
// move 1 from 2 to 1
// move 3 from 1 to 3
// move 2 from 2 to 1
// move 1 from 1 to 2
//
enum class CraneModel {
M9000, M9001
}
fun main() {
data class Move(val count: Int, val from: ... | 0 | Kotlin | 0 | 0 | a0d19d38dae3e0a24bb163f5f98a6a31caae6c05 | 2,863 | 2022-AoC-Kotlin | Apache License 2.0 |
day06/src/main/kotlin/Day06.kt | bzabor | 160,240,195 | false | null | import kotlin.math.absoluteValue
class Day06(input: List<String>) {
private val landingPlaces = input.map { it ->
val (row, col) = it.split(", ").map { it.toInt() }
LandingPlace(row, col)
}
fun part1(): Int {
val gridSize = 1000
for (row in 0 until gridSize) {
... | 0 | Kotlin | 0 | 0 | 14382957d43a250886e264a01dd199c5b3e60edb | 2,982 | AdventOfCode2018 | Apache License 2.0 |
src/aoc2023/Day08.kt | dayanruben | 433,250,590 | false | {"Kotlin": 79134} | package aoc2023
import checkValue
import readInput
fun main() {
val (year, day) = "2023" to "Day08"
fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = (a * b) / gcd(a, b)
fun List<Long>.lcm() = this.reduce { acc, n -> lcm(acc, n) }
fun parse(inp... | 1 | Kotlin | 2 | 30 | df1f04b90e81fbb9078a30f528d52295689f7de7 | 1,987 | aoc-kotlin | Apache License 2.0 |
src/Day09.kt | achugr | 573,234,224 | false | null | import kotlin.math.abs
enum class PlaneDirection(val x: Int, val y: Int) {
RIGHT(1, 0),
LEFT(-1, 0),
DOWN(0, -1),
UP(0, 1),
RIGHT_DOWN(1, -1),
RIGHT_UP(1, 1),
LEFT_DOWN(-1, -1),
LEFT_UP(-1, 1);
}
data class SegmentInput(val direction: PlaneDirection, val length: Int)
data class Point(v... | 0 | Kotlin | 0 | 0 | d91bda244d7025488bff9fc51ca2653eb6a467ee | 3,353 | advent-of-code-kotlin-2022 | Apache License 2.0 |
y2023/src/main/kotlin/adventofcode/y2023/Day23.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2023
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Direction
import adventofcode.util.vector.SparseGrid
import adventofcode.util.vector.Vec2
fun main() {
Day23.solve()
}
object Day23 : AdventSolution(2023, 23, "A Long Walk") {
override fun solvePartOne(input: St... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 4,681 | advent-of-code | MIT License |
src/day07/Day07_functional.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day07
import readLines
/**
* 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 solutions.
*/
class Directory(val name: String) {
pri... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 2,428 | aoc2022 | Apache License 2.0 |
src/main/kotlin/nl/tiemenschut/aoc/y2023/day18.kt | tschut | 723,391,380 | false | {"Kotlin": 61206} | package nl.tiemenschut.aoc.y2023
import nl.tiemenschut.aoc.lib.dsl.aoc
import nl.tiemenschut.aoc.lib.dsl.day
import nl.tiemenschut.aoc.lib.dsl.parser.InputParser
import nl.tiemenschut.aoc.lib.util.Direction
import nl.tiemenschut.aoc.lib.util.Direction.*
import nl.tiemenschut.aoc.lib.util.points.Point
import nl.tiemens... | 0 | Kotlin | 0 | 1 | a1ade43c29c7bbdbbf21ba7ddf163e9c4c9191b3 | 2,400 | aoc-2023 | The Unlicense |
src/Day07.kt | floblaf | 572,892,347 | false | {"Kotlin": 28107} | fun main() {
abstract class Content {
abstract val name: String
abstract val size: Int
}
class Folder(
override val name: String,
val parent: Folder? = null,
val content: MutableList<Content> = mutableListOf(),
) : Content() {
override val size: Int
... | 0 | Kotlin | 0 | 0 | a541b14e8cb401390ebdf575a057e19c6caa7c2a | 2,231 | advent-of-code-2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.