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/Day12.kt | Kbzinho-66 | 572,299,619 | false | {"Kotlin": 34500} | import kotlin.properties.Delegates
private typealias Adjacencies = MutableList<Int>
private class Graph(input: List<String>) {
private var rows by Delegates.notNull<Int>()
private var cols by Delegates.notNull<Int>()
private var start by Delegates.notNull<Int>()
private var end by Delegates.notNull<I... | 0 | Kotlin | 0 | 0 | e7ce3ba9b56c44aa4404229b94a422fc62ca2a2b | 3,549 | advent_of_code_2022_kotlin | Apache License 2.0 |
src/main/kotlin/com/staricka/adventofcode2022/Day2.kt | mathstar | 569,952,400 | false | {"Kotlin": 77567} | package com.staricka.adventofcode2022
import java.lang.Exception
class Day2 : Day {
override val id = 2
enum class Choice(val score: Int) {
ROCK(1), PAPER(2), SCISSORS(3);
fun outcome(vs: Choice) : Int{
if (this == vs) return 3
if (this == ROCK && vs == SCISSORS) return 6
if (this == P... | 0 | Kotlin | 0 | 0 | 2fd07f21348a708109d06ea97ae8104eb8ee6a02 | 1,845 | adventOfCode2022 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NthMagicalNumber.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <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,748 | kotlab | Apache License 2.0 |
src/year2022/05/Day05.kt | Vladuken | 573,128,337 | false | {"Kotlin": 327524, "Python": 16475} | package year2022.`05`
import java.util.Stack
import readInput
fun main() {
fun part1(input: List<String>): String {
val (mutableStacks, listOfCommands) = prepareStacksToCommands(input)
applyCommandsToStacks(
mutableStacks = mutableStacks,
commands = listOfCommands
... | 0 | Kotlin | 0 | 5 | c0f36ec0e2ce5d65c35d408dd50ba2ac96363772 | 4,415 | KotlinAdventOfCode | Apache License 2.0 |
src/day01/Day01.kt | zoricbruno | 573,440,038 | false | {"Kotlin": 13739} | fun findCalories(input: List<String>): List<Int> {
val calories = mutableListOf<Int>()
var currentCalories = 0
var index = 0
while (index < input.size) {
if (input[index] == "") {
calories.add(currentCalories)
currentCalories = 0;
} else if (index == input.size - ... | 0 | Kotlin | 0 | 0 | 16afa06aff0b6e988cbea8081885236e4b7e0555 | 1,081 | kotlin_aoc_2022 | Apache License 2.0 |
grind-75-kotlin/src/main/kotlin/ValidParentheses.kt | Codextor | 484,602,390 | false | {"Kotlin": 27206} | /**
* Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',
* determine if the input string is valid.
*
* An input string is valid if:
*
* Open brackets must be closed by the same type of brackets.
* Open brackets must be closed in the correct order.
*
*
* Example 1:
*
* Input: s ... | 0 | Kotlin | 0 | 0 | 87aa60c2bf5f6a672de5a9e6800452321172b289 | 1,216 | grind-75 | Apache License 2.0 |
src/main/kotlin/days/Day8.kt | mir47 | 433,536,325 | false | {"Kotlin": 31075} | package days
class Day8 : Day(8) {
override fun partOne(): Int {
val r = inputList.map { it.split(" | ") }
.map { it[1] }
.flatMap { it.split(" ") }
return r.count { it.length == 2 || it.length == 3 || it.length == 4 || it.length == 7 }
}
override fun partTwo(): L... | 0 | Kotlin | 0 | 0 | 686fa5388d712bfdf3c2cc9dd4bab063bac632ce | 2,991 | aoc-2021 | Creative Commons Zero v1.0 Universal |
2021/src/Day03.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | // https://adventofcode.com/2021/day/3
import java.io.File
import kotlin.math.pow
fun main() {
fun readLines(fileName: String): List<String>
= File(fileName).bufferedReader().readLines()
fun part1() {
val ones = sortedMapOf<Int, Int>()
val zeros = sortedMapOf<Int, Int>()
for (line in readLines... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 2,041 | advent-of-code | Apache License 2.0 |
src/main/java/com/booknara/problem/bfs/RottingOrangesKt.kt | booknara | 226,968,158 | false | {"Java": 1128390, "Kotlin": 177761} | package com.booknara.problem.bfs
import java.util.*
/**
* 994. Rotting Oranges (Medium)
* https://leetcode.com/problems/rotting-oranges/
*/
class RottingOrangesKt {
// T:O(n^2), S:O(n^2)
fun orangesRotting(grid: Array<IntArray>): Int {
// input check, m, n >= 1
// finding rotten oranges
var count =... | 0 | Java | 1 | 1 | 04dcf500ee9789cf10c488a25647f25359b37a53 | 1,374 | playground | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NumberOfClosedIslands.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,659 | kotlab | Apache License 2.0 |
2022/src/main/kotlin/day2_fast.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
fun main() {
Day2Fast.run()
}
object Day2Fast : Solution<LongArray>() {
override val name = "day2"
// packed longs of plays, where a nibble in each long is
// a game with the bit layout of RRLL
override val parser = Parser.lines.map {
it.chunked(16).map { lines... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,520 | aoc_kotlin | MIT License |
src/main/kotlin/adventofcode/year2020/Day24LobbyLayout.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2020
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import adventofcode.year2020.Day24LobbyLayout.Companion.TileColor.BLACK
import adventofcode.year2020.Day24LobbyLayout.Companion.TileColor.WHITE
class Day24LobbyLayout(customInput: PuzzleInput? = null) : Puzzle(customInput) {
... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 2,449 | AdventOfCode | MIT License |
src/Day09.kt | mikemac42 | 573,071,179 | false | {"Kotlin": 45264} | import java.io.File
fun main() {
val testInput = """R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2"""
val testInput2 = """R 5
U 8
L 8
D 3
R 17
D 10
L 25
U 20"""
val realInput = File("src/Day09.txt").readText()
val part1TestOutput = numPositionsTailVisited(testInput, 2)
println("Part 1 Test Output: $part1TestOutput")
che... | 0 | Kotlin | 1 | 0 | 909b245e4a0a440e1e45b4ecdc719c15f77719ab | 2,577 | advent-of-code-2022 | Apache License 2.0 |
src/Day02/Day02.kt | ctlevi | 578,257,705 | false | {"Kotlin": 10889} | enum class PlayOption {
ROCK, PAPER, SCISSORS
}
enum class OutcomeOption {
LOSE, DRAW, WIN
}
fun main() {
val LOSE_SCORE = 0
val DRAW_SCORE = 3
val WIN_SCORE = 6
val ROCK_SCORE = 1
val PAPER_SCORE = 2
val SCISSOR_SCORE = 3
fun convertToPlayOption(option: String): PlayOption {
... | 0 | Kotlin | 0 | 0 | 0fad8816e22ec0df9b2928983713cd5c1ac2d813 | 3,399 | advent_of_code_2022 | Apache License 2.0 |
src/exercises/Day03.kt | Njko | 572,917,534 | false | {"Kotlin": 53729} | // ktlint-disable filename
package exercises
import readInput
const val ASCII_LOWER_CASE_SHIFT = 96
const val ASCII_UPPER_CASE_SHIFT = 64
const val LOWER_UPPERCASE_OFFSET = 26
fun main() {
fun getItemPriority(equalItem: Char) = if (equalItem.isLowerCase()) {
equalItem.code - ASCII_LOWER_CASE_SHIFT
} e... | 0 | Kotlin | 0 | 2 | 68d0c8d0bcfb81c183786dfd7e02e6745024e396 | 1,591 | advent-of-code-2022 | Apache License 2.0 |
src/day01/Day01.kt | lpleo | 572,702,403 | false | {"Kotlin": 30960} | package day01
import readInput
fun main() {
fun getMaxCaloriesList(input: List<String>): MutableList<Int> {
val maxCaloriesList: MutableList<Int> = mutableListOf(0);
input.forEach {
if (it.isNotEmpty()) {
maxCaloriesList[maxCaloriesList.lastIndex] = maxCaloriesList[max... | 0 | Kotlin | 0 | 0 | 115aba36c004bf1a759b695445451d8569178269 | 1,217 | advent-of-code-2022 | Apache License 2.0 |
src/Day02.kt | tsdenouden | 572,703,357 | false | {"Kotlin": 8295} | fun main() {
var playerScore = 0
val playerMoveMap: Map<Char, Int> = mapOf(
'X' to 1,
'Y' to 2,
'Z' to 3
)
val botMoveMap: Map<Char, Int> = mapOf(
'A' to 1,
'B' to 2,
'C' to 3
)
fun playerWin() {
playerScore += 6
}
// compare pla... | 0 | Kotlin | 0 | 0 | 68982ebffc116f3b49a622d81e725c8ad2356fed | 2,628 | aoc-2022-kotlin | Apache License 2.0 |
day08/src/Day08.kt | simonrules | 491,302,880 | false | {"Kotlin": 68645} | import com.sun.xml.internal.fastinfoset.util.StringArray
import java.io.File
class Day08(private val path: String) {
fun part1(): Int {
var unique = 0
File(path).forEachLine {
val parts = it.split(" | ")
val output = parts[1].split(' ')
output.forEach { part ->
... | 0 | Kotlin | 0 | 0 | d9e4ae66e546f174bcf66b8bf3e7145bfab2f498 | 2,866 | aoc2021 | Apache License 2.0 |
Algo_Ds_Notes-master/Algo_Ds_Notes-master/Knuth_Morris_Pratt_Algorithm/KMP.kt | rajatenzyme | 325,100,742 | false | {"C++": 709855, "Java": 559443, "Python": 397216, "C": 381274, "Jupyter Notebook": 127469, "Go": 123745, "Dart": 118962, "JavaScript": 109884, "C#": 109817, "Ruby": 86344, "PHP": 63402, "Kotlin": 52237, "TypeScript": 21623, "Rust": 20123, "CoffeeScript": 13585, "Julia": 2385, "Shell": 506, "Erlang": 385, "Scala": 310, ... | /*
<NAME> String Searching Algorithm
Given a text txt[0..n-1] and a pattern pat[0..m-1], the algo will find all occurrences of pat[] in txt[]
*/
import java.util.*
internal class KMP {
fun kmpSearch(pat: String, txt: String) {
val m = pat.length
val n = txt.length
// longest_prefix_suffix ... | 0 | C++ | 0 | 0 | 65a0570153b7e3393d78352e78fb2111223049f3 | 1,964 | Coding-Journey | MIT License |
Three_Sum_Closest_v1.kt | xiekch | 166,329,519 | false | {"C++": 165148, "Java": 103273, "Kotlin": 97031, "Go": 40017, "Python": 22302, "TypeScript": 17514, "Swift": 6748, "Rust": 6579, "JavaScript": 4244, "Makefile": 349} | import kotlin.math.absoluteValue
class Solution {
private fun findClosetDiff(nums: IntArray, target: Int, low: Int): Int {
var diff = Int.MAX_VALUE
var high = nums.size - 1
var low = low
// println("$low $high")
while (low <= high) {
val middle = (low + high) / 2
... | 0 | C++ | 0 | 0 | eb5b6814e8ba0847f0b36aec9ab63bcf1bbbc134 | 1,746 | leetcode | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/VerifyingAlienDictionary.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,001 | kotlab | Apache License 2.0 |
src/main/kotlin/g1801_1900/s1856_maximum_subarray_min_product/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1856_maximum_subarray_min_product
// #Medium #Array #Stack #Prefix_Sum #Monotonic_Stack
// #2023_06_22_Time_517_ms_(66.67%)_Space_57.4_MB_(66.67%)
class Solution {
fun maxSumMinProduct(nums: IntArray): Int {
val n = nums.size
val mod = (1e9 + 7).toInt()
if (n == 1) {
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,326 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/day6.kt | danielfreer | 297,196,924 | false | null | import kotlin.time.ExperimentalTime
@ExperimentalTime
fun day6(input: List<String>): List<Solution> {
return listOf(
solve(6, 1) { countTotalOrbits(input) }
)
}
fun countTotalOrbits(orbitMap: List<String>): Int {
val rootNode = parseRootNode(orbitMap)
val directOrbits = countDirectOrbits(rootN... | 0 | Kotlin | 0 | 0 | 74371d15f95492dee1ac434f0bfab3f1160c5d3b | 1,752 | advent2019 | The Unlicense |
year2021/day07/part1/src/main/kotlin/com/curtislb/adventofcode/year2021/day07/part1/Year2021Day07Part1.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Day 7: The Treachery of Whales ---
A giant whale has decided your submarine is its next meal, and it's much faster than you are.
There's nowhere to run!
Suddenly, a swarm of crabs (each in its own tiny submarine - it's too deep for them otherwise) zooms
in to rescue you! They seem to be preparing to blast a ho... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,672 | AdventOfCode | MIT License |
src/main/kotlin/aoc2022/Day20.kt | davidsheldon | 565,946,579 | false | {"Kotlin": 161960} | package aoc2022
import utils.InputUtils
import kotlin.math.absoluteValue
class DoubleLinkedList<T>(initialContent: List<T>) {
var head: Node<T>
val size = initialContent.size
init {
val nodes = initialContent.map { Node(it) }
nodes.zipWithNext { a,b ->
a.right = b
b... | 0 | Kotlin | 0 | 0 | 5abc9e479bed21ae58c093c8efbe4d343eee7714 | 3,382 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/com/groundsfam/advent/y2021/d05/Day05.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2021.d05
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.points.Point
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
fun range(from: Point, to: Point): List<Point> {
val xStep = when {
from.x < to.x -> 1
... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 1,616 | advent-of-code | MIT License |
src/Day25.kt | jordan-thirus | 573,476,470 | false | {"Kotlin": 41711} | import kotlin.math.pow
fun main() {
fun String.toLong(verbose: Boolean): Long {
var num = 0L
this.reversed().forEachIndexed{ index, c ->
val value = 5.0.pow(index).toLong()
when(c) {
'=' -> num -= value * 2
'-' -> num -= value
... | 0 | Kotlin | 0 | 0 | 59b0054fe4d3a9aecb1c9ccebd7d5daa7a98362e | 1,300 | advent-of-code-2022 | Apache License 2.0 |
ceria/03/src/main/kotlin/Solution.kt | VisionistInc | 572,963,504 | false | null | import java.io.File;
val charPriorities = "-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toList()
fun main(args : Array<String>) {
var input = File(args.first()).readLines()
println("Solution 1: ${solution1(input)}")
println("Solution 2: ${solution2(input)}")
}
private fun solution1(input: List... | 0 | Rust | 0 | 0 | 90b348d9c8060a8e967fe1605516e9c126fc7a56 | 984 | advent-of-code-2022 | MIT License |
src/Day11.kt | HaydenMeloche | 572,788,925 | false | {"Kotlin": 25699} | fun main() {
val partTwo = true
val input = readInput("Day11").toMutableList()
val monkeys = mutableMapOf<Int, Monkey>()
input.removeAll { it.isBlank() }
input.windowed(size = 6, step = 6).forEach { entry ->
val id = entry[0].substringBeforeLast(":")
.takeLastUntilSpace()
... | 0 | Kotlin | 0 | 1 | 1a7e13cb525bb19cc9ff4eba40d03669dc301fb9 | 2,637 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day08/Day08.kt | kerchen | 573,125,453 | false | {"Kotlin": 137233} | package day08
import readInput
class HeightMap(input: List<String>) {
var rows = mutableListOf<List<Int>>()
var rowCount = 0
var columnCount = 0
init {
for (row in input) {
rows.add(row.map { it.code - '0'.code })
}
rowCount = rows.size
columnCount = rows[0... | 0 | Kotlin | 0 | 0 | dc15640ff29ec5f9dceb4046adaf860af892c1a9 | 4,269 | AdventOfCode2022 | Apache License 2.0 |
src/Day24/Day24.kt | martin3398 | 436,014,815 | false | {"Kotlin": 63436, "Python": 5921} | fun main() {
fun preprocess(input: List<String>): List<List<String>> {
return input.map { it.split(" ") }
}
fun split(input: List<List<String>>): MutableList<List<List<String>>> {
val blocks = mutableListOf<List<List<String>>>()
var block = mutableListOf<List<String>>()
for ... | 0 | Kotlin | 0 | 0 | 085b1f2995e13233ade9cbde9cd506cafe64e1b5 | 1,978 | advent-of-code-2021 | Apache License 2.0 |
src/Day03.kt | rossilor95 | 573,177,479 | false | {"Kotlin": 8837} | fun main() {
fun Char.toPriority(): Int = when {
this.isLowerCase() -> this.code - 96 // UTF-16 codes for lowercase letters are 97..122
this.isUpperCase() -> this.code - 38 // UTF-16 codes for uppercase letters are 65..90
else -> error("Check your inputs!")
}
fun part1(input: List<S... | 0 | Kotlin | 0 | 0 | 0ed98d0ab5f44b2ccfc625ef091e736c5c748ff0 | 1,036 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/day17/Day17.kt | pocmo | 433,766,909 | false | {"Kotlin": 134886} | package day17
import kotlin.math.max
data class TargetArea(
val xRange: IntRange,
val yRange: IntRange
) {
fun calculateResult(x: Int, y: Int): AreaResult {
return when {
y < yRange.minOrNull()!! -> AreaResult.MissBottom
x > xRange.maxOrNull()!! -> AreaResult.MissRight
... | 0 | Kotlin | 1 | 2 | 73bbb6a41229e5863e52388a19108041339a864e | 3,234 | AdventOfCode2021 | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2022/Day19.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2022
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import com.s13g.aoc.mul
import com.s13g.aoc.resultFrom
import kotlin.math.max
import kotlin.math.min
/**
* --- Day 19: Not Enough Minerals ---
* https://adventofcode.com/2022/day/19
*/
class Day19 : Solver {
enum class Bot { ORE, ... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 4,314 | euler | Apache License 2.0 |
src/day6/main.kt | jorgensta | 573,824,365 | false | {"Kotlin": 31676} | package day6
import readInput
fun main() {
val day = "day6"
val filename = "Day06"
val testMarkers = mapOf(
"bvwbjplbgvbhsrlpgdmjqwftvncz" to 5,
"nppdvjthqldpwncqszvftbrmjlhg" to 6,
"nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg" to 10,
"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw" to 11
)
... | 0 | Kotlin | 0 | 0 | 7243e32351a926c3a269f1e37c1689dfaf9484de | 3,790 | AoC2022 | Apache License 2.0 |
src/day04/Day04.kt | veronicamengyan | 573,063,888 | false | {"Kotlin": 14976} | package day04
/**
* Potential improvement:
* * split on both , and -
* * use IntRange
*/
import readInput
fun main() {
fun isContain(input: String): Boolean {
val pair = input.split(",")
val sections1 = pair[0].split("-")
val sections2 = pair[1].split("-")
... | 0 | Kotlin | 0 | 0 | d443cfa49e9d8c9f76fdb6303ecf104498effb88 | 1,697 | aoc-2022-in-kotlin | Apache License 2.0 |
CyclicRotation.kt | getnahid | 267,415,396 | false | null | /*
CyclicRotation
Rotate an array to the right by a given number of steps.
An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is ... | 0 | Kotlin | 0 | 0 | 589c392237334f6c53513dc7b75bd8fa81ad3b79 | 1,630 | programing-problem-solves-kotlin | Apache License 2.0 |
src/Day07.kt | ahmadshabib | 573,197,533 | false | {"Kotlin": 13577} | fun main() {
val input = readInput("Day07")
var currentDirectory: Directory? = null
val directories: MutableList<Directory> = mutableListOf()
for (command in input) {
if (command.startsWith("\$ cd")) {
if (command.startsWith("\$ cd ..")) {
currentDirectory = currentD... | 0 | Kotlin | 0 | 0 | 81db1b287ca3f6cae95dde41919bfa539ac3adb5 | 2,329 | advent-of-code-kotlin-22 | Apache License 2.0 |
kotlin/yacht/src/main/kotlin/Yacht.kt | fredyw | 523,079,058 | false | null | object Yacht {
fun solve(category: YachtCategory, vararg dices: Int): Int {
return when (category) {
YachtCategory.ONES -> dices.filter { it == 1 }.sum()
YachtCategory.TWOS -> dices.filter { it == 2 }.sum()
YachtCategory.THREES -> dices.filter { it == 3 }.sum()
... | 0 | Kotlin | 0 | 0 | 101a0c849678ebb7d2e15b896cfd9e5d82c56275 | 1,370 | exercism | MIT License |
app/src/main/kotlin/io/github/andrewfitzy/day01/Task02.kt | andrewfitzy | 747,793,365 | false | {"Kotlin": 60159, "Shell": 1211} | package io.github.andrewfitzy.day01
import io.github.andrewfitzy.util.Point
class Task02(puzzleInput: List<String>) {
private val input: List<String> = puzzleInput
private val rotationMapping: Map<Pair<String, String>, String> =
mapOf(
Pair("N", "R") to "E",
Pair("N", "L") to ... | 0 | Kotlin | 0 | 0 | 15ac072a14b83666da095b9ed66da2fd912f5e65 | 1,890 | 2016-advent-of-code | Creative Commons Zero v1.0 Universal |
archive/src/main/kotlin/com/grappenmaker/aoc/year23/Day16.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year23
import com.grappenmaker.aoc.*
import com.grappenmaker.aoc.Direction.*
fun PuzzleSet.day16() = puzzle(day = 16) {
val g = inputLines.asCharGrid()
val sd = mapOf(
'-' to listOf(LEFT, RIGHT),
'|' to listOf(UP, DOWN),
)
val md = mapOf(
'/' to ma... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,842 | advent-of-code | The Unlicense |
src/main/kotlin/org/example/e3fxgaming/adventOfCode/aoc2023/day02/Day02.kt | E3FxGaming | 726,041,587 | false | {"Kotlin": 38290} | package org.example.e3fxgaming.adventOfCode.aoc2023.day02
import org.example.e3fxgaming.adventOfCode.utility.Day
import org.example.e3fxgaming.adventOfCode.utility.IndividualLineInputParser
import org.example.e3fxgaming.adventOfCode.utility.InputParser
class Day02(inputLines: String) : Day<List<Triple<Int, Int, Int>>... | 0 | Kotlin | 0 | 0 | 3ae9e8b60788733d8bc3f6446d7a9ae4b3dabbc0 | 2,409 | adventOfCode | MIT License |
src/Day21.kt | dragere | 440,914,403 | false | {"Kotlin": 62581} | import java.io.File
import java.lang.Integer.max
fun main() {
val debug = false
class Dice {
var last = -1
fun getNext(): Int {
last += 1
return last % 100 +1
}
}
fun part1(playerPositions: List<Int>): Int {
val scores = mutableListOf(0, 0)
... | 0 | Kotlin | 0 | 0 | 3e33ab078f8f5413fa659ec6c169cd2f99d0b374 | 1,497 | advent_of_code21_kotlin | Apache License 2.0 |
day-07/src/main/kotlin/TheTreacheryOfWhales.kt | diogomr | 433,940,168 | false | {"Kotlin": 92651} | import kotlin.math.abs
fun main() {
println("Part One Solution: ${partOne()}")
println("Part Two Solution: ${partTwo()}")
}
private fun partOne(): Int {
val positions = readInputLines()[0].split(",")
.map { it.toInt() }
var minFuel = Int.MAX_VALUE
for (p in positions) {
var fuelF... | 0 | Kotlin | 0 | 0 | 17af21b269739e04480cc2595f706254bc455008 | 1,136 | aoc-2021 | MIT License |
scripts/Day2.kts | matthewm101 | 573,325,687 | false | {"Kotlin": 63435} | import java.io.File
enum class Hand(val handScore: Long) {Rock(1), Paper(2), Scissors(3)}
fun charToHand(c: Char) = when(c) {
'A', 'X' -> Hand.Rock
'B', 'Y' -> Hand.Paper
'C', 'Z' -> Hand.Scissors
else -> Hand.Rock
}
enum class Goal(val goalScore: Long) {Loss(0), Tie(3), Win(6)}
fun charToGoal(c: Char... | 0 | Kotlin | 0 | 0 | bbd3cf6868936a9ee03c6783d8b2d02a08fbce85 | 2,158 | adventofcode2022 | MIT License |
src/main/kotlin/g1601_1700/s1681_minimum_incompatibility/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1601_1700.s1681_minimum_incompatibility
// #Hard #Array #Dynamic_Programming #Bit_Manipulation #Bitmask
// #2023_06_15_Time_162_ms_(100.00%)_Space_36_MB_(100.00%)
class Solution {
private class Node {
var visited: BooleanArray = BooleanArray(17)
var size = 0
var min = 20
v... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,037 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/d17/D17.kt | MTender | 734,007,442 | false | {"Kotlin": 108628} | package d17
import java.util.*
abstract class Location(
open val row: Int,
open val col: Int
) {
abstract fun getNeighbors(): List<Location>
abstract fun isValidTarget(target: Pair<Int, Int>): Boolean
}
fun parseInput(lines: List<String>): List<List<Int>> {
return lines.map { line -> line.toCha... | 0 | Kotlin | 0 | 0 | a6eec4168b4a98b73d4496c9d610854a0165dbeb | 1,951 | aoc2023-kotlin | MIT License |
src/Day06.kt | razvn | 573,166,955 | false | {"Kotlin": 27208} | fun main() {
val day = "Day06"
tailrec fun findMarker(len: Int, buffer: String, index: Int, string: String): Int {
return when {
buffer.length == len -> index
index >= string.length -> 0
else -> {
val char = string[index]
val idxOf = ... | 0 | Kotlin | 0 | 0 | 73d1117b49111e5044273767a120142b5797a67b | 1,159 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CombinationSum2.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 | 3,988 | kotlab | Apache License 2.0 |
2022/src/main/kotlin/de/skyrising/aoc2022/day14/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2022.day14
import de.skyrising.aoc.*
private fun parseInput(input: PuzzleInput, floor: Boolean = false): CharGrid {
val lines = input.lines.flatMapTo(mutableListOf()) { line ->
line.split(" -> ").map(Vec2i::parse).zipWithNext { a, b -> a lineTo b }
}
if (floor) {
va... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 1,349 | aoc | MIT License |
src/main/kotlin/Day01.kt | attilaTorok | 573,174,988 | false | {"Kotlin": 26454} | fun main() {
fun findHighestCalorie(fileName: String): Int {
var max = 0; var sum = 0
readInputWithStream(fileName).useLines {
val iterator = it.iterator()
while (iterator.hasNext()) {
val currentLine = iterator.next()
if (currentLine.isNotEmpt... | 0 | Kotlin | 0 | 0 | 1799cf8c470d7f47f2fdd4b61a874adcc0de1e73 | 1,939 | AOC2022 | Apache License 2.0 |
src/day05/Day05.kt | ivanovmeya | 573,150,306 | false | {"Kotlin": 43768} | package day05
import readInput
fun main() {
data class Operation(val from: Int, val to: Int, val quantity: Int)
fun String.toCrates(): List<Char> {
return this.chunked(4).map {
it.trim().ifBlank {
"[0]"
}
}.map { it[1] }
}
fun parseInitialStac... | 0 | Kotlin | 0 | 0 | 7530367fb453f012249f1dc37869f950bda018e0 | 5,112 | advent-of-code-2022 | Apache License 2.0 |
Kotlin/problems/0059_rotting_oranges.kt | oxone-999 | 243,366,951 | true | {"C++": 961697, "Kotlin": 99948, "Java": 17927, "Python": 9476, "Shell": 999, "Makefile": 187} | //Problem Statement
// In a given grid, each cell can have one of three values:
//
// the value 0 representing an empty cell;
// the value 1 representing a fresh orange;
// the value 2 representing a rotten orange.
// Every minute, any fresh orange that is adjacent (4-directionally) to a rotten orange becomes rotten.
/... | 0 | null | 0 | 0 | 52dc527111e7422923a0e25684d8f4837e81a09b | 2,248 | algorithms | MIT License |
problems/2020adventofcode19b/submissions/accepted/Stefan.kt | stoman | 47,287,900 | false | {"C": 169266, "C++": 142801, "Kotlin": 115106, "Python": 76047, "Java": 68331, "Go": 46428, "TeX": 27545, "Shell": 3428, "Starlark": 2165, "Makefile": 1582, "SWIG": 722} | import java.util.*
fun main() {
val s = Scanner(System.`in`).useDelimiter("\\n\\n")
val sRules = Scanner(s.next()).useDelimiter("\\n")
val rules = mutableMapOf<Int, Set<List<String>>>()
while (sRules.hasNext()) {
val rule = sRules.next().split(":")
rules[rule[0].toInt()] = rule[1].split("|").map { it.... | 0 | C | 1 | 3 | ee214c95c1dc1d5e9510052ae425d2b19bf8e2d9 | 2,157 | CompetitiveProgramming | MIT License |
solution/#26 Remove Duplicates from Sorted Array/Solution.kt | enihsyou | 116,918,868 | false | {"Java": 179666, "Python": 36379, "Kotlin": 32431, "Shell": 367} | package leetcode.q26.kotlin;
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
/**
* 26. Remove Duplicates from Sorted Array
*
* [LeetCode](https://leetcode-cn.com/proble... | 1 | Java | 0 | 0 | 230325d1dfd666ee53f304edf74c9c0f60f81d75 | 1,691 | LeetCode | MIT License |
src/main/kotlin/days/Day12.kt | felix-ebert | 317,592,241 | false | null | package days
import kotlin.math.absoluteValue
class Day12 : Day(12) {
override fun partOne(): Any {
val instructions = inputList.map { it.take(1) to it.substring(1).toInt() }.toMutableList()
return simulateInstructions(instructions, false)
}
override fun partTwo(): Any {
val inst... | 0 | Kotlin | 0 | 4 | dba66bc2aba639bdc34463ec4e3ad5d301266cb1 | 3,054 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/main/java/challenges/educative_grokking_coding_interview/two_heaps/_1/MaximizeCapital.kt | ShabanKamell | 342,007,920 | false | null | package challenges.educative_grokking_coding_interview.two_heaps._1
import challenges.util.PrintHyphens
import java.util.*
/**
A busy investor with an initial capital, c, needs an automated investment program. They can select k distinct projects
from a list of n projects with corresponding capitals requirements and e... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 3,256 | CodingChallenges | Apache License 2.0 |
advent-of-code/src/main/kotlin/com/akikanellis/adventofcode/year2022/Day20.kt | akikanellis | 600,872,090 | false | {"Kotlin": 142932, "Just": 977} | package com.akikanellis.adventofcode.year2022
import java.lang.Math.floorMod
object Day20 {
fun sumOfGroveCoordinatesWithWrongDecryptionRoutine(input: String) =
sumOfGroveCoordinates(
input = input,
decryptionKey = 1,
mixes = 1
)
fun sumOfGroveCoordinatesWi... | 8 | Kotlin | 0 | 0 | 036cbcb79d4dac96df2e478938de862a20549dce | 2,135 | advent-of-code | MIT License |
src/main/kotlin/warmup/2-recusion.kt | dzca | 581,929,762 | false | {"Kotlin": 75573} | package warmup
/**
* Module 4 is recursion
*/
/**
* binary search
*
* find key from sorted array
*
* example:
* a = arrayOf(-4,2,4,5,9,12)
* key = 5, r = 3
* key = 6, r = -1
*
* learn:
* - Math.round() rounds up to the nearest Integer
* which can be above or below or even equal to the actual value.
* -... | 0 | Kotlin | 0 | 0 | b1e7d1cb739e21ed7e8b7484d6efcd576857830f | 5,675 | kotlin-algrithm | MIT License |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/strings/MinimumCharsForWords.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.strings
import kotlin.math.max
fun main() {
print(minimumCharsForWords(listOf("only", "after", "we", "have", "lost", "everything")))
}
// O(n * l) time | O(c) space
// n is number of words
// l is length of longest word
// c is number of unique chars
private fun m... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 989 | algs4-leprosorium | MIT License |
kotlin/src/katas/kotlin/leetcode/palindrome_ignoring_punctuation/NoPunctuationPalindrome.kt | dkandalov | 2,517,870 | false | {"Roff": 9263219, "JavaScript": 1513061, "Kotlin": 836347, "Scala": 475843, "Java": 475579, "Groovy": 414833, "Haskell": 148306, "HTML": 112989, "Ruby": 87169, "Python": 35433, "Rust": 32693, "C": 31069, "Clojure": 23648, "Lua": 19599, "C#": 12576, "q": 11524, "Scheme": 10734, "CSS": 8639, "R": 7235, "Racket": 6875, "C... | package katas.kotlin.leetcode.palindrome_ignoring_punctuation
import datsok.shouldEqual
import org.junit.Test
/**
* Given a string with punctuations, upper case and lower case letters,
* check if it can be read the same from the start and from the end by ignoring punctuations and capitalization.
*/
class NoPunctua... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,576 | katas | The Unlicense |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2015/2015-03.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2015
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.readInputText
fun main() {
val input = readInputText(2015, "03-input")
val test1 = readInputText(2015, "03-test1")
println("Part1:")
println(visitsAtLeastOnce(test1... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,280 | advent-of-code | MIT License |
src/trees/SameTree.kt | develNerd | 456,702,818 | false | {"Kotlin": 37635, "Java": 5892} | package trees
/**
*
Given the roots of two binary trees p and q, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
Example 1:
Input: p = [1,2,3], q = [1,2,3]
Output: true
Example 2:
Input: p = ... | 0 | Kotlin | 0 | 0 | 4e6cc8b4bee83361057c8e1bbeb427a43622b511 | 2,054 | Blind75InKotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinSwaps.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,569 | kotlab | Apache License 2.0 |
src/main/kotlin/de/dikodam/calendar/Day12.kt | dikodam | 433,719,746 | false | {"Kotlin": 51383} | package de.dikodam.calendar
import de.dikodam.AbstractDay
import de.dikodam.executeTasks
import kotlin.time.ExperimentalTime
@ExperimentalTime
fun main() {
Day12().executeTasks()
}
const val start = "start"
const val end = "end"
class Day12 : AbstractDay() {
val testInput1 = """start-A
start-b
A-c
A-b
b-d
... | 0 | Kotlin | 0 | 1 | 4934242280cebe5f56ca8d7dcf46a43f5f75a2a2 | 3,309 | aoc-2021 | MIT License |
src/Day03.kt | marvingrewe | 573,069,044 | false | {"Kotlin": 6473} | import kotlin.system.measureTimeMillis
fun main() {
val day = "Day03"
fun Char.priority() = when (code) {
in 'a'.code..'z'.code -> (code - 'a'.code) + 1
in 'A'.code..'Z'.code -> (code - 'A'.code) + 27
else -> error("no priority for $this")
}
fun part1(input: List<String>): Int... | 0 | Kotlin | 0 | 0 | adec59f236b5f92cfcaf9e595fb913bf0010ac41 | 1,291 | advent-of-code-2022 | Apache License 2.0 |
src/jvmMain/kotlin/algorithm/graph/WeightedGraphModel.kt | DaniiLBez | 659,158,302 | false | null | package algorithm.graph
import algorithm.dijkstra.Dijkstra
import algorithm.dijkstra.ShortestPath
import java.util.*
class WeightedGraphModel(stream: String, separator: String) {
private var graph: GraphModel? = null
private var vertexNameOfNumber = hashMapOf<String, Int>()
init {
val graphStringRepresentation ... | 0 | Kotlin | 0 | 2 | 63f4c707869c10f941bde3b5e072a92e3cf068c3 | 2,287 | stud_practice | MIT License |
src/Day10.kt | mandoway | 573,027,658 | false | {"Kotlin": 22353} | fun shouldCheckSignalStrength(cycle: Int) = (cycle + 20) % 40 == 0
fun String.completionTime() = when (this) {
"noop" -> 1
else -> 2
}
fun runSimulation(commands: List<String>, onEachCycle: (cycle: Int, registerValue: Int) -> Unit) {
var cycle = 0
var registerValue = 1
commands.forEach { cmd ->
... | 0 | Kotlin | 0 | 0 | 0393a4a25ae4bbdb3a2e968e2b1a13795a31bfe2 | 1,778 | advent-of-code-22 | Apache License 2.0 |
2023/src/main/kotlin/net/daams/solutions/11b.kt | Michiel-Daams | 573,040,288 | false | {"Kotlin": 39925, "Nim": 34690} | package net.daams.solutions
import net.daams.Solution
class `11a`(input: String): Solution(input) {
override fun run() {
val splitInput = input.split("\n")
val xToExpand = mutableListOf<Int>()
val yToExpand = mutableListOf<Int>()
splitInput.forEachIndexed { index, s ->
... | 0 | Kotlin | 0 | 0 | f7b2e020f23ec0e5ecaeb97885f6521f7a903238 | 2,024 | advent-of-code | MIT License |
src/cn/leetcode/codes/simple94/Simple94.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple94
import cn.leetcode.codes.common.TreeNode
import cn.leetcode.codes.createTreeNode
import cn.leetcode.codes.out
import java.util.*
import kotlin.collections.ArrayList
fun main() {
val nums = arrayOf<Int?>(1,2)
val treeNode = createTreeNode(nums)
val re = inorderTraversal(... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 1,947 | LeetCodeSimple | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ParallelCourses3.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,216 | kotlab | Apache License 2.0 |
src/Day03.kt | adrianforsius | 573,044,406 | false | {"Kotlin": 68131} | import org.assertj.core.api.Assertions.assertThat
fun code(it: Char): Int = when (it) {
in 'a'..'z' -> it - 'a' + 1
in 'A'..'Z' -> it - 'A' + 27
else -> throw error("nope")
}
fun main() {
fun part1(input: List<String>): Int = input.map{
it.split("\n")
listOf(it.substring(0, it... | 0 | Kotlin | 0 | 0 | f65a0e4371cf77c2558d37bf2ac42e44eeb4bdbb | 1,273 | kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem1161/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1161
import com.hj.leetcode.kotlin.common.model.TreeNode
/**
* LeetCode page: [1161. Maximum Level Sum of a Binary Tree](https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(H) where N and H are ... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,368 | hj-leetcode-kotlin | Apache License 2.0 |
src/chapter4/section4/ex20.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter4.section4
import edu.princeton.cs.algs4.In
import edu.princeton.cs.algs4.Queue
import extensions.formatDouble
import extensions.spendTimeMillis
import kotlin.math.E
import kotlin.math.ln
import kotlin.math.min
import kotlin.math.pow
/**
* 从网上或者报纸上找到一张汇率表并用它构造一张套汇表。
* 注意:不要使用根据若干数据计算得出的汇率表,它们的精度有限。
... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 3,011 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/main/kotlin/nl/jackploeg/aoc/_2022/calendar/day07/Day07.kt | jackploeg | 736,755,380 | false | {"Kotlin": 318734} | package nl.jackploeg.aoc._2022.calendar.day07
import javax.inject.Inject
import nl.jackploeg.aoc.generators.InputGenerator.InputGeneratorFactory
import nl.jackploeg.aoc.utilities.readStringFile
class Day07 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
fun partOne(filename: Stri... | 0 | Kotlin | 0 | 0 | f2b873b6cf24bf95a4ba3d0e4f6e007b96423b76 | 3,462 | advent-of-code | MIT License |
src/main/kotlin/com/github/vqvu/eulerproject/Problem9.kt | vqvu | 57,861,531 | false | null | package com.github.vqvu.eulerproject
import java.util.ArrayList
/**
* @author victor
*/
fun main(args: Array<String>) {
// The following properties from https://en.wikipedia.org/wiki/Pythagorean_triple#Elementary_properties_of_primitive_Pythagorean_triples are used.
// - Exactly one of a, b is odd
// ... | 0 | Kotlin | 0 | 0 | 1163894f462045060eda763b3040c0bbb1a68e30 | 2,154 | euler-project | MIT License |
Algorithm/coding_interviews/Kotlin/Questions55.kt | ck76 | 314,136,865 | false | {"HTML": 1420929, "Java": 723214, "JavaScript": 534260, "Python": 437495, "CSS": 348978, "C++": 348274, "Swift": 325819, "Go": 310456, "Less": 203040, "Rust": 105712, "Ruby": 96050, "Kotlin": 88868, "PHP": 67753, "Lua": 52032, "C": 30808, "TypeScript": 23395, "C#": 4973, "Elixir": 4945, "Pug": 1853, "PowerShell": 471, ... | package com.qiaoyuang.algorithm
import kotlin.math.abs
import kotlin.math.max
fun main() {
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.mLeft = b
a.mRight = c
b.mLeft = ... | 0 | HTML | 0 | 2 | 2a989fe85941f27b9dd85b3958514371c8ace13b | 1,544 | awesome-cs | Apache License 2.0 |
src/main/kotlin/g0501_0600/s0542_01_matrix/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0501_0600.s0542_01_matrix
// #Medium #Array #Dynamic_Programming #Breadth_First_Search #Matrix
// #Algorithm_I_Day_9_Breadth_First_Search_Depth_First_Search
// #Graph_Theory_I_Day_5_Matrix_Related_Problems
// #2023_01_17_Time_441_ms_(94.06%)_Space_54_MB_(78.22%)
class Solution {
fun updateMatrix(mat: Arr... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,399 | LeetCode-in-Kotlin | MIT License |
aoc2023/src/main/kotlin/de/havox_design/aoc2023/day11/CosmicExpansion.kt | Gentleman1983 | 737,309,232 | false | {"Kotlin": 746488, "Java": 441473, "Scala": 33415, "Groovy": 5725, "Python": 3319} | package de.havox_design.aoc2023.day11
import de.havox_design.aoc.utils.kotlin.model.positions.Position2d
import kotlin.math.abs
class CosmicExpansion(private var filename: String) {
private val ICON_GALAXY = "#"
fun solvePart1(): Long =
processSumOfAllDistances(getResourceAsText(filename))
fun s... | 4 | Kotlin | 0 | 1 | 35ce3f13415f6bb515bd510a1f540ebd0c3afb04 | 2,774 | advent-of-code | Apache License 2.0 |
Kotlin/src/main/kotlin/org/algorithm/problems/0008_array_nesting.kt | raulhsant | 213,479,201 | true | {"C++": 1035543, "Kotlin": 114509, "Java": 27177, "Python": 16568, "Shell": 999, "Makefile": 187} | // Proble Statement
//
// A zero-indexed array A of length N contains all integers from 0 to N-1.
// Find and return the longest length of set S,
// where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule below.
//
// Suppose the first element in S starts with the selection of element A[i]
// of index = i,... | 0 | C++ | 0 | 0 | 1578a0dc0a34d63c74c28dd87b0873e0b725a0bd | 1,572 | algorithms | MIT License |
src/main/kotlin/kr/co/programmers/P154540.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
// https://github.com/antop-dev/algorithm/issues/465
class P154540 {
fun solution(maps: Array<String>): IntArray {
val box = maps.map { StringBuilder(it) }
val answer = mutableListOf<Int>()
// DFS
for (y in box.indices) {
for (x in box[y].indice... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,050 | algorithm | MIT License |
src/Day02.kt | raneric | 573,109,642 | false | {"Kotlin": 13043} | const val WIN_SCORE = 6
const val DRAW_SCORE = 3
const val ROCK_SCORE = 1
const val PAPER_SCORE = 2
const val SCISSOR_SCORE = 3
fun main() {
fun part1(input: List<String>): Int {
return input.sumOf { it.checkScore() }
}
fun part2(input: List<String>): Int {
return input.sumOf { it.simulate... | 0 | Kotlin | 0 | 0 | 9558d561b67b5df77c725bba7e0b33652c802d41 | 1,983 | aoc-kotlin-challenge | Apache License 2.0 |
src/main/kotlin/days/aoc2020/Day1.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2020
import days.Day
class Day1 : Day(2020, 1) {
override fun partOne(): Any {
return pairs(inputList.map { it.toInt() })
.filter { (one, two) -> one + two == 2020 }
.map { (one, two) -> one * two }
.first()
}
override fun partTwo()... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 1,056 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
exercises/practice/minesweeper/src/main/kotlin/Minesweeper.kt | Uberts94 | 470,116,778 | true | {"Kotlin": 440843, "Shell": 13575} | data class MinesweeperBoard(val inputBoard: List<String>) {
fun withNumbers(): List<String> =
inputBoard.mapIndexed { row, str ->
str.mapIndexed { col, cell -> when (cell) {
'.' -> adjacentMines(row, col)
else -> cell
}
}.joinToString("")
... | 0 | Kotlin | 0 | 0 | ce5467556e3bb4b0e250011a0a26cbaf63f2bc62 | 1,104 | kotlin | MIT License |
src/main/kotlin/com/colinodell/advent2016/Day07.kt | colinodell | 495,627,767 | false | {"Kotlin": 80872} | package com.colinodell.advent2016
class Day07(private val input: List<String>) {
fun solvePart1() = input.map(::IPv7).count { it.supportsTLS() }
fun solvePart2() = input.map(::IPv7).count { it.supportsSSL() }
private class IPv7(ip: String) {
private val supernets = Regex("(?<!\\[)[a-z]+(?=\\[|$)")... | 0 | Kotlin | 0 | 0 | 8a387ddc60025a74ace8d4bc874310f4fbee1b65 | 1,168 | advent-2016 | Apache License 2.0 |
src/Day05.kt | er453r | 572,440,270 | false | {"Kotlin": 69456} | fun main() {
val inputLineRegex = """move (\d+) from (\d+) to (\d+)""".toRegex()
fun partX(input: List<String>, moveLogic: (List<ArrayDeque<Char>>, Int, Int, Int) -> Unit): String {
val stacks = List(9) { ArrayDeque<Char>() }
for (line in input) {
if (line.contains('[')) {
... | 0 | Kotlin | 0 | 0 | 9f98e24485cd7afda383c273ff2479ec4fa9c6dd | 1,503 | aoc2022 | Apache License 2.0 |
src/Day01.kt | wmichaelshirk | 573,031,182 | false | {"Kotlin": 19037} | fun main() {
fun part1(input: List<String>): Int {
val elfRations = input
.joinToString(",")
.split(",,")
.map {
it.split(',').sumOf { n -> n.toInt() }
}
return elfRations.max()
}
fun part2(input: List<String>): Int {
v... | 0 | Kotlin | 0 | 2 | b748c43e9af05b9afc902d0005d3ba219be7ade2 | 833 | 2022-Advent-of-Code | Apache License 2.0 |
src/main/kotlin/de/dikodam/calendar/Day02.kt | dikodam | 433,719,746 | false | {"Kotlin": 51383} | package de.dikodam.calendar
import de.dikodam.AbstractDay
import de.dikodam.Coordinates2D
import de.dikodam.calendar.CommandType.*
import de.dikodam.executeTasks
import kotlin.time.ExperimentalTime
@ExperimentalTime
fun main() {
Day02().executeTasks()
}
class Day02 : AbstractDay() {
val input = readInputLine... | 0 | Kotlin | 0 | 1 | 4934242280cebe5f56ca8d7dcf46a43f5f75a2a2 | 2,223 | aoc-2021 | MIT License |
src/Day09.kt | iownthegame | 573,926,504 | false | {"Kotlin": 68002} | import kotlin.math.abs
import kotlin.math.max
fun main() {
fun moveHeadPos(direction: String, knotPos: Array<Int>): Array<Int> {
// println("move knot ${knotPos.joinToString(", ")} with direction $direction")
when (direction) {
"U" -> knotPos[0] += 1
"D" -> knotPos[0] -= 1
... | 0 | Kotlin | 0 | 0 | 4e3d0d698669b598c639ca504d43cf8a62e30b5c | 4,216 | advent-of-code-2022 | Apache License 2.0 |
leetcode/src/daily/mid/Q856.kt | zhangweizhe | 387,808,774 | false | null | package daily.mid
import java.util.*
fun main() {
// 856. 括号的分数
// https://leetcode.cn/problems/score-of-parentheses/
println(scoreOfParentheses("(()(()))"))
}
fun scoreOfParentheses(s: String): Int {
// 影响分数的,只有(),至于一对()能贡献多少分数,要看它位于第几层
// 如 (()) ,()位于第二层,根据题意,可以贡献 1*2 = 2 分
// ((())) ,() 位于... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,349 | kotlin-study | MIT License |
src/Day05.kt | allwise | 574,465,192 | false | null | import java.io.File
fun main() {
fun part1(input: List<String>): String {
val stacks = Stacking(input)
return stacks.process()
}
fun part2(input: List<String>): String {
val stacks = Stacking(input)
return stacks.process2()
}
// test if implementation meets crite... | 0 | Kotlin | 0 | 0 | 400fe1b693bc186d6f510236f121167f7cc1ab76 | 3,287 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/SequentialDigits.kt | Codextor | 453,514,033 | false | {"Kotlin": 26975} | /**
* An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
*
* Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
*
*
*
* Example 1:
*
* Input: low = 100, high = 300
* Output: [123,234]
* Example 2:... | 0 | Kotlin | 1 | 0 | 68b75a7ef8338c805824dfc24d666ac204c5931f | 1,443 | kotlin-codes | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/sorts/HeapSort.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <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,891 | kotlab | Apache License 2.0 |
src/problemOfTheDay/problem169_MergeSort/problem196_MergeSort.kt | cunrein | 159,861,371 | false | null | package problemOfTheDay.problem169_MergeSort
data class Node<T : Comparable<T>>(val value: T, var next: Node<T>? = null)
class LinkedList<T : Comparable<T>>(var head: Node<T>?) {
fun push(new_data: T) {
/* allocate node */
val newNode = Node<T>(new_data)
/* link the old list off the new ... | 0 | Kotlin | 0 | 0 | 3488ccb200f993a84f1e9302eca3fe3977dbfcd9 | 2,501 | ProblemOfTheDay | Apache License 2.0 |
src/days/Day07.kt | EnergyFusion | 572,490,067 | false | {"Kotlin": 48323} | import java.io.BufferedReader
fun main() {
val day = 7
fun getDirMap(inputReader: BufferedReader): Map<String, Int> {
val dirMap = mutableMapOf("/" to 0)
val directoryStack = ArrayDeque<String>()
var currentDir = "/"
var lineNum = 0
inputReader.forEachLine { line ->
... | 0 | Kotlin | 0 | 0 | 06fb8085a8b1838289a4e1599e2135cb5e28c1bf | 2,634 | advent-of-code-kotlin | Apache License 2.0 |
year2020/day07/part2/src/main/kotlin/com/curtislb/adventofcode/year2020/day07/part2/Year2020Day07Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Part Two ---
It's getting pretty expensive to fly these days - not because of ticket prices, but because of the
ridiculous number of bags you need to buy!
Consider again your shiny gold bag and the rules from the above example:
- faded blue bags contain 0 other bags.
- dotted black bags contain 0 other bags.
... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 1,960 | AdventOfCode | MIT License |
tool/shard/calculate/src/main/kotlin/flank/shard/Internal.kt | Flank | 84,221,974 | false | {"Kotlin": 1748173, "Java": 101254, "Swift": 41229, "Shell": 10674, "Objective-C": 10006, "Dart": 9705, "HTML": 7235, "Gherkin": 4210, "TypeScript": 2717, "Ruby": 2272, "JavaScript": 1764, "SCSS": 1365, "Batchfile": 1183, "EJS": 1061, "Go": 159} | package flank.shard
import kotlin.math.min
// Stage 1
/**
* Create flat and easy to iterate list of [Chunk] without losing info about app and test related to test case.
* @receiver The [List] of [Shard.App].
* @return The [List] of [Chunk] which is just different representation of input data.
*/
internal fun Lis... | 50 | Kotlin | 121 | 658 | e63c612af38a71fbe563a3f6c12192cc91cb3b9a | 3,158 | flank | Apache License 2.0 |
kotlin/src/com/s13g/aoc/aoc2021/Day19.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2021
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import kotlin.math.abs
import kotlin.math.max
/**
* --- Day 19: Beacon Scanner ---
* https://adventofcode.com/2021/day/19
*/
class Day19 : Solver {
override fun solve(lines: List<String>): Result {
val scanners = parseInput(li... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 4,834 | euler | Apache License 2.0 |
src/Day04.kt | ked4ma | 573,017,240 | false | {"Kotlin": 51348} | import kotlin.math.max
/**
* [Day04](https://adventofcode.com/2022/day/4)
*/
fun main() {
fun rangeToSet(rangeStr: String): Set<Int> = rangeStr.split("-").let { (s, e) ->
IntRange(s.toInt(), e.toInt())
}.toSet()
fun part1(input: List<String>): Int {
return input.filter {
it.s... | 1 | Kotlin | 0 | 0 | 6d4794d75b33c4ca7e83e45a85823e828c833c62 | 1,128 | aoc-in-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DistanceKTree.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 | 5,757 | kotlab | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.