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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
archive/backups/Kata/kotlin-kata/src/main/kotlin/de/felixroske/mostfrequentlyusedwords/MostFrequentlyUsedWords.kt | roskenet | 295,683,964 | false | {"HTML": 708028, "Jupyter Notebook": 571597, "TeX": 547996, "Java": 447619, "Makefile": 214272, "JavaScript": 204557, "CMake": 113090, "Kotlin": 88563, "TypeScript": 61333, "Clojure": 36776, "CSS": 25303, "C++": 19374, "Red": 13104, "Python": 12901, "Shell": 12248, "SCSS": 5588, "Go": 4797, "Dockerfile": 2073, "C": 168... | package de.felixroske.mostfrequentlyusedwords
fun top3(s: String): List<String> {
val splitlist = s.split(' ', ';', '/', ':', '!', '?', ',', '.', '\n', '\t')
val tempMap = mutableMapOf<String, Int>()
splitlist.forEach {
val times: Int? = tempMap[it.toLowerCase()]
if(times == null) {
... | 0 | HTML | 1 | 0 | 39975a0248f2e390f799bdafde1170322267761b | 1,777 | playground | MIT License |
src/Day04.kt | JonasDBB | 573,382,821 | false | {"Kotlin": 17550} | private fun isRangeContained(r0: List<Int>, r1: List<Int>) =
r0[0] >= r1[0] && r0[1] <= r1[1] || r1[0] >= r0[0] && r1[1] <= r0[1]
private fun doesRangeOverlap(r0: List<Int>, r1: List<Int>) =
r0[0] <= r1[0] && r0[1] >= r1[0] || r1[0] <= r0[0] && r1[1] >= r0[0]
private fun part(input: List<List<List<Int>>>, pre... | 0 | Kotlin | 0 | 0 | 199303ae86f294bdcb2f50b73e0f33dca3a3ac0a | 834 | AoC2022 | Apache License 2.0 |
src/main/kotlin/g1501_1600/s1530_number_of_good_leaf_nodes_pairs/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1501_1600.s1530_number_of_good_leaf_nodes_pairs
// #Medium #Depth_First_Search #Tree #Binary_Tree
// #2023_06_12_Time_242_ms_(100.00%)_Space_39.1_MB_(100.00%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree node.
* class TreeNod... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,333 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/newtranx/eval/utils/func.kt | ansonxing23 | 460,949,156 | false | {"Kotlin": 86034, "TeX": 212} | package com.newtranx.eval.utils
import kotlin.math.ln
import kotlin.math.min
/**
* @Author: anson
* @Date: 2022/1/29 11:41 PM
*/
inline fun <T> zip(vararg lists: List<T>): List<List<T>> {
return zip(*lists, transform = { it })
}
inline fun <T, V> zip(vararg lists: List<T>, transform: (List<T>) -> V): List<V> ... | 0 | Kotlin | 0 | 0 | 2f5a970378f2aab67bed6fa6aa8ba61671b6204c | 3,889 | mt-metrics | Apache License 2.0 |
src/main/kotlin/days/Day3.kt | VictorWinberg | 433,748,855 | false | {"Kotlin": 26228} | package days
class Day3 : Day(3) {
override fun partOne(): Any {
val list = inputList[0].toList().map { mutableListOf(0, 0) }
inputList.forEach {
it.toList().map { i -> "$i".toInt() }.forEachIndexed { index, i -> list[index][i] += 1 }
}
val gammaRate = list.map { pair -... | 0 | Kotlin | 0 | 0 | d61c76eb431fa7b7b66be5b8549d4685a8dd86da | 1,277 | advent-of-code-kotlin | Creative Commons Zero v1.0 Universal |
src/main/kotlin/g0001_0100/s0040_combination_sum_ii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0001_0100.s0040_combination_sum_ii
// #Medium #Array #Backtracking #Algorithm_II_Day_10_Recursion_Backtracking
// #2023_07_05_Time_217_ms_(93.75%)_Space_38_MB_(89.06%)
import java.util.LinkedList
class Solution {
fun combinationSum2(candidates: IntArray, target: Int): List<List<Int>> {
val sums:... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,406 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/hackerrank/FormingAMagicSquare.kt | iluu | 94,996,114 | false | {"Java": 89400, "Kotlin": 14594, "Scala": 1758, "Haskell": 776} | package com.hackerrank
import java.util.*
val magicSquares = arrayOf(
intArrayOf(8, 1, 6, 3, 5, 7, 4, 9, 2),
intArrayOf(4, 3, 8, 9, 5, 1, 2, 7, 6),
intArrayOf(2, 9, 4, 7, 5, 3, 6, 1, 8),
intArrayOf(6, 7, 2, 1, 5, 9, 8, 3, 4),
intArrayOf(6, 1, 8, 7, 5, 3, 2, 9, 4),
intAr... | 0 | Java | 3 | 5 | a89b0d332a3d4a257618e9ae6c7f898cb1695246 | 925 | algs-progfun | MIT License |
src/main/kotlin/com/staricka/adventofcode2023/days/Day21.kt | mathstar | 719,656,133 | false | {"Kotlin": 107115} | package com.staricka.adventofcode2023.days
import com.staricka.adventofcode2023.days.GardenCell.Companion.toGardenCell
import com.staricka.adventofcode2023.framework.Day
import com.staricka.adventofcode2023.util.Grid
import com.staricka.adventofcode2023.util.GridCell
import com.staricka.adventofcode2023.util.StandardG... | 0 | Kotlin | 0 | 0 | 8c1e3424bb5d58f6f590bf96335e4d8d89ae9ffa | 2,405 | adventOfCode2023 | MIT License |
src/main/kotlin/Day09.kt | gijs-pennings | 573,023,936 | false | {"Kotlin": 20319} | import kotlin.math.abs
import kotlin.math.max
fun main() {
val n = 10 // use n=2 for part 1
val knots = List(n) { MutablePos() }
val allTailPos = mutableSetOf(knots.last().copy())
for (line in readInput(9)) {
repeat(line.substring(line.indexOf(' ') + 1).toInt()) {
knots.first().mov... | 0 | Kotlin | 0 | 0 | 8ffbcae744b62e36150af7ea9115e351f10e71c1 | 1,037 | aoc-2022 | ISC License |
src/main/kotlin/se/brainleech/adventofcode/aoc2021/Aoc2021Day14.kt | fwangel | 435,571,075 | false | {"Kotlin": 150622} | package se.brainleech.adventofcode.aoc2021
import se.brainleech.adventofcode.compute
import se.brainleech.adventofcode.readLines
import se.brainleech.adventofcode.sortedByChar
import se.brainleech.adventofcode.verify
import java.util.*
class Aoc2021Day14 {
companion object {
private const val PADDED_ARRO... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 5,815 | adventofcode | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem688/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem688
/**
* LeetCode page: [688. Knight Probability in Chessboard](https://leetcode.com/problems/knight-probability-in-chessboard/);
*/
class Solution {
/* Complexity:
* Time O(k * n^2) and Space O(k * n^2);
*/
fun knightProbability(n: Int, k: Int, row: Int, colu... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,995 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/g2301_2400/s2322_minimum_score_after_removals_on_a_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2301_2400.s2322_minimum_score_after_removals_on_a_tree
// #Hard #Array #Depth_First_Search #Tree #Bit_Manipulation
// #2023_06_30_Time_412_ms_(100.00%)_Space_49.1_MB_(100.00%)
class Solution {
private var ans = Int.MAX_VALUE
// function to travel 2nd time on the tree and find the second edge to be r... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 3,624 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/biodivine/algebra/UnivariatePolynomialTools.kt | daemontus | 160,796,526 | false | null | package biodivine.algebra
import biodivine.algebra.svg.zero
import cc.redberry.rings.Rings
import cc.redberry.rings.Rings.Q
import cc.redberry.rings.bigint.BigInteger
import cc.redberry.rings.poly.univar.UnivariatePolynomial
val coder = Rings.UnivariateRingQ.mkCoder("x")
/**
* TODO: Here, we assume this goes up to ... | 0 | Kotlin | 0 | 0 | ed4fd35015b73ea3ac36aecb1c5a568f6be7f14c | 2,705 | biodivine-algebraic-toolkit | MIT License |
src/main/kotlin/sk/mkiss/algorithms/sort/QuickSort.kt | marek-kiss | 430,858,906 | false | {"Kotlin": 85343} | package sk.mkiss.algorithms.sort
object QuickSort : SortAlgorithm() {
override fun <T : Comparable<T>> sort(array: Array<T>): Array<T> {
quickSort(array, 0, array.size)
return array
}
private fun <T : Comparable<T>> quickSort(array: Array<T>, startIndex: Int, endIndex: Int) {
if (... | 0 | Kotlin | 0 | 0 | 296cbd2e04a397597db223a5721b6c5722eb0c60 | 1,636 | algo-in-kotlin | MIT License |
src/jvmMain/kotlin/day11/initial/Grid.kt | liusbl | 726,218,737 | false | {"Kotlin": 109684} | package day11.initial
import util.set
data class Grid<T>(
// TODO this can be improved by forcing creation by row list or column list.
// Now this is ambiguous, but indeded to be created from flattened row list
private val locationList: List<Location<T>>
) {
val rowList: List<List<Location<T>>> = loc... | 0 | Kotlin | 0 | 0 | 1a89bcc77ddf9bc503cf2f25fbf9da59494a61e1 | 2,673 | advent-of-code | MIT License |
src/main/kotlin/com/kishor/kotlin/algo/algorithms/graph/CycleInGraph.kt | kishorsutar | 276,212,164 | false | null | package com.kishor.kotlin.algo.algorithms.graph
fun main() {
val edges = listOf(listOf(1, 3), listOf(2 ,3, 4), listOf(0), emptyList(), listOf(2, 5), emptyList())
cycleInGraph(edges)
}
fun cycleInGraph(edges: List<List<Int>>): Boolean {
val numberOfEdges = edges.size
val visited = BooleanArray(number... | 0 | Kotlin | 0 | 0 | 6672d7738b035202ece6f148fde05867f6d4d94c | 1,173 | DS_Algo_Kotlin | MIT License |
src/day4/Day04.kt | behnawwm | 572,034,416 | false | {"Kotlin": 11987} | package day4
import readInput
fun main() {
val fileLines = readInput("day04", "day4")
fun String.parseInput(): Pair<IntRange, IntRange> {
val (s1, e1) = substringBefore(",").split("-").map { it.toInt() }
val (s2, e2) = substringAfter(",").split("-").map { it.toInt() }
val range1 = s1.... | 0 | Kotlin | 0 | 2 | 9d1fee54837cfae38c965cc1a5b267d7d15f4b3a | 1,103 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/io/github/clechasseur/adventofcode/y2022/Day21.kt | clechasseur | 567,968,171 | false | {"Kotlin": 493887} | package io.github.clechasseur.adventofcode.y2022
import io.github.clechasseur.adventofcode.y2022.data.Day21Data
object Day21 {
private val input = Day21Data.input
fun part1(): Long {
val monkeys = input.toMonkeys()
return monkeys["root"]!!.equation(monkeys).value.toLong()
}
fun part2... | 0 | Kotlin | 0 | 0 | 7ead7db6491d6fba2479cd604f684f0f8c1e450f | 3,554 | adventofcode2022 | MIT License |
data_structures/x_fast_trie/Kotlin/XFastTrie.kt | ZoranPandovski | 93,438,176 | false | {"Jupyter Notebook": 21909905, "C++": 1692994, "Python": 1158220, "Java": 806066, "C": 560110, "JavaScript": 305918, "Go": 145277, "C#": 117882, "PHP": 85458, "Kotlin": 72238, "Rust": 53852, "Ruby": 43243, "MATLAB": 34672, "Swift": 31023, "Processing": 22089, "HTML": 18961, "Haskell": 14298, "Dart": 11842, "CSS": 10509... | /**
* X-fast trie is a data structure for storing integers from a bounded domain
* More info about the structure and complexity here: https://en.wikipedia.org/wiki/X-fast_trie
*/
class XFastTrie(domain: Long) {
private class Node(var left: Node? = null, var right: Node? = null,
var leftA... | 62 | Jupyter Notebook | 1,994 | 1,298 | 62a1a543b8f3e2ca1280bf50fc8a95896ef69d63 | 7,069 | al-go-rithms | Creative Commons Zero v1.0 Universal |
src/Day08.kt | carloxavier | 574,841,315 | false | {"Kotlin": 14082} | fun main() {
check(
ForestRanger(readInput("Day08_test"))
.getTreesVisibleFromOutside()
.size == 21
)
check(
ForestRanger(readInput("Day08_test"))
.getMaxVisibilityIndex() == 8
)
// Part1
println(
ForestRanger(readInput("Day08"))
... | 0 | Kotlin | 0 | 0 | 4e84433fe866ce1a8c073a7a1e352595f3ea8372 | 4,051 | adventOfCode2022 | Apache License 2.0 |
rmq/RangeUpdateSegmentTree.kt | wangchaohui | 737,511,233 | false | {"Kotlin": 36737} | class RangeUpdateSegmentTree(private val n: Int) {
data class Interval(
var b: Int = 0,
var v: Int = 1000000,
)
private val t = Array(n * 2) { Interval() }
private fun set(p: Int, b: Int, v: Int) {
if (p !in t.indices || t[p].v < v) return
t[p].b = b
t[p].v = v
... | 0 | Kotlin | 0 | 0 | 241841f86fdefa9624e2fcae2af014899a959cbe | 1,883 | kotlin-lib | Apache License 2.0 |
src/Day10.kt | olezhabobrov | 572,687,414 | false | {"Kotlin": 27363} | import java.lang.Math.abs
fun main() {
fun part1(input: List<String>): Int {
var counter = 0
var result = 0
input.fold(1) { cur, s ->
val lst = s.split(" ")
var new = cur
if (lst.size == 1) {
counter++
} else {
... | 0 | Kotlin | 0 | 0 | 31f2419230c42f72137c6cd2c9a627492313d8fb | 1,743 | AdventOfCode | Apache License 2.0 |
day5/src/main/kotlin/aoc2015/day5/Day5.kt | sihamark | 581,653,112 | false | {"Kotlin": 263428, "Shell": 467, "Batchfile": 383} | package aoc2015.day5
/**
* [https://adventofcode.com/2015/day/5]
*/
object Day5 {
fun validatePart1() = countValid(Part1Validator())
fun validatePart2() = countValid(Part2Validator()).also {
assert(it == 53) { "there should be 53 valid string in part two" }
}
private fun countValid(validator... | 0 | Kotlin | 0 | 0 | 6d10f4a52b8c7757c40af38d7d814509cf0b9bbb | 2,679 | aoc2015 | Apache License 2.0 |
solutions/src/CountSortedVowelStrings.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | /**
* https://leetcode.com/problems/count-sorted-vowel-strings/
*/
class CountSortedVowelStrings {
fun countVowelStrings(n: Int): Int {
if (n == 1) {
return 5
}
val vowelMap : MutableMap<Pair<Int,Char>,Int> = mutableMapOf()
val vowels = mutableListOf('a','e','i','o','... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 2,402 | leetcode-solutions | MIT License |
cz.wrent.advent/Day12.kt | Wrent | 572,992,605 | false | {"Kotlin": 206165} | package cz.wrent.advent
fun main() {
println(partOne(test))
val result = partOne(input)
println("12a: $result")
println(partTwo(test))
println("12b: ${partTwo(input)}")
}
private fun partOne(input: String): Int {
val map = input.parse()
val start = map.entries.find { it.value.specialArea == SpecialArea.START }... | 0 | Kotlin | 0 | 0 | 8230fce9a907343f11a2c042ebe0bf204775be3f | 6,991 | advent-of-code-2022 | MIT License |
src/main/kotlin/dev/bogwalk/batch4/Problem44.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch4
import dev.bogwalk.util.maths.isPentagonalNumber
/**
* Problem 44: Pentagon Numbers
*
* https://projecteuler.net/problem=44
*
* Goal: For a given K, find all P_n, where n < N, such that P_n - P_(n-K) || P_n + P_(n-K) is
* also pentagonal.
*
* Constraints: 1 <= K <= 9999, K+1 <= N <=... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 2,123 | project-euler-kotlin | MIT License |
src/Day02.kt | bkosm | 572,912,735 | false | {"Kotlin": 17839} | import Shape.Paper
import Shape.Rock
import Shape.Scissors
enum class Shape(val score: Int) {
Rock(1), Paper(2), Scissors(3);
}
val beatsMapping = mapOf(
Rock to Scissors,
Paper to Rock,
Scissors to Paper,
)
val codeMapping = mapOf(
"A" to Rock,
"B" to Paper,
"C" to Scissors,
"X" to R... | 0 | Kotlin | 0 | 1 | 3f9cccad1e5b6ba3e92cbd836a40207a2f3415a4 | 1,419 | aoc22 | Apache License 2.0 |
src/main/kotlin/sschr15/aocsolutions/Day12.kt | sschr15 | 317,887,086 | false | {"Kotlin": 184127, "TeX": 2614, "Python": 446} | package sschr15.aocsolutions
import sschr15.aocsolutions.util.*
/**
* AOC 2023 [Day 12](https://adventofcode.com/2023/day/12)
* Challenge: figure out just how messed up all these spring layouts are
*/
object Day12 : Challenge {
@ReflectivelyUsed
override fun solve() = challenge(2023, 12) {
// test()... | 0 | Kotlin | 0 | 0 | e483b02037ae5f025fc34367cb477fabe54a6578 | 3,223 | advent-of-code | MIT License |
2022/src/main/kotlin/de/skyrising/aoc2022/day7/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2022.day7
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.objects.Object2LongMap
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap
import java.nio.file.Path
private fun parseInput(input: PuzzleInput): Object2LongMap<Path> {
val commands = mutableListOf<Pair<String, List<St... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 2,237 | aoc | MIT License |
src/main/kotlin/07-aug.kt | aladine | 276,334,792 | false | {"C++": 70308, "Kotlin": 53152, "Java": 10020, "Makefile": 511} | /**
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree node.
* class TreeNode(var `val`: Int) {
* var left: TreeNode? = null
* var right: TreeNode? = null
* }
*/
import java.util.*
class Aug07Solution {
var offset = 0
fun dfs(n: TreeNode?, x: Int, y: Int, map... | 0 | C++ | 1 | 1 | 54b7f625f6c4828a72629068d78204514937b2a9 | 2,589 | awesome-leetcode | Apache License 2.0 |
src/test/kotlin/be/brammeerten/y2023/Day8OtherTest.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2023
import be.brammeerten.extractRegexGroups
import be.brammeerten.readFile
import be.brammeerten.toCharList
import org.junit.jupiter.api.Test
class Day8OtherTest {
@Test
fun `part 2`() {
val lines = readFile("2023/day8/input.txt")
val instructions = lines[0].toCharLi... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 3,107 | Advent-of-Code | MIT License |
src/day03/Day03.kt | skokovic | 573,361,100 | false | {"Kotlin": 12166} | package day03
import readInput
fun calculateScore(char: Char): Int {
if(char.isUpperCase()) {
return char.code - 38
}
return char.code - 96
}
fun main() {
fun part1(input: List<String>): Int {
var sum = 0
input.forEach { sack ->
val size = sack.length
... | 0 | Kotlin | 0 | 0 | fa9aee3b5dd09b06bfd5c232272682ede9263970 | 1,186 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/SubstringFinder.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,790 | kotlab | Apache License 2.0 |
src/Day06.kt | ked4ma | 573,017,240 | false | {"Kotlin": 51348} | /**
* [Day06](https://adventofcode.com/2022/day/6)
*/
fun main() {
fun findMarker(input: String, len: Int) : Int{
val map = mutableMapOf<Char, Int>()
(0 until len - 1).forEach {
map[input[it]] = map.getOrDefault(input[it], 0) + 1
}
for (i in len - 1 until input.length) ... | 1 | Kotlin | 0 | 0 | 6d4794d75b33c4ca7e83e45a85823e828c833c62 | 1,189 | aoc-in-kotlin-2022 | Apache License 2.0 |
src/day18/solution.kt | bohdandan | 729,357,703 | false | {"Kotlin": 80367} | package day18
import Direction
import Position
import assert
import plus
import println
import readInput
import times
import kotlin.math.absoluteValue
fun main() {
class Command(val direction: Direction, val steps: Int, val hexColor: Int)
fun parse(input: List<String>): List<Command> {
return input.m... | 0 | Kotlin | 0 | 0 | 92735c19035b87af79aba57ce5fae5d96dde3788 | 1,907 | advent-of-code-2023 | Apache License 2.0 |
src/main/kotlin/com/gitTraining/Fibbonaci.kt | woody-lam | 383,797,784 | true | {"Kotlin": 6393} | package com.gitTraining
fun computeFibbonaciNumber(position: Int?, recursion: Boolean = false): Int {
if (recursion) return recursiveFibbonachi(position!!)
var notNullPosition = position
if (notNullPosition == null) {
notNullPosition = 1
}
if (position == 0) return 0
if (position != nul... | 0 | Kotlin | 0 | 0 | c9c8885afd59dd3f4700ad632759d5e01cf16806 | 2,353 | git-training-rebasing | MIT License |
foundry-math/src/main/kotlin/com/valaphee/foundry/math/Partition.kt | valaphee | 372,059,969 | false | {"Kotlin": 267615} | /*
* Copyright (c) 2021-2022, Valaphee.
*
* 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 ag... | 0 | Kotlin | 0 | 3 | 7e49a4507aa59cebefe928c4aa42f02182f95904 | 2,705 | foundry | Apache License 2.0 |
year2021/day23/amphipod/src/main/kotlin/com/curtislb/adventofcode/year2021/day23/amphipod/BurrowGraph.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.year2021.day23.amphipod
import com.curtislb.adventofcode.common.collection.replaceAt
import com.curtislb.adventofcode.common.graph.WeightedGraph
import com.curtislb.adventofcode.common.range.size
/**
* A graph with edges from each possible [Burrow] state to new [Burrow] states that ... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 5,130 | AdventOfCode | MIT License |
src/test/kotlin/io/github/aarjavp/aoc/day10/Day10Test.kt | AarjavP | 433,672,017 | false | {"Kotlin": 73104} | package io.github.aarjavp.aoc.day10
import io.kotest.matchers.ints.shouldBeExactly
import io.kotest.matchers.longs.shouldBeExactly
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestFactory
class Day10Test {
val solution ... | 0 | Kotlin | 0 | 0 | 3f5908fa4991f9b21bb7e3428a359b218fad2a35 | 2,269 | advent-of-code-2021 | MIT License |
day09/src/Day09.kt | simonrules | 491,302,880 | false | {"Kotlin": 68645} | import java.io.File
class Day09(private val path: String) {
private val map = mutableListOf<Int>()
private var height = 0
private var width = 0
init {
var i = 0
var j = 0
File(path).forEachLine { line ->
j = line.length
line.forEach {
map... | 0 | Kotlin | 0 | 0 | d9e4ae66e546f174bcf66b8bf3e7145bfab2f498 | 3,093 | aoc2021 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/NumOfWays.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 | 4,045 | kotlab | Apache License 2.0 |
src/main/kotlin/days/Day18.kt | hughjdavey | 317,575,435 | false | null | package days
class Day18 : Day(18) {
// 21993583522852
override fun partOne(): Any {
return inputList.map { doCalculation(it) }.sum()
}
// 122438593522757
override fun partTwo(): Any {
return inputList.map { doCalculation(it, true) }.sum()
}
fun doCalculation(expression: ... | 0 | Kotlin | 0 | 1 | 63c677854083fcce2d7cb30ed012d6acf38f3169 | 1,947 | aoc-2020 | Creative Commons Zero v1.0 Universal |
solutions/src/MatrixBlockSum.kt | JustAnotherSoftwareDeveloper | 139,743,481 | false | {"Kotlin": 305071, "Java": 14982} | import kotlin.math.max
import kotlin.math.min
/**
* https://leetcode.com/problems/matrix-block-sum/
*/
class MatrixBlockSum {
fun matrixBlockSum(mat: Array<IntArray>, K: Int) : Array<IntArray> {
val sumMatrix = Array(mat.size+1){IntArray(mat[0].size+1){0} };
val m = mat.size;
val n = mat... | 0 | Kotlin | 0 | 0 | fa4a9089be4af420a4ad51938a276657b2e4301f | 1,293 | leetcode-solutions | MIT License |
src/main/kotlin/days/Day22.kt | julia-kim | 569,976,303 | false | null | package days
import readInput
fun main() {
fun parseInput(input: List<String>): Pair<Array<CharArray>, List<String>> {
val blankLineIndex = input.indexOfFirst { it.isBlank() }
val board = input.subList(0, blankLineIndex).map {
it.map { char -> char }.toCharArray()
}.toTypedArra... | 0 | Kotlin | 0 | 0 | 65188040b3b37c7cb73ef5f2c7422587528d61a4 | 4,907 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/_2022/Day08.kt | novikmisha | 572,840,526 | false | {"Kotlin": 145780} | package _2022
import readInput
fun main() {
fun part1(input: List<String>): Int {
val intInput = input.map { it.map { char -> char.digitToInt() } }
val max_i = intInput.size
val max_j = intInput[0].size
var visibleInside = 0
for (i in 1 until max_i - 1) {
for (... | 0 | Kotlin | 0 | 0 | 0c78596d46f3a8bf977bf356019ea9940ee04c88 | 3,098 | advent-of-code | Apache License 2.0 |
src/day09/Day09.kt | molundb | 573,623,136 | false | {"Kotlin": 26868} | package day09
import readInput
import kotlin.math.abs
fun main() {
val input = readInput(parent = "src/day09", name = "Day09_input")
println(solvePartOne(input))
println(solvePartTwo(input))
}
private fun solvePartTwo(input: List<String>): Int {
val startPoint = Point(0, 0)
val tailVisitedPoint... | 0 | Kotlin | 0 | 0 | a4b279bf4190f028fe6bea395caadfbd571288d5 | 3,710 | advent-of-code-2022 | Apache License 2.0 |
算法/两数之和1.kt | Simplation | 506,160,986 | false | {"Kotlin": 10116} | package com.example.rain_demo.algorithm
/**
*@author: Rain
*@time: 2022/7/14 9:40
*@version: 1.0
*@description: 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。
*/
/**
* 输入:nums = [2,7,11,15], target = 9
* 输出:[0,1]
* 解释:因为 nums[0] + nums[1] ==... | 0 | Kotlin | 0 | 0 | d45feaa4c8ea2a08ce7357ee609a2df5b0639b68 | 2,790 | OpenSourceRepository | Apache License 2.0 |
src/main/kotlin/_2018/Day10.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2018
import aocRun
import parseInput
import java.util.*
import java.util.regex.Pattern
fun main() {
aocRun(puzzleInput) { input ->
val points = parsePoints(input)
val lastPoints = ArrayDeque<Pair<Int, Points>>()
val lastPointsMaxSize = 5
var lastArea = Long.MAX_VALUE
... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 17,442 | AdventOfCode | Creative Commons Zero v1.0 Universal |
solutions/aockt/y2023/Y2023D01.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2023
import aockt.util.parse
import io.github.jadarma.aockt.core.Solution
object Y2023D01 : Solution {
/** A map from digit symbols and spellings to their numerical values. */
private val textToDigit: Map<String, Int> = buildMap {
listOf("zero", "one", "two", "three", "four", "five", "... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 1,600 | advent-of-code-kotlin-solutions | The Unlicense |
src/Year2022Day03.kt | zhangt2333 | 575,260,256 | false | {"Kotlin": 34993} | import java.util.BitSet
fun main() {
fun Char.priority(): Int = when (this) {
in 'a'..'z' -> this - 'a' + 1
in 'A'..'Z' -> this - 'A' + 27
else -> throw IllegalArgumentException()
}
fun indexBitSet(items: String) = BitSet(60).apply {
items.forEach { this[it.priority()] = t... | 0 | Kotlin | 0 | 0 | cdba887c4df3a63c224d5a80073bcad12786ac71 | 990 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day10/Day10.kt | Ciel-MC | 572,868,010 | false | {"Kotlin": 55885} | package day10
import readInput
sealed interface Instruction {
fun run(state: State): Boolean
companion object {
fun parse(line: String): Instruction = when {
line.startsWith("addx ") -> AddX(line.drop(5).toInt())
line == "noop" -> NoOp
else -> throw IllegalArgumentE... | 0 | Kotlin | 0 | 0 | 7eb57c9bced945dcad4750a7cc4835e56d20cbc8 | 2,470 | Advent-Of-Code | Apache License 2.0 |
src/day08/Day08.kt | hamerlinski | 572,951,914 | false | {"Kotlin": 25910} | package day08
import readInput
fun main() {
val input = readInput("Day08", "day08")
val forest = Forest(input)
forest.plant()
println(forest.numOfVisibleTrees())
println(forest.highestScenicScore())
}
@Suppress("DuplicatedCode")
class Forest(private val input: List<String>) {
private val tree... | 0 | Kotlin | 0 | 0 | bbe47c5ae0577f72f8c220b49d4958ae625241b0 | 6,158 | advent-of-code-kotlin-2022 | Apache License 2.0 |
y2018/src/main/kotlin/adventofcode/y2018/Day03.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2018
import adventofcode.io.AdventSolution
object Day03 : AdventSolution(2018, 3, "No Matter How You Slice It") {
override fun solvePartOne(input: String): Int {
val claims = parseInput(input)
val fabric = applyClaimsToFabric(claims)
return fabric.count { it > 1 }
... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 1,654 | advent-of-code | MIT License |
facebook/2019/qualification/4/main.kt | seirion | 17,619,607 | false | {"C++": 801740, "HTML": 42242, "Kotlin": 37689, "Python": 21759, "C": 3798, "JavaScript": 294} | import java.util.*
fun main(args: Array<String>) {
val n = readLine()!!.toInt()
repeat(n) {
print("Case #${it + 1}: ")
solve()
}
}
data class T(val x: Int, val y:Int, val p: Int)
fun solve() {
fail = false
val (n, M) = readLine()!!.split(" ").map { it.toInt() }
val a = IntArra... | 0 | C++ | 4 | 4 | a59df98712c7eeceabc98f6535f7814d3a1c2c9f | 1,793 | code | Apache License 2.0 |
src/main/de/ddkfm/Day2.kt | DDKFM | 433,861,159 | false | {"Kotlin": 13522} | package de.ddkfm
import java.io.File
enum class CommandType {
FORWARD,
DOWN,
UP;
companion object {
fun parse(str : String) : CommandType {
return CommandType.valueOf(str.uppercase())
}
}
}
data class Command(
val type : CommandType,
val unit : Int
) {
fun s... | 0 | Kotlin | 0 | 0 | 6e147b526414ab5d11732dc32c18ad760f97ff59 | 1,658 | AdventOfCode21 | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem1696/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem1696
/**
* LeetCode page: [1696. Jump Game VI](https://leetcode.com/problems/jump-game-vi/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(N) where N is the size of nums;
*/
fun maxResult(nums: IntArray, k: Int): Int {
val maxScorePerIndex ... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 2,391 | hj-leetcode-kotlin | Apache License 2.0 |
src/Day02_part1.kt | jmorozov | 573,077,620 | false | {"Kotlin": 31919} | import java.util.EnumMap
fun main() {
val inputData = readInput("Day02")
var myTotalScore = 0
for (line in inputData) {
val trimmedLine = line.trim()
val opponent = ShapePart1.from(trimmedLine.take(1))
val mine = ShapePart1.from(trimmedLine.takeLast(1))
val shapePoints = mi... | 0 | Kotlin | 0 | 0 | 480a98838949dbc7b5b7e84acf24f30db644f7b7 | 1,452 | aoc-2022-in-kotlin | Apache License 2.0 |
implementation/src/main/kotlin/io/github/tomplum/aoc/map/volcano/OldVolcanoMap.kt | TomPlum | 572,260,182 | false | {"Kotlin": 224955} | package io.github.tomplum.aoc.map.volcano
import io.github.tomplum.libs.extensions.cartesianProduct
import java.util.*
class OldVolcanoMap(scan: List<String>) {
private val flowRates = mutableMapOf<String, Int>()
private val valves: Map<String, List<String>> = scan.associate { line ->
val label = lin... | 0 | Kotlin | 0 | 0 | 703db17fe02a24d809cc50f23a542d9a74f855fb | 4,485 | advent-of-code-2022 | Apache License 2.0 |
src/leetcodeProblem/leetcode/editor/en/DecodeWays.kt | faniabdullah | 382,893,751 | false | null | //A message containing letters from A-Z can be encoded into numbers using the
//following mapping:
//
//
//'A' -> "1"
//'B' -> "2"
//...
//'Z' -> "26"
//
//
// To decode an encoded message, all the digits must be grouped then mapped
//back into letters using the reverse of the mapping above (there may be multiple
... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 2,602 | dsa-kotlin | MIT License |
src/main/kotlin/adventofcode/y2021/Day18.kt | Tasaio | 433,879,637 | false | {"Kotlin": 117806} | import adventofcode.*
import java.math.BigInteger
import kotlin.math.ceil
import kotlin.math.floor
fun main() {
val testInput = """
[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]]
[[[5,[2,8]],4],[5,[[9,9],0]]]
[6,[[[6,2],[5,6]],[[7,6],[4,7]]]]
[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]]
[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9... | 0 | Kotlin | 0 | 0 | cc72684e862a782fad78b8ef0d1929b21300ced8 | 5,689 | adventofcode2021 | The Unlicense |
day12/src/main/kotlin/com/nohex/aoc/day12/CaveMap.kt | mnohe | 433,396,563 | false | {"Kotlin": 105740} | package com.nohex.aoc.day12
const val START_NAME = "start"
const val END_NAME = "end"
class CaveMap(input: Sequence<String>) {
val pathCount: Int
get() = getPaths { path, cave -> path.canVisit(cave) }.count()
val longPathCount: Int
get() = getPaths { path, cave -> path.canVisitTwice(cave) }.co... | 0 | Kotlin | 0 | 0 | 4d7363c00252b5668c7e3002bb5d75145af91c23 | 2,150 | advent_of_code_2021 | MIT License |
src/groundWar/ObjectiveFunctions.kt | hopshackle | 225,904,074 | false | null | package groundWar
import kotlin.math.ln
fun compositeScoreFunction(functions: List<(LandCombatGame, Int) -> Double>): (LandCombatGame, Int) -> Double {
return { game: LandCombatGame, player: Int ->
functions.map { f -> f(game, player) }.sum()
}
}
val interimScoreFunction = simpleScoreFunction(5.0, 1... | 0 | Kotlin | 0 | 0 | e5992d6b535b3f4a6552bf6f2351865a33d56248 | 5,610 | SmarterSims | MIT License |
Retos/Reto #19 - ANÁLISIS DE TEXTO [Media]/kotlin/malopezrom.kt | mouredev | 581,049,695 | false | {"Python": 3866914, "JavaScript": 1514237, "Java": 1272062, "C#": 770734, "Kotlin": 533094, "TypeScript": 457043, "Rust": 356917, "PHP": 281430, "Go": 243918, "Jupyter Notebook": 221090, "Swift": 216751, "C": 210761, "C++": 164758, "Dart": 159755, "Ruby": 70259, "Perl": 52923, "VBScript": 49663, "HTML": 45912, "Raku": ... | /*
* Crea un programa que analice texto y obtenga:
* - Número total de palabras.
* - Longitud media de las palabras.
* - Número de oraciones del texto (cada vez que aparecen un punto).
* - Encuentre la palabra más larga.
*
* Todo esto utilizando un único bucle.
*/
fun main(){
val text ="""
la luna ... | 4 | Python | 2,929 | 4,661 | adcec568ef7944fae3dcbb40c79dbfb8ef1f633c | 2,140 | retos-programacion-2023 | Apache License 2.0 |
src/Day01.kt | mr3y-the-programmer | 572,001,640 | false | {"Kotlin": 8306} | fun main() {
fun part1(input: List<String>): Int? {
return input
.split { line -> line.isBlank() }
.maxOfOrNull { elfCalories -> elfCalories.sumOf { it.toInt() } }
}
fun part2(input: List<String>): Int {
return input
.split { line -> line.isBlank() }
... | 0 | Kotlin | 0 | 0 | 96d1567f38e324aca0cb692be3dae720728a383d | 929 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/aoc2023/Day3.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2023
import days.Day
import util.Point2d
import java.awt.Point
class Day3 : Day(2023, 3) {
override fun partOne(): Any {
return calculatePartOne(inputList)
}
fun calculatePartOne(inputList: List<String>): Int {
var sum = 0
var currentNumber = StringBuilder()
... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 4,140 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/day02/Day02.kt | martindacos | 572,700,466 | false | {"Kotlin": 12412} | package day02
import readInput
fun main() {
fun part1(input: List<String>): Int {
var points = 0
val plays = input.map { play -> play.split(" ") }
for (play in plays) {
val myPoints = when (play.get(1)) {
"X" -> 1
"Y" -> 2
"Z" ->... | 0 | Kotlin | 0 | 0 | f288750fccf5fbc41e8ac03598aab6a2b2f6d58a | 2,156 | 2022-advent-of-code-kotlin | Apache License 2.0 |
codeforces/kotlinheroes3/g.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.kotlinheroes3
private val digits = 1..9
fun main() {
val (m, kIn) = readInts()
listOf(2, 3, 5, 7).fold(m) { acc, p ->
var temp = acc
while (temp % p == 0) temp /= p
temp
}.takeIf { it == 1 } ?: return println(-1)
val memo = mutableMapOf<Pair<Int, Int>, Long>()
fun count(m: Int, len: Int... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,083 | competitions | The Unlicense |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MaximumErasureValue.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 | 5,862 | kotlab | Apache License 2.0 |
src/main/kotlin/cc/stevenyin/algorithms/_02_sorts/_07_QuickSort_Partition2.kt | StevenYinKop | 269,945,740 | false | {"Kotlin": 107894, "Java": 9565} | package cc.stevenyin.algorithms._02_sorts
import cc.stevenyin.algorithms.RandomType
import cc.stevenyin.algorithms.swap
import cc.stevenyin.algorithms.testSortAlgorithm
class _07_QuickSort_Partition2 : SortAlgorithm {
override val name: String = "Quick Sort with Partition 2"
override fun <T : Comparable<T>> ... | 0 | Kotlin | 0 | 1 | 748812d291e5c2df64c8620c96189403b19e12dd | 1,317 | kotlin-demo-code | MIT License |
app/src/main/java/com/kvl/cyclotrack/Statistics.kt | kevinvanleer | 311,970,003 | false | {"Kotlin": 902772, "JavaScript": 20979, "MDX": 5247, "CSS": 3042, "HTML": 2474} | package com.kvl.cyclotrack
import kotlin.math.pow
fun List<Double>.average(): Double =
this.reduce { acc, d -> acc + d } / this.size
fun average(newValue: Double, sampleSize: Int, lastAverage: Double): Double =
(lastAverage * (sampleSize - 1) + newValue) / sampleSize
fun List<Double>.sampleVariance(): Doubl... | 0 | Kotlin | 0 | 6 | c936057abdd328ae184e9f580963c8aff102338a | 4,435 | cyclotrack | The Unlicense |
kotlin/2021/qualification-round/cheating-detection/src/main/kotlin/AnalysisSolution.kts | ShreckYe | 345,946,821 | false | null | import kotlin.math.absoluteValue
import kotlin.math.exp
import kotlin.math.ln
fun main() {
val t = readLine()!!.toInt()
val p = readLine()!!.toInt()
repeat(t, ::testCase)
}
val numHalfExtremeQuestions = 500
fun testCase(ti: Int) {
val results = List(100) {
readLine()!!.map { it - '0' }
}
... | 0 | Kotlin | 1 | 1 | 743540a46ec157a6f2ddb4de806a69e5126f10ad | 1,641 | google-code-jam | MIT License |
gcj/y2023/farewell_d/e_to_upsolve.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package gcj.y2023.farewell_d
import kotlin.random.Random
fun generate(n: Int, m: Int): MutableList<Pair<Int, Int>> {
var toAdd = m
val list = mutableListOf<Pair<Int, Int>>()
fun addEdge(v: Int, u: Int) {
toAdd--
list.add(v to u)
}
for (i in 0 until n) {
addEdge(i, (i + 1) % n)
}
for (i in 2 until n) {
//... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 2,874 | competitions | The Unlicense |
src/Day09.kt | kmes055 | 577,555,032 | false | {"Kotlin": 35314} | import kotlin.math.abs
fun main() {
class Node(
var x: Int = 0,
var y: Int = 0
) {
override fun toString(): String {
return "($x, $y)"
}
fun move(direction: String) {
when (direction) {
"L" -> this.x -= 1
"R" -> th... | 0 | Kotlin | 0 | 0 | 84c2107fd70305353d953e9d8ba86a1a3d12fe49 | 2,142 | advent-of-code-kotlin | Apache License 2.0 |
algorithms/src/main/kotlin/org/baichuan/sample/algorithms/leetcode/hard/NumberToWords.kt | scientificCommunity | 352,868,267 | false | {"Java": 154453, "Kotlin": 69817} | package org.baichuan.sample.algorithms.leetcode.hard
/**
* @author: tk (<EMAIL>)
* @date: 2022/1/10
* https://leetcode-cn.com/problems/english-int-lcci/
* 面试题 16.08. 整数的英语表示
*/
class NumberToWords {
fun numberToWords(num: Int): String {
val unit = arrayOf("Billion", "Million", "Thousand", "Hundred")
... | 1 | Java | 0 | 8 | 36e291c0135a06f3064e6ac0e573691ac70714b6 | 4,026 | blog-sample | Apache License 2.0 |
src/day10/Day10.kt | EdwinChang24 | 572,839,052 | false | {"Kotlin": 20838} | package day10
import readInput
import kotlin.math.absoluteValue
fun main() {
part1()
part2()
}
fun part1() = common { cycles -> println(listOf(20, 60, 100, 140, 180, 220).sumOf { cycles[it - 1] * it }) }
fun part2() = common { cycles ->
val image = mutableListOf<Char>()
cycles.forEachIndexed { index... | 0 | Kotlin | 0 | 0 | e9e187dff7f5aa342eb207dc2473610dd001add3 | 823 | advent-of-code-2022 | Apache License 2.0 |
year2020/src/main/kotlin/net/olegg/aoc/year2020/day23/Day23.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2020.day23
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2020.DayOf2020
/**
* See [Year 2020, Day 23](https://adventofcode.com/2020/day/23)
*/
object Day23 : DayOf2020(23) {
override fun first(): Any? {
val items = data.map { it.digitToInt() }
val queue = ArrayDe... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 2,224 | adventofcode | MIT License |
src/day01/Day01.kt | ubuntudroid | 571,771,936 | false | {"Kotlin": 7845} | package day01
import ensureBlankLastItem
import readInput
fun main() {
val input = readInput("Day01")
println(part1(input))
println(part2(input))
}
fun part1(input: List<String>): Int = input
.ensureBlankLastItem()
.map { it.toIntOrNull() }
.fold(0 to 0) { (maxCals, elfCals), lineCals ->
... | 0 | Kotlin | 0 | 0 | fde55dcf7583aac6571c0f6fc2d323d235337c27 | 1,225 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/ca/voidstarzero/isbd/titlestatement/grammar/MonographTitle.kt | hzafar | 262,218,140 | false | null | package ca.voidstarzero.isbd.titlestatement.grammar
import ca.voidstarzero.isbd.titlestatement.ast.*
import norswap.autumn.DSL.rule
/**
* Matches a string of characters.
*
* Pushes the matched string as a [TitleProper] to the parser's value stack.
*/
val TitleStatementGrammar.titleProper: rule
get() = data
... | 2 | Kotlin | 0 | 2 | 16bb26858722ca818c0a9f659be1cc9d3e4e7213 | 3,402 | isbd-parser | MIT License |
day22/Part2.kt | anthaas | 317,622,929 | false | null | import java.io.File
fun main(args: Array<String>) {
val input = File("input.txt").bufferedReader().use { it.readText() }.split("\n\n")
.map { it.split("\n").let { it.subList(1, it.size) }.map { it.toInt() } }
val decks = input[0].toMutableList() to input[1].toMutableList()
recursiveGame(decks)
... | 0 | Kotlin | 0 | 0 | aba452e0f6dd207e34d17b29e2c91ee21c1f3e41 | 1,683 | Advent-of-Code-2020 | MIT License |
src/Day01.kt | cvb941 | 572,639,732 | false | {"Kotlin": 24794} | fun main() {
fun part1(input: List<String>): Int {
var maxCalories = 0
var calorieSum = 0
input.forEach {
if (it.isEmpty()) {
maxCalories = maxOf(maxCalories, calorieSum)
calorieSum = 0
} else {
calorieSum += it.toInt()
... | 0 | Kotlin | 0 | 0 | fe145b3104535e8ce05d08f044cb2c54c8b17136 | 1,023 | aoc-2022-in-kotlin | Apache License 2.0 |
src/day8/Day08.kt | dinoolivo | 573,723,263 | false | null | package day8
import readInput
fun main() {
fun treeMatrix(input: List<String>): List<List<Int>> = input.map { row -> row.map { elem -> elem.digitToInt() } }
fun scenicScoreFromLeft(input: List<List<Int>>, rowIndex: Int, colIndex: Int): Int {
var leftIndex = colIndex - 1
while (leftIndex > 0 ... | 0 | Kotlin | 0 | 0 | 6e75b42c9849cdda682ac18c5a76afe4950e0c9c | 4,397 | aoc2022-kotlin | Apache License 2.0 |
src/Day09.kt | cornz | 572,867,092 | false | {"Kotlin": 35639} | data class Point(var x: Int, var y: Int)
fun main() {
fun move(
instruction: String,
headAndTail: Triple<Point, Point, MutableList<Point>>
): Triple<Point, Point, MutableList<Point>> {
val parts = instruction.split(" ")
val guidance = parts[0]
val run = parts[1].toInt(... | 0 | Kotlin | 0 | 0 | 2800416ddccabc45ba8940fbff998ec777168551 | 2,799 | aoc2022 | Apache License 2.0 |
kotlin/src/main/kotlin/year2023/Day05.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2023
fun main() {
val input = readInput2("Day05")
Day05.part1(input).println()
Day05.part2(input).println()
}
private typealias SeedRange = Pair<Long, Long>
private typealias Decoder = Set<RangeDecoder>
private typealias Decoders = List<Decoder>
private data class RangeDecoder(val from: Long,... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 6,959 | advent-of-code | MIT License |
Kotlin/src/Combinations.kt | TonnyL | 106,459,115 | false | null | /**
* Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
*
* For example,
* If n = 4 and k = 2, a solution is:
*
* [
* [2,4],
* [3,4],
* [2,3],
* [1,2],
* [1,3],
* [1,4],
* ]
*/
class Combinations {
// Iterative solution.
// Accepted.
fun combine(n: Int,... | 1 | Swift | 22 | 189 | 39f85cdedaaf5b85f7ce842ecef975301fc974cf | 1,647 | Windary | MIT License |
src/Day14.kt | cypressious | 572,898,685 | false | {"Kotlin": 77610} | import java.lang.IllegalStateException
import kotlin.math.max
import kotlin.math.min
fun main() {
data class Point(val x: Int, val y: Int) {
fun isHorizontalLine(other: Point) = y == other.y
}
class Grid(width: Int, height: Int, val offset: Int) {
private val grid = List(height) { CharArra... | 0 | Kotlin | 0 | 1 | 7b4c3ee33efdb5850cca24f1baa7e7df887b019a | 3,831 | AdventOfCode2022 | Apache License 2.0 |
src/commonMain/kotlin/io/github/arashiyama11/functions.kt | arashiyama11 | 581,833,835 | false | {"Kotlin": 69471} | package io.github.arashiyama11
import kotlin.math.*
val validFunctions = listOf("sin", "cos", "tan", "log", "sqrt", "abs", "max", "min", "pow")
val specialFunctions = mapOf(
"sin" to SpecialFunction(
1,
{ Rational(sin(it[0])).reduction() },
{ t, l -> Unary("${t[0].toPolynomial().differential(l).evaluat... | 0 | Kotlin | 0 | 0 | c3832fb4248060b55d2a0528ece479ac799002d8 | 2,554 | mojishiki | MIT License |
src/main/kotlin/com/chriswk/aoc/advent2022/Day9.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2022
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.CompassDirection
import com.chriswk.aoc.util.Point2D
import com.chriswk.aoc.util.report
import kotlin.math.absoluteValue
import kotlin.math.sign
class Day9: AdventDay(2022, 9) {
companion object {
@JvmStatic
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,360 | adventofcode | MIT License |
kotlin/src/main/kotlin/adventofcode/day13/Day13_2.kt | thelastnode | 160,586,229 | false | null | package adventofcode.day13
import java.io.File
import java.lang.IllegalArgumentException
import java.lang.IllegalStateException
import java.util.*
object Day13_2 {
enum class State(val repr: Set<Char>) {
TRACK(setOf('|', '-')),
CURVE(setOf('\\', '/')),
INTERSECTION(setOf('+')),
CAR... | 0 | Kotlin | 0 | 0 | 8c9a3e5a9c8b9dd49eedf274075c28d1ebe9f6fa | 7,103 | adventofcode | MIT License |
src/Day09.kt | SnyderConsulting | 573,040,913 | false | {"Kotlin": 46459} | import kotlin.math.abs
fun main() {
fun part1(input: List<String>): Int {
val movements = input.map { line ->
Movement.of(line)
}
val grid = Grid(2)
movements.forEach {
grid.moveHead(it)
}
return grid.knotPositions.last().distinct().size
... | 0 | Kotlin | 0 | 0 | ee8806b1b4916fe0b3d576b37269c7e76712a921 | 4,958 | Advent-Of-Code-2022 | Apache License 2.0 |
src/Day09.kt | sushovan86 | 573,586,806 | false | {"Kotlin": 47064} | import kotlin.math.abs
enum class Direction {
UP, DOWN, LEFT, RIGHT
}
val DIRECTION_MAP = mapOf(
"R" to Direction.RIGHT,
"L" to Direction.LEFT,
"U" to Direction.UP,
"D" to Direction.DOWN
)
data class Point(val x: Int = 0, val y: Int = 0) {
infix fun moveTowards(movement: Direction): Point = ... | 0 | Kotlin | 0 | 0 | d5f85b6a48e3505d06b4ae1027e734e66b324964 | 3,378 | aoc-2022 | Apache License 2.0 |
app/src/main/kotlin/aoc2021/day03/Day03.kt | dbubenheim | 435,284,482 | false | {"Kotlin": 31242} | package aoc2021.day03
import aoc2021.toFile
class Day03 {
companion object {
@JvmStatic
fun binaryDiagnosticPart1(): Int {
return "input-day03.txt"
.toFile()
.readLines()
.map { it.toIntArray() }
.fold(DiagnosticReport()... | 9 | Kotlin | 0 | 0 | 83a93845ebbc1a6405f858214bfa79b3448b932c | 3,506 | advent-of-code-2021 | MIT License |
src/Day01.kt | msernheim | 573,937,826 | false | {"Kotlin": 32820} | fun main() {
fun part1(input: List<String>): Int {
var cMax = 0;
var current = 0;
input.forEach { food ->
if (food.equals("")) {
if (cMax >= current) {
current = 0
} else {
cMax = current
... | 0 | Kotlin | 0 | 3 | 54cfa08a65cc039a45a51696e11b22e94293cc5b | 1,359 | AoC2022 | Apache License 2.0 |
src/merge_sorted_array/README.kt | AhmedTawfiqM | 458,182,208 | false | {"Kotlin": 11105} | package merge_sorted_array
//https://leetcode.com/problems/merge-sorted-array/
/*
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.
Merge nums1 and nums2 into a single array sorted in non-de... | 0 | Kotlin | 0 | 1 | a569265d5f85bcb51f4ade5ee37c8252e68a5a03 | 1,464 | ProblemSolving | Apache License 2.0 |
src/main/kotlin/adventOfCode2023/Day07.kt | TetraTsunami | 726,140,343 | false | {"Kotlin": 80024} | package adventOfCode2023
import util.*
@Suppress("unused")
class Day07(input: String, context: RunContext = RunContext.PROD) : Day(input, context) {
fun getFreqMap(hand: Pair<String, Int>): Map<Char, Int> {
val freqMap = mutableMapOf<Char, Int>()
var j = 0
for (i in 0..4) {
val ... | 0 | Kotlin | 0 | 0 | 78d1b5d1c17122fed4f4e0a25fdacf1e62c17bfd | 4,102 | AdventOfCode2023 | Apache License 2.0 |
src/cn/ancono/math/algebra/abs/calculator/OrderedCalculators.kt | 140378476 | 105,762,795 | false | {"Java": 1912158, "Kotlin": 1243514} | package cn.ancono.math.algebra.abs.calculator
/*
* Created by liyicheng at 2021-05-06 19:32
*/
/**
* Describes an abelian group with a order relation denoted by `<, <=, >, >=`.
*
* The order must be consistent with addition, that is:
*
* x < y implies x + a < y + a, for any a
*
*
*/
interface O... | 0 | Java | 0 | 6 | 02c2984c10a95fcf60adcb510b4bf111c3a773bc | 1,965 | Ancono | MIT License |
src/main/kotlin/PrimeSteps.kt | Flight552 | 408,072,383 | false | {"Kotlin": 26115, "Assembly": 1320} | //The prime numbers are not regularly spaced.
// For example from 2 to 3 the step is 1. From 3 to 5
// the step is 2. From 7 to 11 it is 4.
// Between 2 and 50 we have the following pairs of 2-steps primes:
//
//3, 5 - 5, 7, - 11, 13, - 17, 19, - 29, 31, - 41, 43
//
//We will write a function step with parameters:
//
/... | 0 | Kotlin | 0 | 0 | b9fb9378120455c55a413ba2e5a95796612143bc | 3,413 | codewars | MIT License |
src/main/kotlin/com/ginsberg/advent2016/Day13.kt | tginsberg | 74,924,040 | false | null | /*
* Copyright (c) 2016 by <NAME>
*/
package com.ginsberg.advent2016
import java.util.ArrayDeque
/**
* Advent of Code - Day 13: December 13, 2016
*
* From http://adventofcode.com/2016/day/13
*
*/
class Day13(favorite: Int, val goalX: Int, val goalY: Int, val depth: Int = 50) {
private val start = Node(1... | 0 | Kotlin | 0 | 3 | a486b60e1c0f76242b95dd37b51dfa1d50e6b321 | 2,340 | advent-2016-kotlin | MIT License |
src/main/kotlin/g1901_2000/s1970_last_day_where_you_can_still_cross/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1901_2000.s1970_last_day_where_you_can_still_cross
// #Hard #Array #Depth_First_Search #Breadth_First_Search #Binary_Search #Matrix #Union_Find
// #2023_06_21_Time_703_ms_(100.00%)_Space_65.6_MB_(100.00%)
@Suppress("NAME_SHADOWING")
class Solution {
fun latestDayToCross(row: Int, col: Int, cells: Array<I... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 2,470 | LeetCode-in-Kotlin | MIT License |
atcoder/agc043/d_wrong.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package atcoder.agc043
fun main() {
// val (n, m) = readInts()
val memo = HashMap<Long, Int>()
fun solve(x: Int, y: Int, z: Int): Int {
if (z == 0 && y == x - 1) return 1
if (y < 0 || y >= x || z >= x) return 0
val code = (x.toLong() shl 42) + (y.toLong() shl 21) + z
if (memo.containsKey(code)) return memo[... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,043 | competitions | The Unlicense |
facebook/y2021/qual/b.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package facebook.y2021.qual
private fun needed(s: String): Pair<Int, Int>? {
return (s.count { it == '.' } to s.indexOf('.')).takeIf { 'O' !in s }
}
private fun solve(): String {
val field = List(readInt()) { readLn() }
val options = field.indices.flatMap { i -> listOf(
needed(field[i])?.let { it.first to (i to ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 831 | competitions | The Unlicense |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.