path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/main/kotlin/day07/Day07.kt | mdenburger | 433,731,891 | false | {"Kotlin": 8573} | package day07
import java.io.File
import kotlin.math.abs
import kotlin.math.min
fun main() {
println("Answer 1: " + minimumFuel(::constantCost))
println("Answer 2: " + minimumFuel(::increasingCost))
}
fun minimumFuel(cost: (positions: List<Int>, position: Int) -> Int): Int {
val positions = File("src/mai... | 0 | Kotlin | 0 | 0 | e890eec2acc2eea9c0432d092679aeb9de3f51b4 | 917 | aoc-2021 | MIT License |
src/com/aaron/helloalgorithm/algorithm/数组/_26_删除有序数组中的重复项.kt | aaronzzx | 431,740,908 | false | null | package com.aaron.helloalgorithm.algorithm.数组
import com.aaron.helloalgorithm.algorithm.LeetCode
import com.aaron.helloalgorithm.algorithm.Printer
/**
* # 26. 删除有序数组中的重复项
*
* 给你一个有序数组 nums ,请你 原地 删除重复出现的元素,使每个元素 只出现一次 ,返回删除后数组的新长度。
*
* 不要使用额外的数组空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成。
*
* 示例 1:
*
* ```
* 输入:... | 0 | Kotlin | 0 | 0 | 2d3d823b794fd0712990cbfef804ac2e138a9db3 | 3,022 | HelloAlgorithm | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year20/Day14.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year20
import com.grappenmaker.aoc.PuzzleSet
fun PuzzleSet.day14() = puzzle(day = 14) {
// Don't think I can generalize here
fun solve(solution: (memory: MutableMap<Long, Long>) -> Unit) =
mutableMapOf<Long, Long>().also(solution).values.sum().s()
fun solvePartOne() =... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 2,071 | advent-of-code | The Unlicense |
src/main/kotlin/day9/solver.kt | derekaspaulding | 317,756,568 | false | null | package day9
import java.io.File
fun solveFirstProblem(numbers: List<Long>, preambleLength: Int = 25): Long? = numbers
.subList(preambleLength, numbers.size)
.withIndex()
.find {
val (index, num) = it
val i2Start = index + 1
val end = index + preambleLength
for (i1 in index... | 0 | Kotlin | 0 | 0 | 0e26fdbb3415fac413ea833bc7579c09561b49e5 | 1,613 | advent-of-code-2020 | MIT License |
src/day14/Day14.kt | GrzegorzBaczek93 | 572,128,118 | false | {"Kotlin": 44027} | package day14
import readInput
import utils.withStopwatch
fun main() {
val testInput = readInput("input14_test")
withStopwatch { println(part1(testInput)) }
withStopwatch { println(part2(testInput)) }
val input = readInput("input14")
withStopwatch { println(part1(input)) }
withStopwatch { pri... | 0 | Kotlin | 0 | 0 | 543e7cf0a2d706d23c3213d3737756b61ccbf94b | 1,601 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/test/kotlin/chapter5/solutions/ex7/listing.kt | DavidGomesh | 680,857,367 | false | {"Kotlin": 204685} | package chapter5.solutions.ex7
import chapter3.List
import chapter5.Stream
import chapter5.Stream.Companion.cons
import chapter5.Stream.Companion.empty
import chapter5.toList
import io.kotest.matchers.shouldBe
import io.kotest.core.spec.style.WordSpec
//tag::append[]
fun <A> Stream<A>.append(sa: () -> Stream<A>): Str... | 0 | Kotlin | 0 | 0 | 41fd131cd5049cbafce8efff044bc00d8acddebd | 3,064 | fp-kotlin | MIT License |
src/main/kotlin/io/dmitrijs/aoc2022/Day07.kt | lakiboy | 578,268,213 | false | {"Kotlin": 76651} | package io.dmitrijs.aoc2022
class Day07(input: List<String>) {
private val fs = readFs(input)
fun puzzle1() = fs
.flatten()
.map { it.size }
.filter { it <= 100_000 }
.sum()
fun puzzle2(): Int {
val taken = fs.size
val free = 70_000_000 - taken
val ... | 0 | Kotlin | 0 | 1 | bfce0f4cb924834d44b3aae14686d1c834621456 | 2,023 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day12.kt | sushovan86 | 573,586,806 | false | {"Kotlin": 47064} | class HillClimbing private constructor(
private val areaElevationMap: MutableMap<Coordinate, Int>,
private val startCoordinate: Coordinate,
private val endCoordinate: Coordinate,
private val width: Int,
private val height: Int
) {
data class Coordinate(val x: Int = 0, val y: Int = 0)
priva... | 0 | Kotlin | 0 | 0 | d5f85b6a48e3505d06b4ae1027e734e66b324964 | 4,174 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day12.kt | jcornaz | 573,137,552 | false | {"Kotlin": 76776} | object Day12 {
@Suppress("UNUSED_PARAMETER")
fun part1(input: String): Long = TODO()
@Suppress("UNUSED_PARAMETER")
fun part2(input: String): Long = TODO()
private const val START_CHARACTER = 'S'
private const val GOAL_CHARACTER = 'E'
fun findPath(input: String): String {
val map ... | 1 | Kotlin | 0 | 0 | 979c00c4a51567b341d6936761bd43c39d314510 | 2,963 | aoc-kotlin-2022 | The Unlicense |
src/me/bytebeats/algo/kt/Solution8.kt | bytebeats | 251,234,289 | false | null | package me.bytebeats.algo.kt
import me.bytebeats.algo.kt.design.CustomFunction
import me.bytebeats.algs.ds.ListNode
import me.bytebeats.algs.ds.TreeNode
class Solution8 {
fun pathSum(root: TreeNode?, sum: Int): Int {//面试题04.12
if (root == null) {
return 0
}
return pathSum(root... | 0 | Kotlin | 0 | 1 | 7cf372d9acb3274003bb782c51d608e5db6fa743 | 34,384 | Algorithms | MIT License |
src/commonMain/kotlin/AI.kt | bdm2505 | 403,340,025 | false | {"Kotlin": 33540, "Shell": 1493} | import kotlin.random.Random
fun Board.getBestCourse(mins:Boolean = true): Pair<Int, Board.Turn>? {
var bestScore = Int.MAX_VALUE
val courses = mutableListOf<Board.Turn>()
getAllCourse(colorCourse).forEach {
val nextBoard = copy()
nextBoard.move(it.start, it.end)
var sc = nextBoard.... | 0 | Kotlin | 1 | 1 | f10170daec6fa2df370799ce558ef846528d713f | 3,083 | kotlin-chess | MIT License |
kotlin/src/katas/kotlin/sort/mergesort/MergeSort3.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.sort.mergesort
import nonstdlib.listOfInts
import nonstdlib.printed
import datsok.shouldEqual
import org.junit.Test
import kotlin.random.Random
class MergeSortTests3 {
@Test fun `trivial examples`() {
emptyList<Int>().mergeSort() shouldEqual emptyList()
listOf(1).mergeSort() s... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,822 | katas | The Unlicense |
src/Day22.kt | Flame239 | 570,094,570 | false | {"Kotlin": 60685} | private fun mm(): MonkeyMap {
val input = readInput("Day22")
val moves = input.takeLastWhile { it.isNotBlank() }[0]
val m = input.takeWhile { it.isNotBlank() }
val w = m.maxOf { it.length }
val map = Array(m.size) { IntArray(w) }
m.forEachIndexed { i, s ->
s.forEachIndexed { j, c ->
... | 0 | Kotlin | 0 | 0 | 27f3133e4cd24b33767e18777187f09e1ed3c214 | 6,566 | advent-of-code-2022 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/special/Questions9.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.special
fun test9() {
printlnResult(intArrayOf(10, 5, 2, 6), 100)
}
/**
* Questions 9: Given an IntArray and an integer k, find the count of all continues sub-array that product is less than k
*/
private infix fun IntArray.findCount(k: Int): Int {
require(isNotEmpty()) { "The... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 974 | Algorithm | Apache License 2.0 |
src/main/kotlin/com/tangledwebgames/tangledmath/rational/RationalExtensions.kt | l-e-webb | 432,786,844 | false | {"Kotlin": 18102} | package com.tangledwebgames.tangledmath.rational
import com.tangledwebgames.tangledmath.rational.Rational.Companion.rational
/* Rounding */
/**
* Returns the largest integer less than or equal to this [Rational]. Equivalent
* to [toInt].
*/
fun Rational.roundDown(): Int = toInt()
/**
* Returns the smallest inte... | 0 | Kotlin | 0 | 0 | 70be827718019464ec3fd38a002273dc51389bc7 | 2,906 | tangledmath | Apache License 2.0 |
src/day10/Day10.kt | martin3398 | 572,166,179 | false | {"Kotlin": 76153} | package day10
import readInput
import java.lang.Math.abs
sealed interface Instruction
object Noop : Instruction
data class AddX(val count: Int) : Instruction
fun main() {
fun simulate(instructions: List<Instruction>, callback: (cycle: Int, registerValue: Int) -> Unit) {
var cycle = 1
var regist... | 0 | Kotlin | 0 | 0 | 4277dfc11212a997877329ac6df387c64be9529e | 2,243 | advent-of-code-2022 | Apache License 2.0 |
src/Day06.kt | monsterbrain | 572,819,542 | false | {"Kotlin": 42040} | import java.util.*
fun main() {
fun part1(input: String): Int {
var firstIndex = -1
input.forEachIndexed { index, char ->
if (index >= 4) {
// check last received 4 char
val last4 = input.substring(index-4, index)
if (firstIndex == -1 && l... | 0 | Kotlin | 0 | 0 | 3a1e8615453dd54ca7c4312417afaa45379ecf6b | 1,819 | advent-of-code-kotlin-2022-Solutions | Apache License 2.0 |
src/day04/Code.kt | fcolasuonno | 572,734,674 | false | {"Kotlin": 63451, "Dockerfile": 1340} | package day04
import readInput
operator fun IntRange.contains(other: IntRange) = first in other && last in other
fun IntRange.overlaps(other: IntRange) = first <= other.last && last >= other.first
fun String.toIntRange(delimiter: Char = '-') = split(delimiter).map { it.toInt() }.let { it[0]..it[1] }
typealias Day04... | 0 | Kotlin | 0 | 0 | 9cb653bd6a5abb214a9310f7cac3d0a5a478a71a | 1,014 | AOC2022 | Apache License 2.0 |
src/main/kotlin/com/anahoret/aoc2022/day07/main.kt | mikhalchenko-alexander | 584,735,440 | false | null | package com.anahoret.aoc2022.day07
import java.io.File as JavaIoFile
class FileTree {
enum class Command {
CD, LS;
companion object {
fun parse(str: String): Command {
return when {
str.startsWith("\$ cd") -> CD
str.startsWith("... | 0 | Kotlin | 0 | 0 | b8f30b055f8ca9360faf0baf854e4a3f31615081 | 4,323 | advent-of-code-2022 | Apache License 2.0 |
src/Day04.kt | diesieben07 | 572,879,498 | false | {"Kotlin": 44432} | private val file = "Day04"
private data class CleaningPair(val a: IntRange, val b: IntRange) {
fun oneFullyContainsTheOther(): Boolean {
return b.first in a && b.last in a || a.first in b && a.last in b
}
fun rangesOverlap(): Boolean {
return a.first <= b.last && b.first <= a.last
}
... | 0 | Kotlin | 0 | 0 | 0b9993ef2f96166b3d3e8a6653b1cbf9ef8e82e6 | 944 | aoc-2022 | Apache License 2.0 |
src/day1/Day01.kt | dinoolivo | 573,723,263 | false | null | package day1
import readInput
fun main() {
fun part1(input: List<Int>): Int {
return input.first()
}
fun part2(input: List<Int>): Int {
return input.take(3).sum()
}
fun clusterByCondition(input: List<String>): List<List<Int>> =
input.foldIndexed(arrayListOf(ArrayList<Int>... | 0 | Kotlin | 0 | 0 | 6e75b42c9849cdda682ac18c5a76afe4950e0c9c | 1,016 | aoc2022-kotlin | Apache License 2.0 |
src/main/aoc2019/Day12.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2019
import MyMath
import kotlin.math.abs
class Day12(input: List<String>) {
data class Moon(val pos: MutableList<Int>, val vel: MutableList<Int>) {
fun applyGravity(other: Moon) {
(0..2).forEach {
vel[it] += if (pos[it] < other.pos[it]) 1 else if (pos[it] > other.p... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 3,265 | aoc | MIT License |
src/kickstart2020/h/BoringNumbers.kt | vubogovich | 256,984,714 | false | null | package kickstart2020.h
import kotlin.math.max
private val power5 = Array(20) { 1L }
fun main() {
val inputFileName = "src/kickstart2020/h/BoringNumbers.in"
java.io.File(inputFileName).takeIf { it.exists() }?.also { System.setIn(it.inputStream()) }
for (i in 1 until power5.size) power5[i] = power5[i - 1... | 0 | Kotlin | 0 | 0 | fc694f84bd313cc9e8fcaa629bafa1d16ca570fb | 1,101 | kickstart | MIT License |
src/main/kotlin/Day4.kt | corentinnormand | 725,992,109 | false | {"Kotlin": 40576} | class Day4 : Aoc("day4.txt") {
private fun strToSet(string: String) =
string.split(" ")
.map { it.trim() }
.filter { it.isNotBlank() }
.map { it.toInt() }
.toSet()
override fun one() {
val input = readFile("day4.txt").lines()
val result = ... | 0 | Kotlin | 0 | 0 | 2b177a98ab112850b0f985c5926d15493a9a1373 | 1,512 | aoc_2023 | Apache License 2.0 |
src/me/bytebeats/algo/kt/Solution9.kt | bytebeats | 251,234,289 | false | null | package me.bytebeats.algo.kt
import java.util.*
import me.bytebeats.algs.ds.ListNode
import me.bytebeats.algs.ds.TreeNode
class Solution9 {
fun avoidFlood(rains: IntArray): IntArray {//1488
val ans = IntArray(rains.size)
val lakes = mutableMapOf<Int, Int>()
val todo = sortedSetOf<Int>()
... | 0 | Kotlin | 0 | 1 | 7cf372d9acb3274003bb782c51d608e5db6fa743 | 22,544 | Algorithms | MIT License |
src/Day03.kt | pmatsinopoulos | 730,162,975 | false | {"Kotlin": 10493} | import kotlin.io.path.Path
import kotlin.io.path.readLines
fun buildMatrix(inputFile: String): Array<CharArray> {
val fileLines = Path("src/$inputFile").readLines()
val numberOfColumns = fileLines.first().length
val matrix = Array(fileLines.size) { rowIndex ->
CharArray(numberOfColumns) { columnInd... | 0 | Kotlin | 0 | 0 | f913207842b2e6491540654f5011127d203706c6 | 5,931 | advent-of-code-kotlin-template | Apache License 2.0 |
src/Day03.kt | Sagolbah | 573,032,320 | false | {"Kotlin": 14528} | fun main() {
fun getPriority(symbol: Char) : Int {
return if (symbol in 'a'..'z') {
symbol - 'a' + 1
} else {
symbol - 'A' + 27
}
}
fun part1(input: List<String>): Int {
var ans = 0
for (line in input) {
val fst = line.substring(0,... | 0 | Kotlin | 0 | 0 | 893c1797f3995c14e094b3baca66e23014e37d92 | 913 | advent-of-code-kt | Apache License 2.0 |
src/main/kotlin/day16.kt | gautemo | 572,204,209 | false | {"Kotlin": 78294} | import shared.getText
/*
This day was hard. This code is slow. This code is messy. But it works if you want to wait some hours.
Not sure if I want to spend more time on it, making it more readable or re-thinking the solution to be faster.
*/
fun main() {
val input = getText("day16.txt")
println(day16A(input)... | 0 | Kotlin | 0 | 0 | bce9feec3923a1bac1843a6e34598c7b81679726 | 9,055 | AdventOfCode2022 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/StoneGame2.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 | 2,036 | kotlab | Apache License 2.0 |
advent-of-code2015/src/main/kotlin/day24/Advent24.kt | REDNBLACK | 128,669,137 | false | null | package day24
import combinations
import mul
import parseInput
import splitToLines
/**
--- Day 24: It Hangs in the Balance ---
It's Christmas Eve, and Santa is loading up the sleigh for this year's deliveries. However, there's one small problem: he can't get the sleigh to balance. If it isn't balanced, he can't defy... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 4,965 | courses | MIT License |
src/Day01.kt | cgeesink | 573,018,348 | false | {"Kotlin": 10745} | fun main() {
fun part1(input: List<String>): Int {
var currentElve = 0
var maxElve = 0
for (line in input) {
if (line.isBlank()) {
if (currentElve > maxElve) {
maxElve = currentElve
}
currentElve = 0
... | 0 | Kotlin | 0 | 0 | 137fb9a9561f5cbc358b7cfbdaf5562c20d6b10d | 1,648 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/jaspervanmerle/aoc2021/day/Day22.kt | jmerle | 434,010,865 | false | {"Kotlin": 60581} | package com.jaspervanmerle.aoc2021.day
import kotlin.math.max
import kotlin.math.min
class Day22 : Day("655005", "1125649856443608") {
private data class Cuboid(val xRange: IntRange, val yRange: IntRange, val zRange: IntRange) {
val volume = xRange.size() * yRange.size() * zRange.size()
fun overl... | 0 | Kotlin | 0 | 0 | dcac2ac9121f9bfacf07b160e8bd03a7c6732e4e | 3,677 | advent-of-code-2021 | MIT License |
src/main/kotlin/com/kishor/kotlin/ds/BinaryTree.kt | kishorsutar | 276,212,164 | false | null | package com.kishor.kotlin.ds
import java.util.*
import kotlin.math.abs
import kotlin.math.max
open class BinaryTree(value: Int) {
var value = value
var left: BinaryTree? = null
var right: BinaryTree? = null
}
fun branchSums(root: BinaryTree): List<Int> {
val listOfSum = mutableListOf<Int>()
getBr... | 0 | Kotlin | 0 | 0 | 6672d7738b035202ece6f148fde05867f6d4d94c | 5,121 | DS_Algo_Kotlin | MIT License |
aoc-day4/src/Board.kt | rnicoll | 438,043,402 | false | {"Kotlin": 90620, "Rust": 1313} | import kotlin.collections.ArrayList
class Board(private val rows: Array<Row>) {
companion object {
fun read(input: Iterator<String>): Board {
val rows = ArrayList<Row>(Day4.BOARD_SIZE)
for (i in 0 until Day4.BOARD_SIZE) {
rows.add(Row.parse(input.next()))
... | 0 | Kotlin | 0 | 0 | 8c3aa2a97cb7b71d76542f5aa7f81eedd4015661 | 2,073 | adventofcode2021 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FindArrayDifference.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 | 2,957 | kotlab | Apache License 2.0 |
2023/src/day10/day10.kt | Bridouille | 433,940,923 | false | {"Kotlin": 171124, "Go": 37047} | package day10
import GREEN
import RESET
import printTimeMillis
import readInput
private fun findStart(table: Array<CharArray>): List<Int> {
for (y in table.indices) {
for (x in table[y].indices) {
if (table[y][x] == 'S') return listOf(x, y)
}
}
throw IllegalStateException("No S... | 0 | Kotlin | 0 | 2 | 8ccdcce24cecca6e1d90c500423607d411c9fee2 | 4,984 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem2316/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2316
/**
* LeetCode page: [2316. Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph/);
*/
class Solution {
/* Complexity:
* Time O(n+E) and Space O(n+E) where E is the size of ed... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,038 | hj-leetcode-kotlin | Apache License 2.0 |
src/cn/leetcode/codes/simple145/Simple145.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple145
import cn.leetcode.codes.common.TreeNode
import cn.leetcode.codes.createTreeNode
import cn.leetcode.codes.out
import java.util.*
import kotlin.collections.ArrayList
fun main() {
val nums = arrayOf<Int?>(1,2,3)
val treeNode = createTreeNode(nums)
val re = postorderTrave... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 1,803 | LeetCodeSimple | Apache License 2.0 |
src/test/kotlin/be/brammeerten/y2022/Day16Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2022
import be.brammeerten.extractRegexGroups
import be.brammeerten.graphs.Dijkstra
import be.brammeerten.graphs.Graph
import be.brammeerten.graphs.Node
import be.brammeerten.graphs.Vertex
import be.brammeerten.readFile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 6,917 | Advent-of-Code | MIT License |
src/main/Day13.kt | ssiegler | 572,678,606 | false | {"Kotlin": 76434} | package day13
import utils.readInput
import java.io.Reader
import java.io.StringReader
sealed interface Packet : Comparable<Packet> {
data class Number(val value: Int) : Packet {
override fun compareTo(other: Packet): Int =
when (other) {
is Number -> value.compareTo(other.valu... | 0 | Kotlin | 0 | 0 | 9133485ca742ec16ee4c7f7f2a78410e66f51d80 | 4,297 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | StephenVinouze | 572,377,941 | false | {"Kotlin": 55719} | import java.lang.IllegalArgumentException
enum class Shape(
val value: Int
) {
Rock(1),
Paper(2),
Scissors(3),
}
enum class Result(val score: Int) {
Loss(0),
Draw(3),
Win(6),
}
fun main() {
fun roundScorePart1(round: String): Int {
val shapes = round.split(" ").take(2)
... | 0 | Kotlin | 0 | 0 | 11b9c8816ded366aed1a5282a0eb30af20fff0c5 | 3,048 | AdventOfCode2022 | Apache License 2.0 |
src/Day03.kt | konclave | 573,548,763 | false | {"Kotlin": 21601} | fun main() {
fun pointCount(code: Int): Int {
return code - if (code < 97) 38 else 96
}
fun solve1(input: List<String>): Int {
return input.sumOf {
val (cmp1, cmp2) = it.chunked(it.length / 2)
var res = 0
for (c in cmp1) {
if (cmp2.contain... | 0 | Kotlin | 0 | 0 | 337f8d60ed00007d3ace046eaed407df828dfc22 | 896 | advent-of-code-2022 | Apache License 2.0 |
src/Day24.kt | astrofyz | 572,802,282 | false | {"Kotlin": 124466} | fun main() {
class Blizzard(var pos: Pair<Int, Int>, var step: Pair<Int, Int>){}
fun parseBlizzards(input: List<String>): MutableList<Blizzard> {
var Blizzards = mutableListOf<Blizzard>()
for ((row, line) in input.withIndex()){
for ((col, elem) in line.withIndex()){
... | 0 | Kotlin | 0 | 0 | a0bc190b391585ce3bb6fe2ba092fa1f437491a6 | 5,072 | aoc22 | Apache License 2.0 |
src/main/kotlin/d7/D7_1.kt | MTender | 734,007,442 | false | {"Kotlin": 108628} | package d7
import input.Input
const val CARD_LABELS = "AKQJT98765432"
data class Hand(
val cards: String,
val bid: Int
) : Comparable<Hand> {
override fun compareTo(other: Hand): Int {
val typeDiff = this.getTypeStrength() - other.getTypeStrength()
if (typeDiff != 0) return typeDiff
... | 0 | Kotlin | 0 | 0 | a6eec4168b4a98b73d4496c9d610854a0165dbeb | 1,700 | aoc2023-kotlin | MIT License |
src/Utils.kt | jorander | 571,715,475 | false | {"Kotlin": 28471} | import java.io.File
import java.math.BigInteger
import java.security.MessageDigest
/**
* Reads lines from the given input txt file.
*/
fun readInput(name: String) = File("src", "$name.txt").readLines()
/**
* Converts string to md5 hash.
*/
fun String.md5(): String = BigInteger(1, MessageDigest.getInstance("MD5").... | 0 | Kotlin | 0 | 0 | 1681218293cce611b2c0467924e4c0207f47e00c | 3,155 | advent-of-code-2022 | Apache License 2.0 |
advent/src/test/kotlin/org/elwaxoro/advent/y2022/Dec07.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2022
import org.elwaxoro.advent.PuzzleDayTester
/**
* Day 7: No Space Left On Device
*/
class Dec07 : PuzzleDayTester(7, 2022) {
/**
* Find directories with total size less than 100000 and add them up
*/
override fun part1(): Any = loader().findDirs().map { it.calcSiz... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 3,214 | advent-of-code | MIT License |
src/main/kotlin/clockvapor/telegram/markov/Utils.kt | ClockVapor | 136,247,129 | false | {"Kotlin": 24060} | package clockvapor.telegram.markov
import clockvapor.markov.MarkovChain
val MarkovChain.wordCounts: Map<String, Int>
get() {
val map = hashMapOf<String, Int>()
for ((_, dataMap) in data) {
for ((word, count) in dataMap) {
val sanitized = word.sanitize()
... | 1 | Kotlin | 4 | 5 | b72a68dd2cedd3c19f53fcdb5b3c89f7f1450cd7 | 1,751 | markov-telegram-bot | MIT License |
src/day05/Day05.kt | chskela | 574,228,146 | false | {"Kotlin": 9406} | package day05
import java.io.File
class Stack<T> {
private val mutableList = mutableListOf<T>()
fun push(vararg element: T) {
mutableList.addAll(element)
}
fun pop(): T? {
return if (mutableList.isNotEmpty()) {
mutableList.removeLast()
} else {
null
... | 0 | Kotlin | 0 | 0 | 951d38a894dcf0109fd0847eef9ff3ed3293fca0 | 3,049 | adventofcode-2022-kotlin | Apache License 2.0 |
2022/src/main/kotlin/org/suggs/adventofcode/Day11MonkeyInTheMiddle.kt | suggitpe | 321,028,552 | false | {"Kotlin": 156836} | package org.suggs.adventofcode
import org.slf4j.LoggerFactory
object Day11MonkeyInTheMiddle {
private val log = LoggerFactory.getLogger(this::class.java)
fun countMonkeyInspectionsFrom(data: List<String>, times: Int, worryAction: (Long) -> Long): Long {
val monkeys = data.map { buildMonkeyFrom(it.sp... | 0 | Kotlin | 0 | 0 | 9485010cc0ca6e9dff447006d3414cf1709e279e | 2,472 | advent-of-code | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LongestCycle.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,370 | kotlab | Apache License 2.0 |
src/Day01.kt | fex42 | 575,013,600 | false | {"Kotlin": 4342} | fun main() {
println(listOf(1, 5, 2, 4, 3).sortedDescending().take(3))
fun maxCals(input: String) =
input.split("\n\n").map { elf ->
elf.split("\n").map { it.toInt() }
}.map { it.sum() }
.max()
fun part1(input: String): Int {
return maxCals(input)
}
... | 0 | Kotlin | 0 | 0 | dd5d9ff58afc615bcac0fd76b86e737833eb7576 | 765 | AuC-2022 | Apache License 2.0 |
src/Day07.kt | lonskiTomasz | 573,032,074 | false | {"Kotlin": 22055} | fun main() {
fun dirs(input: List<String>): MutableMap<String, Long> {
var curr = "."
val dirs: MutableMap<String, Long> = mutableMapOf() // path - size
input.forEach { line ->
when {
"""\$ cd /""".toRegex().matches(line) -> curr = "."
"""\$ cd \... | 0 | Kotlin | 0 | 0 | 9e758788759515049df48fb4b0bced424fb87a30 | 2,021 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/test/kotlin/chapter3/solutions/ex12/listing.kt | DavidGomesh | 680,857,367 | false | {"Kotlin": 204685} | package chapter3.solutions.ex12
import chapter3.List
import chapter3.foldLeft
import chapter3.foldRight
import io.kotest.matchers.shouldBe
import io.kotest.core.spec.style.WordSpec
// tag::init[]
fun <A, B> foldLeftR(xs: List<A>, z: B, f: (B, A) -> B): B =
foldRight(xs, { b: B -> b }, { a, g -> { b -> g(f(b, a)) ... | 0 | Kotlin | 0 | 0 | 41fd131cd5049cbafce8efff044bc00d8acddebd | 1,653 | fp-kotlin | MIT License |
src/Day04.kt | theofarris27 | 574,591,163 | false | null | fun main() {
fun part1(input: List<String>): Int {
var sum = 0
for (lines in input) {
var half1 = lines.substring(0, lines.indexOf(","))
var half1num1 = half1.substring(0, half1.indexOf("-")).toInt()
var half1num2 = half1.substring(half1.indexOf("-") + 1).toInt()
... | 0 | Kotlin | 0 | 0 | cf77115471a7f1caeedf13ae7a5cdcbdcec3eab7 | 2,026 | AdventOfCode | Apache License 2.0 |
solutions/src/LengthOfLongestFibSequence.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | class LengthOfLongestFibSequence {
//https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/description/
fun lenLongestFibSubseq(A: IntArray): Int {
var longest = 0
var index = 0
// O(n)
val valuesToIndex = A.mapIndexed { index, i -> Pair(i, index) }.associateBy({ ... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 1,623 | leetcode-solutions | MIT License |
src/Day18.kt | tigerxy | 575,114,927 | false | {"Kotlin": 21255} | fun main() {
fun part1(input: List<String>): Int =
(0..2)
.flatMap { dimension ->
input
.parse()
.groupBy { it.filterIndexed { idx, _ -> idx != dimension }.toPair() }
.map { it.value.map { it[dimension] }.sorted() }
... | 0 | Kotlin | 0 | 1 | d516a3b8516a37fbb261a551cffe44b939f81146 | 1,209 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day03.kt | gnuphobia | 578,967,785 | false | {"Kotlin": 17559} | fun main() {
fun part1(input: List<String>): Int {
var score: Int = 0
for (contents: String in input) {
var ruck: Rucksack = Rucksack(contents)
score += ruck.itemPriority
}
return score
}
fun part2(input: List<String>): Int {
var journey: Mut... | 0 | Kotlin | 0 | 0 | a1b348ec33f85642534c46af8c4a69e7b78234ab | 1,329 | aoc2022kt | Apache License 2.0 |
2020/src/main/kotlin/sh/weller/adventofcode/twentytwenty/Day21.kt | Guruth | 328,467,380 | false | {"Kotlin": 188298, "Rust": 13289, "Elixir": 1833} | package sh.weller.adventofcode.twentytwenty
fun List<String>.day21Part2(): String {
val allergenIngredientsPairs = this.parseInput()
val allergenSet = allergenIngredientsPairs.flatMap { it.first }.toSet()
// All possible ingredients that contain allergens
val ingredientsThatAppearForEveryAllergen = m... | 0 | Kotlin | 0 | 0 | 69ac07025ce520cdf285b0faa5131ee5962bd69b | 4,123 | AdventOfCode | MIT License |
2021/src/day01/day1.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day01
import java.io.File
fun main() {
// println(findIncreasesSlidingWindow(listOf(199, 200, 208, 210, 200, 207, 240, 269, 260, 263),
// 3))
println(findIncreasesFold(listOf(199, 200, 208, 210, 200, 207, 240, 269, 260, 263)))
val lineList = mutableListOf<Int>()
File("src/day01","day1.t... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 1,431 | adventofcode | Apache License 2.0 |
advent-of-code-2023/src/Day14.kt | osipxd | 572,825,805 | false | {"Kotlin": 141640, "Shell": 4083, "Scala": 693} | import lib.matrix.*
private typealias Platform = Matrix<Char>
private typealias PlatformSnapshot = List<String>
private const val DAY = "Day14"
fun main() {
fun testInput() = readInput("${DAY}_test")
fun input() = readInput(DAY)
"Part 1" {
part1(testInput()) shouldBe 136
measureAnswer { ... | 0 | Kotlin | 0 | 5 | 6a67946122abb759fddf33dae408db662213a072 | 3,373 | advent-of-code | Apache License 2.0 |
src/Day09.kt | cerberus97 | 579,910,396 | false | {"Kotlin": 11722} | import kotlin.math.abs
import kotlin.system.exitProcess
fun main() {
data class Point(val x: Int, val y: Int)
fun Point.move(dir: Char): Point = when (dir) {
'R' -> Point(x + 1, y)
'L' -> Point(x - 1, y)
'D' -> Point(x, y + 1)
'U' -> Point(x, y - 1)
else -> exitProcess(-1)
}
fun findTailP... | 0 | Kotlin | 0 | 0 | ed7b5bd7ad90bfa85e868fa2a2cdefead087d710 | 1,785 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/day02/Day02.kt | iliascholl | 572,982,464 | false | {"Kotlin": 8373} | package day02
import readInput
fun main() {
val left = "ABC"
val right = "XYZ"
val choices = left.length
fun part1(input: List<String>) = input.map { strategy ->
strategy.split(" ").let {
left.indexOf(it.first()) to right.indexOf(it.last())
}
}.sumOf { (first, second) ... | 0 | Kotlin | 0 | 1 | 26db12ddf4731e4ee84f45e1dc4385707f9e1d05 | 997 | advent-of-code-kotlin | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/FindTheDifference.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
/**
* 389. 找不同
*
* 给定两个字符串 s 和 t,它们只包含小写字母。
*
* 字符串 t 由字符串 s 随机重排,然后在随机位置添加一个字母。
*
* 请找出在 t 中被添加的字母。
*
* 示例 1:
*
* 输入:s = "abcd", t = "abcde"
* 输出:"e"
* 解释:'e' 是那个被添加的字母。
* 示例 2:
*
* 输入:s = "", t = "y"
* 输出:"y"
* 示例 3:
*
* 输入:s = "a", t = "aa"
* 输出:"a"
* 示例 4:... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 3,330 | daily_algorithm | Apache License 2.0 |
kotlin/src/main/kotlin/de/p58i/advent-02.kt | mspoeri | 573,120,274 | false | {"Kotlin": 31279} | package de.p58i
import java.io.File
import java.util.LinkedList
val permutations = setOf(
mapOf(
"X" to Move.ROCK,
"Y" to Move.PAPER,
"Z" to Move.SCISSORS,
),
mapOf(
"X" to Move.ROCK,
"Y" to Move.SCISSORS,
... | 0 | Kotlin | 0 | 1 | 62d7f145702d9126a80dac6d820831eeb4104bd0 | 4,686 | Advent-of-Code-2022 | MIT License |
src/main/kotlin/day4.kt | gautemo | 433,582,833 | false | {"Kotlin": 91784} | import shared.getText
fun playBingo(input: String, looseMode: Boolean = false): Int{
val sections = input.trim().split("\n\n")
val numbers = sections.first().split(",").map { it.toInt() }
val boards = sections.drop(1).map { Board(it) }
for(number in numbers){
for(board in boards.filter { !it.bi... | 0 | Kotlin | 0 | 0 | c50d872601ba52474fcf9451a78e3e1bcfa476f7 | 1,768 | AdventOfCode2021 | MIT License |
src/main/java/com/barneyb/aoc/aoc2022/day16/ProboscideaVolcanium.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2022.day16
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toSlice
import com.barneyb.util.HashMap
import com.barneyb.util.Queue
import com.barneyb.util.Stack
fun main() {
Solver.execute(
::parse,
::maximumPressureRelease, // 1880
::maximumPressure... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 4,498 | aoc-2022 | MIT License |
src/adventofcode/blueschu/y2017/day07/solution.kt | blueschu | 112,979,855 | false | null | package adventofcode.blueschu.y2017.day07
import java.io.File
import java.lang.RuntimeException
import kotlin.test.assertEquals
fun input(): List<String> =
File("resources/y2017/day07.txt").useLines { it.toList() }
fun runDemoAssertions() {
val demoTower = parseTower(
listOf(
"pbga (66)",... | 0 | Kotlin | 0 | 0 | 9f2031b91cce4fe290d86d557ebef5a6efe109ed | 4,040 | Advent-Of-Code | MIT License |
src/main/kotlin/me/peckb/aoc/_2023/calendar/day19/Day19.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2023.calendar.day19
import me.peckb.aoc._2023.calendar.day19.Rule.*
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
class Day19 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
fun partOne(filename: String) = genera... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 3,452 | advent-of-code | MIT License |
y2021/src/main/kotlin/adventofcode/y2021/Day17.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2021
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Vec2
object Day17 : AdventSolution(2021, 17, "Trick Shot") {
override fun solvePartOne(input: String): Int {
val (_,yT) = parse(input)
return yT.first * (yT.first+1) / 2
}
override fun solvePa... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,140 | advent-of-code | MIT License |
src/day03/Day03.kt | martindacos | 572,700,466 | false | {"Kotlin": 12412} | package day03
import readInput
fun main() {
fun calculatePriority(intersect: Set<Char>): Int {
val number = if (intersect.first().isUpperCase()) {
intersect.first().code - 38
} else {
intersect.first().code - 96
}
return number
}
fun part1(input: L... | 0 | Kotlin | 0 | 0 | f288750fccf5fbc41e8ac03598aab6a2b2f6d58a | 1,475 | 2022-advent-of-code-kotlin | Apache License 2.0 |
src/Day01.kt | n0irx | 572,845,006 | false | {"Kotlin": 2392} | import java.util.PriorityQueue
fun main() {
// TC: O(n), only looping through the list of calories once
// TC: O(1), only need to hold tempSum, and maxSum variable
fun part1(input: List<String>): Int {
var tempSum = 0; var maxSum = 0
for (num in input) {
if (num != "") {
... | 0 | Kotlin | 0 | 0 | 7a7c2027c32419ad1f82c38a071699ad5bbbbb14 | 1,742 | advent-of-code-kotlin | Apache License 2.0 |
src/day01/solution.kt | bohdandan | 729,357,703 | false | {"Kotlin": 80367} | package day01
import println
import readInput
fun main() {
var spelledDigits = mapOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"five" to 5,
"six" to 6,
"seven" to 7,
"eight" to 8,
"nine" to 9
)
fun getFirstDigit(str: St... | 0 | Kotlin | 0 | 0 | 92735c19035b87af79aba57ce5fae5d96dde3788 | 1,400 | advent-of-code-2023 | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/hard/FindMedianSortedArrays.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode.hard
/**
* 4. 寻找两个正序数组的中位数
*
* 给定两个大小分别为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。
*
*/
class FindMedianSortedArrays {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println(FindMedianSortedArrays().findMedianSortedAr... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,229 | daily_algorithm | Apache License 2.0 |
src/Day06.kt | timmiller17 | 577,546,596 | false | {"Kotlin": 44667} | fun main() {
fun part1(input: List<String>): Int {
val signal = input[0]
for (i in 0..signal.length - 4) {
if (signal[i] != signal[i + 1] &&
signal[i] != signal[i + 2] &&
signal[i] != signal[i + 3] &&
signal[i + 1] != signal[i + 2] &&
... | 0 | Kotlin | 0 | 0 | b6d6b647c7bb0e6d9e5697c28d20e15bfa14406c | 1,283 | advent-of-code-2022 | Apache License 2.0 |
2022/src/day13/Day13.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day13
import java.io.File
import java.util.*
fun main() {
runFileInput("src/day13/day13input.txt")
val input = mutableListOf<String>()
input.addAll(File("src/day13/day13input.txt").readLines())
input.add("[[2]]")
input.add("[[6]]")
println(getSortedIndexMultiplier(input.filter { it.is... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 3,958 | adventofcode | Apache License 2.0 |
usvm-util/src/main/kotlin/org/usvm/algorithms/WeightedAaTree.kt | UnitTestBot | 586,907,774 | false | {"Kotlin": 2547205, "Java": 471958} | package org.usvm.algorithms
import java.util.*
import kotlin.math.min
data class AaTreeNode<T>(
/**
* Value attached to the node.
*/
val value: T,
/**
* Weight attached to the node.
*/
val weight: Double,
/**
* Sum of the children's weights.
*/
val weightSum: Doub... | 39 | Kotlin | 0 | 7 | 94c5a49a0812737024dee5be9d642f22baf991a2 | 6,467 | usvm | Apache License 2.0 |
src/Day02Part2.kt | RickShaa | 572,623,247 | false | {"Kotlin": 34294} | fun main() {
val fileName = "day02.txt"
val testFileName = "day02_test.txt"
val input:String = FileUtil.getTrimmedText(fileName);
val testInput:String = FileUtil.getTrimmedText(testFileName);
val WON = 6;
val DRAW =3;
//Create Lookup map to store
val choiceMap = mapOf<String, Choice... | 0 | Kotlin | 0 | 1 | 76257b971649e656c1be6436f8cb70b80d5c992b | 2,469 | aoc | Apache License 2.0 |
src/main/kotlin/Day24.kt | clechasseur | 318,029,920 | false | null | import org.clechasseur.adventofcode2020.Day24Data
import org.clechasseur.adventofcode2020.Pt
object Day24 {
private val input = Day24Data.input
fun part1(): Int {
val floor = Floor()
input.lines().map { it.toHexDirections() }.forEach { floor.followAndFlip(it) }
return floor.blackTilesC... | 0 | Kotlin | 0 | 0 | 6173c9da58e3118803ff6ec5b1f1fc1c134516cb | 2,613 | adventofcode2020 | MIT License |
AOC-2017/src/main/kotlin/Day14.kt | sagar-viradiya | 117,343,471 | false | {"Kotlin": 72737} | object Day14 {
fun part1(input: String) = (0..127).sumBy { getBinaryKnotHash(Day10.part2("$input-$it"), true).length }
fun part2(input: String): Int {
val disk = getDisk(input)
var regions = 0
for (i in 0 until disk.size) {
for (j in 0 until disk[i].size) {
... | 0 | Kotlin | 0 | 0 | 7f88418f4eb5bb59a69333595dffa19bee270064 | 2,519 | advent-of-code | MIT License |
src/main/aoc2020/Day22.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2020
class Day22(input: List<String>) {
private val players = input.map { player -> player.split("\n").drop(1).map { it.toInt() } }
private fun normalGame(players: List<MutableList<Int>>): Pair<Int, MutableList<Int>> {
while (players.all { it.isNotEmpty() }) {
val cards = List(2... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 2,376 | aoc | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SearchInRotatedSortedArray.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,860 | kotlab | Apache License 2.0 |
facebook/y2020/round2/b.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package facebook.y2020.round2
private fun solve(): DoubleArray {
val s = readStrings()
val n = s[0].toInt()
val p = s[1].toDouble()
var a = DoubleArray(2) { 1.0 }
for (m in 3..n) {
val pairs = m * (m - 1L) / 2
val b = DoubleArray(m) { i ->
val smaller = a.getOrElse(i - 1) { 0.0 }
val same = a.getOrElse(... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 820 | competitions | The Unlicense |
src/day13/Day13.kt | davidcurrie | 579,636,994 | false | {"Kotlin": 52697} | package day13
import java.io.File
fun main() {
val pairs = File("src/day13/input.txt").readText().split("\n\n")
.map { it.split("\n") }
.map { listOf(parse(it[0]), parse(it[1])) }
println(pairs.mapIndexed { index, pair -> if (check(pair[0], pair[1])!!) index + 1 else 0 }.sumOf { it })
va... | 0 | Kotlin | 0 | 0 | 0e0cae3b9a97c6019c219563621b43b0eb0fc9db | 2,427 | advent-of-code-2022 | MIT License |
src/Day17.kt | zfz7 | 573,100,794 | false | {"Kotlin": 53499} | fun main() {
println(day17A(readFile("Day17").trim(), 2200))
println(day17B(readFile("Day17").trim()))
}
//val shapes = listOf("1111", ".2.\n222\n.2.", "..3\n..3\n333", "3\n3\n3\n3", "33\n33")
val shapes = listOf("####", ".#.\n###\n.#.", "..#\n..#\n###", "#\n#\n#\n#", "##\n##")
fun day17A(input: String, blocks... | 0 | Kotlin | 0 | 0 | c50a12b52127eba3f5706de775a350b1568127ae | 6,495 | AdventOfCode22 | Apache License 2.0 |
kotlin/misc/Sat2.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package misc
import java.util.stream.Stream
// https://en.wikipedia.org/wiki/2-satisfiability
object Sat2 {
fun dfs1(graph: Array<List<Integer>>, used: BooleanArray, order: List<Integer?>, u: Int) {
used[u] = true
for (v in graph[u]) if (!used[v]) dfs1(graph, used, order, v)
order.add(u)
... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 2,120 | codelibrary | The Unlicense |
2019/src/main/kotlin/com/github/jrhenderson1988/adventofcode2019/day15/RepairDroid.kt | jrhenderson1988 | 289,786,400 | false | {"Kotlin": 216891, "Java": 166355, "Go": 158613, "Rust": 124111, "Scala": 113820, "Elixir": 112109, "Python": 91752, "Shell": 37} | package com.github.jrhenderson1988.adventofcode2019.day15
import com.github.jrhenderson1988.adventofcode2019.common.Direction
import com.github.jrhenderson1988.adventofcode2019.common.dijkstra
import java.util.Stack
class RepairDroid(private val intCodeComputer: IntCodeComputer) {
private val priorities = listOf(... | 0 | Kotlin | 0 | 0 | 7b56f99deccc3790c6c15a6fe98a57892bff9e51 | 3,720 | advent-of-code | Apache License 2.0 |
kotlin/src/main/kotlin/dev/mikeburgess/euler/problems/Problem021.kt | mddburgess | 261,028,925 | false | null | package dev.mikeburgess.euler.problems
import dev.mikeburgess.euler.common.properDivisors
/**
* Problem 21
*
* Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly
* into n).
*
* If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and... | 0 | Kotlin | 0 | 0 | 86518be1ac8bde25afcaf82ba5984b81589b7bc9 | 924 | project-euler | MIT License |
src/main/kotlin/biz/koziolek/adventofcode/year2023/day20/day20.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2023.day20
import biz.koziolek.adventofcode.findInput
fun main() {
val inputFile = findInput(object {})
val modules = parseModules(inputFile.bufferedReader().readLines())
println("low pulses * high pulses: ${countPulses(modules, buttonPresses = 1000)}")
println("I... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 7,608 | advent-of-code | MIT License |
year2021/day01/part2/src/main/kotlin/com/curtislb/adventofcode/year2021/day01/part2/Year2021Day01Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Part Two ---
Considering every single measurement isn't as useful as you expected: there's just too much noise in
the data.
Instead, consider sums of a three-measurement sliding window. Again considering the above example:
```
199 A
200 A B
208 A B C
210 B C D
200 E C D
207 E F D
240 E F G
269 ... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,156 | AdventOfCode | MIT License |
src/Day02.kt | Longtainbin | 573,466,419 | false | {"Kotlin": 22711} | fun main() {
val input = readInput("inputDay02")
// store shape score
val SHAPE_SCORE = intArrayOf(1, 2, 3)
/**
* OUT_Part1 store result, 0 -> draw
* 1 -> win ,-1 -> lost
*/
val OUT_Part1 = arrayOf(intArrayOf(0, 1, -1), intArrayOf(-1, 0, 1), intArrayOf(1, -1, 0))
val OUT_Part... | 0 | Kotlin | 0 | 0 | 48ef88b2e131ba2a5b17ab80a0bf6a641e46891b | 2,610 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/nl/jackploeg/aoc/_2022/calendar/day08/Day08.kt | jackploeg | 736,755,380 | false | {"Kotlin": 318734} | package nl.jackploeg.aoc._2022.calendar.day08
import javax.inject.Inject
import nl.jackploeg.aoc.generators.InputGenerator.InputGeneratorFactory
import nl.jackploeg.aoc.utilities.readStringFile
class Day08 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
// count visible trees
f... | 0 | Kotlin | 0 | 0 | f2b873b6cf24bf95a4ba3d0e4f6e007b96423b76 | 3,618 | advent-of-code | MIT License |
src/main/kotlin/me/alejandrorm/klosure/sparql/algebra/operators/Project.kt | alejandrorm | 512,041,126 | false | {"Kotlin": 196720, "Ruby": 28544, "HTML": 25737} | package me.alejandrorm.klosure.sparql.algebra.operators
import me.alejandrorm.klosure.model.Graph
import me.alejandrorm.klosure.model.Graphs
import me.alejandrorm.klosure.sparql.SolutionMapping
data class ProjectArguments(val distinct: Boolean, val variables: List<ExpressionVariableBinding>)
class Project(
val a... | 0 | Kotlin | 0 | 0 | 14abf426f3cad162c021ffae750038e25b8cb271 | 3,716 | klosure | Apache License 2.0 |
src/2022/Day25.kt | ttypic | 572,859,357 | false | {"Kotlin": 94821} | package `2022`
import readInput
fun main() {
fun part1(input: List<String>): String {
return input.sumOf { it.fromSNAFU() }.toSNAFU()
}
fun part2(input: List<String>): Int {
return 0
}
// test if implementation meets criteria from the description, like:
val testInput = readIn... | 0 | Kotlin | 0 | 0 | b3e718d122e04a7322ed160b4c02029c33fbad78 | 1,410 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/dayEight/DayEight.kt | janreppien | 573,041,132 | false | {"Kotlin": 26432} | package dayEight
import AocSolution
import java.io.File
class DayEight : AocSolution(8) {
private val input = readInput()
private fun readInput(): MutableList<MutableList<Int>> {
val file = File("src/main/resources/inputs/dayEight/input.txt")
val input = mutableListOf<MutableList<Int>>()
... | 0 | Kotlin | 0 | 0 | b53f6c253966536a3edc8897d1420a5ceed59aa9 | 2,901 | aoc2022 | MIT License |
src/Day07.kt | max-zhilin | 573,066,300 | false | {"Kotlin": 114003} | import java.util.*
class TreeNode(val size: Int, val name: String){
var parent: TreeNode? = null
var children: MutableMap<String, TreeNode> = mutableMapOf()
fun addChild(node:TreeNode){
children[node.name] = node
node.parent = this
}
fun calcSize(): Int {
var sum = size
... | 0 | Kotlin | 0 | 0 | d9dd7a33b404dc0d43576dfddbc9d066036f7326 | 4,834 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/eu/michalchomo/adventofcode/year2023/Day01.kt | MichalChomo | 572,214,942 | false | {"Kotlin": 56758} | package eu.michalchomo.adventofcode.year2023
import eu.michalchomo.adventofcode.Day
import eu.michalchomo.adventofcode.main
object Day01 : Day {
override val number = 1
private val stringDigitsToIntegers = mapOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"fiv... | 0 | Kotlin | 0 | 0 | a95d478aee72034321fdf37930722c23b246dd6b | 1,293 | advent-of-code | Apache License 2.0 |
dataStructuresAndAlgorithms/src/main/java/dev/funkymuse/datastructuresandalgorithms/sort/MergeSortPlain.kt | FunkyMuse | 168,687,007 | false | {"Kotlin": 1728251} | package dev.funkymuse.datastructuresandalgorithms.sort
/**
* Merge sort is an efficient algorithm for sorting lists of data.
* Principle:
* Split the list in half until it is only 2 elements long, then sort those lists.
* After sorting those small lists, start merging them together.
* For instan... | 0 | Kotlin | 92 | 771 | e2afb0cc98c92c80ddf2ec1c073d7ae4ecfcb6e1 | 1,818 | KAHelpers | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FactorCombinations.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,386 | kotlab | Apache License 2.0 |
src/main/kotlin/PalindromicSubstrings.kt | Codextor | 453,514,033 | false | {"Kotlin": 26975} | /**
* Given a string s, return the number of palindromic substrings in it.
*
* A string is a palindrome when it reads the same backward as forward.
*
* A substring is a contiguous sequence of characters within the string.
*
*
*
* Example 1:
*
* Input: s = "abc"
* Output: 3
* Explanation: Three palindromic ... | 0 | Kotlin | 1 | 0 | 68b75a7ef8338c805824dfc24d666ac204c5931f | 1,237 | kotlin-codes | Apache License 2.0 |
src/day03/kotlin/aoc2023-03/src/main/kotlin/Main.kt | JoubaMety | 726,095,975 | false | {"Kotlin": 17724} | data class StringInSchematic(
val schematic: List<String>,
val index: Index,
val length: Int
)
data class Index(
val column: Int,
val row: Int
)
class PartNumberMaximumDimensions(
partNumber: StringInSchematic
) {
val top = getTopDimension(partNumber)
val bottom = getBottomDimension(pa... | 0 | Kotlin | 0 | 0 | 1f883bbbbed64f285b0d3cf7f51f6fb3a1a0e966 | 8,075 | AdventOfCode-2023 | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.