path stringlengths 5 169 | owner stringlengths 2 34 | repo_id int64 1.49M 755M | is_fork bool 2
classes | languages_distribution stringlengths 16 1.68k ⌀ | content stringlengths 446 72k | issues float64 0 1.84k | main_language stringclasses 37
values | forks int64 0 5.77k | stars int64 0 46.8k | commit_sha stringlengths 40 40 | size int64 446 72.6k | name stringlengths 2 64 | license stringclasses 15
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
src/main/kotlin/day6/LanternFish.kt | Arch-vile | 433,381,878 | false | {"Kotlin": 57129} | package day6
import utils.read
fun main() {
solve().let { println(it) }
}
fun solve(): List<Long> {
var startingFishes = read("./src/main/resources/day6Input.txt")
.flatMap { it.split(",").map { it.toInt() } }
return listOf(countFish(startingFishes, 80), countFish(startingFishes, 256))
}
privat... | 0 | Kotlin | 0 | 0 | 4cdafaa524a863e28067beb668a3f3e06edcef96 | 1,026 | adventOfCode2021 | Apache License 2.0 |
src/Day07.kt | cagriyildirimR | 572,811,424 | false | {"Kotlin": 34697} |
// Create a class representing a directory
class Dir(val up: Dir? = null) {
// Maps of subdirectories and files in this directory
val subdirs = mutableMapOf<String, Dir>()
val files = mutableMapOf<String, Long>()
var sum = 0L
}
fun day07Part1() {
// Set up the root directory
val root = Dir()
... | 0 | Kotlin | 0 | 0 | 343efa0fb8ee76b7b2530269bd986e6171d8bb68 | 2,698 | AoC | Apache License 2.0 |
src/Day05.kt | hanmet | 573,490,488 | false | {"Kotlin": 9896} | import java.util.*
fun main() {
fun getTestStacks(): List<Stack<Char>> {
val stack1 = Stack<Char>()
stack1.addAll(listOf('Z', 'N'))
val stack2 = Stack<Char>()
stack2.addAll(listOf('M', 'C', 'D'))
val stack3 = Stack<Char>()
stack3.addAll(listOf('P'))
retur... | 0 | Kotlin | 0 | 0 | e4e1722726587639776df86de8d4e325d1defa02 | 3,205 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day14/Day14.kt | jankase | 573,187,696 | false | {"Kotlin": 70242} | package day14
import Day
import solve
import kotlin.math.max
import kotlin.math.min
data class Coordinate(val x: Int, val y: Int) : Comparable<Coordinate> {
companion object {
fun valueOf(value: String): Coordinate {
val (x, y) = value.split(",").map(String::toInt)
return Coordinat... | 0 | Kotlin | 0 | 0 | 0dac4ec92c82a5ebb2179988fb91fccaed8f800a | 4,738 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/adventofcode/year2021/Day10SyntaxScoring.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2021
import adventofcode.Puzzle
import adventofcode.PuzzleInput
class Day10SyntaxScoring(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val lines by lazy { input.lines() }
private val bracketMap = mapOf(
'(' to ')',
'[' to ']',
'{' to '}',
... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 1,697 | AdventOfCode | MIT License |
src/aoc22/Day05.kt | mihassan | 575,356,150 | false | {"Kotlin": 123343} | @file:Suppress("PackageDirectoryMismatch")
package aoc22.day05
import lib.Collections.headTail
import lib.Solution
import lib.Strings.ints
typealias StackIndex = Int
data class Crate(private val char: Char) {
override fun toString(): String = "$char"
companion object {
fun parse(char: Char): Crate? = Crate... | 0 | Kotlin | 0 | 0 | 698316da8c38311366ee6990dd5b3e68b486b62d | 3,433 | aoc-kotlin | Apache License 2.0 |
src/Challenge2.kt | occmundial | 517,843,760 | false | {"Kotlin": 28105} | /*
* Challenge #2
*
* Date: 15/08/2022
* Difficulty: Medium
* Create a function that translate from natural text to Morse code and vice versa.
* - Must be automatically detect what type it is and perform the conversion.
* - In Morse, dash "—", dot ".", a space " " between letters or symbols, and two spaces between word... | 1 | Kotlin | 0 | 1 | f09ba0a03666ab9cf362adab62b897aa4e399171 | 2,994 | Kotlin-Weekly-Challenge | The Unlicense |
src/main/kotlin/org/vitrivr/cottontail/database/index/vaplus/MarksGenerator.kt | frankier | 278,349,990 | true | {"Kotlin": 1020644, "Dockerfile": 280} | package org.vitrivr.cottontail.database.index.vaplus
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow
object MarksGenerator {
/** */
const val EPSILON = 10E-9
/**
* Get marks.
*/
fun getNonUniformMarks(data: Array<DoubleArray>, marksPerDimension: IntArray): Array<DoubleA... | 0 | Kotlin | 0 | 0 | e4ec66eaf014bb8ea4399cc7ea54062f16cf0c60 | 4,487 | cottontaildb | MIT License |
src/week-day-1/Sqrt.kt | luix | 573,258,926 | false | {"Kotlin": 7897, "Java": 232} | package week1
import kotlin.math.sqrt
/**
* Sqrt (easy)
* Problem Statement
* Given a non-negative integer x, return the square root of x rounded
* down to the nearest integer. The returned integer should be non-negative as well.
*
* You must not use any built-in exponent function or operator.
*
* For example... | 0 | Kotlin | 0 | 0 | 8e9b605950049cc9a0dced9c7ba99e1e2458e53e | 2,823 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2023/Day21.kt | tginsberg | 723,688,654 | false | {"Kotlin": 112398} | /*
* Copyright (c) 2023 by <NAME>
*/
/**
* Advent of Code 2023, Day 21 - Step Counter
* Problem Description: http://adventofcode.com/2023/day/21
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2023/day21/
*/
package com.ginsberg.advent2023
class Day21(input: List<String>) {
private va... | 0 | Kotlin | 0 | 12 | 0d5732508025a7e340366594c879b99fe6e7cbf0 | 2,244 | advent-2023-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/PathSum2.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2021 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 2,245 | kotlab | Apache License 2.0 |
src/main/kotlin/g2701_2800/s2713_maximum_strictly_increasing_cells_in_a_matrix/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2701_2800.s2713_maximum_strictly_increasing_cells_in_a_matrix
// #Hard #Array #Dynamic_Programming #Sorting #Binary_Search #Matrix #Memoization
// #2023_08_01_Time_1141_ms_(100.00%)_Space_110.2_MB_(54.55%)
import java.util.concurrent.atomic.AtomicInteger
class Solution {
fun maxIncreasingCells(mat: Arra... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,438 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/g1101_1200/s1161_maximum_level_sum_of_a_binary_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1101_1200.s1161_maximum_level_sum_of_a_binary_tree
// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
// #2023_05_25_Time_445_ms_(87.50%)_Space_97.1_MB_(75.00%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,181 | LeetCode-in-Kotlin | MIT License |
src/Day10.kt | undermark5 | 574,819,802 | false | {"Kotlin": 67472} | fun main() {
fun part1(input: List<String>): Long {
var cycleCount = 0
var xRegister = 1
val cyclesOfInterest = mutableListOf(20,60,100,140,180,220)
var sum = 0L
input.forEach {
if (it.startsWith("noop")) cycleCount++
if (it.startsWith("addx")) {
... | 0 | Kotlin | 0 | 0 | e9cf715b922db05e1929f781dc29cf0c7fb62170 | 3,246 | AoC_2022_Kotlin | Apache License 2.0 |
src/main/kotlin/g2601_2700/s2658_maximum_number_of_fish_in_a_grid/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2601_2700.s2658_maximum_number_of_fish_in_a_grid
// #Medium #Array #Depth_First_Search #Breadth_First_Search #Matrix #Union_Find
// #2023_07_21_Time_269_ms_(80.00%)_Space_45.4_MB_(80.00%)
class Solution {
fun findMaxFish(grid: Array<IntArray>): Int {
val visited = Array(grid.size) { BooleanArray(... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,179 | LeetCode-in-Kotlin | MIT License |
src/Day01.kt | brste | 577,510,164 | false | {"Kotlin": 2640} | fun main() {
fun topK(input: List<String>, k: Int) : List<Int> {
val caloriesOfElves = mutableListOf<Int>()
var sum = 0
for (line in input) {
if (line.isBlank()) {
caloriesOfElves.add(sum)
sum = 0
} else {
sum += line.to... | 0 | Kotlin | 0 | 0 | e8d6604575021fef95ad3d31cc8d61e929ac9efa | 879 | aoc-2022-kotlin | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/medium/Merge.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode.medium
/**
* 56. 合并区间
*
* 以数组 intervals 表示若干个区间的集合,其中单个区间为 intervals[i] = [starti, endi] 。请你合并所有重叠的区间,并返回一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间。
*/
class Merge {
companion object {
@JvmStatic
fun main(args: Array<String>) {
Merge().merge(arrayOf(intArrayOf... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 1,506 | daily_algorithm | Apache License 2.0 |
src/net/sheltem/aoc/y2022/Day11.kt | jtheegarten | 572,901,679 | false | {"Kotlin": 178521} | package net.sheltem.aoc.y2022
import net.sheltem.common.MathOperation
import net.sheltem.common.lastAsInt
class Day11 : Day<Long>(10605, 2713310158) {
override suspend fun part1(input: List<String>) = input.windowed(6, 7)
.map { it.toMonkey() }
.playRounds(20)
.map { it.inspections }
... | 0 | Kotlin | 0 | 0 | ac280f156c284c23565fba5810483dd1cd8a931f | 2,837 | aoc | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2022/Day17.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2022
import se.saidaspen.aoc.util.*
import kotlin.math.absoluteValue
fun main() = Day17.run()
object Day17 : Day(2022, 17) {
private var dash = "####"
private var plus = ".#.\n###\n.#."
private var lThing = "..#\n..#\n###"
private var iThing = "#\n#\n#\n#"
private var... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 6,307 | adventofkotlin | MIT License |
src/main/kotlin/ru/timakden/aoc/year2023/Day18.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2023
import ru.timakden.aoc.util.Point
import ru.timakden.aoc.util.Polygon
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
/**
* [Day 18: <NAME>](https://adventofcode.com/2023/day/18).
*/
object Day18 {
@JvmStatic
fun main(args: Array<String>) {
... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 2,516 | advent-of-code | MIT License |
src/main/kotlin/day15/day15.kt | corneil | 572,437,852 | false | {"Kotlin": 93311, "Shell": 595} | package day15
import main.utils.measureAndPrint
import main.utils.scanInts
import utils.*
import java.lang.Integer.min
import kotlin.math.abs
import kotlin.math.max
fun main() {
val test = readLines(
"""
Sensor at x=2, y=18: closest beacon is at x=-2, y=15
Sensor at x=9, y=16: closest beacon is at x=10... | 0 | Kotlin | 0 | 0 | dd79aed1ecc65654cdaa9bc419d44043aee244b2 | 5,982 | aoc-2022-in-kotlin | Apache License 2.0 |
src/Day10.kt | michaelYuenAE | 573,094,416 | false | {"Kotlin": 74685} |
private val CYCLE_INDEX = listOf(20, 60, 100, 140, 180, 220)
class Day10(private val input: List<String>) {
private val command = input.map { getCommand(it) }
fun solvePart1() = getSignalStrength()
private fun getSignalStrength(): Int {
var registerX = 1
var sb = StringBuffer()
va... | 0 | Kotlin | 0 | 0 | ee521263dee60dd3462bea9302476c456bfebdf8 | 1,553 | advent22 | Apache License 2.0 |
08.kts | pin2t | 725,922,444 | false | {"Kotlin": 48856, "Go": 48364, "Shell": 54} | import java.util.*
val scanner = Scanner(System.`in`)
val instructions = scanner.nextLine()
scanner.nextLine()
val map = HashMap<String, Pair<String, String>>()
val node = Regex("[A-Z]+")
while (scanner.hasNext()) {
val item = node.findAll(scanner.nextLine()).map { it.value }.toList()
map.put(item[0], Pair(ite... | 0 | Kotlin | 1 | 0 | 7575ab03cdadcd581acabd0b603a6f999119bbb6 | 1,105 | aoc2023 | MIT License |
src/Day01.kt | fmborghino | 573,233,162 | false | {"Kotlin": 60805} | /*
* Hindsight notes.
* - There are much more concise ways to re-express this as chained functions.
*/
fun main() {
fun log(message: Any?) {
// println(message)
}
fun part1(input: List<String>): Int {
var elfIndex = 1
var maxElfIndex = 0
var maxCalories = 0
var cal... | 0 | Kotlin | 0 | 0 | 893cab0651ca0bb3bc8108ec31974654600d2bf1 | 2,100 | aoc2022 | Apache License 2.0 |
src/Day17.kt | felldo | 572,233,925 | false | {"Kotlin": 76496} | fun main() {
val rocks = buildList {
add(arrayOf(Pair(0, 0), Pair(0, 1), Pair(0, 2), Pair(0, 3)))
add(arrayOf(Pair(0, 1), Pair(1, 0), Pair(1, 1), Pair(1, 2), Pair(2, 1)))
add(arrayOf(Pair(0, 2), Pair(1, 2), Pair(2, 0), Pair(2, 1), Pair(2, 2)))
add(arrayOf(Pair(0, 0), Pair(1, 0), Pai... | 0 | Kotlin | 0 | 0 | 0ef7ac4f160f484106b19632cd87ee7594cf3d38 | 2,944 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/P021_AmicableNumber.kt | perihanmirkelam | 291,833,878 | false | null | /**
* P21 - Amicable Numbers
*
* Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
* If d(a) = b and d(b) = a, where a ≠ b,
* then a and b are an amicable pair and each of a and b are called amicable numbers.
*
* For example, the proper divisors of 220 are 1... | 0 | Kotlin | 1 | 3 | a24ac440871220c87419bfd5938f80dc22a422b2 | 1,076 | ProjectEuler | MIT License |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2017/2017-03.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2017
import com.github.ferinagy.adventOfCode.Coord2D
import kotlin.collections.Map
import kotlin.collections.contains
import kotlin.collections.filter
import kotlin.collections.mutableMapOf
import kotlin.collections.set
import kotlin.collections.sumOf
fun main() {
print... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,819 | advent-of-code | MIT License |
src/y2022/Day08.kt | Yg0R2 | 433,731,745 | false | null | package y2022
import DayX
import common.Grid
import common.Grid.Companion.toGrid
class Day08 : DayX<Int>(21, 8) {
override fun part1(input: List<String>): Int {
val grid = input.initializeGrid()
var visibleTreesCount = 0
for (row: Int in grid.getRowIndices()) {
for (column: I... | 0 | Kotlin | 0 | 0 | d88df7529665b65617334d84b87762bd3ead1323 | 2,776 | advent-of-code | Apache License 2.0 |
app/src/test/java/com/zwq65/unity/algorithm/unionfind/LeetCode947.kt | Izzamuzzic | 95,655,850 | false | {"Kotlin": 449365, "Java": 17918} | package com.zwq65.unity.algorithm.unionfind
import org.junit.Test
/**
* ================================================
* <p>
* <a href="https://leetcode-cn.com/problems/most-stones-removed-with-same-row-or-column/">947. 移除最多的同行或同列石头</a>.
* Created by NIRVANA on 2019/7/15.
* Contact with <<EMAIL>>
* ==========... | 0 | Kotlin | 0 | 0 | 98a9ad7bb298d0b0cfd314825918a683d89bb9e8 | 1,544 | Unity | Apache License 2.0 |
src/main/kotlin/biz/koziolek/adventofcode/year2023/day18/day18.kt | pkoziol | 434,913,366 | false | {"Kotlin": 715025, "Shell": 1892} | package biz.koziolek.adventofcode.year2023.day18
import biz.koziolek.adventofcode.*
fun main() {
val inputFile = findInput(object {})
val digPlan = parseDigPlan(inputFile.bufferedReader().readLines())
println("The trench can hold ${calculateTrenchVolume(buildTrenchEdge(digPlan))} cubic meters")
}
data cl... | 0 | Kotlin | 0 | 0 | 1b1c6971bf45b89fd76bbcc503444d0d86617e95 | 8,463 | advent-of-code | MIT License |
src/main/kotlin/days/Day4.kt | sicruse | 434,002,213 | false | {"Kotlin": 29921} | package days
class Day4 : Day(4) {
private val plays: List<Int> by lazy {
inputList.first().split(",").map { it.toInt() }
}
private val boards: List<Board> by lazy {
inputString
// split the file at blank lines
.split("\\n\\n".toRegex())
// skip the fir... | 0 | Kotlin | 0 | 0 | 172babe6ee67a86a7893f8c9c381c5ce8e61908e | 2,750 | aoc-kotlin-2021 | Creative Commons Zero v1.0 Universal |
archive/src/main/kotlin/com/grappenmaker/aoc/year21/Day22.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year21
import com.grappenmaker.aoc.Point3D
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.rangeTo
import com.grappenmaker.aoc.volumeLong
fun PuzzleSet.day22() = puzzle(day = 22) {
// This took me way too long to come up with
// My initial idea of cutting ended u... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 2,159 | advent-of-code | The Unlicense |
src/iii_conventions/MyDate.kt | omegaphoenix | 115,461,312 | false | null | package iii_conventions
data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int) : Comparable<MyDate> {
private val daysInWeek = 7
override fun compareTo(other: MyDate) = when
{
year != other.year -> year - other.year
month != other.month -> month - other.month
else ->... | 0 | Kotlin | 0 | 0 | bfb21969455b154ab078b2d9a43683ae8298085c | 1,816 | kotlin-koans | MIT License |
src/main/kotlin/g0801_0900/s0803_bricks_falling_when_hit/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0803_bricks_falling_when_hit
// #Hard #Array #Matrix #Union_Find #2023_03_16_Time_742_ms_(100.00%)_Space_53.4_MB_(100.00%)
class Solution {
private val dirs = arrayOf(intArrayOf(1, 0), intArrayOf(-1, 0), intArrayOf(0, 1), intArrayOf(0, -1))
fun hitBricks(grid: Array<IntArray>, hits: Array<... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,732 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/offer/31.kt | Eynnzerr | 621,254,277 | false | null | package offer
import java.util.LinkedList
class Solution31 {
fun validateStackSequences(pushed: IntArray, popped: IntArray): Boolean {
// 核心思路:构造辅助栈
val stack = LinkedList<Int>()
var pushedCount = 0
for (poppedNum in popped) {
if (stack.isEmpty() || stack.peek() != popp... | 0 | Kotlin | 0 | 0 | 0327df84200444e1e4ef4b7d7a9f8779e8d7443f | 1,574 | leetcode-kotlin | MIT License |
kotlin/src/com/daily/algothrim/leetcode/WordPattern.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
/**
* 290. 单词规律
*
* 给定一种规律 pattern 和一个字符串 str ,判断 str 是否遵循相同的规律。
*
* 这里的 遵循 指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之间存在着双向连接的对应规律。
*
* 示例1:
*
* 输入: pattern = "abba", str = "dog cat cat dog"
* 输出: true
* 示例 2:
*
* 输入:pattern = "abba", str = "dog cat cat fish"
* 输出: ... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 1,842 | daily_algorithm | Apache License 2.0 |
src/medium/_583DeleteOperationForTwoStrings.kt | ilinqh | 390,190,883 | false | {"Kotlin": 382147, "Java": 32712} | package medium
class _583DeleteOperationForTwoStrings {
class Solution {
fun minDistance(word1: String, word2: String): Int {
val n = word1.length
val m = word2.length
val dp = Array(n + 1) { IntArray(m + 1) }
for (i in 0..n) dp[i][0] = i
for (j i... | 0 | Kotlin | 0 | 0 | 8d2060888123915d2ef2ade293e5b12c66fb3a3f | 1,368 | AlgorithmsProject | Apache License 2.0 |
src/main/kotlin/days/Day5.kt | nuudles | 316,314,995 | false | null | package days
class Day5 : Day(5) {
fun seatId(row: Int, col: Int) = row * 8 + col
fun seat(pattern: String): Pair<Int, Int> {
var rows = 0..127
var cols = 0..7
pattern
.forEach { char ->
when (char) {
'F' -> rows = rows.first..(rows.last ... | 0 | Kotlin | 0 | 0 | 5ac4aac0b6c1e79392701b588b07f57079af4b03 | 1,416 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/de/tek/adventofcode/y2022/util/math/CubicalComplex.kt | Thumas | 576,671,911 | false | {"Kotlin": 192328} | package de.tek.adventofcode.y2022.util.math
import kotlin.math.abs
class ElementaryCube(val intervals: List<IntRange>) : Comparable<ElementaryCube> {
init {
if (intervals.isEmpty()) throw IllegalArgumentException("Interval list must not be empty.")
if (intervals.any { it.last - it.first > 1 }) {
... | 0 | Kotlin | 0 | 0 | 551069a21a45690c80c8d96bce3bb095b5982bf0 | 4,632 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/adventofcode/year2023/Day04Scratchcards.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2023
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import kotlin.math.pow
class Day04Scratchcards(customInput: PuzzleInput? = null) : Puzzle(customInput) {
private val scratchcards by lazy { input.lines().map(Scratchcard::invoke) }
override fun partOne() = scratchcards.s... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 1,717 | AdventOfCode | MIT License |
src/test/kotlin/be/brammeerten/y2023/Day11Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2023
import be.brammeerten.CL
import be.brammeerten.readFile
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
class Day11Test {
@Test
fun `part 1`() {
val lines = readFile("2023/day11/exampleInput.txt");
// val lines = readFile("2023/... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 3,589 | Advent-of-Code | MIT License |
src/Day14.kt | nikolakasev | 572,681,478 | false | {"Kotlin": 35834} | fun main() {
fun part1(input: List<String>): Int {
val rocks = inputToRocks(input)
//find the bottom
val bottomY = rocks.maxBy { it.second }.second
var intoTheAbyss = false
val sand = rocks.toMutableSet()
while(!intoTheAbyss) {
var sandX = 500
... | 0 | Kotlin | 0 | 1 | 5620296f1e7f2714c09cdb18c5aa6c59f06b73e6 | 4,788 | advent-of-code-kotlin-2022 | Apache License 2.0 |
y2023/src/main/kotlin/adventofcode/y2023/Day20.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2023
import adventofcode.io.AdventSolution
import adventofcode.util.math.lcm
fun main() {
Day20.solve()
}
object Day20 : AdventSolution(2023, 20, "Pulse Propagation") {
override fun solvePartOne(input: String): Long {
val modules = parse(input)
var lowPulses = 0L
... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 4,059 | advent-of-code | MIT License |
src/Day03.kt | jalex19100 | 574,686,993 | false | {"Kotlin": 19795} | fun main() {
val letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray() // index + 1
fun part1(input: List<String>): Int {
var sum = 0
input.forEach { line ->
val firstHalf = line.substring(0, line.length / 2).toCharArray()
val secondHalf = line.s... | 0 | Kotlin | 0 | 0 | a50639447a2ef3f6fc9548f0d89cc643266c1b74 | 1,390 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/q51_100/q61_70/Solution70.kt | korilin | 348,462,546 | false | null | package q51_100.q61_70
/**
* https://leetcode-cn.com/problems/climbing-stairs/
*/
class Solution70 {
/**
* f(x) = f(x1) + f(x2)
*
* f(x1) = 最后一步为 1 个台阶的个数 = f(x - 1)
* f(x2) = 最后一步为 2 个台阶的个数 = f(x - 2)
*
* f(x) = f(x-1) + f(x-2)
*
* 矩阵快速幂
*
* M^n * [1, 1].h = [f... | 0 | Kotlin | 0 | 1 | 1ce05efeaf34536fff5fa6226bdcfd28247b2660 | 1,249 | leetcode_kt_solution | MIT License |
src/day10/Code.kt | fcolasuonno | 572,734,674 | false | {"Kotlin": 63451, "Dockerfile": 1340} | package day10
import day06.main
import readInput
data class Instruction(val time: Int, val change: Int)
fun main() {
fun parse(input: List<String>) = input.map {
if (it == "noop") {
Instruction(1, 0)
} else {
Instruction(2, it.split(" ")[1].toInt())
}
}
fu... | 0 | Kotlin | 0 | 0 | 9cb653bd6a5abb214a9310f7cac3d0a5a478a71a | 1,252 | AOC2022 | Apache License 2.0 |
src/day10/Day10.kt | molundb | 573,623,136 | false | {"Kotlin": 26868} | package day10
import readInput
import kotlin.math.abs
fun main() {
val input = readInput(parent = "src/day10", name = "Day10_input")
println(solvePartOne(input))
println(solvePartTwo(input))
}
private fun solvePartTwo(input: List<String>): String {
var allLines = ""
var currLine = "#"
var c ... | 0 | Kotlin | 0 | 0 | a4b279bf4190f028fe6bea395caadfbd571288d5 | 1,346 | advent-of-code-2022 | Apache License 2.0 |
kotlin_practice/src/main/java/dev/vengateshm/kotlin_practice/programs/AnagramSubStringSearchHashMapImpl.kt | vengateshm | 670,054,614 | false | {"Kotlin": 996301, "Java": 26595} | package dev.vengateshm.kotlin_practice.programs
fun main() {
// println(findAnagramsPatternsStartIndicesInString("", "abc").toString())
// println(findAnagramsPatternsStartIndicesInString("abc", "abca").toString())
println(findAnagramsPatternsStartIndicesInString("abczzbcabcadeb", "abc").toString())
// pr... | 0 | Kotlin | 0 | 0 | 40d2c85b09fd2ea22c004bd784bf6b79ccaaf034 | 2,757 | Android-Kotlin-Jetpack-Compose-Practice | Apache License 2.0 |
solutions/aockt/y2015/Y2015D07.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2015
import io.github.jadarma.aockt.core.Solution
object Y2015D07 : Solution {
// Regular expressions for parsing some language tokens.
private val variableRegex = Regex("""\b[a-z]+\b""")
private val constantRegex = Regex("""\b\d+\b""")
private val unary = Regex("""^([A-Z]+) (\d+)$""")... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,172 | advent-of-code-kotlin-solutions | The Unlicense |
y2015/src/main/kotlin/adventofcode/y2015/Day12.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2015
import adventofcode.io.AdventSolution
import java.io.StreamTokenizer
import java.io.StringReader
object Day12 : AdventSolution(2015, 12, "JSAbacusFramework.io") {
override fun solvePartOne(input: String) = traverse(input.asJson()).toString()
override fun solvePartTwo(input: String) = tr... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 2,421 | advent-of-code | MIT License |
src/main/kotlin/github/walkmansit/aoc2020/Day22.kt | walkmansit | 317,479,715 | false | null | package github.walkmansit.aoc2020
import java.util.*
class Day22(val input: String) : DayAoc<Int, Int> {
class Game private constructor(private val deckA: Collection<Int>, private val deckB: Collection<Int>) {
fun getScore(): Int {
val deck1dq: Deque<Int> = ArrayDeque(deckA)
va... | 0 | Kotlin | 0 | 0 | 9c005ac4513119ebb6527c01b8f56ec8fd01c9ae | 3,332 | AdventOfCode2020 | MIT License |
src/main/kotlin/AvailableMeetingSlotsInCalendar.kt | nmicra | 262,980,033 | false | null | import java.time.LocalTime
val person1_meetings = listOf("09:00-09:30", "13:00-14:00", "17:20-18:00") // Scheduled meetings for Person1
val person2_meetings = listOf( "13:30-14:30", "17:00-17:30") // Scheduled meetings for Person2
val restrictions_person1 = "08:00,19:00" // Person1 cannot accept meetings before 8:00 &... | 0 | Kotlin | 0 | 0 | 4bf80f01af6c4a08221131878b7d53e2826db241 | 2,609 | kotlin_practice | Apache License 2.0 |
src/main/kotlin/icfp2019/Brain.kt | randomsamples | 189,507,360 | true | {"JavaScript": 797310, "Kotlin": 89529, "CSS": 9434, "HTML": 5859} | package icfp2019
import icfp2019.analyzers.ConservativeDistanceAnalyzer
import icfp2019.core.DistanceEstimate
import icfp2019.core.Strategy
import icfp2019.core.applyAction
import icfp2019.model.Action
import icfp2019.model.GameState
import icfp2019.model.Problem
import icfp2019.model.RobotId
fun strategySequence(
... | 0 | JavaScript | 0 | 0 | afcf5123ffb72ac10cfa6b0772574d9826f15e41 | 4,098 | icfp-2019 | The Unlicense |
src/Day01.kt | Olivki | 573,156,936 | false | {"Kotlin": 11297} | fun main() {
fun part1(input: List<String>) = buildList {
val inventory = hashSetOf<Int>()
for (line in input) {
if (line.isNotBlank()) {
inventory += line.toInt()
} else {
add(inventory.sum())
inventory.clear()
}
... | 0 | Kotlin | 0 | 1 | 51c408f62589eada3d8454740c9f6fc378e2d09b | 879 | aoc-2022 | Apache License 2.0 |
modules/fathom/src/main/kotlin/silentorb/mythic/fathom/surfacing/old/DuplicateContours.kt | silentorb | 227,508,449 | false | null | package silentorb.mythic.fathom.surfacing.old
import silentorb.mythic.fathom.surfacing.Contours
import kotlin.math.abs
tailrec fun groupDuplicates(tolerance: Float, contours: Contours, duplicates: List<Contours>): List<Contours> {
return if (contours.none())
duplicates
else {
val next = contours.first()
... | 0 | Kotlin | 0 | 2 | 74462fcba9e7805dddec1bfcb3431665df7d0dee | 1,998 | mythic-kotlin | MIT License |
src/main/kotlin/days/Day7.kt | jgrgt | 433,952,606 | false | {"Kotlin": 113705} | package days
import kotlin.math.abs
class Day7 : Day(7) {
override fun runPartOne(lines: List<String>): Any {
val horizontalPositions = lines[0].split(",").map { it.trim().toInt() }
val median = horizontalPositions.median()
return horizontalPositions.sumOf { abs(it - median) }
}
o... | 0 | Kotlin | 0 | 0 | 6231e2092314ece3f993d5acf862965ba67db44f | 1,188 | aoc2021 | Creative Commons Zero v1.0 Universal |
src/Day25/Day25.kt | martin3398 | 436,014,815 | false | {"Kotlin": 63436, "Python": 5921} | fun List<List<Char>>.print() {
for (row in this) {
for (e in row) {
print(e)
}
println()
}
}
fun main() {
fun preprocess(input: List<String>): List<List<Char>> {
return input.map { it.toList() }
}
fun doStep(input: List<List<Char>>): List<List<Char>> {
... | 0 | Kotlin | 0 | 0 | 085b1f2995e13233ade9cbde9cd506cafe64e1b5 | 1,773 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DungeonGame.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 | 1,629 | kotlab | Apache License 2.0 |
src/Day01.kt | eleung4 | 574,590,563 | false | {"Kotlin": 7285} | fun main() {
fun part1(input: List<String>): Int {
return input.size
}
fun part2(input: List<String>): Int {
return input.size
}
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day01_test")
println(part1(testInput))
// pri... | 0 | Kotlin | 0 | 0 | 9013be242f7c2a13f73b297eee9be60655b531ac | 1,011 | AdventOfCode | Apache License 2.0 |
aoc2023/src/main/kotlin/de/havox_design/aoc2023/day14/Matrix.kt | Gentleman1983 | 737,309,232 | false | {"Kotlin": 746488, "Java": 441473, "Scala": 33415, "Groovy": 5725, "Python": 3319} | package de.havox_design.aoc2023.day14
data class Matrix(val matrix: MutableList<CharArray>) {
private val ICON_ROUND_STONE = 'O'
private val ICON_SQUARE_STONE = '#'
fun cycle(cycles: Int = 1): Matrix = apply {
repeat(cycles) {
rollNorth()
.rollWest()
.ro... | 4 | Kotlin | 0 | 1 | 35ce3f13415f6bb515bd510a1f540ebd0c3afb04 | 3,965 | advent-of-code | Apache License 2.0 |
src/Day02.kt | erikthered | 572,804,470 | false | {"Kotlin": 36722} | fun main() {
fun part1(input: List<String>): Int {
var score = 0
for(line in input) {
val opponent = OpponentMove.valueOf(line[0].toString())
val player = PlayerMove.valueOf(line[2].toString())
score += player.points
score += determineOutcome(opponen... | 0 | Kotlin | 0 | 0 | 3946827754a449cbe2a9e3e249a0db06fdc3995d | 2,790 | aoc-2022-kotlin | Apache License 2.0 |
src/com/kotlin/pocs/predicates/Predicates.kt | serbanghita | 253,706,661 | false | null | package com.kotlin.pocs.predicates
fun main(args: Array<String>): Unit {
// val n = listOf(1,2,3,4,5,6,7,8);
// val pred = { value: Int -> value > 5 }
//
// println(n.all(pred))
// println(n.any(pred))
// println(n.count { it > 5 })
//
// println(n.find(pred))
val players = listOf(
Play... | 0 | Kotlin | 0 | 0 | bca562981c731ab5c3fca4519a1af5f67fe8b754 | 1,890 | kotlin-pocs | MIT License |
ctci/arrays_and_strings/_01_is_unique/IsUnique.kt | vishal-sehgal | 730,172,606 | false | {"Kotlin": 8936} | package ctci.arrays_and_strings._01_is_unique
/**
* #1.1
*
* Is Unique: Implement an algorithm to determine if a string has all unique characters.
* What if you can not use additional data structures?
*/
fun main() {
val string1 = "vishal"
val string2 = "sehgal"
val string3 = "linkedin"
val strin... | 0 | Kotlin | 0 | 0 | f83e929dfef941fbd8150c3ebc7c7c6fee60148b | 3,360 | kotlin-coding-interview | MIT License |
src/main/kotlin/com/chriswk/aoc/advent2021/Day17.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2021
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.Pos
import com.chriswk.aoc.util.report
import com.chriswk.aoc.util.reportNano
import kotlin.math.sign
import kotlin.system.measureNanoTime
import kotlin.system.measureTimeMillis
class Day17: AdventDay(2021, 17) {
compa... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 2,816 | adventofcode | MIT License |
codeforces/src/main/kotlin/contest1911/H.kt | austin226 | 729,634,548 | false | {"Kotlin": 23837} | // https://codeforces.com/contest/1911/problem/H
private fun String.splitWhitespace() = split("\\s+".toRegex())
private fun <T> List<T>.counts(): Map<T, Int> = this.groupingBy { it }.eachCount()
private fun <T : Comparable<T>> List<T>.isStrictlyDecreasing(): Boolean =
(size <= 1) || (1 until size).all { i -> get(... | 0 | Kotlin | 0 | 0 | 4377021827ffcf8e920343adf61a93c88c56d8aa | 1,528 | codeforces-kt | MIT License |
src/main/kotlin/dev/bogwalk/batch7/Problem77.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch7
import dev.bogwalk.util.maths.primeNumbers
/**
* Problem 77: Prime Summations
*
* https://projecteuler.net/problem=77
*
* Goal: Count the number of ways that N can be written as the sum of 1 or more primes.
*
* Constraints: 2 <= N <= 1000
*
* e.g.: N = 5
* count = 2 -> {5, 3... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 1,609 | project-euler-kotlin | MIT License |
year2019/day01/part2/src/main/kotlin/com/curtislb/adventofcode/year2019/day01/part2/Year2019Day01Part2.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Part Two ---
During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the
launch sequence. Apparently, you forgot to include additional fuel for the fuel you just added.
Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and
subtra... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,317 | AdventOfCode | MIT License |
src/Day02.kt | burtz | 573,411,717 | false | {"Kotlin": 10999} |
enum class Moves(val points: Int) {
Rock(1),
Paper(2),
Scissors(3)
}
enum class Result(val points: Int) {
Win(6),
Draw(3),
Lose(0)
}
fun main() {
// Rules
// Opponents input: Rock A, Paper B, Scissors C
// My input : Rock X (1 point), Paper Y (2 points), Scissors Z (3 points)
... | 0 | Kotlin | 0 | 0 | daac7f91e1069d1490e905ffe7b7f11b5935af06 | 3,250 | adventOfCode2022 | Apache License 2.0 |
src/main/kotlin/com/mobiento/aoc/Day03.kt | markburk | 572,970,459 | false | {"Kotlin": 22252} | package com.mobiento.aoc
class Day03 {
private val priority: Map<Char, Int> = hashMapOf<Char, Int>().apply {
var priority = 0
for (c in 'a' .. 'z') {
this[c] = ++priority
}
for (c in 'A' .. 'Z') {
this[c] = ++priority
}
}
fun part1(input: Li... | 0 | Kotlin | 0 | 0 | d28656b4d54c506a01252caf6b493e4f7f97e896 | 1,348 | potential-lamp | Apache License 2.0 |
src/main/kotlin/com/colinodell/advent2021/Day21.kt | colinodell | 433,864,377 | true | {"Kotlin": 111114} | package com.colinodell.advent2021
import java.util.Stack
import kotlin.math.max
import kotlin.math.min
class Day21(private val player1Start: Int, private val player2Start: Int) {
val universesPerRoll = arrayOf(0, 0, 0, 1, 3, 6, 7, 6, 3, 1)
fun solvePart1(): Int {
var game = Game(Player(player1Start),... | 0 | Kotlin | 0 | 1 | a1e04207c53adfcc194c85894765195bf147be7a | 2,455 | advent-2021 | Apache License 2.0 |
src/Day06.kt | b0n541 | 571,797,079 | false | {"Kotlin": 17810} | fun main() {
fun String.findMarker(length: Int) = this.indexOf(
this.windowed(length, 1)
.first { substring -> substring.toSet().size == length }) + length
fun part1(input: List<String>): List<Int> {
return input.map { it.findMarker(4) }
}
fun part2(input: List<String>): L... | 0 | Kotlin | 0 | 0 | d451f1aee157fd4d47958dab8a0928a45beb10cf | 1,016 | advent-of-code-2022 | Apache License 2.0 |
problems/src/main/kotlin/org/fundamentals/fp/euler/EulerProblem03.kt | jabrena | 171,358,482 | false | {"HTML": 788595, "Java": 339834, "Kotlin": 16414, "Gherkin": 1092} | package org.fundamentals.fp.euler
/**
* Largest prime factor
* https://projecteuler.net/problem=3
*
* The prime factors of 13195 are 5, 7, 13 and 29.
*
* What is the largest prime factor of the number 600851475143 ?
*
* Scenario 13195
*
* Given primeFactor
* When 13195
* Then 29 [5, 7, 13, 29]
*
* Scenar... | 3 | HTML | 3 | 8 | c722696e1c7130527f2c4952cc37bb3a6c70e374 | 2,317 | functional-rosetta-stone | Apache License 2.0 |
src/main/kotlin/nl/jackploeg/aoc/_2022/calendar/day12/Day12.kt | jackploeg | 736,755,380 | false | {"Kotlin": 318734} | package nl.jackploeg.aoc._2022.calendar.day12
import javax.inject.Inject
import nl.jackploeg.aoc.generators.InputGenerator.InputGeneratorFactory
import nl.jackploeg.aoc.utilities.readStringFile
class Day12 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
fun partOne(filename: Stri... | 0 | Kotlin | 0 | 0 | f2b873b6cf24bf95a4ba3d0e4f6e007b96423b76 | 2,924 | advent-of-code | MIT License |
src/main/kotlin/com/hj/leetcode/kotlin/problem2090/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2090
/**
* LeetCode page: [2090. K Radius Subarray Averages](https://leetcode.com/problems/k-radius-subarray-averages/);
*/
class Solution {
/* Complexity:
* Time O(N) and Space O(N) where N is the size of nums;
*/
fun getAverages(nums: IntArray, k: Int): IntAr... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,326 | hj-leetcode-kotlin | Apache License 2.0 |
2021/src/day12/Solution.kt | vadimsemenov | 437,677,116 | false | {"Kotlin": 56211, "Rust": 37295} | package day12
import java.nio.file.Files
import java.nio.file.Paths
fun main() {
fun buildGraph(lines: Input): Map<String, List<String>> = buildMap<String, MutableList<String>> {
for (line in lines) {
val (v, w) = line.split("-")
val vList = getOrPut(v) { mutableListOf() }
val wList = getOrPut... | 0 | Kotlin | 0 | 0 | 8f31d39d1a94c862f88278f22430e620b424bd68 | 1,496 | advent-of-code | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ImplementTrie.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,854 | kotlab | Apache License 2.0 |
src/main/kotlin/com/hj/leetcode/kotlin/problem438/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem438
/**
* LeetCode page: [438. Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/);
*/
class Solution {
/* Complexity:
* Time O(|s|) and Space O(1);
*/
fun findAnagrams(s: String, p: String): List<Int> {
if (s.le... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,864 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/com/ginsberg/advent2016/Day07.kt | tginsberg | 74,924,040 | false | null | /*
* Copyright (c) 2016 by <NAME>
*/
package com.ginsberg.advent2016
/**
* Advent of Code - Day 7: December 7, 2016
*
* From http://adventofcode.com/2016/day/7
*
*/
class Day07(private val input: List<String>) {
/**
* How many IPs in your puzzle input support TLS?
*/
fun solvePart1(): Int =... | 0 | Kotlin | 0 | 3 | a486b60e1c0f76242b95dd37b51dfa1d50e6b321 | 2,259 | advent-2016-kotlin | MIT License |
src/Day01.kt | cnietoc | 572,880,374 | false | {"Kotlin": 15990} | fun main() {
fun calculateElvesCalories(input: List<String>): MutableList<Long> {
val elvesCalories = mutableListOf<Long>()
var index = 0
input.forEach {
if (it.isBlank()) {
index++
} else {
if (elvesCalories.getOrNull(index) == null) {... | 0 | Kotlin | 0 | 0 | bbd8e81751b96b37d9fe48a54e5f4b3a0bab5da3 | 1,083 | aoc-2022 | Apache License 2.0 |
kotlin/graphs/spanningtree/PrimHeap.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package graphs.spanningtree
// https://en.wikipedia.org/wiki/Prim%27s_algorithm in O(E*log(V))
object PrimHeap {
fun mst(edges: Array<List<Edge>?>, pred: IntArray): Long {
val n = edges.size
Arrays.fill(pred, -1)
val used = BooleanArray(n)
val prio = IntArray(n)
Arrays.fill(... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 1,558 | codelibrary | The Unlicense |
archive/524/solve.kt | daniellionel01 | 435,306,139 | false | null | /*
=== #524 First Sort II - Project Euler ===
Consider the following algorithm for sorting a list:
1. Starting from the beginning of the list, check each pair of adjacent elements in turn.
2. If the elements are out of order:
a. Move the smallest element of the pair at the beginning of the list.
b. Restart the process... | 0 | Kotlin | 0 | 1 | 1ad6a549a0a420ac04906cfa86d99d8c612056f6 | 1,985 | euler | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/EliminateMaxNumOfMonsters.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,177 | kotlab | Apache License 2.0 |
code/data_structures/SparseMinTable.kt | hakiobo | 397,069,173 | false | null | private class SparseMinTable(val nums: IntArray) {
val n = nums.size
val table = Array(
((n shl 2) - 1).takeHighestOneBit().countTrailingZeroBits()
) { IntArray(n) }
init {
for (x in 0 until n) {
table[0][x] = x
}
for (bit in 1 until table.size) {
... | 0 | Kotlin | 1 | 2 | f862cc5e7fb6a81715d6ea8ccf7fb08833a58173 | 1,220 | Kotlinaughts | MIT License |
src/test/kotlin/ch/ranil/aoc/aoc2022/Day18.kt | stravag | 572,872,641 | false | {"Kotlin": 234222} | package ch.ranil.aoc.aoc2022
import ch.ranil.aoc.AbstractDay
import org.junit.jupiter.api.Test
import kotlin.math.max
import kotlin.math.min
import kotlin.test.assertEquals
object Day18 : AbstractDay() {
@Test
fun part1Test() {
assertEquals(64, compute1(testInput))
}
@Test
fun part1Puzzl... | 0 | Kotlin | 1 | 0 | dbd25877071cbb015f8da161afb30cf1968249a8 | 4,159 | aoc | Apache License 2.0 |
src/main/kotlin/day5.kt | Gitvert | 433,947,508 | false | {"Kotlin": 82286} | const val SIZE = 1000
fun day5() {
val lines: List<String> = readFile("day05.txt")
day5part1(lines)
day5part2(lines)
}
fun day5part1(lines: List<String>) {
val answer = findAnswer(lines, false)
println("5a: $answer")
}
fun day5part2(lines: List<String>) {
val answer = findAnswer(lines, true... | 0 | Kotlin | 0 | 0 | 02484bd3bcb921094bc83368843773f7912fe757 | 4,016 | advent_of_code_2021 | MIT License |
src/main/kotlin/g2101_2200/s2106_maximum_fruits_harvested_after_at_most_k_steps/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2101_2200.s2106_maximum_fruits_harvested_after_at_most_k_steps
// #Hard #Array #Binary_Search #Prefix_Sum #Sliding_Window
// #2023_06_25_Time_816_ms_(100.00%)_Space_107.6_MB_(100.00%)
class Solution {
fun maxTotalFruits(fruits: Array<IntArray>, startPos: Int, k: Int): Int {
var res = 0
va... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,159 | LeetCode-in-Kotlin | MIT License |
aoc-2023/src/main/kotlin/aoc/aoc16.kts | triathematician | 576,590,518 | false | {"Kotlin": 615974} | import aoc.AocParser.Companion.parselines
import aoc.*
import aoc.util.*
val testInput = """
.|...\....
|.-.\.....
.....|-...
........|.
..........
.........\
..../.\\..
.-.-/..|..
.|....-|.\
..//.|....
""".parselines
class LaserMaze(val lines: CharGrid) {
fun at(c: Coord) = lines.getOrNull(c.y)?.getOrNull(c.x)
... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 4,091 | advent-of-code | Apache License 2.0 |
src/Day09.kt | dustinlewis | 572,792,391 | false | {"Kotlin": 29162} | import kotlin.math.abs
fun main() {
fun part1(input: List<String>): Int {
// starting position counts as visited
val tailVisits = mutableSetOf<Position>()
var headPosition = Position(0, 0)
var tailPosition = Position(0, 0)
tailVisits.add(tailPosition)
val moves = i... | 0 | Kotlin | 0 | 0 | c8d1c9f374c2013c49b449f41c7ee60c64ef6cff | 5,494 | aoc-2022-in-kotlin | Apache License 2.0 |
src/chapter5/section2/TrieSTIterative.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter5.section2
import chapter5.section1.Alphabet
import edu.princeton.cs.algs4.Queue
import edu.princeton.cs.algs4.Stack
/**
* 基于单词查找树的符号表(非递归实现)
*/
open class TrieSTIterative<V : Any>(protected val alphabet: Alphabet) : StringST<V> {
protected inner class Node {
val next = arrayOfNulls<Node... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 6,145 | Algorithms-4th-Edition-in-Kotlin | MIT License |
advent08/src/Registers.kt | mike10004 | 113,916,865 | false | {"JavaScript": 102872, "C": 9916, "Python": 9458, "Java": 6985, "Go": 3689, "Kotlin": 2536, "Shell": 534} | import java.io.File
import java.io.FileReader
import java.util.stream.Stream
fun main(args: Array<String>) {
FileReader(File("./input.txt")).buffered().use {
main(it.lines())
}
}
fun doExample() {
val lines = listOf(
"b inc 5 if a > 1",
"a inc 1 if b < 5",
"c de... | 0 | JavaScript | 0 | 0 | 977c5c16c90e612447d0842c197d90d35c7e63f7 | 2,536 | adventofcode2017 | MIT License |
src/main/kotlin/adventofcode/day19/Blueprint.kt | jwcarman | 573,183,719 | false | {"Kotlin": 183494} | /*
* Copyright (c) 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 i... | 0 | Kotlin | 0 | 0 | d6be890aa20c4b9478a23fced3bcbabbc60c32e0 | 2,660 | adventofcode2022 | Apache License 2.0 |
src/Day01.kt | Feketerig | 571,677,145 | false | {"Kotlin": 14818} | fun main() {
fun readCalories(input: List<String>): List<Int>{
val calories = mutableListOf<Int>()
var calorie = 0
input.forEach {line ->
if (line.isEmpty()){
calories.add(calorie)
calorie = 0
}else{
calorie += line.toI... | 0 | Kotlin | 0 | 0 | c65e4022120610d930293788d9584d20b81bc4d7 | 979 | Advent-of-Code-2022 | Apache License 2.0 |
src/2/2667.kt | xCrypt0r | 287,291,199 | false | null | /**
* 2667. 단지번호붙이기
*
* 작성자: <NAME>
* 언어: Kotlin (JVM)
* 사용 메모리: 20,200 KB
* 소요 시간: 176 ms
* 해결 날짜: 2020년 9월 29일
*/
import java.util.Scanner
fun main() {
val scanner = Scanner(System.`in`)
val mapSize = scanner.nextLine().toInt()
val map = Array(mapSize) { scanner.nextLine().toCharArray().map { i... | 5 | C++ | 9 | 13 | 7d858d557dbbde6603fe4e8af2891c2b0e1940c0 | 1,865 | Baekjoon | MIT License |
src/day05/Day05Answer2.kt | IThinkIGottaGo | 572,833,474 | false | {"Kotlin": 72162} | package day05
import readString
/**
* Answers from [Advent of Code 2022 Day 5 | Kotlin](https://youtu.be/lKq6r5Nt8Yo)
*/
val input = readString("day05").split("\n\n")
fun main() {
val (initialStackDescription, instructions) = input
val initialStacks = initialStackDescription.lines().dropLast(1).reversed().... | 0 | Kotlin | 0 | 0 | 967812138a7ee110a63e1950cae9a799166a6ba8 | 2,107 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | phoenixli | 574,035,552 | false | {"Kotlin": 29419} | fun main() {
fun part1(input: List<String>): String {
val crateStacks = populateCrates()
input.subList(10, input.size).forEach{
performMove(it, crateStacks)
}
var result = ""
for (stack in crateStacks) {
result += stack.removeLast()
}
... | 0 | Kotlin | 0 | 0 | 5f993c7b3c3f518d4ea926a792767a1381349d75 | 2,355 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/kotlin/io/github/thanosfisherman/bayes/BayesClassifier.kt | ThanosFisherman | 154,952,306 | false | null | package io.github.thanosfisherman.bayes
import kotlin.math.ln
/**
* Simple Naive Bayes Classifier in Kotlin
*
* @author <NAME>
*
* Helpful References:
*
* * https://monkeylearn.com/blog/practical-explanation-naive-bayes-classifier/
* * https://stats.stackexchange.com/questions/274251/why-do-we-need-laplace-sm... | 0 | Kotlin | 2 | 3 | 95a73070cc6a647b297034ad1f2500c0cbec02d9 | 3,497 | kaive-bayes | Apache License 2.0 |
src/main/kotlin/day4.kt | gautemo | 725,273,259 | false | {"Kotlin": 79259} | import shared.Input
import shared.toInts
import kotlin.math.pow
fun main() {
val input = Input.day(4)
println(day4A(input))
println(day4B(input))
}
fun day4A(input: Input): Int {
return input.lines.sumOf { card ->
val (winning, yours) = card.split(':')[1].split('|').map(String::toInts)
... | 0 | Kotlin | 0 | 0 | 6862b6d7429b09f2a1d29aaf3c0cd544b779ed25 | 859 | AdventOfCode2023 | MIT License |
src/day06/Day06.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day06
import readLines
fun main() {
fun find_marker(input: String, distinctCharCount: Int): Int {
var charSet = HashSet<Char>()
var count = 0
var left = 0
for ((index, char) in input.withIndex()) {
if (charSet.contains(char)) {
while (input[left... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 1,299 | aoc2022 | Apache License 2.0 |
src/main/kotlin/dev/kosmx/aoc23/garden/VirtualMemory.kt | KosmX | 726,056,762 | false | {"Kotlin": 32011} | package dev.kosmx.aoc23.garden
import java.io.File
import java.math.BigInteger
import kotlin.math.abs
typealias Offset = Pair<OpenEndRange<BigInteger>, BigInteger>
val OpenEndRange<BigInteger>.size: BigInteger
get() = endExclusive - start
val Offset.destination: OpenEndRange<BigInteger>
get() = (first.start... | 0 | Kotlin | 0 | 0 | ad01ab8e9b8782d15928a7475bbbc5f69b2416c2 | 7,581 | advent-of-code23 | MIT License |
src/Day06.kt | rod41732 | 728,131,475 | false | {"Kotlin": 26028} | /**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
fun getNumbers(line: String): List<Int> {
return Regex("\\d+").findAll(line).map { it.value.toInt() }.toList()
}
fun getWaysToBeat(time: Int, record: Long): Int {
(1L..time.toLong()).forEach { holdDurati... | 0 | Kotlin | 0 | 0 | 05a308a539c8a3f2683b11a3a0d97a7a78c4ffac | 1,333 | aoc-23 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.