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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Problems/Algorithms/417. Pacific Atlantic Water Flow/PacificAtlantic.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 {
private val neighbors: Array<IntArray> = arrayOf(intArrayOf(0, 1), intArrayOf(0, -1), intArrayOf(1, 0), intArrayOf(-1, 0))
fun pacificAtlantic(heights: Array<IntArray>): List<List<Int>> {
val n = heights.size
val m = heights[0].size
val reachableAtlantic: A... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 1,762 | leet-code | MIT License |
src/Day04.kt | MarkRunWu | 573,656,261 | false | {"Kotlin": 25971} | import java.lang.Math.abs
fun main() {
fun parseSectionsAssignments(input: List<String>): List<List<Pair<Int, Int>>> {
return input.map { it ->
it.split(',')
.map {
val pairs = it.split('-')
Pair(pairs[0].toInt(), pairs[1].toInt())
... | 0 | Kotlin | 0 | 0 | ced885dcd6b32e8d3c89a646dbdcf50b5665ba65 | 988 | AOC-2022 | Apache License 2.0 |
ceria/24/src/main/kotlin/Solution.kt | VisionistInc | 317,503,410 | false | null | import java.io.File
val tokenMap = mapOf<String, Pair<Int, Int>>(
"e" to Pair(2, 0),
"w" to Pair(-2, 0),
"se" to Pair(1, -1),
"sw" to Pair(-1, -1),
"ne" to Pair(1, 1),
"nw" to Pair(-1, 1)
)
fun main(args : Array<String>) {
val input = File(args.first()).readLines()
println("Solution 1: ${sol... | 0 | Rust | 0 | 0 | 002734670384aa02ca122086035f45dfb2ea9949 | 3,498 | advent-of-code-2020 | MIT License |
src/aoc2022/Day13.kt | NoMoor | 571,730,615 | false | {"Kotlin": 101800} | @file:Suppress("UNCHECKED_CAST")
package aoc2022
import utils.*
import java.rmi.UnexpectedException
import kotlin.math.min
private class Day13(val lines: List<String>) {
val pairs = lines.filter { it.isNotEmpty() }
.map { parseList(it).first }
/**
* Recursively parses a list where each element is a sub-... | 0 | Kotlin | 1 | 2 | d561db73c98d2d82e7e4bc6ef35b599f98b3e333 | 3,303 | aoc2022 | Apache License 2.0 |
app/src/y2021/day17/Day17TrickShot.kt | henningBunk | 432,858,990 | false | {"Kotlin": 124495} | package y2021.day17
import common.*
import common.annotations.AoCPuzzle
import helper.Point
import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.sign
fun main(args: Array<String>) {
Day17TrickShot().solveThem()
}
@AoCPuzzle(2021, 17)
class Day17TrickShot : AocSolution {
override val ans... | 0 | Kotlin | 0 | 0 | 94235f97c436f434561a09272642911c5588560d | 2,828 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/Day7.kt | amitdev | 574,336,754 | false | {"Kotlin": 21489} | import java.nio.file.Path
fun fileSizeToDelete(lines: Sequence<String>) = directorySizes(lines).smallestFileToDelete()
fun fileSize(lines: Sequence<String>) =
directorySizes(lines).directorySizes.values
.filter { it <=100000 }
.sum()
private fun directorySizes(lines: Sequence<String>) =
lines.fold(Direct... | 0 | Kotlin | 0 | 0 | b2cb4ecac94fdbf8f71547465b2d6543710adbb9 | 1,480 | advent_2022 | MIT License |
src/Day14.kt | underwindfall | 573,471,357 | false | {"Kotlin": 42718} | fun main() {
val dayId = "14"
val input = readInput("Day${dayId}")
data class P(val x: Int, val y: Int)
val ps = input.map { s ->
s.split(" -> ").map { t ->
val (x, y) = t.split(",").map { it.toInt() }
P(x, y)
}
}
val pf = ps.flatten() + P(500, 0)
val ... | 0 | Kotlin | 0 | 0 | 0e7caf00319ce99c6772add017c6dd3c933b96f0 | 1,604 | aoc-2022 | Apache License 2.0 |
src/Day04.kt | jorander | 571,715,475 | false | {"Kotlin": 28471} | fun main() {
val day = "Day04"
fun assignmentsAsIntRanges(assignments: String) = assignments.split(",")
.map { it.split("-") }
.map { (firstSection, lastSection) -> firstSection.toInt()..lastSection.toInt() }
fun part1(input: List<String>): Int {
return input.map(::assignmentsAsIn... | 0 | Kotlin | 0 | 0 | 1681218293cce611b2c0467924e4c0207f47e00c | 1,146 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/com/github/jntakpe/aoc2021/days/day5/Day5.kt | jntakpe | 433,584,164 | false | {"Kotlin": 64657, "Rust": 51491} | package com.github.jntakpe.aoc2021.days.day5
import com.github.jntakpe.aoc2021.shared.Day
import com.github.jntakpe.aoc2021.shared.readInputLines
import kotlin.math.abs
object Day5 : Day {
override val input = readInputLines(5).map { it.split("->").parseLine() }
override fun part1() = input.flatMap { it.str... | 0 | Kotlin | 1 | 5 | 230b957cd18e44719fd581c7e380b5bcd46ea615 | 2,077 | aoc2021 | MIT License |
src/Day05.kt | adrianforsius | 573,044,406 | false | {"Kotlin": 68131} | import org.assertj.core.api.Assertions.assertThat
fun main() {
fun part1(input: String): String {
val parts = input.split("\n\n")
val crates = parts[0].split("\n").map {
it.toCharArray().filterIndexed { index, c -> ((index-1)%4) == 0 }
}
var stacks: List<ArrayDeque<Cha... | 0 | Kotlin | 0 | 0 | f65a0e4371cf77c2558d37bf2ac42e44eeb4bdbb | 3,273 | kotlin-2022 | Apache License 2.0 |
src/aoc23/Day12.kt | mihassan | 575,356,150 | false | {"Kotlin": 123343} | @file:Suppress("PackageDirectoryMismatch")
package aoc23.day12
import lib.Collections.headTail
import lib.Solution
import lib.Strings.extractInts
data class ConditionRecord(val conditions: String, val groups: List<Int>) {
fun unfold(times: Int): ConditionRecord {
val newConditions = List(times) { conditions }.... | 0 | Kotlin | 0 | 0 | 698316da8c38311366ee6990dd5b3e68b486b62d | 2,909 | aoc-kotlin | Apache License 2.0 |
src/main/kotlin/at/mpichler/aoc/solutions/year2021/Day20.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2021
import at.mpichler.aoc.lib.Day
import at.mpichler.aoc.lib.PartSolution
open class Part20A : PartSolution() {
private lateinit var lut: List<Int>
private lateinit var image: List<List<Int>>
open val numRounds = 2
override fun parseInput(text: String) {
... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 2,233 | advent-of-code-kotlin | MIT License |
src/main/aoc2022/Day18.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2022
class Day18(input: List<String>) {
private data class Pos3D(val x: Int, val y: Int, val z: Int) {
fun allNeighbours() = listOf(
Pos3D(x, y, z - 1),
Pos3D(x, y, z + 1),
Pos3D(x, y + 1, z),
Pos3D(x, y - 1, z),
Pos3D(x + 1, y, z),
... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,907 | aoc | MIT License |
2019/src/test/kotlin/Day12.kt | jp7677 | 318,523,414 | false | {"Kotlin": 171284, "C++": 87930, "Rust": 59366, "C#": 1731, "Shell": 354, "CMake": 338} | import kotlin.math.abs
import kotlin.test.Test
import kotlin.test.assertEquals
class Day12 {
data class Vector(val x: Int, val y: Int, val z: Int) {
operator fun plus(other: Vector) = Vector(x + other.x, y + other.y, z + other.z)
fun energy(): Int = abs(x) + abs(y) + abs(z)
}
data class Mo... | 0 | Kotlin | 1 | 2 | 8bc5e92ce961440e011688319e07ca9a4a86d9c9 | 2,467 | adventofcode | MIT License |
src/day10/Day10.kt | diesieben07 | 572,879,498 | false | {"Kotlin": 44432} | package day10
import streamInput
import java.lang.StringBuilder
private val file = "Day10"
//private val file = "Day10Example"
private sealed interface Instruction {
fun decompose(): Sequence<Instruction>
fun nextState(state: CpuState): CpuState
object NOOP : Instruction {
override fun decompo... | 0 | Kotlin | 0 | 0 | 0b9993ef2f96166b3d3e8a6653b1cbf9ef8e82e6 | 2,378 | aoc-2022 | Apache License 2.0 |
src/questions/LetterCombinationsOfPhoneNumber.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.assertIterableSameInAnyOrder
/**
* Given a string containing digits from 2-9 inclusive, return all possible
* letter combinations that the number could represent. Return the answer in any order.
* A mapping of digit to letters (just like on the... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,774 | algorithms | MIT License |
src/day03/Day03.kt | Mini-Stren | 573,128,699 | false | null | package day03
import readInputLines
fun main() {
val day = 3
fun part1(input: List<String>): Int {
return input.sumOf { line ->
line.chunked(line.length / 2, CharSequence::toSet)
.let { it[0] intersect it[1] }
.first()
.let(Char::priority)
... | 0 | Kotlin | 0 | 0 | 40cb18c29089783c9b475ba23c0e4861d040e25a | 1,023 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/days/Day20.kt | andilau | 399,220,768 | false | {"Kotlin": 85768} | package days
import days.Day20.Orientation.*
@AdventOfCodePuzzle(
name = "<NAME>",
url = "https://adventofcode.com/2020/day/20",
date = Date(day = 20, year = 2020)
)
class Day20(input: String) : Puzzle {
private val tiles: List<Tile> = readTiles(input)
private val seaMonster: Set<Point> = getMonst... | 7 | Kotlin | 0 | 0 | 2809e686cac895482c03e9bbce8aa25821eab100 | 7,436 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/Day13.kt | a2xchip | 573,197,744 | false | {"Kotlin": 37206} | import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.*
import java.io.File
class SignalPacket(val data: JsonArray) : Comparable<SignalPacket> {
private fun compare(a: JsonElement, b: JsonElement): Int {
when (Pair(a !is JsonArray, b !is JsonArray)) {
true to true -> {... | 0 | Kotlin | 0 | 2 | 19a97260db00f9e0c87cd06af515cb872d92f50b | 3,029 | kotlin-advent-of-code-22 | Apache License 2.0 |
src/main/kotlin/com/ryanmoelter/advent/day01/Calories.kt | ryanmoelter | 573,615,605 | false | {"Kotlin": 84397} | package com.ryanmoelter.advent.day01
fun main() {
println(countTopCalories(day01Input, 3))
}
fun countTopCalories(input: String, numberOfDwarfs: Int): Int {
var heaviestDwarves = emptyList<Int>()
var currentDwarf = 0
input.lines().forEach { line ->
if (line.isNotBlank()) {
currentDwarf += line.toInt... | 0 | Kotlin | 0 | 0 | aba1b98a1753fa3f217b70bf55b1f2ff3f69b769 | 1,328 | advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | jordanfarrer | 573,120,618 | false | {"Kotlin": 20954} | fun main() {
val day = "Day04"
fun isFullyContained(sectionPairs: List<Int>): Boolean {
val (firstStart, firstEnd, secondStart, secondEnd) = sectionPairs
return (firstStart >= secondStart && firstEnd <= secondEnd) || (secondStart >= firstStart && secondEnd <= firstEnd)
}
fun hasOverlap... | 0 | Kotlin | 0 | 1 | aea4bb23029f3b48c94aa742958727d71c3532ac | 1,319 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day05.kt | kent10000 | 573,114,356 | false | {"Kotlin": 11288} | fun main() {
fun loadStacks(input: List<String>): List<MutableList<Char>> {
var stacks = input.subList(0, input.indexOf(String()))
val num = stacks.last().dropLastWhile { !it.isDigit() }.last().digitToInt()
stacks = stacks.dropLast(1)
val list: List<MutableList<Char>> = List(nu... | 0 | Kotlin | 0 | 0 | c128d05ab06ecb2cb56206e22988c7ca688886ad | 2,494 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/advent/Advent3.kt | v3rm0n | 225,866,365 | false | null | package advent
import kotlin.math.abs
class Advent3 : Advent {
override fun firstTask(input: List<String>) =
intersections(wires(input)).map { (x, y) -> abs(0 - x) + abs(0 - y) }.min() ?: "Not found!"
override fun secondTask(input: List<String>) = wires(input).let { (first, second) ->
inters... | 0 | Kotlin | 0 | 1 | 5c36cb254100f80a6e9c16adff5e7aadc8c9e98f | 1,696 | aoc2019 | MIT License |
src/Day17.kt | shepard8 | 573,449,602 | false | {"Kotlin": 73637} | fun main() {
class Rock(val x: Long, val y: Long) {
override fun toString(): String {
return "($x, $y)"
}
}
class Map {
private val rocks = mutableListOf<Rock>()
private var highest = 0L
fun add(block: List<Rock>) {
rocks.addAll(block)
... | 0 | Kotlin | 0 | 1 | 81382d722718efcffdda9b76df1a4ea4e1491b3c | 5,446 | aoc2022-kotlin | Apache License 2.0 |
src/Day05.kt | Kietyo | 573,293,671 | false | {"Kotlin": 147083} |
fun main() {
fun part1(input: List<String>): Unit {
// val stacks = listOf(
// "ZN", "MCD", "P"
// ).map { it.toMutableList() }
val stacks = listOf(
"BZT", "VHTDN", "BFMD", "TJGWVQL", "WDGPVFQM", "VZQGHFS", "ZSNRLTCW", "ZHWDJNRM", "MQLFDS"
).map { it.toMutable... | 0 | Kotlin | 0 | 0 | dd5deef8fa48011aeb3834efec9a0a1826328f2e | 2,100 | advent-of-code-2022-kietyo | Apache License 2.0 |
src/Day07.kt | dyomin-ea | 572,996,238 | false | {"Kotlin": 21309} | fun main() {
val cd = "\\$ cd (.+)".toRegex()
val dir = "dir (.+)".toRegex()
val file = "(\\d+) (.+)".toRegex()
val ls = "\\$ ls".toRegex()
fun EditableDir.dir(name: String): EditableDir =
object : EditableDir {
override val children = mutableListOf<Node>()
override val parent
get() = this@dir
ov... | 0 | Kotlin | 0 | 0 | 8aaf3f063ce432207dee5f4ad4e597030cfded6d | 3,083 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem2306/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2306
/**
* LeetCode page: [2306. Naming a Company](https://leetcode.com/problems/naming-a-company/);
*/
class Solution {
/* Complexity:
* Time O(L) and Space O(L) where L is the flat length of ideas;
*/
fun distinctNames(ideas: Array<String>): Long {
va... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,844 | hj-leetcode-kotlin | Apache License 2.0 |
src/day10/Day10.kt | JakubMosakowski | 572,993,890 | false | {"Kotlin": 66633} | package day10
import readInput
private fun main() {
fun part1(input: List<String>): Int {
val cycles = input.toCycles()
val importantCycles = listOf(20, 60, 100, 140, 180, 220)
return importantCycles.sumOf { index -> index * cycles[index - 1] }
}
fun part2(input: List<String>) {
... | 0 | Kotlin | 0 | 0 | f6e9a0b6c2b66c28f052d461c79ad4f427dbdfc8 | 1,344 | advent-of-code-2022 | Apache License 2.0 |
src/day2/day2.kt | bienenjakob | 573,125,960 | false | {"Kotlin": 53763} | package day2
import day2.Hand.*
import day2.Outcome.*
import inputTextOfDay
import testTextOfDay
enum class Hand(val value: Int) {
Rock(1), Paper(2), Scissors(3)
}
enum class Outcome(val value: Int) {
Loose(0), Draw(3), Win(6)
}
fun part1(text: String): Int {
return text.lines().sumOf { evaluate(toHand(... | 0 | Kotlin | 0 | 0 | 6ff34edab6f7b4b0630fb2760120725bed725daa | 1,806 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/day3/Part2.kts | holmesdev | 726,678,749 | false | {"Kotlin": 9531} | import java.io.File
val partNumberRegex = Regex("\\d+")
val partRegex = Regex("\\*")
data class PartNumber(val partNumber: Int, val range: IntRange)
fun getPartNumbers(line: String): List<PartNumber> {
return partNumberRegex.findAll(line).map { PartNumber(it.value.toInt(), it.range) }.toList()
}
fun getParts(li... | 0 | Kotlin | 0 | 0 | 6098b7e304e3e388467168a69d51c281035c04db | 2,422 | advent-2023 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/PermutationInString.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <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 | 5,143 | kotlab | Apache License 2.0 |
src/main/kotlin/advent2019/day4/day4.kt | davidpricedev | 225,621,794 | false | null | package advent2019.day4
fun main() {
runRangePart1(264360, 746325)
runRangePart2(264360, 746325)
}
fun runRangePart1(start: Int, end: Int) =
println((start..end).filter(::filterPart1).count())
fun runRangePart2(start: Int, end: Int) =
println((start..end).filter(::filterPart2).count())
fun filterPar... | 0 | Kotlin | 0 | 0 | 2283647e5b4ed15ced27dcf2a5cf552c7bd49ae9 | 980 | adventOfCode2019 | Apache License 2.0 |
src/day09/Day09ToddGinsbergSolution.kt | commanderpepper | 574,647,779 | false | {"Kotlin": 44999} | package day09
import readInput
import kotlin.math.absoluteValue
import kotlin.math.sign
// I was unable to solve part two of day nine, so I am using Todd's solution to learn more about the problem
// His solution https://todd.ginsberg.com/post/advent-of-code/2022/day9/
fun main(){
val input = readInput("day09")
... | 0 | Kotlin | 0 | 0 | fef291c511408c1a6f34a24ed7070ceabc0894a1 | 2,249 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day05/Day05.kt | scottpeterson | 573,109,888 | false | {"Kotlin": 15611} | fun main() {
data class Move(val count: Int, val from: Int, val to: Int)
fun parseInput(stringInput: List<String>): Pair<List<MutableList<Char>>, List<Move>> {
val blankLineIndex = stringInput.indexOfFirst(String::isBlank)
val crateCount = stringInput[blankLineIndex - 1]
.last(Cha... | 0 | Kotlin | 0 | 0 | 0d86213c5e0cd5403349366d0f71e0c09588ca70 | 1,959 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day24.kt | Yeah69 | 317,335,309 | false | {"Kotlin": 73241} | class Day24 : Day() {
override val label: String get() = "24"
private enum class Direction { EAST, SOUTHEAST, SOUTHWEST, WEST, NORTHWEST, NORTHEAST }
private val initialBlackTiles by lazy { input
.lineSequence()
.map {
var rest = it
val instructions = mutableListOf<... | 0 | Kotlin | 0 | 0 | 23121ede8e3e8fc7aa1e8619b9ce425b9b2397ec | 2,926 | AdventOfCodeKotlin | The Unlicense |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2015/2015-13.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2015
import com.github.ferinagy.adventOfCode.TspGraph
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
fun main() {
val input = readInputLines(2015, "13-input")
val test1 = readInputLines(2015, "13-test1")
p... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,383 | advent-of-code | MIT License |
games-impl/src/commonMain/kotlin/net/zomis/games/common/cards/probabilities/CardProbabilityUtils.kt | Zomis | 125,767,793 | false | {"Kotlin": 1346310, "Vue": 212095, "JavaScript": 43020, "CSS": 4513, "HTML": 1459, "Shell": 801, "Dockerfile": 348} | package net.zomis.games.cards.probabilities
enum class CountStyle {
EQUAL, NOT_EQUAL, MORE_THAN, LESS_THAN, UNKNOWN, DONE
}
object Combinatorics {
fun NNKKnoDiv(N: Int, n: Int, K: Int, k: Int): Double {
return nCr(K, k) * nCr(N - K, n - k)
}
fun NNKKdistribution(N: Int, n: Int, K: Int): Doubl... | 89 | Kotlin | 5 | 17 | dd9f0e6c87f6e1b59b31c1bc609323dbca7b5df0 | 2,913 | Games | MIT License |
src/day02/Day02_Part2.kt | m-jaekel | 570,582,194 | false | {"Kotlin": 13764} | package day02
import readInput
fun main() {
/**
* X -> lose
* Y -> draw
* Z -> win
*/
fun part2(input: List<String>): Int {
var score = 0
input.forEach {
val shapes: List<String> = it.chunked(1)
val round = playRound(shapes[0], shapes[2])
... | 0 | Kotlin | 0 | 1 | 07e015c2680b5623a16121e5314017ddcb40c06c | 1,306 | AOC-2022 | Apache License 2.0 |
src/main/kotlin/kr/co/programmers/P160585.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://github.com/antop-dev/algorithm/issues/506
class P160585 {
fun solution(board: Array<String>): Int {
val (oCount, oWin) = check(board, 'O')
val (xCount, xWin) = check(board, 'X')
return when {
// "O"나 "X"의 개수 차이가 나면 안된다.
oCount - x... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,835 | algorithm | MIT License |
src/y2022/Day24.kt | gaetjen | 572,857,330 | false | {"Kotlin": 325874, "Mermaid": 571} | package y2022
import util.Cardinal
import util.Cardinal.EAST
import util.Cardinal.NORTH
import util.Cardinal.SOUTH
import util.Cardinal.WEST
import util.Cardinal.values
import util.Pos
import util.printGrid
import util.readInput
import kotlin.system.measureTimeMillis
object Day24 {
data class Blizzard(val pos: Po... | 0 | Kotlin | 0 | 0 | d0b9b5e16cf50025bd9c1ea1df02a308ac1cb66a | 3,668 | advent-of-code | Apache License 2.0 |
day23/src/main/kotlin/Day23.kt | bzabor | 160,240,195 | false | null | import kotlin.math.abs
class Day23(private val input: List<String>) {
// pos=<0,0,0>, r=4
// pos=<1,0,0>, r=1
// pos=<4,0,0>, r=3
// pos=<0,2,0>, r=1
// pos=<0,5,0>, r=3
// pos=<0,0,3>, r=1
// pos=<1,1,1>, r=1
// pos=<1,1,2>, r=1
// pos=<1,3,1>, r=1
// [, 0, 0, 0, 4]
// [, 1, 0, 0, 1... | 0 | Kotlin | 0 | 0 | 14382957d43a250886e264a01dd199c5b3e60edb | 1,907 | AdventOfCode2018 | Apache License 2.0 |
2021/src/main/kotlin/Day14.kt | eduellery | 433,983,584 | false | {"Kotlin": 97092} | class Day14(val input: List<String>) {
private val template = input[0]
private val rules = input[1].split("\n").groupBy({ it.substringBefore(" -> ") }, { it.substringAfter(" -> ") })
.mapValues { it.value.single() }
private fun transform(steps: Int): Long {
val initial = template.windowed(... | 0 | Kotlin | 0 | 1 | 3e279dd04bbcaa9fd4b3c226d39700ef70b031fc | 1,203 | adventofcode-2021-2025 | MIT License |
2022/src/day07/Day07.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day07
import java.io.File
fun main() {
val input = File("src/day07/day07input.txt").readLines()
val parser = FileSystemParser(input)
parser.processCommands()
val node = parser.getRootNode()
println(getSumDirectoriesAtMost(node as FolderNode, 100000))
println(getCandidateDir(node as Fol... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 5,562 | adventofcode | Apache License 2.0 |
src/main/kotlin/Day3.kt | FredrikFolkesson | 320,692,155 | false | null | class Day3 {
fun getNumberOfTrees(input: List<String>, right: Int, down: Int): Int {
val sizeOfOneLine = input[0].length
return input.filterIndexed { index, it -> index % down == 0 && it[((right / down.toDouble()) * index).toInt() % sizeOfOneLine] == '#' }
.count()
}
}
fun numberO... | 0 | Kotlin | 0 | 0 | 79a67f88e1fcf950e77459a4f3343353cfc1d48a | 941 | advent-of-code | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1162/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1162
/**
* LeetCode page: [1162. As Far from Land as Possible](https://leetcode.com/problems/as-far-from-land-as-possible/);
*/
class Solution {
/* Complexity:
* Time O(N^2) and Space O(N^2) where N is the size of grid;
*/
fun maxDistance(grid: Array<IntArray>)... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,382 | hj-leetcode-kotlin | Apache License 2.0 |
src/day9/Day09.kt | JoeSkedulo | 573,328,678 | false | {"Kotlin": 69788} | package day9
import Runner
import day9.Direction.*
import kotlin.math.abs
fun main() {
Day9Runner().solve()
}
class Day9Runner : Runner<Int>(
day = 9,
expectedPartOneTestAnswer = 13,
expectedPartTwoTestAnswer = 1
) {
override fun partOne(input: List<String>, test: Boolean): Int {
return ... | 0 | Kotlin | 0 | 0 | bd8f4058cef195804c7a057473998bf80b88b781 | 4,508 | advent-of-code | Apache License 2.0 |
src/Day10.kt | cvb941 | 572,639,732 | false | {"Kotlin": 24794} | import kotlin.math.absoluteValue
fun main() {
class Crt {
private var X = 1
fun processCommands(commands: List<String>): Sequence<Int> = sequence {
commands.forEach {
val sequence = processCommand(it)
yieldAll(sequence)
}
}
... | 0 | Kotlin | 0 | 0 | fe145b3104535e8ce05d08f044cb2c54c8b17136 | 2,170 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day11.kt | arhor | 572,349,244 | false | {"Kotlin": 36845} | fun main() {
val input = readInput {}
println("Part 1: ${solvePuzzle(input)}")
}
private fun solvePuzzle(list: List<String>): ULong {
val monkeys = list.split("").map(::Monkey)
val factor = lcm(monkeys.map { it.divisor.toInt() }.toIntArray())
fun tick() {
for (monkey in monkeys) {
... | 0 | Kotlin | 0 | 0 | 047d4bdac687fd6719796eb69eab2dd8ebb5ba2f | 2,072 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/nl/tiemenschut/aoc/y2023/day10.kt | tschut | 723,391,380 | false | {"Kotlin": 61206} | package nl.tiemenschut.aoc.y2023
import nl.tiemenschut.aoc.lib.dsl.aoc
import nl.tiemenschut.aoc.lib.dsl.day
import nl.tiemenschut.aoc.lib.dsl.parser.InputParser
import nl.tiemenschut.aoc.lib.util.points.Point
import nl.tiemenschut.aoc.lib.util.points.PointInt
import nl.tiemenschut.aoc.lib.util.points.by
data class T... | 0 | Kotlin | 0 | 1 | a1ade43c29c7bbdbbf21ba7ddf163e9c4c9191b3 | 5,077 | aoc-2023 | The Unlicense |
2021/src/main/kotlin/com/trikzon/aoc2021/Day14.kt | Trikzon | 317,622,840 | false | {"Kotlin": 43720, "Rust": 21648, "C#": 12576, "C++": 4114, "CMake": 397} | package com.trikzon.aoc2021
fun main() {
val input = getInputStringFromFile("/day14.txt")
benchmark(Part.One, ::day14Part1, input, 3009, 5000)
benchmark(Part.Two, ::day14Part2, input, 3459822539451L, 5000)
}
fun day14Part1(input: String): Int {
val lines = input.lines()
var template = lines[0]
... | 0 | Kotlin | 1 | 0 | d4dea9f0c1b56dc698b716bb03fc2ad62619ca08 | 4,245 | advent-of-code | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaximumLengthRepeatedSubarray.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 | 5,675 | kotlab | Apache License 2.0 |
src/Day05.kt | dmdrummond | 573,289,191 | false | {"Kotlin": 9084} | import java.util.*
fun main() {
fun charPositionFor(i: Int): Int {
return when (i) {
1 -> 1
else -> 4 * i - 3
}
}
fun parseInput(input: List<String>): Pair<ElfStack, List<Instruction>> {
val elfStack = mutableListOf<Stack<Char>>()
val instructions ... | 0 | Kotlin | 0 | 0 | 2493256124c341e9d4a5e3edfb688584e32f95ec | 3,026 | AoC2022 | Apache License 2.0 |
src/aoc2022/Day03.kt | Playacem | 573,606,418 | false | {"Kotlin": 44779} | package aoc2022
import utils.readInput
object Day03 {
override fun toString(): String {
return this.javaClass.simpleName
}
}
fun main() {
fun CharRange.asLongString(): String = this.toList().joinToString(separator = "", prefix = "", postfix = "")
val alphabet: String = ('a'..'z').asLongString... | 0 | Kotlin | 0 | 0 | 4ec3831b3d4f576e905076ff80aca035307ed522 | 1,512 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/year_2022/Day09.kt | krllus | 572,617,904 | false | {"Kotlin": 97314} | package year_2022
import utils.readInput
import kotlin.math.pow
fun main() {
fun getCandidatesToMove(grid: Array<Array<String>>, headPosition: Position): List<Position> {
val positions = mutableListOf<Position>()
val size = grid[0].size
positions.add(headPosition.copy(i = headPosition.i... | 0 | Kotlin | 0 | 0 | b5280f3592ba3a0fbe04da72d4b77fcc9754597e | 4,817 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem2306/Solution2.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2306
/**
* LeetCode page: [2306. Naming a Company](https://leetcode.com/problems/naming-a-company/);
*/
class Solution2 {
/* Complexity:
* Time O(L) and Space O(L) where L is the flat length of ideas;
*/
fun distinctNames(ideas: Array<String>): Long {
v... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,570 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day24.kt | palex65 | 572,937,600 | false | {"Kotlin": 68582} | @file:Suppress("PackageDirectoryMismatch")
package day24
import readInput
import day24.Dir.*
import java.util.Comparator
import java.util.PriorityQueue
import kotlin.math.*
data class Pos(val row: Int, val col: Int) {
override fun toString() = "($row,$col)"
}
data class Offset(val dRow: Int, val dCol: Int)
fun Off... | 0 | Kotlin | 0 | 2 | 35771fa36a8be9862f050496dba9ae89bea427c5 | 4,368 | aoc2022 | Apache License 2.0 |
src/day02/Day02.kt | chskela | 574,228,146 | false | {"Kotlin": 9406} | package day02
import java.io.File
fun main() {
fun parseInput(input: String) = input.lines().map { it.split(" ") }.map { it.first() to it.last() }
val points = mapOf("X" to 1, "Y" to 2, "Z" to 3)
val winsPlayer = listOf("A" to "Y", "B" to "Z", "C" to "X")
val drawPlayer = listOf("A" to "X", "B" to "... | 0 | Kotlin | 0 | 0 | 951d38a894dcf0109fd0847eef9ff3ed3293fca0 | 1,557 | adventofcode-2022-kotlin | Apache License 2.0 |
src/BicliqueCoverProblem.kt | SzybkiDanny | 224,013,942 | false | null | class BicliqueCoverProblem(private val problemGraph: Graph) {
private val solution = mutableSetOf<BipartiteGraph>()
fun solve() {
val vertices = problemGraph.vertices.filterNot { problemGraph.hasSelfLoop(it) }.toHashSet()
var isAnyChange = false
generateInitialSolution(vertices)
... | 0 | Kotlin | 0 | 0 | 67625c8697858bb74a4d582b56ff6e9343a760d1 | 4,609 | FindCompleteBipartiteSubgraphs | MIT License |
kotlin/src/com/s13g/aoc/aoc2020/Day19.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2020
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
/**
* --- Day 19: Monster Messages ---
* https://adventofcode.com/2020/day/19
*/
class Day19 : Solver {
private fun parseRule(str: String): Pair<Int, Val> {
val split = str.split(": ")
val ruleNo = split[0].toInt()
ret... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 2,147 | euler | Apache License 2.0 |
solutions/aockt/util/Search.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.util
import java.util.PriorityQueue
/** A type implementing this interface can represent a network of nodes usable for search algorithms. */
interface Graph<T : Any> {
/** Returns all the possible nodes to visit starting from this [node] associated with the cost of travel. */
fun neighboursOf(n... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 4,155 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/com/ginsberg/advent2020/Day17.kt | tginsberg | 315,060,137 | false | null | /*
* Copyright (c) 2020 by <NAME>
*/
/**
* Advent of Code 2020, Day 17 - Conway Cubes
* Problem Description: http://adventofcode.com/2020/day/17
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2020/day17/
*/
package com.ginsberg.advent2020
class Day17(private val input: List<String>) {
... | 0 | Kotlin | 2 | 38 | 75766e961f3c18c5e392b4c32bc9a935c3e6862b | 1,716 | advent-2020-kotlin | Apache License 2.0 |
src/Day20.kt | SimoneStefani | 572,915,832 | false | {"Kotlin": 33918} | fun main() {
fun decrypt(input: List<Long>, decryptKey: Int = 1, iterations: Int = 1): Long {
val original = input.mapIndexed { index, n -> index to n * decryptKey }
val shifted = original.toMutableList()
repeat(iterations) {
original.forEach { p ->
shifted.index... | 0 | Kotlin | 0 | 0 | b3244a6dfb8a1f0f4b47db2788cbb3d55426d018 | 1,239 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimizeTheDifference.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <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,840 | kotlab | Apache License 2.0 |
src/main/kotlin/co/csadev/advent2022/Day21.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2022 by <NAME>
* Advent of Code 2022, Day 21
* Problem Description: http://adventofcode.com/2021/day/21
*/
package co.csadev.advent2022
import co.csadev.adventOfCode.BaseDay
import co.csadev.adventOfCode.Resources.resourceAsList
import kotlin.math.abs
class Day21(override val input: List<Strin... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 3,245 | advent-of-kotlin | Apache License 2.0 |
src/Day08A.kt | zsmb13 | 572,719,881 | false | {"Kotlin": 32865} | fun main() {
fun part1(testInput: List<String>): Int {
val map = testInput.map { line ->
line.map { digit -> digit.digitToInt() }
}
val xValues = testInput.first().indices
val yValues = testInput.indices
val visible = mutableSetOf<Pair<Int, Int>>()
// r... | 0 | Kotlin | 0 | 6 | 32f79b3998d4dfeb4d5ea59f1f7f40f7bf0c1f35 | 2,913 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} | import kotlin.math.sign
//Advent of Code 2022 Day 9, Rope Physics
class Day09 {
private class Rope(knotAmt: Int){
val knots = mutableListOf<Point2d>()
val tailPositions = mutableSetOf<Pair<Int,Int>>()
val maxKnotDistance = 1
init {
tailPositions.add(Pair(0,0))
... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 2,096 | aoc-22-kotlin | Apache License 2.0 |
src/day02/Day02Answer5.kt | IThinkIGottaGo | 572,833,474 | false | {"Kotlin": 72162} | package day02
import readInput
/**
* Answers from [Advent of Code 2022 - Day 2, in Kotlin - Rock Paper Scissors](https://todd.ginsberg.com/post/advent-of-code/2022/day2/)
*/
fun main() {
fun part1(input: List<String>): Int {
return Day02(input).solvePart1()
}
fun part2(input: List<String>): Int... | 0 | Kotlin | 0 | 0 | 967812138a7ee110a63e1950cae9a799166a6ba8 | 1,443 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/advent/of/code/day08/Solution.kt | brunorene | 160,263,437 | false | null | package advent.of.code.day08
import java.io.File
data class Node(
val children: List<Node>,
val metadata: List<Int>
) {
val length: Int = 2 + metadata.size + children.sumBy { it.length }
val metadataSum: Int = metadata.sum() + children.sumBy { it.metadataSum }
val metadataValue: Int = if (children... | 0 | Kotlin | 0 | 0 | 0cb6814b91038a1ab99c276a33bf248157a88939 | 1,038 | advent_of_code_2018 | The Unlicense |
src/main/kotlin/days/Day17.kt | felix-ebert | 317,592,241 | false | null | package days
class Day17 : Day(17) {
// adapted from: https://todd.ginsberg.com/post/advent-of-code/2020/day17/
override fun partOne(): Any {
var grid = parseInput { x, y -> Cube3D(x, y, 0) }
repeat(6) {
grid = grid.simulate()
}
return grid.count { it.value }
}
... | 0 | Kotlin | 0 | 4 | dba66bc2aba639bdc34463ec4e3ad5d301266cb1 | 2,478 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/Day04.kt | tsschmidt | 572,649,729 | false | {"Kotlin": 24089} | fun main() {
fun parse(input: List<String>): List<Pair<IntRange, IntRange>> {
return input.map {
val (a, b) = it.split(",")
val rangeA = IntRange(a.split("-")[0].toInt(), a.split("-")[1].toInt())
val rangeB = IntRange(b.split("-")[0].toInt(), b.split("-")[1].toInt())
... | 0 | Kotlin | 0 | 0 | 7bb637364667d075509c1759858a4611c6fbb0c2 | 845 | aoc-2022 | Apache License 2.0 |
archive/2022/Day25.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | private const val EXPECTED_1 = 4890L
private const val EXPECTED_2 = 0
val ch = mapOf('=' to -2, '-' to -1, '0' to 0, '1' to 1, '2' to 2)
fun decode(p: String): Long {
var value = 0L
var multiplier = 1L
var index = 0
while (index < p.length) {
value += multiplier * ch[p[p.length -1 - index]]!!
... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 1,273 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g1601_1700/s1697_checking_existence_of_edge_length_limited_paths/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1601_1700.s1697_checking_existence_of_edge_length_limited_paths
// #Hard #Array #Sorting #Graph #Union_Find
// #2023_06_15_Time_1411_ms_(72.90%)_Space_101.6_MB_(99.07%)
import java.util.Arrays
class Solution {
private class Dsu(n: Int) {
private val parent: IntArray
init {
p... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,659 | LeetCode-in-Kotlin | MIT License |
2016/src/main/kotlin/day4.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.mapItems
import utils.withCounts
fun main() {
Day4.run()
}
object Day4 : Solution<List<Day4.Room>>() {
override val name = "day4"
override val parser = Parser.lines.mapItems { parseRoom(it) }
fun parseRoom(line: String): Room {
val checksumStart = li... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,344 | aoc_kotlin | MIT License |
src/shmulik/klein/day05/Day05.kt | shmulik-klein | 573,426,488 | false | {"Kotlin": 9136} | package shmulik.klein.day05
import readInput
/*
[V] [T] [J]
[Q] [M] [P] [Q] [J]
[W] [B] [N] [Q] [C] [T]
[M] [C] [F] [N] [G] [W] [G]
[B] [W] [J] [H] [L] [R] [B] [C]
[N] [R] [R] [W] [W] [W] [D] [N] [F]
[Z] [Z] [Q] [S] [F] [P] [B] [Q] [L]
[C] [H] [F] [Z] [G] [L] [V... | 0 | Kotlin | 0 | 0 | 4d7b945e966dad8514ec784a4837b63a942882e9 | 1,951 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/solutions/day11/Day11.kt | Dr-Horv | 570,666,285 | false | {"Kotlin": 115643} | package solutions.day11
import solutions.Solver
data class Monkey(
val nbr: Long,
val items: MutableList<Long>,
val operation: (Long) -> Long,
val test: (Long) -> Boolean,
val testNbr: Long,
val trueTarget: Long,
val falseTarget: Long,
var inspections: Long
)
class Day11 : Solver {
... | 0 | Kotlin | 0 | 2 | 6c9b24de2fe2a36346cb4c311c7a5e80bf505f9e | 3,778 | Advent-of-Code-2022 | MIT License |
src/main/kotlin/com/ginsberg/advent2021/Day12.kt | tginsberg | 432,766,033 | false | {"Kotlin": 92813} | /*
* Copyright (c) 2021 by <NAME>
*/
/**
* Advent of Code 2021, Day 12 - Passage Pathing
* Problem Description: http://adventofcode.com/2021/day/12
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2021/day12/
*/
package com.ginsberg.advent2021
class Day12(input: List<String>) {
private... | 0 | Kotlin | 2 | 34 | 8e57e75c4d64005c18ecab96cc54a3b397c89723 | 1,820 | advent-2021-kotlin | Apache License 2.0 |
src/aoc2022/day13/Day13.kt | svilen-ivanov | 572,637,864 | false | {"Kotlin": 53827} | package aoc2022.day13
import readInput
import kotlin.math.min
enum class CompareResult(val comparatorOutcome: Int) {
CORRECT(-1),
INCORRECT(1),
SAME(0),
}
sealed class Packet {
abstract fun toNumList(): NumList
data class Num(val num: Int) : Packet() {
override fun toNumList(): NumList =... | 0 | Kotlin | 0 | 0 | 456bedb4d1082890d78490d3b730b2bb45913fe9 | 4,120 | aoc-2022 | Apache License 2.0 |
app/src/main/java/com/itscoder/ljuns/practise/algorithm/QuickSort.kt | ljuns | 148,606,057 | false | {"Java": 26841, "Kotlin": 25458} | package com.itscoder.ljuns.practise.algorithm
/**
* Created by ljuns at 2019/1/5.
* I am just a developer.
* 快速排序
* 例如:3, 1, 1, 6, 2, 4, 19
* 1、定义 left 为最左边,right 为最右边;
* 2、选定 left 位置的元素为 temp;
* 3、用 temp 从最右边开始比较,大于等于 temp 就 right--,否则 right 位置的元素替换掉 left 的元素,并且 left++;
* 4、用 temp 从 left 开始比较,小于等于 temp 就 left... | 0 | Java | 0 | 0 | 365062b38a7ac55468b202ebeff1b760663fc676 | 2,819 | Practise | Apache License 2.0 |
src/main/kotlin/tr/emreone/adventofcode/days/Day13.kt | EmRe-One | 434,793,519 | false | {"Kotlin": 44202} | package tr.emreone.adventofcode.days
import tr.emreone.kotlin_utils.Logger.logger
import tr.emreone.kotlin_utils.extensions.permutations
object Day13 {
class Person(val name: String) {
private val happinessMatrix = mutableMapOf<String, Int>()
fun addPossibleNeighbor(other: String, happiness: Int... | 0 | Kotlin | 0 | 0 | 57f6dea222f4f3e97b697b3b0c7af58f01fc4f53 | 3,389 | advent-of-code-2015 | Apache License 2.0 |
src/main/kotlin/_2023/Day14.kt | novikmisha | 572,840,526 | false | {"Kotlin": 145780} | package _2023
import Coordinate
import Day
import InputReader
import atCoordinates
class Day14 : Day(2023, 14) {
override val firstTestAnswer = 136
override val secondTestAnswer = 64
override fun first(input: InputReader): Int {
val schema = input.asLines().map { it.toCharArray() }
for ... | 0 | Kotlin | 0 | 0 | 0c78596d46f3a8bf977bf356019ea9940ee04c88 | 3,124 | advent-of-code | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MeetingScheduler.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,802 | kotlab | Apache License 2.0 |
kotlin-examples/src/main/kotlin/de/rieckpil/learning/fpbook/propertytesting/Boilerplate.kt | rieckpil | 127,932,091 | false | null | package de.rieckpil.learning.fpbook.propertytesting
interface RNG {
fun nextInt(): Pair<Int, RNG>
}
data class SimpleRNG(val seed: Long) : RNG {
override fun nextInt(): Pair<Int, RNG> {
val newSeed = (seed * 0x5DEECE66DL + 0xBL) and 0xFFFFFFFFFFFFL
val nextRNG = SimpleRNG(newSeed)
val n = (newSeed ush... | 23 | Java | 7 | 11 | 33d8f115c81433abca8f4984600a41350a1d831d | 1,521 | learning-samples | MIT License |
advent2022/src/main/kotlin/year2022/Day18.kt | bulldog98 | 572,838,866 | false | {"Kotlin": 132847} | package year2022
import AdventDay
import Point3D
import exploreFrom
class Day18 : AdventDay(2022, 18) {
enum class Plane {
XY, YZ, XZ
}
// needed because you have to differentiate
data class Face(val point: Point3D, val plane: Plane)
private val Point3D.faces
get() = setOf(
... | 0 | Kotlin | 0 | 0 | 02ce17f15aa78e953a480f1de7aa4821b55b8977 | 2,332 | advent-of-code | Apache License 2.0 |
src/net/sheltem/aoc/y2023/Day08.kt | jtheegarten | 572,901,679 | false | {"Kotlin": 178521} | package net.sheltem.aoc.y2023
import net.sheltem.common.lcm
import net.sheltem.common.regex
import net.sheltem.aoc.y2023.Day08.Tree
import net.sheltem.aoc.y2023.Day08.Tree.Node
suspend fun main() {
Day08().run()
}
class Day08 : Day<Long>(2, 6) {
override suspend fun part1(input: List<String>): Long =
... | 0 | Kotlin | 0 | 0 | ac280f156c284c23565fba5810483dd1cd8a931f | 1,949 | aoc | Apache License 2.0 |
src/Day03.kt | djleeds | 572,720,298 | false | {"Kotlin": 43505} | fun main() {
fun Char.toPriority() = if (code <= 'Z'.code) this - 'A' + 27 else this - 'a' + 1
fun part1(input: List<String>): Int =
input
.map { rucksack -> rucksack.chunked(rucksack.length / 2) }
.map { (compartment1, compartment2) -> compartment1.first { it in compartment2 } ... | 0 | Kotlin | 0 | 4 | 98946a517c5ab8cbb337439565f9eb35e0ce1c72 | 774 | advent-of-code-in-kotlin-2022 | Apache License 2.0 |
src/Day12.kt | nordberg | 573,769,081 | false | {"Kotlin": 47470} | import kotlin.streams.toList
fun main() {
data class Point(val x: Int, val y: Int)
fun getWalkableAdjacent(grid: List<List<Int>>, mid: Point): List<Point> {
val maxX = grid.first().indices.max()
check(mid.x in 0..maxX)
val maxY = grid.indices.max()
check(mid.y in 0..maxY)
... | 0 | Kotlin | 0 | 0 | 3de1e2b0d54dcf34a35279ba47d848319e99ab6b | 4,720 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | camina-apps | 572,935,546 | false | {"Kotlin": 7782} | fun main() {
fun outcomeRound(opponent: String, you: String): Int {
when (you) {
"A" -> {
if (opponent == "A") return 3
} // rock
"B" -> {
if (opponent == "B") return 3
} // paper
"C" -> {
if (oppone... | 0 | Kotlin | 0 | 0 | fb6c6176f8c127e9d36aa0b7ae1f0e32b5c31171 | 2,429 | aoc_2022 | Apache License 2.0 |
src/Day07.kt | andydenk | 573,909,669 | false | {"Kotlin": 24096} | import java.lang.IllegalStateException
fun main() {
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day07_test")
check(part1(testInput) == 95437)
check(part2(testInput) == 24933642)
val input = readInput("Day07")
println("Part 1: ${part1(input)}"... | 0 | Kotlin | 0 | 0 | 1b547d59b1dc55d515fe8ca8e88df05ea4c4ded1 | 4,377 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day13.kt | kevinrobayna | 436,414,545 | false | {"Ruby": 195446, "Kotlin": 42719, "Shell": 1288} | import java.lang.Math.floorMod
fun day13ProblemReader(text: String): Pair<Int, List<String>> {
val lines = text.split('\n')
return Pair(
lines[0].toInt(),
lines[1].split(",")
)
}
// https://adventofcode.com/2020/day/13
class Day13(
private val problem: Pair<Int, List<String>>,
) {
... | 0 | Ruby | 0 | 0 | 9e48ecdebdb4c479ef00f0fd3b1a44a211fb6577 | 1,954 | adventofcode_2020 | MIT License |
src/Day18.kt | sabercon | 648,989,596 | false | null | fun main() {
fun evaluate1(expression: List<String>): Long {
val ops = ArrayDeque<String>()
val nums = ArrayDeque<Long>()
for (token in expression) {
when (token) {
"+", "*", "(" -> {
ops.add(token)
continue
... | 0 | Kotlin | 0 | 0 | 81b51f3779940dde46f3811b4d8a32a5bb4534c8 | 1,629 | advent-of-code-2020 | MIT License |
src/Day05.kt | DiamondMiner88 | 573,073,199 | false | {"Kotlin": 26457, "Rust": 4093, "Shell": 188} | fun main() {
d5part1()
d5part2()
}
fun d5part1() {
val input = readInput("input/day05.txt")
.split("\n\n")
val stackSplits = input[0].split("\n")
val stacksCount = stackSplits.last().count { it.isDigit() }
val stacks = MutableList<MutableList<Char>>(9) { mutableListOf() }
for (sta... | 0 | Kotlin | 0 | 0 | 55bb96af323cab3860ab6988f7d57d04f034c12c | 2,462 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/solutions/day20/Day20.kt | Dr-Horv | 570,666,285 | false | {"Kotlin": 115643} | package solutions.day20
import solutions.Solver
import kotlin.math.abs
var INDEX = 0
fun getIndex(): Int = INDEX++
data class Chain<T>(
val value: T,
var next: Chain<T>?,
var prev: Chain<T>?
) {
val index: Int = getIndex()
fun move(steps: Long) {
var next = this.next!!
var prev ... | 0 | Kotlin | 0 | 2 | 6c9b24de2fe2a36346cb4c311c7a5e80bf505f9e | 2,993 | Advent-of-Code-2022 | MIT License |
src/main/kotlin/day1/day1.kt | lavong | 317,978,236 | false | null | /*
--- Day 1: Report Repair ---
After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you.
The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfi... | 0 | Kotlin | 0 | 1 | a4ccec64a614d73edb4b9c4d4a72c55f04a4b77f | 2,963 | adventofcode-2020 | MIT License |
src/Day04.kt | BrianEstrada | 572,700,177 | false | {"Kotlin": 22757} | fun main() {
// Test Case
val testInput = readInput("Day04_test")
val part1TestResult = Day04.part1(testInput)
println(part1TestResult)
check(part1TestResult == 2)
val part2TestResult = Day04.part2(testInput)
println(part2TestResult)
check(part2TestResult == 4)
// Actual Case
... | 1 | Kotlin | 0 | 1 | 032a4693aff514c9b30e979e63560dc48917411d | 1,639 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/tw/gasol/aoc/aoc2022/Day13.kt | Gasol | 574,784,477 | false | {"Kotlin": 70912, "Shell": 1291, "Makefile": 59} | package tw.gasol.aoc.aoc2022
typealias Packet = List<Any>
class Day13 {
fun part1(input: String): Int {
val pairs = input.split("\n\n")
.map {
val (first, second) = it.split("\n")
toPacket(first) to toPacket(second)
}
return pairs.map { isRi... | 0 | Kotlin | 0 | 0 | a14582ea15f1554803e63e5ba12e303be2879b8a | 3,588 | aoc2022 | MIT License |
src/Day05.kt | makobernal | 573,037,099 | false | {"Kotlin": 16467} | typealias ElfStack = ArrayDeque<Char>
typealias Warehouse = List<ElfStack>
data class Command(val quantity: Int, val source: Int, val destination: Int)
fun calculateRealIndex(currentIndex: Int): Int {
//2,1,1 --> f(1) = 1
//6,5,2 --> f(2) = f(1) + 4
//10,9,3 --> f(3) = f(2) + 4
//14,13,4
//18,17,5... | 0 | Kotlin | 0 | 0 | 63841809f7932901e97465b2dcceb7cec10773b9 | 4,622 | kotlin-advent-of-code-2022 | Apache License 2.0 |
2023/src/main/kotlin/de/skyrising/aoc2023/day1/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2023.day1
import de.skyrising.aoc.*
fun digitToInt(s: String) = when (s) {
"0", "zero" -> 0
"1", "one" -> 1
"2", "two" -> 2
"3", "three" -> 3
"4", "four" -> 4
"5", "five" -> 5
"6", "six" -> 6
"7", "seven" -> 7
"8", "eight" -> 8
"9", "nine" -> 9
else ... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 1,455 | aoc | MIT License |
Day_11/Solution_Pat1.kts | 0800LTT | 317,590,451 | false | null | import java.io.File
enum class Seat {
Empty,
Occupied,
Floor
}
fun File.readSeats(): Array<Array<Seat>> {
return readLines().map {
line -> line.map {
when (it) {
'.' -> Seat.Floor
'L' -> Seat.Empty
else -> Seat.Occupied
}
}.toTypedArray()
}.toTypedArray()
}
fun printSeats(seats:... | 0 | Kotlin | 0 | 0 | 191c8c307676fb0e7352f7a5444689fc79cc5b54 | 2,047 | advent-of-code-2020 | The Unlicense |
src/Day20.kt | jordan-thirus | 573,476,470 | false | {"Kotlin": 41711} | import kotlin.math.abs
fun main() {
fun mix(lst: MutableList<Node>, verbose: Boolean) {
for (index in lst.indices) {
val i = lst.indexOfFirst { it.mixOrder == index }
val node = lst[i]
val moveAmount = node.value
if (abs(moveAmount) > lst.size) moveAmount % ... | 0 | Kotlin | 0 | 0 | 59b0054fe4d3a9aecb1c9ccebd7d5daa7a98362e | 2,418 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day02.kt | rgawrys | 572,698,359 | false | {"Kotlin": 20855} | import Outcome.DRAW
import Outcome.LOST
import Outcome.WON
import Shape.PAPER
import Shape.ROCK
import Shape.SCISSORS
import utils.readInput
fun main() {
fun part1(strategyGuide: List<String>): Int =
strategyGuide
.toGameRounds()
.calculateGameTotalScore()
fun part2(input: List... | 0 | Kotlin | 0 | 0 | 5102fab140d7194bc73701a6090702f2d46da5b4 | 3,988 | advent-of-code-2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.