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/Day01.kt | Djaler | 573,520,591 | false | {"Kotlin": 1613} | fun main() {
fun <T> List<T>.split(delimeter: T): List<List<T>> {
val result = mutableListOf<List<T>>()
var buffer = mutableListOf<T>()
for (item in this) {
if (item != delimeter) {
buffer.add(item)
} else if (buffer.isNotEmpty()) {
res... | 1 | Kotlin | 0 | 0 | 451e019525a888f4bc40feb4327de07598ed07b8 | 965 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/g2501_2600/s2528_maximize_the_minimum_powered_city/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2501_2600.s2528_maximize_the_minimum_powered_city
// #Hard #Array #Greedy #Binary_Search #Prefix_Sum #Sliding_Window #Queue
// #2023_07_04_Time_496_ms_(100.00%)_Space_57_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
private fun canIBeTheMinimum(power: LongArray, minimum: Long, k: Int, r: Int)... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,046 | LeetCode-in-Kotlin | MIT License |
ceria/22/src/main/kotlin/Solution.kt | VisionistInc | 317,503,410 | false | null | import java.io.File
import java.util.Queue
import java.util.LinkedList
fun main(args : Array<String>) {
val input = File(args.first()).readLines()
println("Solution 1: ${solution1(input)}")
println("Solution 2: ${solution2(input)}")
}
private fun solution1(input :List<String>) :Int {
var p1: Queue... | 0 | Rust | 0 | 0 | 002734670384aa02ca122086035f45dfb2ea9949 | 2,977 | advent-of-code-2020 | MIT License |
src/main/kotlin/com/colinodell/advent2023/Day21.kt | colinodell | 726,073,391 | false | {"Kotlin": 114923} | package com.colinodell.advent2023
class Day21(input: List<String>) {
private val grid = input.toGrid()
private val gridSize = grid.width().also { assert(it == grid.height()) }
private val start = grid.entries.first { it.value == 'S' }.key
// Gets the value at the given position in the infinite grid
... | 0 | Kotlin | 0 | 0 | 97e36330a24b30ef750b16f3887d30c92f3a0e83 | 1,282 | advent-2023 | MIT License |
src/main/kotlin/g1001_1100/s1080_insufficient_nodes_in_root_to_leaf_paths/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1001_1100.s1080_insufficient_nodes_in_root_to_leaf_paths
// #Medium #Depth_First_Search #Tree #Binary_Tree
// #2023_06_02_Time_271_ms_(100.00%)_Space_38.9_MB_(100.00%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree node.
* clas... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,436 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/LetterBoxedPuzzle.kt | Kyle-Falconer | 671,044,954 | false | null | import java.util.*
class LetterBoxedSolutionChecker(
private val puzzle: LetterBoxedPuzzle,
private val dictionary: Dictionary,
) {
private var remainingLetters: MutableSet<Char> = puzzle.sides.flatten().toSet().toMutableSet()
init {
reset()
}
fun reset() {
remainingLetters =... | 0 | Kotlin | 0 | 0 | 32f65f18067d686bb79cf84bdbb30bc880319124 | 3,359 | LetterBoxedPuzzleSolver | Apache License 2.0 |
src/main/kotlin/org/metanalysis/srb/Graph.kt | andreihh | 119,868,171 | false | null | /*
* Copyright 2018 <NAME> <<EMAIL>>
*
* 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 agree... | 0 | Kotlin | 0 | 0 | 6ede80136baa23e5dca5d210f17a8a287ef14d92 | 6,300 | metanalysis-srb | Apache License 2.0 |
src/main/kotlin/clustering/ModularityCalculator.kt | loehnertz | 194,407,716 | false | null | package codes.jakob.graphenotype.clustering
import codes.jakob.graphenotype.clustering.graph.ClusterableGraph
import codes.jakob.graphenotype.clustering.graph.ClusterableVertex
import codes.jakob.graphenotype.clustering.graph.WeightedEdge
import kotlin.math.pow
object ModularityCalculator {
const val minimumModu... | 0 | Kotlin | 0 | 0 | 06e0cbfeb760ad6efe445d337b527662235fef24 | 1,973 | Graphenotype | Apache License 2.0 |
src/main/kotlin/com/github/wakingrufus/aoc/Day5.kt | wakingrufus | 159,674,364 | false | null | package com.github.wakingrufus.aoc
class Day5 {
fun part1(input: String): Int = reduce(input).length
fun part2(input: String): Int = 'a'.rangeTo('z')
.map { reduceWithout(input, it) }
.map { it.length }
.min() ?: -1
fun part1Fast(input: String): Int = fastReduce(input)... | 0 | Kotlin | 0 | 0 | bdf846cb0e4d53bd8beda6fdb3e07bfce59d21ea | 2,083 | advent-of-code-2018 | MIT License |
AdventOfCodeDay04/src/nativeMain/kotlin/Day04.kt | bdlepla | 451,510,571 | false | {"Kotlin": 165771} | class Day04(private val lines:List<String>) {
private val bingoNumbers = createNumbers(lines.first())
private fun createNumbers(line: String)=line.split(",").map { it.toInt() }
private fun createBingoCards(lines: List<String>): List<BingoCard> {
val input = lines.joinToString("\n").split("\n\n")
... | 0 | Kotlin | 0 | 0 | 1d60a1b3d0d60e0b3565263ca8d3bd5c229e2871 | 2,091 | AdventOfCode2021 | The Unlicense |
src/main/kotlin/kr/co/programmers/P181187.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
import kotlin.math.pow
import kotlin.math.sqrt
// https://github.com/antop-dev/algorithm/issues/502
class P181187 {
fun solution(r1: Int, r2: Int): Long {
// y가 0인 점의 개수
var count = 0L + (r2 - r1 + 1) * 4
// x 좌표만 루프
for (x in 1 until r2) {
val... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 917 | algorithm | MIT License |
src/day17/Day17.kt | dkoval | 572,138,985 | false | {"Kotlin": 86889} | package day17
import readInputAsString
private const val DAY_ID = "17"
private enum class Direction(val dx: Int, val dy: Int) {
LEFT(-1, 0),
RIGHT(1, 0),
DOWN(0, -1);
}
private data class Point(val x: Int, val y: Int) {
fun move(d: Direction): Point {
return Point(x + d.dx, y + d.dy)
}
... | 0 | Kotlin | 1 | 0 | 791dd54a4e23f937d5fc16d46d85577d91b1507a | 3,676 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day06.kt | arturkowalczyk300 | 573,084,149 | false | {"Kotlin": 31119} | fun main() {
fun rotateCharArrayLeft(arr: CharArray): CharArray {
for (i in 0 until arr.size - 1) {
arr[i] = arr[i + 1]
}
return arr
}
fun findIndexEndSequenceOfNDifferentCharacters(input: String, N:Int): Int {
if (input.length < N) return -1
var sequenc... | 0 | Kotlin | 0 | 0 | 69a51e6f0437f5bc2cdf909919c26276317b396d | 1,471 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day08.kt | dustinlewis | 572,792,391 | false | {"Kotlin": 29162} | import kotlin.text.forEachIndexed as forEachIndexed2
fun main() {
fun part1(input: List<String>): Int {
val edgeCount = input.count() * 2 + (input.count() - 2) * 2
val topBottom = input.fold(MutableList(input.size){ "" }) { acc, element ->
element.withIndex().forEach { c -> acc[c.index... | 0 | Kotlin | 0 | 0 | c8d1c9f374c2013c49b449f41c7ee60c64ef6cff | 3,617 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/de/huddeldaddel/euler/extensions/LongExtensions.kt | huddeldaddel | 171,357,298 | false | null | package de.huddeldaddel.euler.extensions
import de.huddeldaddel.euler.isInt
import de.huddeldaddel.euler.math.Factorizer
import de.huddeldaddel.euler.sequences.PrimeSequence
import de.huddeldaddel.euler.sequences.TriangleNumberSequence
import kotlin.math.sqrt
fun Long.getPrimeFactors(): Collection<Long> {
val res... | 0 | Kotlin | 1 | 0 | df514adde8c62481d59e78a44060dc80703b8f9f | 1,892 | euler | MIT License |
src/Day23.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.time.measureTime
private const val EXPECTED_1 = 94
private const val EXPECTED_2 = 154
private class Day23(isTest: Boolean) : Solver(isTest) {
val field = readAsLines().map { it.toCharArray() }
val Y = field.size
val X = field[0].size
... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 5,602 | advent-of-code-2022 | Apache License 2.0 |
code-sample-kotlin/algorithms/src/main/kotlin/com/codesample/algo/sorts.kt | aquatir | 76,377,920 | false | {"Java": 674809, "Python": 143889, "Kotlin": 112192, "Haskell": 57852, "Elixir": 33284, "TeX": 20611, "Scala": 17065, "Dockerfile": 6314, "HTML": 4714, "Shell": 387, "Batchfile": 316, "Erlang": 269, "CSS": 97} | fun <T> swap(array: Array<T>, fstIndex: Int, sndIndex: Int) {
val fstValue = array[fstIndex]
array[fstIndex] = array[sndIndex]
array[sndIndex] = fstValue
}
/** Selection sort: Find the smallest -> insert it to next position */
fun <T : Comparable<T>> selectionSort(array: Array<T>) {
for (i in array.in... | 1 | Java | 3 | 6 | eac3328ecd1c434b1e9aae2cdbec05a44fad4430 | 5,378 | code-samples | MIT License |
src/main/kotlin/net/voldrich/aoc2022/Day02.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2022
import net.voldrich.BaseDay
// https://adventofcode.com/2022/day/2
fun main() {
Day02().run()
}
// Written mostly by copilot
class Day02 : BaseDay() {
enum class Type {
ROCK, PAPER, SCISSORS
}
override fun task1() : Int {
return input.lines().map {
... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 2,771 | advent-of-code | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round0/Questions55.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round0
import kotlin.math.abs
import kotlin.math.max
fun test55() {
val a = BinaryTreeNode(1)
val b = BinaryTreeNode(2)
val c = BinaryTreeNode(3)
val d = BinaryTreeNode(4)
val e = BinaryTreeNode(5)
val f = BinaryTreeNode(6)
val g = BinaryTreeNode(7)
a.left = b
a.right = c
b.l... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,568 | Algorithm | Apache License 2.0 |
src/main/kotlin/g1701_1800/s1799_maximize_score_after_n_operations/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1701_1800.s1799_maximize_score_after_n_operations
// #Hard #Array #Dynamic_Programming #Math #Bit_Manipulation #Backtracking #Bitmask #Number_Theory
// #2023_06_18_Time_347_ms_(73.17%)_Space_36.4_MB_(81.30%)
class Solution {
fun maxScore(nums: IntArray): Int {
val n = nums.size
val memo =... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,373 | LeetCode-in-Kotlin | MIT License |
src/Day08.kt | felldo | 572,233,925 | false | {"Kotlin": 76496} | import kotlin.math.max
fun main() {
fun part1(testInput: List<String>): Int {
var visibleTrees = 0
//Top and bottom row
visibleTrees += testInput.first().length
visibleTrees += testInput.last().length
// Sides minus the edges
visibleTrees += testInput.size * 2 -... | 0 | Kotlin | 0 | 0 | 0ef7ac4f160f484106b19632cd87ee7594cf3d38 | 3,817 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/d3_BinaryDiagnostic/BinaryDiagnostic.kt | aormsby | 425,644,961 | false | {"Kotlin": 68415} | package d3_BinaryDiagnostic
import util.Input
import util.Output
fun main() {
Output.day(3, "Binary Diagnostic")
val startTime = Output.startTime()
val report = Input.parseLines("/input/d3_diagnostic_report.txt")
val transposedReport = transposeMatrix(report)
val gammaStr = transposedReport.fold... | 0 | Kotlin | 1 | 1 | 193d7b47085c3e84a1f24b11177206e82110bfad | 1,927 | advent-of-code-2021 | MIT License |
src/main/kotlin/executeAgeGenderCmds.kt | sam-hoodie | 534,831,633 | false | {"Kotlin": 43732} | fun main() {
val data = parseCongressFile(true)
interpretAgeAndGenderCommand("-get house.serving.age.oldest", data)
}
fun interpretAgeAndGenderCommand(command: String, data: List<Person>) {
// -get congress.age.youngest
// -get congress.age.oldest
// -get congress.gender.prevalent
if (command.s... | 0 | Kotlin | 0 | 0 | 9efea9f9eec55c1e61ac1cb11d3e3460f825994b | 3,685 | congress-challenge | Apache License 2.0 |
src/main/kotlin/days/Day03.kt | TheMrMilchmann | 433,608,462 | false | {"Kotlin": 94737} | /*
* Copyright (c) 2021 <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 | dfc91afab12d6dad01de552a77fc22a83237c21d | 3,664 | AdventOfCode2021 | MIT License |
src/main/kotlin/me/peckb/aoc/_2015/calendar/day09/Day09.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2015.calendar.day09
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import me.peckb.aoc.generators.PermutationGenerator
import javax.inject.Inject
import kotlin.Int.Companion.MAX_VALUE
import kotlin.math.max
import kotlin.math.min
class Day09 @Inject constructor(
private va... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 2,189 | advent-of-code | MIT License |
CameraXVideo/utils/src/main/java/com/example/android/camera/utils/CameraSizes.kt | android | 185,094,070 | false | {"Kotlin": 665074, "Java": 50339, "RenderScript": 2800} | /*
* Copyright 2020 The Android Open Source Project
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applica... | 141 | Kotlin | 2,274 | 4,651 | 96cbc7d8014d72470c4b70ca76adfdc332d60123 | 3,110 | camera-samples | Apache License 2.0 |
src/main/kotlin/day10/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day10
import java.io.File
val chunkPairs = mapOf(
'(' to ')',
'[' to ']',
'{' to '}',
'<' to '>',
)
val illegalCharacterPoints = mapOf(
')' to 3,
']' to 57,
'}' to 1197,
'>' to 25137,
)
val autocompleteCharacterPoints = mapOf(
')' to 1,
']' to 2,
'}' to 3,
'>' ... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 1,565 | aoc-2021 | MIT License |
src/Day21.kt | zt64 | 572,594,597 | false | null | import kotlin.math.absoluteValue
private object Day21 : Day(21) {
private val monkeys = input.lines().associate { line ->
val (name, job) = line.split(": ")
val split = job.split(" ")
val function = if (split.size == 1) {
Job.Number(job.toLong())
} else {
J... | 0 | Kotlin | 0 | 0 | 4e4e7ed23d665b33eb10be59670b38d6a5af485d | 1,610 | aoc-2022 | Apache License 2.0 |
2021/kotlin/src/main/kotlin/com/pietromaggi/aoc2021/day05/Day05.kt | pfmaggi | 438,378,048 | false | {"Kotlin": 113883, "Zig": 18220, "C": 7779, "Go": 4059, "CMake": 386, "Awk": 184} | /*
* 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 wr... | 0 | Kotlin | 0 | 0 | 7c4946b6a161fb08a02e10e99055a7168a3a795e | 3,474 | AdventOfCode | Apache License 2.0 |
kotlin-practice/src/main/kotlin/practice/Reservation.kt | nicolegeorgieva | 590,020,790 | false | {"Kotlin": 120359} | package practice
//reserve a table
//input 1: peopleCount
//input 2: each person first name
//input 3: each person spending
//min consumation: 10 BGN/person (one can pay for the other). 10bgn is okay for 1 person
//reservation failed/successful (? advance need to pay && ? total)
//program says ? expense(all), advance ... | 0 | Kotlin | 0 | 1 | c96a0234cc467dfaee258bdea8ddc743627e2e20 | 1,887 | kotlin-practice | MIT License |
src/main/kotlin/com/dvdmunckhof/aoc/event2023/Day04.kt | dvdmunckhof | 318,829,531 | false | {"Kotlin": 195848, "PowerShell": 1266} | package com.dvdmunckhof.aoc.event2023
class Day04(private val input: List<String>) {
fun solvePart1(): Int {
return matchingCardNumbers().filter { it > 0 }.sumOf { 1 shl it - 1 }
}
fun solvePart2(): Int {
val cardsCount = Array(input.size) { 1 }
for ((index, matches) in matchingC... | 0 | Kotlin | 0 | 0 | 025090211886c8520faa44b33460015b96578159 | 1,124 | advent-of-code | Apache License 2.0 |
src/Day03.kt | jamesrobert | 573,249,440 | false | {"Kotlin": 13069} | fun main() {
fun itemWeight(commonItem: Char) = if (commonItem <= 'Z') commonItem - 'A' + 27
else commonItem - 'a' + 1
fun List<List<String>>.sumWeightCommonItems() = sumOf {strings ->
strings.map { it.toSet() }
.reduce { acc, chars -> acc.intersect(chars) }
.sumOf { itemWei... | 0 | Kotlin | 0 | 0 | d0b49770fc313ae42d802489ec757717033a8fda | 873 | advent-of-code-2022 | Apache License 2.0 |
src/me/bytebeats/algo/kt/Solution5.kt | bytebeats | 251,234,289 | false | null | package me.bytebeats.algo.kt
import me.bytebeats.algo.kt.design.Employee
import me.bytebeats.algo.kt.design.NestedInteger
import me.bytebeats.algs.ds.TreeNode
import me.bytebeats.algs.ds.TreeNode2
class Solution5 {
var maxPathSum = Int.MIN_VALUE
fun maxPathSum(root: TreeNode?): Int {//124
maxGain(roo... | 0 | Kotlin | 0 | 1 | 7cf372d9acb3274003bb782c51d608e5db6fa743 | 33,826 | Algorithms | MIT License |
2017/day08_kotlin/day8.kts | nikklassen | 112,742,014 | false | {"Rust": 216342, "Go": 151024, "C#": 6392, "Assembly": 6377, "F#": 5335, "Clojure": 4751, "C": 3896, "C++": 3754, "Haskell": 3712, "Elixir": 3132, "Scala": 2919, "Java": 2775, "JavaScript": 2688, "Shell": 2551, "Groovy": 2544, "OCaml": 2073, "PHP": 2034, "Python": 2024, "Julia": 1990, "Ruby": 1990, "Kotlin": 1949, "Com... | import java.io.File
import java.lang.Integer.max
data class Instruction(var reg: String, var incDec: String, var op: Int, var comparisonReg: String, var comparison: String, var predicate: Int)
fun main(maxReg: Boolean) {
val instructions = arrayListOf<Instruction>()
val registers = mutableMapOf<String, Int>()... | 0 | Rust | 0 | 2 | bc1935dbbdb6e569fe2bb1ab69471ba705d14f1e | 1,949 | advent-of-code | MIT License |
aoc16/day_20/main.kt | viktormalik | 436,281,279 | false | {"Rust": 227300, "Go": 86273, "OCaml": 82410, "Kotlin": 78968, "Makefile": 13967, "Roff": 9981, "Shell": 2796} | import java.io.File
import kotlin.math.min
data class Range(val min: Long, val max: Long)
fun main() {
val denylist = File("input")
.readLines()
.map { Range(it.split("-")[0].toLong(), it.split("-")[1].toLong()) }
var validRanges = setOf(Range(0, 4294967295))
for (deny in denylist) {
... | 0 | Rust | 1 | 0 | f47ef85393d395710ce113708117fd33082bab30 | 1,160 | advent-of-code | MIT License |
src/Day01.kt | qexer | 575,383,214 | false | {"Kotlin": 16152} | /*
--- Day 1: Calorie Counting ---
Santa's reindeer typically eat regular reindeer food, but they need a lot of magical energy to deliver presents on Christmas. For that, their favorite snack is a special type of star fruit that only grows deep in the jungle. The Elves have brought you on their annual expedition to th... | 0 | Kotlin | 0 | 0 | a2e81fdfdf395e2d80c0ad31ef66b84e5e2f6829 | 3,790 | Advent-of-Code-2022 | Apache License 2.0 |
solutions/src/WordSearchTwo.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} |
//https://leetcode.com/problems/word-search-ii/
class WordSearchTwo {
private val grid: MutableMap<Pair<Int, Int>, Char> = mutableMapOf()
private val foundWords = mutableSetOf<String>()
private class CharTree(val value: Char, val children: MutableMap<Char,CharTree?> = mutableMapOf() )
fun findWords(bo... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 2,217 | leetcode-solutions | MIT License |
src/main/year_2016/day12/day16.kt | rolf-rosenbaum | 572,864,107 | false | {"Kotlin": 80772} | package year_2016.day12
import readInput
fun main() {
val input = readInput("main/year_2016/day12/Day12")
println(part1(input))
println(part2(input))
}
val registers = mutableMapOf(
"a" to 0,
"b" to 0,
"c" to 0,
"d" to 0,
)
fun part1(input: List<String>): Int {
var index = 0
... | 0 | Kotlin | 0 | 2 | 59cd4265646e1a011d2a1b744c7b8b2afe482265 | 1,518 | aoc-2022 | Apache License 2.0 |
src/Day06.kt | kthun | 572,871,866 | false | {"Kotlin": 17958} | fun main() {
fun firstUniqueCharSequence(chars: CharArray, sequenceLength: Int): Int {
val lastNchars = chars.take(sequenceLength).toMutableList()
chars.foldIndexed(lastNchars) { index, acc, c ->
acc.removeFirst()
acc.add(c)
if (acc.toSet().size == sequenceLength)... | 0 | Kotlin | 0 | 0 | 5452702e4e20ef2db3adc8112427c0229ebd1c29 | 980 | aoc-2022 | Apache License 2.0 |
src/day6/main.kt | DonaldLika | 434,183,449 | false | {"Kotlin": 11805} | package day6
import assert
import readLines
var NR_OF_DAYS = 80
fun main() {
fun part1(fishes: List<Fish>): Long {
return countTotalFish(fishes)
}
fun part2(fishes: List<Fish>): Long {
return countTotalFish(fishes, 256)
}
val testInput = readFishes("day6/test")
assert(part... | 0 | Kotlin | 0 | 0 | b288f16ee862c0a685a3f9e4db34d71b16c3e457 | 1,318 | advent-of-code-2021 | MIT License |
src/Day19.kt | mrugacz95 | 572,881,300 | false | {"Kotlin": 102751} | import kotlin.math.max
private data class Blueprint(
val id: Int,
val oreNeededOre: Int,
val clayNeededOre: Int,
val obsidianNeededOre: Int,
val obsidianNeededClay: Int,
val geodeNeededOre: Int,
val geodeNeededObsidian: Int
) {
val maxOreNeeded = listOf(oreNeededOre, clayNeededOre, obsi... | 0 | Kotlin | 0 | 0 | 29aa4f978f6507b182cb6697a0a2896292c83584 | 5,112 | advent-of-code-2022 | Apache License 2.0 |
advent-of-code-2020/src/main/kotlin/eu/janvdb/aoc2020/day22/Day22.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2020.day22
import eu.janvdb.aocutil.kotlin.readGroupedLines
fun main() {
val decks = readGroupedLines(2020, "input22.txt").map(::parseDeck)
val game = Game(decks[0], decks[1])
part1(game)
part2(game)
}
fun part1(game: Game) {
val winner = playWithRules1(game)
println(winner.deck.score().to... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 2,807 | advent-of-code | Apache License 2.0 |
2021/src/day10/Solution.kt | vadimsemenov | 437,677,116 | false | {"Kotlin": 56211, "Rust": 37295} | package day10
import java.nio.file.Files
import java.nio.file.Paths
fun main() {
val matching = mapOf(
'(' to ')',
'[' to ']',
'{' to '}',
'<' to '>',
)
fun part1(lines: Input): Int {
val points = mapOf(
')' to 3,
']' to 57,
'}' to 1197,
'>' to 25137,
)
retur... | 0 | Kotlin | 0 | 0 | 8f31d39d1a94c862f88278f22430e620b424bd68 | 1,676 | advent-of-code | Apache License 2.0 |
src/main/kotlin/com/groundsfam/advent/y2022/d16/Day16.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2022.d16
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
data class Valve(val name: String, val flowRate: Int, val adjacentValves: List<String>)
fun parseLine(line: String): Valve {
val parts = line.sp... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 5,111 | advent-of-code | MIT License |
2022/src/main/kotlin/Day23.kt | dlew | 498,498,097 | false | {"Kotlin": 331659, "TypeScript": 60083, "JavaScript": 262} | import Day23.Direction.*
import java.util.*
object Day23 {
fun part1(input: String): Int {
var elves = parseElves(input)
repeat(10) {
elves = round(elves, Direction.values()[it % 4])
}
val minX = elves.minOf { it.x }
val maxX = elves.maxOf { it.x }
val minY = elves.minOf { it.y }
... | 0 | Kotlin | 0 | 0 | 6972f6e3addae03ec1090b64fa1dcecac3bc275c | 3,473 | advent-of-code | MIT License |
src/main/kotlin/championofgoats/advent/2019/day12/day12.kt | ChampionOfGoats | 225,446,764 | false | null | package championofgoats.advent.twentynineteen.day12
import championofgoats.advent.Problem
import championofgoats.advent.utils.MutablePair
import championofgoats.advent.utils.Vector3
import championofgoats.advent.utils.logging.Logger
object Day12 : Problem {
override fun solve(inputDir: String, outputDir: String, ... | 0 | Kotlin | 0 | 0 | 4f69de1579f40928c1278c3cea4e23e0c0e3b742 | 2,776 | advent-of-code | MIT License |
src/main/kotlin/g0001_0100/s0064_minimum_path_sum/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0001_0100.s0064_minimum_path_sum
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix
// #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n)
// #2023_07_10_Time_164_ms_(100.00%)_Space_37.3_MB_(84.71%)
class Solution {
fun minPathSum(grid: Array<IntA... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 955 | LeetCode-in-Kotlin | MIT License |
Zumkeller_numbers/Kotlin/src/ZumkellerNumbers.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.util.ArrayList
import kotlin.math.sqrt
object ZumkellerNumbers {
@JvmStatic
fun main(args: Array<String>) {
var n = 1
println("First 220 Zumkeller numbers:")
run {
var count = 1
while (count <= 220) {
if (isZumkeller(n)) {
... | 0 | D | 0 | 4 | c2a9f154a5ae77eea2b34bbe5e0cc2248333e421 | 3,296 | rosetta | MIT License |
src/main/kotlin/leetcode/problem0085/MaximalRectangle.kt | ayukatawago | 456,312,186 | false | {"Kotlin": 266300, "Python": 1842} | package leetcode.problem0085
import java.util.Stack
import kotlin.math.max
class MaximalRectangle {
fun maximalRectangle(matrix: Array<CharArray>): Int {
val heights = Array(matrix.size) { IntArray(matrix[0].size) { 0 } }
matrix.forEachIndexed { row, chars ->
chars.indices.forEach { c... | 0 | Kotlin | 0 | 0 | f9602f2560a6c9102728ccbc5c1ff8fa421341b8 | 1,647 | leetcode-kotlin | MIT License |
src/main/kotlin/day10/KnotHasher.kt | Jessevanbekkum | 112,612,571 | false | null | package day10
fun hash64(input: String): String {
val length = convert(input);
return hex(dense(hash(length, 64)));
}
fun hex(input: List<Int>): String {
return input.map { i -> hexChar(i) }.joinToString("")
}
fun hexChar(i: Int): String {
val c = java.lang.Integer.toHexString(i)
if (i < 16) {
... | 0 | Kotlin | 0 | 0 | 1340efd354c61cd070c621cdf1eadecfc23a7cc5 | 1,585 | aoc-2017 | Apache License 2.0 |
src/main/kotlin/com/vaclavbohac/advent2023/day1/Trebuchet.kt | vaclavbohac | 725,991,261 | false | {"Kotlin": 15155} | package com.vaclavbohac.advent2023.day1
class Trebuchet(private val lines: List<String>) {
fun sumCalibratedValues(): Int =
lines.fold(0) { sum, line -> sum + (line.getFirstDigit() * 10 + line.reversed().getFirstDigit()) }
fun sumCalibratedValuesAfterInterpolation(): Int =
lines.fold(0) { sum,... | 0 | Kotlin | 0 | 0 | daa1feb960c4e3d26c3c75842afbd414ecc2f008 | 1,249 | advent-of-code-2023 | MIT License |
src/main/kotlin/com/leetcode/monthly_challenges/2021/april/ones_and_zeroes/Main.kt | frikit | 254,842,734 | false | null | package com.leetcode.monthly_challenges.`2021`.april.ones_and_zeroes
import kotlin.math.max
fun main() {
println("Test case 1:")
println(Solution().findMaxForm(arrayOf("10", "0001", "111001", "1", "0"), 5, 3)) //4
println()
println("Test case 2:")
println(Solution().findMaxForm(arrayOf("10", "0", ... | 0 | Kotlin | 0 | 0 | dda68313ba468163386239ab07f4d993f80783c7 | 1,131 | leet-code-problems | Apache License 2.0 |
src/chapter1/problem8/solution1.kts | neelkamath | 395,940,983 | false | null | /*
Question:
Zero Matrix: Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.
Solution:
Modifying in-place.
*/
val matrix1 = arrayOf(
arrayOf(0, 1, 2, 3, 4),
arrayOf(5, 6, 7, 8, 9),
arrayOf(10, 11, 12, 0, 14),
arrayOf(15, 16, 17, 18, 19),
arra... | 0 | Kotlin | 0 | 0 | 4421a061e5bf032368b3f7a4cee924e65b43f690 | 1,482 | ctci-practice | MIT License |
src/Day01.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} | fun getList(input: List<String>): HashMap<Int, Int> {
var idx = 0
var sum = 0
val sums = HashMap<Int, Int>()
input.map { it.trim() }.forEach {
if (it.isNotEmpty()) {
sum += it.toInt()
} else {
sums[idx++] = sum
sum = 0
}
}
return sums
... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 736 | aoc-22-kotlin | Apache License 2.0 |
src/main/kotlin/dev/tasso/adventofcode/_2021/day11/Day11.kt | AndrewTasso | 433,656,563 | false | {"Kotlin": 75030} | package dev.tasso.adventofcode._2021.day11
import dev.tasso.adventofcode.Solution
class Day11 : Solution<Int> {
override fun part1(input: List<String>): Int {
val energyMap = input.map{ row -> row.toCharArray().map { it.digitToInt() }.toTypedArray() }.toTypedArray()
var numFlashes = 0
(1... | 0 | Kotlin | 0 | 0 | daee918ba3df94dc2a3d6dd55a69366363b4d46c | 3,781 | advent-of-code | MIT License |
src/main/kotlin/days/Day5.kt | jgrgt | 575,475,683 | false | {"Kotlin": 94368} | package days
class Day5 : Day(5) {
override fun partOne(): Any {
val stackInput = inputList.subList(0, 8)
check(stackInput[7].startsWith("[")) { "probably wrong stack" }
val game = Day5Game.fromStackInput(stackInput)
inputList.drop(10).forEach { line ->
val move = Move.... | 0 | Kotlin | 0 | 0 | 5174262b5a9fc0ee4c1da9f8fca6fb86860188f4 | 2,961 | aoc2022 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/day20.kt | gautemo | 572,204,209 | false | {"Kotlin": 78294} | import shared.getText
import kotlin.math.abs
fun main() {
val input = getText("day20.txt")
println(day20A(input))
println(day20B(input))
}
fun day20A(input: String) = mix(input)
fun day20B(input: String) = mix(input, 10, 811589153)
private fun mix(input: String, times: Int = 1, decryptKey: Long = 1L): Lo... | 0 | Kotlin | 0 | 0 | bce9feec3923a1bac1843a6e34598c7b81679726 | 1,516 | AdventOfCode2022 | MIT License |
leetcode-75-kotlin/src/main/kotlin/StringCompression.kt | Codextor | 751,507,040 | false | {"Kotlin": 49566} | /**
* Given an array of characters chars, compress it using the following algorithm:
*
* Begin with an empty string s. For each group of consecutive repeating characters in chars:
*
* If the group's length is 1, append the character to s.
* Otherwise, append the character followed by the group's length.
* The co... | 0 | Kotlin | 0 | 0 | 0511a831aeee96e1bed3b18550be87a9110c36cb | 2,228 | leetcode-75 | Apache License 2.0 |
src/Day09.kt | MickyOR | 578,726,798 | false | {"Kotlin": 98785} | import kotlin.math.abs
import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
val ropeSize = 2;
var set = mutableSetOf<Pair<Int, Int>>();
var dx = listOf<Int>(1, 0, -1, 0);
var dy = listOf<Int>(0, -1, 0, 1);
var dir = mutableMapOf<Char, Int>();
dir[... | 0 | Kotlin | 0 | 0 | c24e763a1adaf0a35ed2fad8ccc4c315259827f0 | 3,045 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day07.kt | bunjix | 573,915,819 | false | {"Kotlin": 9977} | fun main() {
val rootMap = mutableMapOf<String, Int>()
var currentDir = ""
fun enterDirectory(dirName: String) {
currentDir = when {
currentDir.isEmpty() -> dirName
currentDir == "/" -> "/$dirName"
else -> "$currentDir/$dirName"
}
rootMap[currentD... | 0 | Kotlin | 0 | 0 | ee2a344f6c0bb2563cdb828485e9a56f2ff08fcc | 1,669 | aoc-2022-kotlin | Apache License 2.0 |
core/src/main/kotlin/com/bsse2018/salavatov/flt/algorithms/CFPQTensor.kt | vsalavatov | 241,599,920 | false | {"Kotlin": 149462, "ANTLR": 1960} | package com.bsse2018.salavatov.flt.algorithms
import com.bsse2018.salavatov.flt.automata.PushDownAutomaton
import com.bsse2018.salavatov.flt.grammars.ContextFreeGrammar.Companion.Epsilon
import com.bsse2018.salavatov.flt.utils.Graph
import org.la4j.matrix.SparseMatrix
import org.la4j.matrix.sparse.CRSMatrix
import jav... | 0 | Kotlin | 0 | 1 | c1c229c113546ef8080fc9d3568c5024a22b80a5 | 4,020 | bsse-2020-flt | MIT License |
src/main/kotlin/kr/co/programmers/P67258.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://github.com/antop-dev/algorithm/issues/455
class P67258 {
fun solution(gems: Array<String>): IntArray {
// ["AA", "AB", "AC", "AA", "AC"]
// [ 0, 1, 2, 0, 2 ]
val map = mutableMapOf<String, Int>()
val list = mutableListOf<Int>()
... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,921 | algorithm | MIT License |
src/Day03.kt | proggler23 | 573,129,757 | false | {"Kotlin": 27990} | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
it.chunked(it.length / 2)
.map { half -> half.toSet() }
.let { (left, right) -> left intersect right }
.single().priority
}
}
fun part2(input: List<String>): I... | 0 | Kotlin | 0 | 0 | 584fa4d73f8589bc17ef56c8e1864d64a23483c8 | 909 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/gitTraining/Fibbonaci.kt | stellake | 275,847,748 | true | {"Kotlin": 5488} | package com.gitTraining
fun computeFibbonaciNumber(position: Int?, recursion: Boolean = false): Int {
var notNullPosition = position
if (notNullPosition == null) {
notNullPosition = 1
}
if (recursion) return recursiveFibbonachi(1, 1, notNullPosition - 2)
if (notNullPosition == 0) return 0
... | 0 | Kotlin | 0 | 0 | d4b42d81eb35c78a42ac6aa62f64964d2bd1bc94 | 1,899 | git-training | MIT License |
2021/src/main/kotlin/com/trikzon/aoc2021/Day6.kt | Trikzon | 317,622,840 | false | {"Kotlin": 43720, "Rust": 21648, "C#": 12576, "C++": 4114, "CMake": 397} | package com.trikzon.aoc2021
fun main() {
val input = getInputStringFromFile("/day6.txt")
benchmark(Part.One, ::daySixPartOne, input, 5934, 500)
benchmark(Part.Two, ::daySixPartTwo, input, 377263, 50000)
}
// Note: This was a slow naive solution. Part 2 is much faster. I'm keeping
// this here to show my ... | 0 | Kotlin | 1 | 0 | d4dea9f0c1b56dc698b716bb03fc2ad62619ca08 | 1,250 | advent-of-code | MIT License |
src/Day25.kt | davidkna | 572,439,882 | false | {"Kotlin": 79526} | fun main() {
fun part1(input: List<String>): String {
var n = input.sumOf {
it.fold(0L) { acc, c ->
acc * 5L + when (c) {
'0' -> 0L
'1' -> 1L
'2' -> 2L
'-' -> -1L
'=' -> -2L
... | 0 | Kotlin | 0 | 0 | ccd666cc12312537fec6e0c7ca904f5d9ebf75a3 | 1,195 | aoc-2022 | Apache License 2.0 |
strings/CheckIfAWordOccursAsAPrefixOfAnyWordInASentence/kotlin/Solution.kt | YaroslavHavrylovych | 78,222,218 | false | {"Java": 284373, "Kotlin": 35978, "Shell": 2994} | /**
* Given a sentence that consists of some words separated by a single space,
* and a searchWord. You have to check if searchWord
* is a prefix of any word in sentence.
* Return the index of the word in sentence
* where searchWord is a prefix of this word (1-indexed).
* If searchWord is a prefix of more tha... | 0 | Java | 0 | 2 | cb8e6f7e30563e7ced7c3a253cb8e8bbe2bf19dd | 1,287 | codility | MIT License |
src/Day01.kt | Krzychuk9 | 573,127,179 | false | null | import common.Elv
import common.Item
fun main() {
fun part1(input: List<String>): Int {
return input.getElves()
.maxBy { it.getTotalCalories() }
.getTotalCalories()
}
fun part2(input: List<String>): Int {
return input.getElves()
.sortedByDesc... | 0 | Kotlin | 0 | 0 | ded55d03c9d4586166bf761c7d5f3f45ac968e81 | 939 | adventOfCode2022 | Apache License 2.0 |
src/cn/leetcode/codes/simple724/Simple724.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple724
import cn.leetcode.codes.out
import com.sun.xml.internal.xsom.impl.ForeignAttributesImpl
import java.util.*
fun main() {
// val nums = intArrayOf(1, 7, 3, 6, 5, 6)
// val nums = intArrayOf(1,2,3)
val nums = intArrayOf(-1,-1,-1,-1,-1,0)
val i = pivotIndex(nums)
o... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 1,532 | LeetCodeSimple | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CountPyramids.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 | 2,881 | kotlab | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem2007/Solution2.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2007
/**
* LeetCode page: [2007. Find Original Array From Doubled Array](https://leetcode.com/problems/find-original-array-from-doubled-array/);
*/
class Solution2 {
/* Complexity:
* Time O(NLogN) and Space O(N) where N is size of changed;
*/
fun findOriginalAr... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,957 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day03.kt | naturboy | 572,742,689 | false | {"Kotlin": 6452} | import java.lang.IllegalArgumentException
fun main() {
fun scoreOf(char: Char): Int {
return when (char) {
in 'a'..'z' -> char - 'a' + 1
in 'A'..'Z' -> char - 'A' + 27
else -> throw IllegalArgumentException("Invalid Char '$char'")
}
}
fun part1(input: L... | 0 | Kotlin | 0 | 0 | 852871f58218d80702c3b49dd0fd453096e56a43 | 1,194 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/fp/kotlin/example/chapter04/CompositionFunctions.kt | funfunStory | 101,662,895 | false | null | package fp.kotlin.example.chapter04
import fp.kotlin.example.chapter04.solution.curried
import kotlin.math.abs
fun main() {
println(composed(3)) // 9
val addThree = { i: Int -> i + 3 }
val twice = { i: Int -> i * 2 }
val composedFunc = addThree compose twice
println(composedFunc(3)) // 9
... | 1 | Kotlin | 23 | 39 | bb10ea01d9f0e1b02b412305940c1bd270093cb6 | 1,812 | fp-kotlin-example | MIT License |
workshops/moscow_prefinals2020/day4/c.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package workshops.moscow_prefinals2020.day4
fun main() {
val s = readLine()!!
val initMask = s.reversed().replace("(", "0").replace(")", "1").toLong(2)
val memo = List(s.length + 1) { mutableMapOf<Long, Double>() }
memo[0][0] = 1.0
fun solve(n: Int, mask: Long): Double {
memo[n][mask]?.also { return it }
if (... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 898 | competitions | The Unlicense |
domain/src/main/kotlin/com/seanshubin/kotlin/tryme/domain/dice/SpheresOfInfluenceDiceStatisticsApp.kt | SeanShubin | 228,113,855 | false | null | package com.seanshubin.kotlin.tryme.domain.dice
object SpheresOfInfluenceDiceStatisticsApp {
fun List<Int>.incrementDieRoll(faces: Int): List<Int> {
val newValues = mutableListOf<Int>()
var carry = true
for (currentIndex in size - 1 downTo 0) {
val value = get(currentIndex)
... | 0 | Kotlin | 0 | 0 | abc67c5f43c01bdf55c6d4adcf05b77610c0473a | 5,007 | kotlin-tryme | The Unlicense |
y2017/src/main/kotlin/adventofcode/y2017/Day12.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2017
import adventofcode.io.AdventSolution
object Day12 : AdventSolution(2017, 12, "Digital Plumber") {
override fun solvePartOne(input: String): String {
val connections = parseInput(input)
val group = findGroup(connections, 0)
return group.size.toString()
}
override fun solvePartTw... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,202 | advent-of-code | MIT License |
src/day03.kt | skuhtic | 572,645,300 | false | {"Kotlin": 36109} | fun main() {
day03.execute(onlyTests = false, forceBothParts = true)
}
val day03 = object : Day<Int>(3, 157, 70) {
@Suppress("SpellCheckingInspection")
override val testInput: InputData
get() = """
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
... | 0 | Kotlin | 0 | 0 | 8de2933df90259cf53c9cb190624d1fb18566868 | 1,529 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/sorting/Inversions.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.sorting
fun main() {
val items = mutableListOf(2, 3, 9, 2, 9) // 2
print("items: $items \n")
print("inversions: ${count(items)} \n")
}
// O(nlog(n)) time | O(n) space
private fun count(arr: MutableList<Int>): Long {
val n = arr.size
val b = MutableL... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 1,427 | algs4-leprosorium | MIT License |
src/main/kotlin/day14/Day14.kt | limelier | 725,979,709 | false | {"Kotlin": 48112} | package day14
import common.InputReader
import util.Grid
import util.Grid.Companion.asGrid
private enum class Rock {
Round,
Square,
None;
override fun toString(): String = when(this) {
Round -> "O"
Square -> "#"
None -> "."
}
}
private fun Grid<Rock>.rollNorth() {
for... | 0 | Kotlin | 0 | 0 | 0edcde7c96440b0a59e23ec25677f44ae2cfd20c | 3,365 | advent-of-code-2023-kotlin | MIT License |
src/Day09.kt | sungi55 | 574,867,031 | false | {"Kotlin": 23985} | import kotlin.math.abs
import kotlin.math.sign
fun main() {
val day = "Day09"
fun getHeadSteps(lines: List<String>) =
sequence {
var x = 0
var y = 0
yield(P(x, y))
for (line in lines) {
repeat(line.drop(2).toInt()) {
... | 0 | Kotlin | 0 | 0 | 2a9276b52ed42e0c80e85844c75c1e5e70b383ee | 1,739 | aoc-2022 | Apache License 2.0 |
Bootcamp_00/src/exercise3/src/main/kotlin/Main.kt | Hasuk1 | 740,111,124 | false | {"Kotlin": 120039} | fun main() {
val outputMode = readOutputMode()
val seasonInput = readSeason()
var temperatureInput = readTemperature()
val modeSymbol = getModeSymbol(outputMode)
val comfortableTemperatureRange = getComfortableTemperatureRange(seasonInput, outputMode)
val comfortable = temperatureInput in comfortableTempera... | 0 | Kotlin | 0 | 1 | 1dc4de50dd3cd875e3fe76e3da4a58aa04bb87c7 | 3,490 | Kotlin_bootcamp | MIT License |
src/main/kotlin/g0801_0900/s0815_bus_routes/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0815_bus_routes
// #Hard #Array #Hash_Table #Breadth_First_Search #Level_2_Day_11_Graph/BFS/DFS
// #2023_03_22_Time_429_ms_(100.00%)_Space_55.8_MB_(100.00%)
import java.util.LinkedList
import java.util.Queue
class Solution {
fun numBusesToDestination(routes: Array<IntArray>, source: Int, targ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,665 | LeetCode-in-Kotlin | MIT License |
Chapter07/HeapSort.kt | PacktPublishing | 125,371,513 | false | null | import java.util.*
fun <E: Comparable<E>> Array<E>.sort() {
val middle = size / 2 - 1
for (i in middle downTo 0) {
heapify(this, size, i)
}
for (i in size - 1 downTo 0) {
this[0] = this[i].also { this[i] = this[0] }
heapify(this, i, 0)
}
}
private fun <E: Comparable<E>> hea... | 0 | Kotlin | 62 | 162 | f125372a286a3bf4f0248db109a7427f6bc643a7 | 1,802 | Hands-On-Data-Structures-and-Algorithms-with-Kotlin | MIT License |
2020/Day3/src/main/kotlin/main.kt | airstandley | 225,475,112 | false | {"Python": 104962, "Kotlin": 59337} | import java.io.File
fun getInput(): List<String> {
return File("Input").readLines()
}
val TREE = '#'
val GROUND = '.'
class Slope(val grid: List<String>, start: Pair<Int, Int>) {
var x = start.first
var y = start.second
fun position(): Char {
return this.grid[this.y][this.x]
}
fun a... | 0 | Python | 0 | 0 | 86b7e289d67ba3ea31a78f4a4005253098f47254 | 1,433 | AdventofCode | MIT License |
src/Day04_part1.kt | yashpalrawat | 573,264,560 | false | {"Kotlin": 12474} | fun main() {
val input = readInput("Day04")
/* basically check if one pair is included within other pair
Pair(a,b) Pair(c,d)
the are inclusive if
c >= a && d <= b
a >= c && b <= d
* */
val result = input.sumOf {
val firstPair = it.split(",")[0].toIntPair()
... | 0 | Kotlin | 0 | 0 | 78a3a817709da6689b810a244b128a46a539511a | 1,005 | code-advent-2022 | Apache License 2.0 |
src/main/kotlin/days_2020/Day3.kt | BasKiers | 434,124,805 | false | {"Kotlin": 40804} | package days_2020;
import util.Day
class Day3 : Day(3, 2020) {
val input = World(inputString)
enum class Geology {
TREE, GROUND
}
class World(val geology: List<List<Geology>>) {
constructor(geologyStr: String) : this(
geologyStr.split("\n").map { lineStr ->
... | 0 | Kotlin | 0 | 0 | 870715c172f595b731ee6de275687c2d77caf2f3 | 1,694 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
src/Day01.kt | RusticFlare | 574,508,778 | false | {"Kotlin": 78496} | fun main() {
fun part1(input: String): Int {
return input.splitToSequence("\n\n")
.maxOf { elf -> elf.lines().sumOf { it.toInt() } }
}
fun part2(input: String): Int {
return input.splitToSequence("\n\n")
.map { elf -> elf.lines().sumOf { it.toInt() } }
.s... | 0 | Kotlin | 0 | 1 | 10df3955c4008261737f02a041fdd357756aa37f | 731 | advent-of-code-kotlin-2022 | Apache License 2.0 |
2015/kotlin/src/main/kotlin/nl/sanderp/aoc/aoc2015/day17/Day17.kt | sanderploegsma | 224,286,922 | false | {"C#": 233770, "Kotlin": 126791, "F#": 110333, "Go": 70654, "Python": 64250, "Scala": 11381, "Swift": 5153, "Elixir": 2770, "Jinja": 1263, "Ruby": 1171} | package nl.sanderp.aoc.aoc2015.day17
const val capacity = 150
val input = listOf(50, 44, 11, 49, 42, 46, 18, 32, 26, 40, 21, 7, 18, 43, 10, 47, 36, 24, 22, 40)
fun combinations(options: List<Int> = input.indices.toList(), choices: List<Int> = emptyList()): Set<List<Int>> {
val currentSum = choices.sumOf { input[i... | 0 | C# | 0 | 6 | 8e96dff21c23f08dcf665c68e9f3e60db821c1e5 | 876 | advent-of-code | MIT License |
src/d05/Day05.kt | Ezike | 573,181,935 | false | {"Kotlin": 7967} | package d05
import readString
data class Action(
val size: Int,
val from: Int,
val to: Int,
)
fun main() {
val input = readString("d05/Day05")
.split("\n\n")
val (crates, instructions) = input
val actions = instructions.split(" ", "\n")
.filter {
it !in listOf("mo... | 0 | Kotlin | 0 | 0 | 07ed8acc2dcee09cc4f5868299a8eb5efefeef6d | 1,831 | advent-of-code | Apache License 2.0 |
src/main/kotlin/Day02.kt | csabapap | 117,575,936 | false | null | object Day02 {
fun part1(input: String): Int {
var sum = 0
input.lines().forEach({ line ->
var min = 0
var max = 0
line.split("\\s+".toRegex()).forEach {
val number = it.toInt()
if (min == 0 || min > number) {
m... | 0 | Kotlin | 0 | 0 | c1cca8f43b6af87fe3364696d873e0300b602902 | 1,738 | aoc-2017 | MIT License |
2023/src/day02/Day02.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day02
import java.io.File
fun main() {
val input = File("src/day02/Day02.txt").readLines()
val games = input.map { Game(it) }
val colorMap = mapOf<String, Int>(
"red" to 12,
"green" to 13,
"blue" to 14
)
println(games.filter { it.isValidGame(colorMap) }.sumOf { it... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 1,598 | adventofcode | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2019/Day3.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2019
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.report
class Day3 : AdventDay(2019, 3) {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val d = Day3()
report { d.part1() }
report { d.part2() }
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 1,688 | adventofcode | MIT License |
src/main/kotlin/graph/variation/TwoSat.kt | yx-z | 106,589,674 | false | null | package graph.variation
import graph.core.Edge
import graph.core.Graph
import graph.core.Vertex
import graph.core.tarjan
import util.*
// describe a polynomial time algorithm for 2sat:
// given a boolean formula B in 2cnf (conjunctive normal form)
// determine if it is satisfiable
// note that 3sat is np-complete, bu... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 2,094 | AlgoKt | MIT License |
jeorg-kotlin-algorithms/jeorg-kotlin-alg-4-latent-semantic-analysis/src/main/kotlin/org/jesperancinha/algorithms/weigh/term/frequency/LatentSemanticAnalysisCalculator.kt | jesperancinha | 354,756,418 | false | {"Kotlin": 35444, "Java": 14401, "JavaScript": 10140, "Python": 4018, "Makefile": 1258, "Shell": 89} | package org.jesperancinha.algorithms.weigh.term.frequency
import Jama.EigenvalueDecomposition
import Jama.Matrix
import Jama.SingularValueDecomposition
import org.jesperancinha.console.consolerizer.console.ConsolerizerComposer
import kotlin.math.abs
import kotlin.math.sqrt
class LatentSemanticAnalysisCalculator(sente... | 1 | Kotlin | 0 | 1 | 7a382ed529ebdc53cc025671a453c7bd5699539e | 6,055 | jeorg-algorithms-test-drives | Apache License 2.0 |
src/main/kotlin/at/mpichler/aoc/solutions/year2021/Day16.kt | mpichler94 | 656,873,940 | false | {"Kotlin": 196457} | package at.mpichler.aoc.solutions.year2021
import at.mpichler.aoc.lib.Day
import at.mpichler.aoc.lib.PartSolution
import at.mpichler.aoc.lib.Test
open class Part16A : PartSolution() {
lateinit var packet: Packet
override fun parseInput(text: String) {
val binData = text.map { it.digitToInt(16).toStri... | 0 | Kotlin | 0 | 0 | 69a0748ed640cf80301d8d93f25fb23cc367819c | 4,823 | advent-of-code-kotlin | MIT License |
src/main/kotlin/day03/part2/main.kt | TheMrMilchmann | 225,375,010 | false | null | /*
* Copyright (c) 2019 <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 | 9d6e2adbb25a057bffc993dfaedabefcdd52e168 | 3,246 | AdventOfCode2019 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/UniqueBinarySearchTrees.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,661 | kotlab | Apache License 2.0 |
src/main/kotlin/Main.kt | NiksonJD | 611,690,522 | false | null | package wordsvirtuoso
import java.io.File
fun input(prompt: String) = println(prompt).run { readln() }
fun check(f: Set<String>) = f.filter { it.length != 5 || !it.matches(Regex("[a-z]{5}")) || it.toSet().size != 5 }
class Statistics() {
val start = System.currentTimeMillis()
val badChar = mutableSetOf<Strin... | 0 | Kotlin | 0 | 0 | a3a9cddb24175c9ddffb0f3830885a731360b7be | 3,821 | Kotlin_WordsVirtuoso | Apache License 2.0 |
src/Day04/Day04.kt | NST-d | 573,224,214 | false | null | package Day04
import utils.*
fun main() {
fun part1(input: List<String>)=
input.map {
it.split(',')
}.sumOf {
val first = it[0].split('-')
val second = it[1].split('-')
var value = 0
if (first[0].toInt() >= second[0].toInt() && first[1]... | 0 | Kotlin | 0 | 0 | c4913b488b8a42c4d7dad94733d35711a9c98992 | 1,246 | aoc22 | Apache License 2.0 |
src/main/kotlin/g2801_2900/s2813_maximum_elegance_of_a_k_length_subsequence/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2801_2900.s2813_maximum_elegance_of_a_k_length_subsequence
// #Hard #Array #Hash_Table #Sorting #Greedy #Heap_Priority_Queue
// #2023_12_06_Time_853_ms_(100.00%)_Space_104.7_MB_(100.00%)
import kotlin.math.max
class Solution {
fun findMaximumElegance(items: Array<IntArray>, k: Int): Long {
items... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,262 | LeetCode-in-Kotlin | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.