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/ru/timakden/aoc/year2016/Day01.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2016
import ru.timakden.aoc.util.Point
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
import ru.timakden.aoc.year2016.Day01.Direction.*
import kotlin.math.abs
/**
* [Day 1: No Time for a Taxicab](https://adventofcode.com/2016/day/1).
*/
object Day01 {
@JvmS... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 2,453 | advent-of-code | MIT License |
app/src/main/kotlin/co/netguru/android/carrecognition/common/MultimapExt.kt | netguru | 135,276,208 | false | null | typealias Multimap<K, V> = Map<K, List<V>>
fun <K, V> Multimap<K, V>.partition(
predicate: (V) -> Boolean
): Pair<Multimap<K, V>, Multimap<K, V>> {
val first = mutableMapOf<K, List<V>>()
val second = mutableMapOf<K, List<V>>()
for (k in this.keys) {
val (firstValuePartition, secondValuePartitio... | 0 | Kotlin | 8 | 24 | 321fa52c5cc0a339b27737b626163f8f72348cd9 | 1,898 | CarLens-Android | Apache License 2.0 |
src/main/kotlin/_2022/Day22.kt | novikmisha | 572,840,526 | false | {"Kotlin": 145780} | package _2022
import readGroupedInput
import kotlin.math.absoluteValue
fun main() {
val directions = listOf(
Pair(0, 1), //right
Pair(1, 0), // bottom
Pair(0, -1), // left
Pair(-1, 0), // top
)
fun getNextDirection(currentDirection: Pair<Int, Int>, rotate: Char): Pair<Int,... | 0 | Kotlin | 0 | 0 | 0c78596d46f3a8bf977bf356019ea9940ee04c88 | 9,522 | advent-of-code | Apache License 2.0 |
src/main/kotlin/day9.kt | gautemo | 572,204,209 | false | {"Kotlin": 78294} | import shared.getText
import kotlin.math.abs
fun main(){
val input = getText("day9.txt")
println(day9A(input))
println(day9B(input))
}
fun day9A(input: String): Int {
val motions = input.lines()
val head = Knot(0, 0)
val tail = Knot(0, 0)
val tailBeen = mutableSetOf(tail.copy())
motion... | 0 | Kotlin | 0 | 0 | bce9feec3923a1bac1843a6e34598c7b81679726 | 1,671 | AdventOfCode2022 | MIT License |
src/main/kotlin/adventofcode/PuzzleDay07.kt | MariusSchmidt | 435,574,170 | false | {"Kotlin": 28290} | package adventofcode
import java.io.File
import kotlin.math.*
/**
*
* PART I
* Interestingly enough, for any series of numbers in R^1 the central point that minimizes the sum of distances to each
* other point is the median. In fact "The median minimizes the sum of absolute deviations". Until AoC 2021 I did not
... | 0 | Kotlin | 0 | 0 | 2b7099350fa612cb69c2a70d9e57a94747447790 | 2,696 | adventofcode2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/aoc22/Day10.kt | asmundh | 573,096,020 | false | {"Kotlin": 56155} | package aoc22
import readInput
fun Map<Int, Int>.getSignalStrengthAtCycles(cycles: List<Int>): Int {
var sum = 0
for (cycle in cycles) {
sum += this[cycle]!! * cycle
}
return sum
}
data class Sprite(
var position: Int = 1
) {
fun move(steps: Int) = run {
position += steps
... | 0 | Kotlin | 0 | 0 | 7d0803d9b1d6b92212ee4cecb7b824514f597d09 | 1,835 | advent-of-code | Apache License 2.0 |
aoc-2023/src/main/kotlin/aoc/aoc12.kts | triathematician | 576,590,518 | false | {"Kotlin": 615974} | import aoc.AocParser.Companion.parselines
import aoc.AocRunner
import aoc.chunk
import aoc.print
import aoc.util.getDayInput
val testInput = """
???.### 1,1,3
.??..??...?##. 1,1,3
?#?#?#?#?#?#?#? 1,3,1,6
????.#...#... 4,1,1
????.######..#####. 1,6,5
?###???????? 3,2,1
""".parselines
class Springs(_line: String, val n... | 0 | Kotlin | 0 | 0 | 7b1b1542c4bdcd4329289c06763ce50db7a75a2d | 4,969 | advent-of-code | Apache License 2.0 |
src/main/kotlin/kt/kotlinalgs/app/graph/MinSpanningTreePrim.ws.kts | sjaindl | 384,471,324 | false | null | package com.sjaindl.kotlinalgsandroid.graph
/*
MinSpanningTreePrim - MST weighted undirected graph
O(V^2) runtime (adj. matrix)
*/
//https://www.geeksforgeeks.org/prims-minimum-spanning-tree-mst-greedy-algo-5/
class MinSpanningTreePrim {
fun minSpanningTree(graph: Array<IntArray>): IntArray {
val... | 0 | Java | 0 | 0 | e7ae2fcd1ce8dffabecfedb893cb04ccd9bf8ba0 | 2,016 | KotlinAlgs | MIT License |
fibonacci/src/main/kotlin/com/nickperov/stud/algorithms/fibonacci/FibonacciLargeGenerator.kt | nickperov | 327,780,009 | false | null | package com.nickperov.stud.algorithms.fibonacci
import java.math.BigInteger
fun main() {
println("Hello, large Fibonacci numbers")
println(FibonacciLargeTailRecursiveOptimisedGenerator().calculate(1000000))
/*for (number in 93..150) {
println("====================>$number<==================")
... | 0 | Kotlin | 0 | 0 | 6696f5d8bd73ce3a8dfd4200f902e2efe726cc5a | 3,795 | Algorithms | MIT License |
src/Day13.kt | adrianforsius | 573,044,406 | false | {"Kotlin": 68131} | import org.assertj.core.api.Assertions.assertThat
fun order(a: List<Any>, b: List<Any>): Int {
for ((index, _) in a.withIndex()) {
val r = b.getOrNull(index) ?: return -1
val l = a.get(index)
if (l is Int && r is Int) {
if (l == r) continue
return if (l < r) 1 else ... | 0 | Kotlin | 0 | 0 | f65a0e4371cf77c2558d37bf2ac42e44eeb4bdbb | 5,299 | kotlin-2022 | Apache License 2.0 |
year2016/src/main/kotlin/net/olegg/aoc/year2016/day8/Day8.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2016.day8
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.year2016.DayOf2016
/**
* See [Year 2016, Day 8](https://adventofcode.com/2016/day/8)
*/
object Day8 : DayOf2016(8) {
private val PATTERN = "(\\D*)(\\d+)\\D*(\\d+)\\D*".toRegex()
override fun first(): Any? {
return... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 1,687 | adventofcode | MIT License |
src/Day19.kt | risboo6909 | 572,912,116 | false | {"Kotlin": 66075} | enum class ResType {
GEODE,
OBSIDIAN,
CLAY,
ORE,
}
typealias NumItem = Map<ResType, Int>
typealias Blueprint = Map<ResType, NumItem>
fun main() {
fun matchRes(res: String): ResType? {
return when (res) {
"ore" -> ResType.ORE
"clay" -> ResType.CLAY
"obsi... | 0 | Kotlin | 0 | 0 | bd6f9b46d109a34978e92ab56287e94cc3e1c945 | 6,046 | aoc2022 | Apache License 2.0 |
leetcode/src/sort/Q414.kt | zhangweizhe | 387,808,774 | false | null | package sort
fun main() {
// 414. 第三大的数
// https://leetcode-cn.com/problems/third-maximum-number/
val intArrayOf = intArrayOf(1,1,1)
println(thirdMax(intArrayOf))
}
fun thirdMax(nums: IntArray): Int {
var a = Long.MIN_VALUE
var b = Long.MIN_VALUE
var c = Long.MIN_VALUE
for (i in num... | 0 | Kotlin | 0 | 0 | 1d213b6162dd8b065d6ca06ac961c7873c65bcdc | 1,813 | kotlin-study | MIT License |
src/Day11.kt | cornz | 572,867,092 | false | {"Kotlin": 35639} | import java.math.BigInteger
data class Monkey(
var id: Int, var items: MutableList<Int>, var operation: Pair<String, String>, var divisor: Int,
var throwTo: Pair<Int, Int>, var numberOfInspections: Int
)
data class LongMonkey(
var id: Int, var items: MutableList<BigInteger>, var operation: Pair<String, St... | 0 | Kotlin | 0 | 0 | 2800416ddccabc45ba8940fbff998ec777168551 | 6,132 | aoc2022 | Apache License 2.0 |
kotlin/numbertheory/Euclid.kt | polydisc | 281,633,906 | true | {"Java": 540473, "Kotlin": 515759, "C++": 265630, "CMake": 571} | package numbertheory
import java.math.BigInteger
object Euclid {
fun gcd(a: Int, b: Int): Int {
return if (b == 0) Math.abs(a) else gcd(b, a % b)
}
fun gcd2(a: Int, b: Int): Int {
var a = a
var b = b
while (b != 0) {
val t = b
b = a % b
... | 1 | Java | 0 | 0 | 4566f3145be72827d72cb93abca8bfd93f1c58df | 4,764 | codelibrary | The Unlicense |
src/day21/Expressions.kt | g0dzill3r | 576,012,003 | false | {"Kotlin": 172121} | package day21
// NOT 9879574614298
fun Jobs.simplify (e: Expression.Calculation): Pair<Expression.Calculation, Boolean> {
// We only solve expressions expressed as equalities
if (e.operation != Operation.EQUALS) {
throw IllegalArgumentException ("Can only solve equality expressions.")
}
// ... | 0 | Kotlin | 0 | 0 | 6ec11a5120e4eb180ab6aff3463a2563400cc0c3 | 3,176 | advent_of_code_2022 | Apache License 2.0 |
src/main/kotlin/me/peckb/aoc/_2021/calendar/day20/Day20.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2021.calendar.day20
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import javax.inject.Inject
class Day20 @Inject constructor(private val generatorFactory: InputGeneratorFactory) {
companion object {
const val OUTPUT_LIT = '#'
const val OUTPUT_DIM = ' '
const ... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 3,312 | advent-of-code | MIT License |
src/leetcodeProblem/leetcode/editor/en/SumOfBeautyInTheArray.kt | faniabdullah | 382,893,751 | false | null | //You are given a 0-indexed integer array nums. For each index i (1 <= i <=
//nums.length - 2) the beauty of nums[i] equals:
//
//
// 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <=
//nums.length - 1.
// 1, if nums[i - 1] < nums[i] < nums[i + 1], and the previous condition is not
//satis... | 0 | Kotlin | 0 | 6 | ecf14fe132824e944818fda1123f1c7796c30532 | 1,774 | dsa-kotlin | MIT License |
src/Day03RucksackReorganization.kt | zizoh | 573,932,084 | false | {"Kotlin": 13370} | fun main() {
val priorities = mapOf(
'a' to 1,
'b' to 2,
'c' to 3,
'd' to 4,
'e' to 5,
'f' to 6,
'g' to 7,
'h' to 8,
'i' to 9,
'j' to 10,
'k' to 11,
'l' to 12,
'm' to 13,
'n' to 14,
'o' to 15,
... | 0 | Kotlin | 0 | 0 | 817017369d257cca648974234f1e4137cdcd3138 | 3,087 | aoc-2022 | Apache License 2.0 |
src/Day02.kt | georgiizorabov | 573,050,504 | false | {"Kotlin": 10501} | import java.util.concurrent.ConcurrentHashMap
val RPCUnitsToInt = hashMapOf(
'A' to 1,
'B' to 2,
'C' to 3,
'X' to 1,
'Y' to 2,
'Z' to 3
)
val IntToRPCUnits = hashMapOf(
0 to 'Z',
1 to 'X',
2 to 'Y',
3 to 'Z'
)
fun compare1(unit1: Char, unit2: Char): Int {
val realUnit2: Cha... | 0 | Kotlin | 0 | 0 | bf84e55fe052c9c5f3121c245a7ae7c18a70c699 | 1,393 | aoc2022 | Apache License 2.0 |
src/commonMain/kotlin/com/jeffpdavidson/kotwords/model/DownsOnly.kt | jpd236 | 143,651,464 | false | {"Kotlin": 4390419, "HTML": 41919, "Rouge": 3731, "Perl": 1705, "Shell": 744, "JavaScript": 618} | package com.jeffpdavidson.kotwords.model
/** Extension functions to make crosswords downs-only. */
object DownsOnly {
/**
* Return a copy of this puzzle with only the down clues (usually).
*
* Solving with down clues generally works because all the theme answers, which are typically
* the longe... | 5 | Kotlin | 5 | 19 | c2dc23bafc7236ba076a63060e08e6dc134c8e24 | 3,879 | kotwords | Apache License 2.0 |
src/Day18.kt | LauwiMeara | 572,498,129 | false | {"Kotlin": 109923} | const val OFFSET_DAY_18 = 1
data class Cube(val x: Int, val y: Int, val z: Int)
fun getNeighbours(cube: Cube): List<Cube> {
return listOf(
Cube(cube.x - 1, cube.y, cube.z),
Cube(cube.x + 1, cube.y, cube.z),
Cube(cube.x, cube.y - 1, cube.z),
Cube(cube.x, cube.y + 1, cube.z),
... | 0 | Kotlin | 0 | 1 | 34b4d4fa7e562551cb892c272fe7ad406a28fb69 | 4,123 | AoC2022 | Apache License 2.0 |
src/main/kotlin/Day4.kt | amitdev | 574,336,754 | false | {"Kotlin": 21489} | import java.io.File
fun main() {
val result = File("inputs/day_4.txt").useLines { computeOverlaps(it) }
println(result)
}
fun computeFullOverlaps(lines: Sequence<String>) =
lines.map { toPairs(it) }
.count { it.first.contains(it.second) || it.second.contains(it.first)}
fun computeOverlaps(lines: Sequence<S... | 0 | Kotlin | 0 | 0 | b2cb4ecac94fdbf8f71547465b2d6543710adbb9 | 891 | advent_2022 | MIT License |
src/main/kotlin/days/Day04.kt | Kebaan | 573,069,009 | false | null | package days
import utils.Day
import utils.asIntRange
fun main() {
Day04.solve()
}
object Day04 : Day<Int>(2022, 4) {
private fun parseGroups(input: List<String>): List<Pair<IntRange, IntRange>> {
return input.map { group ->
group.substringBefore(",").asIntRange() to group.substringAfter(... | 0 | Kotlin | 0 | 0 | ef8bba36fedbcc93698f3335fbb5a69074b40da2 | 1,294 | Advent-of-Code-2022 | Apache License 2.0 |
kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/combinations.kt | ca-r0-l | 258,232,982 | true | {"Kotlin": 2272378, "HTML": 423, "Java": 153} | package io.kotest.property.arbitrary
import io.kotest.property.Arb
import io.kotest.property.Gen
import io.kotest.property.Sample
/**
* Returns a stream of values based on weights:
*
* Arb.choose(1 to 'A', 2 to 'B') will generate 'A' 33% of the time
* and 'B' 66% of the time.
*
* @throws IllegalArgumentExceptio... | 0 | null | 0 | 1 | e176cc3e14364d74ee593533b50eb9b08df1f5d1 | 2,336 | kotest | Apache License 2.0 |
src/day04/Day04.kt | Raibaz | 571,997,684 | false | {"Kotlin": 9423} | package day04
import readInput
fun main() {
fun String.parseLine() : Pair<IntRange, IntRange> {
val pairs = this.split(",")
val first = pairs[0].split("-")
val second = pairs[1].split("-")
return first[0].toInt() ..first[1].toInt() to second[0].toInt() .. second[1].toInt()
}
... | 0 | Kotlin | 0 | 0 | 99d912f661bd3545ca9ff222ac7d93c12682f42d | 1,267 | aoc-22 | Apache License 2.0 |
src/twentytwentytwo/day4/Day04.kt | colinmarsch | 571,723,956 | false | {"Kotlin": 65403, "Python": 6148} | package twentytwentytwo.day4
import readInput
fun main() {
fun part1(input: List<String>): Int = input.count { pair ->
val ranges = pair.split(",")
val first = ranges[0].split("-").map { it.toInt() }
val second = ranges[1].split("-").map { it.toInt() }
((first[0] <= second[0] && se... | 0 | Kotlin | 0 | 0 | bcd7a08494e6db8140478b5f0a5f26ac1585ad76 | 865 | advent-of-code | Apache License 2.0 |
src/questions/MajorityElement.kt | realpacific | 234,499,820 | false | null | package questions
import kotlin.test.assertEquals
/**
* Given an array nums of size n, return the majority element.
* The majority element is the element that appears more than ⌊n / 2⌋ times.
* You may assume that the majority element always exists in the array.
*
* [Source](https://leetcode.com/problems/majorit... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 1,662 | algorithms | MIT License |
src/main/kotlin/com/github/michaelbull/advent2021/day23/Burrow.kt | michaelbull | 433,565,311 | false | {"Kotlin": 162839} | package com.github.michaelbull.advent2021.day23
import java.util.PriorityQueue
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
fun Sequence<String>.toBurrow(): Burrow {
val lines = toList().dropWhile(String::isEmpty)
val hallway = lines[1].filter { it == Cell.OPEN_SPACE }.toCharArray()
... | 0 | Kotlin | 0 | 4 | 7cec2ac03705da007f227306ceb0e87f302e2e54 | 7,502 | advent-2021 | ISC License |
hoon/HoonAlgorithm/src/main/kotlin/programmers/lv01/Lv1_70128.kt | boris920308 | 618,428,844 | false | {"Kotlin": 137657, "Swift": 35553, "Java": 1947, "Rich Text Format": 407} | package main.kotlin.programmers.lv01
/**
*
* https://school.programmers.co.kr/learn/courses/30/lessons/70128
*
* 문제 설명
* 길이가 같은 두 1차원 정수 배열 a, b가 매개변수로 주어집니다.
* a와 b의 내적을 return 하도록 solution 함수를 완성해주세요.
*
* 이때, a와 b의 내적은 a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1] 입니다. (n은 a, b의 길이)
*
* 제한사항
* a, b의 길이는 1 이... | 1 | Kotlin | 1 | 2 | 88814681f7ded76e8aa0fa7b85fe472769e760b4 | 1,092 | HoOne | Apache License 2.0 |
src/day16/Day16.kt | daniilsjb | 726,047,752 | false | {"Kotlin": 66638, "Python": 1161} | package day16
import java.io.File
fun main() {
val data = parse("src/day16/Day16.txt")
println("🎄 Day 16 🎄")
println()
println("[Part 1]")
println("Answer: ${part1(data)}")
println()
println("[Part 2]")
println("Answer: ${part2(data)}")
}
private fun parse(path: String): List<L... | 0 | Kotlin | 0 | 0 | 46a837603e739b8646a1f2e7966543e552eb0e20 | 3,304 | advent-of-code-2023 | MIT License |
src/main/kotlin/dev/tasso/adventofcode/_2021/day06/Day06.kt | AndrewTasso | 433,656,563 | false | {"Kotlin": 75030} | package dev.tasso.adventofcode._2021.day06
import dev.tasso.adventofcode.Solution
import java.math.BigInteger
class Day06 : Solution<BigInteger> {
override fun part1(input: List<String>): BigInteger {
return(simulatePopulation(input, 80))
}
override fun part2(input: List<String>): BigInteger {... | 0 | Kotlin | 0 | 0 | daee918ba3df94dc2a3d6dd55a69366363b4d46c | 1,199 | advent-of-code | MIT License |
src/Day09.kt | PascalHonegger | 573,052,507 | false | {"Kotlin": 66208} | import kotlin.math.abs
private enum class HeadDirection(val x: Int, val y: Int) {
Up(0, 1),
UpRight(1, 1),
Right(1, 0),
DownRight(1, -1),
Down(0, -1),
DownLeft(-1, -1),
Left(-1, 0),
UpLeft(-1, 1),
}
private data class RopePosition(val x: Int, val y: Int)
private operator fun RopePosit... | 0 | Kotlin | 0 | 0 | 2215ea22a87912012cf2b3e2da600a65b2ad55fc | 3,708 | advent-of-code-2022 | Apache License 2.0 |
src/Day08.kt | matheusfinatti | 572,935,471 | false | {"Kotlin": 12612} | fun main() {
val input = readInput("Day08").replace("\r", "").split("\n")
input
.map(String::toList)
.map { row -> row.map(Char::digitToInt).toTypedArray() }.toTypedArray()
.also { matrix ->
matrix.map2dIndexed { i, j, _ ->
if (i == 0 || j == 0 || i == matrix.... | 0 | Kotlin | 0 | 0 | a914994a19261d1d81c80e0ef8e196422e3cd508 | 1,865 | adventofcode2022 | Apache License 2.0 |
src/day5/fr/Day05_2.kt | BrunoKrantzy | 433,844,189 | false | {"Kotlin": 63580} | package day5.fr
fun main() {
val testInput = day2.fr.readInputInt("input5")
// val testInput = day2.fr.readInputInt("test5")
val regex = "^(\\d+),(\\d+)\\s->\\s(\\d+),(\\d+)".toRegex()
var x1 = 0
var x2 = 0
var y1 = 0
var y2 = 0
var maxX = 0
var maxY = 0
var lstH = mutableLi... | 0 | Kotlin | 0 | 0 | 0d460afc81fddb9875e6634ee08165e63c76cf3a | 2,314 | Advent-of-Code-2021 | Apache License 2.0 |
src/main/kotlin/Problem18.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | /**
* By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from
* top to bottom is 23.
*
* 3
* 7 4
* 2 4 6
* 8 5 9 3
*
* That is, 3 + 7 + 4 + 9 = 23.
*
* Find the maximum total from top to bottom of the triangle below:
*
* ... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 2,666 | project-euler | MIT License |
src/main/Day05.kt | lifeofchrome | 574,709,665 | false | {"Kotlin": 19233} | package main
import readInput
fun main() {
val input = readInput("Day05")
val day5 = Day05(input)
print("Part 1: ${day5.part1()}\n")
print("Part 2: ${day5.part2()}")
}
class Day05(input: List<String>) {
private val numStacks = input[input.indexOf("") - 1].split(" ").last().toInt()
private val s... | 0 | Kotlin | 0 | 0 | 6c50ea2ed47ec6e4ff8f6f65690b261a37c00f1e | 2,608 | aoc2022 | Apache License 2.0 |
src/main/kotlin/aoc22/Day18.kt | tom-power | 573,330,992 | false | {"Kotlin": 254717, "Shell": 1026} | package aoc22
import aoc22.Day18Domain.CubeRange
import aoc22.Day18Runner.countExposedSides
import aoc22.Day18Runner.countExposedSidesOutside
import aoc22.Day18Solution.part1Day18
import aoc22.Day18Solution.part2Day18
import common.Space3D.Parser.toPoint3D
import common.Space3D.Point3D
import common.Year22
object Day... | 0 | Kotlin | 0 | 0 | baccc7ff572540fc7d5551eaa59d6a1466a08f56 | 2,212 | aoc | Apache License 2.0 |
dsalgo/src/commonMain/kotlin/com/nalin/datastructurealgorithm/problems/FB_problems.kt | nalinchhajer1 | 534,780,196 | false | {"Kotlin": 86359, "Ruby": 1605} | package com.nalin.datastructurealgorithm.problems
import com.nalin.datastructurealgorithm.ds.LinkedListNode
/**
* Find minimum value from sorted array. Note that array is shifted by some amount.
*/
fun findMinimum_shiftedSortedArray(array: Array<Int>): Int {
println(array.joinToString());
var start = 0
... | 0 | Kotlin | 0 | 0 | eca60301dab981d0139788f61149d091c2c557fd | 7,866 | kotlin-ds-algo | MIT License |
src/main/kotlin/nl/kelpin/fleur/advent2018/Day07.kt | fdlk | 159,925,533 | false | null | package nl.kelpin.fleur.advent2018
import java.util.*
class Day07(val input: List<String>, val baseTimeToCompletion: Int = 60, val workers: Int = 5) {
companion object {
private val dependencyRE = Regex("""Step (\w) must be finished before step (\w) can begin\.""")
}
private fun parse(): Map<Char... | 0 | Kotlin | 0 | 3 | a089dbae93ee520bf7a8861c9f90731eabd6eba3 | 2,590 | advent-2018 | MIT License |
src/day04/Day04.kt | skokovic | 573,361,100 | false | {"Kotlin": 12166} | package day04
import readInput
fun main() {
fun part1(input: List<String>): Int {
var sum = 0
val pairRegex = """(\d+)-(\d+),(\d+)-(\d+)""".toRegex()
input.forEach {
val (sx, ex, sy, ey) = pairRegex.matchEntire(it)!!.destructured
val (startX, endX) = sx.toInt() to... | 0 | Kotlin | 0 | 0 | fa9aee3b5dd09b06bfd5c232272682ede9263970 | 1,257 | advent-of-code-2022 | Apache License 2.0 |
src/cn/leetcode/codes/simple144/Simple144.kt | shishoufengwise1234 | 258,793,407 | false | {"Java": 771296, "Kotlin": 68641} | package cn.leetcode.codes.simple144
import cn.leetcode.codes.common.TreeNode
import cn.leetcode.codes.createTreeNode
import cn.leetcode.codes.out
import cn.leetcode.codes.outTreeNote
import java.util.*
import kotlin.collections.ArrayList
fun main() {
val nums = arrayOf<Int?>(1, 4, 3, 2)
val treeNode = create... | 0 | Java | 0 | 0 | f917a262bcfae8cd973be83c427944deb5352575 | 2,083 | LeetCodeSimple | Apache License 2.0 |
src/main/kotlin/0017.kts | ktgw0316 | 373,665,309 | false | null | // http://www.odz.sakura.ne.jp/projecteuler/?Problem+17
// ISBN978-4-04-893053-6 の 1.4 節を参照
val units = listOf("zero", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine")
val teens = listOf("ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eight... | 0 | Kotlin | 0 | 0 | 1dc3b1bbb647a0541393eedf12be798e5b0ef84a | 1,872 | EulerKotlin | Creative Commons Zero v1.0 Universal |
src/Day01.kt | mpylypovych | 572,998,434 | false | {"Kotlin": 6455} | fun main() {
fun split(input: List<String>) = input
.flatMapIndexed { index, x ->
when {
index == 0 || index == input.lastIndex -> listOf(index)
x.isEmpty() -> listOf(index - 1, index + 1)
else -> emptyList()
}
}
.window... | 0 | Kotlin | 0 | 0 | 733b35c3f4eea777a5f666c804f3c92d0cc9854b | 874 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinSpeedToArriveOnTime.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2023 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,973 | kotlab | Apache License 2.0 |
src/Day03.kt | 0xBuro | 572,308,139 | false | {"Kotlin": 4929} | fun main() {
fun part1(input: List<String>): Int {
return input.map {
it.substring(0..it.length / 2) to it.substring(it.length / 2 until it.length) }
.map { (firstHalf, secondHalf) ->
firstHalf.toSet().intersect(secondHalf.toSet()).first() }
.map { 1 + if (it... | 0 | Kotlin | 0 | 0 | c05c4db78e24fc36f6f112bc1e8cf24ad5fd7698 | 915 | Advent-of-Kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ShortestPathLength.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,136 | kotlab | Apache License 2.0 |
app/src/main/kotlin/aoc2021/day06/Day06.kt | dbubenheim | 435,284,482 | false | {"Kotlin": 31242} | package aoc2021.day06
import aoc2021.toFile
class Day06 {
companion object {
@JvmStatic
fun lanternfishPart1() = "input-day06.txt".toFile()
.readLines()
.first()
.split(",")
.map { it.toInt() }
.groupingBy { it }
.eachCount(... | 9 | Kotlin | 0 | 0 | 83a93845ebbc1a6405f858214bfa79b3448b932c | 2,059 | advent-of-code-2021 | MIT License |
src/Day18.kt | felldo | 572,233,925 | false | {"Kotlin": 76496} | import kotlin.system.measureNanoTime
data class Point(val x: Int, val y: Int, val z: Int, var visited: Boolean = false)
fun main() {
fun part1(input: List<String>): Int {
val cubes = mutableListOf<Point>()
var totalExposed = 0
for (line in input) {
val nums = line.split(",").m... | 0 | Kotlin | 0 | 0 | 0ef7ac4f160f484106b19632cd87ee7594cf3d38 | 3,516 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day22.kt | mjossdev | 574,439,750 | false | {"Kotlin": 81859} | private enum class Tile {
VOID, WALL, OPEN;
}
private sealed interface Command {
object TurnLeft : Command {
override fun toString(): String = "L"
}
object TurnRight : Command {
override fun toString(): String = "R"
}
data class Move(val distance: Int) : Command {
over... | 0 | Kotlin | 0 | 0 | afbcec6a05b8df34ebd8543ac04394baa10216f0 | 8,214 | advent-of-code-22 | Apache License 2.0 |
lib/src/main/kotlin/aoc/day16/Day16.kt | Denaun | 636,769,784 | false | null | @file:Suppress("UnstableApiUsage")
package aoc.day16
import java.util.*
import kotlin.math.max
fun part1(input: String): Int = maximizeSingleReleasedPressure(parse(input), Valve("AA"), 30)!!
fun part2(input: String): Int = maximizeDoubleReleasedPressure(parse(input), Valve("AA"), 26)
fun maximizeSingleReleasedPres... | 0 | Kotlin | 0 | 0 | 560f6e33f8ca46e631879297fadc0bc884ac5620 | 3,337 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/day16.kt | tobiasae | 434,034,540 | false | {"Kotlin": 72901} | class Day16 : Solvable("16") {
override fun solveA(input: List<String>): String {
val bits = input.first().toBinary()
val p = Packet.parsePacket(bits.toConsumer())
fun getVersionSum(p: Packet): Int {
var sum = p.version
if (p is OperatorPacket) sum += p.packets.map... | 0 | Kotlin | 0 | 0 | 16233aa7c4820db072f35e7b08213d0bd3a5be69 | 4,258 | AdventOfCode | Creative Commons Zero v1.0 Universal |
leetcode-75-kotlin/src/main/kotlin/FindTheHighestAltitude.kt | Codextor | 751,507,040 | false | {"Kotlin": 49566} | /**
* There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes.
* The biker starts his trip on point 0 with altitude equal 0.
*
* You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i and i + 1 for all (0 <= i < n).
* ... | 0 | Kotlin | 0 | 0 | 0511a831aeee96e1bed3b18550be87a9110c36cb | 1,073 | leetcode-75 | Apache License 2.0 |
src/day03/Day03.kt | gr4cza | 572,863,297 | false | {"Kotlin": 93944} | package day03
import readInput
fun main() {
fun score(item: Char): Int = when (item) {
in 'a'..'z' -> item - 'a' + 1
in 'A'..'Z' -> item - 'A' + 27
else -> error("")
}
fun part1(input: List<String>): Int {
return input
.map { it.chunked(it.length / 2) }
... | 0 | Kotlin | 0 | 0 | ceca4b99e562b4d8d3179c0a4b3856800fc6fe27 | 954 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day04.kt | sjgoebel | 573,578,579 | false | {"Kotlin": 21782} | fun main() {
fun part1(input: List<String>): Int {
var count = 0
for (line in input) {
val (a, b) = line.split(',')
val (c, d) = a.split("-").map(String::toInt)
val (e, f) = b.split("-").map(String::toInt)
if ((e >= c && f <= d) || (c >= e) && (d <= f)... | 0 | Kotlin | 0 | 0 | ae1588dbbb923dbcd4d19fd1495ec4ebe8f2593e | 1,071 | advent-of-code-2022-kotlin | Apache License 2.0 |
year2021/src/main/kotlin/net/olegg/aoc/year2021/day23/Day23.kt | 0legg | 110,665,187 | false | {"Kotlin": 511989} | package net.olegg.aoc.year2021.day23
import net.olegg.aoc.someday.SomeDay
import net.olegg.aoc.utils.Vector2D
import net.olegg.aoc.year2021.DayOf2021
import java.util.PriorityQueue
import kotlin.math.abs
/**
* See [Year 2021, Day 23](https://adventofcode.com/2021/day/23)
*/
object Day23 : DayOf2021(23) {
private ... | 0 | Kotlin | 1 | 7 | e4a356079eb3a7f616f4c710fe1dfe781fc78b1a | 6,959 | adventofcode | MIT License |
calendar/day07/Day7.kt | mpetuska | 571,764,215 | false | {"Kotlin": 18073} | package day07
import Day
import Lines
class Day7 : Day() {
sealed interface FS {
val name: String
val size: Int
data class Dir(override val name: String, override val size: Int, val children: List<FS>) : FS {
fun flatten(): List<Dir> =
listOf(this) + children
.mapNotNull { if (i... | 0 | Kotlin | 0 | 0 | be876f0a565f8c14ffa8d30e4516e1f51bc3c0c5 | 1,873 | advent-of-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/Excercise21.kt | underwindfall | 433,989,850 | false | {"Kotlin": 55774} | private fun part1() {
val input = getInputAsTest("21")
val p = IntArray(2)
for (i in 0..1) {
p[i] = input[i].removePrefix("Player ${i + 1} starting position: ").toInt()
}
var rolls = 0L
val s = IntArray(2)
var i = 0
var d = 1
fun next(): Int {
rolls++
return d.also { d = d % 100 + 1 }
}
... | 0 | Kotlin | 0 | 0 | 4fbee48352577f3356e9b9b57d215298cdfca1ed | 1,390 | advent-of-code-2021 | MIT License |
src/main/kotlin/days/aoc2023/Day4.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2023
import days.Day
import kotlin.math.pow
class Day4 : Day(2023, 4) {
override fun partOne(): Any {
return calculatePartOne(inputList)
}
fun calculatePartOne(inputList: List<String>): Int {
return inputList.sumOf { line ->
Card.factory(line).score()
}... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 1,941 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/day10/Day10.kt | seastco | 574,758,881 | false | {"Kotlin": 72220} | package day10
import readLines
private fun part1(input: List<String>): Int {
var cycle = 0
var register = 1
val map = mutableMapOf<Int, Int>()
input.forEach {
val instruction = it.substringBefore(" ")
if (instruction == "addx") {
val number = it.substringAfter(" ").toInt(... | 0 | Kotlin | 0 | 0 | 2d8f796089cd53afc6b575d4b4279e70d99875f5 | 1,603 | aoc2022 | Apache License 2.0 |
src/main/kotlin/com/github/solairerove/algs4/leprosorium/arrays/CompliancePriorities.kt | solairerove | 282,922,172 | false | {"Kotlin": 251919} | package com.github.solairerove.algs4.leprosorium.arrays
/*
https://leetcode.com/discuss/interview-question/1362915/amazon-hackerrank-question-priority-assignment
*/
fun main() {
reassignedPriorities(arrayOf(1, 4, 8, 4)).forEach { print("$it ") }// [1, 2, 3, 2]
println()
reassignedPrioritiesHS(arrayOf(... | 1 | Kotlin | 0 | 3 | 64c1acb0c0d54b031e4b2e539b3bc70710137578 | 1,023 | algs4-leprosorium | MIT License |
leetcode2/src/leetcode/LeafSimilarTrees.kt | hewking | 68,515,222 | false | null | package leetcode
import leetcode.structure.TreeNode
import java.util.*
/**
* 872. 叶子相似的树
* https://leetcode-cn.com/problems/leaf-similar-trees/
* Created by test
* Date 2019/5/29 1:09
* Description
* 请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个 叶值序列 。
举个例子,如上图所示,给定一颗叶值序列为 (6, 7, 4, 9, 8) 的树。
如果有两颗二叉树的叶值序列是相同,那么我们就认为... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,593 | leetcode | MIT License |
src/Day04.kt | kipwoker | 572,884,607 | false | null |
fun main() {
fun parse(lines: List<String>): List<Pair<Interval, Interval>> {
return lines.map { line ->
val intervals = line
.split(',')
.map { range ->
val rangeParts = range.split('-')
Interval(rangeParts[0].toInt(), ra... | 0 | Kotlin | 0 | 0 | d8aeea88d1ab3dc4a07b2ff5b071df0715202af2 | 936 | aoc2022 | Apache License 2.0 |
src/questions/ContainerWithMostWater.kt | realpacific | 234,499,820 | false | null | package questions
import algorithmdesignmanualbook.print
import kotlin.test.assertTrue
fun _containerWithMostWater(height: IntArray): Int {
if (height.size == 2) {
return calcArea(0, 1, height)
}
var maxArea = calcArea(0, height.lastIndex, height)
for (i in 0 until height.lastIndex) {
... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 2,136 | algorithms | MIT License |
src/Day03.kt | shepard8 | 573,449,602 | false | {"Kotlin": 73637} | fun main() {
fun priority(item: Char) = when(item) {
in 'a'..'z' -> item - 'a' + 1
in 'A'..'Z' -> item - 'A' + 27
else -> throw IllegalArgumentException()
}
fun part1(rucksacks: List<String>) =
rucksacks.map { line ->
val left = line.subSequence(0, line.length / ... | 0 | Kotlin | 0 | 1 | 81382d722718efcffdda9b76df1a4ea4e1491b3c | 747 | aoc2022-kotlin | Apache License 2.0 |
src/day10.kt | miiila | 725,271,087 | false | {"Kotlin": 77215} | import java.io.File
import kotlin.math.max
import kotlin.system.exitProcess
private const val DAY = 10
fun main() {
if (!File("./day${DAY}_input").exists()) {
downloadInput(DAY)
println("Input downloaded")
exitProcess(0)
}
val transformer = { x: String -> x.toMutableList() }
va... | 0 | Kotlin | 0 | 1 | 1cd45c2ce0822e60982c2c71cb4d8c75e37364a1 | 4,255 | aoc2023 | MIT License |
src/main/kotlin/g1301_1400/s1368_minimum_cost_to_make_at_least_one_valid_path_in_a_grid/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1301_1400.s1368_minimum_cost_to_make_at_least_one_valid_path_in_a_grid
// #Hard #Array #Breadth_First_Search #Matrix #Heap_Priority_Queue #Graph #Shortest_Path
// #2023_06_06_Time_220_ms_(100.00%)_Space_37.6_MB_(100.00%)
import java.util.LinkedList
import java.util.Objects
import java.util.Queue
@Suppress("... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,936 | LeetCode-in-Kotlin | MIT License |
src/Day03.kt | elliaoster | 573,666,162 | false | {"Kotlin": 14556} | fun main() {
fun findPriority(commonChar: Char) = when (commonChar) {
'a' -> 1
'b' -> 2
'c' -> 3
'd' -> 4
'e' -> 5
'f' -> 6
'g' -> 7
'h' -> 8
'i' -> 9
'j' -> 10
'k' -> 11
'l' -> 12
'm' -> 13
'n' -> 14
... | 0 | Kotlin | 0 | 0 | 27e774b133f9d5013be9a951d15cefa8cb01a984 | 3,202 | advent-of-code-2022 | Apache License 2.0 |
day 01/Wouter - kotlin/solution.kts | AE-nv | 420,076,649 | false | {"Python": 254337, "Java": 180867, "C#": 167466, "F#": 114222, "Clojure": 88016, "C++": 45744, "HTML": 22679, "TypeScript": 19433, "Go": 16626, "JavaScript": 10488, "Assembly": 8364, "Rust": 6671, "Kotlin": 3264, "Scala": 2328, "CSS": 252} | fun solve(input: List<String>) : Int =
input.map { it.toInt() }
.windowed(2, 1)
.sumOf { (a, b) -> compare(a, b) }
fun solve2(input: List<String>) : Int =
input.asSequence().map { it.toInt() }
.windowed(3, 1)
.map { it.sum() }
.windowed(2, 1)
.sumOf { (a, b) -> c... | 0 | Python | 1 | 1 | e9c803dc5fab3c51a2acbbaade56b71d4f5ce7d2 | 638 | aedvent-code-2021 | MIT License |
src/day03/day03.kt | mahmoud-abdallah863 | 572,935,594 | false | {"Kotlin": 16377} | package day03
import assertEquals
import readInput
import readTestInput
fun main() {
fun part1(input: List<String>): Int = input
.sumOf { line ->
val (compartment1, compartment2) = line.chunked(line.length / 2).map { it.toSet() }
val commonCharacters = compartment1.intersect(compa... | 0 | Kotlin | 0 | 0 | f6d1a1583267e9813e2846f0ab826a60d2d1b1c9 | 1,204 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LongestRepeatingSubstring.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 | 4,046 | kotlab | Apache License 2.0 |
kotlin/2021/round-1c/closest-pick/src/main/kotlin/Solution.kt | ShreckYe | 345,946,821 | false | null | import kotlin.math.max
fun main() {
val t = readLine()!!.toInt()
repeat(t, ::testCase)
}
fun testCase(ti: Int) {
val (n, k) = readLine()!!.splitToSequence(' ').map { it.toInt() }.toList()
val ps = readLine()!!.splitToSequence(' ').map { it.toInt() }.toList()
val sortedPs = ps.sorted().distinct()
... | 0 | Kotlin | 1 | 1 | 743540a46ec157a6f2ddb4de806a69e5126f10ad | 1,089 | google-code-jam | MIT License |
problems/2021adventofcode16b/submissions/accepted/Stefan.kt | stoman | 47,287,900 | false | {"C": 169266, "C++": 142801, "Kotlin": 115106, "Python": 76047, "Java": 68331, "Go": 46428, "TeX": 27545, "Shell": 3428, "Starlark": 2165, "Makefile": 1582, "SWIG": 722} | import java.math.BigInteger
import java.util.*
abstract class Packet(val version: Int, val type: Int, val bitCount: Int) {
abstract fun value(): BigInteger
}
class Literal(version: Int, type: Int, bitCount: Int, private val value: Long) : Packet(version, type, bitCount) {
override fun value(): BigInteger = value.... | 0 | C | 1 | 3 | ee214c95c1dc1d5e9510052ae425d2b19bf8e2d9 | 2,683 | CompetitiveProgramming | MIT License |
src/main/kotlin/leetcode/kotlin/array/SortingAlgorithms/EfficientSort/MergeSort.kt | sandeep549 | 251,593,168 | false | null | package leetcode.kotlin.array.SortingAlgorithms.EfficientSort
// https://en.wikipedia.org/wiki/Sorting_algorithm
/*
1. Merge Sort
(a.) Divide the unsorted list into n sublists, each containing one element (a list of one element is considered sorted)
(b.) Repeatedly merge sublists to produce new sorted sublists until ... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 1,729 | kotlinmaster | Apache License 2.0 |
src/main/kotlin/aoc2019/CrossedWires.kt | komu | 113,825,414 | false | {"Kotlin": 395919} | package komu.adventofcode.aoc2019
import komu.adventofcode.utils.Direction
import komu.adventofcode.utils.Direction.*
import komu.adventofcode.utils.Point
private typealias Wire = List<Movement>
fun crossedWires(input: String): Int {
val (wire1, wire2) = input.lines().take(2).map { parseWire(it) }
val visit... | 0 | Kotlin | 0 | 0 | 8e135f80d65d15dbbee5d2749cccbe098a1bc5d8 | 1,784 | advent-of-code | MIT License |
src/main/kotlin/g0901_1000/s1000_minimum_cost_to_merge_stones/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s1000_minimum_cost_to_merge_stones
// #Hard #Array #Dynamic_Programming #2023_05_13_Time_152_ms_(75.00%)_Space_35.5_MB_(12.50%)
class Solution {
private lateinit var memo: Array<IntArray>
private lateinit var prefixSum: IntArray
fun mergeStones(stones: IntArray, k: Int): Int {
v... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,498 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/tw/gasol/aoc/aoc2022/Day4.kt | Gasol | 574,784,477 | false | {"Kotlin": 70912, "Shell": 1291, "Makefile": 59} | package tw.gasol.aoc.aoc2022
class Day4 {
fun part1(input: String): Int {
return input.lineSequence()
.filterNot { it.isBlank() }
.map(::toTwoSections)
.filter { it.isFullContained() }
.count()
}
private fun toTwoSections(line: String): Pair<IntRange... | 0 | Kotlin | 0 | 0 | a14582ea15f1554803e63e5ba12e303be2879b8a | 1,312 | aoc2022 | MIT License |
src/main/kotlin/Day08.kt | brigham | 573,127,412 | false | {"Kotlin": 59675} | fun main() {
fun parseLine(line: String): List<Int> =
line.toList().map { it.digitToInt() }.toList()
fun parse(input: List<String>): List<List<Int>> = input.map { parseLine(it) }
fun part1(input: List<String>): Int {
val heights = parse(input)
val visible = mutableListOf<MutableLis... | 0 | Kotlin | 0 | 0 | b87ffc772e5bd9fd721d552913cf79c575062f19 | 4,130 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day5.kt | gautemo | 572,204,209 | false | {"Kotlin": 78294} | import shared.chunks
import shared.getText
fun main() {
val input = getText("day5.txt")
println(day5A(input))
println(day5B(input))
}
fun day5A(input: String): String {
val (drawing, procedures) = input.chunks()
val stacks = readDrawing(drawing)
for(procedure in procedures.lines()) {
v... | 0 | Kotlin | 0 | 0 | bce9feec3923a1bac1843a6e34598c7b81679726 | 1,636 | AdventOfCode2022 | MIT License |
src/year2022/day17/Solution.kt | TheSunshinator | 572,121,335 | false | {"Kotlin": 144661} | package year2022.day17
import arrow.optics.copy
import arrow.optics.optics
import io.kotest.matchers.shouldBe
import kotlin.math.max
import utils.Direction
import utils.Point
import utils.continuing
import utils.cyclical
import utils.mapSecond
import utils.move
import utils.readInput
import utils.x
import utils.y
fun... | 0 | Kotlin | 0 | 0 | d050e86fa5591447f4dd38816877b475fba512d0 | 6,989 | Advent-of-Code | Apache License 2.0 |
src/main/kotlin/dev/siller/aoc2023/Day06.kt | chearius | 725,594,554 | false | {"Kotlin": 50795, "Shell": 299} | package dev.siller.aoc2023
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.pow
import kotlin.math.sqrt
data object Day06 : AocDayTask<ULong, ULong>(
day = 6,
exampleInput =
"""
|Time: 7 15 30
|Distance: 9 40 200
""".trimMargin(),
expectedExamp... | 0 | Kotlin | 0 | 0 | fab1dd509607eab3c66576e3459df0c4f0f2fd94 | 3,017 | advent-of-code-2023 | MIT License |
src/main/day04/Day04.kt | FlorianGz | 573,204,597 | false | {"Kotlin": 8491} | package main.day04
import readInput
import kotlin.math.max
import kotlin.math.min
fun main() {
val elfSections = readInput("main/day04/day04")
fun part1(): Int {
return elfSections.map { it.asRanges() }.count { (range1, range2) ->
range1.containedIn(range2) >= 2 || range2.containedIn(ran... | 0 | Kotlin | 0 | 0 | 58c9aa8fdec77c25a9d9945ca8e77ecd1170321b | 948 | aoc-kotlin-2022 | Apache License 2.0 |
Hackerrank/queens-attack-2-v1.kt | myinnernerd | 423,058,040 | true | {"Java": 95496, "C++": 36899, "Python": 8691, "JavaScript": 5544, "Kotlin": 4888, "C#": 4557, "C": 2699, "Ruby": 1277, "Clojure": 1018, "Scala": 563, "OCaml": 121} | import kotlin.collections.*
import kotlin.io.*
import kotlin.math.abs
import kotlin.ranges.*
import kotlin.text.*
/**
* @author: <NAME>
* This problem comes from HackerRank: https://www.hackerrank.com/challenges/queens-attack-2/problem
*
* queensAttack() Function Description:
* Given the queen's position and the ... | 0 | Java | 0 | 0 | b046b327a795ffd527112671413dc131d19bcc75 | 4,888 | Hacktoberfest | MIT License |
src/day05/Main.kt | nikwotton | 572,814,041 | false | {"Kotlin": 77320} | package day05
import java.io.File
import java.util.ArrayList
import java.util.Stack
const val workingDir = "src/day05"
fun main() {
val sample = File("$workingDir/sample.txt")
val input1 = File("$workingDir/input_1.txt")
println("Step 1a: ${runStep1(sample)}")
println("Step 1b: ${runStep1(input1)}")
... | 0 | Kotlin | 0 | 0 | dee6a1c34bfe3530ae6a8417db85ac590af16909 | 2,246 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/CountHighestScoreNodes.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,772 | kotlab | Apache License 2.0 |
src/ad/kata/aoc2021/day03/DiagnosticReport.kt | andrej-dyck | 433,401,789 | false | {"Kotlin": 161613} | package ad.kata.aoc2021.day03
import ad.kata.aoc2021.PuzzleInput
import ad.kata.aoc2021.extensions.transposed
class DiagnosticReport(val statusCodes: List<BinaryNumber>) {
val gammaRate: BinaryNumber by lazy { mostCommonBits(statusCodes) }
val epsilonRate: BinaryNumber by lazy { gammaRate.inv() }
val ox... | 0 | Kotlin | 0 | 0 | 28d374fee4178e5944cb51114c1804d0c55d1052 | 2,081 | advent-of-code-2021 | MIT License |
src/Day02.kt | msernheim | 573,937,826 | false | {"Kotlin": 32820} | fun main() {
fun getMoveScore(s: String): Int {
return when (s) {
"X" -> 1
"Y" -> 2
"Z" -> 3
else -> 0
}
}
fun getMatchScore(moveA: String, moveB: String): Int {
return when (moveA) {
"A" -> {
when (moveB) {... | 0 | Kotlin | 0 | 3 | 54cfa08a65cc039a45a51696e11b22e94293cc5b | 2,399 | AoC2022 | Apache License 2.0 |
src/main/kotlin/year2023/Day11.kt | forketyfork | 572,832,465 | false | {"Kotlin": 142196} | package year2023
import utils.Point2D
class Day11 {
fun part1(input: String) = solve(input, 2L)
fun part2(input: String) = solve(input, 1000000L)
fun solve(input: String, shift: Long): Long {
val space = input.lines().map { it.toCharArray() }
space.forEach { row ->
if (row.... | 0 | Kotlin | 0 | 0 | 5c5e6304b1758e04a119716b8de50a7525668112 | 1,785 | aoc-2022 | Apache License 2.0 |
src/Day03.kt | KristianAN | 571,726,775 | false | {"Kotlin": 9011} | fun Char.valueOf(): Int =
if (this.isLowerCase()) this.code.minus(96) else this.code.minus(38)
fun main() {
fun part1(input: List<String>): Int = input.map { s ->
s.chunked(s.length / 2).let { it[0].toSet().intersect(it[1].toSet()) }.toCharArray()[0]
}.sumOf { it.valueOf() }
fun part2(input: L... | 0 | Kotlin | 0 | 0 | 3a3af6e99794259217bd31b3c4fd0538eb797941 | 596 | AoC2022Kt | Apache License 2.0 |
dojos/music-theory/kotlin/Main.kt | magrathealabs | 210,662,430 | false | null | data class Note(val name: String)
{
fun flatten() = Note(name[0].toString() + 'b')
}
val Notes by lazy {
listOf("C", "C#", "D", "D#", "E", "F",
"F#", "G", "G#", "A", "A#", "B")
.map { Note(it) }
}
enum class Interval(val value: Int) {
Half(1),
Whole(2),
WholeAndHalf(3);
... | 0 | Jupyter Notebook | 1 | 27 | c6f28443895f70c9f677bc9346f9757cc526d678 | 4,565 | university | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[39]组合总和.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} |
import java.util.*
import kotlin.collections.ArrayList
//给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。
//
// candidates 中的数字可以无限制重复被选取。
//
// 说明:
//
//
// 所有数字(包括 target)都是正整数。
// 解集不能包含重复的组合。
//
//
// 示例 1:
//
// 输入:candidates = [2,3,6,7], target = 7,
//所求解集为:
//[
// [7],
// [... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 2,384 | MyLeetCode | Apache License 2.0 |
src/Day01.kt | sebastian-heeschen | 572,932,813 | false | {"Kotlin": 17461} | fun main() {
fun caloriesPerElf(
input: List<String>
): List<Int> {
val indexesOfSeparators = input.mapIndexedNotNull { index, element -> index.takeIf { element.isEmpty() } }
var indexToInsert1 = 0
val list = mutableListOf<Int>()
input.forEachIndexed { index, element ->... | 0 | Kotlin | 0 | 0 | 4432581c8d9c27852ac217921896d19781f98947 | 1,223 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/pl/klemba/aoc/day4/Main.kt | aklemba | 726,935,468 | false | {"Kotlin": 16373} | package pl.klemba.aoc.day4
import java.io.File
import kotlin.math.pow
fun main() {
// ----- PART 1 -----
File(inputPath)
.readLines()
.sumOf { card -> getNumberOfPointsForCard(card) }
.let { println(it) }
// ----- PART 2 -----
val cardList = File(inputPath)
.readLines()
val amountOfScratch... | 0 | Kotlin | 0 | 1 | 2432d300d2203ff91c41ffffe266e19a50cca944 | 1,959 | adventOfCode2023 | Apache License 2.0 |
src/Day01.kt | jmorozov | 573,077,620 | false | {"Kotlin": 31919} | import java.util.PriorityQueue
fun main() {
val inputData = readInput("Day01")
part1(inputData)
part2(inputData)
}
private fun part1(inputData: List<String>) {
var theMostTotalCalories = 0
var currentElfCalories = 0
for (line in inputData) {
when(line.trim()) {
"" -> {
... | 0 | Kotlin | 0 | 0 | 480a98838949dbc7b5b7e84acf24f30db644f7b7 | 2,122 | aoc-2022-in-kotlin | Apache License 2.0 |
advent-of-code-2023/src/main/kotlin/Day08.kt | jomartigcal | 433,713,130 | false | {"Kotlin": 72459} | // Day 08: <NAME>
// https://adventofcode.com/2023/day/8
import java.io.File
import kotlin.math.min
fun main() {
val lines = File("src/main/resources/Day08.txt").readLines()
val steps = lines.first().toList()
val map = lines.drop(2)
println(getHumanSteps(map, steps))
println(getGhostSteps(map, s... | 0 | Kotlin | 0 | 0 | 6b0c4e61dc9df388383a894f5942c0b1fe41813f | 1,857 | advent-of-code | Apache License 2.0 |
commons/src/commonMain/kotlin/org/jetbrains/letsPlot/commons/intern/typedGeometry/algorithms/Geometry.kt | JetBrains | 176,771,727 | false | {"Kotlin": 6221641, "Python": 1158665, "Shell": 3495, "C": 3039, "JavaScript": 931, "Dockerfile": 94} | /*
* Copyright (c) 2023. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package org.jetbrains.letsPlot.commons.intern.typedGeometry.algorithms
import org.jetbrains.letsPlot.commons.geometry.DoubleVector
import org.jetbrains.letsPlot.commons.inter... | 128 | Kotlin | 46 | 1,373 | c61353ece18358ba6c6306a0f634e3b4b036577a | 2,671 | lets-plot | MIT License |
src/main/kotlin/days/Day3.kt | C06A | 435,034,782 | false | {"Kotlin": 20662} | package days
class Day3: Day(3) {
override fun partOne(): Any {
val onesCounts = Array<Int>(inputList[0].length) { 0 }
val half = inputList.size / 2
inputList.forEach {
it.toCharArray().forEachIndexed { i, char ->
if (char == '1') onesCounts[i]++
}... | 0 | Kotlin | 0 | 0 | afbe60427eddd2b6814815bf7937a67c20515642 | 1,756 | Aoc2021 | Creative Commons Zero v1.0 Universal |
src/day04/Day04.kt | easchner | 572,762,654 | false | {"Kotlin": 104604} | package day04
import readInputString
fun main() {
fun part1(input: List<String>): Long {
var totalOverlap = 0L
for (line in input) {
val elves = line.split(",").map {
it.split("-").map {
it.toInt()
}
}.map {
... | 0 | Kotlin | 0 | 0 | 5966e1a1f385c77958de383f61209ff67ffaf6bf | 1,254 | Advent-Of-Code-2022 | Apache License 2.0 |
src/net/sheltem/aoc/y2022/Day12.kt | jtheegarten | 572,901,679 | false | {"Kotlin": 178521} | package net.sheltem.aoc.y2022
class Day12 : Day<Int>(31, 29) {
override suspend fun part1(input: List<String>) = HeightMap(input).dijkstra().goal.cost
override suspend fun part2(input: List<String>) = HeightMap(input, true).dijkstra().goal.cost
}
suspend fun main() {
Day12().run()
}
class HeightMap(in... | 0 | Kotlin | 0 | 0 | ac280f156c284c23565fba5810483dd1cd8a931f | 1,764 | aoc | Apache License 2.0 |
LeetCode/Medium/3-sum/Solution.kt | GregoryHo | 254,657,102 | false | null | class Solution {
fun threeSum(nums: IntArray): List<List<Int>> {
val size = nums.size
val sortedNums = nums.sorted()
val answers = mutableListOf<List<Int>>()
if (size < 3) {
return answers
}
for (i in 0 until size - 2) {
var leftIndex = i + 1
var rightIndex = size - 1
... | 0 | Kotlin | 0 | 0 | 8f126ffdf75aa83a6d60689e0b6fcc966a173c70 | 1,823 | coding-fun | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.