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/g2901_3000/s2926_maximum_balanced_subsequence_sum/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2901_3000.s2926_maximum_balanced_subsequence_sum
// #Hard #Array #Dynamic_Programming #Binary_Search #Segment_Tree #Binary_Indexed_Tree
// #2024_01_16_Time_636_ms_(100.00%)_Space_66.4_MB_(66.67%)
import kotlin.math.max
@Suppress("NAME_SHADOWING")
class Solution {
fun maxBalancedSubsequenceSum(nums: IntA... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,035 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/leonra/adventofcode/advent2023/day02/Day2.kt | LeonRa | 726,688,446 | false | {"Kotlin": 30456} | package com.leonra.adventofcode.advent2023.day02
import com.leonra.adventofcode.shared.readResource
import kotlin.math.max
/** https://adventofcode.com/2023/day/2 */
private object Day2 {
fun partOne(): Int {
val redMax = 12
val greenMax = 13
val blueMax = 14
var sum = 0
... | 0 | Kotlin | 0 | 0 | 46bdb5d54abf834b244ba9657d0d4c81a2d92487 | 2,194 | AdventOfCode | Apache License 2.0 |
app/src/main/java/online/vapcom/codewars/strings/MostFrequentlyUsedWords.kt | vapcomm | 503,057,535 | false | {"Kotlin": 142486} | package online.vapcom.codewars.strings
/**
* #24 Most frequently used words in a text - 4 kyu
*
* https://www.codewars.com/kata/51e056fe544cf36c410000fb/train/kotlin
*/
fun top3(str: String): List<String> {
fun plusOne(map: HashMap<String, Int>, word: String) {
map.merge(word, 1) { old, value ->
... | 0 | Kotlin | 0 | 0 | 97b50e8e25211f43ccd49bcee2395c4bc942a37a | 2,430 | codewars | MIT License |
src/Day01.kt | ked4ma | 573,017,240 | false | {"Kotlin": 51348} | /**
* [Day01](https://adventofcode.com/2022/day/1)
*/
fun main() {
fun convInput(input: List<String>): List<Int> = buildList {
var list = ArrayList<Int>()
for (s in input) {
if (s.isEmpty()) {
if (list.size > 0) {
add(list)
list =... | 1 | Kotlin | 0 | 0 | 6d4794d75b33c4ca7e83e45a85823e828c833c62 | 1,022 | aoc-in-kotlin-2022 | Apache License 2.0 |
src/pl/shockah/aoc/y2021/Day4.kt | Shockah | 159,919,224 | false | null | package pl.shockah.aoc.y2021
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import pl.shockah.aoc.AdventTask
import pl.shockah.unikorn.collection.Array2D
class Day4: AdventTask<Day4.Input, Int, Int>(2021, 4) {
data class Input(
val rng: List<Int>,
val boards: List<Array2D<Int>>
)
ov... | 0 | Kotlin | 0 | 0 | 9abb1e3db1cad329cfe1e3d6deae2d6b7456c785 | 3,139 | Advent-of-Code | Apache License 2.0 |
Kotlin/search/TernarySearch.kt | HarshCasper | 274,711,817 | false | {"C++": 1488046, "Java": 948670, "Python": 703942, "C": 615475, "JavaScript": 228879, "Go": 166382, "Dart": 107821, "Julia": 82766, "C#": 76519, "Kotlin": 40240, "PHP": 5465} | //Kotlin program to implement ternary search using recursive approach
import java.util.*
// A function to declare ternary search
fun ternarySearch(left:Int, right:Int, key:Int, array: ArrayList<Int>): Int{
if (right >= left) {
// Finding the midterms
val mid1 = left + (right - left) / 3
v... | 2 | C++ | 1,086 | 877 | 4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be | 2,901 | NeoAlgo | MIT License |
aoc-2020/src/commonMain/kotlin/fr/outadoc/aoc/twentytwenty/Day24.kt | outadoc | 317,517,472 | false | {"Kotlin": 183714} | package fr.outadoc.aoc.twentytwenty
import fr.outadoc.aoc.scaffold.Day
import fr.outadoc.aoc.scaffold.readDayInput
class Day24 : Day<Int> {
private enum class Color { WHITE, BLACK }
private fun Color.flip(): Color = when (this) {
Color.WHITE -> Color.BLACK
Color.BLACK -> Color.WHITE
}
... | 0 | Kotlin | 0 | 0 | 54410a19b36056a976d48dc3392a4f099def5544 | 5,043 | adventofcode | Apache License 2.0 |
2019/day6/orbits.kt | sergeknystautas | 226,467,020 | false | null | package aoc2019.day6;
import java.io.File;
fun LoadOrbits(filename: String) : List<String> {
return File(filename).readLines();
}
fun MapOrbits(lines: List<String>): Map<String, String> {
var orbits = lines.associateBy (
{ it.split(")")[1]},
{ it.split(")")[0]}
);
return orbits;
}... | 0 | Kotlin | 0 | 0 | 38966bc742f70122681a8885e986ed69dd505243 | 2,104 | adventofkotlin2019 | Apache License 2.0 |
year2020/day03/trees/src/main/kotlin/com/curtislb/adventofcode/year2020/day03/trees/TreeField.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.year2020.day03.trees
import com.curtislb.adventofcode.common.grid.Grid
import com.curtislb.adventofcode.common.geometry.Point
import com.curtislb.adventofcode.common.geometry.Ray
import com.curtislb.adventofcode.common.grid.toGrid
import com.curtislb.adventofcode.common.number.Fractio... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,268 | AdventOfCode | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/PartitionString.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,916 | kotlab | Apache License 2.0 |
src/main/kotlin/day08/Code.kt | fcolasuonno | 317,324,330 | false | null | package day08
import isDebug
import java.io.File
fun main() {
val name = if (isDebug()) "test.txt" else "input.txt"
System.err.println(name)
val dir = ::main::class.java.`package`.name
val input = File("src/main/kotlin/$dir/$name").readLines()
val parsed = parse(input)
part1(parsed)
part2(... | 0 | Kotlin | 0 | 0 | e7408e9d513315ea3b48dbcd31209d3dc068462d | 2,272 | AOC2020 | MIT License |
src/main/kotlin/com/jaspervanmerle/aoc2020/day/Day18.kt | jmerle | 317,518,472 | false | null | package com.jaspervanmerle.aoc2020.day
class Day18 : Day("654686398176", "8952864356993") {
private val parensRegex = "\\(([^()]*)\\)".toRegex()
private val addRegex = "(\\d+) \\+ (\\d+)".toRegex()
private val multiplyRegex = "(\\d+) \\* (\\d+)".toRegex()
override fun solvePartOne(): Any {
ret... | 0 | Kotlin | 0 | 0 | 81765a46df89533842162f3bfc90f25511b4913e | 2,055 | advent-of-code-2020 | MIT License |
src/main/kotlin/cloud/dqn/leetcode/PalindromeLinkedListKt.kt | aviuswen | 112,305,062 | false | null | package cloud.dqn.leetcode
/**
* https://leetcode.com/problems/palindrome-linked-list/description/
*
Given a singly linked list, determine if it is a palindrome.
Follow up:
Could you do it in O(n) time and O(1) space?
*/
class PalindromeLinkedListKt {
class ListNode(var `val`: Int = 0) {
va... | 0 | Kotlin | 0 | 0 | 23458b98104fa5d32efe811c3d2d4c1578b67f4b | 6,305 | cloud-dqn-leetcode | No Limit Public License |
src/sort/HeapSort.kt | daolq3012 | 143,137,563 | false | null | package sort
import extention.swap
import java.io.IOException
/**
* * Heap Sort Algorithm.
* * @see: http://staff.ustc.edu.cn/~csli/graduate/algorithms/book6/chap07.htm
*/
class HeapSort : SortAlgorithms<ArrayList<Int>> {
override fun sort(arr: ArrayList<Int>) {
val count = arr.size
// check ... | 1 | Kotlin | 11 | 74 | 40e00d0d3f1c7cbb93ad28f4197e7ffa5ea36ef9 | 2,706 | Kotlin-Algorithms | Apache License 2.0 |
src/main/kotlin/kr/co/programmers/P60059.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://school.programmers.co.kr/learn/courses/30/lessons/60059
class P60059 {
fun solution(k: Array<IntArray>, lock: Array<IntArray>): Boolean {
var key = k
repeat(4) { // 키를 4번 회전면서 체크한다.
if (check(key, lock)) {
return true
}
... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,971 | algorithm | MIT License |
src/adventofcode/Day15.kt | Timo-Noordzee | 573,147,284 | false | {"Kotlin": 80936} | package adventofcode
import org.openjdk.jmh.annotations.*
import java.util.concurrent.TimeUnit
import kotlin.math.abs
import kotlin.math.absoluteValue
private operator fun List<MatchResult>.component1() = this[0].groupValues[1].toInt()
private operator fun List<MatchResult>.component2() = this[1].groupValues[2].toInt... | 0 | Kotlin | 0 | 2 | 10c3ab966f9520a2c453a2160b143e50c4c4581f | 2,817 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day25.kt | jvmusin | 572,685,421 | false | {"Kotlin": 86453} | import java.util.*
import kotlin.math.abs
fun main() {
val cost = mapOf(
'2' to 2,
'1' to 1,
'0' to 0,
'-' to -1,
'=' to -2
)
fun String.snafuToLong(): Long {
var n = 0L
var k = 1L
for (c in reversed()) {
n += k * cost[c]!!
... | 1 | Kotlin | 0 | 0 | 4dd83724103617aa0e77eb145744bc3e8c988959 | 1,798 | advent-of-code-2022 | Apache License 2.0 |
src/aoc22/Day12.kt | mihassan | 575,356,150 | false | {"Kotlin": 123343} | @file:Suppress("PackageDirectoryMismatch")
package aoc2022.day12
import lib.Grid
import lib.Point
import lib.Solution
enum class PlotType {
START, END, MIDDLE
}
data class Plot(val plotType: PlotType, val height: Int) {
infix fun canStepTo(other: Plot): Boolean = other.height <= height + 1
companion object {... | 0 | Kotlin | 0 | 0 | 698316da8c38311366ee6990dd5b3e68b486b62d | 2,043 | aoc-kotlin | Apache License 2.0 |
year2022/src/cz/veleto/aoc/year2022/Day20.kt | haluzpav | 573,073,312 | false | {"Kotlin": 164348} | package cz.veleto.aoc.year2022
import cz.veleto.aoc.core.AocDay
class Day20(config: Config) : AocDay(config) {
override fun part1(): String {
val list = parseList().toList()
val mixedList = mix(list, rounds = 1)
return getGroveCoors(mixedList).toString()
}
override fun part2(): S... | 0 | Kotlin | 0 | 1 | 32003edb726f7736f881edc263a85a404be6a5f0 | 2,738 | advent-of-pavel | Apache License 2.0 |
src/Day03.kt | er453r | 572,440,270 | false | {"Kotlin": 69456} | fun main() {
val lowerScoreOffset = 'a'.code - 1
val upperScoreOffset = 'A'.code - 1 - 26
fun Char.priority(): Int = this.code - (if (this.code > lowerScoreOffset) lowerScoreOffset else upperScoreOffset)
fun part1(input: List<String>): Int = input.sumOf { items ->
items.chunked(items.length / ... | 0 | Kotlin | 0 | 0 | 9f98e24485cd7afda383c273ff2479ec4fa9c6dd | 800 | aoc2022 | Apache License 2.0 |
logicsolver/src/main/kotlin/nl/hiddewieringa/logicsolver/Solver.kt | hiddewie | 147,922,971 | false | null | package nl.hiddewieringa.logicsolver
interface LogicPuzzleSolver<IN, OUT> {
fun solve(input: IN): OneOf<OUT, List<LogicSolveError>>
}
/**
* Solving data structure for sudokus.
*
* Contains its location, its value, and any values that are not allowed.
*/
class SudokuSolveData(val coordinate: Coordinate, val va... | 0 | Kotlin | 0 | 0 | bcf12c102f4ab77c5aa380dbf7c98a1cc3e585c0 | 5,247 | LogicSolver | MIT License |
src/Day02.kt | hiteshchalise | 572,795,242 | false | {"Kotlin": 10694} | fun main() {
fun part1(input: List<String>): Int {
val score = input.fold(0) { acc, round ->
val (opponentMove, yourMove) = round.split(" ")
val score: Int = when(opponentMove) {
"A" -> {
when (yourMove) {
"X" -> 1 + 3
... | 0 | Kotlin | 0 | 0 | e4d66d8d1f686570355b63fce29c0ecae7a3e915 | 2,338 | aoc-2022-kotlin | Apache License 2.0 |
codeforces/vk2022/round1/d.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.vk2022.round1
import kotlin.math.roundToLong
import kotlin.math.sqrt
private fun solve() {
readln()
val a = readInts()
var ans = 1
val toTest = mutableSetOf<Long>()
for (i in a.indices) for (j in 0 until i) {
val ba = a[i] - a[j]
for (d in 1..ba) {
if (d * d > ba) break
if (ba % d !=... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 860 | competitions | The Unlicense |
jvm/src/main/kotlin/io/prfxn/aoc2021/day19.kt | prfxn | 435,386,161 | false | {"Kotlin": 72820, "Python": 362} | // Beacon Scanner (https://adventofcode.com/2021/day/19)
package io.prfxn.aoc2021
import kotlin.math.abs
private typealias CT = Triple<Int, Int, Int>
fun main() {
val orientationMappers = // region sequenceOf..
sequenceOf(
{ t: CT -> t.let { (x, y, z) -> Triple(x, y, z) } }, // (default)... | 0 | Kotlin | 0 | 0 | 148938cab8656d3fbfdfe6c68256fa5ba3b47b90 | 4,812 | aoc2021 | MIT License |
src/main/kotlin/days/Day02.kt | TheMrMilchmann | 571,779,671 | false | {"Kotlin": 56525} | /*
* Copyright (c) 2022 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, dis... | 0 | Kotlin | 0 | 1 | 2e01ab62e44d965a626198127699720563ed934b | 2,729 | AdventOfCode2022 | MIT License |
src/Day11.kt | rromanowski-figure | 573,003,468 | false | {"Kotlin": 35951} | object Day11 : Runner<Long, Long>(11, 10605L, 2713310158L) {
private fun String.toItems(): List<Item> = split(",").map { Item(it.trim().toLong()) }
object Regex {
val monkey = """Monkey (\d+):""".toRegex()
val itemList = """\s+Starting items: (.*)""".toRegex()
val operation = """\s+Ope... | 0 | Kotlin | 0 | 0 | 6ca5f70872f1185429c04dcb8bc3f3651e3c2a84 | 7,002 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/main/kotlin/g0701_0800/s0786_k_th_smallest_prime_fraction/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0701_0800.s0786_k_th_smallest_prime_fraction
// #Medium #Array #Binary_Search #Heap_Priority_Queue
// #2023_03_13_Time_165_ms_(100.00%)_Space_35.8_MB_(100.00%)
class Solution {
fun kthSmallestPrimeFraction(arr: IntArray, k: Int): IntArray {
val n = arr.size
var low = 0.0
var high ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,676 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/lesson3/FrogJmp.kt | iafsilva | 633,017,063 | false | null | package lesson3
/**
* A small frog wants to get to the other side of the road.
*
* The frog is currently located at position X and wants to get to a position greater than or equal to Y.
*
* The small frog always jumps a fixed distance, D.
*
* Count the minimal number of jumps that the small frog must perform to... | 0 | Kotlin | 0 | 0 | 5d86aefe70e9401d160c3d87c09a9bf98f6d7ab9 | 1,291 | codility-lessons | Apache License 2.0 |
src/Day06.kt | BionicCa | 574,904,899 | false | {"Kotlin": 20039} | fun main() {
fun part1(input: List<String>): Int {
val dataStream = input.first().toCharArray()
val checkCharacters = 4
for (i in dataStream.indices) {
if (i + checkCharacters - 1 >= dataStream.size) break
val slice = dataStream.slice(i until i + checkCharacters)
... | 0 | Kotlin | 0 | 0 | ed8bda8067386b6cd86ad9704bda5eac81bf0163 | 1,202 | AdventOfCode2022 | Apache License 2.0 |
src/main/kotlin/aoc04/solution.kt | dnene | 317,653,484 | false | null | package aoc04
import aoc04.Field.Companion.fieldMap
import java.io.File
enum class Field(
val str: String,
val validator: ((String) -> Boolean)? = null
) {
BirthYear("byr", { it.length == 4 && it.all { it.isDigit() } && it.toInt() in (1920..2002) }),
IssueYear("iyr", { it.length == 4 && it.all { it.is... | 0 | Kotlin | 0 | 0 | db0a2f8b484575fc3f02dc9617a433b1d3e900f1 | 2,634 | aoc2020 | MIT License |
src/main/kotlin/com/kishor/kotlin/algo/dp/GlobMatching.kt | kishorsutar | 276,212,164 | false | null | package com.kishor.kotlin.algo.dp
fun isMatch(fileName: String, pattern: String): Boolean {
val sLen = fileName.length
val pLen = pattern.length
// base cases
if (pattern == fileName || pattern == "*") return true
if (pattern.isEmpty() || fileName.isEmpty()) return false
// init all matrix e... | 0 | Kotlin | 0 | 0 | 6672d7738b035202ece6f148fde05867f6d4d94c | 1,693 | DS_Algo_Kotlin | MIT License |
meistercharts-commons/src/commonMain/kotlin/it/neckar/open/kotlin/lang/RandomExt.kt | Neckar-IT | 599,079,962 | false | {"Kotlin": 5819931, "HTML": 87784, "JavaScript": 1378, "CSS": 1114} | package it.neckar.open.kotlin.lang
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.pow
import kotlin.math.sqrt
import kotlin.random.Random
/**
* Code adopted from KDS (License: Apache or MIT)
*/
fun Random.ints(): Sequence<Int> = sequence { while (true) yield(nextInt()) }
fun Random.ints(from: Int,... | 3 | Kotlin | 3 | 5 | ed849503e845b9d603598e8d379f6525a7a92ee2 | 3,265 | meistercharts | Apache License 2.0 |
src/main/kotlin/com/groundsfam/advent/y2020/d20/Day20.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2020.d20
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.sqrt
import kotlin.io.path.div
import kotlin.io.path.useLines
typealias Tile = List<String>
/**
* Returns all edges of this tile, read both clockwise (cw)
* and counterclockwise (ccw). The order is:
* cw t... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 9,997 | advent-of-code | MIT License |
src/main/kotlin/org/vitrivr/cottontail/utilities/name/Name.kt | frankier | 278,349,990 | true | {"Kotlin": 1020644, "Dockerfile": 280} | package org.vitrivr.cottontail.utilities.name
/**
* A [Name] that identifies a DBO used within Cottontail DB.
*
* @author <NAME>
* @version 1.0
*/
class Name(name: String) {
companion object {
/** The separator between Cottontail DB name components. */
const val COTTONTAIL_NAME_COMPONENT_SEP... | 0 | Kotlin | 0 | 0 | e4ec66eaf014bb8ea4399cc7ea54062f16cf0c60 | 7,544 | cottontaildb | MIT License |
src/main/kotlin/g1101_1200/s1191_k_concatenation_maximum_sum/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1101_1200.s1191_k_concatenation_maximum_sum
// #Medium #Array #Dynamic_Programming #2023_05_25_Time_389_ms_(100.00%)_Space_77.8_MB_(100.00%)
class Solution {
private var mod = (1e9 + 7).toInt()
fun kConcatenationMaxSum(arr: IntArray, k: Int): Int {
var sum: Long = 0
for (i in arr.ind... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,821 | LeetCode-in-Kotlin | MIT License |
src/year2015/day22/Day22.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2015.day22
import readInput
import kotlin.math.max
fun main() {
// test if implementation meets criteria from the description, like:
val input = readInput("2015", "Day22")
println(part1(input))
println(part2(input))
}
private fun part1(input: List<String>) = winWithLeastManaSpent(toGame(i... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 4,080 | AdventOfCode | Apache License 2.0 |
kotlin/src/main/kotlin/com/pbh/soft/day7/Day7Solver.kt | phansen314 | 579,463,173 | false | {"Kotlin": 105902} | package com.pbh.soft.day7
import cc.ekblad.konbini.*
import com.pbh.soft.common.Solver
import com.pbh.soft.common.parsing.ParsingUtils.newlineP
import com.pbh.soft.common.parsing.ParsingUtils.onSuccess
import com.pbh.soft.common.parsing.ParsingUtils.parseMap
import com.pbh.soft.day7.Card._J
import com.pbh.soft.day7.Ha... | 0 | Kotlin | 0 | 0 | 7fcc18f453145d10aa2603c64ace18df25e0bb1a | 4,004 | advent-of-code | MIT License |
src/Day06.kt | Yasenia | 575,276,480 | false | {"Kotlin": 15232} | fun main() {
fun getStartOfMessage(message: String, markerSize: Int): Int {
val data = message.toCharArray()
var startPosition = markerSize
while (data.slice(startPosition - markerSize until startPosition).distinct().count() < markerSize) startPosition++
return startPosition
}
... | 0 | Kotlin | 0 | 0 | 9300236fa8697530a3c234e9cb39acfb81f913ba | 1,145 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/leetcodeProblem/leetcode/editor/en/RankTeamsByVotes.kt | faniabdullah | 382,893,751 | false | null | //In a special ranking system, each voter gives a rank from highest to lowest
//to all teams participated in the competition.
//
// The ordering of teams is decided by who received the most position-one votes.
// If two or more teams tie in the first position, we consider the second
//position to resolve the conflict... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 5,070 | dsa-kotlin | MIT License |
java/com/google/android/libraries/pcc/chronicle/analysis/Utils.kt | google | 564,990,777 | false | {"Kotlin": 1440335, "Starlark": 162149, "Java": 10061, "AIDL": 5852, "Python": 4367, "Dockerfile": 2035, "Shell": 1301} | /*
* Copyright 2022 Google LLC
*
* 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 ... | 0 | Kotlin | 8 | 27 | cc72138bf0d0d77aedbc05dd4d3d9e4bb7e28f17 | 3,267 | private-compute-libraries | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year18/Day23.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year18
import com.grappenmaker.aoc.*
fun PuzzleSet.day23() = puzzle(day = 23) {
data class Bot(val pos: Point3D, val r: Int)
val bots = inputLines.map { l ->
val (x, y, z, r) = l.splitInts()
Bot(Point3D(x, y, z), r)
}
fun Point3D.inRange(bot: Bot) = this m... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 4,218 | advent-of-code | The Unlicense |
src/main/kotlin/fijb/leetcode/algorithms/A4MedianOfTwoSortedArrays.kt | fi-jb | 552,324,917 | false | {"Kotlin": 22836} | package fijb.leetcode.algorithms
//https://leetcode.com/problems/median-of-two-sorted-arrays/
object A4MedianOfTwoSortedArrays {
fun findMedianSortedArrays(nums1: IntArray, nums2: IntArray): Double {
val nums = arrayListOf<Int>()
var i1 = 0
var i2 = 0
val s = (nums1.size + nums2.si... | 0 | Kotlin | 0 | 0 | f0d59da5bcffaa7a008fe6b83853306d40ac4b90 | 828 | leetcode | MIT License |
src/Day09.kt | mihansweatpants | 573,733,975 | false | {"Kotlin": 31704} | import java.lang.IllegalArgumentException
import kotlin.math.abs
fun main() {
fun part1(moves: List<RopeMove>): Int {
val visitedPositions = mutableSetOf<KnotPosition>()
var headKnotPosition = KnotPosition(0, 0)
var tailKnotPosition = KnotPosition(0, 0)
visitedPositions.add(tailKn... | 0 | Kotlin | 0 | 0 | 0de332053f6c8f44e94f857ba7fe2d7c5d0aae91 | 3,529 | aoc-2022 | Apache License 2.0 |
melif/src/main/kotlin/ru/ifmo/ctddev/isaev/datasetFilter.kt | siviae | 53,358,845 | false | {"Kotlin": 152748, "Java": 152582} | package ru.ifmo.ctddev.isaev
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import ru.ifmo.ctddev.isaev.point.Point
import java.util.*
/**
* @author iisaev
*/
enum class NormalizationMode { NONE, VALUE_BASED, MEASURE_BASED }
fun DoubleArray.normalize(min: Double, max: Double) {
this.forEachIndexed { i... | 0 | Kotlin | 0 | 1 | 2a3300ea32dda160d400258f2400c03ad84cb713 | 5,115 | parallel-feature-selection | MIT License |
src/main/kotlin/g0501_0600/s0502_ipo/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0501_0600.s0502_ipo
// #Hard #Array #Sorting #Greedy #Heap_Priority_Queue
// #2023_01_06_Time_799_ms_(54.55%)_Space_88.5_MB_(9.09%)
import java.util.PriorityQueue
class Solution {
inner class Data(var profit: Int, var capital: Int)
// max heap for profit
var profitMaxHeap = PriorityQueue<Data> ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,562 | LeetCode-in-Kotlin | MIT License |
Special_factorials/Kotlin/src/main/kotlin/Special.kt | ncoe | 108,064,933 | false | {"D": 425100, "Java": 399306, "Visual Basic .NET": 343987, "C++": 328611, "C#": 289790, "C": 216950, "Kotlin": 162468, "Modula-2": 148295, "Groovy": 146721, "Lua": 139015, "Ruby": 84703, "LLVM": 58530, "Python": 46744, "Scala": 43213, "F#": 21133, "Perl": 13407, "JavaScript": 6729, "CSS": 453, "HTML": 409} | import java.math.BigInteger
import java.util.function.Function
/* n! = 1 * 2 * 3 * ... * n */
fun factorial(n: Int): BigInteger {
val bn = BigInteger.valueOf(n.toLong())
var result = BigInteger.ONE
var i = BigInteger.TWO
while (i <= bn) {
result *= i++
}
return result
}
/* if(n!) = n *... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 2,529 | rosetta | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[46]全排列.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | import java.util.*
import kotlin.collections.ArrayList
//给定一个不含重复数字的数组 nums ,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。
//
//
//
// 示例 1:
//
//
//输入:nums = [1,2,3]
//输出:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
//
//
// 示例 2:
//
//
//输入:nums = [0,1]
//输出:[[0,1],[1,0]]
//
//
// 示例 3:
//
//
//输入:nums = [1]
//输出:[[1]... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,843 | MyLeetCode | Apache License 2.0 |
src/Day06.kt | weberchu | 573,107,187 | false | {"Kotlin": 91366} | private fun isUniqueMarker(s: String): Boolean {
for (i in s.indices) {
if (s.indexOf(s[i], i + 1) != -1) {
return false
}
}
return true
}
private fun endIndexOfMarker(input: List<String>, markerLength: Int): Int {
val data = input[0]
for (i in data.indices) {
i... | 0 | Kotlin | 0 | 0 | 903ff33037e8dd6dd5504638a281cb4813763873 | 837 | advent-of-code-2022 | Apache License 2.0 |
src/leetcodeProblem/leetcode/editor/en/MissingNumber.kt | faniabdullah | 382,893,751 | false | null | //Given an array nums containing n distinct numbers in the range [0, n], return
//the only number in the range that is missing from the array.
//
//
// Example 1:
//
//
//Input: nums = [3,0,1]
//Output: 2
//Explanation: n = 3 since there are 3 numbers, so all numbers are in the range
//[0,3]. 2 is the missing numb... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,026 | dsa-kotlin | MIT License |
src/main/kotlin/com/sk/topicWise/trie/211. Add and Search Word - Data structure design.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package com.sk.topicWise.trie
class WordDictionary() {
private class TrieNode {
var wordEnd = false
var children = HashMap<Char, TrieNode>()
}
private var root = TrieNode()
fun addWord(word: String) {
var cur = root
for (ch in word) {
if (!cur.children.con... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 2,297 | leetcode-kotlin | Apache License 2.0 |
advent-of-code-2021/src/code/day13a/Main.kt | Conor-Moran | 288,265,415 | false | {"Kotlin": 53347, "Java": 14161, "JavaScript": 10111, "Python": 6625, "HTML": 733} | package code.day13a
import java.io.File
import java.lang.Integer.max
import kotlin.math.min
fun main() {
doIt("Day 13a Part 2: Test Input", "src/code/day13a/test.input", part2)
doIt("Day 13a Part 2: Real Input", "src/code/day13a/part1.input", part2);
}
fun doIt(msg: String, input: String, calc: (nums: List<S... | 0 | Kotlin | 0 | 0 | ec8bcc6257a171afb2ff3a732704b3e7768483be | 3,218 | misc-dev | MIT License |
src/main/kotlin/Excercise13.kt | underwindfall | 433,989,850 | false | {"Kotlin": 55774} | private fun part1() {
val input = getInputAsTest("13")
var a =
input
.takeWhile { it.isNotEmpty() }
.map { it.split(",").map { it.toInt() }.let { (x, y) -> Point(x, y) } }
.toSet()
val i = input.indexOf("") + 1
val s = input[i]
val pr = "fold along "
check(s.startsWith(pr))
val ss =... | 0 | Kotlin | 0 | 0 | 4fbee48352577f3356e9b9b57d215298cdfca1ed | 1,847 | advent-of-code-2021 | MIT License |
src/main/kotlin/dev/siller/aoc2023/Day13.kt | chearius | 725,594,554 | false | {"Kotlin": 50795, "Shell": 299} | package dev.siller.aoc2023
import kotlin.math.min
data object Day13 : AocDayTask<UInt, UInt>(
day = 13,
exampleInput =
"""
|#.##..##.
|..#.##.#.
|##......#
|##......#
|..#.##.#.
|..##..##.
|#.#.##.#.
|
|#...##..#
|#....#..... | 0 | Kotlin | 0 | 0 | fab1dd509607eab3c66576e3459df0c4f0f2fd94 | 2,900 | advent-of-code-2023 | MIT License |
src/net/sheltem/aoc/y2023/Day22.kt | jtheegarten | 572,901,679 | false | {"Kotlin": 178521} | package net.sheltem.aoc.y2023
import net.sheltem.common.mapParallel
suspend fun main() {
Day22().run()
}
class Day22 : Day<Long>(5, 7) {
override suspend fun part1(input: List<String>): Long = input.map { it.toBrick() }.settle().canDisintegrate().count().toLong()
override suspend fun part2(input: List<... | 0 | Kotlin | 0 | 0 | ac280f156c284c23565fba5810483dd1cd8a931f | 2,877 | aoc | Apache License 2.0 |
src/day14/Day14.kt | pocmo | 433,766,909 | false | {"Kotlin": 134886} | package day14
import java.io.File
fun readFile(fileName: String): Pair<String, Map<String, String>> {
return readFromString(File(fileName)
.readText()
.trim())
}
fun Map<String, String>.toCharacterMap(): Map<String, Char> {
return mapValues { (_, character) -> character[0] }
}
fun performIns... | 0 | Kotlin | 1 | 2 | 73bbb6a41229e5863e52388a19108041339a864e | 4,844 | AdventOfCode2021 | Apache License 2.0 |
leetcode2/src/leetcode/closestDivisors.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* @Classname closestDivisors
* @Description TODO
* @Date 2020-05-16 13:47
* @Created by jianhao
* 给你一个整数 num,请你找出同时满足下面全部要求的两个整数:
两数乘积等于 num + 1 或 num + 2
以绝对差进行度量,两数大小最接近
你可以按任意顺序返回这两个整数。
示例 1:
输入:num = 8
输出:[3,3]
解释:对于 num + 1 = 9,最接近的两个因数是 3 & 3;对于 num + 2 = 10, 最接近的两个因数是 2 & 5,因此返回 ... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,535 | leetcode | MIT License |
src/main/kotlin/ru/timakden/aoc/year2022/Day17.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2022
import ru.timakden.aoc.util.Point
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 17: Pyroclastic Flow](https://adventofcode.com/2022/day/17).
*/
object Day17 {
@JvmStatic
fun main(args: Array<String>) {
measure {
val ... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 5,178 | advent-of-code | MIT License |
src/main/kotlin/g2301_2400/s2382_maximum_segment_sum_after_removals/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2301_2400.s2382_maximum_segment_sum_after_removals
// #Hard #Array #Prefix_Sum #Union_Find #Ordered_Set
// #2023_07_02_Time_857_ms_(50.00%)_Space_60_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
private class UF(n: Int) {
var root: IntArray
var sum: LongArray
init {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,847 | LeetCode-in-Kotlin | MIT License |
src/solutionsForBookCrackingTheCodingInterview/linkedLists/MathActions.kt | mrkostua | 120,207,236 | false | null | package solutionsForBookCrackingTheCodingInterview.linkedLists
/**
* @author <NAME>
* @created on 3/20/2018
* "Cracking the Coding Interview" task 2.4
*/
/**
* Task :
* You have two numbers represented by a linked list, where each node contains a single
* digit. The digits are stored in reverse order, such tha... | 0 | Kotlin | 0 | 0 | bfb7124e93e485bee5ee8c4b69bf9c0a0a532ecf | 2,385 | Cracking-the-Coding-Interview-solutions | MIT License |
src/Utils.kt | MisterTeatime | 561,848,263 | false | {"Kotlin": 37980} | import java.io.File
import java.math.BigInteger
import java.security.MessageDigest
import kotlin.math.absoluteValue
/**
* 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, ... | 0 | Kotlin | 0 | 0 | d684bd252a9c6e93106bdd8b6f95a45c9924aed6 | 6,040 | AoC2022 | Apache License 2.0 |
2021/src/main/kotlin/day25_imp.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.IntGrid
import utils.Parser
import utils.Solution
import utils.Vec2i
import utils.wrap
fun main() {
Day25Imp.run()
}
object Day25Imp : Solution<IntGrid>() {
override val name = "day25"
private const val EMPTY = 0
private const val EAST = 1
private const val SOUTH = 2
override val parser = P... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,807 | aoc_kotlin | MIT License |
kotlin/graphs/spanningtree/SteinerTree.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package graphs.spanningtree
object SteinerTree {
fun minLengthSteinerTree(g: Array<IntArray>, verticesToConnect: IntArray): Int {
val n = g.size
val m = verticesToConnect.size
if (m <= 1) return 0
for (k in 0 until n) for (i in 0 until n) for (j in 0 until n) g[i][j] = Math.min(g[i]... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,176 | codelibrary | The Unlicense |
Bootcamp_01/src/exercise2/src/main/kotlin/Exercise1.kt | Hasuk1 | 740,111,124 | false | {"Kotlin": 120039} | import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.pow
import kotlin.math.sqrt
fun readZone(): Zone? {
println("Enter zone parameters:")
val input = readLine() ?: return null
val parts = input.split(" ")
return try {
when (parts.size) {
2 -> parts[0].split(";")
... | 0 | Kotlin | 0 | 1 | 1dc4de50dd3cd875e3fe76e3da4a58aa04bb87c7 | 5,445 | Kotlin_bootcamp | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NumSubseq.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,879 | kotlab | Apache License 2.0 |
src/main/kotlin/day11_dumbo_octopus/DumboOctopus.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package day11_dumbo_octopus
import geom2d.Rect
import geom2d.asLinearOffset
import geom2d.asPoint
import java.util.*
/**
* Conway's game of life, but with cascade! Since each state is wholly derived
* from the prior state, that suggests an immutable fold of some sort. But with
* the cascade, it's not going to be a... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 2,490 | aoc-2021 | MIT License |
src/Day01.kt | robotfooder | 573,164,789 | false | {"Kotlin": 25811} | fun main() {
fun groupedElves(input: List<String>): List<List<Int>> = input
.chunkedBy { it.isBlank() }
.map { elf ->
elf.map { it.toInt() }
}
fun part1(input: List<String>): Int = groupedElves(input)
.maxOf { it.sum() }
fun part2(input: List<String>): Int = g... | 0 | Kotlin | 0 | 0 | 9876a52ef9288353d64685f294a899a58b2de9b5 | 708 | aoc2022 | Apache License 2.0 |
src/main/java/kt/day1/PermutationGeneratorKotlin.kt | surya-uppuluri | 292,050,828 | false | {"Java": 9862, "Kotlin": 5746} | package kt.day1
import java.util.*
internal class PermutationGeneratorKotlin {
/**
* Given input as 1,2,3,4 generate all permutations of it as -
* 1234
* 1243
* 1324
* 1342
* 1423
* 1432
* ----
* 2134
* 2143
* 2314
* 2341
* 2413
* 2431
* -... | 0 | Java | 0 | 0 | 5cddbecb5502294537137b6864aaf54eb001be5d | 2,911 | september-leetcode-challenge | Apache License 2.0 |
src/main/kotlin/g2301_2400/s2385_amount_of_time_for_binary_tree_to_be_infected/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2301_2400.s2385_amount_of_time_for_binary_tree_to_be_infected
// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
// #2023_07_02_Time_609_ms_(100.00%)_Space_75.2_MB_(100.00%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,383 | LeetCode-in-Kotlin | MIT License |
src/test/kotlin/com/igorwojda/string/isanagram/solution.kt | Daenges | 400,897,104 | true | {"Kotlin": 217983} | package com.igorwojda.string.isanagram
private object Solution1 {
private fun isAnagram(str1: String, str2: String): Boolean {
val a1 = str1.toUpperCase().filter { it.isLetter() }.groupBy { it }
val a2 = str2.toUpperCase().filter { it.isLetter() }.groupBy { it }
return a1 == a2
}
}
pri... | 0 | Kotlin | 0 | 0 | cd1d0c0b76dfef09ad8a2984674cdb4cb3bbea9c | 1,634 | kotlin-coding-challenges | MIT License |
kotlin/src/main/java/com/samelody/samples/kotlin/algorithms/quicksort.kt | belinwu | 140,991,591 | false | {"Kotlin": 70895, "Java": 1117} | package com.samelody.samples.kotlin.algorithms
import com.samelody.samples.kotlin.example
import com.samelody.samples.kotlin.swapAt
import java.util.*
fun <T : Comparable<T>> MutableList<T>.hoarePartition(low: Int, high: Int): Int {
val pivot = this[low]
var i = low - 1
var j = high + 1
while (true) {... | 0 | Kotlin | 0 | 2 | dce2b98cb031df6bbf04cfc576541a2d96134b5d | 4,893 | samples | Apache License 2.0 |
src/Day05.kt | thelmstedt | 572,818,960 | false | {"Kotlin": 30245} | import java.io.File
import java.util.*
fun main() {
fun parseCommands(moves: String): List<List<Int>> {
val commands = moves.lineSequence()
.filter { it.isNotBlank() }
.map { move ->
"[0-9]+".toRegex().allMatches(move).map { it.toInt() }
}.toList()
... | 0 | Kotlin | 0 | 0 | e98cd2054c1fe5891494d8a042cf5504014078d3 | 3,006 | advent2022 | Apache License 2.0 |
src/day5.kt | SerggioC | 573,171,085 | false | {"Kotlin": 8824} | import java.io.File
import java.util.Stack
fun main() {
val file5 = File("src", "day5.txt").readText()
val (stacks, movementsStr) = file5.split("\r\n\r\n")
val stackLines = stacks.split("\r\n")
val movements = movementsStr.split("\r\n")
var stackMap = getStackMapFromInput(stackLines)
println(... | 0 | Kotlin | 0 | 0 | d56fb119196e2617868c248ae48dcde315e5a0b3 | 2,049 | aoc-2022 | Apache License 2.0 |
src/y2022/Day07.kt | Yg0R2 | 433,731,745 | false | null | package y2022
import DayX
class Day07 : DayX<Int>(95_437, 24_933_642) {
override fun part1(input: List<String>): Int {
val rootDir = Dir("/")
initDir(input, rootDir)
return getFoldersSize(rootDir)
.filter { it.key <= 100_000 }
.keys
.sum()
}
o... | 0 | Kotlin | 0 | 0 | d88df7529665b65617334d84b87762bd3ead1323 | 4,303 | advent-of-code | Apache License 2.0 |
src/day24/Day24.kt | HGilman | 572,891,570 | false | {"Kotlin": 109639, "C++": 5375, "Python": 400} | package day24
import lib.DecreaseYDirection
import lib.IncreaseYDirection
import lib.LeftDirection
import lib.Point2D
import lib.RightDirection
import lib.Vector2D
import lib.directionsClockwise
import readInput
fun main() {
val day = 24
// val testInput = readInput("day$day/testInput")
// check(part1(testI... | 0 | Kotlin | 0 | 1 | d05a53f84cb74bbb6136f9baf3711af16004ed12 | 4,531 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/groundsfam/advent/y2023/d01/Day01.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2023.d01
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
val englishDigits = mapOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"five" to 5,
"six" to 6,
"seven" to 7,
... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 1,236 | advent-of-code | MIT License |
ceria/05/src/main/kotlin/Solution.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File;
var ventLines = mutableListOf<Pair<Pair<Int, Int>, Pair<Int, Int>>>()
fun main(args : Array<String>) {
arrangeInput(File(args.first()).readLines())
println("Solution 1: ${solution1()}")
println("Solution 2: ${solution2()}")
}
private fun solution1() :Int {
var ventCounts = mutabl... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 5,287 | advent-of-code-2021 | MIT License |
src/Day01.kt | yashpalrawat | 573,264,560 | false | {"Kotlin": 12474} | import java.util.*
private fun getSortedEnergyLevels(input: List<String>) : List<Int> {
val energyLevels = mutableListOf<Int>()
val result = mutableListOf<Int>()
input.forEach {
if (it.isNotEmpty()) {
energyLevels.add(it.toInt())
} else {
result.add(energyLevels.... | 0 | Kotlin | 0 | 0 | 78a3a817709da6689b810a244b128a46a539511a | 982 | code-advent-2022 | Apache License 2.0 |
src/main/kotlin/io/github/misawa/coassign/Solution.kt | MiSawa | 226,680,692 | false | null | package io.github.misawa.coassign
import kotlin.math.max
class Solution(
private val graph: BipartiteGraph,
private val used: BooleanArray,
private val potential: WeightArray
) {
val value: LargeWeight
init {
var res: LargeWeight = 0
for (e in graph.forwardEdges) if (used[e]) res ... | 0 | Kotlin | 0 | 0 | 2b723480d16e7c9517cf1e5394405a466a5a5360 | 1,986 | coassign | MIT License |
src/Day01.kt | cypressious | 572,898,685 | false | {"Kotlin": 77610} | fun main() {
fun part1(input: List<String>): Int {
var max = 0
var current = 0
for (line in input) {
if (line.isBlank()) {
max = maxOf(max, current)
current = 0
} else {
current += line.toInt()
}
}
... | 0 | Kotlin | 0 | 1 | 7b4c3ee33efdb5850cca24f1baa7e7df887b019a | 1,079 | AdventOfCode2022 | Apache License 2.0 |
src/Day03.kt | ricardorlg-yml | 573,098,872 | false | {"Kotlin": 38331} | fun main() {
val priorities = ('a'..'z')
.plus('A'..'Z')
.mapIndexed { index, c -> c to index + 1 }
.toMap()
fun intersect(strings: List<String>): Set<Char> {
return strings
.map(String::toSet)
.reduce { acc, set -> acc.intersect(set) }
}
fun pa... | 0 | Kotlin | 0 | 0 | d7cd903485f41fe8c7023c015e4e606af9e10315 | 842 | advent_code_2022 | Apache License 2.0 |
day11/src/main/kotlin/Day11.kt | bzabor | 160,240,195 | false | null | class Day11(private val input: List<String>?) {
val gridSize = 301
val cellGrid = Array(gridSize) { Array(gridSize) { 0 } }
fun part1(): String {
setPowerLevel(7989)
return findMaxPowerForDim(3).toString()
}
fun part2(): String {
return findMaxDim().toString()
}
... | 0 | Kotlin | 0 | 0 | 14382957d43a250886e264a01dd199c5b3e60edb | 2,710 | AdventOfCode2018 | Apache License 2.0 |
src/main/kotlin/co/csadev/advent2022/Day02.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2022 by <NAME>
* Advent of Code 2022, Day 2
* Problem Description: http://adventofcode.com/2021/day/2
*/
package co.csadev.advent2022
import co.csadev.adventOfCode.BaseDay
import co.csadev.adventOfCode.Resources
class Day02(override val input: String = Resources.resourceAsText("22day02.txt")) ... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 1,432 | advent-of-kotlin | Apache License 2.0 |
src/day08/Day08.kt | sanyarajan | 572,663,282 | false | {"Kotlin": 24016} | package day08
import readInputText
fun main() {
fun getTreeGrid(input: String): MutableList<MutableList<Int>> {
//a square grid of tree heights
val treeGrid = mutableListOf<MutableList<Int>>()
// convert input to treeGrid
input.lines().forEach { line ->
val row = mutabl... | 0 | Kotlin | 0 | 0 | e23413357b13b68ed80f903d659961843f2a1973 | 4,667 | Kotlin-AOC-2022 | Apache License 2.0 |
src/Day04.kt | YunxiangHuang | 572,333,905 | false | {"Kotlin": 20157} | fun main() {
class Range(r: String) {
private val sepIdx = r.indexOf('-')
private var begin = kotlin.run {
Integer.valueOf(r.subSequence(0, sepIdx).toString())
}
private var end = kotlin.run {
Integer.valueOf(r.subSequence(sepIdx + 1, r.length).toString())
... | 0 | Kotlin | 0 | 0 | f62cc39dd4881f4fcf3d7493f23d4d65a7eb6d66 | 1,163 | AoC_2022 | Apache License 2.0 |
openrndr-shape/src/commonMain/kotlin/org/openrndr/shape/LineSegment3D.kt | openrndr | 122,222,767 | false | {"Kotlin": 2343473, "ANTLR": 9333, "GLSL": 2677, "CSS": 87} | package org.openrndr.shape
import org.openrndr.math.Vector3
import kotlin.math.max
import kotlin.math.min
data class LineSegment3D(val start: Vector3, val end: Vector3) {
val direction get() = (end - start)
fun nearest(query: Vector3): Vector3 {
val l2 = end.minus(start).squaredLength
if (l... | 34 | Kotlin | 71 | 808 | 7707b957f1c32d45f2fbff6b6a95a1a2da028493 | 1,731 | openrndr | BSD 2-Clause FreeBSD License |
src/main/kotlin/lyrics/Analysis.kt | yukinsnow | 302,052,124 | true | {"Kotlin": 176568, "CSS": 1679, "JavaScript": 491, "HTML": 445} | package lyrics
import model.LyricsType
import model.LyricsType.KANA_CV
import model.LyricsType.KANA_VCV
import model.LyricsType.ROMAJI_CV
import model.LyricsType.ROMAJI_VCV
import model.LyricsType.UNKNOWN
import model.Note
import model.Project
import model.Track
fun analyseLyricsTypeForProject(project: Project): Lyri... | 0 | Kotlin | 0 | 1 | 439073496530b5326ae860f96886a4c337cc1622 | 1,867 | utaformatix3 | Apache License 2.0 |
src/main/kotlin/me/consuegra/algorithms/KMergeTwoSortedLinkedLists.kt | aconsuegra | 91,884,046 | false | {"Java": 113554, "Kotlin": 79568} | package me.consuegra.algorithms
import me.consuegra.datastructure.KListNode
/**
* Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together
* the nodes of the first two lists.
*/
class KMergeTwoSortedLinkedLists {
fun merge(list1: KListNode<Int>?, list2: KList... | 0 | Java | 0 | 7 | 7be2cbb64fe52c9990b209cae21859e54f16171b | 1,923 | algorithms-playground | MIT License |
src/questions/MaxAreaOfIsland.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
/**
* You are given an m x n binary matrix grid. An island is a group of 1's (representing land)
* connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
* Return the maxi... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,062 | algorithms | MIT License |
src/main/kotlin/org/example/e3fxgaming/wortproblem/ExtendedCYKAlgorithm.kt | E3FxGaming | 418,121,777 | false | {"Kotlin": 9405} | package org.example.e3fxgaming.wortproblem
fun main() {
val fileContent = InputReader::class.java.getResource("/inputChomskyNF.txt")?.readText() ?: throw Exception("No rules found")
val inputReader = InputReader(fileContent)
val firstTestWord = "abaaba"
val secondTestWord = "abbbba"
val thirdTest... | 0 | Kotlin | 1 | 2 | 292026d34ab9392d662730c4de26b08a93752d53 | 6,400 | ExtendedCYK-Algorithm | Creative Commons Zero v1.0 Universal |
src/aoc2022/Day11.kt | Playacem | 573,606,418 | false | {"Kotlin": 44779} | package aoc2022
import utils.lcm
import utils.readInputText
typealias WorryLevel = Long
fun String.toWorryLevelOrNull(): WorryLevel? = toLongOrNull()
infix fun WorryLevel.divisibleBy(divisor: Int) = this % divisor == 0L
private class Monkey(
val name: String,
val items: MutableList<WorryLevel>,
val opera... | 0 | Kotlin | 0 | 0 | 4ec3831b3d4f576e905076ff80aca035307ed522 | 5,131 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | nikolakasev | 572,681,478 | false | {"Kotlin": 35834} | import kotlin.math.absoluteValue
fun main() {
fun bothParts(input: List<String>, ropeLength: Int): Int {
// fill elements with ropeLength amount of Points set at coordinates 0, 0
var elements = List(ropeLength) { Point(0, 0) }
return input.flatMap {
val steps = it.split(" ")[1]... | 0 | Kotlin | 0 | 1 | 5620296f1e7f2714c09cdb18c5aa6c59f06b73e6 | 1,377 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day04/Day04.kt | jpveilleux | 573,221,738 | false | {"Kotlin": 42252} | package day04
import readInput
fun main() {
val testInputFileName = "./day04/Day04_test"
val part1controlFileName = "./day04/Day04_part1_control"
val inputFileName = "./day04/Day04"
val part1controlInput = readInput(part1controlFileName)
val input = readInput(inputFileName)
fun part1(input: ... | 0 | Kotlin | 0 | 0 | 5ece22f84f2373272b26d77f92c92cf9c9e5f4df | 2,475 | jpadventofcode2022 | Apache License 2.0 |
src/hongwei/leetcode/playground/leetcodecba/E58LengthOfLastWord.kt | hongwei-bai | 201,601,468 | false | {"Java": 143669, "Kotlin": 38875} | package hongwei.leetcode.playground.leetcodecba
class E58LengthOfLastWord {
fun test() {
val testData = arrayOf(
"Hello World" to 5,
" " to 0,
"a " to 1
)
val onlyTestIndex = -1
testData.forEachIndexed { i, pair ->
if (!(onlyTestIndex ... | 0 | Java | 0 | 1 | 9d871de96e6b19292582b0df2d60bbba0c9a895c | 1,911 | leetcode-exercise-playground | Apache License 2.0 |
src/d05/Main.kt | cweckerl | 572,838,803 | false | {"Kotlin": 12921} | package d05
import java.io.File
import java.util.LinkedList
fun main() {
fun part1(input: List<String>) {
val (a, b) = input.partition { !Regex("""move \d+ from \d+ to \d+""").matches(it) }
val crates = mutableMapOf<Int, LinkedList<Char>>()
a.forEach { line ->
line.forEachInd... | 0 | Kotlin | 0 | 0 | 612badffbc42c3b4524f5d539c5cbbfe5abc15d3 | 1,967 | aoc | Apache License 2.0 |
src/common_prefix/CommonPrefix.kt | AhmedTawfiqM | 458,182,208 | false | {"Kotlin": 11105} | package common_prefix
//https://leetcode.com/problems/longest-common-prefix/
object CommonPrefix {
private fun longestCommonPrefix(list: Array<String>): String {
if (list.isEmpty()) return ""
var prefix = list[0]
list.forEach {
while (it.indexOf(prefix) != 0) {
... | 0 | Kotlin | 0 | 1 | a569265d5f85bcb51f4ade5ee37c8252e68a5a03 | 1,167 | ProblemSolving | Apache License 2.0 |
src/main/kotlin/ca/voidstarzero/isbd/ParserUtils.kt | hzafar | 262,218,140 | false | null | package ca.voidstarzero.isbd
import ca.voidstarzero.isbd.titlestatement.ast.*
import ca.voidstarzero.marc.MARCField
import ca.voidstarzero.marc.fieldData
fun cleanInput(input: String): String {
val REPLACE = 0xfffd.toChar()
return input
.replace(" = ", "$REPLACE=$REPLACE")
.replace(" : ", "$RE... | 2 | Kotlin | 0 | 2 | 16bb26858722ca818c0a9f659be1cc9d3e4e7213 | 2,841 | isbd-parser | MIT License |
src/test/kotlin/ch/ranil/aoc/aoc2022/Day09.kt | stravag | 572,872,641 | false | {"Kotlin": 234222} | package ch.ranil.aoc.aoc2022
import ch.ranil.aoc.AbstractDay
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
object Day09 : AbstractDay() {
@Test
fun tests() {
assertEquals(13, compute(testInput, 2))
assertEquals(6212, compute(puzzleInput, 2))
assertEquals(1, comput... | 0 | Kotlin | 1 | 0 | dbd25877071cbb015f8da161afb30cf1968249a8 | 2,149 | aoc | Apache License 2.0 |
src/week2/PacificAtlantic.kt | anesabml | 268,056,512 | false | null | package week2
import kotlin.system.measureNanoTime
class PacificAtlantic {
/**
* Using two boolean matrix to keep track of the grid elements that each ocean can be reached from
* in the end if the grid element can be reached from both oceans we add it to the list.
* Time complexity: O(n*m)
* ... | 0 | Kotlin | 0 | 1 | a7734672f5fcbdb3321e2993e64227fb49ec73e8 | 4,547 | leetCode | Apache License 2.0 |
src/Day08.kt | matusekma | 572,617,724 | false | {"Kotlin": 119912, "JavaScript": 2024} | class Day08 {
fun part1(grid: List<String>): Int {
val width = grid[0].length
val height = grid.size
var visibleTrees = width * 2 + height * 2 - 4
for (i in 1..height - 2) {
for (j in 1..width - 2) {
if (visibleInRow(grid, i, j) || visibleInColumn(grid, i,... | 0 | Kotlin | 0 | 0 | 744392a4d262112fe2d7819ffb6d5bde70b6d16a | 3,371 | advent-of-code | Apache License 2.0 |
src/year2023/03/Day03.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2023.`03`
import readInput
private const val CURRENT_DAY = "03"
private data class Point(
val x: Int,
val y: Int,
)
private data class NumberDataStore(
val digits: List<DataPoint>,
) {
fun digitRepresentation(): Int {
return digits.joinToString("") { it.data }.toInt()
}
... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 5,129 | KotlinAdventOfCode | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.