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/g0001_0100/s0085_maximal_rectangle/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0001_0100.s0085_maximal_rectangle
// #Hard #Array #Dynamic_Programming #Matrix #Stack #Monotonic_Stack
// #2023_07_10_Time_209_ms_(100.00%)_Space_37.9_MB_(100.00%)
class Solution {
fun maximalRectangle(matrix: Array<CharArray>): Int {
/*
* idea: using [LC84 Largest Rectangle in Histogram... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 3,278 | LeetCode-in-Kotlin | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[95]不同的二叉搜索树 II.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import javax.swing.tree.TreeNode
//给你一个整数 n ,请你生成并返回所有由 n 个节点组成且节点值从 1 到 n 互不相同的不同 二叉搜索树 。可以按 任意顺序 返回答案。
//
//
//
//
//
// 示例 1:
//
//
//输入:n = 3
//输出:[[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]
//
//
// 示例 2:
//
//
//输入:n = 1
//输出:[[1]]
//
//
//
//
// 提示:
//
//
// 1 <= n <= 8
... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 2,059 | MyLeetCode | Apache License 2.0 |
src/main/kotlin/com/github/aoc/AOCD4P1.kt | frikit | 317,914,710 | false | null | package com.github.aoc
import com.github.aoc.utils.*
fun main() {
val input = InputParser.parseInput(InputDay4Problem1, "\n\n")
.map { it.replace("\n", " ") }
.map { it.replace("\r", " ") }
val map = input.map {
it.split(" ").map { elem ->
val key = elem.split(":")[0].trim... | 0 | Kotlin | 0 | 0 | 2fca82225a19144bbbca39247ba57c42a30ef459 | 1,157 | aoc2020 | Apache License 2.0 |
src/main/kotlin/aoc2022/Day13.kt | lukellmann | 574,273,843 | false | {"Kotlin": 175166} | package aoc2022
import AoCDay
import util.illegalInput
// https://adventofcode.com/2022/day/13
object Day13 : AoCDay<Int>(
title = "Distress Signal",
part1ExampleAnswer = 13,
part1Answer = 6046,
part2ExampleAnswer = 140,
part2Answer = 21423,
) {
private sealed class PacketData : Comparable<Pac... | 0 | Kotlin | 0 | 1 | 344c3d97896575393022c17e216afe86685a9344 | 4,185 | advent-of-code-kotlin | MIT License |
src/main/kotlin/first/MarkingWay.kt | Kvest | 163,103,813 | false | null | package first
import java.util.*
import kotlin.math.pow
import kotlin.math.sqrt
private const val START = 'S'
private const val END = 'X'
private const val OBSTACLE = 'B'
private const val PATH = '*'
private const val STRAIGHT_STEP = 1f
private const val DIAGONAL_STEP = 1.5f
fun addPath(mapString: String): String {
... | 0 | Kotlin | 0 | 0 | d94b725575a8a5784b53e0f7eee6b7519ac59deb | 4,647 | aoc2018 | Apache License 2.0 |
src/main/kotlin/pl/mrugacz95/aoc/day23/day23.kt | mrugacz95 | 317,354,321 | false | null | package pl.mrugacz95.aoc.day23
fun <T> List<T>.cycle(): Sequence<T> {
var i = 0
if (isEmpty()) return emptySequence()
return generateSequence {
this[i++ % this.size]
}
}
const val cupsToPick = 3
fun makeMove(state: List<Int>): List<Int> {
val current = state.first()
var cups = state
... | 0 | Kotlin | 0 | 1 | a2f7674a8f81f16cd693854d9f564b52ce6aaaaf | 3,099 | advent-of-code-2020 | Do What The F*ck You Want To Public License |
src/Day03.kt | Fenfax | 573,898,130 | false | {"Kotlin": 30582} | fun main() {
val alphabet = ('a'..'z').joinToString("").plus(('A'..'Z').joinToString(""))
fun postionInAlphabet(char: Char): Int {
return alphabet.indexOfFirst { it == char } + 1
}
fun part1(input: List<String>): Int {
return input.map { it.chunked(it.length / 2) }
.map {... | 0 | Kotlin | 0 | 0 | 28af8fc212c802c35264021ff25005c704c45699 | 817 | AdventOfCode2022 | Apache License 2.0 |
22/part_one.kt | ivanilos | 433,620,308 | false | {"Kotlin": 97993} | import java.io.File
fun readInput() : Reactor {
val input = File("input.txt")
.readLines()
.map { it.split(",") }
val opRegex = """(\w+)""".toRegex()
val cubeRegex = """(-?\d+)..(-?\d+)""".toRegex()
val steps = mutableListOf<Step>()
input.forEach {
val op = opRegex.find(it... | 0 | Kotlin | 0 | 3 | a24b6f7e8968e513767dfd7e21b935f9fdfb6d72 | 2,576 | advent-of-code-2021 | MIT License |
src/main/day08/Part1.kt | ollehagner | 572,141,655 | false | {"Kotlin": 80353} | package day08
import common.Point
import readInput
typealias TreeRow = List<Tree>
typealias Column = List<Int>
fun main() {
// val input = readInput("day08/testinput.txt")
val input = readInput("day08/input.txt")
val inputRows = inputAsRows(input)
val inputRowsReversed = inputRows.map { it.reversed() }... | 0 | Kotlin | 0 | 0 | 6e12af1ff2609f6ef5b1bfb2a970d0e1aec578a1 | 1,463 | aoc2022 | Apache License 2.0 |
src/main/kotlin/day19/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day19
import java.io.File
import kotlin.math.abs
fun main() {
val unidentifiedScanners = mutableListOf<UnidentifiedScanner>()
File("src/main/kotlin/day19/input.txt").useLines { linesSeq ->
val linesIterator = linesSeq.iterator()
while (linesIterator.hasNext()) {
val scanner... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 7,576 | aoc-2021 | MIT License |
AnalyticHierarchyProcess/app/src/main/java/com/emirhanaydin/analytichierarchyprocess/math.kt | emirhanaydin | 159,205,125 | false | null | package com.emirhanaydin.analytichierarchyprocess
fun getRandomIndex(n: Int): Float {
return when (n) {
1, 2 -> 0f
3 -> 0.58f
4 -> 0.90f
5 -> 1.12f
6 -> 1.24f
7 -> 1.32f
8 -> 1.41f
9 -> 1.45f
10 -> 1.49f
11 -> 1.51f
12 -> 1.48f... | 0 | Kotlin | 1 | 0 | 7a58319c4b90d027cb24afda6a6793eba807b410 | 3,411 | ahp-android | The Unlicense |
src/main/kotlin/mkuhn/aoc/Day08.kt | mtkuhn | 572,236,871 | false | {"Kotlin": 53161} | package mkuhn.aoc
import mkuhn.aoc.util.*
fun main() {
val input = readInput("Day08")
println(day08part1(input))
println(day08part2(input))
}
fun day08part1(input: List<String>): Int =
TreeGrid(input.map { l -> l.map { it.digitToInt() } }.transpose())
.findVisibleTrees()
.count()
fun... | 0 | Kotlin | 0 | 1 | 89138e33bb269f8e0ef99a4be2c029065b69bc5c | 1,679 | advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | palex65 | 572,937,600 | false | {"Kotlin": 68582} |
private fun String.toRanges(): List<IntRange> = split(',').map { range ->
val (start, end) = range.split('-').map { it.toInt() }
start..end
}
private fun part1(lines: List<String>): Int =
lines.count { line ->
val(a, b) = line.toRanges()
a.all{ it in b } || b.all { it in a }
}
private... | 0 | Kotlin | 0 | 2 | 35771fa36a8be9862f050496dba9ae89bea427c5 | 684 | aoc2022 | Apache License 2.0 |
src/main/kotlin/y2022/Day02.kt | jforatier | 432,712,749 | false | {"Kotlin": 44692} | package y2022
class Day02(private val data: List<String>) {
enum class Action(val char: Set<String>, val value:Int) {
UNKNOWN(setOf(),0),
ROCK(setOf("A","X"), 1),
PAPER(setOf("B","Y"), 2),
SCISSORS(setOf("C","Z"),3);
fun winAgainst() : Action {
return when(this... | 0 | Kotlin | 0 | 0 | 2a8c0b4ccb38c40034c6aefae2b0f7d4c486ffae | 2,534 | advent-of-code-kotlin | MIT License |
src/main/kotlin/days/Day03.kt | julia-kim | 569,976,303 | false | null | package days
import readInput
fun main() {
val lettersToNumber = (('a'..'z') + ('A'..'Z')).mapIndexed { i, c ->
c to (i + 1)
}.toMap()
fun part1(input: List<String>): Int {
var sum = 0
input.forEach { rucksack ->
val halfLength = rucksack.length / 2
val com... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 1,196 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day11.kt | felix-ebert | 317,592,241 | false | null | package days
import kotlin.math.max
import kotlin.math.min
class Day11 : Day(11) {
override fun partOne(): Any {
return simulateSeatModel(parseSeatModel(), ::findNeighbours, 4)
}
override fun partTwo(): Any {
return simulateSeatModel(parseSeatModel(), ::findFirstVisibleSeats, 5)
}
... | 0 | Kotlin | 0 | 4 | dba66bc2aba639bdc34463ec4e3ad5d301266cb1 | 3,112 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/aoc2021/day8/SevenSegments.kt | arnab | 75,525,311 | false | null | package aoc2021.day8
object SevenSegments {
data class Observation(
val pattern: List<String>,
val output: List<String>
)
fun parse(data: String) = data.split("\n").map { line ->
val (pattern, output) = line.split(" | ")
Observation(
pattern.split(" ").map { it.... | 0 | Kotlin | 0 | 0 | 1d9f6bc569f361e37ccb461bd564efa3e1fccdbd | 3,421 | adventofcode | MIT License |
src/main/kotlin/days/Geometry.kt | andilau | 429,206,599 | false | {"Kotlin": 113274} | package days
import kotlin.math.absoluteValue
import kotlin.math.sign
data class Point(val x: Int, val y: Int) {
fun up() = copy(y = y - 1)
fun down() = copy(y = y + 1)
fun left() = copy(x = x - 1)
fun right() = copy(x = x + 1)
fun manhattanDistance(to: Point = ORIGIN) =
(x - to.x).absolu... | 2 | Kotlin | 0 | 0 | f51493490f9a0f5650d46bd6083a50d701ed1eb1 | 2,296 | advent-of-code-2019 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/io/undefined/TrappingRainWater.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.undefined
import io.utils.runTests
// https://leetcode.com/problems/trapping-rain-water/
class TrappingRainWater {
// https://leetcode.com/problems/trapping-rain-water/discuss/17391/Share-my-short-solution.
fun execute(heights: IntArray): Int {
var start = 0
var end = heights.lastIndex
var... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 2,748 | coding | MIT License |
src/Day02.kt | rinas-ink | 572,920,513 | false | {"Kotlin": 14483} | import java.lang.IllegalArgumentException
fun main() {
fun convertInput(c: Char): Int = if (c - 'A' < 3) (c - 'A')
else {
(c - 'X')
} + 1
fun less(x: Int) = when (x) {
1 -> 3
2 -> 1
3 -> 2
else -> throw IllegalArgumentException("Must be in range [1; 3]")
}
... | 0 | Kotlin | 0 | 0 | 462bcba7779f7bfc9a109d886af8f722ec14c485 | 1,600 | anvent-kotlin | Apache License 2.0 |
puzzles/src/main/kotlin/com/kotlinground/puzzles/hashmap/equalrowsandcolumns/equalPairs.kt | BrianLusina | 113,182,832 | false | {"Kotlin": 483489, "Shell": 7283, "Python": 1725} | package com.kotlinground.puzzles.hashmap.equalrowsandcolumns
fun equalPairsHashMap(grid: Array<IntArray>): Int {
var count = 0
val n = grid.size
val rowCounter = hashMapOf<String, Int>()
for (row in grid) {
val rowString = row.contentToString()
rowCounter[rowString] = 1 + rowCounter.g... | 1 | Kotlin | 1 | 0 | 5e3e45b84176ea2d9eb36f4f625de89d8685e000 | 2,390 | KotlinGround | MIT License |
src/Day05.kt | maximilianproell | 574,109,359 | false | {"Kotlin": 17586} | import java.io.File
fun main() {
fun extractMoveActionsFromInput(input: String): List<Int> {
return input
.replaceFirst("move", "")
.replaceFirst("from", "")
.replaceFirst("to", "")
.chunked(3)
.map { it.trim().toInt() }
}
fun part1(input... | 0 | Kotlin | 0 | 0 | 371cbfc18808b494ed41152256d667c54601d94d | 4,376 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LongestCommonPrefix.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* 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 w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,498 | kotlab | Apache License 2.0 |
src/Day03.kt | SpencerDamon | 573,244,838 | false | {"Kotlin": 6482} |
fun main() {
/*fun part1(input: List<String>): Int {
var subString1 = ""
var subString2 = ""
val points = mutableListOf<Int>()
for (i in input) {
val string = i.toString()
subString1 = string.substring(0, string.length / 2)
subString2 = string.... | 0 | Kotlin | 0 | 0 | 659a9e9ae4687bd633bddfb924416c80a8a2db2e | 1,758 | aoc-2022-in-Kotlin | Apache License 2.0 |
src/aoc2017/kot/Day16.kt | Tandrial | 47,354,790 | false | null | package aoc2017.kot
import java.io.File
object Day16 {
fun solve(input: List<String>, times: Int = 1): String {
val sequence = mutableListOf<List<Char>>()
var curr = (0 until 16).map { 'a' + it }
repeat(times) {
if (curr in sequence) {
return sequence[times % sequence.size].joinToString(se... | 0 | Kotlin | 1 | 1 | 9294b2cbbb13944d586449f6a20d49f03391991e | 1,348 | Advent_of_Code | MIT License |
src/Day02.kt | Kbzinho-66 | 572,299,619 | false | {"Kotlin": 34500} | private const val WIN = 6
private const val DRAW = 3
private const val LOSS = 0
private const val ROCK = 1
private const val PAPER = 2
private const val SCISSORS = 3
fun main() {
operator fun String.component1() = this[0] - 'A'
operator fun String.component2() = this[1]
operator fun String.component3() = ... | 0 | Kotlin | 0 | 0 | e7ce3ba9b56c44aa4404229b94a422fc62ca2a2b | 1,776 | advent_of_code_2022_kotlin | Apache License 2.0 |
src/Day04.kt | morris-j | 573,197,835 | false | {"Kotlin": 7085} | fun main() {
fun createRange(value: String): IntRange {
val split = value.split("-")
val first = split[0].toInt()
val second = split[1].toInt()
return IntRange(first, second)
}
fun processInput(input: List<String>): List<Pair<IntRange, IntRange>> {
return input.map ... | 0 | Kotlin | 0 | 0 | e3f2d02dad432dbc1b15c9e0eefa7b35ace0e316 | 1,390 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem886/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem886
/**
* LeetCode page: [886. Possible Bipartition](https://leetcode.com/problems/possible-bipartition/);
*/
class Solution {
/* Complexity:
* Time O(n+|dislikes|) and Space O(n+|dislikes|);
*/
fun possibleBipartition(n: Int, dislikes: Array<IntArray>): Boolea... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,460 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day05.kt | vlsolodilov | 573,277,339 | false | {"Kotlin": 19518} | fun main() {
val testCrates: List<Stack<Char>> = listOf<Stack<Char>>(
mutableListOf('Z', 'N'),
mutableListOf('M', 'C', 'D'),
mutableListOf('P'),
)
val crates: List<Stack<Char>> = listOf<Stack<Char>>(
mutableListOf('N', 'S', 'D', 'C', 'V', 'Q', 'T'),
mutableListOf('M... | 0 | Kotlin | 0 | 0 | b75427b90b64b21fcb72c16452c3683486b48d76 | 3,243 | aoc22 | Apache License 2.0 |
src/Day21.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | fun main() {
val testInput = readInput("Day21_test")
.map(String::parseYellingMonkey)
val input = readInput("Day21")
.map(String::parseYellingMonkey)
part1(testInput).also {
println("Part 1, test input: $it")
check(it == 152L)
}
part1(input).also {
println("... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 5,069 | aoc22-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/RangeSumQuery.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* 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 w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,854 | kotlab | Apache License 2.0 |
src/Day03.kt | jfiorato | 573,233,200 | false | null | fun main() {
val items = ".abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
fun part1(input: List<String>): Int {
var totalPriority = 0
for (line in input) {
val contents = line.toList()
val compartment1 = contents.take(contents.size/2)
val compartment2 =... | 0 | Kotlin | 0 | 0 | 4455a5e9c15cd067d2661438c680b3d7b5879a56 | 1,370 | kotlin-aoc-2022 | Apache License 2.0 |
leetcode/src/linkedlist/Q234.kt | zhangweizhe | 387,808,774 | false | null | package linkedlist
import linkedlist.kt.ListNode
fun main() {
// 234. 回文链表
// https://leetcode-cn.com/problems/palindrome-linked-list/
val createList = LinkedListUtil.createList(intArrayOf(1, 2, 1))
println(isPalindrome1(createList))
}
/**
* 把原链表反转,构造一个新链表,对比新旧链表的每个节点的值是否一样
* 时间复杂度O(n)
* 空间复杂度O... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,635 | kotlin-study | MIT License |
src/main/kotlin/d8_SevenSegmentSearch/SevenSegmentSearch.kt | aormsby | 425,644,961 | false | {"Kotlin": 68415} | package d8_SevenSegmentSearch
import util.Input
import util.Output
fun main() {
Output.day(8, "Seven Segment Search")
val startTime = Output.startTime()
/*
// Regex works for P1, but it's slooooooow.
val allDisplayText = Input.parseAllText(filename = "/input/d8_seven_segment_displays.txt")
va... | 0 | Kotlin | 1 | 1 | 193d7b47085c3e84a1f24b11177206e82110bfad | 3,932 | advent-of-code-2021 | MIT License |
src/day14/Day14.kt | HGilman | 572,891,570 | false | {"Kotlin": 109639, "C++": 5375, "Python": 400} | package day14
import lib.Path
import lib.Point2D
import readInput
fun main() {
val day = 14
val testInput = readInput("day$day/testInput")
// check(part1(testInput) == 1)
// check(part2(testInput) == 1)
val input = readInput("day$day/input")
// println(part1(input))
println(part2(input))
}
... | 0 | Kotlin | 0 | 1 | d05a53f84cb74bbb6136f9baf3711af16004ed12 | 5,196 | advent-of-code-2022 | Apache License 2.0 |
src/Day16.kt | syncd010 | 324,790,559 | false | null | class Day16: Day {
private fun convert(input: List<String>) : List<Int> {
return input[0].map { it - '0' }
}
override fun solvePartOne(input: List<String>): Int {
var signal = convert(input)
val basePattern = listOf(0, 1, 0, -1)
val newSignal = MutableList(signal.size) { '0... | 0 | Kotlin | 0 | 0 | 11c7c7d6ccd2488186dfc7841078d9db66beb01a | 1,787 | AoC2019 | Apache License 2.0 |
src/main/kotlin/_2023/Day11.kt | novikmisha | 572,840,526 | false | {"Kotlin": 145780} | package _2023
import Coordinate
import Day
import InputReader
import atCoordinates
import kotlin.math.abs
class Day11 : Day(2023, 11) {
override val firstTestAnswer = 374
override val secondTestAnswer = 0
override fun first(input: InputReader): Int {
val space = input.asLines().toMutableList()
... | 0 | Kotlin | 0 | 0 | 0c78596d46f3a8bf977bf356019ea9940ee04c88 | 3,436 | advent-of-code | Apache License 2.0 |
dcp_kotlin/src/main/kotlin/dcp/day292/day292.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day292
// day292.kt
// By <NAME>, 2020.
import java.util.*
typealias Vertex = Int
typealias AdjacencyList = List<Vertex>
typealias AdjacencyGraph = List<AdjacencyList>
typealias Partition = Set<Vertex>
data class Bipartition(val partition1: Partition, val partition2: Partition) {
init {
requi... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 3,572 | daily-coding-problem | MIT License |
src/aoc22/Day11_Simple.kt | mihassan | 575,356,150 | false | {"Kotlin": 123343} | @file:Suppress("PackageDirectoryMismatch")
package aoc22.day11_simple
import lib.Maths.divisibleBy
import lib.Solution
import lib.Strings.extractInts
import lib.Strings.extractLongs
import lib.Strings.words
data class Monkey(
val startingItems: List<Long>,
val operation: (Long) -> Long,
val divisor: Long,
va... | 0 | Kotlin | 0 | 0 | 698316da8c38311366ee6990dd5b3e68b486b62d | 2,309 | aoc-kotlin | Apache License 2.0 |
src/day04/Day04.kt | barbulescu | 572,834,428 | false | {"Kotlin": 17042} | package day04
import readInput
fun main() {
val pairs = readInput("day04/Day04")
.map { it.split(",") }
.onEach { require(it.size == 2) { "expected 2 ranges" } }
.map { parseRange(it[0]) to parseRange(it[1]) }
val fullyOverlapped = pairs
.count(::isFullyOverlapped)
println... | 0 | Kotlin | 0 | 0 | 89bccafb91b4494bfe4d6563f190d1b789cde7a4 | 937 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/day21.kt | gautemo | 572,204,209 | false | {"Kotlin": 78294} | import shared.getText
fun main() {
val input = getText("day21.txt")
println(day21A(input))
println(day21B(input))
}
fun day21A(input: String) = yellGame(input)
fun day21B(input: String) = yellGame(input, true)
private fun yellGame(input: String, withUnkown: Boolean = false): Long {
val monkeys = inpu... | 0 | Kotlin | 0 | 0 | bce9feec3923a1bac1843a6e34598c7b81679726 | 2,766 | AdventOfCode2022 | MIT License |
src/day-7.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 fun partOne(): String {
var result = ""
val inDegreeGraph = parseFile()
do {
val verticesWithNoInDegree = getVerticesWithNoInDegree(inDegreeGraph)
val vert... | 0 | Kotlin | 0 | 0 | a7f04450406a08a5d9320271148e0ae226f34ac3 | 2,812 | advent-of-code-2018 | MIT License |
src/main/kotlin/nl/tiemenschut/aoc/y2023/day2.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.AsListOfStrings
fun main() {
aoc(AsListOfStrings) {
puzzle { 2023 day 2 }
data class Turn(val red: Int, val green: Int, val blue: Int)
data... | 0 | Kotlin | 0 | 1 | a1ade43c29c7bbdbbf21ba7ddf163e9c4c9191b3 | 1,606 | aoc-2023 | The Unlicense |
src/Day02.kt | rk012 | 574,169,156 | false | {"Kotlin": 9389} | private const val ROCK = 0
private const val PAPER = 1
private const val SCISSORS = 2
fun main() {
fun Char.asItem() = when (this) {
in "AX" -> ROCK
in "BY" -> PAPER
in "CZ" -> SCISSORS
else -> fail()
}
fun itemBeats(item: Int) = when (item) {
ROCK -> SCISSORS
... | 0 | Kotlin | 0 | 0 | bfb4c56c4d4c8153241fa6aa6ae0e829012e6679 | 1,556 | advent-of-code-2022 | Apache License 2.0 |
src/Day23.kt | wgolyakov | 572,463,468 | false | null | private enum class Direction {
NORTH, SOUTH, WEST, EAST
}
fun main() {
fun parse(input: List<String>): Set<Pair<Int, Int>> {
val elves = mutableSetOf<Pair<Int, Int>>()
for (y in input.indices)
for (x in input[y].indices)
if (input[y][x] == '#') elves.add(x to y)
return elves
}
val checkPositionsToSta... | 0 | Kotlin | 0 | 0 | 789a2a027ea57954301d7267a14e26e39bfbc3c7 | 3,395 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dec24/Main.kt | dladukedev | 318,188,745 | false | null | package dec24
enum class Direction {
NORTHWEST,
NORTHEAST,
SOUTHWEST,
SOUTHEAST,
EAST,
WEST
}
fun parseInput(input: String): List<List<Direction>> {
return input.lines()
.map { it.toCharArray().toList() }
.map { line ->
line.foldIndexed(emptyList<Direction>()) {... | 0 | Kotlin | 0 | 0 | d4591312ddd1586dec6acecd285ac311db176f45 | 5,316 | advent-of-code-2020 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FrequencySort.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,287 | kotlab | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/strings/MaxDistanceBetweenSameElements.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.strings
import kotlin.math.max
/**
* We are given a string S consisting of N lowercase letters.
* A sequence of two adjacent letters inside a string is called a digram.
* The distance between two digrams is the distance between the first letter of the first digram
... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 1,668 | algs4-leprosorium | MIT License |
src/twentytwentytwo/day13/Day13.kt | colinmarsch | 571,723,956 | false | {"Kotlin": 65403, "Python": 6148} | package twentytwentytwo.day13
import readInput
fun main() {
fun part1(input: List<String>): Int {
var total = 0
input.chunked(3).forEachIndexed { index, pair ->
val left = parse(pair[0])
val right = parse(pair[1])
if (inOrder(left, right)) {
tota... | 0 | Kotlin | 0 | 0 | bcd7a08494e6db8140478b5f0a5f26ac1585ad76 | 3,161 | advent-of-code | Apache License 2.0 |
src/main/aoc2023/Day2.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2023
class Day2(input: List<String>) {
private val gameData = input.associate { line ->
//line: "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green"
val gameId = line.substringAfter(" ").substringBefore(":").toInt()
val sets = line.substringAfter(": ").split("; ")
//s... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,502 | aoc | MIT License |
src/Day02.kt | ZiomaleQ | 573,349,910 | false | {"Kotlin": 49609} | fun main() {
fun part1(input: List<String>): Int {
var score = 0
for (line in input) {
val enemyMove = toEnum(line[0])
val myMove = toEnum(line[2])
score += (myMove.ordinal + 1) + isWin(enemyMove, myMove)
}
return score
}
fun part2(inpu... | 0 | Kotlin | 0 | 0 | b8811a6a9c03e80224e4655013879ac8a90e69b5 | 2,466 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day05.kt | brigham | 573,127,412 | false | {"Kotlin": 59675} | import java.util.ArrayDeque
import java.util.Deque
import java.util.regex.Pattern
data class Instruction(val times: Int, val from: Int, val to: Int)
fun main() {
fun parse(input: List<String>): Pair<List<Deque<Char>>, List<Instruction>> {
val stacks = mutableListOf<Deque<Char>>()
fun ensureSize(n... | 0 | Kotlin | 0 | 0 | b87ffc772e5bd9fd721d552913cf79c575062f19 | 2,882 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/me/grison/aoc/y2020/Day17.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc.y2020
import me.grison.aoc.*
class Day17 : Day(17, 2020) {
override fun title() = "Conway Cubes"
override fun partOne() = (0..5).fold(loadCubes()) { g, _ -> g.evolve() }.count()
override fun partTwo() = (0..5).fold(loadCubes(true)) { g, _ -> g.evolve() }.count()
private fun lo... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 2,375 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/leetcodeProblem/leetcode/editor/en/NextGreaterElementI.kt | faniabdullah | 382,893,751 | false | null | //The next greater element of some element x in an array is the first greater
//element that is to the right of x in the same array.
//
// You are given two distinct 0-indexed integer arrays nums1 and nums2, where
//nums1 is a subset of nums2.
//
// For each 0 <= i < nums1.length, find the index j such that nums1[i]... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,822 | dsa-kotlin | MIT License |
2023/src/main/kotlin/org/suggs/adventofcode/Day05SeedFertilizer.kt | suggitpe | 321,028,552 | false | {"Kotlin": 156836} | package org.suggs.adventofcode
import org.slf4j.LoggerFactory
import kotlin.time.measureTime
object Day05SeedFertilizer {
private val log = LoggerFactory.getLogger(this::class.java)
fun calculateLowestLocationNumber(data: List<String>): Long {
val seeds = extractSeedsFrom(data)
val ranges = e... | 0 | Kotlin | 0 | 0 | 9485010cc0ca6e9dff447006d3414cf1709e279e | 2,716 | advent-of-code | Apache License 2.0 |
src/Day20.kt | nordberg | 573,769,081 | false | {"Kotlin": 47470} | import kotlin.math.abs
fun wrapAroundIndex(index: Int, indexWrapLimit: Int, movingUp: Boolean): Int {
if (index in 0..indexWrapLimit) {
return if (movingUp) {
if (index == indexWrapLimit) {
0
} else {
index
}
} else {
i... | 0 | Kotlin | 0 | 0 | 3de1e2b0d54dcf34a35279ba47d848319e99ab6b | 3,383 | aoc-2022 | Apache License 2.0 |
grind-75-kotlin/src/main/kotlin/TwoSum.kt | Codextor | 484,602,390 | false | {"Kotlin": 27206} | /**
* Given an array of integers nums and an integer target,
* return indices of the two numbers such that they add up to target.
*
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
*
* You can return the answer in any order.
*
*
*
* Example 1:
*
*... | 0 | Kotlin | 0 | 0 | 87aa60c2bf5f6a672de5a9e6800452321172b289 | 1,748 | grind-75 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NumSubmatrixSumTarget.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* 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 w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,463 | kotlab | Apache License 2.0 |
src/main/kotlin/solutions/day16/Day16.kt | Dr-Horv | 112,381,975 | false | null |
package solutions.day16
import solutions.Solver
class TwoWayMap<K, V> {
private val keyMap = mutableMapOf<K, V>()
private val valueMap = mutableMapOf<V, K>()
fun put(key: K, value: V) {
keyMap.put(key, value)
valueMap.put(value, key)
}
fun putAll(map: TwoWayMap<K, V>) {
... | 0 | Kotlin | 0 | 2 | 975695cc49f19a42c0407f41355abbfe0cb3cc59 | 4,515 | Advent-of-Code-2017 | MIT License |
src/main/kotlin/com/nibado/projects/advent/y2020/Day07.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2020
import com.nibado.projects.advent.*
object Day07 : Day {
private val REGEX_LINES = "([a-z ]+) bags contain ([0-9a-z, ]+)\\.".toRegex()
private val REGEX_BAG = "([0-9]+) ([a-z ]+) (bag|bags)".toRegex()
private val bags = resourceRegex(2020, 7, REGEX_LINES).map { (_,... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 1,243 | adventofcode | MIT License |
src/Day23.kt | dizney | 572,581,781 | false | {"Kotlin": 105380} | import Day23.draw
import Day23.proposeMoves
object Day23 {
const val EXPECTED_PART1_CHECK_ANSWER = 110
const val EXPECTED_PART2_CHECK_ANSWER = 20
sealed interface GridCell
object Empty : GridCell
object Elf : GridCell
class Grid {
private val rows = mutableListOf<List<GridCell>>()
... | 0 | Kotlin | 0 | 0 | f684a4e78adf77514717d64b2a0e22e9bea56b98 | 4,853 | aoc-2022-in-kotlin | Apache License 2.0 |
aoc-day3/src/Day3.kt | rnicoll | 438,043,402 | false | {"Kotlin": 90620, "Rust": 1313} | import java.io.File
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.pow
fun main() {
val filename = File("input");
val contents = parse(filename);
part1(contents);
part2(contents);
}
fun parse(path: File): ArrayList<ArrayList<Int>> {
val bits = ArrayList<ArrayList<Int>>()... | 0 | Kotlin | 0 | 0 | 8c3aa2a97cb7b71d76542f5aa7f81eedd4015661 | 2,567 | adventofcode2021 | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem210/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem210
/**
* LeetCode page: [210. Course Schedule II](https://leetcode.com/problems/course-schedule-ii/);
*/
class Solution {
/* Complexity:
* Time O(V+E) and Space O(V+E) where V is numCourses and E is size of prerequisites;
*/
fun findOrder(numCourses: Int, prer... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,610 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/com/mckernant1/advent2023/Day1.kt | mckernant1 | 494,952,749 | false | {"Kotlin": 33093} | package com.mckernant1.advent2023
import com.mckernant1.commons.extensions.collections.SortedMaps.firstEntry
import com.mckernant1.commons.extensions.collections.SortedMaps.lastEntry
fun main() {
val cords1 = """
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
""".trimIndent()
... | 0 | Kotlin | 0 | 0 | 5aaa96588925b1b8d77d7dd98dd54738deeab7f1 | 1,523 | kotlin-random | Apache License 2.0 |
src/main/kotlin/day17.kt | gautemo | 433,582,833 | false | {"Kotlin": 91784} | import shared.getText
import kotlin.math.max
import kotlin.math.min
fun highestPosTrajectory(input: String) = hittingProbes(input).maxOf { it.maxY }
fun nrHitTrajectories(input: String) = hittingProbes(input).size
private fun hittingProbes(input: String): List<Probe> {
val target = findTarget(input)
val onTar... | 0 | Kotlin | 0 | 0 | c50d872601ba52474fcf9451a78e3e1bcfa476f7 | 2,155 | AdventOfCode2021 | MIT License |
src/main/kotlin/g2601_2700/s2602_minimum_operations_to_make_all_array_elements_equal/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2601_2700.s2602_minimum_operations_to_make_all_array_elements_equal
// #Medium #Array #Sorting #Binary_Search #Prefix_Sum
// #2023_07_13_Time_790_ms_(100.00%)_Space_63.8_MB_(100.00%)
class Solution {
fun minOperations(nums: IntArray, queries: IntArray): List<Long> {
nums.sort()
val sum = ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,373 | LeetCode-in-Kotlin | MIT License |
src/2021/Day14.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2021`
import java.io.File
import java.math.BigInteger
import java.util.*
fun main() {
Day14().solve()
}
class Day14 {
val input = """
NNCB
CH -> B
HH -> N
CB -> H
NH -> C
HB -> C
HC -> B
HN -> C
NN -> C
BH -> H
NC -> B
NB -> B
BN -> B
BB -> N
BC -> B
CC -> N
CN -> C
""".trimIndent()
fu... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 2,468 | advent-of-code | Apache License 2.0 |
src/Day10.kt | mcrispim | 573,449,109 | false | {"Kotlin": 46488} | fun main() {
fun part1(input: List<String>): Int {
var nextCommand = 0
val measures = listOf(20, 60, 100, 140, 180, 220)
val strength = mutableListOf<Int>()
var nextMeasure = 0
var cycle = 1
var registerX = 1
while (nextCommand <= input.lastIndex) {
... | 0 | Kotlin | 0 | 0 | 5fcacc6316e1576a172a46ba5fc9f70bcb41f532 | 2,335 | AoC2022 | Apache License 2.0 |
src/main/kotlin/g0801_0900/s0840_magic_squares_in_grid/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0840_magic_squares_in_grid
// #Medium #Array #Math #Matrix #2023_03_28_Time_149_ms_(100.00%)_Space_34.2_MB_(100.00%)
class Solution {
fun numMagicSquaresInside(grid: Array<IntArray>): Int {
val m = grid.size
val n = grid[0].size
var count = 0
for (i in 0 until m... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,139 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/adventofcode/y2021/Day05.kt | Tasaio | 433,879,637 | false | {"Kotlin": 117806} | import adventofcode.*
fun main() {
val day = Day05()
println(day.part1())
day.reset()
println(day.part2())
}
class Day05 : Y2021Day(5) {
private val input = fetchInput()
private val points: List<Pair<Coordinate, Coordinate>> = input.map {
val a = it.split("->")
val res1= a[0].... | 0 | Kotlin | 0 | 0 | cc72684e862a782fad78b8ef0d1929b21300ced8 | 3,065 | adventofcode2021 | The Unlicense |
src/main/kotlin/g2001_2100/s2045_second_minimum_time_to_reach_destination/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2001_2100.s2045_second_minimum_time_to_reach_destination
// #Hard #Breadth_First_Search #Graph #Shortest_Path
// #2023_06_23_Time_862_ms_(100.00%)_Space_57.2_MB_(100.00%)
import java.util.LinkedList
import java.util.Queue
class Solution {
fun secondMinimum(n: Int, edges: Array<IntArray>, time: Int, chan... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,908 | LeetCode-in-Kotlin | MIT License |
src/Day19.kt | andrikeev | 574,393,673 | false | {"Kotlin": 70541, "Python": 18310, "HTML": 5558} | fun main() {
fun part1(input: List<String>): Int {
val blueprints = input.map(Blueprint::parse)
return blueprints.sumOf { blueprint ->
(blueprint.id * blueprint.simulate(24)).also { println("${blueprint.id}: $it") }
}
}
fun part2(input: List<String>): Int {
val ... | 0 | Kotlin | 0 | 1 | 1aedc6c61407a28e0abcad86e2fdfe0b41add139 | 6,117 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2017/Day19.kt | tginsberg | 112,672,087 | false | null | /*
* Copyright (c) 2017 by <NAME>
*/
package com.ginsberg.advent2017
/**
* AoC 2017, Day 19
*
* Problem Description: http://adventofcode.com/2017/day/19
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2017/day19/
*/
class Day19(private val input: List<String>) {
private val grid = in... | 0 | Kotlin | 0 | 15 | a57219e75ff9412292319b71827b35023f709036 | 2,013 | advent-2017-kotlin | MIT License |
src/org/aoc2021/Day13.kt | jsgroth | 439,763,933 | false | {"Kotlin": 86732} | package org.aoc2021
import java.nio.file.Files
import java.nio.file.Path
object Day13 {
data class Point(val x: Int, val y: Int)
data class Fold(val direction: String, val coordinate: Int)
private fun solvePart1(lines: List<String>): Int {
val (points, folds) = parseLines(lines)
val (co... | 0 | Kotlin | 0 | 0 | ba81fadf2a8106fae3e16ed825cc25bbb7a95409 | 4,131 | advent-of-code-2021 | The Unlicense |
src/kotlin/_2022/Task05.kt | MuhammadSaadSiddique | 567,431,330 | false | {"Kotlin": 20410} | package _2022
import Task
import readInput
import java.util.*
object Task05 : Task {
override fun partA() = parseInput().let { (stacks, instructions) ->
instructions.forEach { (move, from, to) ->
repeat(move) { stacks[to]?.push(stacks[from]?.pop()) }
}
findTopCrates(stacks)
... | 0 | Kotlin | 0 | 0 | 3893ae1ac096c56e224e798d08d7fee60e299a84 | 1,750 | AdventCode-Kotlin | Apache License 2.0 |
src/Day02.kt | razvn | 573,166,955 | false | {"Kotlin": 27208} | import java.lang.Exception
fun main() {
val day = "Day02"
fun part1(input: List<String>): Int = input.fold(0) { acc, line ->
val player1 = calcPlayer(line[0])
val player2 = calcPlayer(line[2])
val result = calcResult(player1, player2)
acc + result.value + player2.value
}
... | 0 | Kotlin | 0 | 0 | 73d1117b49111e5044273767a120142b5797a67b | 2,579 | aoc-2022-kotlin | Apache License 2.0 |
src/day5/Day05.kt | JoeSkedulo | 573,328,678 | false | {"Kotlin": 69788} | package day5
import Runner
fun main() {
Day5Runner().solve()
}
class Day5Runner : Runner<String>(
day = 5,
expectedPartOneTestAnswer = "CMZ",
expectedPartTwoTestAnswer = "MCD"
) {
override fun partOne(input: List<String>, test: Boolean): String {
val moves = input.filter { line -> line.... | 0 | Kotlin | 0 | 0 | bd8f4058cef195804c7a057473998bf80b88b781 | 2,914 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem904/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem904
/**
* LeetCode page: [904. Fruit Into Baskets](https://leetcode.com/problems/fruit-into-baskets/);
*/
class Solution {
/* Complexity:
* Time O(|fruits|) and Space O(1);
*/
fun totalFruit(fruits: IntArray): Int {
// an emptyBasket that match algorith... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,852 | hj-leetcode-kotlin | Apache License 2.0 |
2021/src/test/kotlin/Day19.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import Util.splitWhen
import kotlin.math.abs
import kotlin.test.Test
import kotlin.test.assertEquals
class Day19 {
data class Position(val x: Int, val y: Int, val z: Int)
data class Scanner(val index: Int, val beacons: Set<Position>)
enum class Turn { NONE, RIGHT, LEFT, UP, DOWN, BACKWARDS }
enum class... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 13,218 | adventofcode | MIT License |
src/main/kotlin/Day09.kt | arosenf | 726,114,493 | false | {"Kotlin": 40487} | import kotlin.system.exitProcess
fun main(args: Array<String>) {
if (args.isEmpty() or (args.size < 2)) {
println("Input not specified")
exitProcess(1)
}
val fileName = args.first()
println("Reading $fileName")
val lines = readLines(fileName)
val result =
if (args[1] ==... | 0 | Kotlin | 0 | 0 | d9ce83ee89db7081cf7c14bcad09e1348d9059cb | 1,823 | adventofcode2023 | MIT License |
src/main/kotlin/y2022/day07/Day07.kt | TimWestmark | 571,510,211 | false | {"Kotlin": 97942, "Shell": 1067} | package y2022.day07
fun main() {
AoCGenerics.printAndMeasureResults(
part1 = { part1() },
part2 = { part2() }
)
}
data class Directory(
val name: String,
val subDirs: MutableList<Directory>,
val parentDir: Directory?,
var size: Int
)
fun input(): Directory {
val root = Di... | 0 | Kotlin | 0 | 0 | 23b3edf887e31bef5eed3f00c1826261b9a4bd30 | 2,046 | AdventOfCode | MIT License |
src/2021-Day02.kt | frozbiz | 573,457,870 | false | {"Kotlin": 124645} | fun main() {
// coords = [0,0,0]
// for line in input:
// (cmd, distance) = line.split(" ")
// distance = int(distance)
// if cmd == "forward":
// coords[0] += distance
// coords[1] += distance * coords[2]
// elif cmd == "up":
// coords[2] -= distance
// else:
// coords[2] += distance
... | 0 | Kotlin | 0 | 0 | 4feef3fa7cd5f3cea1957bed1d1ab5d1eb2bc388 | 2,171 | 2022-aoc-kotlin | Apache License 2.0 |
src/main/kotlin/puzzle10/SyntaxScorer.kt | tpoujol | 436,532,129 | false | {"Kotlin": 47470} | package puzzle10
import java.lang.IllegalStateException
import kotlin.system.measureTimeMillis
fun main() {
val syntaxScorer = SyntaxScorer()
val time = measureTimeMillis {
println("Bad line scoring: ${syntaxScorer.fixBrokenLines()}")
println("Incomplete line scoring: ${syntaxScorer.fixIncomp... | 0 | Kotlin | 0 | 1 | 6d474b30e5204d3bd9c86b50ed657f756a638b2b | 5,283 | aoc-2021 | Apache License 2.0 |
src/day10/Day10.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day10
import readInput
data class Instruction(val duration: Int, val delta: Int)
fun main() {
fun part1(input: List<String>): Int {
var signalStrengthSum = 0
var x = 1
var counter = 0
var cycle = 0
var instruction: Instruction
val signalSampleCycles = listO... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 3,275 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/days/Day2.kt | jgrgt | 433,952,606 | false | {"Kotlin": 113705} | package days
class Day2 : Day(2) {
override fun partOne(): Any {
val commands = inputList.map { Command.from(it) }
val position = commands.fold(Position(0, 0)) { position, command ->
move(position, command)
}
return position.horizontal * position.depth
}
overrid... | 0 | Kotlin | 0 | 0 | 6231e2092314ece3f993d5acf862965ba67db44f | 2,341 | aoc2021 | Creative Commons Zero v1.0 Universal |
src/Day05.kt | rk012 | 574,169,156 | false | {"Kotlin": 9389} | fun main() {
fun List<String>.parseLayout() = ((last().length + 2) / 4).let { size ->
dropLast(1).map { line ->
("$line ").chunked(4).let { items ->
List(size) {
items.getOrNull(it)?.ifBlank { null }?.get(1)
}
}
}
}
... | 0 | Kotlin | 0 | 0 | bfb4c56c4d4c8153241fa6aa6ae0e829012e6679 | 2,103 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/michaelbull/advent2021/day4/BingoBoard.kt | michaelbull | 433,565,311 | false | {"Kotlin": 162839} | package com.github.michaelbull.advent2021.day4
import com.github.michaelbull.advent2021.math.Vector2
private val ROW_REGEX = "(\\d+)+".toRegex()
fun Iterator<String>.toBingoBoard(size: Int): BingoBoard {
val cells = buildMap {
repeat(size) { rowIndex ->
val row = this@toBingoBoard.next()
... | 0 | Kotlin | 0 | 4 | 7cec2ac03705da007f227306ceb0e87f302e2e54 | 1,910 | advent-2021 | ISC License |
src/Day05.kt | chasebleyl | 573,058,526 | false | {"Kotlin": 15274} |
data class Stack(
val id: Int,
val crates: ArrayDeque<String> = ArrayDeque(),
)
fun ArrayDeque<String>.removeLastN(n: Int): ArrayDeque<String> {
val elements = ArrayDeque<String>()
for (i in 1..n) {
elements.addFirst(this.removeLast())
}
return elements
}
fun ArrayDeque<String>.addLastN... | 0 | Kotlin | 0 | 1 | f2f5cb5fd50fb3e7fb9deeab2ae637d2e3605ea3 | 3,564 | aoc-2022 | Apache License 2.0 |
kotlin/src/2022/Day07_2022.kt | regob | 575,917,627 | false | {"Kotlin": 50757, "Python": 46520, "Shell": 430} |
private data class Elem(val parent: Elem?, val children: MutableMap<String, Elem> = mutableMapOf(), var size: Int = 0)
private fun calcTotalSize(node: Elem, acc: MutableList<Int>): Int {
var total = node.children.values.sumOf {
calcTotalSize(it, acc)
}
total += node.size
acc.add(total)
ret... | 0 | Kotlin | 0 | 0 | cf49abe24c1242e23e96719cc71ed471e77b3154 | 1,463 | adventofcode | Apache License 2.0 |
src/day08/Day08.kt | TheJosean | 573,113,380 | false | {"Kotlin": 20611} | package day08
import readInput
fun main() {
fun List<List<Char>>.visibleLeft(i: Int, j: Int): Boolean {
val base = this[i][j]
for (x in j - 1 downTo 0) {
if (this[i][x] >= base) return false
}
return true
}
fun List<List<Char>>.visibleRight(i: Int, j: Int): Bo... | 0 | Kotlin | 0 | 0 | 798d5e9b1ce446ba3bac86f70b7888335e1a242b | 3,068 | advent-of-code | Apache License 2.0 |
src/Day02.kt | JonahBreslow | 578,314,149 | false | {"Kotlin": 6978} | import java.io.File
fun main(){
fun read_file(file_path: String) : List<String> {
val text = File(file_path).readLines()
return text
}
val fix = mapOf("A" to "X", "B" to "Y", "C" to "Z")
fun part1(x: String) : Int {
val me: String = x[2].toString()
val opp: String = f... | 0 | Kotlin | 0 | 1 | c307ff29616f613473768168cc831a7a3fa346c2 | 1,727 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day04/Day04.kt | Volifter | 572,720,551 | false | {"Kotlin": 65483} | package day04
import utils.*
fun getRanges(input: List<String>): List<Pair<IntRange, IntRange>> {
val regex = """^(\d+)-(\d+),(\d+)-(\d+)$""".toRegex()
return input.map { line ->
val (a, b, c, d) = regex.find(line)!!.groupValues
.drop(1)
.map(String::toInt)
Pair(a..b,... | 0 | Kotlin | 0 | 0 | c2c386844c09087c3eac4b66ee675d0a95bc8ccc | 823 | AOC-2022-Kotlin | Apache License 2.0 |
src/main/kotlin/days_2021/Day9.kt | BasKiers | 434,124,805 | false | {"Kotlin": 40804} | package days_2021
import util.Day
class Day9 : Day(9) {
val input = inputList.map { row -> row.toCharArray().map(Char::digitToInt) }
fun getPosition(seaFloor: List<List<Int>>, position: Pair<Int, Int>) =
seaFloor.getOrNull(position.second)?.getOrNull(position.first)
val directions = listOf(1 to ... | 0 | Kotlin | 0 | 0 | 870715c172f595b731ee6de275687c2d77caf2f3 | 2,969 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/groundsfam/advent/y2023/d13/Day13.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2023.d13
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.grids.Grid
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
sealed interface Reflection
@JvmInline
value class Column(val n: Int) : Reflection
@JvmInline
value class ... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 3,273 | advent-of-code | MIT License |
day16/src/Day16.kt | simonrules | 491,302,880 | false | {"Kotlin": 68645} | import java.io.File
class Day16(path: String) {
var binary = ""
var versionTotal = 0
init {
val text = File(path).readText()
text.forEach {
binary = binary.plus(when(it) {
'0' -> "0000"
'1' -> "0001"
'2' -> "0010"
... | 0 | Kotlin | 0 | 0 | d9e4ae66e546f174bcf66b8bf3e7145bfab2f498 | 3,411 | aoc2021 | Apache License 2.0 |
src/main/kotlin/io/github/clechasseur/adventofcode/y2022/Day11.kt | clechasseur | 567,968,171 | false | {"Kotlin": 493887} | package io.github.clechasseur.adventofcode.y2022
object Day11 {
private val input = listOf(
Monkey(
id = 0,
items = listOf(63L, 84L, 80L, 83L, 84L, 53L, 88L, 72L),
op = { it * 11L },
test = { if (it % 13L == 0L) 4 else 7 }
),
Monkey(
... | 0 | Kotlin | 0 | 0 | 7ead7db6491d6fba2479cd604f684f0f8c1e450f | 3,218 | adventofcode2022 | MIT License |
src/day01/Day01.kt | schrami8 | 572,631,109 | false | {"Kotlin": 18696} | fun <E> List<E>.splitBy(predicate: (E) -> Boolean): List<List<E>> =
this.fold(mutableListOf(mutableListOf<E>())) { acc, element ->
if (predicate.invoke(element)) {
acc += mutableListOf<E>()
} else {
acc.last() += element
}
acc
}
fun main() {
fun part1... | 0 | Kotlin | 0 | 0 | 215f89d7cd894ce58244f27e8f756af28420fc94 | 1,382 | advent-of-code-kotlin | Apache License 2.0 |
src/y2022/day01.kt | sapuglha | 573,238,440 | false | {"Kotlin": 33695} | package y2022
import readFileAsLines
import readFileAsText
fun main() {
val fileName = "y2022/data/day01"
fun sumElves(input: List<String>): List<Int> {
val response: MutableList<Int> = mutableListOf()
val sublist: MutableList<Int> = mutableListOf()
input.forEach {
if (it... | 0 | Kotlin | 0 | 0 | 82a96ccc8dcf38ae4974e6726e27ddcc164e4b54 | 1,678 | adventOfCode2022 | Apache License 2.0 |
src/day-12.kt | drademacher | 160,820,401 | false | null | import java.io.File
fun main(args: Array<String>) {
println("part 1: " + simulateFast(20))
println("part 2: " + simulateFast(50000000000))
}
// REMARK: the cycle becomes stable after around 200 generations, then adding 34 plants each cycle
private fun simulateFast(generations: Long): Long {
if (generation... | 0 | Kotlin | 0 | 0 | a7f04450406a08a5d9320271148e0ae226f34ac3 | 1,843 | advent-of-code-2018 | MIT License |
src/main/kotlin/net/wrony/aoc2023/a15/15.kt | kopernic-pl | 727,133,267 | false | {"Kotlin": 52043} | package net.wrony.aoc2023.a15
import kotlin.io.path.Path
import kotlin.io.path.readText
fun String.hASH(): Int {
return this.fold(0) { acc, c ->
((acc + c.code) * 17) % 256
}
}
sealed class Operation(val element: String) {
class INSERT(element: String, val focal: Int) : Operation(element) {
... | 0 | Kotlin | 0 | 0 | 1719de979ac3e8862264ac105eb038a51aa0ddfb | 2,315 | aoc-2023-kotlin | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.