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-2020/src/test/java/aoc/Day10AdapterArray.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | package aoc
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
class Day10AdapterArray {
@Test
fun silverTest() {
val zipped = connectAdapters(testInput)
assertThat(zipped.count { it == 1 }).isEqualTo(7)
assertThat(zipped.count { it == 3 }).isEqualTo(5)
}
... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 4,103 | advent-of-code | MIT License |
lib/src/main/kotlin/com/bloidonia/advent/day21/Day21.kt | timyates | 433,372,884 | false | {"Kotlin": 48604, "Groovy": 33934} | package com.bloidonia.advent.day21
class Die(var next: Int = 0) {
fun next(): Int = (next + 1).apply {
next = this.mod(100)
}
fun three(): Int = listOf(next(), next(), next()).sum()
}
class Game(private val die: Die, val turn: Int, private val pos: IntArray, val scores: IntArray = IntArray(2) { 0... | 0 | Kotlin | 0 | 1 | 9714e5b2c6a57db1b06e5ee6526eb30d587b94b4 | 2,328 | advent-of-kotlin-2021 | MIT License |
src/main/kotlin/year2022/day-12.kt | ppichler94 | 653,105,004 | false | {"Kotlin": 182859} | package year2022
import lib.TraversalBreadthFirstSearch
import lib.aoc.Day
import lib.aoc.Part
import lib.math.Vector
import lib.math.plus
fun main() {
Day(12, 2022, Part12('S', "31"), Part12('a', "29")).run()
}
open class Part12(private val startChar: Char, private val example: String) : Part() {
private l... | 0 | Kotlin | 0 | 0 | 49dc6eb7aa2a68c45c716587427353567d7ea313 | 2,023 | Advent-Of-Code-Kotlin | MIT License |
Kotlin/problems/0052_eventual_safe_nodes.kt | oxone-999 | 243,366,951 | true | {"C++": 961697, "Kotlin": 99948, "Java": 17927, "Python": 9476, "Shell": 999, "Makefile": 187} | //Problem Statement
// In a directed graph, we start at some node and every turn, walk along a directed
// edge of the graph. If we reach a node that is terminal
// (that is, it has no outgoing directed edges), we stop.
//
// Now, say our starting node is eventually safe if and only if we must eventually
// walk to a ... | 0 | null | 0 | 0 | 52dc527111e7422923a0e25684d8f4837e81a09b | 2,093 | algorithms | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round0/Questions14.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round0
import kotlin.math.*
/**
* 将长度为n的绳子剪成m段,求每段乘积相乘最大时的最大乘积
*/
fun test14() {
println("绳子长度为8时,最大乘积为:${maxProductAfterCutting1(8)}")
println("绳子长度为8时,最大乘积为:${maxProductAfterCutting2(8)}")
}
// 动态规划
fun maxProductAfterCutting1(length: Int): Int = when {
length < 2 -> throw Ill... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,195 | Algorithm | Apache License 2.0 |
src/main/kotlin/g1801_1900/s1815_maximum_number_of_groups_getting_fresh_donuts/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1815_maximum_number_of_groups_getting_fresh_donuts
// #Hard #Array #Dynamic_Programming #Bit_Manipulation #Bitmask #Memoization
// #2023_06_20_Time_1073_ms_(100.00%)_Space_71.3_MB_(100.00%)
import java.util.Objects
class Solution {
inner class Data(var idx: Int, var arrHash: Int) {
ov... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,076 | LeetCode-in-Kotlin | MIT License |
Main.kt | MBM1607 | 330,647,417 | false | null | package processor
import java.util.Scanner
import kotlin.math.min
import kotlin.math.pow
val scanner = Scanner(System.`in`)
fun readMatrix(messageInfix: String = ""): Array<DoubleArray> {
print("Enter size of ${messageInfix}matrix: ")
val row = scanner.nextInt()
val col = scanner.nextInt()
val matrix... | 0 | Kotlin | 0 | 0 | 9619a1b91aae5783395ebba81d69a8466c07e532 | 7,064 | matrix-calculator | MIT License |
src/Day04.kt | kmakma | 574,238,598 | false | null | fun main() {
fun part1(input: List<List<Int>>): Int {
return input.count { list ->
(list[0] <= list[2] && list[1] >= list[3])
|| (list[0] >= list[2] && list[1] <= list[3])
}
}
fun part2(input: List<List<Int>>): Int {
return input.count { list ->
... | 0 | Kotlin | 0 | 0 | 950ffbce2149df9a7df3aac9289c9a5b38e29135 | 648 | advent-of-kotlin-2022 | Apache License 2.0 |
src/main/aoc2023/Day19.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2023
import size
import kotlin.math.max
import kotlin.math.min
class Day19(input: List<String>) {
private fun String.toIntRange(): IntRange {
val i = this.toInt()
return i..i
}
private val partRatings = input.last().split("\n").map { line ->
val regex = """\{x=(\d+),m=... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 4,252 | aoc | MIT License |
src/main/kotlin/Extensions.kt | nishtahir | 91,517,572 | false | null | import java.util.*
import java.util.concurrent.locks.Lock
fun isValidTriangle(values: List<Int>): Boolean =
values[0] + values[1] > values[2] &&
values[0] + values[2] > values[1] &&
values[1] + values[2] > values[0]
inline fun <reified T> List<T>.grouped(by: Int): List<List<T>>... | 0 | Kotlin | 0 | 0 | 51115e3405ac75e436b783ceeca74afe120243f3 | 1,157 | scratchpad | Apache License 2.0 |
2022/Day21/problems.kt | moozzyk | 317,429,068 | false | {"Rust": 102403, "C++": 88189, "Python": 75787, "Kotlin": 72672, "OCaml": 60373, "Haskell": 53307, "JavaScript": 51984, "Go": 49768, "Scala": 46794} | import java.io.File
fun main(args: Array<String>) {
val lines = File(args[0]).readLines()
val regex = """(.*): (.*)""".toRegex()
val monkeys =
lines
.map { regex.matchEntire(it)!!.destructured }
.map { (name, operation) -> name to operation }
... | 0 | Rust | 0 | 0 | c265f4c0bddb0357fe90b6a9e6abdc3bee59f585 | 3,246 | AdventOfCode | MIT License |
src/main/kotlin/me/consuegra/algorithms/KPascalTriangle.kt | aconsuegra | 91,884,046 | false | {"Java": 113554, "Kotlin": 79568} | package me.consuegra.algorithms
/**
* Given numRows, generate the first numRows of Pascal’s triangle.
* <p>
* Pascal’s triangle : To generate A[C] in row R, sum up A’[C] and A’[C-1] from previous row R - 1.
* <p>
* Example:
* <p>
* Given numRows = 5,
* <p>
* Return
* <p>
* [
* [1],
* [1,1],
* [1,2,1],
*... | 0 | Java | 0 | 7 | 7be2cbb64fe52c9990b209cae21859e54f16171b | 995 | algorithms-playground | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MergeSortedArray.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,559 | kotlab | Apache License 2.0 |
24.kt | pin2t | 725,922,444 | false | {"Kotlin": 48856, "Go": 48364, "Shell": 54} | data class Pos3D(val x: Long, val y: Long, val z: Long)
data class Hailstone(val pos: Pos3D, val velocity: Pos3D)
class Day24 {
var hailstones = ArrayList<Hailstone>()
val number = Regex("-?\\d+")
fun run() {
while (true) {
val line = readlnOrNull() ?: break
val items = num... | 0 | Kotlin | 1 | 0 | 7575ab03cdadcd581acabd0b603a6f999119bbb6 | 1,868 | aoc2023 | MIT License |
app/src/main/kotlin/ch/empa/openbisio/interfaces/Tree.kt | empa-scientific-it | 618,383,912 | false | null | /*
* 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 wr... | 0 | Kotlin | 0 | 0 | 39396bb489fa91e8e65f83206e806b67fcd3ac65 | 2,806 | instanceio | Apache License 2.0 |
src/Day01.kt | leeturner | 572,659,397 | false | {"Kotlin": 13839} | fun main() {
fun part1(input: List<List<Int>>): Int {
return input.maxOf { it.sum() }
}
fun part2(input: List<List<Int>>): Int {
return input.map { it.sum() }.sortedDescending().take(3).sum()
}
// test if implementation meets criteria from the description, like:
val testInput =
readInputSpli... | 0 | Kotlin | 0 | 0 | 8da94b6a0de98c984b2302b2565e696257fbb464 | 655 | advent-of-code-2022 | Apache License 2.0 |
app/src/y2021/day04/Day04GiantSquid.kt | henningBunk | 432,858,990 | false | {"Kotlin": 124495} | package y2021.day04
import common.Answers
import common.AocSolution
import common.annotations.AoCPuzzle
fun main(args: Array<String>) {
Day04GiantSquid().solveThem()
}
@AoCPuzzle(2021, 4)
class Day04GiantSquid : AocSolution {
override val answers = Answers(samplePart1 = 4512, samplePart2 = 1924, part1 = 1068... | 0 | Kotlin | 0 | 0 | 94235f97c436f434561a09272642911c5588560d | 1,595 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/com/jacobhyphenated/advent2022/day14/Day14.kt | jacobhyphenated | 573,603,184 | false | {"Kotlin": 144303} | package com.jacobhyphenated.advent2022.day14
import com.jacobhyphenated.advent2022.Day
import kotlin.math.max
import kotlin.math.min
/**
* Day 14: Regolith Reservoir
*
* Sand is dropping from the ceiling of the cave. The puzzle input is the rock structure of the cave in 2D.
* The input shows lists of pairs that r... | 0 | Kotlin | 0 | 0 | 9f4527ee2655fedf159d91c3d7ff1fac7e9830f7 | 3,897 | advent2022 | The Unlicense |
src/Day08.kt | aaronbush | 571,776,335 | false | {"Kotlin": 34359} | enum class ForestDirection { N, S, E, W }
enum class TreeVisibility { VISIBLE, NOT_VISIBLE, UNKNOWN }
fun main() {
data class Tree(
val row: Int,
val column: Int,
val height: Int,
var visibility: TreeVisibility = TreeVisibility.UNKNOWN,
var treesVisible: Int = 0
)
d... | 0 | Kotlin | 0 | 0 | d76106244dc7894967cb8ded52387bc4fcadbcde | 5,712 | aoc-2022-kotlin | Apache License 2.0 |
src/Day03.kt | touchman | 574,559,057 | false | {"Kotlin": 16512} |
fun main() {
val input = readInput("Day03")
fun getNumberForChar(it: String) = it.toCharArray()[0]
.let {
if (it.isLowerCase()) {
it - 'a' + 1
} else {
it - 'A' + 1 + 26
}
}
fun part1(input: List<String>) =
input... | 0 | Kotlin | 0 | 0 | 4f7402063a4a7651884be77bb9e97828a31459a7 | 1,502 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/shmvanhouten/adventofcode/day24airductmaze/RouteFinder.kt | SHMvanHouten | 109,886,692 | false | {"Kotlin": 616528} | package com.github.shmvanhouten.adventofcode.day24airductmaze
class RouteFinder {
fun getPossibleRoutes(possibleRoutesAndSizes: Map<Route, Int>, relevantLocations: Set<Int>): Set<WeightedNode> {
return getPossibleRoutesVisitingAllLocations(possibleRoutesAndSizes, relevantLocations)
}
fun getPos... | 0 | Kotlin | 0 | 0 | a8abc74816edf7cd63aae81cb856feb776452786 | 2,986 | adventOfCode2016 | MIT License |
src/main/kotlin/de/pgebert/aoc/days/Day15.kt | pgebert | 724,032,034 | false | {"Kotlin": 65831} | package de.pgebert.aoc.days
import de.pgebert.aoc.Day
class Day15(input: String? = null) : Day(15, "Lens Library", input) {
override fun partOne() = inputList.first().split(",").sumOf { it.hash() }
private fun String.hash() = fold(0) { agg, char -> ((agg + char.code) * 17) % 256 }
data class Lens(val... | 0 | Kotlin | 1 | 0 | a30d3987f1976889b8d143f0843bbf95ff51bad2 | 1,764 | advent-of-code-2023 | MIT License |
year2015/src/main/kotlin/net/olegg/aoc/year2015/day13/Day13.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2015.day13
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.permutations
import net.olegg.aoc.year2015.DayOf2015
/**
* See [Year 2015, Day 13](https://adventofcode.com/2015/day/13)
*/
object Day13 : DayOf2015(13) {
private val PATTERN = "^\\b(\\w+)\\b.*\\b(gain|lose) \\b(\... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,239 | adventofcode | MIT License |
src/main/kotlin/g0101_0200/s0126_word_ladder_ii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0101_0200.s0126_word_ladder_ii
// #Hard #String #Hash_Table #Breadth_First_Search #Backtracking
// #2022_10_08_Time_418_ms_(51.45%)_Space_41.1_MB_(65.94%)
import java.util.Collections
import java.util.LinkedList
import java.util.Queue
class Solution {
fun findLadders(beginWord: String, endWord: String, ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 3,700 | LeetCode-in-Kotlin | MIT License |
day3/src/main/kotlin/main.kt | jorgensta | 434,206,181 | false | {"Kotlin": 8252, "Assembly": 62} | import java.io.File
fun parseFileAndGetInput(): List<String> {
val filepath = "/Users/jorgenstamnes/Documents/own/AdventOfCode2021/day3/src/main/kotlin/input.txt"
return File(filepath).readLines(Charsets.UTF_8).toList()
}
fun first() {
val inputs = parseFileAndGetInput()
val one = '1'
val zero = ... | 0 | Kotlin | 0 | 0 | 5e296aaad25d1538306fa514c27efc35505e3a18 | 3,272 | AdventOfCode2021 | MIT License |
src/Day07.kt | zsmb13 | 572,719,881 | false | {"Kotlin": 32865} | import java.io.File
fun main() {
val elfDrive = File("elfdrive")
fun initializeElfDrive(testInput: List<String>) {
var file = elfDrive
file.deleteRecursively()
file.mkdir()
testInput.drop(1).forEach { line ->
when (line.first()) {
'$' -> {
... | 0 | Kotlin | 0 | 6 | 32f79b3998d4dfeb4d5ea59f1f7f40f7bf0c1f35 | 1,884 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/katas/15.duplicateCount.kt | ch8n | 312,467,034 | false | null | @file:Suppress("PackageDirectoryMismatch")
package katas.longestCount
//https://www.codewars.com/kata/5656b6906de340bd1b0000ac/train/kotlin
import kotlin.time.measureTimedValue
/**
*
* Take 2 strings s1 and s2 including only letters from a to z.
* Return a new sorted string, the longest possible, containing dis... | 3 | Kotlin | 0 | 1 | e0619ebae131a500cacfacb7523fea5a9e44733d | 2,649 | Big-Brain-Kotlin | Apache License 2.0 |
src/Day07.kt | JonasDBB | 573,382,821 | false | {"Kotlin": 17550} | import java.lang.Exception
data class Dir(val name: String, val parent: Dir?) {
val subdir = mutableSetOf<Dir>()
val files = mutableMapOf<String, Int>()
val size: Int by lazy { subdir.sumOf { it.size } + files.values.sum() }
}
private fun createFS(input: List<String>): MutableSet<Dir> {
val fileSys = ... | 0 | Kotlin | 0 | 0 | 199303ae86f294bdcb2f50b73e0f33dca3a3ac0a | 1,707 | AoC2022 | Apache License 2.0 |
src/main/kotlin/g0601_0700/s0687_longest_univalue_path/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0601_0700.s0687_longest_univalue_path
// #Medium #Depth_First_Search #Tree #Binary_Tree
// #2023_02_17_Time_303_ms_(100.00%)_Space_39.2_MB_(100.00%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree node.
* class TreeNode(var `val... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,376 | LeetCode-in-Kotlin | MIT License |
src/day5/Day05.kt | jorgensta | 573,824,365 | false | {"Kotlin": 31676} | import java.util.*
fun main() {
val day = "day5"
val filename = "Day05"
val WHITESPACE = 32
class Action(val numCrates: Int, val from: Int, val to: Int)
class Crate(val name: Char) {
override fun toString(): String {
return "[$name]"
}
}
class Stack(val crates:... | 0 | Kotlin | 0 | 0 | 7243e32351a926c3a269f1e37c1689dfaf9484de | 3,540 | AoC2022 | Apache License 2.0 |
src/Constraint.kt | jonward1982 | 350,285,956 | true | {"Kotlin": 213021, "Java": 286} | import lib.sparseVector.SparseVector
import lib.sparseVector.asVector
interface Constraint<out COEFF> {
val coefficients: Map<Int, COEFF>
val relation: String
val constant: COEFF
fun numVars(): Int = coefficients.keys.max()?.let { it+1 }?:0
}
fun<COEFF: Comparable<COEFF>> Constraint<COEFF>.isSati... | 0 | Kotlin | 0 | 0 | 621d32d5e2d9d363c753d42cd1ede6b31195e716 | 1,392 | AgentBasedMCMC | MIT License |
src/chapter4/section3/ex32_SpecifiedSet.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter4.section3
import chapter1.section5.CompressionWeightedQuickUnionUF
import chapter2.section4.HeapMinPriorityQueue
import chapter3.section5.LinearProbingHashSET
import chapter3.section5.SET
/**
* 指定的集合
* 给定一幅连通的加权图G和一个边的集合S(不含环),给出一种算法得到含有S中所有边的最小加权生成树
*
* 解:使用Kruskal算法计算最小生成树时,先将集合S内的所有边都加入到最小生成树中,... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,716 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/main/kotlin/com/colinodell/advent2016/Day17.kt | colinodell | 495,627,767 | false | {"Kotlin": 80872} | package com.colinodell.advent2016
class Day17(private val input: String) {
private val start = State(Vector2(0, 0))
private val reachedGoal: (State) -> Boolean = { it.pos == Vector2(3, 3) }
fun solvePart1() = AStar(start, reachedGoal, ::generateNextMoves).end!!.path
fun solvePart2() = DFS_all(start, r... | 0 | Kotlin | 0 | 0 | 8a387ddc60025a74ace8d4bc874310f4fbee1b65 | 1,025 | advent-2016 | Apache License 2.0 |
src/main/kotlin/g1601_1700/s1691_maximum_height_by_stacking_cuboids/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1601_1700.s1691_maximum_height_by_stacking_cuboids
// #Hard #Array #Dynamic_Programming #Sorting
// #2023_06_15_Time_187_ms_(100.00%)_Space_38.6_MB_(100.00%)
import java.util.Arrays
class Solution {
fun maxHeight(cuboids: Array<IntArray>): Int {
for (a in cuboids) {
a.sort()
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,102 | LeetCode-in-Kotlin | MIT License |
src/day01/Day01.kt | dkoval | 572,138,985 | false | {"Kotlin": 86889} | package day01
import readInputAsString
import java.util.*
private const val DAY_ID = "01"
fun main() {
fun parseInput(input: String): List<List<Int>> =
input.split("\n\n").map { group -> group.lines().map { it.toInt() } }
fun part1(input: String): Int {
val groups = parseInput(input)
... | 0 | Kotlin | 1 | 0 | 791dd54a4e23f937d5fc16d46d85577d91b1507a | 1,087 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem1834/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1834
import java.util.*
/**
* LeetCode page: [1834. Single-Threaded CPU](https://leetcode.com/problems/single-threaded-cpu/);
*/
class Solution {
/* Complexity:
* Time O(NLogN) and Space O(N) where N is the size of tasks;
*/
fun getOrder(tasks: Array<IntArray>... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,828 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/com/nibado/projects/advent/y2017/Day12.kt | nielsutrecht | 47,550,570 | false | null | package com.nibado.projects.advent.y2017
import com.nibado.projects.advent.Day
import com.nibado.projects.advent.resourceRegex
object Day12 : Day {
private val input = resourceRegex(2017, 12, Regex("^([0-9]+) <-> ([0-9 ,]+)$")).map { Pair(it[1].toInt(), it[2].split(", ").map { it.toInt() }) }
private val solu... | 1 | Kotlin | 0 | 15 | b4221cdd75e07b2860abf6cdc27c165b979aa1c7 | 1,611 | adventofcode | MIT License |
src/main/kotlin/g2301_2400/s2328_number_of_increasing_paths_in_a_grid/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2301_2400.s2328_number_of_increasing_paths_in_a_grid
// #Hard #Array #Dynamic_Programming #Depth_First_Search #Breadth_First_Search #Matrix #Graph
// #Memoization #Topological_Sort #2023_07_01_Time_689_ms_(79.53%)_Space_59.1_MB_(91.34%)
class Solution {
private fun help(a: Array<IntArray>, i: Int, j: Int... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,499 | LeetCode-in-Kotlin | MIT License |
src/day05/Day05.kt | Puju2496 | 576,611,911 | false | {"Kotlin": 46156} | package day05
import readInput
import java.util.*
fun main() {
// test if implementation meets criteria from the description, like:
val input = readInput("src/day05", "Day05")
println("Part1")
part1(input)
println("Part2")
part2(input)
}
private fun part1(inputs: List<String>) {
val stack... | 0 | Kotlin | 0 | 0 | e04f89c67f6170441651a1fe2bd1f2448a2cf64e | 2,577 | advent-of-code-2022 | Apache License 2.0 |
AdventOfCodeDay19/src/nativeMain/kotlin/Scanner.kt | bdlepla | 451,510,571 | false | {"Kotlin": 165771} | import kotlin.math.absoluteValue
data class Point3d(val x: Int, val y: Int, val z: Int) {
operator fun plus(other: Point3d): Point3d =
Point3d(x + other.x, y + other.y, z + other.z)
operator fun minus(other: Point3d): Point3d =
Point3d(x - other.x, y - other.y, z - other.z)
infix fun dis... | 0 | Kotlin | 0 | 0 | 1d60a1b3d0d60e0b3565263ca8d3bd5c229e2871 | 1,382 | AdventOfCode2021 | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/JobScheduling.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2024 <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,574 | kotlab | Apache License 2.0 |
src/Day03.kt | TinusHeystek | 574,474,118 | false | {"Kotlin": 53071} | class Day03 : Day(3) {
private val priorities = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// --- Part 1 ---
private fun calculateRucksack(rucksack : String) : Int {
val middle = rucksack.length / 2
val compartment1 = rucksack.substring(0, middle).toCharArray()
val co... | 0 | Kotlin | 0 | 0 | 80b9ea6b25869a8267432c3a6f794fcaed2cf28b | 1,531 | aoc-2022-in-kotlin | Apache License 2.0 |
app/src/main/kotlin/day06/Day06.kt | KingOfDog | 433,706,881 | false | {"Kotlin": 76907} | package day06
import common.InputRepo
import common.readSessionCookie
import common.solve
fun main(args: Array<String>) {
val day = 6
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay06Part1, ::solveDay06Part2)
}
fun solveDay06Part1(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | 576e5599ada224e5cf21ccf20757673ca6f8310a | 2,165 | advent-of-code-kt | Apache License 2.0 |
algorithms/src/main/kotlin/org/baichuan/sample/algorithms/leetcode/middle/Divide.kt | scientificCommunity | 352,868,267 | false | {"Java": 154453, "Kotlin": 69817} | package org.baichuan.sample.algorithms.leetcode.middle
/**
* https://leetcode.cn/problems/divide-two-integers/
* 两数相除
* 核心思路: 38/3 = 3*2 + 32 = 3*2*2+26= 3*2*2*2 + 14 = 3*2*2*2 + 3*2*2 +2 = 3(2*2*2 + 2*2) +2 = 3 * 12 + 2 = 12
*/
class Divide {
fun divide(dividend: Int, divisor: Int): Int {
if (dividend... | 1 | Java | 0 | 8 | 36e291c0135a06f3064e6ac0e573691ac70714b6 | 1,923 | blog-sample | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CountVowelsPermutation.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 | 6,920 | kotlab | Apache License 2.0 |
src/main/kotlin/me/circuitrcay/euler/challenges/twentySixToFifty/Problem33.kt | adamint | 134,989,381 | false | null | package me.circuitrcay.euler.challenges.twentySixToFifty
import me.circuitrcay.euler.Problem
import java.math.BigInteger
class Problem33 : Problem<String>() {
override fun calculate(): Any {
val numerators = mutableListOf<Int>()
val denominators = mutableListOf<Int>()
(10..99).forEach { nu... | 0 | Kotlin | 0 | 0 | cebe96422207000718dbee46dce92fb332118665 | 1,825 | project-euler-kotlin | Apache License 2.0 |
src/main/kotlin/Day02.kt | todynskyi | 573,152,718 | false | {"Kotlin": 47697} | fun main() {
fun part1(input: List<String>): Int = input.sumOf {
val player = it[0]
val you = it[2]
val yourScore = when (you) {
'X' -> 1
'Y' -> 2
'Z' -> 3
else -> 0
}
val score = when (player) {
'A' -> {
... | 0 | Kotlin | 0 | 0 | 5f9d9037544e0ac4d5f900f57458cc4155488f2a | 2,042 | KotlinAdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/tr/emreone/adventofcode/days/Day05.kt | EmRe-One | 568,569,073 | false | {"Kotlin": 166986} | package tr.emreone.adventofcode.days
import tr.emreone.adventofcode.readTextGroups
import tr.emreone.kotlin_utils.Logger.logger
import java.util.Stack
object Day05 {
private val pattern = "move (\\d+) from (\\d+) to (\\d+)".toRegex()
private fun printCrates(crates: List<Stack<Char>>) {
val sb = Stri... | 0 | Kotlin | 0 | 0 | a951d2660145d3bf52db5cd6d6a07998dbfcb316 | 3,135 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | sushovan86 | 573,586,806 | false | {"Kotlin": 47064} | import java.io.File
import java.util.*
import kotlin.collections.ArrayDeque
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.component3
import kotlin.collections.set
typealias StackElements = ArrayDeque<Char>
fun StackElements.removeLast(n: Int): List<Char> {
va... | 0 | Kotlin | 0 | 0 | d5f85b6a48e3505d06b4ae1027e734e66b324964 | 4,289 | aoc-2022 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions55.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import com.qiaoyuang.algorithm.round0.BinaryTreeNode
import kotlin.math.abs
import kotlin.math.max
fun test55() {
printlnResult1(testCase1())
printlnResult1(testCase2())
printlnResult1(testCase3())
printlnResult2(testCase1())
printlnResult2(testCase2())
... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 2,582 | Algorithm | Apache License 2.0 |
src/main/kotlin/dk/lessor/Day7.kt | aoc-team-1 | 317,571,356 | false | {"Java": 70687, "Kotlin": 34171} | package dk.lessor
fun main() {
val lines = readFile("day_7.txt")
val bags = bagParser(lines)
val canHaveShiny = containsBag(bags)
println(canHaveShiny.size)
println(countBags(bags))
}
fun containsBag(bags: Map<String, List<Bag>>, name: String = "shiny gold"): List<String> {
val result = mutabl... | 0 | Java | 0 | 0 | 48ea750b60a6a2a92f9048c04971b1dc340780d5 | 1,718 | lessor-aoc-comp-2020 | MIT License |
src/main/kotlin/biodivine/algebra/ia/Interval.kt | daemontus | 160,796,526 | false | null | package biodivine.algebra.ia
import biodivine.algebra.NumQ
import biodivine.algebra.rootisolation.Root
import cc.redberry.rings.Rational
import cc.redberry.rings.Rings
import cc.redberry.rings.bigint.BigDecimal
import cc.redberry.rings.bigint.BigInteger
import biodivine.algebra.rootisolation.compareTo
import kotlin.ma... | 0 | Kotlin | 0 | 0 | ed4fd35015b73ea3ac36aecb1c5a568f6be7f14c | 3,372 | biodivine-algebraic-toolkit | MIT License |
src/main/kotlin/leetcode/Problem2222.kt | fredyw | 28,460,187 | false | {"Java": 1280840, "Rust": 363472, "Kotlin": 148898, "Shell": 604} | package leetcode
/**
* https://leetcode.com/problems/number-of-ways-to-select-buildings/
*/
class Problem2222 {
fun numberOfWays(s: String): Long {
data class Binary(val zero: Int = 0, val one: Int = 0)
val left = Array(s.length) { Binary() }
for (i in s.indices) {
val zero = ... | 0 | Java | 1 | 4 | a59d77c4fd00674426a5f4f7b9b009d9b8321d6d | 1,292 | leetcode | MIT License |
src/main/kotlin/be/tabs_spaces/advent2021/days/Day04.kt | janvryck | 433,393,768 | false | {"Kotlin": 58803} | package be.tabs_spaces.advent2021.days
class Day04: Day(4) {
override fun partOne(): Any {
val bingoSubsystem = BingoSubsystem(inputList)
return bingoSubsystem.firstWinningBoard()
}
override fun partTwo(): Any {
val bingoSubsystem = BingoSubsystem(inputList)
return bingoSub... | 0 | Kotlin | 0 | 0 | f6c8dc0cf28abfa7f610ffb69ffe837ba14bafa9 | 1,980 | advent-2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/adventofcode/y2021/Day07.kt | Tasaio | 433,879,637 | false | {"Kotlin": 117806} | import adventofcode.*
import java.math.BigInteger
fun main() {
val testInput = """
16,1,2,0,4,2,7,1,2,14
""".trimIndent()
val test = Day07(testInput)
println("TEST: " + test.part1())
println("TEST: " + test.part2())
val day = Day07()
val t1 = System.currentTimeMillis()
println(... | 0 | Kotlin | 0 | 0 | cc72684e862a782fad78b8ef0d1929b21300ced8 | 1,527 | adventofcode2021 | The Unlicense |
src/main/kotlin/com/kishor/kotlin/algo/problems/arrayandstrings/SpecialPalindromeString.kt | kishorsutar | 276,212,164 | false | null | package com.kishor.kotlin.algo.problems.arrayandstrings
import java.util.*
import kotlin.text.*
// Complete the substrCount function below.
/**
- get all combinations of the strings / O(n^2)
- check all chars are same or all except one in the middle O(m)
- return the count which follows the above condition
O(n^2m)
*... | 0 | Kotlin | 0 | 0 | 6672d7738b035202ece6f148fde05867f6d4d94c | 1,376 | DS_Algo_Kotlin | MIT License |
src/main/kotlin/extractors/AprioriExtractor.kt | Albaross | 98,739,245 | false | null | package org.albaross.agents4j.extraction.extractors
import org.albaross.agents4j.extraction.*
import org.albaross.agents4j.extraction.bases.MultiAbstractionLevelKB
import java.util.*
class AprioriExtractor<A>(
private val new: () -> KnowledgeBase<A> = { MultiAbstractionLevelKB() },
private val minsupp... | 1 | Kotlin | 0 | 0 | 36bbbccd8ff9a88ea8745a329a446912d4de007d | 3,143 | agents4j-extraction | MIT License |
src/main/kotlin/quantum/core/Measurement.kt | AlexanderScherbatiy | 155,193,555 | false | {"Kotlin": 58447} | package quantum.core
import kotlin.random.Random
/**
* Return index of the basis which has been measured
*/
fun QuantumState.measureBasisIndex(): Int {
val array = Array(size) { this[it].sqr() }
for (i in (1 until size)) {
array[i] += array[i - 1]
}
val probability = Random.nextDouble(1.0... | 0 | Kotlin | 0 | 0 | 673dd1c2a6c9964700ea682d49410d10843070db | 1,794 | quntum-gates | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions50.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
fun test50() {
printlnResult1("abaccdeff")
printlnResult2("We are students.", "aeiou")
printlnResult3("google")
printlnResult4("silent", "listen")
getFirstCharacterAppearOnce(sequence {
"google".forEach {
yield(it)
}
})
}
/**
... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 3,211 | Algorithm | Apache License 2.0 |
aoc-2022/src/main/kotlin/nerok/aoc/aoc2022/day09/Day09.kt | nerok | 572,862,875 | false | {"Kotlin": 113337} | package nerok.aoc.aoc2022.day09
import nerok.aoc.utils.Input
import java.util.*
import kotlin.math.abs
import kotlin.time.DurationUnit
import kotlin.time.measureTime
fun main() {
fun part1(input: List<String>): Long {
val H = GeoPoint(0, 0)
val T = GeoPoint(0, 0)
val visited = emptySet<Ge... | 0 | Kotlin | 0 | 0 | 7553c28ac9053a70706c6af98b954fbdda6fb5d2 | 5,828 | AOC | Apache License 2.0 |
2021/src/Day16.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | import java.util.*
// https://adventofcode.com/2021/day/16
fun main() {
class Packet(typeId: Int, version: Int) {
val typeId = typeId
val version = version
var literal : Long = -1
var packets = mutableListOf<Packet>()
fun isLiteral() : Boolean {
return (typeId == 4)
}
fun comput... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 3,937 | advent-of-code | Apache License 2.0 |
lib/src/main/kotlin/com/bloidonia/advent/day10/Day10.kt | timyates | 433,372,884 | false | {"Kotlin": 48604, "Groovy": 33934} | package com.bloidonia.advent.day10
import com.bloidonia.advent.readList
import kotlin.collections.ArrayDeque
fun opener(ch: Char) = when (ch) {
')' -> '('
']' -> '['
'}' -> '{'
else -> '<'
}
private fun corruptScore(ch: Char) = when (ch) {
')' -> 3
']' -> 57
'}' -> 1197
else -> 25137
... | 0 | Kotlin | 0 | 1 | 9714e5b2c6a57db1b06e5ee6526eb30d587b94b4 | 1,244 | advent-of-kotlin-2021 | MIT License |
tasks-2/lib/src/main/kotlin/trees/structures/Graph.kt | AzimMuradov | 472,473,231 | false | {"Kotlin": 127576} | package trees.structures
public class Graph<V, out E : Edge<V, E, EE>, out EE : EdgeEnd<V, E, EE>> private constructor(
public val vertices: Set<V>,
public val edges: Set<E>,
public val adjList: Map<V, List<EE>>,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
... | 0 | Kotlin | 0 | 0 | 01c0c46df9dc32c2cc6d3efc48b3a9ee880ce799 | 1,981 | discrete-math-spbu | Apache License 2.0 |
kt/problem_493.main.kts | dfings | 31,622,045 | false | {"Go": 12328, "Kotlin": 12241, "Clojure": 11585, "Python": 9457, "Haskell": 8314, "Dart": 5990, "Rust": 5389, "TypeScript": 4158, "Elixir": 3093, "F#": 2745, "C++": 1608} | #!/usr/bin/env kotlin
import java.math.BigDecimal
import java.math.RoundingMode
val NUM_COLORS = 7
val NUM_PER_COLOR = 10
val NUM_TO_PICK = 20
val SUM_ALL_PICKED = NUM_COLORS * NUM_PER_COLOR - NUM_TO_PICK
/**
* Represents the state of the urn. The slots are the colors, and the value of the slot is the
* number of ... | 0 | Go | 0 | 0 | f66389dcd8ff4e4d64fbd245cfdaebac7b9bd4ef | 2,324 | project-euler | The Unlicense |
src/main/kotlin/kr/co/programmers/P87377.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://school.programmers.co.kr/learn/courses/30/lessons/87377
class P87377 {
fun solution(line: Array<IntArray>): Array<String> {
// 교점 좌표를 기록할 Set
val set = mutableSetOf<Pair<Long, Long>>()
// 가장자리 좌표
var minX = Long.MAX_VALUE
var maxX = Long.... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,849 | algorithm | MIT License |
src/Day10.kt | andrewgadion | 572,927,267 | false | {"Kotlin": 16973} | fun main() {
fun interpret(input: List<String>) = sequence {
var x = 1L
input.forEach {
yield(x)
if (it.startsWith("addx")) {
yield(x)
x += it.split(" ")[1].toLong()
}
}
}
fun part1(input: List<String>) = interpret(... | 0 | Kotlin | 0 | 0 | 4d091e2da5d45a786aee4721624ddcae681664c9 | 811 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2022/2022-22.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2022
import com.github.ferinagy.adventOfCode.CharGrid
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.contains
import com.github.ferinagy.adventOfCode.get
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adven... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 4,883 | advent-of-code | MIT License |
src/aoc2022/Day09.kt | anitakar | 576,901,981 | false | {"Kotlin": 124382} | package aoc2022
import println
import readInput
fun main() {
data class Position(val x: Int, val y: Int)
fun part1(input: List<String>): Int {
val moveRegex = """(\w) (\d+)""".toRegex()
var head = Position(0, 0)
var tail = Position(0, 0)
val unique = mutableSetOf<Position>(... | 0 | Kotlin | 0 | 1 | 50998a75d9582d4f5a77b829a9e5d4b88f4f2fcf | 4,693 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/me/dkim19375/adventofcode2022/day/Day7.kt | dkim19375 | 573,172,567 | false | {"Kotlin": 13147} | package me.dkim19375.adventofcode2022.day
import me.dkim19375.adventofcode2022.AdventOfCodeDay
object Day7 : AdventOfCodeDay() {
@JvmStatic
fun main(args: Array<String>) = solve()
override val day: Int = 7
override fun solve() {
val input = getInputString().lines()
val files = Folde... | 1 | Kotlin | 0 | 0 | f77c4acec08a4eca92e6d68fe2a5302380688fe6 | 2,856 | AdventOfCode2022 | The Unlicense |
src/chapter3/section2/ex26_ExactProbabilities.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter3.section2
import chapter1.section4.factorial
import chapter2.sleep
import edu.princeton.cs.algs4.StdDraw
import extensions.formatDouble
/**
* 准确的概率
* 计算用N个随机的互不相同的键构造出练习3.2.9中每一棵树的概率
*
* 解:创建一个新类,继承BinarySearchTree,并实现Comparable接口,
* 以二叉查找树为key,出现次数为value,将3.2.9中未去重的全量二叉查找树列表依次插入另一颗二叉查找树中,
* 遍历所... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 2,408 | Algorithms-4th-Edition-in-Kotlin | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[113]路径总和 II.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.util.*
import javax.swing.tree.TreeNode
import kotlin.collections.ArrayList
//给你二叉树的根节点 root 和一个整数目标和 targetSum ,找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。
//
// 叶子节点 是指没有子节点的节点。
//
//
//
//
//
// 示例 1:
//
//
//输入:root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
//输出:[[5,4,11,2],[5,8,4,5]]
//
//
/... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 3,707 | MyLeetCode | Apache License 2.0 |
src/Day03.kt | nikolakasev | 572,681,478 | false | {"Kotlin": 35834} |
fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
val firstHalf = it.chunked(it.length/2)[0].toCharArray().toSet()
val secondHalf = it.chunked(it.length/2)[1].toCharArray().toSet()
val asciiCode = (firstHalf intersect secondHalf).first().code.toByt... | 0 | Kotlin | 0 | 1 | 5620296f1e7f2714c09cdb18c5aa6c59f06b73e6 | 1,032 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/d9/d9.kt | LaurentJeanpierre1 | 573,454,829 | false | {"Kotlin": 118105} | package d9
import readInput
import java.lang.IllegalArgumentException
import java.util.Scanner
data class Point(val x : Int, val y: Int) {}
fun moveHead(pt : Point, dir: String) : Point = when(dir) {
"U" -> Point(pt.x, pt.y+1)
"D" -> Point(pt.x, pt.y-1)
"L" -> Point(pt.x-1, pt.y)
"R" -> Point(pt.x+... | 0 | Kotlin | 0 | 0 | 5cf6b2142df6082ddd7d94f2dbde037f1fe0508f | 2,354 | aoc2022 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ConcatenatedWords.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,655 | kotlab | Apache License 2.0 |
src/leetcodeProblem/leetcode/editor/en/TwoSum.kt | faniabdullah | 382,893,751 | false | null | //Given an array of integers nums and an integer target, return indices of the
//two numbers such that they add up to target.
//
// You may assume that each input would have exactly one solution, and you may
//not use the same element twice.
//
// You can return the answer in any order.
//
//
// Example 1:
//
// ... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 1,698 | dsa-kotlin | MIT License |
src/day01/Code.kt | ldickmanns | 572,675,185 | false | {"Kotlin": 48227} | package day01
import readInput
fun main() {
val input = readInput("day01/input")
val inputAsInt = input.map {
if (it.isEmpty()) null else it.toInt()
}
println(part1(inputAsInt))
println(part2(inputAsInt))
}
fun part1(input: List<Int?>): Int {
var max = Int.MIN_VALUE
input.fold(0)... | 0 | Kotlin | 0 | 0 | 2654ca36ee6e5442a4235868db8174a2b0ac2523 | 874 | aoc-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/days/Day23.kt | andilau | 399,220,768 | false | {"Kotlin": 85768} | package days
@AdventOfCodePuzzle(
name = "<NAME>",
url = "https://adventofcode.com/2020/day/23",
date = Date(day = 23, year = 2020)
)
class Day23(val input: String) : Puzzle {
override fun partOne(): String {
return CupGame(input)
.playRounds(100)
.getCupsAfter(1)
... | 7 | Kotlin | 0 | 0 | 2809e686cac895482c03e9bbce8aa25821eab100 | 2,895 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/adventofcode2020/Day07HandyHaversacks.kt | n81ur3 | 484,801,748 | false | {"Kotlin": 476844, "Java": 275} | package adventofcode2020
class Day07HandyHaversacks
data class Bag(val type: String, val color: String, val canContain: Pair<Bag, Int>?) {
val bagName: String
get() = type + " " + color
fun containsBag(type: String, color: String, count: Int, recursive: Boolean = false): Boolean {
if (recursi... | 0 | Kotlin | 0 | 0 | fdc59410c717ac4876d53d8688d03b9b044c1b7e | 4,635 | kotlin-coding-challenges | MIT License |
day10/Kotlin/day10.kt | Ad0lphus | 353,610,043 | false | {"C++": 195638, "Python": 139359, "Kotlin": 80248} | import java.io.*
import java.util.*
fun print_day_10() {
val yellow = "\u001B[33m"
val reset = "\u001b[0m"
val green = "\u001B[32m"
println(yellow + "-".repeat(25) + "Advent of Code - Day 10" + "-".repeat(25) + reset)
println(green)
val process = Runtime.getRuntime().exec("figlet Syntax Sco... | 0 | C++ | 0 | 0 | 02f219ea278d85c7799d739294c664aa5a47719a | 2,336 | AOC2021 | Apache License 2.0 |
app/src/main/kotlin/aoc2022/day05/Day05.kt | dbubenheim | 574,231,602 | false | {"Kotlin": 18742} | package aoc2022.day05
import aoc2022.day05.Day05.part1
import aoc2022.day05.Day05.part2
import aoc2022.toFile
object Day05 {
private val stacksRegex = "^\\s+[0-9](\\s+[0-9]+)*\$".toRegex()
private val cratesRegex = "([A-Z])|\\s{2}(\\s)\\s".toRegex()
private val rearrangementRegex = "move ([0-9]+) from ([... | 8 | Kotlin | 0 | 0 | ee381bb9820b493d5e210accbe6d24383ae5b4dc | 3,063 | advent-of-code-2022 | MIT License |
src/Day01/Day01.kt | thmsbdr | 574,632,643 | false | {"Kotlin": 6603} | package Day01
import readInput
fun main() {
fun part1(input: List<String>): Int {
var max = 0
var current = 0
input.forEach {
if (it == "") {
if (current > max) {
max = current
}
current = 0
} else... | 0 | Kotlin | 0 | 0 | b9ac3ed8b52a95dcc542f4de79fb24163f3929a4 | 1,502 | AoC-2022 | Apache License 2.0 |
src/day07/Day07.kt | maxmil | 578,287,889 | false | {"Kotlin": 32792} | package day07
import println
import readInputAsText
import kotlin.math.abs
import kotlin.math.min
fun main() {
fun shortest(input: String, fuelUsed: (Int, Int) -> Int): Int {
val start = input.split(",").map { it.toInt() }
return (start.min()..start.max()).fold(Int.MAX_VALUE) { acc, position ->
... | 0 | Kotlin | 0 | 0 | 246353788b1259ba11321d2b8079c044af2e211a | 817 | advent-of-code-2021 | Apache License 2.0 |
app/src/main/kotlin/com/resurtm/aoc2023/day07/Solution.kt | resurtm | 726,078,755 | false | {"Kotlin": 119665} | package com.resurtm.aoc2023.day07
fun launchDay07(testCase: String) {
val ex = Exception("Cannot read the input")
val rawReader = object {}.javaClass.getResourceAsStream(testCase)?.bufferedReader()
val reader = rawReader ?: throw ex
val result = listOf(mutableListOf<Hand>(), mutableListOf())
while... | 0 | Kotlin | 0 | 0 | fb8da6c246b0e2ffadb046401502f945a82cfed9 | 3,843 | advent-of-code-2023 | MIT License |
src/Day04.kt | svignesh93 | 572,116,133 | false | {"Kotlin": 33603} | /**
* Advent of Code 2022
*
* --- Day 4: Camp Cleanup ---
*
* Space needs to be cleared before the last supplies can be unloaded from the ships,
* and so several Elves have been assigned the job of cleaning up sections of the camp.
* Every section has a unique ID number, and each Elf is assigned a range of secti... | 0 | Kotlin | 0 | 1 | ea533d256ba16c0210c2daf16ad1c6c37318b5b4 | 4,108 | AOC-2022 | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions56.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
fun test56() {
printlnResult1(intArrayOf(2, 4, 3, 6, 3, 2, 5, 5))
printlnResult1(intArrayOf(1, 1, 2, 3))
printlnResult1(intArrayOf(2, 3))
printlnResult2(intArrayOf(1, 2, 1, 1))
printlnResult2(intArrayOf(2, 3, 2, 1, 2, 3, 3))
printlnResult2(intArrayOf(1))
... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 2,105 | Algorithm | Apache License 2.0 |
src/day1/Day01.kt | francoisadam | 573,453,961 | false | {"Kotlin": 20236} | package day1
import readInput
fun main() {
fun part1(input: List<String>): Int {
val elvesSupplies = input.joinToString(",")
.split(",,")
.map { elfSupplies ->
elfSupplies.split(",").sumOf { it.toInt() }
}
return elvesSupplies.max()
}
fu... | 0 | Kotlin | 0 | 0 | e400c2410db4a8343c056252e8c8a93ce19564e7 | 1,100 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/days/aoc2020/Day24.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2020
import days.Day
class Day24: Day(2020, 24) {
override fun partOne(): Any {
return partOneSolution(inputList)
}
fun calculateStartingGrid(list: List<String>) : HexGrid<HexTile> {
val grid = HexGrid<HexTile>()
var currentCoordinate = Triple(0,0,0)
list.... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 5,840 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
kotlin/structures/Treap.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package structures
import java.util.Random
// https://cp-algorithms.com/data_structures/treap.html
object Treap {
var random: Random = Random()
fun split(root: Node?, minRight: Long): TreapPair {
if (root == null) return TreapPair(null, null)
root.push()
return if (root.key >= minRight... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 4,347 | codelibrary | The Unlicense |
kotlin/src/main/kotlin/io/github/ocirne/aoc/year2023/Day19.kt | ocirne | 327,578,931 | false | {"Python": 323051, "Kotlin": 67246, "Sage": 5864, "JavaScript": 832, "Shell": 68} | package io.github.ocirne.aoc.year2023
import io.github.ocirne.aoc.AocChallenge
class Day19(val lines: List<String>) : AocChallenge(2023, 19) {
companion object {
private val IDENTIFIER_PATTERN = """[a-z]+""".toRegex()
private val END_STATE_PATTERN = """[AR]""".toRegex()
private val PART_P... | 0 | Python | 0 | 1 | b8a06fa4911c5c3c7dff68206c85705e39373d6f | 5,609 | adventofcode | The Unlicense |
src/test/kotlin/Day05.kt | christof-vollrath | 317,635,262 | false | null | import io.kotest.core.spec.style.FunSpec
import io.kotest.data.forAll
import io.kotest.data.headers
import io.kotest.data.row
import io.kotest.data.table
import io.kotest.matchers.shouldBe
/*
--- Day 5: Binary Boarding ---
See https://adventofcode.com/2020/day/5
*/
fun decodeBoardingPass(passString: String): Int =... | 1 | Kotlin | 0 | 0 | 8ad08350aa4bd1a29b7e18765fc7a2d6de8021e8 | 2,917 | advent_of_code_2020 | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2020/Day09.kt | tginsberg | 315,060,137 | false | null | /*
* Copyright (c) 2020 by <NAME>
*/
/**
* Advent of Code 2020, Day 9 - Encoding Error
* Problem Description: http://adventofcode.com/2020/day/9
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2020/day9/
*/
package com.ginsberg.advent2020
class Day09(private val input: List<Long>) {
f... | 0 | Kotlin | 2 | 38 | 75766e961f3c18c5e392b4c32bc9a935c3e6862b | 1,195 | advent-2020-kotlin | Apache License 2.0 |
src/main/kotlin/com/manalili/advent/Day02.kt | maines-pet | 162,116,190 | false | null | package com.manalili.advent
class Day02 {
fun checksum(input: List<String>): Int {
var twos = 0
var threes = 0
input.map { boxId: String ->
val uniqueChars = boxId.toSet()
val uniqueCharsCount =
uniqueChars.map { boxId.count { c -> it == c } }.filter ... | 0 | Kotlin | 0 | 0 | 25a01e13b0e3374c4abb6d00cd9b8d7873ea6c25 | 1,377 | adventOfCode2018 | MIT License |
core-kotlin-modules/core-kotlin-collections-2/src/main/kotlin/com/baeldung/aggregate/AggregateOperations.kt | Baeldung | 260,481,121 | false | {"Kotlin": 1476024, "Java": 43013, "HTML": 4883} | package com.baeldung.aggregate
class AggregateOperations {
private val numbers = listOf(1, 15, 3, 8)
fun countList(): Int {
return numbers.count()
}
fun sumList(): Int {
return numbers.sum()
}
fun averageList(): Double {
return numbers.average()
}
fun maximum... | 10 | Kotlin | 273 | 410 | 2b718f002ce5ea1cb09217937dc630ff31757693 | 2,977 | kotlin-tutorials | MIT License |
src/main/kotlin/adventOfCode2015/Day13.kt | TetraTsunami | 716,279,556 | false | {"Kotlin": 29433} | package adventOfCode2015
import util.*
import org.apache.commons.collections4.iterators.PermutationIterator
@Suppress("unused")
class Day13(input: String) : Day(input) {
override fun solve() {
val moodMap = mutableMapOf<Pair<String, String>, Int>()
for (line in lines) {
val words = line... | 0 | Kotlin | 0 | 0 | 2a150a3381e790a5b45c9b74f77c1997315a5ba0 | 1,785 | AdventOfCode2015 | Apache License 2.0 |
src/main/kotlin/net/codetreats/aoc/day02/Game.kt | codetreats | 725,535,998 | false | {"Kotlin": 45007, "Shell": 1060} | package net.codetreats.aoc.day02
import kotlin.math.max
data class Game(val id: Int, val extractions: List<Extraction>) {
fun isPossible(input: Map<String, Int>) =
extractions.map { it.dices }.flatten().none { input[it.color]!! < it.amount }
fun power(): Int {
val min = mutableMapOf("green" t... | 0 | Kotlin | 0 | 1 | 3cd4aa53093b5f95328cf478e63fe2a7a4e90961 | 1,432 | aoc2023 | MIT License |
archive/src/main/kotlin/com/grappenmaker/aoc/year15/Day14.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year15
import com.grappenmaker.aoc.PuzzleSet
fun PuzzleSet.day14() = puzzle {
val allReindeer = inputLines.map { l ->
val split = l.split(" ")
Reindeer(split[0], split[3].toInt(), split[6].toInt(), split[13].toInt())
}
val timeRange = 0..<2503 // seconds
v... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,226 | advent-of-code | The Unlicense |
app/src/main/kotlin/solution/Solution1392.kt | likexx | 559,794,763 | false | {"Kotlin": 136661} | package solution
import solution.annotation.Leetcode
import kotlin.math.exp
class Solution1392 {
@Leetcode(1392)
class Solution {
fun longestPrefix(s: String): String {
val dp = IntArray(s.length) { 0 }
var len = 0
var i = 1
while (i < s.length) {
... | 0 | Kotlin | 0 | 0 | 376352562faf8131172e7630ab4e6501fabb3002 | 3,381 | leetcode-kotlin | MIT License |
src/main/kotlin/com/leetcode/random_problems/easy/maximum_product_in_array/Main.kt | frikit | 254,842,734 | false | null | package com.leetcode.random_problems.easy.maximum_product_in_array
fun main() {
println("Test case 1:")
// Explanation: We can choose indices 1 and 3 for the first pair (6, 7) and indices 2 and 4 for the second pair (2, 4).
// The product difference is (6 * 7) - (2 * 4) = 34.
println(Solution().maxProduc... | 0 | Kotlin | 0 | 0 | dda68313ba468163386239ab07f4d993f80783c7 | 1,000 | leet-code-problems | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MatrixBlockSum.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,704 | kotlab | Apache License 2.0 |
src/Day01.kt | SnyderConsulting | 573,040,913 | false | {"Kotlin": 46459} | fun main() {
fun getElvesList(input: List<String>): List<List<Int>> {
val elves = mutableListOf(mutableListOf<Int>())
var counter = 0
input.forEach {
if (it.isBlank()) {
counter += 1
elves.add(mutableListOf())
} else {
... | 0 | Kotlin | 0 | 0 | ee8806b1b4916fe0b3d576b37269c7e76712a921 | 993 | Advent-Of-Code-2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.