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/me/grison/aoc/y2020/Day19.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc.y2020
import me.grison.aoc.*
class Day19 : Day(19, 2020) {
override fun title() = "Monster Messages"
private val solutionKey = "0"
override fun partOne() = findSolutions(loadRules()).let { solutions ->
loadMessages().count { solutions[solutionKey]!!.regex().matches(it) }
... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 2,516 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/year2021/day-13.kt | ppichler94 | 653,105,004 | false | {"Kotlin": 182859} | package year2021
import lib.Position
import lib.aoc.Day
import lib.aoc.Part
fun main() {
Day(13, 2021, PartA13(), PartB13()).run()
}
open class PartA13 : Part() {
data class Paper(var points: List<Position>) {
var width = points.maxOf { it[0] } + 1
var height = points.maxOf { it[1] } + 1
... | 0 | Kotlin | 0 | 0 | 49dc6eb7aa2a68c45c716587427353567d7ea313 | 3,270 | Advent-Of-Code-Kotlin | MIT License |
src/day_7.kt | gardnerdickson | 152,621,962 | false | null | import java.io.File
import java.util.regex.Matcher
fun main(args: Array<String>) {
val filename = "res/day_7_input.txt"
val answer1 = Day7.part1(File(filename))
println("Part 1: $answer1")
val answer2 = Day7.part2(File(filename), answer1)
println("Part 2: $answer2")
}
object Day7 {
fun part1(... | 0 | Kotlin | 0 | 0 | 4a23ab367a87cae5771c3c8d841303b984474547 | 5,103 | advent-of-code-2015 | MIT License |
day22/src/main/kotlin/Main.kt | rstockbridge | 159,586,951 | false | null | fun main() {
val inputDepth = 5616
val inputTarget = GridPoint2d(x = 10, y = 785)
val cave = Cave(inputDepth, inputTarget)
println("Part I: the solution is ${cave.risk()}")
println("Part II: the solution is ${cave.rescueTime()}")
}
class Cave(private val scanDepth: Int, private val scanTarget: Gr... | 0 | Kotlin | 0 | 0 | c404f1c47c9dee266b2330ecae98471e19056549 | 4,377 | AdventOfCode2018 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LatestDayToCross.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 | 7,717 | kotlab | Apache License 2.0 |
src/main/kotlin/at/doml/anc/lab2/MultiSearchers.kt | domagojlatecki | 124,923,523 | false | null | package at.doml.anc.lab2
import java.lang.Math.sqrt
object MultiSearchers {
private operator fun DoubleArray.minus(other: DoubleArray): DoubleArray {
val new = DoubleArray(this.size) { i -> this[i] }
for (i in this.indices) {
new[i] -= other[i]
}
return new
}
... | 0 | Kotlin | 0 | 0 | b483dda88bd9f2a6dc9f4928c7aa4e9a217eac8f | 7,209 | anc-lab | MIT License |
src/main/kotlin/no/uib/inf273/operators/MinimizeWaitTime.kt | elgbar | 237,403,030 | false | {"Kotlin": 141160} | package no.uib.inf273.operators
import no.uib.inf273.extra.randomizeExchange
import no.uib.inf273.processor.Solution
/**
* Minimize the cargo that is waiting the longest globally.
* This operators find the cargo which is currently waiting for port opening the longest and to and change the vessel cargo
* order in s... | 0 | Kotlin | 0 | 3 | 1f76550a631527713b1eba22817e6c1215f5d84e | 2,310 | INF273 | The Unlicense |
src/main/kotlin/_2022/Day3.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2022
import REGEX_LINE_SEPARATOR
import aoc
const val LOWER_CODE_OFFSET = 'a'.code - 1
const val UPPER_CODE_OFFSET = 'A'.code - 27
fun main() {
aoc(2022, 3) {
aocRun { input ->
input.split(REGEX_LINE_SEPARATOR).sumOf { contents ->
findCommonItemsInRucksack(contents).sumOf { itemPriority(it) }
}... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 1,074 | AdventOfCode | Creative Commons Zero v1.0 Universal |
p08/src/main/kotlin/MemoryManeuver.kt | jcavanagh | 159,918,838 | false | null | package p08
import common.file.readLines
import java.util.*
class Node(
val metadata: MutableList<Int> = mutableListOf(),
val children: MutableList<Node> = mutableListOf()
) {
fun sum(): Int {
return children.fold(metadata.sum()) { all, node ->
all + node.sum()
}
}
fun value(): Int {
if(c... | 0 | Kotlin | 0 | 0 | 289511d067492de1ad0ceb7aa91d0ef7b07163c0 | 1,562 | advent2018 | MIT License |
src/day05/a/day05a.kt | pghj | 577,868,985 | false | {"Kotlin": 94937} | package day05.a
import readInputLines
import shouldBe
fun main() {
val lines = readInputLines(5)
val i = lines.indexOfFirst { it.isBlank() }
val stacks = readInitialStacks(lines.subList(0, i))
val instr = lines.subList(i+1, lines.size)
for (j in instr) apply(decodeInstruction(j), stacks)
val t... | 0 | Kotlin | 0 | 0 | 4b6911ee7dfc7c731610a0514d664143525b0954 | 1,213 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/MaxTurbulenceSize.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
/**
* 978. 最长湍流子数组
* 当 A 的子数组 A[i], A[i+1], ..., A[j] 满足下列条件时,我们称其为湍流子数组:
*
* 若 i <= k < j,当 k 为奇数时, A[k] > A[k+1],且当 k 为偶数时,A[k] < A[k+1];
* 或 若 i <= k < j,当 k 为偶数时,A[k] > A[k+1] ,且当 k 为奇数时, A[k] < A[k+1]。
* 也就是说,如果比较符号在子数组中的每个相邻元素对之间翻转,则该子数组是湍流子数组。
* 返回 A 的最大湍流子数组的长度。
*/
... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 1,726 | daily_algorithm | Apache License 2.0 |
src/main/kotlin/com/staricka/adventofcode2023/days/Day13.kt | mathstar | 719,656,133 | false | {"Kotlin": 107115} | package com.staricka.adventofcode2023.days
import com.staricka.adventofcode2023.framework.Day
import com.staricka.adventofcode2023.util.*
enum class ReflectionDirection {
COLUMN, ROW
}
data class ReflectionPoint(val num: Int, val direction: ReflectionDirection)
fun <T: GridCell> StandardGrid<T>.findReflection()... | 0 | Kotlin | 0 | 0 | 8c1e3424bb5d58f6f590bf96335e4d8d89ae9ffa | 3,639 | adventOfCode2023 | MIT License |
src/main/kotlin/se/brainleech/adventofcode/aoc2020/Aoc2020Day01.kt | fwangel | 435,571,075 | false | {"Kotlin": 150622} | package se.brainleech.adventofcode.aoc2020
import se.brainleech.adventofcode.compute
import se.brainleech.adventofcode.readIntegers
import se.brainleech.adventofcode.verify
class Aoc2020Day01 {
fun part1(entries: List<Int>): Int {
return entries
.filter { entries.contains(2020 - it) }
... | 0 | Kotlin | 0 | 0 | 0bba96129354c124aa15e9041f7b5ad68adc662b | 1,287 | adventofcode | MIT License |
src/Day01.kt | lonskiTomasz | 573,032,074 | false | {"Kotlin": 22055} | fun main() {
fun maxCalories(input: List<String>): Int {
var maximum = 0
var current = 0
input.forEach { line ->
if (line.isBlank()) {
maximum = maxOf(maximum, current)
current = 0
} else {
current += line.toInt()
... | 0 | Kotlin | 0 | 0 | 9e758788759515049df48fb4b0bced424fb87a30 | 1,570 | advent-of-code-kotlin-2022 | Apache License 2.0 |
app/src/main/kotlin/com/resurtm/aoc2023/day12/Solution.kt | resurtm | 726,078,755 | false | {"Kotlin": 119665} | package com.resurtm.aoc2023.day12
fun launchDay12(testCase: String) {
println("Day 12, part 1: ${calculate(testCase)}")
println("Day 12, part 2: ${calculate(testCase, 5)}")
}
private fun calculate(testCase: String, repCount: Int = 1): Long {
val reader =
object {}.javaClass.getResourceAsStream(tes... | 0 | Kotlin | 0 | 0 | fb8da6c246b0e2ffadb046401502f945a82cfed9 | 2,706 | advent-of-code-2023 | MIT License |
advent/src/test/kotlin/org/elwaxoro/advent/y2021/Dec15.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2021
import org.elwaxoro.advent.Node
import org.elwaxoro.advent.PuzzleDayTester
import org.elwaxoro.advent.cost
import org.elwaxoro.advent.neighborCoords
import org.elwaxoro.advent.splitToInt
/**
* Chiton (oh look its Dijkstra)
*/
class Dec15 : PuzzleDayTester(15, 2021) {
override ... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 2,352 | advent-of-code | MIT License |
src/Day02.kt | ArtManyak | 572,905,558 | false | {"Kotlin": 2152} | fun main() {
fun part1(lines: List<String>): Int {
var score = 0
for (round in lines.map { Pair(it[0] - 'A', it[2] - 'X') }) {
score += round.second + 1
if (round.first == round.second) score += 3
if ((round.first + 1) % 3 == round.second) score += 6
}
... | 0 | Kotlin | 0 | 0 | 8450515b1773f4fd2103a5c8594d43c476603348 | 806 | AoC2022 | Apache License 2.0 |
src/Day08.kt | hrach | 572,585,537 | false | {"Kotlin": 32838} | @file:Suppress("NAME_SHADOWING")
fun main() {
fun getSeq(input: List<List<Int>>, y: Int, x: Int, dy: Int, dx: Int): Sequence<Int> = sequence {
var x = x
var y = y
do {
y += dy
x += dx
val t = input.getOrNull(y)?.getOrNull(x)
if (t != null) yie... | 0 | Kotlin | 0 | 1 | 40b341a527060c23ff44ebfe9a7e5443f76eadf3 | 2,562 | aoc-2022 | Apache License 2.0 |
src/test/kotlin/com/igorwojda/string/maxchar/solution.kt | handiism | 455,862,994 | true | {"Kotlin": 218721} | package com.igorwojda.string.maxchar
// Kotlin idiomatic solution
private object Solution1 {
private fun maxOccurrentChar(str: String): Char? {
return str.toCharArray()
.groupBy { it }
.maxBy { it.value.size }
?.key
}
}
// Kotlin idiomatic solution
private object So... | 1 | Kotlin | 2 | 1 | 413316e0e9de2f237d9768cfa68db3893e72b48c | 1,491 | kotlin-coding-challenges | MIT License |
src/main/kotlin/net/mguenther/adventofcode/day12/Day12.kt | mguenther | 115,937,032 | false | null | package net.mguenther.adventofcode.day12
import net.mguenther.adventofcode.array2dOfBoolean
/**
* @author <NAME> (<EMAIL>)
*/
data class Node(val id: String, val successors: Map<Int, List<Int>>)
fun programsInRootComponent(nodes: Map<Int, List<Int>>): Int {
val adjacencyMatrix = computeAdjacencyMatrix(nodes)... | 0 | Kotlin | 0 | 0 | c2f80c7edc81a4927b0537ca6b6a156cabb905ba | 1,326 | advent-of-code-2017 | MIT License |
kotlin/src/main/kotlin/year2023/Day20.kt | adrisalas | 725,641,735 | false | {"Kotlin": 130217, "Python": 1548} | package year2023
import year2023.Day20.Pulse.HIGH
import year2023.Day20.Pulse.LOW
fun main() {
val input = readInput("Day20")
Day20.part1(input).println()
Day20.part2(input).println()
}
//832957356
//240162699605221
object Day20 {
fun part1(input: List<String>): Int {
val dataStructures = ini... | 0 | Kotlin | 0 | 2 | 6733e3a270781ad0d0c383f7996be9f027c56c0e | 5,873 | advent-of-code | MIT License |
src/main/kotlin/com/chriswk/aoc/advent2021/Day21.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2021
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.report
class Day21: AdventDay(2021, 21) {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day = Day21()
report {
day.part1()
}
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 3,869 | adventofcode | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/BeautifulArrangement.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,084 | kotlab | Apache License 2.0 |
src/day18.kt | miiila | 725,271,087 | false | {"Kotlin": 77215} | import java.io.File
import java.util.Collections.max
import java.util.Collections.min
import kotlin.math.abs
import kotlin.system.exitProcess
private const val DAY = 18
fun main() {
if (!File("./day${DAY}_input").exists()) {
downloadInput(DAY)
println("Input downloaded")
exitProcess(0)
... | 0 | Kotlin | 0 | 1 | 1cd45c2ce0822e60982c2c71cb4d8c75e37364a1 | 5,635 | aoc2023 | MIT License |
src/main/kotlin/com/pandarin/aoc2022/Day4.kt | PandarinDev | 578,619,167 | false | {"Kotlin": 6586} | package com.pandarin.aoc2022
class Range(val from: Int, val until: Int)
typealias RangePair = Pair<Range, Range>
fun RangePair.fullyOverlaps(): Boolean {
return (first.from >= second.from && first.until <= second.until) ||
(second.from >= first.from && second.until <= first.until)
}
fun RangePair.has... | 0 | Kotlin | 0 | 0 | 42c35d23129cc9f827db5b29dd10342939da7c99 | 1,296 | aoc2022 | MIT License |
src/main/kotlin2023/Day005.kt | teodor-vasile | 573,434,400 | false | {"Kotlin": 41204} | package main.kotlin2023
class Day005 {
fun part1(lines: String): Long {
val parsedInput = parseInput(lines)
val seeds = parsedInput.get(0).get(0)
val seedMaps = parsedInput.drop(1)
val locationValues = mutableSetOf<Long>()
for (seed in seeds) {
val foundCorrespo... | 0 | Kotlin | 0 | 0 | 2fcfe95a05de1d67eca62f34a1b456d88e8eb172 | 3,081 | aoc-2022-kotlin | Apache License 2.0 |
src/Day11.kt | mjossdev | 574,439,750 | false | {"Kotlin": 81859} | fun main() {
class MultiModuloNumber private constructor(private val valueByModulus: Map<Int, Int>) {
constructor(value: Int, moduluses: Iterable<Int>) : this(moduluses.associateWith { value % it })
operator fun plus(x: Int) = MultiModuloNumber(valueByModulus.mapValues { (modulus, value) -> (value ... | 0 | Kotlin | 0 | 0 | afbcec6a05b8df34ebd8543ac04394baa10216f0 | 5,449 | advent-of-code-22 | Apache License 2.0 |
src/aoc2022/Day04.kt | nguyen-anthony | 572,781,123 | false | null | package aoc2022
import utils.readInputAsList
fun main() {
fun part1(input: List<String>) : Int {
var fullContains = 0
for(assignment in input) {
val (elf1, elf2) = assignment.split(",")
val (min1, max1) = elf1.split("-").map(String::toInt)
val (min2, max2) = ... | 0 | Kotlin | 0 | 0 | 9336088f904e92d801d95abeb53396a2ff01166f | 1,387 | AOC-2022-Kotlin | Apache License 2.0 |
kotlin/src/com/daily/algothrim/leetcode/EqualSubstring.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
import kotlin.math.abs
import kotlin.math.max
/**
* 1208. 尽可能使字符串相等
* 给你两个长度相同的字符串,s 和 t。
*
* 将 s 中的第 i 个字符变到 t 中的第 i 个字符需要 |s[i] - t[i]| 的开销(开销可能为 0),也就是两个字符的 ASCII 码值的差的绝对值。
*
* 用于变更字符串的最大预算是 maxCost。在转化字符串时,总开销应当小于等于该预算,这也意味着字符串的转化可能是不完全的。
*
* 如果你可以将 s 的子字符串转化为它在 t 中对应的... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,014 | daily_algorithm | Apache License 2.0 |
src/main/kotlin/g0801_0900/s0886_possible_bipartition/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0801_0900.s0886_possible_bipartition
// #Medium #Depth_First_Search #Breadth_First_Search #Graph #Union_Find
// #Graph_Theory_I_Day_14_Graph_Theory #2023_04_08_Time_397_ms_(100.00%)_Space_51.3_MB_(100.00%)
class Solution {
fun possibleBipartition(n: Int, dislikes: Array<IntArray>): Boolean {
// b... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,766 | LeetCode-in-Kotlin | MIT License |
src/Day01.kt | EemeliHeinonen | 574,062,219 | false | {"Kotlin": 6073} | fun sumByElf(input: List<String>): List<Int> = input.fold(mutableListOf(0)) { sums, currentString ->
if (currentString == "") {
sums.add(0)
}
else {
sums[sums.lastIndex] = sums.last().plus(currentString.toInt())
}
sums
}
fun main() {
fun part1(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | 33775d9e6e848ab0efae0e3f00f43368c036799d | 784 | aoc-22-kotlin | Apache License 2.0 |
src/Day07.kt | sushovan86 | 573,586,806 | false | {"Kotlin": 47064} | import java.util.*
sealed class Node(
val name: String,
val parent: Directory? = null,
protected var size: Int = 0
) {
fun getNodeSize() = size
override fun equals(other: Any?): Boolean {
return Objects.equals(this, other)
}
override fun hashCode(): Int {
return Objects.h... | 0 | Kotlin | 0 | 0 | d5f85b6a48e3505d06b4ae1027e734e66b324964 | 4,325 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day07.kt | brigham | 573,127,412 | false | {"Kotlin": 59675} | private val ElfDirectory.dirs: Sequence<ElfDirectory>
get() = entries.asSequence().mapNotNull { it.asDirectory }
fun ElfDirectory.getDirectory(name: String): ElfDirectory =
dirs.first { it.name == name }
interface ElfEntry {
val name: String
val size: Int
val entries: List<ElfEntry>
val asFile... | 0 | Kotlin | 0 | 0 | b87ffc772e5bd9fd721d552913cf79c575062f19 | 4,348 | advent-of-code-2022 | Apache License 2.0 |
src/Day10.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | fun main() {
fun toValues(input: List<String>): List<Int> {
val current = mutableListOf(1)
input.forEach {
current.add(current.last())
if (it.startsWith("addx")) {
current.add(current.last() + it.split(" ")[1].toInt())
}
}
return cu... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 1,719 | advent-of-kotlin-2022 | Apache License 2.0 |
year2018/src/main/kotlin/net/olegg/aoc/year2018/day23/Day23.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2018.day23
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.Vector3D
import net.olegg.aoc.year2018.DayOf2018
import java.util.PriorityQueue
/**
* See [Year 2018, Day 23](https://adventofcode.com/2018/day/23)
*/
object Day23 : DayOf2018(23) {
private val PATTERN = "pos=<(-?... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 4,165 | adventofcode | MIT License |
06/src/commonMain/kotlin/Main.kt | daphil19 | 725,415,769 | false | {"Kotlin": 131380} | expect fun getLines(): List<String>
fun main() {
var lines = getLines()
// lines = """Time: 7 15 30
//Distance: 9 40 200""".lines()
part1(lines)
part2(lines)
}
fun part1(lines: List<String>) = printDuration {
val times = lines[0].removePrefix("Time: ").trim().split(" ").filter { it.isNo... | 0 | Kotlin | 0 | 0 | 70646b330cc1cea4828a10a6bb825212e2f0fb18 | 1,256 | advent-of-code-2023 | Apache License 2.0 |
src/Day01.kt | ty-garside | 573,030,387 | false | {"Kotlin": 75779} | // Day 1: Calorie Counting
// https://adventofcode.com/2022/day/1
fun main() {
// NOTE: assumes always at least one elf and ignores possible
// parsing errors and extra blank lines
fun List<String>.sumOfCaloriesForEachElf() =
fold(mutableListOf(0 /* first elf */)) { elves, calories ->
... | 0 | Kotlin | 0 | 0 | 49ea6e3ad385b592867676766dafc48625568867 | 4,481 | aoc-2022-in-kotlin | Apache License 2.0 |
lib/src/main/kotlin/com/bloidonia/advent/day14/Day14.kt | timyates | 433,372,884 | false | {"Kotlin": 48604, "Groovy": 33934} | package com.bloidonia.advent.day14
import com.bloidonia.advent.readText
class Template(
private val initialChar: Char,
private val polymer: Map<String, Long>,
private val insertions: Map<String, List<String>>
) {
fun step(): Template {
val next = mutableMapOf<String, Long>()
polymer.fo... | 0 | Kotlin | 0 | 1 | 9714e5b2c6a57db1b06e5ee6526eb30d587b94b4 | 1,757 | advent-of-kotlin-2021 | MIT License |
kotlin/src/com/daily/algothrim/leetcode/medium/Exist.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode.medium
/**
* 79. 单词搜索
*
* 给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中,返回 true ;否则,返回 false 。
* 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。
*/
class Exist {
companion object {
@JvmStatic
fun main(args: Array<String>) {
... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,969 | daily_algorithm | Apache License 2.0 |
advent-of-code-2021/src/main/kotlin/eu/janvdb/aoc2021/day04/Day04.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2021.day04
import eu.janvdb.aocutil.kotlin.readLines
const val FILENAME = "input04.txt"
const val CARD_SIZE = 5
fun main() {
val lines = readLines(2021, FILENAME).map { it.trim() }.filter { it.isNotBlank() }
val numbers = lines[0].split(",").map { it.toInt() }
val cards = lines.asSequence()
... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,462 | advent-of-code | Apache License 2.0 |
2022/09/09.kt | LiquidFun | 435,683,748 | false | {"Kotlin": 40554, "Python": 35985, "Julia": 29455, "Rust": 20622, "C++": 1965, "Shell": 1268, "APL": 191} | operator fun Pair<Int, Int>.plus(o: Pair<Int, Int>) = Pair(this.first + o.first, this.second + o.second)
fun main() {
val input = generateSequence(::readlnOrNull).toList().map { it.split(" ") }
val visited2: MutableSet<Pair<Int, Int>> = mutableSetOf()
val visited10: MutableSet<Pair<Int, Int>> = mutableSetO... | 0 | Kotlin | 7 | 43 | 7cd5a97d142780b8b33b93ef2bc0d9e54536c99f | 1,054 | adventofcode | Apache License 2.0 |
src/main/kotlin/day09/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day09
import java.io.File
private const val MAX_HEIGHT = 9
fun main() {
val lines = File("src/main/kotlin/day09/input.txt").readLines()
val mapSize = lines.size
val heightMap: Array<IntArray> = Array(mapSize) { i -> lines[i].map { it.digitToInt() }.toIntArray() }
var riskLevel = 0
val bas... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 2,067 | aoc-2021 | MIT License |
dsalgo/src/commonMain/kotlin/com/nalin/datastructurealgorithm/problems/DataStructure.kt | nalinchhajer1 | 534,780,196 | false | {"Kotlin": 86359, "Ruby": 1605} | package com.nalin.datastructurealgorithm.problems
fun findFibonacciSeries(n: Int): MutableList<Int> {
val result = mutableListOf<Int>()
var a = 0;
result.add(a)
if (n == 0) {
return result
}
var b = 1;
result.add(b)
if (n == 1) {
return result
}
var sum = 0;
... | 0 | Kotlin | 0 | 0 | eca60301dab981d0139788f61149d091c2c557fd | 1,555 | kotlin-ds-algo | MIT License |
src/main/kotlin/co/csadev/advent2021/Day03.kt | gtcompscientist | 577,439,489 | false | {"Kotlin": 252918} | /**
* Copyright (c) 2021 by <NAME>
* Advent of Code 2021, Day 3
* Problem Description: http://adventofcode.com/2021/day/3
*/
package co.csadev.advent2021
import co.csadev.adventOfCode.BaseDay
import co.csadev.adventOfCode.Resources.resourceAsList
import co.csadev.adventOfCode.longest
import co.csadev.adventOfCode.... | 0 | Kotlin | 0 | 1 | 43cbaac4e8b0a53e8aaae0f67dfc4395080e1383 | 2,476 | advent-of-kotlin | Apache License 2.0 |
src/main/kotlin/Day1.kt | noamfreeman | 572,834,940 | false | {"Kotlin": 30332} | private val part1ExampleInput = """
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
""".trimIndent()
private fun main() {
println("day1")
println()
println("part1")
assertEquals(part1(part1ExampleInput), 24_000)
println(part1(readInputFile("day1_input... | 0 | Kotlin | 0 | 0 | 1751869e237afa3b8466b213dd095f051ac49bef | 985 | advent_of_code_2022 | MIT License |
leetcode/src/daily/mid/Q904.kt | zhangweizhe | 387,808,774 | false | null | package daily.mid
fun main() {
// 904. 水果成篮
// https://leetcode.cn/problems/fruit-into-baskets/
println(totalFruit(intArrayOf(1,2,3,2,2)))
}
fun totalFruit(fruits: IntArray): Int {
// 其实就是找一个只包含两个元素的最长子序列
// 用一个 hashMap 存储出现的元素,以及这个元素出现的次数
// 且要保证 hashMap 中只能有2个键值对
// 用双指针 left、right 执行第一个... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,417 | kotlin-study | MIT License |
src/day2.kts | AfzalivE | 317,962,201 | false | null | println("Start")
// val input = listOf(
// "1-3 a: abcde",
// "1-3 b: cdefg",
// "2-9 c: ccccccccc"
// )
val input = readInput("day2.txt").readLines()
val validPasswords = findValid(input)
println("${validPasswords.size} valid passwords")
// println(validPasswords)
fun findValid(input: List<String>): Lis... | 0 | Kotlin | 0 | 0 | cc5998bfcaadc99e933fb80961be9a20541e105d | 1,303 | AdventOfCode2020 | Apache License 2.0 |
src/day4/Day04.kt | kacperhreniak | 572,835,614 | false | {"Kotlin": 85244} | package day4
import readInput
private fun part1(input: List<String>): Int {
var result = 0
for(line in input) {
val items = line.split(',')
val first = items[0].split("-")
val second = items[1].split("-")
if((first[0].toInt() >= second[0].toInt() && first[1].toInt() <= secon... | 0 | Kotlin | 1 | 0 | 03368ffeffa7690677c3099ec84f1c512e2f96eb | 1,135 | aoc-2022 | Apache License 2.0 |
src/day04/Day04.kt | taer | 573,051,280 | false | {"Kotlin": 26121} | package day04
import readInput
fun main() {
fun oneContainsOther(first: IntRange, second: IntRange) =
first.first <= second.first && first.last >= second.last
fun parseInput(input: List<String>) = input.map {
it.split(",")
}.map {
val first = it[0].split("-")
val second ... | 0 | Kotlin | 0 | 0 | 1bd19df8949d4a56b881af28af21a2b35d800b22 | 1,092 | aoc2022 | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2015/Day15.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2015
import se.saidaspen.aoc.util.Day
fun main() = Day15.run()
object Day15 : Day(2015, 15) {
data class Ingredient(val name: String, val cap: Int, val dur: Int, val fla: Int, val tex: Int, val cal: Int)
private val inp = input.lines().map {
val (ing, cap, dur, fla, tex,... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 2,018 | adventofkotlin | MIT License |
AoC2022/src/main/kotlin/xyz/danielstefani/Day8.kt | OpenSrcerer | 572,873,135 | false | {"Kotlin": 14185} | package xyz.danielstefani
import java.util.function.Function
lateinit var trees: List<List<Int>>
const val GRID_SIZE = 4
fun main() {
trees = object {}.javaClass
.classLoader
.getResource("Day8Input.in")!!
.readText()
.split("\n")
.map { it.map { it.digitToInt() }.toList()... | 0 | Kotlin | 0 | 3 | 84b9b62e15c70a4a17f8b2379dc29f9daa9f4be3 | 2,503 | aoc-2022 | The Unlicense |
src/main/java/io/deeplay/qlab/algorithm/placer/PlacerHelper.kt | oQaris | 475,961,305 | false | {"Jupyter Notebook": 766904, "Java": 47993, "Kotlin": 23299} | package io.deeplay.qlab.algorithm.placer
import com.github.shiguruikai.combinatoricskt.combinations
import com.github.shiguruikai.combinatoricskt.permutations
import com.github.shiguruikai.combinatoricskt.powerset
import io.deeplay.qlab.algorithm.eval.IEvaluator
import io.deeplay.qlab.parser.models.Unit
import io.deep... | 0 | Jupyter Notebook | 0 | 0 | 5dd497b74a767c740386dc67e6841673b17b96fb | 2,173 | QLab | MIT License |
src/Day03.kt | AleksanderBrzozowski | 574,061,559 | false | null | import java.lang.IllegalArgumentException
fun main() {
fun Char.priority(): Int = if (this.isUpperCase()) this.code - 38 else this.code - 96
fun String.splitIntoCompartments(): Pair<String, String> = take(length / 2) to substring(length / 2)
fun Pair<String, String>.itemInBothCompartments(): Char {
... | 0 | Kotlin | 0 | 0 | 161c36e3bccdcbee6291c8d8bacf860cd9a96bee | 1,302 | kotlin-advent-of-code-2022 | Apache License 2.0 |
src/days/Day12.kt | EnergyFusion | 572,490,067 | false | {"Kotlin": 48323} | import java.io.BufferedReader
fun main() {
val day = 12
fun getHeight(char: Char):Int {
return if (char.isUpperCase()) {
if (char == 'S') {
0
} else {
27
}
} else {
char.code - 96
}
}
fun setupMapA... | 0 | Kotlin | 0 | 0 | 06fb8085a8b1838289a4e1599e2135cb5e28c1bf | 5,965 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2020/Day20.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2020
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.Point2D
import com.chriswk.aoc.util.report
import kotlin.math.sqrt
class Day20 : AdventDay(2020, 20) {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val day = Day20()
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 6,748 | adventofcode | MIT License |
src/main/kotlin/Day4.kt | ivan-gusiev | 726,608,707 | false | {"Kotlin": 34715, "Python": 2022, "Makefile": 50} | import util.AocDay
import util.AocInput
typealias Day4InputType = List<Day4.ScratchCard>;
class Day4 : Runner {
val TEST_INPUT: String = """
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
... | 0 | Kotlin | 0 | 0 | 5585816b435b42b4e7c77ce9c8cabc544b2ada18 | 4,137 | advent-of-code-2023 | MIT License |
src/Day14.kt | 6234456 | 572,616,769 | false | {"Kotlin": 39979} | import kotlin.math.min
fun main() {
fun part1(input: List<String>): Int {
var minX = Int.MAX_VALUE
var maxX = Int.MIN_VALUE
var maxY = Int.MIN_VALUE
input.forEach {
it.split(" -> ").forEach {
val tmp = it.split(",").map { it.toInt() }
m... | 0 | Kotlin | 0 | 0 | b6d683e0900ab2136537089e2392b96905652c4e | 5,426 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinOperationsToMakeArrayContinuous.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,734 | kotlab | Apache License 2.0 |
src/main/kotlin/days/Day3.kt | hughjdavey | 725,972,063 | false | {"Kotlin": 76988} | package days
import xyz.hughjd.aocutils.Coords.Coord
class Day3 : Day(3) {
val bounds = Coord(inputList[0].length, inputList.size)
private val numbers = schematicMatches(Regex("\\d+"))
private val partNumbers = numbers.filter { number -> number.getValidAdjacents(bounds).any {
!Character.isDigit... | 0 | Kotlin | 0 | 0 | 330f13d57ef8108f5c605f54b23d04621ed2b3de | 1,703 | aoc-2023 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/staricka/adventofcode2023/days/Day17.kt | mathstar | 719,656,133 | false | {"Kotlin": 107115} | package com.staricka.adventofcode2023.days
import com.staricka.adventofcode2023.days.CrucibleQueueKey.Companion.toQueueKey
import com.staricka.adventofcode2023.framework.Day
import com.staricka.adventofcode2023.util.Direction
import com.staricka.adventofcode2023.util.Grid
import com.staricka.adventofcode2023.util.Grid... | 0 | Kotlin | 0 | 0 | 8c1e3424bb5d58f6f590bf96335e4d8d89ae9ffa | 4,253 | adventOfCode2023 | MIT License |
advent-of-code-2018/src/test/java/aoc/Advent23.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | package aoc
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import kotlin.math.absoluteValue
class Advent23 {
data class Point(val x: Int, val y: Int, val z: Int) {
operator fun minus(other: Point): Point {
return copy(x = x - other.x, y = y - other.y, z = z - other.z)... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 50,776 | advent-of-code | MIT License |
src/day02/Day02.kt | tschens95 | 573,743,557 | false | {"Kotlin": 32775} | fun main() {
val valueMap =
mapOf("A" to 1, "B" to 2, "C" to 3, "X" to 1, "Y" to 2, "Z" to 3)
fun part1(input: List<String>): Int {
var totalSum = 0
for (r in input) {
val s = r.split(" ")
val myShapeValue = valueMap[s[1]]
val enemyShapeValue = valueM... | 0 | Kotlin | 0 | 2 | 9d78a9bcd69abc9f025a6a0bde923f53c2d8b301 | 2,229 | AdventOfCode2022 | Apache License 2.0 |
21-MonkeyMath/MonkeyMath.kt | SwampThingTom | 573,012,389 | false | null | // Monkey Math
// https://adventofcode.com/2022/day/21
import java.io.File
import java.util.ArrayDeque
typealias MonkeyMap = Map<String, List<String>>
typealias MutableValuesMap = MutableMap<String, Long>
fun debugPrint(msg: String, show: Boolean = false) = if (show) { println(msg) } else {}
fun readInput(): List<S... | 0 | Makefile | 1 | 14 | a7825f70aee93980a959a63fb2d429ac587b0c86 | 3,406 | AoC2022 | MIT License |
src/main/kotlin/dp/maxProfit/SolutionKt3.kt | eleven-max | 441,597,605 | false | {"Java": 104251, "Kotlin": 41506} | package dp.maxProfit
import com.evan.dynamicprogramming.Common.CommonUtil
//https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/
class SolutionKt3 {
fun maxProfit(prices: IntArray): Int {
val dp = Array(3) { IntArray(prices.size) { 0 } }
//0, 持有股票
//1,处于冷冻期
... | 0 | Java | 0 | 0 | 2e9b234b052896c6b8be07044d2b0c6812133e66 | 1,092 | Learn_Algorithm | Apache License 2.0 |
src/Day10.kt | JIghtuse | 572,807,913 | false | {"Kotlin": 46764} | import java.io.File
sealed class Instruction {
object Noop: Instruction()
data class Addx(val value: Int): Instruction()
}
fun parseInstruction(line: String) =
when (line) {
"noop" -> Instruction.Noop
else -> Instruction.Addx(line.substringAfter(" ").toInt())
}
fun parseInstructions(... | 0 | Kotlin | 0 | 0 | 8f33c74e14f30d476267ab3b046b5788a91c642b | 2,692 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/pl/klemba/aoc/day1/Main.kt | aklemba | 726,935,468 | false | {"Kotlin": 16373} | package pl.klemba.aoc.day1
import java.io.File
fun main2() {
// ----- PART 1 -----
File(inputPath)
.readLines()
.map { extractCalibrationValue(it) }
.reduce { accumulator, calibrationValue -> accumulator + calibrationValue }
.let { println(it) }
// ----- PART 2 -----
File(inputPath)
.read... | 0 | Kotlin | 0 | 1 | 2432d300d2203ff91c41ffffe266e19a50cca944 | 1,901 | adventOfCode2023 | Apache License 2.0 |
src/main/kotlin/_2020/Day4.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2020
import aocRun
private val keyValueRegex = Regex("(\\w+):([\\w#]+)")
fun main() {
aocRun(puzzleInput) { input ->
return@aocRun process(input) { passport ->
val size = passport.size
return@process size == 8 || (size == 7 && !passport.any { it.first == PassportField.COUNTRY_ID })
}
}
aocRun(p... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 21,560 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/Day14.kt | arksap2002 | 576,679,233 | false | {"Kotlin": 31030} | import kotlin.math.max
import kotlin.math.min
fun main() {
val board = mutableListOf<MutableList<Char>>()
val n = 700
fun put(x: Int, y: Int): Boolean {
if (x == board.size - 1) return false
if (board[x + 1][y] == '.') return put(x + 1, y)
if (board[x + 1][y - 1] == '.') return put... | 0 | Kotlin | 0 | 0 | a24a20be5bda37003ef52c84deb8246cdcdb3d07 | 2,977 | advent-of-code-kotlin | Apache License 2.0 |
src/test/kotlin/be/brammeerten/y2022/Day8Test.kt | BramMeerten | 572,879,653 | false | {"Kotlin": 170522} | package be.brammeerten.y2022
import be.brammeerten.readFile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class Day8Test {
@Test
fun `part 1`() {
val forest = toMap(readFile("2022/day8/exampleInput.txt"))
Assertions.assertEquals(21, forest.getVisibleTrees().size)
... | 0 | Kotlin | 0 | 0 | 1defe58b8cbaaca17e41b87979c3107c3cb76de0 | 3,795 | Advent-of-Code | MIT License |
src/main/kotlin/aoc2019/MonitoringStation.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2019
import komu.adventofcode.utils.Point
import komu.adventofcode.utils.nonEmptyLines
import kotlin.math.atan2
private typealias Angle = Double
fun monitoringStation1(input: String): Int =
parseAsteroidMap(input).buildAngleMap().values.map { it.size }.maxOrNull()!!
fun monitoringSt... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 1,602 | advent-of-code | MIT License |
archive/k/kotlin/Rot13.kt | TheRenegadeCoder | 125,427,624 | false | {"BASIC": 97136, "Rust": 61107, "PHP": 58368, "Beef": 51651, "Mathematica": 43477, "C++": 37590, "Java": 33084, "Python": 30222, "JavaScript": 29447, "C": 29061, "Go": 22022, "C#": 18001, "Objective-C": 16797, "Haskell": 16781, "Kotlin": 13185, "Brainfuck": 12179, "Perl": 11260, "TypeScript": 10875, "MATLAB": 9411, "Ma... | data class EncodingBounds(val lowerBound: Int, val upperBound: Int)
fun encodingBoundsForCharValue(c: Char): EncodingBounds? {
val lowerCaseBounds = EncodingBounds('a'.toInt(), 'z'.toInt())
val upperCaseBounds = EncodingBounds('A'.toInt(), 'Z'.toInt())
return when (c) {
in 'a'..'z' -> lowerCaseBoun... | 83 | BASIC | 540 | 527 | bd5f385f6b3f7881c496a4c2884d1a63b8bb5448 | 1,495 | sample-programs | MIT License |
ceria/04/src/main/kotlin/Solution.kt | VisionistInc | 433,099,870 | false | {"Kotlin": 91599, "Go": 87605, "Ruby": 65600, "Python": 21104} | import java.io.File;
lateinit var drawList: List<Int>
var boards = mutableListOf<List<MutableList<Int>>>()
fun main(args : Array<String>) {
arrangeInput(File(args.first()).readLines())
println("Solution 1: ${solution1()}")
println("Solution 2: ${solution2()}")
}
private fun solution1() :Int {
for (x ... | 0 | Kotlin | 4 | 1 | e22a1d45c38417868f05e0501bacd1cad717a016 | 3,604 | advent-of-code-2021 | MIT License |
advent-of-code-2022/src/test/kotlin/Day 8 Treetop Tree House.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
class `Day 8 Treetop Tree House` {
@Test
fun silverTest() {
countTreesVisibleFromOutside(forest(testInput)) shouldBe 21
}
@Test
fun silver() {
countTreesVisibleFromOutside(forest(loadResource("day8"))) shouldBe 1684
}
private fu... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 3,308 | advent-of-code | MIT License |
gcj/y2023/farewell_d/b_small_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
private fun solve(): String {
val (a, b, qIn) = readLn().split(" ")
val leftMost = HashMap<Long, Int>(a.length * a.length)
for (i in a.indices) {
var h = 0L
for (j in i until a.length) {
h = mix(h + a[j].code)
leftMost.putIfAbsent(h, j + 1)
}
}
val ans = List(qIn.toInt()) ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,042 | competitions | The Unlicense |
src/2022/Day09.kt | nagyjani | 572,361,168 | false | {"Kotlin": 369497} | package `2022`
import java.io.File
import java.util.*
fun main() {
Day09().solve()
}
class Day09 {
val input1 = """
R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2
""".trimIndent()
val input2 = """
R 5
U 8
L 8
D 3
R 17
D 10
L 25
U 20
""".trimIndent()
data class Step(val direction: Char, val size: Int)
... | 0 | Kotlin | 0 | 0 | f0c61c787e4f0b83b69ed0cde3117aed3ae918a5 | 2,001 | advent-of-code | Apache License 2.0 |
src/main/java/com/booknara/problem/dp/LongestPalindromicSubsequenceKt.kt | booknara | 226,968,158 | false | {"Java": 1128390, "Kotlin": 177761} | package com.booknara.problem.dp
/**
* 516. Longest Palindromic Subsequence (Medium)
* https://leetcode.com/problems/longest-palindromic-subsequence/
*/
class LongestPalindromicSubsequenceKt {
// T:O(n^2), S:O(n^2)
fun longestPalindromeSubseq(s: String): Int {
// input check s.length >= 1
val n = s.lengt... | 0 | Java | 1 | 1 | 04dcf500ee9789cf10c488a25647f25359b37a53 | 863 | playground | MIT License |
src/day02/Day02.kt | pnavais | 574,712,395 | false | {"Kotlin": 54079} | package day02
import readInput
fun part1(input: List<String>): Long {
var totalSum = 0L
for (moveDesc in input) {
val points = when (moveDesc) {
"A X" -> 3 + 1 // Rock vs Rock, Draw, 1 point for Rock
"A Y" -> 6 + 2 // Rock vs Paper, Win, 2 point for Paper
"A Z" -> ... | 0 | Kotlin | 0 | 0 | ed5f521ef2124f84327d3f6c64fdfa0d35872095 | 2,025 | advent-of-code-2k2 | Apache License 2.0 |
yandex/y2021/qual/e.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package yandex.y2021.qual
fun main() {
val (hei, wid) = readInts()
val f = List(hei) { readLn().map { it - '0' } }
val countZero = f.sumOf { row -> row.count { it == 0 } }
val inf = hei * wid * 3
val a = List(wid + 1) { List(hei + 1) { IntArray(wid * hei + 1) { inf } } }
for (y in 0..hei) a[0][y][0] = 0
for (x ... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,011 | competitions | The Unlicense |
src/main/kotlin/g1401_1500/s1419_minimum_number_of_frogs_croaking/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1401_1500.s1419_minimum_number_of_frogs_croaking
// #Medium #String #Counting #2023_06_07_Time_210_ms_(90.91%)_Space_37.5_MB_(90.91%)
class Solution {
fun minNumberOfFrogs(s: String): Int {
var ans = 0
val f = IntArray(26)
for (i in 0 until s.length) {
f[s[i].code - 'a... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,693 | LeetCode-in-Kotlin | MIT License |
src/Day03.kt | llama-0 | 574,081,845 | false | {"Kotlin": 6422} | fun main() {
fun fillCase(start: Int, end: Int, char: Char): Map<Char, Int> {
val case = mutableMapOf<Char, Int>()
for (i in start..end) {
case[char + i - start] = i
}
return case
}
val lowercase = fillCase(1, 26, 'a')
val uppercase = fillCase(27, 52, 'A')
... | 0 | Kotlin | 0 | 0 | a3a9a07be54a764a707ab25332a9f324cb84ac2a | 1,669 | AoC-2022 | Apache License 2.0 |
src/Day01.kt | JonasDBB | 573,382,821 | false | {"Kotlin": 17550} | private fun splitListOnEmpty(lst: List<Int?>): List<List<Int>> {
val ret: MutableList<List<Int>> = mutableListOf()
val sublist: MutableList<Int> = mutableListOf()
for (i in lst.indices) {
if (lst[i] == null) {
if (sublist.isNotEmpty()) ret.add(sublist.toList())
sublist.clear(... | 0 | Kotlin | 0 | 0 | 199303ae86f294bdcb2f50b73e0f33dca3a3ac0a | 923 | AoC2022 | Apache License 2.0 |
Kotlin/7 kyu Complementary DNA.kt | MechaArms | 508,384,440 | false | {"Kotlin": 22917, "Python": 18312} | /*
Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.
If you want to know more: http://en.wikipedia.org/wiki/DNA
In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". Your function... | 0 | Kotlin | 0 | 1 | b23611677c5e2fe0f7e813ad2cfa21026b8ac6d3 | 1,231 | My-CodeWars-Solutions | MIT License |
src/main/kotlin/year2022/Day07.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2022
class Day07 {
class Directory(val parent: Directory?) {
var totalSize: Int = 0
val childDirs: MutableMap<String, Directory> = mutableMapOf()
fun find(predicate: (Directory) -> Boolean): List<Directory> = buildList {
if (predicate(this@Directory)) {
... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 1,734 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/g1801_1900/s1870_minimum_speed_to_arrive_on_time/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1801_1900.s1870_minimum_speed_to_arrive_on_time
// #Medium #Array #Binary_Search #Binary_Search_II_Day_6
// #2023_06_22_Time_628_ms_(50.00%)_Space_51.5_MB_(100.00%)
class Solution {
fun minSpeedOnTime(dist: IntArray, hour: Double): Int {
val n = dist.size
return fmin(dist, n, hour)
}
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,373 | LeetCode-in-Kotlin | MIT License |
src/main/java/challenges/leetcode/LongestCommonPrefix.kt | ShabanKamell | 342,007,920 | false | null | package challenges.leetcode
import java.util.*
/**
Write a function to find the longest common prefix string amongst an array of strings.
If there is no common prefix, return an empty string "".
Example 1:
Input: strs = ["flower","flow","flight"]
Output: "fl"
Example 2:
Input: strs = ["dog","racecar","car"]
Output... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 2,282 | CodingChallenges | Apache License 2.0 |
2019/kotlin/day3/day3.kt | Deph0 | 225,142,801 | false | null | package aoc.day.three
import java.io.File
import kotlin.random.Random
import java.awt.*
import java.awt.geom.*
import javax.swing.*
data class WirePosition(
var x: Int = 0,
var y: Int = 0,
var walked: Int = 0 )
data class WireData(
val direction: String,
val steps: Int )
data class Wire(
var a... | 0 | Kotlin | 0 | 0 | 42a4fce4526182737d9661fae66c011f0948e481 | 5,342 | adventofcode | MIT License |
archive/2022/Day16_dijkstra.kt | mathijs81 | 572,837,783 | false | {"Kotlin": 167658, "Python": 725, "Shell": 57} | import java.util.*
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
private const val EXPECTED_1 = 1651
private const val EXPECTED_2 = 1707
/**
* Reworked solution: use Dijkstra's to find the highest value path through the state space
* for part1.
*
* Actually a bit slower than the dp solution.
... | 0 | Kotlin | 0 | 2 | 92f2e803b83c3d9303d853b6c68291ac1568a2ba | 4,221 | advent-of-code-2022 | Apache License 2.0 |
src/Day16.kt | greg-burgoon | 573,074,283 | false | {"Kotlin": 120556} | fun main() {
class Node(name: String, flowRate: Int, adjacentValves: MutableList<Node> = mutableListOf<Node>()) {
val name = name
val flowRate = flowRate
var adjacentValves = adjacentValves
}
data class State(val currentNode: String, val openValves: List<String>, var accumulatedPres... | 0 | Kotlin | 0 | 1 | 74f10b93d3bad72fa0fc276b503bfa9f01ac0e35 | 11,422 | aoc-kotlin | Apache License 2.0 |
src/day04/Day04.kt | EdwinChang24 | 572,839,052 | false | {"Kotlin": 20838} | package day04
import readInput
fun main() {
part1()
part2()
}
fun part1() {
val input = readInput(4)
var total = 0
for (line in input) {
val ranges = line.split(',')
val r1 = ranges[0].split('-')[0].toInt() to ranges[0].split('-')[1].toInt()
val r2 = ranges[1].split('-')[0... | 0 | Kotlin | 0 | 0 | e9e187dff7f5aa342eb207dc2473610dd001add3 | 1,087 | advent-of-code-2022 | Apache License 2.0 |
src/main/Kotlin/fca/Concept.kt | Jianwei-Wu-1 | 467,248,073 | false | {"Kotlin": 133590, "Java": 595} | package edu.udel.fca
data class Concept<O, A>(
val objects: Set<O>,
val attributes: Set<A>,
private val context: Context<O, A>
) : Comparable<Concept<O, A>> {
val successors: Set<Concept<O, A>> by lazy {
context.successors(this).toSet()
}
val predecessors: Set<Concept<O, A>> by lazy {
... | 0 | Kotlin | 0 | 0 | fc9d1658fcbd03f33a66ee279efe2f057c69b6dc | 1,598 | NameGenerationPlugin | The Unlicense |
src/main/kotlin/g1301_1400/s1312_minimum_insertion_steps_to_make_a_string_palindrome/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1301_1400.s1312_minimum_insertion_steps_to_make_a_string_palindrome
// #Hard #String #Dynamic_Programming #2023_06_05_Time_186_ms_(67.70%)_Space_37.6_MB_(26.09%)
class Solution {
private fun longestPalindrome(a: String, b: String, n: Int): Int {
val dp = Array(n + 1) { IntArray(n + 1) }
f... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 972 | LeetCode-in-Kotlin | MIT License |
jvm/src/main/kotlin/io/prfxn/aoc2021/day24.kt | prfxn | 435,386,161 | false | {"Kotlin": 72820, "Python": 362} | // Arithmetic Logic Unit (https://adventofcode.com/2021/day/24)
package io.prfxn.aoc2021
import kotlin.math.absoluteValue
import kotlin.math.log
fun main() {
fun parseInstruction(str: String) =
str.split(" ").let {
if (it.size == 3) Triple(it[0], it[1], it[2])
else Triple(it[0], ... | 0 | Kotlin | 0 | 0 | 148938cab8656d3fbfdfe6c68256fa5ba3b47b90 | 7,251 | aoc2021 | MIT License |
src/day5/Day05.kt | armanaaquib | 572,849,507 | false | {"Kotlin": 34114} | package day5
import readInput
fun main() {
fun parseInput(input: List<String>) =
input.map {
val line = it.split(" ")
listOf(
line[1].toInt(),
line[3].toInt(),
line[5].toInt()
)
}
val testStacks = listOf(
... | 0 | Kotlin | 0 | 0 | 47c41ceddacb17e28bdbb9449bfde5881fa851b7 | 2,468 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/tr/emreone/adventofcode/days/Day02.kt | EmRe-One | 726,902,443 | false | {"Kotlin": 95869, "Python": 18319} | package tr.emreone.adventofcode.days
import tr.emreone.kotlin_utils.automation.Day
class Day02 : Day(2, 2023, "Cube Conundrum") {
class Bag(
val red: Int = 0,
val green: Int = 0,
val blue: Int = 0
) {
val MAX_RED = 13
val MAX_GREEN = 14
val MAX_BLUE = 15
... | 0 | Kotlin | 0 | 0 | c75d17635baffea50b6401dc653cc24f5c594a2b | 1,901 | advent-of-code-2023 | Apache License 2.0 |
src/Day04.kt | AxelUser | 572,845,434 | false | {"Kotlin": 29744} | fun main() {
fun List<String>.parse(): Sequence<Pair<IntRange, IntRange>> {
val regex = Regex("\\d+")
return sequence {
for (s in this@parse) {
yield(regex.findAll(s).map { it.value.toInt() }.toList().let { (it[0]..it[1]) to (it[2]..it[3]) })
}
}
... | 0 | Kotlin | 0 | 1 | 042e559f80b33694afba08b8de320a7072e18c4e | 972 | aoc-2022 | Apache License 2.0 |
2023/src/main/kotlin/de/skyrising/aoc2023/day8/solution.kt | skyrising | 317,830,992 | false | {"Kotlin": 411565} | package de.skyrising.aoc2023.day8
import de.skyrising.aoc.*
import it.unimi.dsi.fastutil.ints.Int2LongMap
import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap
private inline fun steps(start: Int, lr: BooleanArray, map: Int2LongMap, end: (Int)->Boolean) =
start.stepsUntil(end) { PackedIntPair(map[this])[lr[it % l... | 0 | Kotlin | 0 | 0 | 19599c1204f6994226d31bce27d8f01440322f39 | 1,621 | aoc | MIT License |
src/day07/Day07.kt | hamerlinski | 572,951,914 | false | {"Kotlin": 25910} | package day07
import readInput
import java.math.BigDecimal
fun main() {
fun part1and2() {
val input = readInput("Day07", "day07")
val maxSize = BigDecimal(70000000)
val updateSizeRequirement = BigDecimal(30000000)
val fileSystem = FileSystem(input)
fileSystem.load()
... | 0 | Kotlin | 0 | 0 | bbe47c5ae0577f72f8c220b49d4958ae625241b0 | 5,094 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/TwoEditWords.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,636 | kotlab | Apache License 2.0 |
src/main/kotlin/solutions/Day12HillClimbingAlgorithm.kt | aormsby | 571,002,889 | false | {"Kotlin": 80084} | package solutions
import models.Coord2d
import utils.Input
import utils.Solution
// run only this day
fun main() {
Day12HillClimbingAlgorithm()
}
class Day12HillClimbingAlgorithm : Solution() {
init {
begin("Day 12 - Hill Climbing Algorithm")
var start = Coord2d(0, 0)
var end = Coor... | 0 | Kotlin | 0 | 0 | 1bef4812a65396c5768f12c442d73160c9cfa189 | 3,117 | advent-of-code-2022 | MIT License |
src/Day08.kt | vlsolodilov | 573,277,339 | false | {"Kotlin": 19518} | fun main() {
fun fillMatrix(input: List<String>): List<List<Int>> =
input.map { line ->
line.map { it.digitToInt() }
}
fun checkLeft(y: Int, x: Int, matrix: List<List<Int>>): Boolean {
val currentTree = matrix[y][x]
matrix[y].forEachIndexed { index, tree ->
... | 0 | Kotlin | 0 | 0 | b75427b90b64b21fcb72c16452c3683486b48d76 | 4,111 | aoc22 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.