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/Day6.kt | clechasseur | 264,758,910 | false | null | object Day6 {
private val input = """
2 8 8 5 4 2 3 1 5 5 1 2 15 13 5 14
""".trimIndent().split('\t').map { it.toInt() }
fun part1() = detectLoop().size - 1
fun part2(): Int {
val loop = detectLoop()
val start = loop.indexOf(loop.last())
return loop.indices.last - start... | 0 | Kotlin | 0 | 0 | f3e8840700e4c71e59d34fb22850f152f4e6e739 | 1,061 | adventofcode2017 | MIT License |
src/Day04.kt | andrewgadion | 572,927,267 | false | {"Kotlin": 16973} | fun main() {
fun parseRange(str: String) = str.split("-").let { it[0].toLong()..it[1].toLong() }
fun parse(input: List<String>) = input.map { it.split(',').map(::parseRange) }
fun LongRange.contains(range: LongRange) = this.first <= range.first && this.last >= range.last
fun LongRange.intersects(range:... | 0 | Kotlin | 0 | 0 | 4d091e2da5d45a786aee4721624ddcae681664c9 | 703 | advent-of-code-2022 | Apache License 2.0 |
2019/src/test/kotlin/Day03.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import kotlin.IllegalArgumentException
import kotlin.math.absoluteValue
import kotlin.test.Test
import kotlin.test.assertEquals
class Day03 {
enum class Direction { R, L, U, D }
data class Location(val x: Int, val y: Int) { fun toManhattenDistance() = x.absoluteValue + y.absoluteValue }
data class Path(va... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 2,119 | adventofcode | MIT License |
src/main/kotlin/com/mantono/tsa/Trends.kt | mantono | 105,402,624 | false | null | package com.mantono.tsa
import java.time.Duration
import java.time.Instant
data class Trend(val first: Collection<Number>, val second: Collection<Number>)
{
fun bySum(): Double = second.sum() / first.sum()
fun byAverage(): Double = second.average() / first.average()
fun byMedian(): Double = second.median(... | 0 | Kotlin | 0 | 0 | 978a8a82dd02b20028f5012060caa7ca2fe22b8e | 3,060 | time-series-analysis | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year21/Day03.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year21
import com.grappenmaker.aoc.PuzzleSet
import kotlin.math.pow
fun PuzzleSet.day3() = puzzle(day = 3) {
// Part one
val lines = inputLines
val width = lines.first().length
val numbers = lines.map { it.toInt(2) }
val gamma = (0 until width)
.reduceIndexed ... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,261 | advent-of-code | The Unlicense |
src/day10/day10.kt | bienenjakob | 573,125,960 | false | {"Kotlin": 53763} | package day10
import inputTextOfDay
import testTextOfDay
fun part1(input: String): Int {
val instructions = input.lines()
var cycle = 1
var x = 1
var strength = 0
instructions.forEach {
when {
it.startsWith("addx") -> {
strength += measureStrength(cycle, x) ... | 0 | Kotlin | 0 | 0 | 6ff34edab6f7b4b0630fb2760120725bed725daa | 2,185 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/github/michaelbull/advent2023/day25/WiringDiagram.kt | michaelbull | 726,012,340 | false | {"Kotlin": 195941} | package com.github.michaelbull.advent2023.day25
import org.jgrapht.Graph
import org.jgrapht.alg.StoerWagnerMinimumCut
import org.jgrapht.graph.DefaultWeightedEdge
import org.jgrapht.graph.SimpleWeightedGraph
fun Sequence<String>.toWiringDiagram(): WiringDiagram {
return WiringDiagram(map(String::toConnection).toL... | 0 | Kotlin | 0 | 1 | ea0b10a9c6528d82ddb481b9cf627841f44184dd | 1,361 | advent-2023 | ISC License |
src/main/kotlin/Day14.kt | clechasseur | 267,632,210 | false | null | import org.clechasseur.adventofcode2016.md5
object Day14 {
private const val input = "ahsbgdzn"
private val tripleRegex = """(.)\1\1""".toRegex()
fun part1(): Int = keySequence(false).drop(63).first().second
fun part2(): Int = keySequence(true).drop(63).first().second
private fun hashSequence(s... | 0 | Kotlin | 0 | 0 | 120795d90c47e80bfa2346bd6ab19ab6b7054167 | 1,699 | adventofcode2016 | MIT License |
src/Day01.kt | vladislav-og | 573,326,483 | false | {"Kotlin": 27072} | fun main() {
fun part1(input: List<String>): Int {
var maxCalories = 0
var caloriesCounter = 0
for (row in input) {
if (row == "") {
if (maxCalories < caloriesCounter) {
maxCalories = caloriesCounter
}
caloriesCo... | 0 | Kotlin | 0 | 0 | b230ebcb5705786af4c7867ef5f09ab2262297b6 | 1,325 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/d8/d8.kt | LaurentJeanpierre1 | 573,454,829 | false | {"Kotlin": 118105} | package d8
import readInput
fun part1(input: List<String>): Int {
val trees = mutableListOf<List<Int>>()
for (line in input) {
if (line.isNotBlank())
trees.add(line.toList().map { v-> v-'0' })
}
var nbVis = 0
val lines = trees.size
for ((idxL, line) in trees.withIndex()) {... | 0 | Kotlin | 0 | 0 | 5cf6b2142df6082ddd7d94f2dbde037f1fe0508f | 4,254 | aoc2022 | Creative Commons Zero v1.0 Universal |
src/main/aoc2022/Day15.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2022
import Pos
import intersect
import size
import unionALl
import kotlin.math.abs
class Day15(input: List<String>) {
data class Sensor(val pos: Pos, val beacon: Pos) {
/**
* Gives the range of x coordinates that is visible on the given y coordinate for this sensor. Returns
... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,492 | aoc | MIT License |
src/main/kotlin/day24.kt | tobiasae | 434,034,540 | false | {"Kotlin": 72901} | class Day24 : Solvable("24") {
override fun solveA(input: List<String>): String {
return solve(getInstructions(input), true)
}
override fun solveB(input: List<String>): String {
return solve(getInstructions(input), false)
}
private fun getInstructions(input: List<String>): List<Pa... | 0 | Kotlin | 0 | 0 | 16233aa7c4820db072f35e7b08213d0bd3a5be69 | 4,726 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/day13.kt | Gitvert | 725,292,325 | false | {"Kotlin": 97000} | val originalReflection = mutableMapOf<Int, Mirror>()
fun day13 (lines: List<String>) {
val patterns = parsePatterns(lines)
var sum = 0L
patterns.forEachIndexed { index, it ->
var newSum = findHorizontalReflectionSum(it, 100, true, index)
if (newSum == 0) {
newSum = f... | 0 | Kotlin | 0 | 0 | f204f09c94528f5cd83ce0149a254c4b0ca3bc91 | 4,363 | advent_of_code_2023 | MIT License |
jvm_sandbox/projects/advent_of_code/src/main/kotlin/year2018/Day2.kt | jduan | 166,515,850 | false | {"Rust": 876461, "Kotlin": 257167, "Java": 139101, "Python": 114308, "Vim Script": 100117, "Shell": 96665, "C": 67784, "Starlark": 23497, "JavaScript": 20939, "HTML": 12920, "Ruby": 5087, "Thrift": 4518, "Nix": 2919, "HCL": 1069, "Lua": 926, "CSS": 826, "Assembly": 761, "Makefile": 591, "Haskell": 585, "Dockerfile": 50... | package year2018.day2
import java.io.File
import java.lang.Exception
import java.util.*
fun checksum(path: String): Int {
var totalTwos = 0
var totalThrees = 0
File(path).forEachLine {
val (twos, threes) = countID2(it)
totalTwos += twos
totalThrees += threes
}
return (totalTwos * totalThrees)
}... | 58 | Rust | 1 | 0 | d5143e89ce25d761eac67e9c357620231cab303e | 2,584 | cosmos | MIT License |
kotlin/src/main/kotlin/dev/akkinoc/atcoder/workspace/kotlin/algo/ListAlgo.kt | akkinoc | 520,873,415 | false | {"Kotlin": 24773} | package dev.akkinoc.atcoder.workspace.kotlin.algo
/**
* The algorithms for [List].
*/
object ListAlgo {
/**
* Generate a sequence of permutations.
*
* @receiver The source elements.
* @param T The element type.
* @param r The number of elements to select.
* @return A sequence of pe... | 1 | Kotlin | 0 | 1 | e650a9c2e73d26a8f037b4f9f0dfe960171a604a | 2,575 | atcoder-workspace | MIT License |
LeetCode2020April/week3/src/main/kotlin/net/twisterrob/challenges/leetcode2020april/week3/number_islands/Solution.kt | TWiStErRob | 136,539,340 | false | {"Kotlin": 104880, "Java": 11319} | package net.twisterrob.challenges.leetcode2020april.week3.number_islands
class Solution {
fun numIslands(grid: Array<CharArray>): Int {
val islands = Array(grid.size) { r ->
IntArray(grid[0].size) { c ->
when (grid[r][c]) {
'1' -> Marker.UNPROCESSED_LAND
'0' -> Marker.WATER
else -> error("Inv... | 1 | Kotlin | 1 | 2 | 5cf062322ddecd72d29f7682c3a104d687bd5cfc | 1,645 | TWiStErRob | The Unlicense |
src/main/kotlin/com/groundsfam/advent/y2020/d14/Day14.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2020.d14
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.pow
import kotlin.io.path.div
import kotlin.io.path.useLines
private sealed class Instruction
private data class SetMask(val mask: String) : Instruction()
private data class WriteValue(val location: Int, val va... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 3,082 | advent-of-code | MIT License |
src/questions/FindDuplicateNumber.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import kotlin.math.ceil
import kotlin.test.assertEquals
/**
* Given an array of integers nums containing `n + 1` integers where each integer is in the range `[1, n]` inclusive.
* There is only one repeated number in `nums`, return this repeated number.
* Yo... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,799 | algorithms | MIT License |
kotlin/src/main/kotlin/AoC_Day23.kt | sviams | 115,921,582 | false | null | object AoC_Day23 {
fun registers(aVal: Long) = mapOf<Char, Long>('a' to aVal,
'b' to 0, 'c' to 0, 'd' to 0, 'e' to 0, 'f' to 0, 'g' to 0, 'h' to 0, 'x' to 0)
data class State(val registers: Map<Char, Long>, val pc: Long, val isTerminated: Boolean)
fun parseOps(instructions: List<String>) : Lis... | 0 | Kotlin | 0 | 0 | 19a665bb469279b1e7138032a183937993021e36 | 3,809 | aoc17 | MIT License |
src/Day05.kt | euphonie | 571,665,044 | false | {"Kotlin": 23344} | class MultiStack(private val stackCount: Int, private val stackSize: Int) {
private val array: Array<String> = Array(stackCount * stackSize) {""}
private val tops: Array<Int> = Array(stackCount) {-1}
fun push(stackIndex: Int, value: String) {
if (tops[stackIndex] == stackSize -1) {
thr... | 0 | Kotlin | 0 | 0 | 82e167e5a7e9f4b17f0fbdfd01854c071d3fd105 | 4,845 | advent-of-code-kotlin | Apache License 2.0 |
src/Day08.kt | a-glapinski | 572,880,091 | false | {"Kotlin": 26602} | import utils.readInputAsLines
fun main() {
val input = readInputAsLines("day08_input_test")
val grid = input.map { it.map(Char::digitToInt) }
val result1 = flyOver(grid,
lookAround = { current, direction -> direction.all { it < current } },
calculate = { directions -> if (directions.any { ... | 0 | Kotlin | 0 | 0 | c830d23ffc2ab8e9a422d015ecd413b5b01fb1a8 | 1,298 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | erikthered | 572,804,470 | false | {"Kotlin": 36722} | fun main() {
fun part1(input: List<String>): String {
var stacks = arrayListOf<ArrayDeque<Char>>()
var layout = true
for(line in input) {
if(layout) {
if(line.isBlank()) {
layout = false
}
val cols = line.windowe... | 0 | Kotlin | 0 | 0 | 3946827754a449cbe2a9e3e249a0db06fdc3995d | 2,664 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/mirecxp/aoc23/day01/Day01.kt | MirecXP | 726,044,224 | false | {"Kotlin": 42343} | package mirecxp.aoc23.day01
import java.io.File
import java.util.*
//https://adventofcode.com/2023/day/1
class Day01(inputPath: String) {
private val calibrations: List<String> =
File(inputPath).readLines().map { it.lowercase(Locale.getDefault()) }
fun solveA() {
println("Solving day 1A for ... | 0 | Kotlin | 0 | 0 | 6518fad9de6fb07f28375e46b50e971d99fce912 | 2,559 | AoC-2023 | MIT License |
lib/src/main/kotlin/de/linkel/aoc/utils/iterables/CombinationMixIn.kt | norganos | 726,350,504 | false | {"Kotlin": 162220} | package de.linkel.aoc.utils.iterables
fun <T> List<T>.combinationPairs(
withSelf: Boolean = false,
withMirrors: Boolean = false
): Sequence<Pair<T,T>> {
val size = this.size
val list = this
return sequence {
(0 until size)
.forEach { i ->
((if (withMirrors) 0 els... | 0 | Kotlin | 0 | 0 | 3a1ea4b967d2d0774944c2ed4d96111259c26d01 | 2,005 | aoc-utils | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch6/Problem63.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch6
import kotlin.math.log10
import kotlin.math.pow
/**
* Problem 63: Powerful Digit Counts
*
* https://projecteuler.net/problem=63
*
* Goal: Given N, find all N-digit positive integers that are also a Nth power.
*
* Constraints: 1 <= N <= 19
*
* e.g.: N = 2
* output = [16, 25, ... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,944 | project-euler-kotlin | MIT License |
src/Day04.kt | MerickBao | 572,842,983 | false | {"Kotlin": 28200} | fun main() {
fun game1(s: String): Boolean {
val arr = s.split(",")
val L = arr[0].split("-")
val R = arr[1].split("-")
val ll = L[0].toInt()
val lr = L[1].toInt()
val rl = R[0].toInt()
val rr = R[1].toInt()
return ll >= rl && lr <= rr || rl >= ll && ... | 0 | Kotlin | 0 | 0 | 70a4a52aa5164f541a8dd544c2e3231436410f4b | 1,077 | aoc-2022-in-kotlin | Apache License 2.0 |
app/src/main/java/com/marknkamau/justjava/data/models/AppProduct.kt | MarkNjunge | 86,477,705 | false | {"Kotlin": 237127} | package com.marknkamau.justjava.data.models
import com.marknjunge.core.data.model.Product
import com.marknjunge.core.data.model.ProductChoice
import com.marknjunge.core.data.model.ProductChoiceOption
data class AppProduct(
val id: Long,
val name: String,
val slug: String,
val image: String,
val cr... | 1 | Kotlin | 35 | 74 | e3811f064797d50fadef4033bf1532b3c2ceef8d | 2,294 | JustJava-Android | Apache License 2.0 |
src/Day25.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | fun main() {
val testInput = readInput("Day25_test")
val input = readInput("Day25")
part1(testInput).also {
println("Part 1, test input: $it")
check(it == "2=-1=0")
}
part1(input).also {
println("Part 1, real input: $it")
//check(it == 1)
}
part2(testInput)... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 1,853 | aoc22-kotlin | Apache License 2.0 |
src/Day06.kt | esteluk | 572,920,449 | false | {"Kotlin": 29185} | fun main() {
fun findMarker(message: String, size: Int): Int {
val windows = message.windowed(size, 1)
val index = windows.indexOfFirst { it.toCharArray().distinct().size == size }
return index + size
}
fun part1(input: String): Int {
return findMarker(input, 4)
}
f... | 0 | Kotlin | 0 | 0 | 5d1cf6c32b0c76c928e74e8dd69513bd68b8cb73 | 1,298 | adventofcode-2022 | Apache License 2.0 |
year2023/src/cz/veleto/aoc/year2023/Day09.kt | haluzpav | 573,073,312 | false | {"Kotlin": 164348} | package cz.veleto.aoc.year2023
import cz.veleto.aoc.core.AocDay
class Day09(config: Config) : AocDay(config) {
override fun part1(): String = input
.mapToEndStates()
.map { it.lastNumbers.sum() } // b = a + c
.sum()
.toString()
override fun part2(): String = input
.ma... | 0 | Kotlin | 0 | 1 | 32003edb726f7736f881edc263a85a404be6a5f0 | 1,575 | advent-of-pavel | Apache License 2.0 |
src/Day10.kt | kecolk | 572,819,860 | false | {"Kotlin": 22071} | data class Instruction(val operation: String, val operand: Int = 0)
fun parseInput(input: List<String>): List<Instruction> = input.map {
val parts = it.split(" ")
Instruction(
operation = parts[0],
operand = if (parts[0] == "addx") parts[1].toInt() else 0
)
}
class Processor() {
privat... | 0 | Kotlin | 0 | 0 | 72b3680a146d9d05be4ee209d5ba93ae46a5cb13 | 1,880 | kotlin_aoc_22 | Apache License 2.0 |
src/day03/Day03.kt | elenavuceljic | 575,436,628 | false | {"Kotlin": 5472} | package day03
import java.io.File
fun main() {
fun prioritiseItem(it: Char) = if (it.isUpperCase())
(it - 'A' + 27)
else
(it - 'a' + 1)
fun part1(input: String): Int {
val rucksacks = input.lines()
val duplicateItems = rucksacks.flatMap {
val (first, second) =... | 0 | Kotlin | 0 | 0 | c5093b111fd02e28823d31f2edddb7e66c295add | 1,140 | advent-of-code-2022 | Apache License 2.0 |
src/y2021/Day06.kt | Yg0R2 | 433,731,745 | false | null | package y2021
fun main() {
fun part1(input: List<String>): Long {
val fishTank = FishTank(input)
for (i in 0 until 80) {
fishTank.nextDay()
}
return fishTank.getFishCount()
}
fun part2(input: List<String>): Long {
val fishTank = FishTank(input)
... | 0 | Kotlin | 0 | 0 | d88df7529665b65617334d84b87762bd3ead1323 | 1,409 | advent-of-code | Apache License 2.0 |
src/Day13_json.kt | szymon-kaczorowski | 572,839,642 | false | {"Kotlin": 45324} | import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.jsonArray
fun main() {
operator fun JsonElement.compareTo(other: JsonElement): Int {
if (this i... | 0 | Kotlin | 0 | 0 | 1d7ab334f38a9e260c72725d3f583228acb6aa0e | 2,463 | advent-2022 | Apache License 2.0 |
advent-of-code-2020/src/main/kotlin/eu/janvdb/aoc2020/day06/Day06.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2020.day06
import eu.janvdb.aocutil.kotlin.readGroupedLines
fun main() {
val groups = readGroups()
println(groups.map(Group::combineOr).map(Answers::count).sum())
println(groups.map(Group::combineAnd).map(Answers::count).sum())
}
private fun readGroups(): List<Group> {
return readGroupedLin... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,163 | advent-of-code | Apache License 2.0 |
AdventOfCodeDay12/src/nativeMain/kotlin/Day12.kt | bdlepla | 451,510,571 | false | {"Kotlin": 165771} | class Day12(lines:List<String>) {
private val paths = buildPaths(lines)
fun solvePart1() = traverse(::part1VisitRule).size
fun solvePart2() = traverse(::part2VisitRule).size
private fun buildPaths(input: List<String>): Map<String, List<String>> =
input
.map { it.split("-") }
... | 0 | Kotlin | 0 | 0 | 1d60a1b3d0d60e0b3565263ca8d3bd5c229e2871 | 1,458 | AdventOfCode2021 | The Unlicense |
src/main/kotlin/kt/kotlinalgs/app/kickstart/roundG22/curling.ws.kts | sjaindl | 384,471,324 | false | null | var line = 0
var args: Array<String> = arrayOf()
fun readLine(): String? {
val result = args[line]
line++
return result
}
fun main(mainArgs: Array<String>) {
args = mainArgs
line = 0
// https://codingcompetitions.withgoogle.com/kickstart/round/00000000008cb2e1/0000000000c17c82
val testCa... | 0 | Java | 0 | 0 | e7ae2fcd1ce8dffabecfedb893cb04ccd9bf8ba0 | 3,008 | KotlinAlgs | MIT License |
src/main/kotlin/PerfectSquares.kt | Codextor | 453,514,033 | false | {"Kotlin": 26975} | /**
* Given an integer n, return the least number of perfect square numbers that sum to n.
*
* A perfect square is an integer that is the square of an integer;
* in other words, it is the product of some integer with itself.
* For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not.
*
*
*
* Exa... | 0 | Kotlin | 1 | 0 | 68b75a7ef8338c805824dfc24d666ac204c5931f | 972 | kotlin-codes | Apache License 2.0 |
src/main/kotlin/us/jwf/aoc2021/Day17TrickShot.kt | jasonwyatt | 318,073,137 | false | null | package us.jwf.aoc2021
import java.io.Reader
import us.jwf.aoc.Day
/**
* AoC 2021 - Day 17
*/
class Day17TrickShot : Day<Int, Int> {
override suspend fun executePart1(input: Reader): Int {
val targetArea = Rect(96..125, -144..-98)
val highestValidYs = mutableSetOf<Int>()
(1..125).forEach { candidate... | 0 | Kotlin | 0 | 0 | 0c92a62ba324aaa1f21d70b0f9f5d1a2c52e6868 | 2,001 | AdventOfCode-Kotlin | Apache License 2.0 |
kotlin/09.kt | NeonMika | 433,743,141 | false | {"Kotlin": 68645} | class Day9 : Day<TwoDimensionalArray<Int>>("09") {
override fun dataStar1(lines: List<String>): TwoDimensionalArray<Int> =
TwoDimensionalArray(lines.map { line -> line.map(Char::digitToInt) })
override fun dataStar2(lines: List<String>): TwoDimensionalArray<Int> = dataStar1(lines)
override fun sta... | 0 | Kotlin | 0 | 0 | c625d684147395fc2b347f5bc82476668da98b31 | 1,399 | advent-of-code-2021 | MIT License |
src/Day06.kt | cnietoc | 572,880,374 | false | {"Kotlin": 15990} |
fun main() {
fun process(input: String, markerSize: Int): Int {
val chars = input.iterator()
var charProcessedCount = 0;
val charProcessed = ArrayDeque<Char>(markerSize + 1)
while (chars.hasNext()) {
charProcessed.add(chars.nextChar())
charProcessedCount++
... | 0 | Kotlin | 0 | 0 | bbd8e81751b96b37d9fe48a54e5f4b3a0bab5da3 | 1,262 | aoc-2022 | Apache License 2.0 |
leetcode2/src/leetcode/decode-ways.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* 91. 解码方法
* https://leetcode-cn.com/problems/decode-ways/
* Created by test
* Date 2020/1/31 0:02
* Description
* 一条包含字母 A-Z 的消息通过以下方式进行了编码:
'A' -> 1
'B' -> 2
...
'Z' -> 26
给定一个只包含数字的非空字符串,请计算解码方法的总数。
示例 1:
输入: "12"
输出: 2
解释: 它可以解码为 "AB"(1 2)或者 "L"(12)。
示例 2:
输入: "226"
输出: 3
解释: 它可以解码为 ... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,636 | leetcode | MIT License |
src/main/kotlin/days/Day2.kt | hughjdavey | 159,955,618 | false | null | package days
import util.lazyAllPossiblePairs
import util.toInt
class Day2 : Day(2) {
override fun partOne(): Int {
val counts = inputList.map { toMatchSummary(it) }.fold(Pair(0, 0)) { totals, summary ->
Pair(totals.first + summary.first.toInt(), totals.second + summary.second.toInt())
... | 0 | Kotlin | 0 | 0 | 4f163752c67333aa6c42cdc27abe07be094961a7 | 1,832 | aoc-2018 | Creative Commons Zero v1.0 Universal |
leetcode2/src/leetcode/construct-binary-tree-from-preorder-and-inorder-traversal.kt | hewking | 68,515,222 | false | null | package leetcode
import leetcode.structure.TreeNode
/**
*
105. 从前序与中序遍历序列构造二叉树
* https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
* Created by test
* Date 2020/2/1 13:14
* Description
* 根据一棵树的前序遍历与中序遍历构造二叉树。
注意:
你可以假设树中没有重复的元素。
例如,给出
前序遍历 preorder = [3,9,20,15,7]
中序... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,006 | leetcode | MIT License |
Kotlin/src/main/kotlin/org/algorithm/problems/0049_unique_paths_iii.kt | raulhsant | 213,479,201 | true | {"C++": 1035543, "Kotlin": 114509, "Java": 27177, "Python": 16568, "Shell": 999, "Makefile": 187} | //Problem Statement
// On a 2-dimensional grid, there are 4 types of squares:
//
// * 1 represents the starting square. There is exactly one starting square.
// * 2 represents the ending square. There is exactly one ending square.
// * 0 represents empty squares we can walk over.
// * -1 represents obstacles that we ... | 0 | C++ | 0 | 0 | 1578a0dc0a34d63c74c28dd87b0873e0b725a0bd | 1,856 | algorithms | MIT License |
src/Day25.kt | felldo | 572,233,925 | false | {"Kotlin": 76496} | import kotlin.math.pow
fun main() {
fun snafuToDecimal(snafu: String): Long {
var total = 0L
for (i in snafu.indices) {
val power = 5.0.pow(snafu.length - i.toDouble() - 1).toLong()
total += when (snafu[i]) {
'2' -> 2L * power
'1' -> 1L * powe... | 0 | Kotlin | 0 | 0 | 0ef7ac4f160f484106b19632cd87ee7594cf3d38 | 1,287 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/days/aoc2023/Day5.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2023
import days.Day
class Day5 : Day(2023, 5) {
override fun partOne(): Any {
return calculatePartOne(inputList)
}
fun calculatePartOne(inputList: List<String>): Long {
val seeds = inputList.first().split("\\s+".toRegex()).drop(1).map { it.toLong() }
val maps = m... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 2,824 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
Problems/Algorithms/1473. Paint House III/PaintHouseIII.kt | xuedong | 189,745,542 | false | {"Kotlin": 332182, "Java": 294218, "Python": 237866, "C++": 97190, "Rust": 82753, "Go": 37320, "JavaScript": 12030, "Ruby": 3367, "C": 3121, "C#": 3117, "Swift": 2876, "Scala": 2868, "TypeScript": 2134, "Shell": 149, "Elixir": 130, "Racket": 107, "Erlang": 96, "Dart": 65} | class Solution {
fun minCost(houses: IntArray, cost: Array<IntArray>, m: Int, n: Int, target: Int): Int {
val dp = Array(m) { Array(n) { IntArray(target+1) { 1000001 } } }
for (color in 1..n) {
if (houses[0] == color) {
dp[0][color-1][1] = 0
} else if... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 1,631 | leet-code | MIT License |
src/main/kotlin/adventofcode/NumberUtils.kt | Tasaio | 433,879,637 | false | {"Kotlin": 117806} | package adventofcode
import java.math.BigInteger
fun allCombinationsOf(num: List<Int>): Set<List<Int>> {
return allCombinationsOf(num, arrayListOf())
}
fun allCombinationsOf(num: IntRange): Set<List<Int>> {
return allCombinationsOf(num.toList(), arrayListOf())
}
private fun allCombinationsOf(num: List<Int>,... | 0 | Kotlin | 0 | 0 | cc72684e862a782fad78b8ef0d1929b21300ced8 | 3,334 | adventofcode2021 | The Unlicense |
src/main/aoc2018/Day13.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2018
import Direction
import Pos
import next
class Day13(input: List<String>) {
enum class Turn {
LEFT,
STRAIGHT,
RIGHT
}
data class Path(val exits: List<Direction>)
data class Cart(var pos: Pos, var comingFrom: Direction) {
var removed = false
priv... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 4,636 | aoc | MIT License |
src/main/kotlin/com/rtarita/days/Day7.kt | RaphaelTarita | 724,581,070 | false | {"Kotlin": 64943} | package com.rtarita.days
import com.rtarita.structure.AoCDay
import com.rtarita.util.day
import kotlinx.datetime.LocalDate
object Day7 : AoCDay {
override val day: LocalDate = day(7)
private fun parse(input: String) = input.lineSequence()
.map {
val (hand, bid) = it.split(" ")
... | 0 | Kotlin | 0 | 0 | 4691126d970ab0d5034239949bd399c8692f3bb1 | 2,570 | AoC-2023 | Apache License 2.0 |
src/Day05.kt | felldo | 572,233,925 | false | {"Kotlin": 76496} | import java.util.LinkedList
fun main() {
fun getSupplyStacks() = listOf(
LinkedList(listOf("D", "M", "S", "Z", "R", "F", "W", "N")),
LinkedList(listOf("W", "P", "Q", "G", "S")),
LinkedList(listOf("W", "R", "V", "Q", "F", "N", "J", "C")),
LinkedList(listOf("F", "Z", "P", "C", "G", "D... | 0 | Kotlin | 0 | 0 | 0ef7ac4f160f484106b19632cd87ee7594cf3d38 | 1,805 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day02/Day02.kt | jpveilleux | 573,221,738 | false | {"Kotlin": 42252} | package day02
import readInput
fun main() {
// Opponent
// -----------------
// A = Rock
// B = Paper
// C = Scissors
// Player
// -----------------
// X = Rock = 1
// Y = Paper = 2
// Z = Scissors = 3
val myMoveScores = mapOf(
"X" to 1,
"Y" to 2,
... | 0 | Kotlin | 0 | 0 | 5ece22f84f2373272b26d77f92c92cf9c9e5f4df | 3,213 | jpadventofcode2022 | Apache License 2.0 |
src/main/kotlin/year2023/Day09.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2023
class Day09 {
fun part1(input: String) = solve(parseInput(input, false))
fun part2(input: String) = solve(parseInput(input, true))
fun parseInput(input: String, reverse: Boolean) = input.lines()
.map { line ->
line.split(' ').map { num -> num.toLong() }
... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 1,318 | aoc-2022 | Apache License 2.0 |
src/day01/Day01.kt | Puju2496 | 576,611,911 | false | {"Kotlin": 46156} | package day01
import readInput
fun main() {
// test if implementation meets criteria from the description, like:
val input = readInput("src/day01", "Day01")
val elfs = part1(input)
part2(elfs)
}
private fun part1(input: List<String>): List<Int> {
var sum = 0
val elfs = mutableListOf<Int>()
... | 0 | Kotlin | 0 | 0 | e04f89c67f6170441651a1fe2bd1f2448a2cf64e | 1,003 | advent-of-code-2022 | Apache License 2.0 |
src/com/ajithkumar/aoc2022/Day04.kt | ajithkumar | 574,372,025 | false | {"Kotlin": 21950} | package com.ajithkumar.aoc2022
import com.ajithkumar.utils.*
import java.util.stream.IntStream
import kotlin.streams.toList
fun main() {
fun stringRangeToSet(stringRange: String): Set<Int> {
val rangeArr = stringRange.split("-").map(String::toInt)
val result = IntStream.rangeClosed(rangeArr[0], ra... | 0 | Kotlin | 0 | 0 | f95b8d1c3c8a67576eb76058a1df5b78af47a29c | 1,331 | advent-of-code-kotlin-template | Apache License 2.0 |
src/test/kotlin/be/brammeerten/y2022/Day24Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2022
import be.brammeerten.C
import be.brammeerten.gcd
import be.brammeerten.readFile
import be.brammeerten.toCharList
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import java.util.*
class Day24Test {
val DIRECTIONS = listOf(C(0, 0), C.LEFT, C.RIGHT, C.UP, C.DO... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 4,857 | Advent-of-Code | MIT License |
leetcode2/src/leetcode/n-th-tribonacci-number.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* 1137. 第 N 个泰波那契数
* https://leetcode-cn.com/problems/n-th-tribonacci-number/
* @program: leetcode
* @description: ${description}
* @author: hewking
* @create: 2019-10-23 10:40
* 泰波那契序列 Tn 定义如下:
T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
给你整数 n,请返回第 n 个泰波那契数 Tn 的值。
... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,700 | leetcode | MIT License |
src/day7/Solution.kt | chipnesh | 572,700,723 | false | {"Kotlin": 48016} | package day7
import day7.CMDLine.Command
import day7.CMDLine.Command.CD
import day7.CMDLine.Command.CD.Back
import day7.CMDLine.Command.CD.Root
import day7.CMDLine.Command.CD.To
import day7.CMDLine.Command.LS
import day7.CMDLine.Output
import day7.CMDLine.Output.DIR
import day7.CMDLine.Output.FileInfo
import readInput... | 0 | Kotlin | 0 | 1 | 2d0482102ccc3f0d8ec8e191adffcfe7475874f5 | 5,048 | AoC-2022 | Apache License 2.0 |
src/Day05.kt | Misano9699 | 572,108,457 | false | null | fun main() {
// list of stacks
var stacks: MutableList<MutableList<String>> = MutableList(9) { mutableListOf() }
// list of moves (number of elements to move, source stack, destination stack)
var moves: MutableList<List<Int>> = mutableListOf()
fun reset() {
// needs to be reset before eve... | 0 | Kotlin | 0 | 0 | adb8c5e5098fde01a4438eb2a437840922fb8ae6 | 3,489 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/tw/gasol/aoc/aoc2022/Day9.kt | Gasol | 574,784,477 | false | {"Kotlin": 70912, "Shell": 1291, "Makefile": 59} | package tw.gasol.aoc.aoc2022
import kotlin.math.absoluteValue
typealias Position = Pair<Int, Int>
class Day9 {
enum class Direction {
UP, DOWN, LEFT, RIGHT;
companion object {
fun fromString(str: String): Direction {
return when (str) {
"U" -> UP
... | 0 | Kotlin | 0 | 0 | a14582ea15f1554803e63e5ba12e303be2879b8a | 4,675 | aoc2022 | MIT License |
src/challenges/Day02.kt | paralleldynamic | 572,256,326 | false | {"Kotlin": 15982} | package challenges
import utils.readInput
fun main() {
fun part1(games: List<String>): Int = games
.map {
round -> when(round) {
"A X" -> 4
"A Y" -> 8
"A Z" -> 3
"B X" -> 1
"B Y" -> 5
"B Z" -> 9
... | 0 | Kotlin | 0 | 0 | ad32a9609b5ce51ac28225507f77618482710424 | 1,085 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/adventofcode/year2021/Day05HydrothermalVenture.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2021
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import kotlin.math.max
import kotlin.math.min
class Day05HydrothermalVenture(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val lines by lazy { input.lines().map { it.split(" -> ").map(Point::invoke) }.map(... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 1,997 | AdventOfCode | MIT License |
src/main/kotlin/DailyTemperatures.kt | Codextor | 453,514,033 | false | {"Kotlin": 26975} | /**
* Given an array of integers temperatures represents the daily temperatures,
* return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature.
* If there is no future day for which this is possible, keep answer[i] == 0 instead.
*
*
*
* Example ... | 0 | Kotlin | 1 | 0 | 68b75a7ef8338c805824dfc24d666ac204c5931f | 1,223 | kotlin-codes | Apache License 2.0 |
advent-of-code-2020/src/test/java/aoc/Day7HandyHaversacks.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | package aoc
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
class Day7HandyHaversacks {
@Test
fun silverTest() {
val parsed = parseBagPolicy(testInput)
assertThat(countAllPossibleParentsOfShinyGoldBag(parsed)).isEqualTo(4)
}
@Test
fun silver() {
val... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 48,292 | advent-of-code | MIT License |
src/day5/Day05.kt | ousa17 | 573,435,223 | false | {"Kotlin": 8095} | package day5
import readInput
val list1 = mutableListOf("S", "L", "W")
val list2 = mutableListOf("J", "T", "N", "Q")
val list3 = mutableListOf("S", "C", "H", "F", "J")
val list4 = mutableListOf("T", "R", "M", "W", "N", "G", "B")
val list5 = mutableListOf("T", "R", "L", "S", "D", "H", "Q", "B")
val list6 = mutableLi... | 0 | Kotlin | 0 | 0 | aa7f2cb7774925b7e88676a9ca64ca9548bce5b2 | 2,191 | advent-day-1 | Apache License 2.0 |
src/main/kotlin/com/oocode/PipesGrid.kt | ivanmoore | 725,978,325 | false | {"Kotlin": 42155} | package com.oocode
fun pipesGridFrom(input: String): PipesGrid {
val lines = input.split("\n")
val tiles = lines.mapIndexed { y, line ->
tilesFrom(y, line)
}
return PipesGrid(tiles)
}
data class PipesGrid(val tiles: List<List<Tile>>) {
fun furthestDistanceFromStart() = path().size / 2
... | 0 | Kotlin | 0 | 0 | 36ab66daf1241a607682e7f7a736411d7faa6277 | 4,397 | advent-of-code-2023 | MIT License |
src/cn/leetcode/codes/simple18/Simple18_2.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple18
import java.util.*
import kotlin.collections.ArrayList
class Simple18_2 {
fun fourSum(nums: IntArray, target: Int): List<List<Int>> {
val list = ArrayList<ArrayList<Int>>()
if (nums.size < 4) return list
//对数组进行排序
Arrays.sort(nums)
va... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 2,552 | LeetCodeSimple | Apache License 2.0 |
src/main/kotlin/tw/gasol/aoc/aoc2022/Day5.kt | Gasol | 574,784,477 | false | {"Kotlin": 70912, "Shell": 1291, "Makefile": 59} | package tw.gasol.aoc.aoc2022
import java.util.Scanner
class Day5 {
fun part1(input: String): String {
val stackBuilder = StringBuilder()
var stacks: List<ArrayDeque<Char>>? = null
input.lineSequence()
.forEach { line ->
if (stacks == null) {
... | 0 | Kotlin | 0 | 0 | a14582ea15f1554803e63e5ba12e303be2879b8a | 3,805 | aoc2022 | MIT License |
src/main/kotlin/day5.kt | tianyu | 574,561,581 | false | {"Kotlin": 49942} | import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isEqualTo
private fun main() {
val crateMover9000 = CargoCrane { stacks, count, from, to ->
stacks[to].append(stacks[from].unappend(count).reversed())
}
val crateMover9001 = CargoCrane { stacks, count, from, to ->
... | 0 | Kotlin | 0 | 0 | 6144cc0ccf1a51ba2e28c9f38ae4e6dd4c0dc1ea | 3,453 | AdventOfCode2022 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/AreOccurrencesEqual.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 | 1,564 | kotlab | Apache License 2.0 |
src/main/kotlin/calculations/Matrix.kt | J-MR-T | 359,117,393 | false | null | package calculations
import calculations.*
import kotlin.math.abs
private val Array<Array<Double>>.asNumberMatrix: Array<Array<out Number>>
get() {
return if (flatMap { doubles: Array<Double> -> doubles.asIterable() }
.all { d: Double -> d.toString().endsWith(".0") }) {
map { d... | 0 | Kotlin | 0 | 0 | 2295152b89fc2fd9f5a9a48db8c9655fea035451 | 12,803 | MatrixMultiplication | MIT License |
src/main/kotlin/day1/Solution.kt | krazyglitch | 573,086,664 | false | {"Kotlin": 31494} | package day1
import util.Utils
import java.time.Duration
import java.time.LocalDateTime
class Solution {
// Parse elves from input and find the elf with the highest calorie count
fun part1(input: List<String>): Int {
val elves = parseElves(input)
return elves.maxOf { e -> e.calorieCount }
... | 0 | Kotlin | 0 | 0 | db6b25f7668532f24d2737bc680feffc71342491 | 2,570 | advent-of-code2022 | MIT License |
src/Day05.kt | CrazyBene | 573,111,401 | false | {"Kotlin": 50149} | import java.util.*
fun main() {
data class Instruction(val from: Int, val to: Int, val repeat: Int = 1)
abstract class Crane {
abstract fun performInstruction(state: List<Stack<Char>>, instruction: Instruction)
}
class CrateMover9000 : Crane() {
override fun performInstruction(state: ... | 0 | Kotlin | 0 | 0 | dfcc5ba09ca3e33b3ec75fe7d6bc3b9d5d0d7d26 | 3,924 | AdventOfCode2022 | Apache License 2.0 |
src/Day10.kt | zirman | 572,627,598 | false | {"Kotlin": 89030} | fun main() {
fun part1(input: List<String>): Int {
return input
.scan(listOf(1)) { signals, line ->
val x = signals.last()
val s = line.split(" ")
when (s[0]) {
"addx" -> listOf(x, x + s[1].toInt())
"noop" -... | 0 | Kotlin | 0 | 1 | 2ec1c664f6d6c6e3da2641ff5769faa368fafa0f | 1,945 | aoc2022 | Apache License 2.0 |
WordSearch.kt | ncschroeder | 604,822,497 | false | {"Kotlin": 19399} | /*
https://leetcode.com/problems/word-search/
Given an m x n grid of characters `board` and a string `word`, return `true` if word exists in the grid.
The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally
or vertically neighboring. The same letter cell may not ... | 0 | Kotlin | 0 | 0 | c77d0c8bb0595e61960193fc9b0c7a31952e8e48 | 1,999 | Coding-Challenges | MIT License |
src/Day06.kt | andrikeev | 574,393,673 | false | {"Kotlin": 70541, "Python": 18310, "HTML": 5558} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { line ->
var marker = 0
for (i in 0..line.lastIndex - 3) {
if (line.subSequence(i, i + 4).toSet().size == 4) {
marker = i + 4
break
}
... | 0 | Kotlin | 0 | 1 | 1aedc6c61407a28e0abcad86e2fdfe0b41add139 | 994 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/io/github/lawseff/aoc2023/optimization/WinStrategyCounter.kt | lawseff | 573,226,851 | false | {"Kotlin": 37196} | package io.github.lawseff.aoc2023.optimization
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.sqrt
class WinStrategyCounter {
companion object {
private const val MINUS_ONE = -1.0
}
fun countWinStrategies(race: Race): Long {
val minDistanceToWin = race.recordDistance... | 0 | Kotlin | 0 | 0 | b60ab611aec7bb332b8aa918aa7c23a43a3e61c8 | 2,723 | advent-of-code-2023 | MIT License |
src/main/kotlin/day13/Day13.kt | jankase | 573,187,696 | false | {"Kotlin": 70242} | package day13
import Day
import safeTimes
import solve
typealias Signal = List<Any>
class Day13 : Day(13, 2022, "Distress Signal") {
override fun part1(): Int {
val signalGroups = inputAsGroups.map { (firstSetOfSignals, secondSetOfSignals) ->
Pair(firstSetOfSignals.toSignal(), secondSetOfSign... | 0 | Kotlin | 0 | 0 | 0dac4ec92c82a5ebb2179988fb91fccaed8f800a | 3,678 | adventofcode2022 | Apache License 2.0 |
puzzles/src/main/kotlin/com/kotlinground/puzzles/search/binarysearch/searchrotatedsortedarray/rotatedSortedArray.kt | BrianLusina | 113,182,832 | false | {"Kotlin": 483489, "Shell": 7283, "Python": 1725} | package com.kotlinground.puzzles.search.binarysearch.searchrotatedsortedarray
fun search(nums: IntArray, target: Int): Int {
var left = 0
var right = nums.size - 1
while (left <= right) {
val middle = (left + right) / 2
if (nums[middle] == target) {
return middle
}
... | 1 | Kotlin | 1 | 0 | 5e3e45b84176ea2d9eb36f4f625de89d8685e000 | 3,954 | KotlinGround | MIT License |
src/main/kotlin/be/inniger/euler/problems01to10/Problem09.kt | bram-inniger | 135,620,989 | false | {"Kotlin": 20003} | package be.inniger.euler.problems01to10
private const val TRIPLET_SUM = 1000
/**
* Special Pythagorean triplet
*
* A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
* a^2 + b^2 = c^2
* For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
* There exists exactly one Pythagorean triplet for whi... | 0 | Kotlin | 0 | 0 | 8fea594f1b5081a824d829d795ae53ef5531088c | 775 | euler-kotlin | MIT License |
2023/src/main/kotlin/day13.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Grid
import utils.Parser
import utils.Solution
import utils.mapItems
import utils.flipAxis
fun main() {
Day13.run()
}
object Day13 : Solution<List<Grid<Char>>>() {
override val name = "day13"
override val parser = Parser.blocks.mapItems { Parser.charGrid(it) }
private fun reflects(g: Grid<Char>,... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 843 | aoc_kotlin | MIT License |
src/questions/MinTotalInTriangle.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
import kotlin.math.min
/**
* Given a triangle array, return the minimum path sum from top to bottom.
* For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the
* current row, you ... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 1,660 | algorithms | MIT License |
2023/src/main/kotlin/day4.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parse
import utils.Parser
import utils.Solution
import utils.mapItems
import utils.pow2
fun main() {
Day4.run(skipTest = false)
}
object Day4 : Solution<List<Day4.Card>>() {
override val name = "day4"
override val parser = Parser.lines.mapItems { parseCard(it) }
@Parse("Card {id}: {r ' ' winning... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,115 | aoc_kotlin | MIT License |
src/main/kotlin/cz/tomasbublik/Day06.kt | tomasbublik | 572,856,220 | false | {"Kotlin": 21908} | package cz.tomasbublik
import java.util.LinkedList
import java.util.Queue
fun String.allUnique(): Boolean = all(hashSetOf<Char>()::add)
fun Queue<Char>.allUnique(): Boolean = all(hashSetOf<Char>()::add)
fun main() {
fun allCharsDifferent(nums: Queue<Char>): Boolean {
return nums.allUnique()
}
fun... | 0 | Kotlin | 0 | 0 | 8c26a93e8f6f7ab0f260c75a287608dd7218d0f0 | 1,778 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day04.kt | thomasreader | 573,047,664 | false | {"Kotlin": 59975} | import java.io.Reader
fun main() {
val testInput = """
2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8
""".trimIndent()
check(partOne(testInput.reader()) == 2)
val input = file("Day04.txt")
println(partOne(input.bufferedReader()))
check(partTw... | 0 | Kotlin | 0 | 0 | eff121af4aa65f33e05eb5e65c97d2ee464d18a6 | 1,391 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/algorithms/PopularChaAlgorithm.kt | aaronoe | 186,243,764 | false | null | package de.aaronoe.algorithms
import de.aaronoe.models.Seminar
import de.aaronoe.models.Student
import org.jgrapht.alg.matching.HopcroftKarpMaximumCardinalityBipartiteMatching
import org.jgrapht.graph.DefaultEdge
import org.jgrapht.graph.SimpleGraph
object PopularChaAlgorithm : StudentMatchingAlgorithm {
overrid... | 0 | Kotlin | 0 | 1 | 8265e6553aca23c3bf2c5236ba56d46ab7e2b3f3 | 4,061 | matching_server | MIT License |
atcoder/arc159/c.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package atcoder.arc159
fun main() {
readInt()
val a = readInts().toIntArray()
val ans = mutableListOf<IntArray>()
fun apply(p: IntArray) {
for (i in a.indices) a[i] += p[i]
ans.add(p)
}
var sumOk = false
for (j in a.indices) {
if (a.sum() % a.size == 0) {
sumOk = true
break
}
val b = a.indices... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,236 | competitions | The Unlicense |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[74]搜索二维矩阵.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:
//
//
// 每行中的整数从左到右按升序排列。
// 每行的第一个整数大于前一行的最后一个整数。
//
//
//
//
// 示例 1:
//
//
//输入:matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
//输出:true
//
//
// 示例 2:
//
//
//输入:matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
//输出:false
//
//
// ... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,853 | MyLeetCode | Apache License 2.0 |
src/Day01.kt | AxelUser | 572,845,434 | false | {"Kotlin": 29744} | fun main() {
fun List<String>.calcSums(): List<Int> {
val sums = mutableListOf<Int>()
sums.add(0)
for (line in this) {
if (line == "") {
sums.add(0)
} else {
sums[sums.lastIndex] += line.toInt()
}
}
return su... | 0 | Kotlin | 0 | 1 | 042e559f80b33694afba08b8de320a7072e18c4e | 790 | aoc-2022 | Apache License 2.0 |
src/day01/Day01.kt | palpfiction | 572,688,778 | false | {"Kotlin": 38770} | package day01
import readInput
fun main() {
data class Elf(val calories: Int)
fun parseElves(input: List<String>): List<Elf> {
val elves = mutableListOf<Elf>()
var currentElf = Elf(0)
input.forEach {
when {
it.isEmpty() -> elves.add(currentElf.copy()).also... | 0 | Kotlin | 0 | 0 | 5b79ec5fa4116e496cd07f0c7cea7dabc8a371e7 | 1,053 | advent-of-code | Apache License 2.0 |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day07.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwenty
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
class Day07 : Day<Long> {
private val containerRegex = Regex("^([a-z ]+) bags contain .+$")
private val contentsRegex = Regex(" ([0-9]+) ([a-z ]+) bags?[,.]")
private val rules = readDayInp... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 2,430 | adventofcode | Apache License 2.0 |
src/Day02.kt | pejema | 576,456,995 | false | {"Kotlin": 7994} | import kotlin.streams.toList
fun main() {
fun getPointsPart1(elfShape: String, myShape: String) : Int {
var points = 0
if (elfShape == "A" && myShape == "X") {
points = 1 + 3
} else if (elfShape == "A" && myShape == "Y") {
points = 2 + 6
} else if (elfShape =... | 0 | Kotlin | 0 | 0 | b2a06318f0fcf5c6067058755a44e5567e345e0c | 3,282 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/github/michaelbull/advent/day4/Day4.kt | michaelbull | 225,205,583 | false | null | package com.github.michaelbull.advent.day4
fun readRange(): IntRange {
return ClassLoader.getSystemResourceAsStream("day4.txt")
.bufferedReader()
.readLine()
.split("-")
.map(String::toInt)
.let { IntRange(it[0], it[1]) }
}
fun IntRange.validPasswords(criteria: (Int) -> Boo... | 0 | Kotlin | 0 | 2 | d271a7c43c863acd411bd1203a93fd10485eade6 | 1,863 | advent-2019 | ISC License |
src/main/kotlin/Puzzle11.kt | namyxc | 317,466,668 | false | null | object Puzzle11 {
@JvmStatic
fun main(args: Array<String>) {
val input = Puzzle11::class.java.getResource("puzzle11.txt").readText()
val calculateOccupiedSeats = calculateOccupiedSeats(input, Puzzle11::countImmediatelyAdjacentSeats, 4)
println(calculateOccupiedSeats)
val calc... | 0 | Kotlin | 0 | 0 | 60fa6991ac204de6a756456406e1f87c3784f0af | 3,868 | adventOfCode2020 | MIT License |
src/main/kotlin/Day06.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("Almanac not specified")
exitProcess(1)
}
val fileName = args.first()
println("Reading $fileName")
val lines = readLines(fileName).toList()
val result =
if ... | 0 | Kotlin | 0 | 0 | d9ce83ee89db7081cf7c14bcad09e1348d9059cb | 1,665 | adventofcode2023 | MIT License |
leetcode2/src/leetcode/find-all-numbers-disappeared-in-an-array.kt | hewking | 68,515,222 | false | null | package leetcode
import java.util.*
/**448. 找到所有数组中消失的数字
* https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/
* Created by test
* Date 2019/7/17 0:56
* Description
*给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次。
找到所有在 [1, n] 范围之间没有出现在数组中的数字。
您能在不使用额外空间且时间复杂度为O(n)的情况下完... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,638 | leetcode | MIT License |
2022/23/23.kt | LiquidFun | 435,683,748 | false | {"Kotlin": 40554, "Python": 35985, "Julia": 29455, "Rust": 20622, "C++": 1965, "Shell": 1268, "APL": 191} | typealias Point = Pair<Int, Int>
val DIRS8 = listOf(-1 to -1, -1 to 0, -1 to 1, 0 to 1, 1 to 1, 1 to 0, 1 to -1, 0 to -1)
val DIRS = mutableListOf(
listOf(DIRS8[0], DIRS8[1], DIRS8[2]), // N
listOf(DIRS8[4], DIRS8[5], DIRS8[6]), // S
listOf(DIRS8[6], DIRS8[7], DIRS8[0]), // E
listOf(DI... | 0 | Kotlin | 7 | 43 | 7cd5a97d142780b8b33b93ef2bc0d9e54536c99f | 1,836 | adventofcode | Apache License 2.0 |
src/Day01.kt | pavlo-dh | 572,882,309 | false | {"Kotlin": 39999} | fun main() {
fun calculateElvesCalories(input: List<String>): List<Int> {
val elvesCalories = arrayListOf<Int>()
var currentElfCalories = 0
input.forEach {
if (it.isEmpty()) {
elvesCalories.add(currentElfCalories)
currentElfCalories = 0
... | 0 | Kotlin | 0 | 2 | c10b0e1ce2c7c04fbb1ad34cbada104e3b99c992 | 1,040 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/aoc/Day9.kt | dtsaryov | 573,392,550 | false | {"Kotlin": 28947} | package aoc
import kotlin.math.abs
import kotlin.math.hypot
/**
* [AoC 2022: Day 9](https://adventofcode.com/2022/day/9)
*/
fun getRopeTailPositionsCount(moves: List<String>, length: Int): Int {
val points = IntRange(0, length - 1)
.map { Point(1, 1) }
.toTypedArray()
var head: Point
va... | 0 | Kotlin | 0 | 0 | 549f255f18b35e5f52ebcd030476993e31185ad3 | 2,757 | aoc-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.