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/ca/josue/solution/src/TaxiParkTask.kt | josue-lubaki | 428,923,506 | false | {"Kotlin": 171443} | package ca.josue.solution.src
import ca.josue.solution.test.passenger
/*
* Task #1. Find all the drivers who performed no trips.
*/
fun TaxiPark.findFakeDrivers(): Set<Driver> =
allDrivers - trips.map{ it.driver}.toSet()
// this.allDrivers.filter { d -> trips.none{ it.driver == d }}.toSet()
/*
* Task #2. Find... | 0 | Kotlin | 0 | 1 | 847f7af8ba9b5712241c36ca3979e4195766b9ab | 3,248 | TaxiPark | Apache License 2.0 |
src/main/kotlin/me/peckb/aoc/_2020/calendar/day21/Day21.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2020.calendar.day21
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
class Day21 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
fun partOne(filename: String) = generatorFactory.forFile(filename).readAs(::food) { in... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 3,650 | advent-of-code | MIT License |
2020/src/main/java/D02.kt | ununhexium | 113,359,669 | false | null | // counts valid passwords
fun day2a(input: List<String>): Int {
return input.count { l ->
val (policy, password) = l.split(':')
val (low, tail) = policy.split('-')
val (high, char) = tail.split(' ')
val freq = password.groupingBy { it }.eachCount()
val charFreq = (freq[char.first()] ?: 0)
(lo... | 6 | Kotlin | 0 | 0 | d5c38e55b9574137ed6b351a64f80d764e7e61a9 | 828 | adventofcode | The Unlicense |
ceria/08/src/main/kotlin/Solution.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File;
val knownDigits = mapOf<Int, Int>(2 to 1, 3 to 7, 4 to 4, 7 to 8)
fun main(args : Array<String>) {
var inputMap = mutableMapOf<String, String>()
File(args.first()).readLines().map {
val input = it.split(" | ")
inputMap.put(input[0], input[1])
}
println("Solution 1... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 4,544 | advent-of-code-2021 | MIT License |
2022/main/day_07/Main.kt | Bluesy1 | 572,214,020 | false | {"Rust": 280861, "Kotlin": 94178, "Shell": 996} | package day_07_2022
import java.io.File
@Suppress("UNCHECKED_CAST")
fun castMapTypes(toCast: Any?): MutableMap<String, Any> = toCast as MutableMap<String, Any>
fun calculateDirSize(dirName: String, dir: Map<String, Any>, dirSizes: MutableMap<String, Int>): Int{
if (dir.values.any { it is MutableMap<*,*> }){
... | 0 | Rust | 0 | 0 | 537497bdb2fc0c75f7281186abe52985b600cbfb | 2,777 | AdventofCode | MIT License |
src/main/kotlin/adventofcode2017/potasz/P08Registers.kt | potasz | 113,064,245 | false | null | package adventofcode2017.potasz
import kotlin.math.max
sealed class Expr<out T>(val reg: String, val number: Int, val op: (Int) -> T) {
fun eval(context: MutableMap<String, Int>): T {
return op(context.getOrDefault(reg, 0))
}
override fun toString(): String {
return "${this.javaClass.simp... | 0 | Kotlin | 0 | 1 | f787d9deb1f313febff158a38466ee7ddcea10ab | 3,092 | adventofcode2017 | Apache License 2.0 |
src/Day02.kt | daividssilverio | 572,944,347 | false | {"Kotlin": 10575} | import java.lang.Exception
fun main() {
/*
scoring
win = 6
lose = 0
draw = 3
initial strategy (wrong)
A, X = Rock (1)
B, Y = Paper (2)
C, Z = Scissors (3)
actual strategy
X = lose
Y = draw
Z = win
*/
val entries = readInput("Day02_test")
val wronglyCa... | 0 | Kotlin | 0 | 0 | 141236c67fe03692785e0f3ab90248064a1693da | 1,624 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/jacobhyphenated/advent2022/day15/Day15.kt | jacobhyphenated | 573,603,184 | false | {"Kotlin": 144303} | package com.jacobhyphenated.advent2022.day15
import com.jacobhyphenated.advent2022.Day
import kotlin.math.absoluteValue
/**
* Day 15: Beacon Exclusion Zone
*
* There are a number of beacons. You have sensors that can show the beacon locations.
* Each sensor knows its own location as well as the closest beacon to ... | 0 | Kotlin | 0 | 0 | 9f4527ee2655fedf159d91c3d7ff1fac7e9830f7 | 4,923 | advent2022 | The Unlicense |
src/main/kotlin/days/day7/Day7.kt | Stenz123 | 725,707,248 | false | {"Kotlin": 123279, "Shell": 862} | package days.day7
import days.Day
class Day7 : Day(false) {
override fun partOne(): Any {
val hands: MutableMap<Hand, Int> = readInput().map { line ->
val cards = line.split(" ")[0].map { Card(it) }
val hand = Hand(cards)
hand to line.split(" ")[1].toInt()
}.to... | 0 | Kotlin | 1 | 0 | 3de47ec31c5241947d38400d0a4d40c681c197be | 12,356 | advent-of-code_2023 | The Unlicense |
src/twentytwo/Day01.kt | mihainov | 573,105,304 | false | {"Kotlin": 42574} | package twentytwo
import readInputTwentyTwo
import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
var maxSum: Int = -1
var tempSum = 0
input.forEach { inputString ->
if (inputString.isBlank()) {
maxSum = max(tempSum, maxSum)
t... | 0 | Kotlin | 0 | 0 | a9aae753cf97a8909656b6137918ed176a84765e | 1,269 | kotlin-aoc-1 | Apache License 2.0 |
day04/src/main/kotlin/Main.kt | rstockbridge | 225,212,001 | false | null | fun main() {
println("Part I: the solution is ${solvePartI()}.")
println("Part II: the solution is ${solvePartII()}.")
}
fun solvePartI(): Int {
var result = 0
for (password in Range.lowerBound..Range.upperBound) {
if (isValidPartI(password)) {
result++
}
}
return ... | 0 | Kotlin | 0 | 0 | bcd6daf81787ed9a1d90afaa9646b1c513505d75 | 2,100 | AdventOfCode2019 | MIT License |
src/main/kotlin/aoc2015/day05_intern_elves/InternElves.kt | barneyb | 425,532,798 | false | {"Kotlin": 238776, "Shell": 3825, "Java": 567} | package aoc2015.day05_intern_elves
fun main() {
util.solve(236, ::partOne)
util.solve(51, ::partTwo)
}
private fun String.isNice(): Boolean {
var vowelCount = 0
var prev = '\u0000'
var double = false
forEach { c ->
when (c) {
'a', 'e', 'i', 'o', 'u' -> ++vowelCount
... | 0 | Kotlin | 0 | 0 | a8d52412772750c5e7d2e2e018f3a82354e8b1c3 | 967 | aoc-2021 | MIT License |
kotlin/structures/RTree.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package structures
// https://en.wikipedia.org/wiki/R-tree
class RTree(segments: Array<Segment?>) {
class Segment(val x1: Int, val y1: Int, val x2: Int, val y2: Int)
val x1: IntArray
val y1: IntArray
val x2: IntArray
val y2: IntArray
val minx: IntArray
val maxx: IntArray
val miny: IntA... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 6,780 | codelibrary | The Unlicense |
kotlin/src/com/s13g/aoc/aoc2023/Day4.kt | shaeberling | 50,704,971 | false | {"Kotlin": 300158, "Go": 140763, "Java": 107355, "Rust": 2314, "Starlark": 245} | package com.s13g.aoc.aoc2023
import com.s13g.aoc.Result
import com.s13g.aoc.Solver
import com.s13g.aoc.resultFrom
import com.s13g.aoc.`**`
/**
* --- Day 4: Scratchcards ---
* https://adventofcode.com/2023/day/4
*/
class Day4 : Solver {
override fun solve(lines: List<String>): Result {
val cards = lines.map ... | 0 | Kotlin | 1 | 2 | 7e5806f288e87d26cd22eca44e5c695faf62a0d7 | 1,363 | euler | Apache License 2.0 |
src/main/kotlin/cloud/dqn/leetcode/Permutations2Kt.kt | aviuswen | 112,305,062 | false | null | package cloud.dqn.leetcode
/**
* https://leetcode.com/problems/permutations-ii/description/
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,
[1,1,2] have the following unique permutations:
[
[1,1,2],
[1,2,1],
[2,1,1]
... | 0 | Kotlin | 0 | 0 | 23458b98104fa5d32efe811c3d2d4c1578b67f4b | 2,259 | cloud-dqn-leetcode | No Limit Public License |
solutions/aockt/y2021/Y2021D19.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
import kotlin.math.absoluteValue
object Y2021D19 : Solution {
/** Represents a discrete point in 3D space. */
private data class Point(val x: Int, val y: Int, val z: Int)
private operator fun Point.minus(other: Point): Point = Point(x - ot... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 5,837 | advent-of-code-kotlin-solutions | The Unlicense |
src/com/freaklius/kotlin/algorithms/sort/RadixSort.kt | vania-pooh | 8,736,623 | false | null | package com.freaklius.kotlin.algorithms.sort
import java.util.LinkedList
/**
* Radix sort algorithm
* Assumption: all sorted values has the same number of digits.
* Average performance = O(n + k), where k is a number of digits
*/
class RadixSort : SortAlgorithm {
override fun sort(arr: Array<Long>): Array<Lo... | 1 | Kotlin | 14 | 51 | 8c5e7b52d2831322d578af895cd4e80fbe471950 | 2,482 | kotlin-algorithms | MIT License |
src/main/kotlin/week1/Rucksack.kt | waikontse | 572,850,856 | false | {"Kotlin": 63258} | package week1
import shared.Puzzle
class Rucksack : Puzzle(3) {
override fun solveFirstPart(): Any {
return puzzleInput
.map { splitRucksack(it) }
.map { it.map { charArray -> charArray.toSet() } }
.map { getMisplacedSnackType(it, 2) }
.sumOf { snackToPoint(... | 0 | Kotlin | 0 | 0 | 860792f79b59aedda19fb0360f9ce05a076b61fe | 1,195 | aoc-2022-in-kotllin | Creative Commons Zero v1.0 Universal |
src/Day06.kt | jaldhar | 573,188,501 | false | {"Kotlin": 14191} | fun List<Char>.isUnique(): Boolean {
return this.distinct().size == this.size
}
fun List<Char>.search(length: Int): Int {
for (chunk in this.windowed(length).withIndex()) {
if (chunk.value.isUnique()) {
return chunk.index + length
}
}
return 0
}
fun main() {
fun part1... | 0 | Kotlin | 0 | 0 | b193df75071022cfb5e7172cc044dd6cff0f6fdf | 766 | aoc2022-kotlin | Apache License 2.0 |
src/array/LeetCode384.kt | Alex-Linrk | 180,918,573 | false | null | package array
import java.util.concurrent.ThreadLocalRandom
import kotlin.random.Random
/**
* 打乱一个没有重复元素的数组。
示例:
// 以数字集合 1, 2 和 3 初始化数组。
int[] nums = {1,2,3};
Solution solution = new Solution(nums);
// 打乱数组 [1,2,3] 并返回结果。任何 [1,2,3]的排列返回的概率应该相同。
solution.shuffle();
// 重设数组到它的初始状态[1,2,3]。
solution.reset();
// 随机... | 0 | Kotlin | 0 | 0 | 59f4ab02819b7782a6af19bc73307b93fdc5bf37 | 1,650 | LeetCode | Apache License 2.0 |
2021/src/day02/day2.kt | scrubskip | 160,313,272 | false | {"Kotlin": 198319, "Python": 114888, "Dart": 86314} | package day02
import java.io.File
fun main() {
// println(testSample())
println(readFile("day2.txt"))
}
fun testSample(): Int {
val (depth, distance) =
moveSubWithAim(
listOf("forward 5", "down 5", "forward 8", "up 3", "down 8", "forward 2")
)
return depth... | 0 | Kotlin | 0 | 0 | a5b7f69b43ad02b9356d19c15ce478866e6c38a1 | 1,583 | adventofcode | Apache License 2.0 |
logicsolver/src/test/kotlin/nl/hiddewieringa/logicsolver/SudokuIntegrationTest.kt | hiddewie | 147,922,971 | false | null | package nl.hiddewieringa.logicsolver
import org.junit.Assert.assertEquals
import org.junit.Test
class SudokuIntegrationTest {
@Test
fun solveAlreadySolvedSudoku() {
val coordinates = (1..9).flatMap { i ->
(1..9).map { j ->
Coordinate(i, j)
}
}
v... | 0 | Kotlin | 0 | 0 | bcf12c102f4ab77c5aa380dbf7c98a1cc3e585c0 | 6,856 | LogicSolver | MIT License |
src/Day01.kt | StephenVinouze | 572,377,941 | false | {"Kotlin": 55719} | fun main() {
fun caloriesPerEfl(input: List<String>): List<Int> {
var caloriesPerElf = 0
val elfCalories = mutableListOf<Int>()
input.forEachIndexed { index, calories ->
when {
calories.isBlank() -> {
elfCalories.add(caloriesPerElf)
... | 0 | Kotlin | 0 | 0 | 11b9c8816ded366aed1a5282a0eb30af20fff0c5 | 1,112 | AdventOfCode2022 | Apache License 2.0 |
src/Day01.kt | mpythonite | 572,671,910 | false | {"Kotlin": 29542} | fun main() {
fun part1(input: List<String>): Int {
var currentCalories = 0
var maxCalories = 0
for (i in input.indices)
{
if (input[i].isBlank())
{
if (currentCalories > maxCalories) {
maxCalories = currentCalories
... | 0 | Kotlin | 0 | 0 | cac94823f41f3db4b71deb1413239f6c8878c6e4 | 1,448 | advent-of-code-2022 | Apache License 2.0 |
16117/solution.kt | daily-boj | 253,815,781 | false | null | fun main(args: Array<out String>) {
val (height, width) = readLine()!!.split(" ").map { it.toInt() }
val realMap = List(height * 2) {
if (it % 2 == 0) {
List(width * 2) { 0L }
} else {
readLine()!!.split(" ").flatMap { listOf(0L, it.toLong()) }
}
}
fun ge... | 0 | Rust | 0 | 12 | 74294a4628e96a64def885fdcdd9c1444224802c | 1,140 | RanolP | The Unlicense |
app/src/main/kotlin/day11/Day11.kt | W3D3 | 572,447,546 | false | {"Kotlin": 159335} | package day11
import com.github.keelar.exprk.Expressions
import common.InputRepo
import common.readSessionCookie
import common.solve
import util.split
import java.math.BigInteger
data class MonkeyTest(val divisor: Int, val positive: Int, val negative: Int)
data class Monkey(
val id: Int,
val items: MutableLis... | 0 | Kotlin | 0 | 0 | 34437876bf5c391aa064e42f5c984c7014a9f46d | 4,459 | AdventOfCode2022 | Apache License 2.0 |
src/Day08/Day08.kt | G-lalonde | 574,649,075 | false | {"Kotlin": 39626} | package Day08
import readInput
import kotlin.math.max
fun main() {
fun buildMatrix(treeMatrix: Matrix, input: List<String>) {
for ((i, line) in input.withIndex()) {
for ((j, v) in line.withIndex()) {
treeMatrix[i, j] = v.digitToInt()
}
}
}
fun part1... | 0 | Kotlin | 0 | 0 | 3463c3228471e7fc08dbe6f89af33199da1ceac9 | 7,729 | aoc-2022 | Apache License 2.0 |
src.kt | Sladernom | 653,728,520 | false | null | package cinema
var totalIncome = 0
fun setupCinema(): Pair<Int, Int> {
println("Enter the number of rows:")
val numRows: Int = readln()!!.toInt()
println("Enter the number of seats in each row:")
val seatsInRow: Int = readln()!!.toInt()
return Pair(numRows, seatsInRow)
}
fun printCinema(topList: ... | 0 | Kotlin | 0 | 0 | 90d3400445ad2c139d42299eef50f57bf3e1eb2b | 2,817 | Hyperskill-Cinema-Project | MIT License |
src/day01/Day01.kt | jacobprudhomme | 573,057,457 | false | {"Kotlin": 29699} | import java.io.File
fun main() {
fun readInput(name: String) = File("src/day01", name)
.readLines()
fun part1(input: List<String>): Int {
var maxSoFar = 0
var currentSum = 0
for (line in input) {
if (line.isEmpty()) {
if (currentSum > maxSoFar) {
... | 0 | Kotlin | 0 | 1 | 9c2b080aea8b069d2796d58bcfc90ce4651c215b | 1,410 | advent-of-code-2022 | Apache License 2.0 |
src/adventofcode/blueschu/y2017/day13/solution.kt | blueschu | 112,979,855 | false | null | package adventofcode.blueschu.y2017.day13
import java.io.File
import kotlin.test.assertEquals
val input: List<String> by lazy {
File("resources/y2017/day13.txt")
.bufferedReader()
.use { r -> r.readLines() }
}
fun main(args: Array<String>) {
val exampleFirewall = listOf(
"0: 3",
... | 0 | Kotlin | 0 | 0 | 9f2031b91cce4fe290d86d557ebef5a6efe109ed | 1,460 | Advent-Of-Code | MIT License |
server/src/main/kotlin/models/LongestRouteManager.kt | jaydenmilne | 165,130,222 | false | {"HTML": 614644, "TypeScript": 160418, "Kotlin": 128363, "SCSS": 12884, "Java": 5447, "JavaScript": 1732, "Dockerfile": 569} | package models
import java.io.Serializable
import commands.CommandException
import commands.UpdatePlayerCommand
import kotlin.system.measureTimeMillis
class LongestRouteManager(private val game: Game): Serializable {
// Player id of the player who last got the longest route
private var currentPlayerWithLonges... | 11 | HTML | 11 | 1 | 29e1d056ec02757bc1725fbbe843e9ef4ffdd004 | 5,319 | CS340 | MIT License |
src/main/kotlin/days/aoc2015/Day9.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2015
import days.Day
class Day9: Day(2015, 9) {
override fun partOne(): Any {
val segments: MutableList<Segment> = mutableListOf()
val startingPoints: MutableSet<Location> = mutableSetOf()
val destinations: MutableSet<Location> = mutableSetOf()
val locations: Mutabl... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 6,193 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/richodemus/advent_of_code/two_thousand_sixteen/day3_triangles/Main.kt | RichoDemus | 75,489,317 | false | null | package com.richodemus.advent_of_code.two_thousand_sixteen.day3_triangles
import com.richodemus.advent_of_code.two_thousand_sixteen.toFile
import java.util.*
fun main(args: Array<String>) {
val validTriangles = "day3/triangles.txt".toFile().readLines().map(::Triangle).filter { it.valid() }.count()
println("Th... | 0 | Kotlin | 0 | 0 | 32655174f45808eb1530f00c4c49692310036395 | 1,665 | advent-of-code | Apache License 2.0 |
2020/day21/day21.kt | flwyd | 426,866,266 | false | {"Julia": 207516, "Elixir": 120623, "Raku": 119287, "Kotlin": 89230, "Go": 37074, "Shell": 24820, "Makefile": 16393, "sed": 2310, "Jsonnet": 1104, "HTML": 398} | /*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/
package day21
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource
import kotlin.time.measureTimedValue
/* Input: l... | 0 | Julia | 1 | 5 | f2d6dbb67d41f8f2898dbbc6a98477d05473888f | 3,760 | adventofcode | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1129/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1129
/**
* LeetCode page: [1129. Shortest Path with Alternating Colors](https://leetcode.com/problems/shortest-path-with-alternating-colors/);
*/
class Solution {
/* Complexity:
* Time O(n + e) and Space (e) where e is the sum of redEdges' size and blueEdges' size;
... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,214 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/TwoOutOfThree.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,016 | kotlab | Apache License 2.0 |
src/main/kotlin/day04/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day04
import java.io.File
fun main() {
var drawnNumbers: List<Int> = listOf()
var bingoBoards: List<BingoBoard> = listOf()
File("src/main/kotlin/day04/input.txt").useLines { seq ->
val iterator = seq.iterator()
drawnNumbers = List(1) { iterator.next() }.single().split(",").map { it... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 2,060 | aoc-2021 | MIT License |
src/main/kotlin/days/Solution13.kt | Verulean | 725,878,707 | false | {"Kotlin": 62395} | package days
import adventOfCode.InputHandler
import adventOfCode.Solution
import adventOfCode.util.PairOf
import kotlin.math.min
object Solution13 : Solution<List<CharGrid>>(AOC_YEAR, 13) {
override fun getInput(handler: InputHandler) = handler.getInput("\n\n")
.map { it.split('\n').map(String::toCharArr... | 0 | Kotlin | 0 | 1 | 99d95ec6810f5a8574afd4df64eee8d6bfe7c78b | 1,336 | Advent-of-Code-2023 | MIT License |
backend/src/main/kotlin/Verifier.kt | lounres | 448,685,049 | true | {"Kotlin": 75138, "JavaScript": 2316, "HTML": 1022} | import java.lang.Integer.max
import java.lang.Integer.min
operator fun Coords.minus(other: Coords): Coords {
return Coords(this.row - other.row, this.column - other.column)
}
fun Coords.norm(): Int {
return this.row * this.row + this.column * this.column
}
infix fun Coords.cross(other: Coords): Int {
ret... | 0 | null | 0 | 0 | b11b94347644c8f2a03e585f862f538a22d95ae9 | 2,298 | KotlinLine | MIT License |
src/main/kotlin/org/deafsapps/adventofcode/day01/part02/Main.kt | pablodeafsapps | 733,033,603 | false | {"Kotlin": 6685} | package org.deafsapps.adventofcode.day01.part02
import org.deafsapps.adventofcode.day01.part01.concatFirstAndLastDigit
import java.io.File
import java.util.Scanner
fun main() {
val input = Scanner(File("src/main/resources/day01-data.txt"))
val digitsList = mutableListOf<Int>()
while (input.hasNext()) {
... | 0 | Kotlin | 0 | 0 | 3a7ea1084715ab7c2ab1bfa8a1a7e357aa3c4b40 | 1,535 | advent-of-code_2023 | MIT License |
src/problems/day1/dayone.kt | klnusbaum | 733,782,662 | false | {"Kotlin": 43060} | package problems.day1
import java.io.File
private const val calibrationValues = "input/day1/calibration_values.txt"
fun main() {
part1()
part2()
}
private fun part1() {
val sum = File(calibrationValues)
.bufferedReader()
.useLines { sumLines(it) }
println("Sum of values is $sum")
}
... | 0 | Kotlin | 0 | 0 | d30db2441acfc5b12b52b4d56f6dee9247a6f3ed | 1,421 | aoc2023 | MIT License |
src/main/kotlin/string/IsNumer.kt | ghonix | 88,671,637 | false | null | package string
/**
* https://leetcode.com/problems/valid-number/description/
*/
class IsNumer {
enum class TokenType {
DIGIT,
SIGN,
DOT,
EXPONENT,
INVALID
}
private val dfa = hashMapOf(
Pair(0, hashMapOf(Pair(TokenType.DIGIT, 1), Pair(TokenType.SIGN, 2), P... | 0 | Kotlin | 0 | 2 | 25d4ba029e4223ad88a2c353a56c966316dd577e | 2,794 | Problems | Apache License 2.0 |
src/main/kotlin/year2022/Day20.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2022
import utils.nextIndexOf
import utils.prevIndexOf
class Day20(input: String) {
private val numbers = input.lines().map(String::toLong)
inner class Node(val value: Long) {
var prev: Node? = null
var next: Node? = null
fun shift() {
val shift = value.mod(nu... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 1,407 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/AlienDictionary.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 6,239 | kotlab | Apache License 2.0 |
shared/src/commonMain/kotlin/io/github/andremion/slidingpuzzle/domain/puzzle/PuzzleState.kt | andremion | 750,744,594 | false | {"Kotlin": 62332, "Swift": 659} | package io.github.andremion.slidingpuzzle.domain.puzzle
import kotlin.math.sqrt
data class PuzzleState @Throws(IllegalArgumentException::class) constructor(
val tiles: List<Int>
) {
data class TilePosition(
val row: Int,
val column: Int
)
val matrixSize = sqrt(tiles.size.toDouble()).... | 0 | Kotlin | 0 | 0 | 8f8b9c40b5e1e212fd99fd71e4f2a5f1ce63bf6c | 2,936 | SlidingPuzzle | Apache License 2.0 |
src/day03/Day03.kt | Ciel-MC | 572,868,010 | false | {"Kotlin": 55885} | package day03
import readInput
fun main() {
val charToIntMap =
(('a'..'z') + ('A'..'Z')).withIndex().associate { (i, c) -> c to i + 1 }
fun Char.charToInt(): Int {
return charToIntMap[this]!!
}
fun part1(input: List<String>): Int {
return input.sumOf {
assert(it.... | 0 | Kotlin | 0 | 0 | 7eb57c9bced945dcad4750a7cc4835e56d20cbc8 | 849 | Advent-Of-Code | Apache License 2.0 |
src/day17/Day17.kt | HGilman | 572,891,570 | false | {"Kotlin": 109639, "C++": 5375, "Python": 400} | package day17
import lib.LeftDirection
import lib.DecreaseYDirection
import lib.Point2D
import lib.RightDirection
import lib.Vector2D
import readText
const val chamberWidth = 7
const val xStart = 2 // from 0 counting
const val yOffsetFromTop = 3
fun main() {
val day = 17
val testInput = readText("day$day/t... | 0 | Kotlin | 0 | 1 | d05a53f84cb74bbb6136f9baf3711af16004ed12 | 11,761 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/wtf/log/xmas2021/day/day12/Day12.kt | damianw | 434,043,459 | false | {"Kotlin": 62890} | package wtf.log.xmas2021.day.day12
import wtf.log.xmas2021.Day
import java.io.BufferedReader
object Day12 : Day<CaveSystem, Int, Int> {
override fun parseInput(reader: BufferedReader): CaveSystem {
return CaveSystem.parse(reader.lineSequence().asIterable())
}
override fun part1(input: CaveSystem... | 0 | Kotlin | 0 | 0 | 1c4c12546ea3de0e7298c2771dc93e578f11a9c6 | 3,881 | AdventOfKotlin2021 | BSD Source Code Attribution |
src/Day09.kt | MerickBao | 572,842,983 | false | {"Kotlin": 28200} | import kotlin.math.abs
fun main() {
fun next(px: Int, py: Int, nx: Int, ny: Int): Array<Int> {
val diff = abs(px - nx) + abs(py - ny)
var x = nx
var y = ny
if (diff == 2) {
if (px == nx) {
if (py > ny) y++
else y--
} else if (p... | 0 | Kotlin | 0 | 0 | 70a4a52aa5164f541a8dd544c2e3231436410f4b | 1,851 | aoc-2022-in-kotlin | Apache License 2.0 |
dcp_kotlin/src/main/kotlin/dcp/day211/day211.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | package dcp.day211
// day211.kt
// By <NAME>, 2019.
fun Char.hash(): Int = this.toInt() - 'a'.toInt() + 1
// Scan windows for substring.
fun findStartPoints(str: String, substr: String): Set<Int> {
require(str.length >= substr.length) { "Main string must be longer than substring" }
val strlen = str.length
... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 1,648 | daily-coding-problem | MIT License |
src/Day01.kt | realpacific | 573,561,400 | false | {"Kotlin": 59236} | fun main() {
fun part1(input: List<String>): Int {
var currentCaloriesSum = 0
var maxCalories = Integer.MIN_VALUE
input.forEach {
if (it.isEmpty()) {
maxCalories = maxOf(maxCalories, currentCaloriesSum)
currentCaloriesSum = 0
} else {
... | 0 | Kotlin | 0 | 0 | f365d78d381ac3d864cc402c6eb9c0017ce76b8d | 1,194 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day2/Day2.kt | alxgarcia | 435,549,527 | false | {"Kotlin": 91398} | package day2
import java.io.File
sealed interface SubmarineActions<out S : SubmarineActions<S>> {
fun moveForward(delta: Int): S
fun goUp(delta: Int): S
fun goDown(delta: Int): S = goUp(-delta)
}
data class Submarine1(val horizontal: Int, val depth: Int): SubmarineActions<Submarine1> {
companion object {
... | 0 | Kotlin | 0 | 0 | d6b10093dc6f4a5fc21254f42146af04709f6e30 | 1,936 | advent-of-code-2021 | MIT License |
src/day10/Day10.kt | easchner | 572,762,654 | false | {"Kotlin": 104604} | package day10
import readInputString
fun main() {
fun part1(input: List<String>): Int {
val cycles = Array(input.size * 2) { 1 }
var currentCycle = 1
var register = 1
for (line in input) {
if (line == "noop") {
currentCycle++
cycles[curr... | 0 | Kotlin | 0 | 0 | 5966e1a1f385c77958de383f61209ff67ffaf6bf | 1,897 | Advent-Of-Code-2022 | Apache License 2.0 |
src/day19/Day19.kt | crmitchelmore | 576,065,911 | false | {"Kotlin": 115199} | package day19
import helpers.ReadFile
class Day19 {
class Blueprint {
val number: Int
val ore: Int
val clay: Int
val obsidian: Pair<Int, Int>
val geode: Pair<Int, Int>
val maxOre: Int
constructor(number: Int, ore: Int, clay: Int, obsidian: Pair<Int, Int>, g... | 0 | Kotlin | 0 | 0 | fd644d442b5ff0d2f05fbf6317c61ee9ce7b4470 | 4,866 | adventofcode2022 | MIT License |
utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/utils/Combinations.kt | UnitTestBot | 480,810,501 | false | {"Kotlin": 6661796, "Java": 2209528, "Python": 223199, "Go": 99696, "C#": 80947, "JavaScript": 42483, "Shell": 15961, "HTML": 8704, "Batchfile": 8586, "Dockerfile": 2057} | package org.utbot.fuzzing.utils
/**
* Enumerates all possible combinations for a given list of maximum numbers of elements for every position.
*
* For any index between 0 and [size] excluded it returns the unique combination as an array with
* values that are between 0 and corresponding maximum number from the `el... | 410 | Kotlin | 37 | 110 | c7f2ac4286b9861485c67ad3b11cd14e2b3ab82f | 4,255 | UTBotJava | Apache License 2.0 |
src/main/kotlin/io/steinh/aoc/day01/Trebuchet.kt | daincredibleholg | 726,426,347 | false | {"Kotlin": 25396} | package io.steinh.aoc.day01
class Trebuchet {
fun String.replace(vararg pairs: Pair<String, String>): String =
pairs.fold(this) { acc, (old, new) -> acc.replace(old, new, ignoreCase = true) }
fun calibrate(input: List<String>): Int {
val transformedStrings = transform(input)
return... | 0 | Kotlin | 0 | 0 | 4aa7c684d0e337c257ae55a95b80f1cf388972a9 | 1,702 | AdventOfCode2023 | MIT License |
src/main/kotlin/se/saidaspen/aoc/aoc2016/Day14.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2016
import se.saidaspen.aoc.util.*
fun main() = Day14.run()
object Day14 : Day(2016, 14) {
override fun part1(): Any {
val salt = input
var i = 0
val keys = mutableSetOf<P<String, Int>>()
val lastThousandHashes = mutableListOf<Triple<String, Char?, In... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 3,307 | adventofkotlin | MIT License |
Algorithm/coding_interviews/Kotlin/Questions48.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
/**
* 一个只包含小写字母的字符串的最大非重复子字符串的长度
*/
fun main() {
val str = "arabcacfr"
println("字符串:$str,最大子字符串的长度是:${longestSubstringWithoutDuplication(str)}")
}
fun longestSubstringWithoutDuplication(str: String): Int {
// 检查字符是否合法
fun Char.isLegal(): Boolean = toInt() in 97..122
// 获取字符在数组中... | 0 | HTML | 0 | 2 | 2a989fe85941f27b9dd85b3958514371c8ace13b | 940 | awesome-cs | Apache License 2.0 |
src/main/kotlin/days/Day7.kt | MisterJack49 | 574,081,723 | false | {"Kotlin": 35586} | package days
class Day7 : Day(7) {
override fun partOne(): Any {
val fileSystem = buildFileSystem()
return fileSystem.getAllDirectories(fileSystem.root)
.filter { it.size <= 100000 }
.sumOf { it.size }
}
override fun partTwo(): Any {
val fileSystem = buildF... | 0 | Kotlin | 0 | 0 | e82699a06156e560bded5465dc39596de67ea007 | 3,479 | AoC-2022 | Creative Commons Zero v1.0 Universal |
src/aoc2022/day15/Day15.kt | svilen-ivanov | 572,637,864 | false | {"Kotlin": 53827} | package aoc2022.day15
import aoc2022.day04.overlap
import com.google.common.collect.Comparators
import readInput
import java.util.*
import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.min
import kotlin.reflect.KClass
val number = "((?:-)?\\d+)"
val regex = Regex("Sensor at x=$number, y=$number:... | 0 | Kotlin | 0 | 0 | 456bedb4d1082890d78490d3b730b2bb45913fe9 | 6,688 | aoc-2022 | Apache License 2.0 |
src/day01/Solution.kt | abhabongse | 576,594,038 | false | {"Kotlin": 63915} | /* Solution to Day 1: Calorie Counting
* https://adventofcode.com/2022/day/1
*/
package day01
import utils.largest
import utils.splitAt
import java.io.File
fun main() {
val fileName =
// "day01_sample.txt"
"day01_input.txt"
val elves = readInput(fileName)
// Part 1: find the most calorie... | 0 | Kotlin | 0 | 0 | 8a0aaa3b3c8974f7dab1e0ad4874cd3c38fe12eb | 1,015 | aoc2022-kotlin | Apache License 2.0 |
src/day01/Day01.kt | LostMekka | 574,697,945 | false | {"Kotlin": 92218} | package day01
import util.readInput
import util.shouldBe
fun main() {
val day = 1
val testInput = readInput(day, testInput = true).parseInput()
part1(testInput) shouldBe 24000
part2(testInput) shouldBe 45000
val input = readInput(day).parseInput()
println("output for part1: ${part1(input)}")
... | 0 | Kotlin | 0 | 0 | 58d92387825cf6b3d6b7567a9e6578684963b578 | 1,113 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/CountTriplets.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
/**
* 1442. 形成两个异或相等数组的三元组数目
*
* 给你一个整数数组 arr 。
*
* 现需要从数组中取三个下标 i、j 和 k ,其中 (0 <= i < j <= k < arr.length) 。
*
* a 和 b 定义如下:
*
* a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
* b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
* 注意:^ 表示 按位异或 操作。
*
* 请返回能够令 a == b 成立的三元组 (i, j , k) ... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 1,773 | daily_algorithm | Apache License 2.0 |
src/day3/day3s.kt | bienenjakob | 573,125,960 | false | {"Kotlin": 53763} | package day3
import inputTextOfDay
import testTextOfDay
private val Char.priority: Int
get() = when (this) {
in 'a'..'z' -> this - 'a' + 1
in 'A'..'Z' -> this - 'A' + 27
else -> error("$this is unknown, check your input!")
}
fun part1s(text: String): Int =
text.lines()
.ma... | 0 | Kotlin | 0 | 0 | 6ff34edab6f7b4b0630fb2760120725bed725daa | 881 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/com/briarshore/aoc2022/day06/TuningTroublePuzzle.kt | steveswing | 579,243,154 | false | {"Kotlin": 47151} | package com.briarshore.aoc2022.day06
import println
import readInput
fun main() {
fun scanForStartPacket(noise: String, expectedIndex: Int): Int {
val startPacket = noise
.asSequence()
.windowed(4, 1)
.filter { it.size == 4 && it.toSet().size == 4 }
.first()... | 0 | Kotlin | 0 | 0 | a0d19d38dae3e0a24bb163f5f98a6a31caae6c05 | 2,475 | 2022-AoC-Kotlin | Apache License 2.0 |
src/Day02.kt | nemethandor | 575,143,939 | false | {"Kotlin": 2854} | // https://adventofcode.com/2022/day/2
private val whoBeatsWho = mapOf("A" to "C", "B" to "A", "C" to "B")
private val pointsForTool = mapOf("X" to 1, "Y" to 2, "Z" to 3)
private val equivalentTools = mapOf("A" to "X", "B" to "Y", "C" to "Z")
fun main() {
fun getGameResult(tactic: String): Int = when (tactic) {
... | 0 | Kotlin | 0 | 0 | 42ce114850d08a741fae3fdd572506fdc3e43a3f | 1,297 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2021/Day13.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2021
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.Pos
import com.chriswk.aoc.util.report
class Day13: AdventDay(2021, 13) {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day = Day13()
report {
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,297 | adventofcode | MIT License |
puzzles/src/main/kotlin/com/kotlinground/puzzles/search/binarysearch/successfulpairsspellspotions/successfulPairs.kt | BrianLusina | 113,182,832 | false | {"Kotlin": 483489, "Shell": 7283, "Python": 1725} | package com.kotlinground.puzzles.search.binarysearch.successfulpairsspellspotions
import java.util.TreeMap
import java.util.Arrays
fun successfulPairs(spells: IntArray, potions: IntArray, success: Long): IntArray {
// O(mlogm) operation to sort potions
Arrays.sort(potions)
val treeMap = TreeMap<Long, Int... | 1 | Kotlin | 1 | 0 | 5e3e45b84176ea2d9eb36f4f625de89d8685e000 | 1,795 | KotlinGround | MIT License |
src/main/kotlin/g0801_0900/s0813_largest_sum_of_averages/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0813_largest_sum_of_averages
// #Medium #Array #Dynamic_Programming #2023_03_17_Time_160_ms_(100.00%)_Space_35.3_MB_(100.00%)
class Solution {
fun largestSumOfAverages(nums: IntArray, k: Int): Double {
return helper(nums, k, 0, Array(k + 1) { arrayOfNulls(nums.size) })
}
priva... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 939 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/io/github/pshegger/aoc/y2015/Y2015D12.kt | PsHegger | 325,498,299 | false | null | package io.github.pshegger.aoc.y2015
import io.github.pshegger.aoc.common.BaseSolver
class Y2015D12 : BaseSolver() {
override val year = 2015
override val day = 12
private val tokenizedInput: Token by lazy { tokenize(parseInput()) }
override fun part1(): Int = tokenizedInput.sumNumbers(false)
ov... | 0 | Kotlin | 0 | 0 | 346a8994246775023686c10f3bde90642d681474 | 2,901 | advent-of-code | MIT License |
src/main/kotlin/co/csadev/advent2022/Day09.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2022 by <NAME>
* Advent of Code 2022, Day 9
* Problem Description: http://adventofcode.com/2021/day/9
*/
package co.csadev.advent2022
import co.csadev.adventOfCode.BaseDay
import co.csadev.adventOfCode.Point2D
import co.csadev.adventOfCode.Resources.resourceAsList
import co.csadev.adventOfCode.... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 2,514 | advent-of-kotlin | Apache License 2.0 |
src/Day17/Day17.kt | Nathan-Molby | 572,771,729 | false | {"Kotlin": 95872, "Python": 13537, "Java": 3671} | package Day17
import readInput
import kotlin.math.*
class Chasm() {
var matrix: MutableList<Array<Boolean>> = mutableListOf()
fun resize(matrixVerticalSize: Int) {
for (i in matrix.size..matrixVerticalSize) {
matrix.add(Array(7) { false })
}
}
fun print() {
for(r... | 0 | Kotlin | 0 | 0 | 750bde9b51b425cda232d99d11ce3d6a9dd8f801 | 3,648 | advent-of-code-2022 | Apache License 2.0 |
src/week1/TwoSum.kt | anesabml | 268,056,512 | false | null | package week1
import java.util.*
import kotlin.system.measureNanoTime
class TwoSum {
/** Brute force
* Loop through each element x and find if there is a value that equals to target - x
* Time complexity : O(n2)
* Space complexity : O(1)
*/
fun twoSum(nums: IntArray, target: Int): IntArra... | 0 | Kotlin | 0 | 1 | a7734672f5fcbdb3321e2993e64227fb49ec73e8 | 2,298 | leetCode | Apache License 2.0 |
src/main/kotlin/io/tree/LowestCommonAncestor.kt | jffiorillo | 138,075,067 | false | {"Kotlin": 434399, "Java": 14529, "Shell": 465} | package io.tree
import io.models.TreeNode
// https://leetcode.com/explore/learn/card/data-structure-tree/133/conclusion/932/
// https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
class LowestCommonAncestor {
fun <T> execute(root: BinaryTree<T>?, p: T, q: T): BinaryTree<T>? = when {
r... | 0 | Kotlin | 0 | 0 | f093c2c19cd76c85fab87605ae4a3ea157325d43 | 1,559 | coding | MIT License |
src/2020/Day7_1.kts | Ozsie | 318,802,874 | false | {"Kotlin": 99344, "Python": 1723, "Shell": 975} | import java.io.File
import kotlin.collections.ArrayList
data class Bag(val color: String, val contents: HashMap<Bag,Int> = HashMap<Bag,Int>()) {
fun findBagOrNew(color: String): Bag {
val x = contents.keys.filter { color == it.color }
val i = x.indexOfFirst { color == it.color }
return if (... | 0 | Kotlin | 0 | 0 | d938da57785d35fdaba62269cffc7487de67ac0a | 1,585 | adventofcode | MIT License |
src/main/kotlin/aoc2023/day11/day11Solver.kt | Advent-of-Code-Netcompany-Unions | 726,531,711 | false | {"Kotlin": 94973} | package aoc2023.day11
import aoc2022.day15.manhattanDistance
import lib.*
suspend fun main() {
setupChallenge().solveChallenge()
}
fun setupChallenge(): Challenge<Array<Array<Char>>> {
return setup {
day(11)
year(2023)
parser {
it.readLines().get2DArrayOfColumns()
... | 0 | Kotlin | 0 | 0 | a77584ee012d5b1b0d28501ae42d7b10d28bf070 | 2,269 | AoC-2023-DDJ | MIT License |
dataclass/src/main/kotlin/utils/CategoryUtils.kt | omarmiatello | 264,021,780 | false | null | package com.github.omarmiatello.noexp.utils
import com.github.omarmiatello.noexp.Category
import com.github.omarmiatello.noexp.ProductHome
data class CategoryProducts(
val category: Category,
val productsInCategory: List<ProductHome>,
val productsInChildren: List<ProductHome>
)
fun List<Category>.withPro... | 0 | Kotlin | 0 | 0 | da932571df18ec333f56f26a4f01f9bfff9547fc | 2,354 | noexp | MIT License |
src/Day07.kt | mcrispim | 573,449,109 | false | {"Kotlin": 46488} | fun main() {
open class MyFile(val name: String, val type: String, val onDir: MyFile?) {
var size = 0
var subItens = mutableListOf<MyFile>()
override fun toString(): String {
return "$name ${if (type == "dir") "(dir [$size])" else "(file, $size)"}"
}
}
var fileS... | 0 | Kotlin | 0 | 0 | 5fcacc6316e1576a172a46ba5fc9f70bcb41f532 | 4,340 | AoC2022 | Apache License 2.0 |
src/Day10.kt | felldo | 572,233,925 | false | {"Kotlin": 76496} | fun main() {
fun generateCycles(input: List<String>, startCycle: Int): Array<Int> {
val cycles = Array(input.size * 2) { 1 }
var currentCycle = startCycle
var register = 1
for (line in input) {
if (line == "noop") {
currentCycle++
cycles[c... | 0 | Kotlin | 0 | 0 | 0ef7ac4f160f484106b19632cd87ee7594cf3d38 | 1,465 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/questions/CountAndSay.kt | realpacific | 234,499,820 | false | null | package questions
import _utils.UseCommentAsDocumentation
import utils.shouldBe
import java.math.BigInteger
/**
* The count-and-say sequence is a sequence of digit strings defined by the recursive formula:
* * `countAndSay(1)` = "1"
* * `countAndSay(n)` is the way you would "say" the digit string from `countAndSay... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,303 | algorithms | MIT License |
algorithms/src/main/kotlin/algorithms/Quicksort.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | package algorithms
import java.util.*
fun <T : Comparable<T>> List<T>.quickSort(inPlace: Boolean = true): List<T> {
return if (inPlace) {
toMutableList().apply { quickSortInPlace() }
} else {
quickSortNewList()
}
}
fun <T : Comparable<T>> MutableList<T>.quickSortInPlace() {
if (size <= 1) return
va... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 1,134 | advent-of-code | MIT License |
y2022/src/main/kotlin/adventofcode/y2022/Day22.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2022
import adventofcode.io.AdventSolution
import adventofcode.util.vector.Direction
import adventofcode.util.vector.Vec2
import java.io.StreamTokenizer
import java.io.StringReader
object Day22 : AdventSolution(2022, 22, "Monkey Map") {
override fun solvePartOne(input: String): Int = solve... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 6,054 | advent-of-code | MIT License |
src/day25/Day25.kt | martin3398 | 572,166,179 | false | {"Kotlin": 76153} | package day25
import readInput
import kotlin.math.pow
fun main() {
fun decToSnafu(dec: Long): String {
var cur = dec
var snafu = ""
while (cur > 0) {
val mod = cur % 5
snafu = when (mod) {
3L -> "="
4L -> "-"
else -> ... | 0 | Kotlin | 0 | 0 | 4277dfc11212a997877329ac6df387c64be9529e | 1,035 | advent-of-code-2022 | Apache License 2.0 |
src/Day20.kt | frozbiz | 573,457,870 | false | {"Kotlin": 124645} | class CircularList {
class Node(
val num: Long
) {
lateinit var prev: Node
lateinit var next: Node
}
lateinit var orderList: List<Node>
lateinit var zero: Node
var countNodes = 0L
inline fun makeNode(string: String, multiplier: Long): Node {
return Node(stri... | 0 | Kotlin | 0 | 0 | 4feef3fa7cd5f3cea1957bed1d1ab5d1eb2bc388 | 3,238 | 2022-aoc-kotlin | Apache License 2.0 |
Problems/Algorithms/200. Number of Islands/NumberOfIslands.kt | xuedong | 189,745,542 | false | {"Kotlin": 332182, "Java": 294218, "Python": 237866, "C++": 97190, "Rust": 82753, "Go": 37320, "JavaScript": 12030, "Ruby": 3367, "C": 3121, "C#": 3117, "Swift": 2876, "Scala": 2868, "TypeScript": 2134, "Shell": 149, "Elixir": 130, "Racket": 107, "Erlang": 96, "Dart": 65} | class Solution {
fun numIslands(grid: Array<CharArray>): Int {
val n = grid.size
val m = grid[0].size
val visited = Array(n) { BooleanArray(m) { false } }
val neighbors = arrayOf(intArrayOf(0, 1), intArrayOf(0, -1), intArrayOf(1, 0), intArrayOf(-1, 0))
var ans = 0
... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 1,549 | leet-code | MIT License |
aoc/src/main/kotlin/com/bloidonia/aoc2023/day06/Main.kt | timyates | 725,647,758 | false | {"Kotlin": 45518, "Groovy": 202} | package com.bloidonia.aoc2023.day06
import com.bloidonia.aoc2023.lines
private const val example = """Time: 7 15 30
Distance: 9 40 200"""
private fun distance(time: Long, best: Long) = (0..time).map { it * (time - it) }.count { it > best }
private fun parse(input: List<String>) = input[0].split(Regex("\\... | 0 | Kotlin | 0 | 0 | 158162b1034e3998445a4f5e3f476f3ebf1dc952 | 1,076 | aoc-2023 | MIT License |
aockt-test/src/test/kotlin/io/github/jadarma/aockt/test/integration/ExampleCompilesRunsAndPasses.kt | Jadarma | 324,646,170 | false | {"Kotlin": 38013} | package io.github.jadarma.aockt.test.integration
import io.github.jadarma.aockt.core.Solution
import io.github.jadarma.aockt.test.AdventDay
import io.github.jadarma.aockt.test.AdventSpec
/** A solution to a fictitious puzzle used for testing. */
class Y9999D01 : Solution {
private fun parseInput(input: String): ... | 0 | Kotlin | 0 | 4 | 1db6da68069a72256c3e2424a0d2729fc59eb0cf | 1,106 | advent-of-code-kotlin | MIT License |
solutions/aockt/y2021/Y2021D07.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
import kotlin.math.absoluteValue
import kotlin.math.roundToInt
object Y2021D07 : Solution {
/** Return the median value of this collection of numbers, or `null` if the collection is empty. */
private fun Collection<Int>.medianOrNull(): Double? ... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 1,435 | advent-of-code-kotlin-solutions | The Unlicense |
src/iii_conventions/MyDate.kt | schnell18 | 150,126,108 | true | {"Kotlin": 74962, "Java": 4952} | package iii_conventions
data class RepeatedTimeInterval(val interval: TimeInterval, val repeat : Int = 1)
enum class TimeInterval {
DAY(),
WEEK(),
YEAR();
operator fun times(i: Int): RepeatedTimeInterval {
return RepeatedTimeInterval(this, i)
}
}
data class MyDate(val year: Int, val mont... | 0 | Kotlin | 0 | 0 | 7c1e281aba1627dbe646d3c2b870b53a914a8442 | 2,262 | kotlin-koans | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/GlobalAndLocalInversions.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,537 | kotlab | Apache License 2.0 |
src/main/kotlin/aoc2019/DonutMaze.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2019
import komu.adventofcode.utils.Point
import komu.adventofcode.utils.nonEmptyLines
import utils.shortestPathBetween
fun donutMaze1(input: String): Int {
val maze = DonutMaze.parse(input)
val path = shortestPathBetween(maze.start, maze.end) { it.directNeighbors + listOfNotNull... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 4,452 | advent-of-code | MIT License |
src/day11/Day11.kt | pnavais | 574,712,395 | false | {"Kotlin": 54079} | package day11
import readInput
import java.util.*
import kotlin.math.floor
enum class Operator {
SUM, MULTIPLY, SUBTRACT, DIVIDE, NONE;
companion object {
fun from(c: Char): Operator {
return when (c) {
'+' -> SUM
'*' -> MULTIPLY
'-' -> SUBT... | 0 | Kotlin | 0 | 0 | ed5f521ef2124f84327d3f6c64fdfa0d35872095 | 6,789 | advent-of-code-2k2 | Apache License 2.0 |
src/nativeMain/kotlin/Day14.kt | rubengees | 576,436,006 | false | {"Kotlin": 67428} | import Day14.Material.ROCK
import Day14.Material.SAND
class Day14 : Day {
private data class Point(val x: Int, val y: Int) {
fun rangeTo(other: Point): List<Point> {
return (x toward other.x).flatMap { x ->
(y toward other.y).map { y -> Point(x, y) }
}
}
... | 0 | Kotlin | 0 | 0 | 21f03a1c70d4273739d001dd5434f68e2cc2e6e6 | 2,641 | advent-of-code-2022 | MIT License |
src/Day10.kt | aneroid | 572,802,061 | false | {"Kotlin": 27313} | import Operation.*
private enum class Operation(val cycleCost: Int) {
NOOP(1),
ADDX(2),
;
companion object {
fun fromString(s: String): Operation =
values().first { it.name == s.uppercase() }
}
}
private class CPU(var accX: Int = 1) {
private var cycle = 1
private ... | 0 | Kotlin | 0 | 0 | cf4b2d8903e2fd5a4585d7dabbc379776c3b5fbd | 3,112 | advent-of-code-2022-kotlin | Apache License 2.0 |
calendar/day09/Day9.kt | starkwan | 573,066,100 | false | {"Kotlin": 43097} | package day09
import Day
import Lines
import kotlin.math.abs
import kotlin.math.sign
class Day9 : Day() {
override fun part1(input: Lines): Any {
val tailVisitedSet = mutableSetOf<Knot>()
var rope = Rope(Knot(0, 0), Knot(0, 0))
input.forEach {
val (action, times) = it.split(" "... | 0 | Kotlin | 0 | 0 | 13fb66c6b98d452e0ebfc5440b0cd283f8b7c352 | 2,938 | advent-of-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/ikueb/advent18/Day02.kt | h-j-k | 159,901,179 | false | null | package com.ikueb.advent18
object Day02 {
fun getChecksum(input: List<String>) = input
.map { word -> word.groupingBy { it }.eachCount() }
.map { Pair(it.containsValue(2).toInt(), it.containsValue(3).toInt()) }
.reduce { a, b -> Pair(a.first + b.first, a.second + b.second) }
... | 0 | Kotlin | 0 | 0 | f1d5c58777968e37e81e61a8ed972dc24b30ac76 | 1,500 | advent18 | Apache License 2.0 |
src/2021/Day08.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2021`
import java.io.File
import java.util.*
fun main() {
Day08().solve()
}
val input = """ be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
fg... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 4,316 | advent-of-code | Apache License 2.0 |
src/main/kotlin/g0901_1000/s0924_minimize_malware_spread/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s0924_minimize_malware_spread
// #Hard #Array #Depth_First_Search #Breadth_First_Search #Matrix #Union_Find
// #2023_04_17_Time_791_ms_(100.00%)_Space_59.7_MB_(100.00%)
class Solution {
private lateinit var size: IntArray
private lateinit var par: IntArray
fun minMalwareSpread(graph: A... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,074 | LeetCode-in-Kotlin | MIT License |
13/src/main/kotlin/TableSitting.kt | kopernic-pl | 109,750,709 | false | null | import com.google.common.collect.Collections2
import com.google.common.io.Resources
@Suppress("UnstableApiUsage")
fun main() {
val input = Resources.getResource("input.txt").readText()
val bestSittingWithoutMe = SittingPlan().findBestSitting(SittingPreferences(input))
println(bestSittingWithoutMe)
va... | 0 | Kotlin | 0 | 0 | 06367f7e16c0db340c7bda8bc2ff991756e80e5b | 2,659 | aoc-2015-kotlin | The Unlicense |
kotlin/graphs/shortestpaths/FloydWarshall.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package graphs.shortestpaths
import java.util.Arrays
object FloydWarshall {
val INF: Int = Integer.MAX_VALUE / 2
// precondition: d[i][i] == 0
fun floydWarshall(d: Array<IntArray>): Array<IntArray>? {
val n = d.size
val pred = Array(n) { IntArray(n) }
for (i in 0 until n) for (j i... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,878 | codelibrary | The Unlicense |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.