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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
app/src/main/kotlin/com/resurtm/aoc2023/day24/Solution.kt | resurtm | 726,078,755 | false | {"Kotlin": 119665} | package com.resurtm.aoc2023.day24
import kotlin.math.round
/**
* See the README.md file for more details on this one.
*/
fun launchDay24(testCase: String) {
val neverTellMeTheOdds = NeverTellMeTheOdds.readInput(testCase)
val part1 = neverTellMeTheOdds.solvePart1(
if (testCase.contains("test")) 7L..... | 0 | Kotlin | 0 | 0 | fb8da6c246b0e2ffadb046401502f945a82cfed9 | 8,193 | advent-of-code-2023 | MIT License |
src/main/kotlin/leetcode/kotlin/tree/501. Find Mode in Binary Search Tree.kt | sandeep549 | 251,593,168 | false | null | package leetcode.kotlin.tree
import java.util.ArrayDeque
/**
* Traverse the tree and maintain hashmap of all elements with their frequencies.
* Return element with highest frequency from map.
* O(n), n is no of nodes in tree
* O(n)
*/
private fun findMode(root: TreeNode?): IntArray {
if (root == null) retur... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 3,086 | kotlinmaster | Apache License 2.0 |
src/main/kotlin/Exercise3.kt | US-ADDA | 521,923,956 | false | {"Kotlin": 17265} | import java.util.stream.Stream
class Exercise3 {
companion object {
fun functional(start: Int, end: Int): List<Pair<Int, Int>> {
return Stream
.iterate(
Pair(0, start), // Cuando empieza.
{ it.first < end }, // Cuando termina.
... | 0 | Kotlin | 0 | 0 | b83e4fd0e457bda0b026df3a94f538d4dab715cf | 2,299 | PI1_kotlin | Apache License 2.0 |
src/test/kotlin/com/igorwojda/integer/pyramidgenerator/solution.kt | handiism | 455,862,994 | true | {"Kotlin": 218721} | package com.igorwojda.integer.pyramidgenerator
// iterative solution
private object Solution1 {
private fun generatePyramid(n: Int): List<String> {
val list = mutableListOf<String>()
val numColumns = (n * 2) - 1
(0 until n).forEach { row ->
val numHashes = (row * 2) + 1
... | 0 | Kotlin | 0 | 1 | 413316e0e9de2f237d9768cfa68db3893e72b48c | 3,183 | kotlin-coding-challenges | MIT License |
src/twentytwentytwo/day14/Day14.kt | colinmarsch | 571,723,956 | false | {"Kotlin": 65403, "Python": 6148} | package twentytwentytwo.day14
import readInput
// All x points need to subtract 450
fun main() {
val grid = mutableListOf<MutableList<Char>>()
// 150 by 200 grid
// x is 450 to 600, y is 0 to 200
fun setupGrid(input: List<String>, addFloor: Boolean = false) {
grid.clear()
for (y in 0... | 0 | Kotlin | 0 | 0 | bcd7a08494e6db8140478b5f0a5f26ac1585ad76 | 3,139 | advent-of-code | Apache License 2.0 |
solutions/src/solutions/y20/day 21.kt | Kroppeb | 225,582,260 | false | null | @file:Suppress("PackageDirectoryMismatch")
package solutions.y20.d21
import grid.Clock
import helpers.*
val xxxxx = Clock(6, 3);
private fun part1(data: Data) {
val mmm = data.map{line ->
val p = line.split('(')
val items = p[0].split(" ").filter { it.isNotBlank() }.toSet()
val alerg = if(p.size < 2) emptyLi... | 0 | Kotlin | 0 | 1 | 744b02b4acd5c6799654be998a98c9baeaa25a79 | 2,080 | AdventOfCodeSolutions | MIT License |
src/day04/Day04Answer.kt | IThinkIGottaGo | 572,833,474 | false | {"Kotlin": 72162} | package day04
import readInput
/**
* Answers from [Advent of Code 2022 Day 4 | Kotlin](https://youtu.be/dBIbr55YS0A)
*/
fun main() {
val testInput = Day04(readInput("day04_test"))
check(testInput.solvePart1() == 2)
check(testInput.solvePart2() == 4)
val input = Day04(readInput("day04"))
println... | 0 | Kotlin | 0 | 0 | 967812138a7ee110a63e1950cae9a799166a6ba8 | 1,221 | advent-of-code-2022 | Apache License 2.0 |
src/day08/Day08.kt | IThinkIGottaGo | 572,833,474 | false | {"Kotlin": 72162} | package day08
import readInput
fun main() {
fun part1(input: List<String>): Int {
var count = 0
input.forEachIndexed { iy, line ->
line.forEachIndexed { ix, _ ->
if (input.visible(ix, iy)) count++
}
}
return count
}
fun part2(input: ... | 0 | Kotlin | 0 | 0 | 967812138a7ee110a63e1950cae9a799166a6ba8 | 2,814 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/io/github/dca/strategy/Weight.kt | laguiar | 476,662,074 | false | {"Kotlin": 43279} | package io.github.dca.strategy
import io.github.dca.Asset
import io.github.dca.DcaRequest
import io.github.dca.Distribution
import io.github.dca.Thresholds
import io.github.dca.ZERO
import io.github.dca.calculateAdjustedAmountToInvest
import io.github.dca.calculateAdjustedWeight
import io.github.dca.calculateDistribut... | 0 | Kotlin | 1 | 0 | 2b07dc89982390cf990765ac414f676aba69bf45 | 2,905 | dca-optimizer | MIT License |
src/chapter5/section3/ex37_KMPforRandomText.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter5.section3
import chapter5.section1.Alphabet
import extensions.random
/**
* 随机文本的KMP算法
* 编写一个用例,接受整型参数M、N和T并运行以下实验T遍:
* 随机生成一个长度为M的模式字符串和一段长度为N的文本,记录使用KMP算法在文本中查找该模式时比较字符的次数。
* 修改KMP类的实现来记录比较次数并打印出重复T次之后的平均比较次数。
*/
fun ex37_KMPforRandomText(M: Int, N: Int, T: Int): Int {
// 使用小写字母作为字符集(使用较小的字符... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,674 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/main/kotlin/d18/D18_1.kt | MTender | 734,007,442 | false | {"Kotlin": 108628} | package d18
import d10.padInput
import d16.Direction
import input.Input
val CHAR_TO_DIR = mapOf(
Pair('R', Direction.RIGHT),
Pair('L', Direction.LEFT),
Pair('U', Direction.ABOVE),
Pair('D', Direction.BELOW)
)
data class Instruction(
val dir: Direction,
val count: Int
)
fun parseInput(lines: ... | 0 | Kotlin | 0 | 0 | a6eec4168b4a98b73d4496c9d610854a0165dbeb | 2,438 | aoc2023-kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NumRollsToTarget.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,643 | kotlab | Apache License 2.0 |
aoc2022/day9.kt | davidfpc | 726,214,677 | false | {"Kotlin": 127212} | package aoc2022
import utils.InputRetrieval
fun main() {
Day9.execute()
}
object Day9 {
fun execute() {
val input = readInput()
println("Part 1: ${part1(input)}")
println("Part 2: ${part2(input)}")
}
private fun part1(input: List<Pair<Char, Int>>): Int = calcMoves(input, 2)
... | 0 | Kotlin | 0 | 0 | 8dacf809ab3f6d06ed73117fde96c81b6d81464b | 3,524 | Advent-Of-Code | MIT License |
src/main/kotlin/leetcode/Problem2048.kt | fredyw | 28,460,187 | false | {"Java": 1280840, "Rust": 363472, "Kotlin": 148898, "Shell": 604} | package leetcode
import kotlin.math.min
/**
* https://leetcode.com/problems/next-greater-numerically-balanced-number/
*/
class Problem2048 {
fun nextBeautifulNumber(n: Int): Int {
var answer = Answer()
val s = n.toString()
val numbers = arrayOf("1", "22", "122", "333", "1333", "4444", "1... | 0 | Java | 1 | 4 | a59d77c4fd00674426a5f4f7b9b009d9b8321d6d | 1,281 | leetcode | MIT License |
src/main/kotlin/days/aoc2023/Day17.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2023
import days.Day
import util.CharArray2d
import util.Pathfinding
import util.Point2d
class Day17 : Day(2023, 17) {
override fun partOne(): Any {
return calculatePartOne(inputList)
}
override fun partTwo(): Any {
return calculatePartTwo(inputList)
}
fun calcula... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 3,580 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
MicrobenchmarkSample/benchmarkable/src/main/java/com/example/benchmark/ui/SortingAlgorithms.kt | android | 31,396,355 | false | {"Kotlin": 158640, "TypeScript": 11355, "Shell": 544} | /*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applica... | 8 | Kotlin | 211 | 1,150 | 6555fe327ea6a5f08e366bd5df7dc4ea156f4aca | 1,894 | performance-samples | Apache License 2.0 |
src/GeneticAlgorithm.kt | KonstantinLukaschenko | 92,331,788 | false | null | import java.lang.Math.random
/**
* Implementation of a basic genetic algorithm, that is capable to generate solutions for optimization and search
* problems relying on bio-inspired operations such as crossover, mutation and selection.
*
* @param T the type of an individual.
* @property population a collection of ... | 0 | Kotlin | 0 | 6 | e2828542dbb13966d5d473f445b6676f10a9e5a2 | 1,903 | genetic-algorithm-kotlin | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaxCoinsYouCanGet.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,630 | kotlab | Apache License 2.0 |
src/main/kotlin/io/github/pshegger/aoc/y2015/Y2015D9.kt | PsHegger | 325,498,299 | false | null | package io.github.pshegger.aoc.y2015
import io.github.pshegger.aoc.common.BaseSolver
import io.github.pshegger.aoc.common.extractAll
import io.github.pshegger.aoc.common.permutations
import io.github.pshegger.aoc.common.toExtractor
class Y2015D9 : BaseSolver() {
override val year = 2015
override val day = 9
... | 0 | Kotlin | 0 | 0 | 346a8994246775023686c10f3bde90642d681474 | 1,846 | advent-of-code | MIT License |
src/main/kotlin/g2601_2700/s2617_minimum_number_of_visited_cells_in_a_grid/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2601_2700.s2617_minimum_number_of_visited_cells_in_a_grid
// #Hard #Array #Dynamic_Programming #Binary_Search #Stack #Union_Find #Segment_Tree
// #Binary_Indexed_Tree #2023_07_14_Time_1255_ms_(100.00%)_Space_99.7_MB_(100.00%)
import java.util.LinkedList
import java.util.Queue
class Solution {
fun minimu... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,879 | LeetCode-in-Kotlin | MIT License |
advent-of-code/src/main/kotlin/com/akikanellis/adventofcode/year2022/Day24.kt | akikanellis | 600,872,090 | false | {"Kotlin": 142932, "Just": 977} | package com.akikanellis.adventofcode.year2022
import com.akikanellis.adventofcode.year2022.utils.Point
import java.util.*
import kotlin.math.min
object Day24 {
fun numberOfMinutesToReachGoal(input: String): Int {
val valleyIdsToValleys = valleyIdsToValleys(input)
val initialValley = valleyIdsToVal... | 8 | Kotlin | 0 | 0 | 036cbcb79d4dac96df2e478938de862a20549dce | 8,908 | advent-of-code | MIT License |
src/Day17.kt | i-tatsenko | 575,595,840 | false | {"Kotlin": 90644} | import kotlin.math.max
data class LongPoint(var x: Long, var y: Long) {
fun eq(x: Long, y: Long): Boolean = this.x == x && this.y == y
fun move(direction: Char, distance: Long = 1L) {
when (direction) {
'R', '>' -> y += distance
'L', '<' -> y -= distance
'U', '^' -... | 0 | Kotlin | 0 | 0 | 0a9b360a5fb8052565728e03a665656d1e68c687 | 6,288 | advent-of-code-2022 | Apache License 2.0 |
src/main/java/challenges/cracking_coding_interview/trees_graphs/validate_bst/ValidateBstB.kt | ShabanKamell | 342,007,920 | false | null | package challenges.cracking_coding_interview.trees_graphs.validate_bst
import challenges.util.AssortedMethods
import challenges.util.AssortedMethods.randomIntInRange
import challenges.util.TreeNode
object ValidateBstB {
private fun checkBST(n: TreeNode?, min: Int?, max: Int?): Boolean {
if (n == null) re... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 3,651 | CodingChallenges | Apache License 2.0 |
src/Day13.kt | syncd010 | 324,790,559 | false | null | import kotlin.math.sign
class Day13: Day {
private fun convert(input: List<String>) : List<Long> {
return input[0].split(",").map { it.toLong() }
}
override fun solvePartOne(input: List<String>): Int {
val output = Intcode(convert(input))
.execute()
return output.slice(... | 0 | Kotlin | 0 | 0 | 11c7c7d6ccd2488186dfc7841078d9db66beb01a | 1,795 | AoC2019 | Apache License 2.0 |
2021/src/main/kotlin/com/github/afranken/aoc/Day202106.kt | afranken | 434,026,010 | false | {"Kotlin": 28937} | package com.github.afranken.aoc
object Day202106 {
fun part1(inputs: Array<String>): Long {
val fish = fishMap(inputs.map { Integer.valueOf(it) })
val agedFish = age(fish, 80)
return agedFish.values.sum()
}
fun part2(inputs: Array<String>): Long {
val fish = fishMap(inpu... | 0 | Kotlin | 0 | 0 | 0140f68e60fa7b37eb7060ade689bb6634ba722b | 1,574 | advent-of-code-kotlin | Apache License 2.0 |
src/Day02.kt | tristanrothman | 572,898,348 | false | null | fun main() {
fun part1(input: List<String>): Int {
return input.sumOf {
val moveScore = (it.toCharArray().last() - 'X') + 1
val roundScore = when(it) {
"A X", "B Y", "C Z" -> 3
"A Y", "B Z", "C X" -> 6
"A Z", "B X", "C Y" -> 0
... | 0 | Kotlin | 0 | 0 | e794ab7e0d50f22d250c65b20e13d9b5aeba23e2 | 919 | advent-of-code-2022 | Apache License 2.0 |
2023/14/Solution.kt | AdrianMiozga | 588,519,359 | false | {"Kotlin": 110785, "Python": 11275, "Assembly": 3369, "C": 2378, "Pawn": 1390, "Dart": 732} | import java.io.File
private const val FILENAME = "2023/14/input.txt"
fun main() {
partOne()
partTwo()
}
private fun partOne() {
val file = File(FILENAME).readLines().toMutableList()
moveUp(file)
println(calculateLoad(file))
}
private fun calculateLoad(file: MutableList<String>): Int {
var ... | 0 | Kotlin | 0 | 0 | c9cba875089d8d4fb145932c45c2d487ccc7e8e5 | 2,893 | Advent-of-Code | MIT License |
solution/#5 Longest Palindromic Substring/Solution.kt | enihsyou | 116,918,868 | false | {"Java": 179666, "Python": 36379, "Kotlin": 32431, "Shell": 367} | package leetcode.q5.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
class Solution {
fun longestPalindrome(s: String): String {
val T = preProcess(s)
... | 1 | Java | 0 | 0 | 230325d1dfd666ee53f304edf74c9c0f60f81d75 | 1,873 | LeetCode | MIT License |
src/main/kotlin/extractors/MemExtractor.kt | Albaross | 98,739,245 | false | null | package org.albaross.agents4j.extraction.extractors
import org.albaross.agents4j.extraction.*
import org.albaross.agents4j.extraction.bases.TreeMapKB
import org.albaross.agents4j.extraction.collections.Multiset
import java.util.*
typealias Triple<A> = kotlin.Triple<State, Collection<Pair<State, A>>, Collection<Rule<A... | 1 | Kotlin | 0 | 0 | 36bbbccd8ff9a88ea8745a329a446912d4de007d | 3,755 | agents4j-extraction | MIT License |
solutions/cheating-detection/kotlin/cheating-detection.kt | cavesdev | 418,595,190 | true | {"Java": 85120, "Elixir": 51650, "Go": 50067, "Ruby": 24382, "Dart": 19382, "Scala": 18626, "JavaScript": 14831, "Python": 10246, "Rust": 6885, "Clojure": 5403, "Kotlin": 4945, "F#": 3328} | /******************
Qualification Round - Google Code Jam 2021
Problem #5: Cheating Detection.
https://codingcompetitions.withgoogle.com/codejam/round/000000000043580a/00000000006d1155
Written by: <NAME> <@cavesdev> 18/10/21
for the Encora Apprentice Program
The approach used here is taken fr... | 0 | Java | 0 | 0 | 81e55cb08f410429187b802e8684bac3b54e3510 | 4,945 | google-code-jam | MIT License |
src/commonMain/kotlin/ai/Combinatorics.kt | KristiansKaneps | 624,533,678 | false | null | package ai
import game.cards.*
object Combinatorics {
fun <T> permutations(from: Collection<T>): Collection<Collection<T>> {
if (from.isEmpty()) return listOf(emptySet())
return from.flatMap { element ->
permutations(from - element).map { setOf(element) + it }
}
}
fun ... | 0 | Kotlin | 0 | 0 | 0ef9c3fe3befdc11c8f55303fa3439fa26c3e80e | 1,925 | korge-test-card-game | MIT License |
KotlinDeveloper/SeamCarving/VerticalSeamCalculator.kt | Tsyshnatiy | 561,408,519 | false | {"Kotlin": 64886, "JavaScript": 3306, "CSS": 1632, "HTML": 726} | package seamcarving
data class Cell(val row: Int, val col: Int)
typealias Seam = HashSet<Cell>
class VerticalSeamCalculator(private val energies: Energies) {
fun calculate() : Seam {
val h = energies.size
val w = energies[0].size
val arrows = Array(h) { Array(w) { Cell(0, 0) } }
... | 0 | Kotlin | 0 | 0 | 5c3ef96cca79e51cc8bc3f65cad6086e0c99ea2d | 2,134 | JetBrainsCourses | Apache License 2.0 |
src/main/kotlin/day16/Day16.kt | cyril265 | 433,772,262 | false | {"Kotlin": 39445, "Java": 4273} | package day16
import readToList
import java.util.Stack
private val input = readToList("day16.txt").first()
fun main() {
val map = input.map { char ->
toBits(char)
}.flatMap { it.toList() }.toMutableList()
val packets = getPacket(map, null)
println(packets)
// println(packets.sumOf { it.v... | 0 | Kotlin | 0 | 0 | 1ceda91b8ef57b45ce4ac61541f7bc9d2eb17f7b | 7,951 | aoc2021 | Apache License 2.0 |
src/Day01.kt | ranveeraggarwal | 573,754,764 | false | {"Kotlin": 12574} | fun main() {
fun splitOnEmpty(input: List<String>): ArrayList<Int> {
val allCalories = ArrayList<Int>()
var current = 0
input.forEach {
if (it.isEmpty()) {
allCalories.add(current)
current = 0
} else {
current += Integer... | 0 | Kotlin | 0 | 0 | c8df23daf979404f3891cdc44f7899725b041863 | 950 | advent-of-code-2022-kotlin | Apache License 2.0 |
kotlin/src/katas/kotlin/leetcode/bst_level_order_traversal/BstLevelOrderTraversal2.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.bst_level_order_traversal
import katas.kotlin.leetcode.TreeNode
import datsok.shouldEqual
import org.junit.Test
import java.util.*
import kotlin.collections.ArrayList
/**
* https://leetcode.com/problems/binary-tree-level-order-traversal
*/
class BstLevelOrderTraversal2 {
@Test fun ... | 7 | Roff | 3 | 5 | 0f169804fae2984b1a78fc25da2d7157a8c7a7be | 1,878 | katas | The Unlicense |
src/Day04.kt | topr | 572,937,822 | false | {"Kotlin": 9662} | import kotlin.math.max
import kotlin.math.min
fun main() {
operator fun ClosedRange<Int>.contains(other: ClosedRange<Int>) =
this.start <= other.start && this.endInclusive >= other.endInclusive
fun ClosedRange<Int>.overlaps(other: ClosedRange<Int>) =
max(this.start, other.start) - min(this.en... | 0 | Kotlin | 0 | 0 | 8c653385c9a325f5efa2895e94830c83427e5d87 | 1,117 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/AOC2022/Day04/Day04.kt | kfbower | 573,519,224 | false | {"Kotlin": 44562} | package AOC2022.Day04
import AOC2022.readInput
fun main() {
fun part1(input: List<String>): Int {
var encapsulatedcount = 0
input.forEachIndexed { i, s ->
val parts = s.split(",","-")
val min1= parts[0].toInt()
val max1 = parts[1].toInt()
val min... | 0 | Kotlin | 0 | 0 | 48a7c563ebee77e44685569d356a05e8695ae36c | 1,322 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/P011_LargestProductInAGrid.kt | perihanmirkelam | 291,833,878 | false | null | /**
* P11-Largest product in a grid
* In the 20×20 grid below, four numbers along a diagonal line have been marked in red.
* The product of these numbers is 26 × 63 × 78 × 14 = 1788696.
* What is the greatest product of four adjacent numbers in the same direction
* (up, down, left, right, or diagonally) in the 20×... | 0 | Kotlin | 1 | 3 | a24ac440871220c87419bfd5938f80dc22a422b2 | 2,786 | ProjectEuler | MIT License |
src/main/kotlin/report/plain.kt | Tiofx | 175,697,373 | false | null | package report
import algorithm.CPF
import algorithm.Matrix
import algorithm.Program
import report.latex.toLatex
fun List<CPF.Iteration>.description(namer: OperatorNamer) {
forEach {
it.description(it.program, namer)
}
}
fun CPF.Iteration.description(program: Program, namer: OperatorNamer) {
prin... | 0 | Kotlin | 0 | 0 | 32c1cc3e95940e377ed9a99293eccc871ce13864 | 1,815 | CPF | The Unlicense |
2021/kotlin/src/main/kotlin/com/pietromaggi/aoc2021/day18/Day18.kt | pfmaggi | 438,378,048 | false | {"Kotlin": 113883, "Zig": 18220, "C": 7779, "Go": 4059, "CMake": 386, "Awk": 184} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in wr... | 0 | Kotlin | 0 | 0 | 7c4946b6a161fb08a02e10e99055a7168a3a795e | 5,265 | AdventOfCode | Apache License 2.0 |
src/Day01.kt | jfiorato | 573,233,200 | false | null | fun main() {
fun accumulateElves(input: List<String>): MutableList<Int> {
val elves = mutableListOf<Int>()
var currentElf = 0
for (line in input) {
if (line.isNotEmpty()) {
currentElf += line.toInt()
} else {
elves.add(currentElf)
... | 0 | Kotlin | 0 | 0 | 4455a5e9c15cd067d2661438c680b3d7b5879a56 | 1,007 | kotlin-aoc-2022 | Apache License 2.0 |
src/Day03.kt | dustinlewis | 572,792,391 | false | {"Kotlin": 29162} | fun main() {
fun part1(input: List<String>): Int {
return input.fold(0) {
acc, el ->
val (firstHalf, secondHalf) = el.chunked(el.count()/2)
acc + getIntersection(firstHalf, secondHalf).first().priority
}
}
fun part2(input: List<String>): Int {
ret... | 0 | Kotlin | 0 | 0 | c8d1c9f374c2013c49b449f41c7ee60c64ef6cff | 1,065 | aoc-2022-in-kotlin | Apache License 2.0 |
2023/src/main/kotlin/day16_fast.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.IntGrid
import utils.MutableIntGrid
import utils.Parser
import utils.Solution
import utils.Vec2i
fun main() {
Day16Fast.run()
}
object Day16Fast : Solution<IntGrid>() {
override val name = "day16"
override val parser = Parser.charGrid.map {
IntGrid(it.width, it.height) { p ->
when (it[p])... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 3,657 | aoc_kotlin | MIT License |
src/main/kotlin/io/github/leandroborgesferreira/dagcommand/logic/NodeList.kt | leandroBorgesFerreira | 268,720,218 | false | {"Kotlin": 33555} | package io.github.leandroborgesferreira.dagcommand.logic
import io.github.leandroborgesferreira.dagcommand.domain.AdjacencyList
import io.github.leandroborgesferreira.dagcommand.domain.Node
import java.util.*
fun findRootNodes(adjacencyList: AdjacencyList) = adjacencyList.keys - adjacencyList.values.flatten().toSet()... | 8 | Kotlin | 10 | 38 | 1bb81d504593b997e43851d09fbdb6a47662909b | 1,469 | dag-command | Apache License 2.0 |
src/main/kotlin/days/Day9.kt | MaciejLipinski | 317,582,924 | true | {"Kotlin": 60261} | package days
class Day9 : Day(9) {
override fun partOne(): Any {
val numbers = inputList.map { it.toLong() }
for (i in numbers.indices) {
if (i < PREAMBLE_LENGTH) {
continue
}
if (!isSumOfPrevious(numbers[i], numbers.subList(i - PREAMBLE_LENGTH, i... | 0 | Kotlin | 0 | 0 | 1c3881e602e2f8b11999fa12b82204bc5c7c5b51 | 1,636 | aoc-2020 | Creative Commons Zero v1.0 Universal |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[867]转置矩阵.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给你一个二维整数数组 matrix, 返回 matrix 的 转置矩阵 。
//
// 矩阵的 转置 是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引。
//
//
//
//
//
// 示例 1:
//
//
//输入:matrix = [[1,2,3],[4,5,6],[7,8,9]]
//输出:[[1,4,7],[2,5,8],[3,6,9]]
//
//
// 示例 2:
//
//
//输入:matrix = [[1,2,3],[4,5,6]]
//输出:[[1,4],[2,5],[3,6]]
//
//
//
//
// 提示:
//
//
// m == matrix.length
... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,205 | MyLeetCode | Apache License 2.0 |
src/day20/Code.kt | fcolasuonno | 572,734,674 | false | {"Kotlin": 63451, "Dockerfile": 1340} | package day20
import day06.main
import readInput
fun main() {
fun part1(input: List<String>) = input.map { it.toLong() }.withIndex()
.toMutableList().apply {
for (originalIndex in indices) {
val mixingIndex = indexOfFirst { it.index == originalIndex }
val mixing... | 0 | Kotlin | 0 | 0 | 9cb653bd6a5abb214a9310f7cac3d0a5a478a71a | 1,681 | AOC2022 | Apache License 2.0 |
src/main/kotlin/g1601_1700/s1627_graph_connectivity_with_threshold/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1601_1700.s1627_graph_connectivity_with_threshold
// #Hard #Array #Math #Union_Find #2023_06_16_Time_703_ms_(100.00%)_Space_87.8_MB_(100.00%)
class Solution {
fun areConnected(n: Int, threshold: Int, queries: Array<IntArray>): List<Boolean> {
if (n < 1 || queries.isEmpty()) {
return A... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,904 | LeetCode-in-Kotlin | MIT License |
src/main/java/com/ncorti/aoc2021/Exercise11.kt | cortinico | 433,486,684 | false | {"Kotlin": 36975} | package com.ncorti.aoc2021
object Exercise11 {
private fun getInput() =
getInputAsTest("11") { split("\n") }
.map { line -> line.toCharArray().map { it.digitToInt() }.toTypedArray() }
.toTypedArray()
private fun Array<Array<Int>>.letItFlash(): Int {
var count = 0
... | 0 | Kotlin | 0 | 4 | af3df72d31b74857201c85f923a96f563c450996 | 2,406 | adventofcode-2021 | MIT License |
src/chapter4/section4/ex25_ShortestPathsBetweenTwoSubsets.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter4.section4
import chapter3.section5.LinearProbingHashSET
import chapter3.section5.SET
/**
* 两个顶点集合之间的最短路径
* 给定一幅边的权重均为正的有向图和两个没有交集的顶点集S和T,
* 找到从S中的任意顶点到达T中的任意顶点的最短路径。
* 你的算法在最坏情况下所需的时间应该与ElogV成正比。
*
* 解:根据练习4.4.24中的算法,将集合S中的所有顶点作为起点,生成最短路径森林,
* 遍历集合T,找到到达每个顶点的最短路径,最短的最短路径必定只含有一条边
*/
fun ex25_Sh... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 1,827 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/main/kotlin/biz/koziolek/adventofcode/year2022/day04/day4.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2022.day04
import biz.koziolek.adventofcode.findInput
fun main() {
val inputFile = findInput(object {})
val assignments = parseAssignments(inputFile.bufferedReader().readLines())
println("Fully contained assignment pairs: ${assignments.count { it.isAnyFullyContainedIn... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 1,318 | advent-of-code | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinDepth.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,457 | kotlab | Apache License 2.0 |
src/Day16.kt | jrmacgill | 573,065,109 | false | {"Kotlin": 76362} |
class Day16 {
val inputLineRegex = """Valve ([A-Z]*) has flow rate=(\d+); tunnel[s]? lead[s]? to valve[s]? (.*)""".toRegex()
val data = mutableMapOf<String, Room>()
val maxTicks = 30
var best = 0
class Room(val id : String, val flow : Int, val links : List<String>) {
}
fun maxRemain(op... | 0 | Kotlin | 0 | 1 | 3dcd590f971b6e9c064b444139d6442df034355b | 2,061 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/io/github/kmakma/adventofcode/y2019/Y2019Day10.kt | kmakma | 225,714,388 | false | null | package io.github.kmakma.adventofcode.y2019
import io.github.kmakma.adventofcode.y2019.utils.Vector2D
import kotlin.math.abs
internal class Y2019Day10 : Y2019Day(10, "Monitoring Station") {
private lateinit var asteroidList: List<Vector2D>
private lateinit var detectedAsteroids: List<Int>
override fun in... | 0 | Kotlin | 0 | 0 | 7e6241173959b9d838fa00f81fdeb39fdb3ef6fe | 3,996 | adventofcode-kotlin | MIT License |
modules/fathom/src/main/kotlin/silentorb/mythic/fathom/surfacing/EdgeUnification.kt | silentorb | 227,508,449 | false | null | package silentorb.mythic.fathom.surfacing
import silentorb.mythic.spatial.Vector3
import kotlin.math.abs
data class BrokenLine(
val middle: Vector3,
val first: Edge,
val second: Edge
) {
val edges = listOf(first, second)
}
typealias BrokenLines = List<BrokenLine>
tailrec fun accumulateNeighborLines(ed... | 0 | Kotlin | 0 | 2 | 74462fcba9e7805dddec1bfcb3431665df7d0dee | 2,411 | mythic-kotlin | MIT License |
src/commonMain/kotlin/rtree/Context.kt | seisuke | 509,360,379 | false | {"Kotlin": 165567, "HTML": 268} | package rtree
/**
* Configures an RTree prior to instantiation of an [RTree].
*
* @constructor
* @param minChildren minimum number of children per node (at least 1)
* @param maxChildren max number of children per node (minimum is 3)
* @param selector algorithm to select search path
* @param splitter algorithm t... | 0 | Kotlin | 0 | 4 | fe6480c744dabcdcf532d6733a089b500f229c80 | 5,690 | ksn-draw | Apache License 2.0 |
src/Day14.kt | Totwart123 | 573,119,178 | false | null | enum class Materials{
AIR, ROCK, SAND
}
fun main() {
fun printGround(ground: List<List<Materials>>){
var xOffset = Int.MAX_VALUE
ground.forEach { line ->
line.forEachIndexed { index, materials ->
if(index > xOffset){
return@forEachIndexed
... | 0 | Kotlin | 0 | 0 | 33e912156d3dd4244c0a3dc9c328c26f1455b6fb | 6,486 | AoC | Apache License 2.0 |
library/src/main/kotlin/com/yt8492/indikate/RoutingPath.kt | yt8492 | 295,082,472 | false | null | package com.yt8492.indikate
class RoutingPath(val parts: List<RoutingPathSegment>) {
fun evaluate(path: String): PathEvaluationResult {
val pathParts = path.splitToSequence("/")
.filter { it.isNotBlank() }
.toList()
if (pathParts.size != parts.size) {
return Pat... | 0 | Kotlin | 0 | 8 | 4f86715b99e48120f700cab957c55066ac0f7d66 | 2,875 | indikate | MIT License |
graph/MaximumFlow.kt | wangchaohui | 737,511,233 | false | {"Kotlin": 36737} | class MaximumFlow(vertexSize: Int, private val s: Int, private val t: Int) {
data class Edge(
val u: Int,
val v: Int,
var capacity: Int,
var flow: Int = 0,
) {
lateinit var reverse: Edge
}
private val level = IntArray(vertexSize)
private val edges = Array(ver... | 0 | Kotlin | 0 | 0 | 241841f86fdefa9624e2fcae2af014899a959cbe | 1,905 | kotlin-lib | Apache License 2.0 |
백준/문제 추천 시스템 Version 1.kt | jisungbin | 382,889,087 | false | null | import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.util.TreeMap
private enum class ProblemType {
EASY, HARD
}
private val solvedProblemNumbers = mutableListOf<Int>()
private val problemsTree = TreeMap<Int, TreeMap<Int, Int>>()... | 0 | Kotlin | 1 | 10 | ee43375828ca7e748e7c79fbed63a3b4d27a7a2c | 2,638 | algorithm-code | MIT License |
src/day04/Day04.kt | daniilsjb | 726,047,752 | false | {"Kotlin": 66638, "Python": 1161} | package day04
import java.io.File
import kotlin.math.pow
fun main() {
val data = parse("src/day04/Day04.txt")
println("🎄 Day 04 🎄")
println()
println("[Part 1]")
println("Answer: ${part1(data)}")
println()
println("[Part 2]")
println("Answer: ${part2(data)}")
}
private fun Stri... | 0 | Kotlin | 0 | 0 | 46a837603e739b8646a1f2e7966543e552eb0e20 | 1,178 | advent-of-code-2023 | MIT License |
src/Day05.kt | ChrisCrisis | 575,611,028 | false | {"Kotlin": 31591} | import java.io.File
data class MovementOperation(
val from: Int,
val to: Int,
val amount: Int,
)
data class StorageSlot(
//val slotId: Int,
val currentContainer: List<Char>,
)
data class InputData(
val craneSlots: List<StorageSlot>,
val moves: List<MovementOpera... | 1 | Kotlin | 0 | 0 | 732b29551d987f246e12b0fa7b26692666bf0e24 | 3,574 | aoc2022-kotlin | Apache License 2.0 |
src/main/kotlin/io/github/pshegger/aoc/y2020/Y2020D23.kt | PsHegger | 325,498,299 | false | null | package io.github.pshegger.aoc.y2020
import io.github.pshegger.aoc.common.BaseSolver
import io.github.pshegger.aoc.common.TaskVisualizer
import io.github.pshegger.aoc.y2020.visualization.Y2020D23Visualizer
class Y2020D23 : BaseSolver() {
override val year = 2020
override val day = 23
override fun getVisu... | 0 | Kotlin | 0 | 0 | 346a8994246775023686c10f3bde90642d681474 | 3,650 | advent-of-code | MIT License |
src/Day04.kt | faragogergo | 573,451,927 | false | {"Kotlin": 4406} | fun main() {
fun String.range(): IntRange {
val (start, end) = split("-")
return IntRange(start.toInt(), end.toInt())
}
fun String.rangePair(): Pair<IntRange, IntRange> {
val (first, second) = split(",")
return Pair(first.range(), second.range())
}
fun IntRange.c... | 0 | Kotlin | 0 | 0 | 47dce5333f3c3e74d02ac3aaf51501069ff615bc | 791 | Advent_of_Code_2022 | Apache License 2.0 |
src/main/kotlin/com/jacobhyphenated/day18/Day18.kt | jacobhyphenated | 572,119,677 | false | {"Kotlin": 157591} | package com.jacobhyphenated.day18
import com.jacobhyphenated.Day
import com.jacobhyphenated.day15.PathCost
import java.io.File
import java.util.*
// Many Worlds Interpretation
class Day18: Day<List<List<Char>>> {
override fun getInput(): List<List<Char>> {
return createGrid(
this.javaClass.cla... | 0 | Kotlin | 0 | 0 | 1a0b9cb6e9a11750c5b3b5a9e6b3d63649bf78e4 | 8,796 | advent2019 | The Unlicense |
src/main/kotlin/dev/bogwalk/batch0/Problem7.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch0
import dev.bogwalk.util.maths.isPrime
/**
* Problem 7: The 10001st Prime
*
* https://projecteuler.net/problem=7
*
* Goal: Find the Nth prime number.
*
* Constraints: 1 <= N <= 10_001
*
* e.g.: N = 6
* primes = {2,3,5,7,11,13,...}
* 6th prime = 13
*/
class The10001st... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 1,718 | project-euler-kotlin | MIT License |
src/test/kotlin/Day04.kt | christof-vollrath | 317,635,262 | false | null | import io.kotest.core.datatest.forAll
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
/*
--- Day 4: Passport Processing ---
See https://adventofcode.com/2020/day/4
*/
fun parsePassportStrings(passportsString: String): List<String> =
passportsString.split("""\n\s*\n""".toRegex())
fu... | 1 | Kotlin | 0 | 0 | 8ad08350aa4bd1a29b7e18765fc7a2d6de8021e8 | 8,018 | advent_of_code_2020 | Apache License 2.0 |
src/day4/day4.kt | bienenjakob | 573,125,960 | false | {"Kotlin": 53763} | package day4
import inputTextOfDay
import testTextOfDay
val input = inputTextOfDay(4)
fun getInput(input: String): List<Pair<Set<Int>, Set<Int>>> {
return input.lines().map {
it.split(',','-').map(String::toInt)
.let{ (a,b,c,d)
-> (a..b).toSet() to (c..d).toSet() }
}
}
fun... | 0 | Kotlin | 0 | 0 | 6ff34edab6f7b4b0630fb2760120725bed725daa | 801 | aoc-2022-in-kotlin | Apache License 2.0 |
day21/kotlin/corneil/src/main/kotlin/solution.kt | jensnerche | 317,661,818 | true | {"HTML": 2739009, "Java": 348790, "Kotlin": 271602, "TypeScript": 262310, "Python": 198318, "JetBrains MPS": 191916, "Groovy": 125347, "Jupyter Notebook": 116902, "C++": 101742, "Dart": 47762, "Haskell": 43633, "CSS": 35030, "Ruby": 27091, "JavaScript": 13242, "Scala": 11409, "Dockerfile": 10370, "PHP": 4152, "Go": 283... | package com.github.corneil.aoc2019.day21
import com.github.corneil.aoc2019.intcode.Program
import com.github.corneil.aoc2019.intcode.readProgram
import java.io.File
fun makeInput(input: String): List<Long> {
val lines = input.trim().split('\n')
return lines.map { it.trim().map { it.toLong() } + 10L }.flatten(... | 0 | HTML | 0 | 0 | a84c00ddbeb7f9114291125e93871d54699da887 | 1,658 | aoc-2019 | MIT License |
src/Day24.kt | underwindfall | 573,471,357 | false | {"Kotlin": 42718} | fun main() {
day24Part(1)
day24Part(2)
}
fun day24Part(part: Int) {
val dayId = "24"
val input = readInput("Day${dayId}")
val a = input.toCharArray2()
val (n, m) = a.size2()
val (di, dj) = RDLU_DIRS
data class B(val i: Int, val j: Int, val d: Int)
val bs = a.mapIndexed2NotNull { i, ... | 0 | Kotlin | 0 | 0 | 0e7caf00319ce99c6772add017c6dd3c933b96f0 | 1,568 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem1146/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1146
/**
* LeetCode page: [1146. Snapshot Array](https://leetcode.com/problems/snapshot-array/);
*/
class SnapshotArray(length: Int) {
private var latestSnapId = -1
private val snapshots = Array(length) { mutableListOf(Record(latestSnapId, 0)) }
private val pendingC... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,129 | hj-leetcode-kotlin | Apache License 2.0 |
app/src/main/kotlin/com/github/ilikeyourhat/kudoku/model/dividers/RegionDivider.kt | ILikeYourHat | 139,063,649 | false | {"Kotlin": 166134} | package com.github.ilikeyourhat.kudoku.model.dividers
import com.github.ilikeyourhat.kudoku.model.Board
import com.github.ilikeyourhat.kudoku.model.Field
import com.github.ilikeyourhat.kudoku.model.Region
import com.github.ilikeyourhat.kudoku.model.SudokuType
class RegionDivider {
private val dividers = mutableL... | 1 | Kotlin | 0 | 0 | b234b2de2edb753844c88ea3cd573444675fc1cf | 2,767 | Kudoku | Apache License 2.0 |
2021/src/main/kotlin/day7_fast.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import kotlin.math.abs
fun main() {
Day7Fast.run()
}
object Day7All {
@JvmStatic fun main(args: Array<String>) {
mapOf("func" to Day7Func, "imp" to Day7Imp, "fast" to Day7Fast).forEach { (header, solution) ->
solution.run(header = header, skipPart1 = true, skipT... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,225 | aoc_kotlin | MIT License |
day04/src/Day04.kt | simonrules | 491,302,880 | false | {"Kotlin": 68645} | import java.io.File
class Day04(path: String) {
private var numbers: List<Int>
private val boards = mutableListOf<MutableList<Int>>()
private val won: MutableList<Boolean>
init {
val lines = File(path).readLines()
numbers = lines[0].split(',').map { it.toInt() }
val numBoards... | 0 | Kotlin | 0 | 0 | d9e4ae66e546f174bcf66b8bf3e7145bfab2f498 | 3,374 | aoc2021 | Apache License 2.0 |
kotlin/sort/NthElement.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package sort
import java.util.stream.IntStream
object NthElement {
// See: http://www.cplusplus.com/reference/algorithm/nth_element
// O(n) on average
fun nth_element(a: IntArray, low: Int, high: Int, n: Int, rnd: Random) {
var low = low
var high = high
while (true) {
v... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 3,302 | codelibrary | The Unlicense |
src/main/kotlin/day06/Day6.kt | limelier | 725,979,709 | false | {"Kotlin": 48112} | package day06
import common.InputReader
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.sqrt
private fun waysToBeat(time: Long, recordDistance: Long): Long {
// terms of a quadratic inequality: timePressed^2 - time * timePressed + recordDistance >= 0
val a = 1L
val b = -time
val c ... | 0 | Kotlin | 0 | 0 | 0edcde7c96440b0a59e23ec25677f44ae2cfd20c | 1,266 | advent-of-code-2023-kotlin | MIT License |
src/main/kotlin/01.kts | reitzig | 318,492,753 | false | null | fun matchingPair(entries: List<Int>, target: Int): Pair<Int, Int>? {
val sortedEntries = entries.sorted();
var left = 0
var right = entries.lastIndex
while (left < right ) {
val sum = sortedEntries[left] + sortedEntries[right]
if (sum < target) {
left += 1
} else if ... | 0 | Kotlin | 0 | 0 | f17184fe55dfe06ac8897c2ecfe329a1efbf6a09 | 1,536 | advent-of-code-2020 | The Unlicense |
leetcode2/src/leetcode/n-queens.kt | hewking | 68,515,222 | false | null | package leetcode
import java.lang.StringBuilder
import java.util.*
/**
* 51. N皇后
* https://leetcode-cn.com/problems/n-queens/
* Created by test
* Date 2019/12/22 20:30
* Description
* n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。
上图为 8 皇后问题的一种解法。
给定一个整数 n,返回所有不同的 n 皇后问题的解决方案。
每一种解法包含一个明确的 n 皇后问题的棋子放置方案,... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 3,649 | leetcode | MIT License |
src/main/kotlin/Problem34.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | /**
* Digit factorials
*
* 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
*
* Find the sum of all numbers which are equal to the sum of the factorial of their digits.
*
* Note: As 1! = 1 and 2! = 2 are not sums they are not included.
*
* https://projecteuler.net/problem=34
*/
fun main() {
che... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 662 | project-euler | MIT License |
src/main/kotlin/Day13.kt | clechasseur | 264,758,910 | false | null | object Day13 {
private val input = """
0: 3
1: 2
2: 4
4: 4
6: 5
8: 6
10: 6
12: 6
14: 6
16: 8
18: 8
20: 8
22: 8
24: 10
26: 8
28: 8
30: 12
32: 14
34: 12
36: 1... | 0 | Kotlin | 0 | 0 | f3e8840700e4c71e59d34fb22850f152f4e6e739 | 2,334 | adventofcode2017 | MIT License |
2015/src/main/kotlin/day2_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.mapItems
fun main() {
Day2Func.run()
}
data class Box(val l: Int, val w: Int, val h: Int) {
val area: Int get() = 2*l*w + 2*w*h + 2*h*l
val slack: Int get() = minOf(l*w, w*h, h*l)
val smallestPerimeter: Int get() = minOf(2*(l+w), 2*(w+h), 2*(h+l))
va... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 749 | aoc_kotlin | MIT License |
src/main/kotlin/g0201_0300/s0273_integer_to_english_words/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0201_0300.s0273_integer_to_english_words
// #Hard #String #Math #Recursion #Udemy_Strings
// #2022_11_03_Time_273_ms_(82.93%)_Space_35.5_MB_(87.80%)
import java.util.StringJoiner
class Solution {
private val ones = arrayOf(
"One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", ... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,067 | LeetCode-in-Kotlin | MIT License |
src/day22/b/day22b.kt | pghj | 577,868,985 | false | {"Kotlin": 94937} | package day22.b
import readInputLines
import shouldBe
import util.IntVector
import vec
import java.util.regex.Pattern
import kotlin.math.sqrt
fun main() {
val input = read()
val c = input.cube
var s = c.faces[vec(0, 0, 1)]!!
var p = vec(0, c.size - 1)
var d = vec(1, 0)
val valid = 0 until c.... | 0 | Kotlin | 0 | 0 | 4b6911ee7dfc7c731610a0514d664143525b0954 | 7,705 | advent-of-code-2022 | Apache License 2.0 |
src/Day08.kt | karloti | 573,006,513 | false | {"Kotlin": 25606} | fun part1(a: Array<IntArray>): Int {
val n = a.size
val m = a[0].size
val b = Array(n) { BooleanArray(m) }
var hIndex: Int
var h1: Int
var h2: Int
for (i in 0 until n) {
hIndex = 0
h1 = -1
for (j in 0 until m) {
if (a[i][j] > h1) {
h1 = a[i... | 0 | Kotlin | 1 | 2 | 39ac1df5542d9cb07a2f2d3448066e6e8896fdc1 | 2,717 | advent-of-code-2022-kotlin | Apache License 2.0 |
src/Day06.kt | max-zhilin | 573,066,300 | false | {"Kotlin": 114003} | fun main() {
fun part1(input: List<String>): Int {
var buf = ""
input[0].forEachIndexed() { pos, c ->
buf += c
val set = mutableSetOf<Char>()
buf.forEach { b ->
set.add(b)
if (set.size == 4) {
return pos + 1
... | 0 | Kotlin | 0 | 0 | d9dd7a33b404dc0d43576dfddbc9d066036f7326 | 1,531 | AoC-2022 | Apache License 2.0 |
src/main/kotlin/algorithms/NumUtils.kt | xmmmmmovo | 280,634,710 | false | null | /*
* Copyright (c) 2020. xmmmmmovo
*/
package algorithms
import ds.LinkedList
import edu.princeton.cs.algs4.StdRandom
import ext.compareTo
/**
* 蛮力法求三数之和
* @author xmmmmmovo
* @date 2020/7/28 16:09
* @param list 数字列表
* @param num 所求的数字
* @return 满足条件的个数
* @since version-1.0
*/
fun threeSumForce(list: List<I... | 0 | Kotlin | 0 | 0 | 94da0519cf2b8d8a9b42b4aea09caf50d9732599 | 3,724 | Algorithms4thEditionKotlinSolutions | Apache License 2.0 |
src/Day06.kt | iownthegame | 573,926,504 | false | {"Kotlin": 68002} | fun main() {
fun findFirstMessage(n: Int, input: String): Int {
val length = input.length
for (i in 0 until length) {
val string = input.substring(i, i + n)
if (string.toSet().size == n) {
return i + n
}
}
return 0
}
fun pa... | 0 | Kotlin | 0 | 0 | 4e3d0d698669b598c639ca504d43cf8a62e30b5c | 1,261 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/icu/trub/aoc/day12/SpringRegistry.kt | dtruebin | 728,432,747 | false | {"Kotlin": 76202} | package icu.trub.aoc.day12
import kotlin.time.measureTimedValue
internal class SpringRegistry(val records: List<Record>) {
fun countPossibleArrangements(debug: Boolean = false) = records.map {
val (arrangements, duration) = measureTimedValue { it.countPossibleArrangements() }
if (debug && duration... | 0 | Kotlin | 0 | 0 | 1753629bb13573145a9781f984a97e9bafc34b6d | 4,121 | advent-of-code | MIT License |
src/Day25.kt | Kietyo | 573,293,671 | false | {"Kotlin": 147083} | import kotlin.math.absoluteValue
fun Long.pow(num: Int): Long {
var curr = 1L
repeat(num) {
curr *= this
}
return curr
}
fun calculateMaxSnafu(n: Int): Long {
var sum = 0L
for (i in 0 until n) {
val currPosition = i
val fiveOrder = 5L.pow(currPosition)
sum += fi... | 0 | Kotlin | 0 | 0 | dd5deef8fa48011aeb3834efec9a0a1826328f2e | 5,279 | advent-of-code-2022-kietyo | Apache License 2.0 |
src/commonMain/kotlin/org/parserkt/pat/complex/TriePattern.kt | ParserKt | 242,278,819 | false | null | package org.parserkt.pat.complex
import org.parserkt.*
import org.parserkt.util.*
import org.parserkt.pat.*
// File: pat/complex/TriePattern
class MapPattern<K, V>(val map: Map<K, V>, private val noKey: Feed<K>.(K) -> V? = {notParsed}): PreetyPattern<K, V>() {
override fun read(s: Feed<K>): V? {
val key = s.pe... | 1 | Kotlin | 0 | 11 | 37599098dc9aafef7b509536e6d17ceca370d6cf | 2,318 | ParserKt | MIT License |
advent-of-code-2021/src/main/kotlin/eu/janvdb/aoc2021/day24/Transform.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2021.day24
import eu.janvdb.aocutil.kotlin.readLines
const val FILENAME = "input24.txt"
val LINE_PATTERN = Regex("([a-z]{3}) ([a-z]) ?(.+)?")
fun main() {
var input = 0
val variables = mutableMapOf(
Pair("x", 0),
Pair("y", 0),
Pair("z", 0),
Pair("w", 0)
)
fun transform(line: String... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,213 | advent-of-code | Apache License 2.0 |
solutions/aockt/y2023/Y2023D16.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2023
import aockt.util.parse
import aockt.util.spacial.Area
import aockt.util.spacial.Direction
import aockt.util.spacial.Direction.*
import aockt.util.spacial.Point
import aockt.util.spacial.move
import aockt.y2023.Y2023D16.Element.*
import io.github.jadarma.aockt.core.Solution
object Y2023D16 : Solut... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 4,740 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/days/aoc2022/Day23.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2022
import days.Day
import util.Point2d
class Day23 : Day(2022, 23) {
override fun partOne(): Any {
return calculateEmptyLandOnMinimalRectangleAfterRounds(inputList, 10)
}
override fun partTwo(): Any {
return calculateRoundWithNoMovingElves(inputList)
}
fun calcu... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 6,326 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/day01/Day01.kt | hamerlinski | 572,951,914 | false | {"Kotlin": 25910} | package day01
import readInput
fun main() {
fun prepareElves(input: List<String>): Elves {
val inputIterator = input.iterator();
val elvesList = mutableListOf<Elf>()
val temporaryList = mutableListOf<Int>()
inputIterator.forEach {
if (it == "") {
val tem... | 0 | Kotlin | 0 | 0 | bbe47c5ae0577f72f8c220b49d4958ae625241b0 | 1,132 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day05/Day05.kt | brhliluk | 572,914,305 | false | {"Kotlin": 16006} | fun main() {
val matcher = Regex("move (\\d.*) from (\\d) to (\\d)")
fun parseInput(input: List<String>, inputLinesLen: Int = 7, step: Int = 4, crateTowers: Int = 9): List<MutableList<Char>> {
val dock = Array(crateTowers) { Array<Char?>(inputLinesLen + 1) { null } }
for (i in 0..inputLinesLen)... | 0 | Kotlin | 0 | 0 | 96ac4fe0c021edaead8595336aad73ef2f1e0d06 | 1,567 | kotlin-aoc | Apache License 2.0 |
src/main/kotlin/com/groundsfam/advent/y2022/d09/Day09.kt | agrounds | 573,140,808 | false | {"Kotlin": 281620, "Shell": 742} | package com.groundsfam.advent.y2022.d09
import com.groundsfam.advent.DATAPATH
import com.groundsfam.advent.timed
import kotlin.io.path.div
import kotlin.io.path.useLines
import kotlin.math.abs
data class Move(val direction: Char, val times: Int)
fun trackTail(moves: List<Move>, numKnots: Int): Int {
val knotsX =... | 0 | Kotlin | 0 | 1 | c20e339e887b20ae6c209ab8360f24fb8d38bd2c | 1,928 | advent-of-code | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1234/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1234
/**
* LeetCode page: [1234. Replace the Substring for Balanced String](https://leetcode.com/problems/replace-the-substring-for-balanced-string/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(1) where N is the length of s;
*/
fun balancedStrin... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,528 | hj-leetcode-kotlin | Apache License 2.0 |
Round 1C - B. Parenting Partnering/src/app.kt | amirkhanyana | 110,548,909 | false | {"Kotlin": 20514} | import java.util.*
data class TimeInterval(val from: Int, val to: Int) : Comparable<TimeInterval> {
val size: Int
get() = if (from > to)
24 * 60 - from + to
else to - from
override fun compareTo(other: TimeInterval): Int = from.compareTo(other.from)
}
data class ParentActivity(val... | 0 | Kotlin | 0 | 0 | 25a8e6dbd5843e9d4a054d316acc9d726995fffe | 2,765 | Google-Code-Jam-2017-Problem-Kotlin-Solutions | The Unlicense |
src/Day04.kt | LauwiMeara | 572,498,129 | false | {"Kotlin": 109923} | fun main() {
fun part1(input: List<List<IntRange>>): Int {
var count = 0
for (pair in input) {
val intersection = pair.first().intersect(pair.last())
if (intersection == pair.first().toSet() || intersection == pair.last().toSet()) {
count++
}
... | 0 | Kotlin | 0 | 1 | 34b4d4fa7e562551cb892c272fe7ad406a28fb69 | 871 | AoC2022 | Apache License 2.0 |
app/src/main/java/de/kauker/unofficial/grocy/utils/StringUtils.kt | aimok04 | 556,343,801 | false | {"Kotlin": 114124} | package de.kauker.unofficial.grocy.utils
import java.util.*
fun String.distanceTo(c: String): Double {
return similarity(this, c)
}
fun similarity(s1: String, s2: String): Double {
var longer = s1
var shorter = s2
if (s1.length < s2.length) { // longer should always have greater length
longer... | 0 | Kotlin | 0 | 3 | 9796c5ec845d32a38b7833ef62197112a775d578 | 1,376 | grocy-for-wear-os | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.