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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
advent-of-code-2022/src/main/kotlin/Day05.kt | jomartigcal | 433,713,130 | false | {"Kotlin": 72459} | //Day 05: Supply Stacks
//https://adventofcode.com/2022/day/5
import java.io.File
import kotlin.collections.ArrayDeque
data class Command(val itemsToMove: Int, val source: String, val destination: String) {
companion object {
fun fromString(command: String): Command {
return Command(
... | 0 | Kotlin | 0 | 0 | 6b0c4e61dc9df388383a894f5942c0b1fe41813f | 2,258 | advent-of-code | Apache License 2.0 |
ceria/10/src/main/kotlin/Solution.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File;
import java.util.Stack;
val matches = mapOf<Char, Char>(
')' to '(',
']' to '[',
'}' to '{',
'>' to '<'
)
val leftChars = matches.values.toSet()
val corruptedValues = mapOf<Char, Int>(
')' to 3,
']' to 57,
'}' to 1197,
'>' to 25137
)
val scoreValues = mapOf<Char,... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 2,559 | advent-of-code-2021 | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2017/Day03.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2017
import se.saidaspen.aoc.util.Day
import kotlin.math.absoluteValue
import kotlin.math.floor
import kotlin.math.pow
fun main() = Day03.run()
object Day03 : Day(2017, 3) {
private val directions = arrayOf(Pair(0, 1), Pair(-1, 0), Pair(0, -1), Pair(1, 0))
override fun part1(): A... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 2,536 | adventofkotlin | MIT License |
logger/core/src/main/kotlin/org/sollecitom/chassis/logger/core/implementation/datastructure/Trie.kt | sollecitom | 669,483,842 | false | {"Kotlin": 831362, "Java": 30834} | package org.sollecitom.chassis.logger.core.implementation.datastructure
internal interface Trie {
/**
* Returns the word in the trie with the longest prefix in common to the given word.
*/
fun searchLongestPrefixWord(word: String): String
/**
* Returns the longest prefix in the trie common... | 0 | Kotlin | 0 | 2 | e4e3403e46f7358a03c8ee3520b3b94be679792b | 3,766 | chassis | MIT License |
src/main/kotlin/com/github/michaelbull/advent2021/day14/Polymer.kt | michaelbull | 433,565,311 | false | {"Kotlin": 162839} | package com.github.michaelbull.advent2021.day14
private fun <T, K> Grouping<T, K>.eachCountLong(): Map<K, Long> {
return fold(0L) { count, _ -> count + 1 }
}
fun String.toPolymer(): Polymer {
return Polymer(
elements = groupingBy { it }.eachCountLong(),
pairs = zipWithNext().groupingBy { it }.... | 0 | Kotlin | 0 | 4 | 7cec2ac03705da007f227306ceb0e87f302e2e54 | 1,479 | advent-2021 | ISC License |
src/Day10.kt | rod41732 | 572,917,438 | false | {"Kotlin": 85344} | import kotlin.math.abs
fun main() {
val input = readInput("Day10")
fun part1(input: List<String>): Int {
val reg = calculateRegister(input)
return (20..220 step 40).map { reg[it] * it }.sum()
}
// return 40x6 CRT screen seperated by newline
fun part2(input: List<String>): String {... | 0 | Kotlin | 0 | 0 | 1d2d3d00e90b222085e0989d2b19e6164dfdb1ce | 1,471 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/days/aoc2022/Day8.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2022
import days.Day
class Day8 : Day(2022, 8) {
override fun partOne(): Any {
return calculateVisibleTrees(inputList)
}
override fun partTwo(): Any {
return calculateHighestScenicScore(inputList)
}
fun calculateVisibleTrees(input: List<String>): Int {
val... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 3,353 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/year_2022/day_20/Day20.kt | scottschmitz | 572,656,097 | false | {"Kotlin": 240069} | package year_2022.day_20
import readInput
class Day20(input: List<String>) {
private val encryptedData = parseInput(input)
/**
* @return
*/
fun solutionOne(): Long {
val mutable = encryptedData.toMutableList()
encryptedData.forEach { (initialIndex, value) ->
val cur... | 0 | Kotlin | 0 | 0 | 70efc56e68771aa98eea6920eb35c8c17d0fc7ac | 2,599 | advent_of_code | Apache License 2.0 |
src/main/kotlin/io/dmitrijs/aoc2022/Day24.kt | lakiboy | 578,268,213 | false | {"Kotlin": 76651} | package io.dmitrijs.aoc2022
import io.dmitrijs.aoc2022.Direction.DOWN
import io.dmitrijs.aoc2022.Direction.LEFT
import io.dmitrijs.aoc2022.Direction.RIGHT
import io.dmitrijs.aoc2022.Direction.UP
class Day24(input: List<String>) {
private val grid = input.drop(1).dropLast(1).map { it.drop(1).dropLast(1) }
priv... | 0 | Kotlin | 0 | 1 | bfce0f4cb924834d44b3aae14686d1c834621456 | 3,029 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/wabradshaw/claptrap/design/SubstringGenerator.kt | wabradshaw | 154,681,482 | false | null | package com.wabradshaw.claptrap.design
import java.lang.Math.min
/**
* A SubstringGenerator is used to find substrings of words that are candidates for substitution. These will later be
* reduced to just the substrings representing actual words. The default setting is to select substrings at the start
* and end of... | 0 | Kotlin | 0 | 0 | 7886787603e477d47ea858a8d9c76e11c4c25fe3 | 2,245 | claptrap | Apache License 2.0 |
src/day25/result.kt | davidcurrie | 437,645,413 | false | {"Kotlin": 37294} | package day25
import java.io.File
fun main() {
val lines = File("src/day25/input.txt").readLines()
val seafloor = Seafloor(lines[0].length, lines.size,
Herd.values().associateWith { herd -> herd.parse(lines) }.toMutableMap())
while (seafloor.move()) {}
println(seafloor.steps)
}
data class S... | 0 | Kotlin | 0 | 0 | dd37372420dc4b80066efd7250dd3711bc677f4c | 1,544 | advent-of-code-2021 | MIT License |
src/test/kotlin/com/dambra/adventofcode2018/day17/UndergroundMap.kt | pauldambra | 159,939,178 | false | null | package com.dambra.adventofcode2018.day17
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
internal class UndergroundMap {
@Test
fun `can parse the example scan`() {
val exampleInput = """
x=495, y=2..7
y=7, x=495..501
x=501, y=3..7
x=498, y=2..4
x=506, y=1..2
x=498,... | 0 | Kotlin | 0 | 1 | 7d11bb8a07fb156dc92322e06e76e4ecf8402d1d | 3,097 | adventofcode2018 | The Unlicense |
src/day02/Day02_Part1.kt | m-jaekel | 570,582,194 | false | {"Kotlin": 13764} | package day02
import readInput
fun main() {
/**
* A Y
* B X
* C Z
*
* A,X -> Rock (1)
* B,Y -> Paper (2)
* C,Z -> Scissors (3)
*
* lost -> 0
* draw -> 3
* win -> 6
*
*/
fun part1(input: List<String>): Int {
var score = 0
input.... | 0 | Kotlin | 0 | 1 | 07e015c2680b5623a16121e5314017ddcb40c06c | 1,250 | AOC-2022 | Apache License 2.0 |
src/main/kotlin/com/github/dangerground/aoc2020/Day22.kt | dangerground | 317,439,198 | false | null | package com.github.dangerground.aoc2020
import com.github.dangerground.aoc2020.util.DayInput
import java.util.*
fun main() {
val process = Day22(DayInput.batchesOfStringList(22))
println("result part 1: ${process.part1()}")
println("result part 2: ${process.part2()}")
}
class Day22(val input: List<List<... | 0 | Kotlin | 0 | 0 | c3667a2a8126d903d09176848b0e1d511d90fa79 | 4,231 | adventofcode-2020 | MIT License |
grind-75-kotlin/src/main/kotlin/BalancedBinaryTree.kt | Codextor | 484,602,390 | false | {"Kotlin": 27206} | import commonclasses.TreeNode
import kotlin.math.abs
/**
* Given a binary tree, determine if it is
* height-balanced
* .
*
*
*
* Example 1:
*
*
* Input: root = [3,9,20,null,null,15,7]
* Output: true
* Example 2:
*
*
* Input: root = [1,2,2,3,3,null,null,4,4]
* Output: false
* Example 3:
*
* Input: ro... | 0 | Kotlin | 0 | 0 | 87aa60c2bf5f6a672de5a9e6800452321172b289 | 1,262 | grind-75 | Apache License 2.0 |
src/main/kotlin/aoc/day5/SupplyStacks.kt | hofiisek | 573,543,194 | false | {"Kotlin": 17421} | package aoc.day5
import aoc.loadInput
import aoc.matchesNot
import java.io.File
/**
* https://adventofcode.com/2022/day/5
*
* @author <NAME>
*/
typealias Stacks = Map<Int, ArrayDeque<Crate>>
data class Crate(val stackId: Int, val id: String)
data class Move(val quantity: Int, val from: Int, val to: Int)
infix ... | 0 | Kotlin | 0 | 2 | 5908a665db4ac9fc562c44d6907f81cd3cd8d647 | 2,320 | Advent-of-code-2022 | MIT License |
2023/7/solve-1.kts | gugod | 48,180,404 | false | {"Raku": 170466, "Perl": 121272, "Kotlin": 58674, "Rust": 3189, "C": 2934, "Zig": 850, "Clojure": 734, "Janet": 703, "Go": 595} | import java.io.File
import kotlin.math.pow
enum class HandType(val strongness: Int) {
FiveOfAKind(7),
FourOfAKind(6),
FullHouse(5),
ThreeOfAKind(4),
TwoPair(3),
OnePair(2),
HighCard(1);
companion object {
fun fromString(hand: String) : HandType {
val freq = hand.fol... | 0 | Raku | 1 | 5 | ca0555efc60176938a857990b4d95a298e32f48a | 1,287 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/Day06.kt | rbraeunlich | 573,282,138 | false | {"Kotlin": 63724} | fun main() {
fun part1(input: List<String>): Int {
val buffer = mutableListOf<Char>()
input.first().forEachIndexed { index, c ->
if (buffer.size < 4) {
buffer.add(c)
} else if (buffer.size == 4 && buffer.allDifferent()) {
return index
... | 0 | Kotlin | 0 | 1 | 3c7e46ddfb933281be34e58933b84870c6607acd | 1,592 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | jfiorato | 573,233,200 | false | null | fun main() {
fun part1(input: List<String>): Int {
var total = 0
for (play in input) {
val (col1, col2) = play.split(" ")
val opponent = "ABC".indexOf(col1)
val you = "XYZ".indexOf(col2)
total += you + 1
when ((you - opponent).mod(3)) {
... | 0 | Kotlin | 0 | 0 | 4455a5e9c15cd067d2661438c680b3d7b5879a56 | 1,320 | kotlin-aoc-2022 | Apache License 2.0 |
src/Day02.kt | HaydenMeloche | 572,788,925 | false | {"Kotlin": 25699} | fun main() {
val input = readInput("Day02")
// part one
var partOneScore = 0
input.forEach { line ->
val split = line.split(" ")
val opponentHand = Play.from(split[0])
val myHand = Play.from(split[1])
partOneScore += myHand.score + myHand.computeScore(opponentHand)
... | 0 | Kotlin | 0 | 1 | 1a7e13cb525bb19cc9ff4eba40d03669dc301fb9 | 2,609 | advent-of-code-kotlin-2022 | Apache License 2.0 |
kotlin/strings/StringDistances.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package strings
import java.util.Arrays
object StringDistances {
// https://en.wikipedia.org/wiki/Longest_common_subsequence_problem
fun getLCS(x: IntArray, y: IntArray): IntArray {
val m = x.size
val n = y.size
val lcs = Array(m + 1) { IntArray(n + 1) }
for (i in 0 until m) {
... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 2,071 | codelibrary | The Unlicense |
src/day03/Day03.kt | TimberBro | 572,681,059 | false | {"Kotlin": 20536} | package day03
import readInput
import separateInputByRows
fun main() {
fun part1(input: List<String>): Int {
val result = input.stream()
.map { it.take(it.length / 2) to it.takeLast(it.length / 2) }
.map { it.first.toCharArray().intersect(it.second.asIterable().toSet()).first() }
... | 0 | Kotlin | 0 | 0 | 516a98e5067d11f0e6ff73ae19f256d8c1bfa905 | 1,610 | AoC2022 | Apache License 2.0 |
2015/kotlin/src/main/kotlin/nl/sanderp/aoc/aoc2015/day14/Day14.kt | sanderploegsma | 224,286,922 | false | {"C#": 233770, "Kotlin": 126791, "F#": 110333, "Go": 70654, "Python": 64250, "Scala": 11381, "Swift": 5153, "Elixir": 2770, "Jinja": 1263, "Ruby": 1171} | package nl.sanderp.aoc.aoc2015.day14
import nl.sanderp.aoc.common.transpose
data class Stats(val speed: Int, val flyTime: Int, val restTime: Int)
val input = mapOf(
"Vixen" to Stats(19, 7, 124),
"Rudolph" to Stats(3, 15, 28),
"Donner" to Stats(19, 9, 164),
"Blitzen" to Stats(19, 9, 158),
"Comet" ... | 0 | C# | 0 | 6 | 8e96dff21c23f08dcf665c68e9f3e60db821c1e5 | 1,205 | advent-of-code | MIT License |
src/day12/day12.kt | diesieben07 | 572,879,498 | false | {"Kotlin": 44432} | package day12
import streamInput
import java.util.HashSet
import java.util.PriorityQueue
private val file = "Day12"
//private val file = "Day12Example"
data class Point(val x: Int, val y: Int)
data class Parsed(val grid: List<IntArray>, val start: Point, val end: Point)
private fun parseInput(): Parsed {
return... | 0 | Kotlin | 0 | 0 | 0b9993ef2f96166b3d3e8a6653b1cbf9ef8e82e6 | 4,147 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | dmstocking | 575,012,721 | false | {"Kotlin": 40350} | import java.lang.Exception
fun main() {
fun part1(input: List<String>): Int {
return input
.map { line ->
val first = line.substring(0, line.length/2)
val second = line.substring(line.length/2)
first
.toSet()
... | 0 | Kotlin | 0 | 0 | e49d9247340037e4e70f55b0c201b3a39edd0a0f | 1,434 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2023/Day17.kt | tginsberg | 723,688,654 | false | {"Kotlin": 112398} | /*
* Copyright (c) 2023 by <NAME>
*/
/**
* Advent of Code 2023, Day 17 - Clumsy Crucible
* Problem Description: http://adventofcode.com/2023/day/17
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2023/day17/
*/
package com.ginsberg.advent2023
import com.ginsberg.advent2023.Point2D.Companio... | 0 | Kotlin | 0 | 12 | 0d5732508025a7e340366594c879b99fe6e7cbf0 | 2,924 | advent-2023-kotlin | Apache License 2.0 |
src/main/aoc2018/Day22.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2018
import Pos
import Search
import Search.WeightedGraph
class Day22(input: List<String>) {
enum class Type(val risk: Int) {
ROCKY(0),
WET(1),
NARROW(2);
companion object {
fun typeForErosionLevel(level: Int) = when (level % 3) {
0 -> ROCKY
... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 5,160 | aoc | MIT License |
src/Day20.kt | Kietyo | 573,293,671 | false | {"Kotlin": 147083} | import java.lang.Exception
import kotlin.math.absoluteValue
import kotlin.math.sign
data class CircularArrayElement(
var idx: Int,
val data: Long
)
@JvmInline
value class CircularArray(
val data: Array<CircularArrayElement>
) {
private fun normalizeIndex(idx: Int): Int {
val mod = idx % data.s... | 0 | Kotlin | 0 | 0 | dd5deef8fa48011aeb3834efec9a0a1826328f2e | 3,960 | advent-of-code-2022-kietyo | Apache License 2.0 |
code/day_07/src/jvm8Main/kotlin/task2.kt | dhakehurst | 725,945,024 | false | {"Kotlin": 105846} | package day_07
val map2 = mapOf(
"A" to 14,
"K" to 13,
"Q" to 12,
"J" to 1,
"T" to 10
)
data class Hand2(
val cards: String,
val bid: Int
) : Comparable<Hand2> {
val cardValues = cards.map { map2[it.toString()] ?: it.toString().toInt() }
val grouped = cardValues.filterNot { map2[... | 0 | Kotlin | 0 | 0 | be416bd89ac375d49649e7fce68c074f8c4e912e | 2,168 | advent-of-code | Apache License 2.0 |
aoc2023/day8.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2023
import utils.InputRetrieval
import utils.Math
fun main() {
Day8.execute()
}
private object Day8 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
private fun part1(input: DesertMap): Long = input.... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 2,229 | Advent-Of-Code | MIT License |
src/main/kotlin/day01/day01.kt | corneil | 572,437,852 | false | {"Kotlin": 93311, "Shell": 595} | package main.day01
import utils.readFile
import utils.readLines
fun main() {
fun findCalories(input: List<String>): List<Int> {
val elves = mutableListOf<Int>()
var calories = 0
for (line in input) {
if (line.isBlank()) {
elves.add(calories)
calories = 0
} else {
calor... | 0 | Kotlin | 0 | 0 | dd79aed1ecc65654cdaa9bc419d44043aee244b2 | 1,434 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day03.kt | joy32812 | 573,132,774 | false | {"Kotlin": 62766} |
fun main() {
fun Char.toScore() = when (this) {
in 'a'..'z' -> 1 + (this - 'a')
else -> 27 + (this - 'A')
}
fun part2(input: List<String>): Int {
return input.chunked(3).sumOf { (a, b, c) ->
a.toSet().intersect(b.toSet()).intersect(c.toSet()).first().toScore()
}... | 0 | Kotlin | 0 | 0 | 5e87958ebb415083801b4d03ceb6465f7ae56002 | 801 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/arrays/MergeSortedArray.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.arrays
/**
* You are given two integer arrays nums1 and nums2,
* sorted in non-decreasing order, and two integers m and n,
* representing the number of elements in nums1 and nums2 respectively.
*
* Merge nums1 and nums2 into a single array sorted in non-decreasing ... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 1,733 | algs4-leprosorium | MIT License |
src/main/kotlin/days/Day20.kt | julia-kim | 569,976,303 | false | null | package days
import readInput
fun main() {
fun Int.isOutOfBounds(upperLimit: Int): Boolean {
return (this < 0 || this > upperLimit)
}
fun Long.isOutOfBounds(upperLimit: Int): Boolean {
return (this < 0 || this > upperLimit)
}
fun part1(input: List<String>): Int {
val encr... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 2,657 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/ca/kiaira/advent2023/day6/Day6.kt | kiairatech | 728,913,965 | false | {"Kotlin": 78110} | package ca.kiaira.advent2023.day6
import ca.kiaira.advent2023.Puzzle
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.sqrt
/**
* Class responsible for solving the Day 6 puzzle of Advent of Code.
*
* This class extends the Puzzle class, providing implementations for parsing the input
* and solvi... | 0 | Kotlin | 0 | 1 | 27ec8fe5ddef65934ae5577bbc86353d3a52bf89 | 2,998 | kAdvent-2023 | Apache License 2.0 |
leetcode2/src/leetcode/powx-n.kt | hewking | 68,515,222 | false | null | package leetcode
/**
*50. Pow(x, n)
* https://leetcode-cn.com/problems/powx-n/
* @program: leetcode
* @description: ${description}
* @author: hewking
* @create: 2019-10-15 15:34
* 实现 pow(x, n) ,即计算 x 的 n 次幂函数。
示例 1:
输入: 2.00000, 10
输出: 1024.00000
示例 2:
输入: 2.10000, 3
输出: 9.26100
示例 3:
输入: 2.00000, -2
输出: 0.... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,750 | leetcode | MIT License |
advent-of-code-2021/src/code/day14/Main.kt | Conor-Moran | 288,265,415 | false | {"Kotlin": 53347, "Java": 14161, "JavaScript": 10111, "Python": 6625, "HTML": 733} | package code.day14
import java.io.File
import kotlin.math.max
import kotlin.math.min
val doDump = false
fun main() {
doIt("Day 14 Part 1: Test Input", "src/code/day14/test.input", part1)
doIt("Day 14 Part 1: Real Input", "src/code/day14/part1.input", part1)
doIt("Day 14 Part 2: Test Input", "src/code/day1... | 0 | Kotlin | 0 | 0 | ec8bcc6257a171afb2ff3a732704b3e7768483be | 4,449 | misc-dev | MIT License |
src/aoc2022/Day02.kt | miknatr | 576,275,740 | false | {"Kotlin": 413403} | package aoc2022
fun main() {
class Round(
// A for Rock, B for Paper, and C for Scissors
val attack: String,
// X for Rock, Y for Paper, and Z for Scissors
val defense: String
) {
val scoreForResponse get() = when (defense) {
"X" -> 1
"Y" -> 2
... | 0 | Kotlin | 0 | 0 | 400038ce53ff46dc1ff72c92765ed4afdf860e52 | 2,239 | aoc-in-kotlin | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions39.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import com.qiaoyuang.algorithm.round0.partition
fun test39() {
printlnResult(intArrayOf(1, 2, 3, 2, 2, 2, 5, 4, 2))
printlnResult(intArrayOf(0, 9, 9, 8, 2, 9, 5, 9, 9))
}
/**
* Questions 39: Find the number that more than a half in an IntArray
*/
private fun IntArray.... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,839 | Algorithm | Apache License 2.0 |
src/Day01.kt | rweekers | 573,305,041 | false | {"Kotlin": 38747} | fun main() {
fun part1(input: List<String>): Int {
return input.splitBy { it.isEmpty() }
.map { it.map { s -> s.toInt() } }
.maxOfOrNull { it.fold(0) { acc, curr -> acc + curr } } ?: throw IllegalArgumentException()
}
fun part2(input: List<String>): Int {
return inpu... | 0 | Kotlin | 0 | 1 | 276eae0afbc4fd9da596466e06866ae8a66c1807 | 810 | adventofcode-2022 | Apache License 2.0 |
src/Day21.kt | er453r | 572,440,270 | false | {"Kotlin": 69456} | fun main() {
class Monkey(val name: String, var value: Long?, val operation: String) {
fun yell(monkeys: Map<String, Monkey>): Long = if (value != null)
value!!
else {
val (name1, operator, name2) = operation.split(" ")
val monkey1 = monkeys[name1]!!.yell(monkeys)... | 0 | Kotlin | 0 | 0 | 9f98e24485cd7afda383c273ff2479ec4fa9c6dd | 4,084 | aoc2022 | Apache License 2.0 |
advent/src/test/kotlin/org/elwaxoro/advent/y2021/Dec09.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2021
import org.elwaxoro.advent.Coord
import org.elwaxoro.advent.PuzzleDayTester
import org.elwaxoro.advent.neighborCoords
import org.elwaxoro.advent.neighbors
import org.elwaxoro.advent.splitToInt
/**
* Smoke Basin
*/
class Dec09 : PuzzleDayTester(9, 2021) {
override fun part1(): ... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 2,046 | advent-of-code | MIT License |
src/Day23.kt | Riari | 574,587,661 | false | {"Kotlin": 83546, "Python": 1054} | fun main() {
data class Vector2(var x: Int, var y: Int) {
operator fun plus(other: Vector2): Vector2 = Vector2(x + other.x, y + other.y)
operator fun minus(other: Vector2): Vector2 = Vector2(x - other.x, y - other.y)
}
var paddingSize = 0
val directions = listOf(
listOf(Vector2(... | 0 | Kotlin | 0 | 0 | 8eecfb5c0c160e26f3ef0e277e48cb7fe86c903d | 4,492 | aoc-2022 | Apache License 2.0 |
src/Day09.kt | mcrispim | 573,449,109 | false | {"Kotlin": 46488} | import kotlin.Exception
fun main() {
data class Pos(var x: Int, var y: Int) {
fun move(dir: String) {
when (dir) {
"L" -> x--
"R" -> x++
"U" -> y++
"D" -> y--
"LU" -> { x--; y++ }
"RU" -> { x++; y++... | 0 | Kotlin | 0 | 0 | 5fcacc6316e1576a172a46ba5fc9f70bcb41f532 | 2,886 | AoC2022 | Apache License 2.0 |
src/Day11.kt | Vlisie | 572,110,977 | false | {"Kotlin": 31465} | import java.io.File
import java.lang.IllegalArgumentException
//inputbestand doorlopen en volgende waarden verzamelen voor monkeys: check
//innitial values, accumulator calculatie en test waarde.
//Dit in fold/reduce methode vullen met initial list waar accumulator wordt gebruikt. vervolgens test uitvoeren met deler g... | 0 | Kotlin | 0 | 0 | b5de21ed7ab063067703e4adebac9c98920dd51e | 3,324 | AoC2022 | Apache License 2.0 |
src/Day03.kt | MerickBao | 572,842,983 | false | {"Kotlin": 28200} | fun main() {
fun computer1(s: String): Int {
var cnt = 0
val n = s.length
val left = HashSet<Char>()
val right = HashSet<Char>()
for (i in 0 until n / 2) left.add(s[i])
for (i in n / 2 until n) right.add(s[i])
for (key in left) {
if (right.contain... | 0 | Kotlin | 0 | 0 | 70a4a52aa5164f541a8dd544c2e3231436410f4b | 1,423 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/dvdmunckhof/aoc/event2020/Day14.kt | dvdmunckhof | 318,829,531 | false | {"Kotlin": 195848, "PowerShell": 1266} | package com.dvdmunckhof.aoc.event2020
import com.dvdmunckhof.aoc.splitOnce
class Day14(private val input: List<String>) {
fun solvePart1(): Long {
val memory = mutableMapOf<Long, Long>()
runProgram { index, value, maskZeroes, maskOnes, _ ->
memory[index] = value and maskZeroes or mask... | 0 | Kotlin | 0 | 0 | 025090211886c8520faa44b33460015b96578159 | 2,128 | advent-of-code | Apache License 2.0 |
year2022/src/cz/veleto/aoc/year2022/Day11.kt | haluzpav | 573,073,312 | false | {"Kotlin": 164348} | package cz.veleto.aoc.year2022
import cz.veleto.aoc.core.AocDay
import cz.veleto.aoc.core.component6
class Day11(config: Config) : AocDay(config) {
override fun part1(): String {
val monkeys = parseMonkeys()
return simulate(monkeys, rounds = 20) { it / 3 }
}
override fun part2(): String ... | 0 | Kotlin | 0 | 1 | 32003edb726f7736f881edc263a85a404be6a5f0 | 2,776 | advent-of-pavel | Apache License 2.0 |
app/src/y2021/day11/Day11DumboOctopus.kt | henningBunk | 432,858,990 | false | {"Kotlin": 124495} | package y2021.day11
import common.Answers
import common.AocSolution
import common.annotations.AoCPuzzle
import kotlin.properties.Delegates
fun main(args: Array<String>) {
Day11DumboOctopus().solveThem()
}
@AoCPuzzle(2021, 11)
class Day11DumboOctopus : AocSolution {
override val answers = Answers(samplePart1 ... | 0 | Kotlin | 0 | 0 | 94235f97c436f434561a09272642911c5588560d | 3,117 | advent-of-code-2021 | Apache License 2.0 |
src/day8.kt | miiila | 725,271,087 | false | {"Kotlin": 77215} | import java.io.File
import java.util.function.Predicate
import kotlin.system.exitProcess
private const val DAY = 8
fun main() {
if (!File("./day${DAY}_input").exists()) {
downloadInput(DAY)
println("Input downloaded")
exitProcess(0)
}
val transformer = { x: String -> x }
val in... | 0 | Kotlin | 0 | 1 | 1cd45c2ce0822e60982c2c71cb4d8c75e37364a1 | 1,923 | aoc2023 | MIT License |
kotlin/0115-distinct-subsequences.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | /*
* DP bottom up
*/
class Solution {
fun numDistinct(s: String, t: String): Int {
val dp = Array(s.length + 1) { IntArray(t.length + 1) }
for (i in 0..s.length)
dp[i][t.length] = 1
for (i in s.length - 1 downTo 0) {
for (j in t.length - 1 downTo 0) {
... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 1,106 | leetcode | MIT License |
app/src/main/java/edu/hm/pedemap/density/strategy/RadiusNormalDistributedDensityCalculationStrategy.kt | matthinc | 342,849,905 | false | {"Jupyter Notebook": 266922, "Kotlin": 99317, "C++": 7484, "HTML": 2589} | package edu.hm.pedemap.density.strategy
import edu.hm.pedemap.density.Density
import edu.hm.pedemap.density.UTMLocation
import edu.hm.pedemap.density.sum
import kotlin.collections.HashMap
import kotlin.math.exp
import kotlin.math.floor
import kotlin.math.pow
class RadiusNormalDistributedDensityCalculationStrategy(val... | 0 | Jupyter Notebook | 0 | 2 | afe5d9adbb918141c520934cfe04637be0b880c7 | 3,081 | PeDeMaP | Apache License 2.0 |
src/main/kotlin/day03/Day03.kt | daniilsjb | 434,765,082 | false | {"Kotlin": 77544} | package day03
import java.io.File
fun main() {
val data = parse("src/main/kotlin/day03/Day03.txt")
val answer1 = part1(data)
val answer2 = part2(data)
println("🎄 Day 03 🎄")
println()
println("[Part 1]")
println("Answer: $answer1")
println()
println("[Part 2]")
println("... | 0 | Kotlin | 0 | 1 | bcdd709899fd04ec09f5c96c4b9b197364758aea | 1,378 | advent-of-code-2021 | MIT License |
src/Day10.kt | 6234456 | 572,616,769 | false | {"Kotlin": 39979} | import kotlin.math.abs
fun main() {
fun part1(input: List<String>): Int {
val queue = java.util.LinkedList<Int>()
input.forEach {
if (it == "noop"){
queue.add(0)
}else{
queue.add(0)
queue.add(it.split(" ").last().toInt())
... | 0 | Kotlin | 0 | 0 | b6d683e0900ab2136537089e2392b96905652c4e | 1,428 | advent-of-code-kotlin-2022 | Apache License 2.0 |
advent2022/src/main/kotlin/year2022/Day22.kt | bulldog98 | 572,838,866 | false | {"Kotlin": 132847} | package year2022
import AdventDay
import Point2D
import kotlin.math.sqrt
private fun List<String>.findAllWithChar(char: Char): Set<Point2D> = buildSet {
this@findAllWithChar.forEachIndexed { y, line ->
line.forEachIndexed { x, c ->
if (c == char) {
add(Point2D(x.toLong(), y.toL... | 0 | Kotlin | 0 | 0 | 02ce17f15aa78e953a480f1de7aa4821b55b8977 | 5,958 | advent-of-code | Apache License 2.0 |
google/2019/qualification_round/3/main_brute_force.kt | seirion | 17,619,607 | false | {"C++": 801740, "HTML": 42242, "Kotlin": 37689, "Python": 21759, "C": 3798, "JavaScript": 294} | import java.util.*
var n = 0
var limit = 0
val prime = arrayListOf(2)
var v = emptyList<Int>() // input
fun main(args: Array<String>) {
for (i in 3 until 10000 step 2) {
if (isPrime(i)) prime.add(i)
}
val t = readLine()!!.toInt()
(1..t).forEach {
print("Case #$it: ")
input()
... | 0 | C++ | 4 | 4 | a59df98712c7eeceabc98f6535f7814d3a1c2c9f | 2,538 | code | Apache License 2.0 |
src/Day03.kt | cypressious | 572,898,685 | false | {"Kotlin": 77610} | fun main() {
fun Char.prio() = if (isUpperCase()) {
52 - ('Z' - this)
} else {
26 - ('z' - this)
}
fun part1(input: List<String>): Int {
return input.sumOf {
val first = it.substring(0, it.length / 2)
val second = it.substring(it.length / 2)
... | 0 | Kotlin | 0 | 1 | 7b4c3ee33efdb5850cca24f1baa7e7df887b019a | 815 | AdventOfCode2022 | Apache License 2.0 |
2021/src/main/kotlin/de/skyrising/aoc2021/day4/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2021.day4
import de.skyrising.aoc.*
val test = TestInput("""
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
22 13 17 11 0
8 2 23 4 24
21 9 14 16 7
6 10 3 18 5
1 12 20 15 19
3 15 0 2 22
... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 4,138 | aoc | MIT License |
leetcode/src/main/kotlin/com/artemkaxboy/leetcode/p00/Leet1.kt | artemkaxboy | 513,636,701 | false | {"Kotlin": 547181, "Java": 13948} | package com.artemkaxboy.leetcode.p00
private class Leet1 {
fun twoSum(nums: IntArray, target: Int): IntArray {
for (i in nums.indices) {
getPairForSum(nums, i, target)
?.let { return intArrayOf(i, it) }
}
return intArrayOf()
}
private fun getPairForSum(n... | 0 | Kotlin | 0 | 0 | 516a8a05112e57eb922b9a272f8fd5209b7d0727 | 1,056 | playground | MIT License |
src/main/kotlin/days/day10.kt | josergdev | 573,178,933 | false | {"Kotlin": 20792} | package days
import java.io.File
fun String.parse() = when(this) {
"noop" -> sequence{ yield { (cycle, x): Pair<Int, Int> -> cycle + 1 to x } }
else -> this.replace("addx ", "").toInt().let {
sequence{
yield { (cycle, x): Pair<Int, Int> -> cycle + 1 to x }
yield { (cycle, x): P... | 0 | Kotlin | 0 | 0 | ea17b3f2a308618883caa7406295d80be2406260 | 927 | aoc-2022 | MIT License |
ceria/21/src/main/kotlin/Solution.kt | VisionistInc | 317,503,410 | false | null | import java.io.File
val allergenStart ="(contains "
fun main(args : Array<String>) {
val input = File(args.first()).readLines()
println("Solution 1: ${solution1(input)}")
println("Solution 2: ${solution2(input)}")
}
private fun solution1(input :List<String>) :Int {
var allergenToCandidates = mutableMapOf<Str... | 0 | Rust | 0 | 0 | 002734670384aa02ca122086035f45dfb2ea9949 | 3,264 | advent-of-code-2020 | MIT License |
src/main/kotlin/Day03.kt | SimonMarquis | 434,880,335 | false | {"Kotlin": 38178} | import Day03.Criteria.LEAST
import Day03.Criteria.MOST
import Day03.Fallback.ONES
import Day03.Fallback.ZEROS
class Day03(raw: List<String>) {
private val input: List<String> = raw
fun part1(): Int = input
.map { number -> number.map { char -> char.toBit() } }
.fold(IntArray(input.first().len... | 0 | Kotlin | 0 | 0 | 8fd1d7aa27f92ba352e057721af8bbb58b8a40ea | 2,703 | advent-of-code-2021 | Apache License 2.0 |
src/Day03.kt | Hwajun1323 | 574,962,608 | false | {"Kotlin": 6799} | fun main() {
val priorities = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
fun findSharedItem(items: String): String {
val (firstCompartment, secondCompartment) = items.chunked(items.length / 2)
return firstCompartment.filter { c -> secondCompartment.contains(c) }.toSet().joinToStri... | 0 | Kotlin | 0 | 0 | 667a8c7a0220bc10ddfc86b74e3e6de44b73d5dd | 1,120 | advent-of-code-2022 | Apache License 2.0 |
src/Day14.kt | joy32812 | 573,132,774 | false | {"Kotlin": 62766} | fun main() {
fun getGrid(input: List<String>, hasFloor: Boolean = false): Array<Array<Char>> {
val grid = Array(1000) { Array(1000) { '.' } }
var maxX = Int.MIN_VALUE
fun addPath(s: String, t: String) {
val (sy, sx) = s.split(",").map { it.toInt() }
val (ty, tx) = t.split(",").map { it.toInt... | 0 | Kotlin | 0 | 0 | 5e87958ebb415083801b4d03ceb6465f7ae56002 | 1,693 | aoc-2022-in-kotlin | Apache License 2.0 |
day23/part2.kts | bmatcuk | 726,103,418 | false | {"Kotlin": 214659} | // --- Part Two ---
// As you reach the trailhead, you realize that the ground isn't as slippery as
// you expected; you'll have no problem climbing up the steep slopes.
//
// Now, treat all slopes as if they were normal paths (.). You still want to
// make sure you have the most scenic hike possible, so continue to en... | 0 | Kotlin | 0 | 0 | a01c9000fb4da1a0cd2ea1a225be28ab11849ee7 | 3,915 | adventofcode2023 | MIT License |
src/main/kotlin/advent/day6/Lanternfish.kt | hofiisek | 434,171,205 | false | {"Kotlin": 51627} | package advent.day6
import advent.loadInput
import java.io.File
/**
* @author <NAME>
*/
@JvmInline
value class Fish(val age: Int)
fun part1(input: File) = loadFish(input).let(::makeThoseFishHaveRecursiveSex)
/**
* Just accumulate the fish in the list and count them
*/
fun makeThoseFishHaveRecursiveSex(fish: Li... | 0 | Kotlin | 0 | 2 | 3bd543ea98646ddb689dcd52ec5ffd8ed926cbbb | 2,070 | Advent-of-code-2021 | MIT License |
src/org/aoc2021/Day12.kt | jsgroth | 439,763,933 | false | {"Kotlin": 86732} | package org.aoc2021
import java.nio.file.Files
import java.nio.file.Path
object Day12 {
private fun solvePart1(lines: List<String>): Int {
val points = parseLines(lines)
return search("start", points)
}
private fun solvePart2(lines: List<String>): Int {
val points = parseLines(li... | 0 | Kotlin | 0 | 0 | ba81fadf2a8106fae3e16ed825cc25bbb7a95409 | 2,516 | advent-of-code-2021 | The Unlicense |
src/day24/second/Solution.kt | verwoerd | 224,986,977 | false | null | package day24.second
import day24.first.ErisTile
import day24.first.ErisTile.BUG
import day24.first.ErisTile.EMPTY
import day24.first.toTile
import tools.Coordinate
import tools.adjacentCoordinates
import tools.timeSolution
import tools.xRange
import tools.yRange
const val MINUTES = 200
val CENTER = Coordinate(2, 2)
... | 0 | Kotlin | 0 | 0 | 554377cc4cf56cdb770ba0b49ddcf2c991d5d0b7 | 3,933 | AoC2019 | MIT License |
src/main/kotlin/com/jacobhyphenated/advent2022/day7/Day7.kt | jacobhyphenated | 573,603,184 | false | {"Kotlin": 144303} | package com.jacobhyphenated.advent2022.day7
import com.jacobhyphenated.advent2022.Day
/**
* Day 7: No Space Left On Device
*
* To run the system update, your device needs more space.
* The puzzle input is a list of commands that provide the directory structure and file sizes on the device.
*/
class Day7: Day<Lis... | 0 | Kotlin | 0 | 0 | 9f4527ee2655fedf159d91c3d7ff1fac7e9830f7 | 3,884 | advent2022 | The Unlicense |
src/main/kotlin/aoc2023/Day04.kt | lukellmann | 574,273,843 | false | {"Kotlin": 175166} | package aoc2023
import AoCDay
// https://adventofcode.com/2023/day/4
object Day04 : AoCDay<Int>(
title = "Scratchcards",
part1ExampleAnswer = 13,
part1Answer = 20829,
part2ExampleAnswer = 30,
part2Answer = 12648035,
) {
private class Card(val id: Int, val winningNumbers: List<Int>, val myNumbe... | 0 | Kotlin | 0 | 1 | 344c3d97896575393022c17e216afe86685a9344 | 1,585 | advent-of-code-kotlin | MIT License |
src/main/kotlin/day21.kt | gautemo | 725,273,259 | false | {"Kotlin": 79259} | import shared.*
fun main() {
val input = Input.day(21)
println(day21A(input))
println(day21B(input))
}
fun day21A(input: Input, steps: Int = 64): Long {
val map = InfinityMap(input)
return possibleGardenPlots(map, steps)
}
/* Runs in a few hours */
fun day21B(input: Input, steps: Int = 26501365):... | 0 | Kotlin | 0 | 0 | 6862b6d7429b09f2a1d29aaf3c0cd544b779ed25 | 1,788 | AdventOfCode2023 | MIT License |
src/aoc21/Day03.kt | mihassan | 575,356,150 | false | {"Kotlin": 123343} | @file:Suppress("PackageDirectoryMismatch")
package aoc21.day03
import lib.Solution
import lib.Collections.histogram
enum class Day03Rating {
O2,
CO2
}
private val solution = object : Solution<List<String>, Int>(2021, "Day03") {
override fun parse(input: String): List<String> = input.lines()
override fun fo... | 0 | Kotlin | 0 | 0 | 698316da8c38311366ee6990dd5b3e68b486b62d | 1,862 | aoc-kotlin | Apache License 2.0 |
src/Day16.kt | Flame239 | 570,094,570 | false | {"Kotlin": 60685} | private fun input(): ValvesInput {
val file = "Day16"
val g: HashMap<Int, List<Edge>> = HashMap()
val flows = IntArray(readInput(file).size)
val idMap = readInput(file).mapIndexed { i, s ->
(s.substring(
"Valve ".length, "Valve ".length + 2
) to i).also { if (it.first == "AA"... | 0 | Kotlin | 0 | 0 | 27f3133e4cd24b33767e18777187f09e1ed3c214 | 5,374 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/de/nosswald/aoc/days/Day21.kt | 7rebux | 722,943,964 | false | {"Kotlin": 34890} | package de.nosswald.aoc.days
import de.nosswald.aoc.Day
// https://adventofcode.com/2023/day/21
object Day21 : Day<Int>(21, "Step Counter") {
private data class Point(val x: Int, val y: Int) {
fun neighbors(): Set<Point> = buildSet {
add(Point(x + 1, y))
add(Point(x - 1, y))
... | 0 | Kotlin | 0 | 1 | 398fb9873cceecb2496c79c7adf792bb41ea85d7 | 2,291 | advent-of-code-2023 | MIT License |
src/Day07.kt | rromanowski-figure | 573,003,468 | false | {"Kotlin": 35951} | object Day07 : Runner<Int, Int>(7, 95437, 24933642) {
override fun part1(input: List<String>): Int {
val fs = Directory(null, "")
buildFileSystem(fs, input)
return allDirectories(fs).filter { it.size() <= 100000 }.sumOf { it.size() }
}
private fun buildFileSystem(fs: Directory, in... | 0 | Kotlin | 0 | 0 | 6ca5f70872f1185429c04dcb8bc3f3651e3c2a84 | 3,656 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/test/kotlin/io/github/fbiville/solver/SolverTest.kt | fbiville | 129,937,320 | false | null | package io.github.fbiville.solver
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
class SolverTest {
@Test
fun `solves problems with maximum 1 move`() {
val plus2 = { n: Number -> (n.toInt() + 2) }.toNamedFunction("plus2")
val times2 = { n: Number -> (n.toInt() * 2) }.... | 4 | Kotlin | 0 | 0 | 490d55d8b6af8fc40704439c19effbcc1a8f9e1b | 3,061 | calculator-solver | Apache License 2.0 |
src/main/kotlin/me/camdenorrb/timorforest/tree/DecisionTree.kt | camdenorrb | 202,772,314 | false | null | package me.camdenorrb.timorforest.tree
import me.camdenorrb.timorforest.node.base.NodeBase
import kotlin.math.pow
class DecisionTree(val header: List<String>, val trainingData: List<List<Any>>) {
var root: NodeBase<*>
init {
root = buildTree(trainingData)
}
fun classCounts(rows: List<List... | 0 | Kotlin | 0 | 0 | b746f0ca27b587fbff4dcc08d97051f463cac53e | 4,431 | TimorForest | MIT License |
kotlin/src/katas/kotlin/leetcode/regex_matching/v4/RegexMatching.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.regex_matching.v4
import datsok.shouldEqual
import org.junit.jupiter.api.Test
class RegexMatching {
@Test fun `some examples`() {
"".matchRegex("") shouldEqual true
"a".matchRegex("a") shouldEqual true
"ab".matchRegex("ab") shouldEqual true
"a".matchRe... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 2,038 | katas | The Unlicense |
2022/src/main/kotlin/de/skyrising/aoc2022/day5/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2022.day5
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.chars.CharArrayList
private fun parseInput(input: PuzzleInput): Pair<List<String>, Array<CharArrayList>> {
val splitPoint = input.lines.indexOf("")
val setup = input.lines.subList(0, splitPoint - 1)
val moves = input.... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 1,665 | aoc | MIT License |
src/main/kotlin/io/github/pshegger/aoc/y2015/Y2015D6.kt | PsHegger | 325,498,299 | false | null | package io.github.pshegger.aoc.y2015
import io.github.pshegger.aoc.common.BaseSolver
import io.github.pshegger.aoc.common.Coordinate
import kotlin.math.max
class Y2015D6 : BaseSolver() {
override val year = 2015
override val day = 6
override fun part1(): Int =
parseInput().fold(List(GRID_SIZE * G... | 0 | Kotlin | 0 | 0 | 346a8994246775023686c10f3bde90642d681474 | 2,763 | advent-of-code | MIT License |
src/Day02.kt | baghaii | 573,918,961 | false | {"Kotlin": 11922} | fun main() {
fun part1(input: List<String>): Int {
var sum = 0
input.forEach{
val their = it[0]
val our = it[2]
val score = scoreRound(their, our)
sum += score
}
return sum
}
fun part2(input: List<String>): Int {
var s... | 0 | Kotlin | 0 | 0 | 8c66dae6569f4b269d1cad9bf901e0a686437469 | 2,825 | AdventOfCode2022 | Apache License 2.0 |
kotlin/src/_0004.kt | yunshuipiao | 179,794,004 | false | null | import org.testng.annotations.Test
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
val m = nums1.size
val n = nums2.size
if (m > n) {
return findMedianSortedArrays(nums2, nums1)
}
var low = 0
var high = m
while (low <= high) {
// 针对 nums1 进行 二分查找
... | 29 | Kotlin | 0 | 2 | 6b188a8eb36e9930884c5fa310517be0db7f8922 | 2,470 | rice-noodles | Apache License 2.0 |
src/main/kotlin/io/nozemi/aoc/solutions/year2021/day03/BinaryDiagnostic.kt | Nozemi | 433,882,587 | false | {"Kotlin": 92614, "Shell": 421} | package io.nozemi.aoc.solutions.year2021.day03
import io.nozemi.aoc.puzzle.Puzzle
import io.nozemi.aoc.solutions.year2021.day03.impl.countBitsInPosition
import io.nozemi.aoc.solutions.year2021.day03.impl.toEpsilonRateBinary
import io.nozemi.aoc.solutions.year2021.day03.impl.toGammaRateBinary
import kotlin.reflect.KFun... | 0 | Kotlin | 0 | 0 | fc7994829e4329e9a726154ffc19e5c0135f5442 | 4,373 | advent-of-code | MIT License |
src/main/kotlin/me/peckb/aoc/_2015/calendar/day19/Day19.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2015.calendar.day19
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import javax.inject.Inject
import kotlin.Int.Companion.MAX_VALUE
class Day19 @Inject constructor(private val generatorFactory: InputGeneratorFactory) {
fun partOne(filename: String) = generatorFactory.forFi... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 3,489 | advent-of-code | MIT License |
src/main/kotlin/me/grison/aoc/y2020/Day21.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc.y2020
import me.grison.aoc.*
class Day21 : Day(21, 2020) {
override fun title() = "Allergen Assessment"
override fun partOne(): Any {
val (allergens, ingredients) = load()
val allAllergens = allergens.values.fold(setOf<String>()) { a, b -> a.union(b) }
return (i... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 1,916 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/Day04.kt | Jenner-Zhl | 576,294,907 | false | {"Kotlin": 8369} | fun main() {
val regex = Regex("[-,]")
fun processInput(input: List<String>, block: (List<Int>) -> Boolean): Int {
var count = 0
input.forEach {line ->
val numbers = line.split(regex).map { it.toInt() }
if (block(numbers)) {
count++
print... | 0 | Kotlin | 0 | 0 | 5940b844155069e020d1859bb2d3fb06cb820981 | 1,010 | aoc | Apache License 2.0 |
src/com/hlq/leetcode/array/Question349.kt | HLQ-Struggle | 310,978,308 | false | null | package com.hlq.leetcode.array
/**
* @author HLQ_Struggle
* @date 2020/11/08
* @desc LeetCode 349. 两个数组的交集 https://leetcode-cn.com/problems/intersection-of-two-arrays/
*/
fun main() {
val nums1 = IntArray(4)
nums1[0] = 1
nums1[1] = 2
nums1[2] = 2
nums1[3] = 1
val nums2 = IntArray(2)
nu... | 0 | Kotlin | 0 | 2 | 76922f46432783218ddd34e74dbbf3b9f3c68f25 | 2,612 | LeetCodePro | Apache License 2.0 |
src/Day01.kt | mikrise2 | 573,939,318 | false | {"Kotlin": 62406} | import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
var maxSum = Int.MIN_VALUE
var tempSum = 0
for (index in input.indices) {
when {
input[index] == "" -> {
maxSum = max(tempSum, maxSum)
tempSum=0
... | 0 | Kotlin | 0 | 0 | d5d180eaf367a93bc038abbc4dc3920c8cbbd3b8 | 1,367 | Advent-of-code | Apache License 2.0 |
src/main/kotlin/Day05.kt | SimonMarquis | 724,825,757 | false | {"Kotlin": 30983} | class Day05(private val input: List<String>) {
private val seeds = input.first().substringAfter(":").trim().split(" ").map(String::toLong).also(::println)
private val almanac = input.asSequence().drop(2).foldInPlace(mutableListOf<Conversion>()) { line: String ->
when (line.firstOrNull()) {
... | 0 | Kotlin | 0 | 1 | 043fbdb271603c84b7e5eddcd0e8f323c6ebdf1e | 1,373 | advent-of-code-2023 | MIT License |
src/main/kotlin/nl/jackploeg/aoc/_2023/calendar/day19/Day19.kt | jackploeg | 736,755,380 | false | {"Kotlin": 318734} | package nl.jackploeg.aoc._2023.calendar.day19
import nl.jackploeg.aoc.generators.InputGenerator.InputGeneratorFactory
import nl.jackploeg.aoc.utilities.readStringFile
import java.util.*
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.min
class Day19 @Inject constructor(
private val generatorFac... | 0 | Kotlin | 0 | 0 | f2b873b6cf24bf95a4ba3d0e4f6e007b96423b76 | 9,242 | advent-of-code | MIT License |
Collections/GroupBy/src/TaskExtenstionGroupBy.kt | Rosietesting | 373,564,502 | false | {"HTML": 178715, "JavaScript": 147056, "Kotlin": 113135, "CSS": 105840} | fun main () {
/*
Example 1 : groupBy() takes a lambda function and returns a Map
In this map, each key is the lambda result and the corresponding value
is the List of elements on which this result is returned
*/
val numbers = listOf("one", "two", "three", "four", "five")
println(numbers.g... | 0 | HTML | 0 | 0 | b0aa518d220bb43c9398dacc8a6d9b6c602912d5 | 2,008 | KotlinKoans | MIT License |
src/main/kotlin/Day03.kt | alex859 | 573,174,372 | false | {"Kotlin": 80552} | fun main() {
val testInput = readInput("Day03_test.txt")
check(testInput.itemsPriority() == 157)
check(testInput.badgesPriority() == 70)
val input = readInput("Day03.txt")
println(input.itemsPriority())
println(input.badgesPriority())
}
fun String.itemsPriority() = lines().map { it.itemInCommo... | 0 | Kotlin | 0 | 0 | fbbd1543b5c5d57885e620ede296b9103477f61d | 1,198 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/leetcode_problems/medium/K-diffIinArray.kt | MhmoudAlim | 451,633,139 | false | {"Kotlin": 31257, "Java": 586} | package leetcode_problems.medium
import kotlin.math.abs
/*
https://leetcode.com/problems/k-diff-pairs-in-an-array/
* Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.
A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:
0 <= i, j ... | 0 | Kotlin | 0 | 0 | 31f0b84ebb6e3947e971285c8c641173c2a60b68 | 1,449 | Coding-challanges | MIT License |
src/main/kotlin/io/steinh/aoc/day05/Almanac.kt | daincredibleholg | 726,426,347 | false | {"Kotlin": 25396} | package io.steinh.aoc.day05
class Almanac(private val sourceData: Input) {
fun lowestLocation(): Long {
val list = mutableListOf<Long>()
sourceData.seeds.forEach {
val soil = getSoilForSeed(it)
val fertilizer = getFertilizerForSoil(soil)
val water = getWaterFor... | 0 | Kotlin | 0 | 0 | 4aa7c684d0e337c257ae55a95b80f1cf388972a9 | 3,239 | AdventOfCode2023 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NumSplits.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 | 3,082 | kotlab | Apache License 2.0 |
src/day_2.kt | gardnerdickson | 152,621,962 | false | null | import java.io.File
import kotlin.streams.toList
fun main(args: Array<String>) {
val input = "res/day_2_input.txt"
val answer1 = Day2.part1(input)
println("Part 1: $answer1")
val answer2 = Day2.part2(input)
println("Part 2: $answer2")
}
object Day2 {
fun part1(input: String): Int {
v... | 0 | Kotlin | 0 | 0 | 4a23ab367a87cae5771c3c8d841303b984474547 | 1,557 | advent-of-code-2015 | MIT License |
src/main/kotlin/day7/LuggageRules.kt | lukasz-marek | 317,632,409 | false | {"Kotlin": 172913} | package day7
data class Bag(val color: String)
data class Rule(val describedBag: Bag, val containedBags: Map<Bag, Int>)
private val nonEmptyRulePattern =
Regex("^(\\w+ \\w+) bags contain (.+)\\.")
private val emptyRulePattern = Regex("^(\\w+ \\w+) bags contain no other bags.")
fun parseRule(line: String): Rule =
... | 0 | Kotlin | 0 | 0 | a16e95841e9b8ff9156b54e74ace9ccf33e6f2a6 | 2,446 | aoc2020 | MIT License |
src/main/kotlin/08_Registers.kt | barta3 | 112,792,199 | false | null | class Parser {
fun parse(filename: String): ArrayList<Instruction> {
val reader = Parser::class.java.getResource(filename).openStream().bufferedReader()
val instructions = ArrayList<Instruction>()
reader.forEachLine { l ->
val parts = l.split(" ")
if (parts.size != ... | 0 | Kotlin | 0 | 0 | 51ba74dc7b922ac11f202cece8802d23011f34f1 | 2,804 | AdventOfCode2017 | MIT License |
src/Day05.kt | tstellfe | 575,291,176 | false | {"Kotlin": 8536} | fun main() {
fun List<String>.createStacks(separator: Int): MutableMap<Int, MutableList<String>> {
val stacks = mutableMapOf<Int, MutableList<String>>()
for (i in separator - 2 downTo 0) {
this[i].let { line ->
var key = 1
line.windowed(size = 3, step = 4, partialWindows = false) { stack... | 0 | Kotlin | 0 | 0 | e100ba705c8e2b83646b172d6407475c27f02eff | 1,975 | adventofcode-2022 | Apache License 2.0 |
src/main/kotlin/days/Day24.kt | butnotstupid | 571,247,661 | false | {"Kotlin": 90768} | package days
class Day24 : Day(24) {
override fun partOne(): Any {
val colNum = inputList.first().length - 2
val rowNum = inputList.size - 2
val blizzards = parseBlizzards()
val start = Point(-1, 0)
val fin = Point(rowNum, colNum - 1)
return route(start, fin, 0, bl... | 0 | Kotlin | 0 | 0 | 4760289e11d322b341141c1cde34cfbc7d0ed59b | 3,660 | aoc-2022 | Creative Commons Zero v1.0 Universal |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.