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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2021/src/Day07.kt | Bajena | 433,856,664 | false | {"Kotlin": 65121, "Ruby": 14942, "Rust": 1698, "Makefile": 454} | import kotlin.math.abs
// https://adventofcode.com/2021/day/7
fun main() {
fun part1() {
var crabPositions = listOf<Int>()
for (line in readInput("Day07")) {
crabPositions = line.split(",").map { it.toInt() }.sorted()
}
println(crabPositions.size)
var minSum = Int.MAX_VALUE
var resu... | 0 | Kotlin | 0 | 0 | a5ca56b7ac8d9d48f82dc079c8ea0cf06d17109a | 1,469 | advent-of-code | Apache License 2.0 |
src/main/kotlin/days/Day03.kt | julia-kim | 435,257,054 | false | {"Kotlin": 15771} | package days
import readInput
fun main() {
fun part1(input: List<String>): Long {
var gammaRate = ""
var epsilonRate = ""
var i = 0
while (i < input[0].length) {
val bits = input.map { it[i] }.groupingBy { it }.eachCount()
gammaRate += bits.maxByOrNull { it.... | 0 | Kotlin | 0 | 0 | 5febe0d5b9464738f9a7523c0e1d21bd992b9302 | 1,946 | advent-of-code-2021 | Apache License 2.0 |
src/day05/day05.kt | tmikulsk1 | 573,165,106 | false | {"Kotlin": 25281} | package day05
import readInput
fun main() {
val inputFile = readInput("day05/input.txt").readLines()
val indexReference = inputFile.indexOf("")
val commands = getCommandsForStackMoves(inputFile, indexReference)
val arrayStacksForPuzzle1 = getSupplyStacks(inputFile, indexReference)
getPuzzle1TopSt... | 0 | Kotlin | 0 | 1 | f5ad4e601776de24f9a118a0549ac38c63876dbe | 4,241 | AoC-22 | Apache License 2.0 |
src/main/kotlin/days/Day8.kt | jgrgt | 433,952,606 | false | {"Kotlin": 113705} | package days
class Day8 : Day(8) {
// 0: abcefg
// 1: cf
// 2: acdeg
// 3: acdfg
// 4: bcdf
// 5: abdfg
// 6: abdefg
// 7: acf
// 8: abcdefg
// 9: abcdfg
val sevenDigit = mapOf(
"abcefg" to 0,
"cf" to 1,
"acdeg" to 2,
"acdfg" to 3,
... | 0 | Kotlin | 0 | 0 | 6231e2092314ece3f993d5acf862965ba67db44f | 5,661 | aoc2021 | Creative Commons Zero v1.0 Universal |
src/Day07.kt | sjgoebel | 573,578,579 | false | {"Kotlin": 21782} | fun main() {
fun part1(input: List<String>): Int {
val directory = Folder("/", null)
var current = directory
for (line in input)
{
val commands = line.split(" ")
if (commands[0] == "$")
{
if (commands[1] == "cd") {
... | 0 | Kotlin | 0 | 0 | ae1588dbbb923dbcd4d19fd1495ec4ebe8f2593e | 4,781 | advent-of-code-2022-kotlin | Apache License 2.0 |
kotlin/0912-sort-an-array.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | /*
* Merge sort
*/
class Solution {
fun sortArray(nums: IntArray): IntArray {
mergeSort(nums, 0, nums.lastIndex)
return nums
}
private fun mergeSort(nums: IntArray, left: Int, right: Int) {
if(left == right) return
val mid = (left + right) / 2
mergeSort(nums, left, ... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 3,040 | leetcode | MIT License |
kotlin/0139-word-break.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | //DP
class Solution {
fun wordBreak(s: String, wordDict: List<String>): Boolean {
val cache = BooleanArray (s.length + 1).apply {
this[s.length] = true
}
for (i in s.lastIndex downTo 0) {
for (word in wordDict) {
if (word.length + i <= s.leng... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 2,320 | leetcode | MIT License |
src/Day01.kt | MarkTheHopeful | 572,552,660 | false | {"Kotlin": 75535} | import kotlin.math.max
fun main() {
fun part1(input: List<String>): Int {
return input.fold(Pair(0, 0)) { maxAndSum, element ->
if (element.isBlank()) Pair(max(maxAndSum.first, maxAndSum.second), 0)
else Pair(maxAndSum.first, maxAndSum.second + element.toInt())
}.first
}... | 0 | Kotlin | 0 | 0 | 8218c60c141ea2d39984792fddd1e98d5775b418 | 963 | advent-of-kotlin-2022 | Apache License 2.0 |
src/main/kotlin/dev/bogwalk/batch7/Problem76.kt | bog-walk | 381,459,475 | false | null | package dev.bogwalk.batch7
/**
* Problem 76: Counting Summations
*
* https://projecteuler.net/problem=76
*
* Goal: Count the number of ways (mod 1e9 + 7) that N can be written as a sum of at least 2
* positive integers.
*
* Constraints: 2 <= N <= 1000
*
* e.g.: N = 5
* count = 6 -> {4+1, 3+2, 3+1+1, 2... | 0 | Kotlin | 0 | 0 | 62b33367e3d1e15f7ea872d151c3512f8c606ce7 | 1,934 | project-euler-kotlin | MIT License |
day9/src/main/kotlin/com/nohex/aoc/day9/MeasureCalculator.kt | mnohe | 433,396,563 | false | {"Kotlin": 105740} | package com.nohex.aoc.day9
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking
/**
* Methods to apply calculations to a set of height measurements.
*/
class MeasureCalculator(private val measures: Set<Measure>) {
/**
* Finds risk levels, i.e. the lowest points' heights, plus one.
*... | 0 | Kotlin | 0 | 0 | 4d7363c00252b5668c7e3002bb5d75145af91c23 | 2,284 | advent_of_code_2021 | MIT License |
src/main/kotlin/Day07.kt | attilaTorok | 573,174,988 | false | {"Kotlin": 26454} | open class Directory(
val name: String, val parent: Directory?, val children: MutableList<Directory> = mutableListOf(), var size: Long = 0
) {
fun calculateSize() {
for (child in children) {
size += child.size
}
}
}
fun main() {
fun createFileHierarchy(fileName: String): Di... | 0 | Kotlin | 0 | 0 | 1799cf8c470d7f47f2fdd4b61a874adcc0de1e73 | 3,277 | AOC2022 | Apache License 2.0 |
src/main/kotlin/day17/solution.kt | bukajsytlos | 433,979,778 | false | {"Kotlin": 63913} | package day17
import java.io.File
import kotlin.math.abs
import kotlin.math.round
import kotlin.math.sqrt
fun main() {
val lines = File("src/main/kotlin/day17/input.txt").readLines()
val (x1, x2) = lines.first().substringAfter("target area: x=").substringBefore(", y=").split("..")
.map { it.toInt() }
... | 0 | Kotlin | 0 | 0 | f47d092399c3e395381406b7a0048c0795d332b9 | 1,950 | aoc-2021 | MIT License |
src/aoc2023/Day04.kt | dayanruben | 433,250,590 | false | {"Kotlin": 79134} | package aoc2023
import readInput
import checkValue
fun main() {
val (year, day) = "2023" to "Day04"
fun countMatches(cardLine: String): Int {
val (_, cards) = cardLine.split(": ")
val (win, mine) = cards.split("|").map { group ->
group.trim().split("\\s+".toRegex()).map { num ->
... | 1 | Kotlin | 2 | 30 | df1f04b90e81fbb9078a30f528d52295689f7de7 | 1,332 | aoc-kotlin | Apache License 2.0 |
src/main/kotlin/be/swsb/aoc2021/day13/Day13.kt | Sch3lp | 433,542,959 | false | {"Kotlin": 90751} | package be.swsb.aoc2021.day13
import be.swsb.aoc2021.common.FoldInstruction
import be.swsb.aoc2021.common.Point
import be.swsb.aoc2021.common.Point.Companion.at
object Day13 {
fun solve1(input: List<String>): Int {
val (paper, instructions) = parse(input)
return paper.fold(instructions.take(1)).vi... | 0 | Kotlin | 0 | 0 | 7662b3861ca53214e3e3a77c1af7b7c049f81f44 | 2,259 | Advent-of-Code-2021 | MIT License |
src/main/kotlin/day9/Day9.kt | Arch-vile | 317,641,541 | false | null | package day9
import readFile
fun pairCombinations(numbers: List<Long>): List<Pair<Long,Long>> =
numbers
.map { first ->
numbers.map { second ->
Pair(first, second)
}
}.flatten()
.filter { it.first !== it.second }
fun pairCombinationsSums(dropLast: List<Long>): List<Long> =
pairC... | 0 | Kotlin | 0 | 0 | 12070ef9156b25f725820fc327c2e768af1167c0 | 1,044 | adventOfCode2020 | Apache License 2.0 |
advent-of-code2016/src/main/kotlin/day07/Advent7.kt | REDNBLACK | 128,669,137 | false | null | package day07
import chunk
import parseInput
import splitToLines
/**
--- Day 7: Internet Protocol Version 7 ---
While snooping around the local network of EBHQ, you compile a list of IP addresses (they're IPv7, of course; IPv6 is much too limited). You'd like to figure out which IPs support TLS (transport-layer snoo... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 3,977 | courses | MIT License |
src/test/kotlin/days/y2022/Day11Test.kt | jewell-lgtm | 569,792,185 | false | {"Kotlin": 161272, "Jupyter Notebook": 103410, "TypeScript": 78635, "JavaScript": 123} | package days.y2022
import days.Day
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.Is.`is`
import org.junit.jupiter.api.Test
class Day11 : Day(2022, 11) {
override fun partOne(input: String): Any {
val monkeys = parseInput(input)
repeat(20) {
for (monkey in mon... | 0 | Kotlin | 0 | 0 | b274e43441b4ddb163c509ed14944902c2b011ab | 4,511 | AdventOfCode | Creative Commons Zero v1.0 Universal |
calendar/day16/Day16.kt | rocketraman | 573,845,375 | false | {"Kotlin": 45660} | package day16
import Day
import Lines
class Day16 : Day() {
val INPUT_PATTERN = """^Valve (.+) has flow rate=(\d+); tunnels? leads? to valves? (.*)$""".toRegex()
sealed class PathElement {
abstract val node: String
}
data class Open(override val node: String): PathElement()
data class Move(override val... | 0 | Kotlin | 0 | 0 | 6bcce7614776a081179dcded7c7a1dcb17b8d212 | 5,326 | adventofcode-2022 | Apache License 2.0 |
src/Day24Part2.kt | schoi80 | 726,076,340 | false | {"Kotlin": 83778} | import Day24Part2.part2
import com.microsoft.z3.Context
import com.microsoft.z3.Model
import com.microsoft.z3.RatNum
import com.microsoft.z3.RealExpr
import com.microsoft.z3.Status
import java.math.BigDecimal
object Day24Part2 {
data class XYZ(
val x: Long,
val y: Long,
val z: Long,
)
... | 0 | Kotlin | 0 | 0 | ee9fb20d0ed2471496185b6f5f2ee665803b7393 | 2,848 | aoc-2023 | Apache License 2.0 |
archive/153/solve.kt | daniellionel01 | 435,306,139 | false | null | /*
=== #153 Investigating Gaussian Integers - Project Euler ===
As we all know the equation x2=-1 has no solutions for real x.
If we however introduce the imaginary number i this equation has two solutions: x=i and x=-i.
If we go a step further the equation (x-3)2=-4 has two complex solutions: x=3+2i and x=3-2i.
x=3... | 0 | Kotlin | 0 | 1 | 1ad6a549a0a420ac04906cfa86d99d8c612056f6 | 2,160 | euler | MIT License |
src/Day17.kt | astrofyz | 572,802,282 | false | {"Kotlin": 124466} | import java.io.File
fun main() {
class Point(var x: Int, var y: Int){}
class Shape(var points: MutableList<Point>){}
fun Shape.rightmost(): Int{
return this.points.map { it.x }.max()
}
fun Shape.leftmost(): Int{
return this.points.map { it.x }.min()
}
fun Shape.lowest()... | 0 | Kotlin | 0 | 0 | a0bc190b391585ce3bb6fe2ba092fa1f437491a6 | 6,794 | aoc22 | Apache License 2.0 |
src/main/kotlin/se/saidaspen/aoc/aoc2021/Day18.kt | saidaspen | 354,930,478 | false | {"Kotlin": 301372, "CSS": 530} | package se.saidaspen.aoc.aoc2021
import se.saidaspen.aoc.aoc2021.SnailFishNumber.SFPair.Companion.parse
import se.saidaspen.aoc.util.Day
import se.saidaspen.aoc.util.permutations
import kotlin.math.ceil
import kotlin.math.floor
fun main() = Day18.run()
object Day18 : Day(2021, 18) {
override fun part1() = input.... | 0 | Kotlin | 0 | 1 | be120257fbce5eda9b51d3d7b63b121824c6e877 | 4,712 | adventofkotlin | MIT License |
src/main/aoc2016/Day17.kt | nibarius | 154,152,607 | false | {"Kotlin": 963896} | package aoc2016
import md5
class Day17(private val input: String) {
private data class State(val x: Int, val y: Int, val history: String)
private fun walkMaze(passcode: String, findShortestRoute: Boolean = true): String {
val toCheck = mutableListOf(State(1, 1, ""))
val isOpen = "bcdef"
... | 0 | Kotlin | 0 | 6 | f2ca41fba7f7ccf4e37a7a9f2283b74e67db9f22 | 1,588 | aoc | MIT License |
algorithms/src/main/kotlin/io/nullables/api/playground/algorithms/MergeSort.kt | AlexRogalskiy | 331,076,596 | false | null | /*
* Copyright (C) 2021. <NAME>. All Rights Reserved.
*
* 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 applic... | 13 | Kotlin | 2 | 2 | d7173ec1d9ef227308d926e71335b530c43c92a8 | 2,128 | gradle-kotlin-sample | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FindKClosestElements.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 | 3,905 | kotlab | Apache License 2.0 |
src/Day07.kt | MT-Jacobs | 574,577,538 | false | {"Kotlin": 19905} | fun main() {
fun part1(input: List<String>): Int {
val system: Filesystem = traverseInfo(input)
return system.directories.map { it.dataSize }.filter { it <= 100000 }.sum()
}
fun part2(input: List<String>): Int {
val system: Filesystem = traverseInfo(input)
val totalSpace = 7... | 0 | Kotlin | 0 | 0 | 2f41a665760efc56d531e56eaa08c9afb185277c | 5,126 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/days/aoc2023/Day2.kt | bjdupuis | 435,570,912 | false | {"Kotlin": 537037} | package days.aoc2023
import days.Day
import java.lang.Integer.min
import java.util.IllegalFormatException
import kotlin.math.max
class Day2 : Day(2023, 2) {
override fun partOne(): Any {
return calculatePartOne(inputList)
}
override fun partTwo(): Any {
return calculatePartTwo(inputList)
... | 0 | Kotlin | 0 | 1 | c692fb71811055c79d53f9b510fe58a6153a1397 | 3,042 | Advent-Of-Code | Creative Commons Zero v1.0 Universal |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FourSum.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2020 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 3,797 | kotlab | Apache License 2.0 |
2015/src/main/kotlin/day12.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
fun main() {
Day12.run()
}
object Day12 : Solution<String>() {
override val name = "day12"
override val parser: Parser<String> = Parser { it }
data class VisitResult(
val sum: Int,
val redSum: Int,
val len: Int,
val red: Boolean,
)
private fun vi... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 2,153 | aoc_kotlin | MIT License |
src/main/kotlin/P018_MaximumPathSum.kt | perihanmirkelam | 291,833,878 | false | null | /**
* P18-Maximum Path Sum
* 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 | 1 | 3 | a24ac440871220c87419bfd5938f80dc22a422b2 | 2,077 | ProjectEuler | MIT License |
src/main/kotlin/adventofcode/year2015/Day15ScienceForHungryPeople.kt | pfolta | 573,956,675 | false | {"Kotlin": 199554, "Dockerfile": 227} | package adventofcode.year2015
import adventofcode.Puzzle
import adventofcode.PuzzleInput
import adventofcode.common.cartesianProduct
import kotlin.math.max
class Day15ScienceForHungryPeople(customInput: PuzzleInput? = null) : Puzzle(customInput) {
override val name = "Science for Hungry People"
private val i... | 0 | Kotlin | 0 | 0 | 72492c6a7d0c939b2388e13ffdcbf12b5a1cb838 | 2,468 | AdventOfCode | MIT License |
src/Day02.kt | ezeferex | 575,216,631 | false | {"Kotlin": 6838} | // A and X are Rock (1 point)
// B and Y are Paper (2 points)
// C and Z are Scissors (3 points)
// 6 points if won
// 3 points if draw
// 0 point if lost
fun scoreShape(shape: String) = when(shape) {
"X" -> 1
"Y" -> 2
"Z" -> 3
else -> 0
}
fun scoreRock(shape: String) = when(shape) {
"A" -> 3
... | 0 | Kotlin | 0 | 0 | f06f8441ad0d7d4efb9ae449c9f7848a50f3f57c | 1,766 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2021/2021-25.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2021
import com.github.ferinagy.adventOfCode.Coord2D
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
fun main() {
val input = readInputLines(2021, "25-input")
val test1 = readInputLines(2021, "25-test1")
pr... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 2,568 | advent-of-code | MIT License |
day14/kotlin/corneil/src/main/kotlin/solution.kt | tschulte | 317,661,818 | true | {"HTML": 2739009, "Java": 348790, "Kotlin": 271053, "TypeScript": 262310, "Python": 198318, "Groovy": 125347, "Jupyter Notebook": 116902, "C++": 101742, "Dart": 47762, "Haskell": 43633, "CSS": 35030, "Ruby": 27091, "JavaScript": 13242, "Scala": 11409, "Dockerfile": 10370, "PHP": 4152, "Go": 2838, "Shell": 2651, "Rust":... | package com.github.corneil.aoc2019.day14
import java.io.File
typealias ChemicalQty = Pair<Long, String>
data class ReactionFormula(val inputs: List<ChemicalQty>, val output: ChemicalQty)
fun readChemicalQty(it: String): ChemicalQty {
val tokens = it.trim().split(" ")
require(tokens.size == 2)
return Che... | 0 | HTML | 0 | 0 | afcaede5326b69fedb7588b1fe771fd0c0b3f6e6 | 5,516 | docToolchain-aoc-2019 | MIT License |
src/Day04.kt | i-tatsenko | 575,595,840 | false | {"Kotlin": 90644} | class Range(serialized: String) {
private val start: Int
private val end: Int
init {
val split = serialized.split('-')
start = split[0].toInt()
end = split[1].toInt()
}
fun contains(other: Range): Boolean = start <= other.start && end >= other.end
fun overlaps(other: R... | 0 | Kotlin | 0 | 0 | 0a9b360a5fb8052565728e03a665656d1e68c687 | 1,317 | advent-of-code-2022 | Apache License 2.0 |
src/Day12.kt | lsimeonov | 572,929,910 | false | {"Kotlin": 66434} | import kotlin.math.abs
typealias GridPosition = Triple<Int, Int, Char>
typealias Barrier = Set<GridPosition>
const val MAX_SCORE = 99999999
abstract class Grid(private val barriers: List<Barrier>) {
open fun heuristicDistance(start: GridPosition, finish: GridPosition): Int {
val dx = abs(start.first - f... | 0 | Kotlin | 0 | 0 | 9d41342f355b8ed05c56c3d7faf20f54adaa92f1 | 6,798 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/day2/Day02.kt | Avataw | 572,709,044 | false | {"Kotlin": 99761} | package day2
val outcomesA = mapOf(
"A X" to 4, "A Y" to 8, "A Z" to 3,
"B X" to 1, "B Y" to 5, "B Z" to 9,
"C X" to 7, "C Y" to 2, "C Z" to 6,
)
fun solveA(input: List<String>) = input.mapNotNull { outcomesA[it] }.sum()
val outcomesB = mapOf(
"A X" to 3, "A Y" to 4, "A Z" to 8,
"B X" to 1, "B Y"... | 0 | Kotlin | 2 | 0 | 769c4bf06ee5b9ad3220e92067d617f07519d2b7 | 2,172 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/net/voldrich/aoc2021/Day10.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2021
import net.voldrich.BaseDay
import java.util.*
// https://adventofcode.com/2021/day/10
fun main() {
Day10().run()
}
class Day10 : BaseDay() {
override fun task1() : Int {
val list = input.lines().map { analyzeLine(it) }
return list.filter { it.type == Type.CORRUP... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 2,305 | advent-of-code | Apache License 2.0 |
kotlin/0779-k-th-symbol-in-grammar.kt | neetcode-gh | 331,360,188 | false | {"JavaScript": 473974, "Kotlin": 418778, "Java": 372274, "C++": 353616, "C": 254169, "Python": 207536, "C#": 188620, "Rust": 155910, "TypeScript": 144641, "Go": 131749, "Swift": 111061, "Ruby": 44099, "Scala": 26287, "Dart": 9750} | class Solution {
fun kthGrammar(n: Int, k: Int): Int {
var cur = 0
var left = 1
var right = 2.0.pow(n - 1).toInt()
repeat (n - 1) {
val mid = (left + right) / 2
if (k <= mid) {
right = mid
} else {
left = mid + 1
... | 337 | JavaScript | 2,004 | 4,367 | 0cf38f0d05cd76f9e96f08da22e063353af86224 | 959 | leetcode | MIT License |
src/day02/Day02.kt | scottpeterson | 573,109,888 | false | {"Kotlin": 15611} | enum class Opponent {
A,
B,
C
}
enum class You {
X,
Y,
Z
}
data class Round(
val opponent: Opponent,
val you: You
)
fun main() {
fun result(opponent: Opponent, you: You): Int {
return when (opponent) {
Opponent.A -> when (you) {
You.X -> 3
... | 0 | Kotlin | 0 | 0 | 0d86213c5e0cd5403349366d0f71e0c09588ca70 | 2,331 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/11.kts | reitzig | 318,492,753 | false | null | @file:Include("shared.kt")
import _11.GridElement.*
import _11.Position
import java.io.File
enum class GridElement(val rep: Char) {
EmptySeat('L'),
OccupiedSeat('#'),
Floor('.');
companion object {
fun valueOfRep(rep: Char): GridElement =
values().firstOrNull { it.rep == rep }
... | 0 | Kotlin | 0 | 0 | f17184fe55dfe06ac8897c2ecfe329a1efbf6a09 | 3,040 | advent-of-code-2020 | The Unlicense |
src/year2023/day24/Day24.kt | lukaslebo | 573,423,392 | false | {"Kotlin": 222221} | package year2023.day24
import check
import com.microsoft.z3.*
import readInput
import java.math.BigDecimal
fun main() {
val testInput = readInput("2023", "Day24_test")
check(part1(testInput, testArea = 7L..27L), 2)
check(part2(testInput), 47)
val input = readInput("2023", "Day24")
println(part1(i... | 0 | Kotlin | 0 | 1 | f3cc3e935bfb49b6e121713dd558e11824b9465b | 3,335 | AdventOfCode | Apache License 2.0 |
src/Day12.kt | mpythonite | 572,671,910 | false | {"Kotlin": 29542} | import java.time.InstantSource
fun main() {
class GridSpot(val height: Int, var distance: Int = Int.MAX_VALUE)
class Move(val destX: Int, val destY: Int, val direction: String)
class Grid() {
var grid: Array<Array<GridSpot>> = arrayOf()
var moves: ArrayDeque<Move> = ArrayDeque()
fu... | 0 | Kotlin | 0 | 0 | cac94823f41f3db4b71deb1413239f6c8878c6e4 | 4,224 | advent-of-code-2022 | Apache License 2.0 |
src/Day05.kt | ajspadial | 573,864,089 | false | {"Kotlin": 15457} | import java.util.*
fun main() {
fun loadCrates(input: List<String>): MutableList<Stack<String>> {
val stacks : MutableList<Stack<String>> = mutableListOf<Stack<String>>()
for (line in input) {
var nextCrate = line.indexOf('[')
while (nextCrate != -1) {
val ... | 0 | Kotlin | 0 | 0 | ed7a2010008be17fec1330b41adc7ee5861b956b | 2,941 | adventofcode2022 | Apache License 2.0 |
leetcode-75-kotlin/src/main/kotlin/MaximumNumberOfVowelsInASubstringOfGivenLength.kt | Codextor | 751,507,040 | false | {"Kotlin": 49566} | /**
* Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.
*
* Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'.
*
*
*
* Example 1:
*
* Input: s = "abciiidef", k = 3
* Output: 3
* Explanation: The substring "iii" contains 3 vowel letters.
... | 0 | Kotlin | 0 | 0 | 0511a831aeee96e1bed3b18550be87a9110c36cb | 1,388 | leetcode-75 | Apache License 2.0 |
src/day03/Day03.kt | schrami8 | 572,631,109 | false | {"Kotlin": 18696} | package day03
import readInput
fun charToPriority(char: Char): Int =
when (char) {
in 'a'..'z' -> char.code - 96 // 'a' is 97 on the ascii table
in 'A'..'Z' -> char.code - 64 + 26 // 'A' is 65 on the ascii table
else -> 0
}
fun main() {
fun part1(input: List<String>): Int {
return input.ma... | 0 | Kotlin | 0 | 0 | 215f89d7cd894ce58244f27e8f756af28420fc94 | 1,064 | advent-of-code-kotlin | Apache License 2.0 |
src/main/java/com/barneyb/aoc/aoc2022/day05/SupplyStacks.kt | barneyb | 553,291,150 | false | {"Kotlin": 184395, "Java": 104225, "HTML": 6307, "JavaScript": 5601, "Shell": 3219, "CSS": 1020} | package com.barneyb.aoc.aoc2022.day05
import com.barneyb.aoc.util.Slice
import com.barneyb.aoc.util.Solver
import com.barneyb.aoc.util.toInt
import com.barneyb.aoc.util.toSlice
import com.barneyb.util.Stack
fun main() {
Solver.benchmark(
::parse,
::crateMover9000,
::crateMover9001,
)
}... | 0 | Kotlin | 0 | 0 | 8b5956164ff0be79a27f68ef09a9e7171cc91995 | 2,525 | aoc-2022 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimumGeneticMutation.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 | 2,074 | kotlab | Apache License 2.0 |
src/main/kotlin/Main.kt | BrightOS | 618,253,629 | false | null | import java.io.File
const val QUANTUM_TIME = 2
private var numberOfPriorityTicks = 0
fun parseInputFile(file: File): Pair<ArrayList<Process>, Int> {
var resultNumberOfTicks = 0
val list = arrayListOf<Process>().apply {
file.forEachLine {
it.split(" ").let {
add(
... | 0 | Kotlin | 0 | 0 | 84f5b7175ec6a750c5c16410a8f90d3d42e09952 | 2,915 | os_2 | Apache License 2.0 |
2022/Day08.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | fun main() {
val input = readInput("Day08")
var res1 = 0
var res2 = 0
for (i0 in input.indices) {
for (j0 in input[i0].indices) {
val t = input[i0][j0]
val visible =
(0 until i0).all { input[it][j0] < t } ||
(i0+1 until input.size).all { in... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 1,195 | advent-of-code-kotlin | Apache License 2.0 |
src/main/kotlin/org/kotrix/matrix/decomp/CholeskyDecompPrototype.kt | JarnaChao09 | 285,169,397 | false | {"Kotlin": 446442, "Jupyter Notebook": 26378} | package org.kotrix.matrix.decomp
import org.kotrix.matrix.DoubleMatrix
import org.kotrix.utils.by
import kotlin.math.max
import kotlin.math.sqrt
fun List<List<Double>>.transpose(): List<List<Double>> {
val ret = MutableList(this.size) { MutableList(this.size) { 0.0 } }
for (i in this.indices) {
for (j... | 0 | Kotlin | 1 | 5 | c5bb19457142ce1f3260e8fed5041a4d0c77fb14 | 2,299 | Kotrix | MIT License |
src/main/kotlin/day15/BacktrackingPathfinder.kt | Ostkontentitan | 434,500,914 | false | {"Kotlin": 73563} | package day15
class BacktrackingPathfinder : Pathfinder {
override fun searchOptimalPath(
map: Array<Array<Int>>
): Int {
val destination = CavePosition(map.lastIndex, map.first().lastIndex, map.last().last())
val start = CavePosition(0, 0, map[0][0])
val bestForPosition: Array<... | 0 | Kotlin | 0 | 0 | e0e5022238747e4b934cac0f6235b92831ca8ac7 | 3,338 | advent-of-kotlin-2021 | Apache License 2.0 |
src/day25/Day25.kt | easchner | 572,762,654 | false | {"Kotlin": 104604} | package day25
import readInputString
import java.lang.Math.abs
import java.lang.Math.pow
import java.util.PriorityQueue
import kotlin.math.pow
import kotlin.system.measureNanoTime
fun main() {
fun snafuToDecimal(snafu: String): Long {
var total = 0L
for (i in snafu.indices) {
val power... | 0 | Kotlin | 0 | 0 | 5966e1a1f385c77958de383f61209ff67ffaf6bf | 1,986 | Advent-Of-Code-2022 | Apache License 2.0 |
src/main/kotlin/days/Day7Data.kt | yigitozgumus | 572,855,908 | false | {"Kotlin": 26037} | package days
import utils.SolutionData
import java.util.Stack
fun main() = with(Day7Data()) {
solvePart1()
solvePart2()
}
sealed interface FileSystem {
data class Dir(
val name: String,
val contents: MutableList<FileSystem> = mutableListOf()
): FileSystem
data class File(val name: String, val size: Int): Fi... | 0 | Kotlin | 0 | 0 | 9a3654b6d1d455aed49d018d9aa02d37c57c8946 | 1,781 | AdventOfCode2022 | MIT License |
src/main/kotlin/Day11.kt | i-redbyte | 433,743,675 | false | {"Kotlin": 49932} | import java.util.*
class Cavern(private val octopi: Array<IntArray>) {
constructor(lines: List<String>) :
this(lines.map { it.map { c -> c.digitToInt() }.toIntArray() }.toTypedArray())
fun step(): Pair<Cavern, Int> {
val incremented = Array(10) { IntArray(10) }
val flashSpots = Li... | 0 | Kotlin | 0 | 0 | 6d4f19df3b7cb1906052b80a4058fa394a12740f | 2,265 | AOC2021 | Apache License 2.0 |
src/day14/Day14.kt | idle-code | 572,642,410 | false | {"Kotlin": 79612} | package day14
import Position
import log
import logEnabled
import logln
import readInput
import kotlin.math.max
private const val DAY_NUMBER = 14
data class Line(val start: Position, val end: Position) {
init {
if (start >= end)
throw IllegalArgumentException("Start cannot be greater than end... | 0 | Kotlin | 0 | 0 | 1b261c399a0a84c333cf16f1031b4b1f18b651c7 | 5,608 | advent-of-code-2022 | Apache License 2.0 |
src/year2022/day06/Day.kt | tiagoabrito | 573,609,974 | false | {"Kotlin": 73752} | package year2022.day06
import readInput
fun main() {
fun distinctSequence(sequence: CharSequence, size: Int): Int {
return sequence.withIndex()
.windowed(size)
.first { it.map { it.value }.distinct().size == size }
.last().index + 1
}
fun part1(input: List<C... | 0 | Kotlin | 0 | 0 | 1f9becde3cbf5dcb345659a23cf9ff52718bbaf9 | 995 | adventOfCode | Apache License 2.0 |
src/main/kotlin/days/Day6.kt | hughjdavey | 433,597,582 | false | {"Kotlin": 53042} | package days
import java.math.BigInteger
class Day6 : Day(6) {
private val fish = inputString.split(",").map { it.replace(Regex("\\s+"), "").toInt() }
override fun partOne(): Any {
return slowWay(80)
}
override fun partTwo(): Any {
return fastWay(256)
}
private fun slowWay(... | 0 | Kotlin | 0 | 0 | a3c2fe866f6b1811782d774a4317457f0882f5ef | 1,435 | aoc-2021 | Creative Commons Zero v1.0 Universal |
calendar/day07/Day7.kt | rocketraman | 573,845,375 | false | {"Kotlin": 45660} | package day07
import Day
import Lines
class Day7 : Day() {
override fun part1(input: Lines): Any {
return populateRoot(input)
.walk()
.filter { it.size() <= 100_000 }
.sumOf { it.size() }
}
override fun part2(input: Lines): Any {
val rootDirectory = populateRoot(input)
val total =... | 0 | Kotlin | 0 | 0 | 6bcce7614776a081179dcded7c7a1dcb17b8d212 | 2,191 | adventofcode-2022 | Apache License 2.0 |
src/main/kotlin/sschr15/aocsolutions/Day3.kt | sschr15 | 317,887,086 | false | {"Kotlin": 184127, "TeX": 2614, "Python": 446} | package sschr15.aocsolutions
import sschr15.aocsolutions.util.*
import sschr15.aocsolutions.util.watched.WatchedInt
import sschr15.aocsolutions.util.watched.product
import sschr15.aocsolutions.util.watched.sum
import sschr15.aocsolutions.util.watched.toLong
/**
* AOC 2023 [Day 3](https://adventofcode.com/2023/day/3)... | 0 | Kotlin | 0 | 0 | e483b02037ae5f025fc34367cb477fabe54a6578 | 2,134 | advent-of-code | MIT License |
solution/kotlin/aoc/src/main/kotlin/codes/jakob/aoc/Day10.kt | loehnertz | 573,145,141 | false | {"Kotlin": 53239} | package codes.jakob.aoc
import codes.jakob.aoc.Day10.Instruction.Type.ADD_X
import codes.jakob.aoc.Day10.Instruction.Type.NOOP
import codes.jakob.aoc.shared.splitMultiline
class Day10 : Solution() {
override fun solvePart1(input: String): Any {
var cycle = 1
var x = 1
val instructions: Lis... | 0 | Kotlin | 0 | 0 | ddad8456dc697c0ca67255a26c34c1a004ac5039 | 1,779 | advent-of-code-2022 | MIT License |
lib/src/main/kotlin/aoc/day02/Day02.kt | Denaun | 636,769,784 | false | null | package aoc.day02
enum class Result(val score: Int) { LOSS(0), DRAW(3), WIN(6) }
enum class Shape(val score: Int) {
ROCK(1) {
override fun shapeForResult(result: Result) = when (result) {
Result.WIN -> PAPER
Result.DRAW -> this
Result.LOSS -> SCISSORS
}
},
... | 0 | Kotlin | 0 | 0 | 560f6e33f8ca46e631879297fadc0bc884ac5620 | 1,639 | aoc-2022 | Apache License 2.0 |
src/Day01.kt | jalex19100 | 574,686,993 | false | {"Kotlin": 19795} | fun main() {
fun part1(input: List<String>): Int {
var max = 0
var sum = 0
input.forEach { it ->
if (it.isNotBlank()) {
sum += it.toInt()
} else {
if (sum > max) {
max = sum
}
sum = 0
... | 0 | Kotlin | 0 | 0 | a50639447a2ef3f6fc9548f0d89cc643266c1b74 | 1,160 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/Day02.kt | romainbsl | 572,718,344 | false | {"Kotlin": 17019} | fun main() {
fun part1(input: List<String>): Int {
return input
.map {
val (left, right) = it.split(" ")
Shape.from(left) to Shape.from(right)
}
.fold(0) { score, round ->
val (elf, me) = round
val outcome = ... | 0 | Kotlin | 0 | 0 | b72036968769fc67c222a66b97a11abfd610f6ce | 3,113 | advent-of-code-kotlin-2022 | Apache License 2.0 |
2021/src/main/kotlin/day6_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.mergeToMap
import utils.withLCounts
fun main() {
Day6Func.run()
}
object Day6Func : Solution<Map<Int, Long>>() {
override val name = "day6"
override val parser = Parser.ints.map { it.withLCounts() }
override fun part1(input: Map<Int, Long>): Long {
r... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 1,093 | aoc_kotlin | MIT License |
src/Day03.kt | Aldas25 | 572,846,570 | false | {"Kotlin": 106964} | fun main() {
fun priority(c: Char): Int {
if (c in 'a'..'z')
return (c - 'a' + 1)
return (c - 'A' + 27)
}
fun part1(input: List<String>): Int {
var ans = 0
for (s in input) {
var firstHalf: Set<Char> = emptySet<Char>()
val sz = s.length
... | 0 | Kotlin | 0 | 0 | 80785e323369b204c1057f49f5162b8017adb55a | 1,254 | Advent-of-Code-2022 | Apache License 2.0 |
src/main/kotlin/dk/lessor/Day21.kt | aoc-team-1 | 317,571,356 | false | {"Java": 70687, "Kotlin": 34171} | package dk.lessor
fun main() {
val lines = readFile("day_21.txt").map {
val (ingredients, allergies) = it.split(" (contains ")
ingredients.split(" ") to allergies.dropLast(1).split(", ")
}
val translations = identifyAllergyTranslations(lines)
val count = lines.flatMap { it.first }.filt... | 0 | Java | 0 | 0 | 48ea750b60a6a2a92f9048c04971b1dc340780d5 | 1,217 | lessor-aoc-comp-2020 | MIT License |
src/day22/Day22.kt | Oktosha | 573,139,677 | false | {"Kotlin": 110908} | package day22
import readInput
typealias FlatRepresentation = List<String>
data class Position(val row: Int, val column: Int) {
operator fun plus(other: Position): Position {
return Position(row + other.row, column + other.column)
}
operator fun minus(other: Position): Position {
return P... | 0 | Kotlin | 0 | 0 | e53eea61440f7de4f2284eb811d355f2f4a25f8c | 15,760 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day7.kt | Walop | 573,012,840 | false | {"Kotlin": 53630} | import java.io.InputStream
interface IFile {
val name: String
val size: Int
}
data class File(override val name: String, override val size: Int) : IFile
data class Directory(
override val name: String,
override var size: Int,
val children: MutableList<IFile>,
val parent: Directory?,
) : I... | 0 | Kotlin | 0 | 0 | 7a13f6500da8cb2240972fbea780c0d8e0fde910 | 4,521 | AdventOfCode2022 | The Unlicense |
src/main/kotlin/com/ginsberg/advent2022/Day22.kt | tginsberg | 568,158,721 | false | {"Kotlin": 113322} | /*
* Copyright (c) 2022 by <NAME>
*/
/**
* Advent of Code 2022, Day 22 - Monkey Map
* Problem Description: http://adventofcode.com/2022/day/22
* Blog Post/Commentary: https://todd.ginsberg.com/post/advent-of-code/2022/day22/
*/
package com.ginsberg.advent2022
class Day22(input: List<String>) {
private val ... | 0 | Kotlin | 2 | 26 | 2cd87bdb95b431e2c358ffaac65b472ab756515e | 13,145 | advent-2022-kotlin | Apache License 2.0 |
src/Day21.kt | l8nite | 573,298,097 | false | {"Kotlin": 105683} | class BetterMonkey(val id: String, var leftMonkey: BetterMonkey? = null, var operator: String? = null, var rightMonkey: BetterMonkey? = null, var result: Long? = null) {
var isHuman: Boolean = false
init {
if (id == "humn") { isHuman = true }
}
override fun toString(): String {
return ... | 0 | Kotlin | 0 | 0 | f74331778fdd5a563ee43cf7fff042e69de72272 | 5,082 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/Day15.kt | clechasseur | 258,279,622 | false | null | import org.clechasseur.adventofcode2019.Day15Data
import org.clechasseur.adventofcode2019.IntcodeComputer
import org.clechasseur.adventofcode2019.Pt
import org.clechasseur.adventofcode2019.dij.Dijkstra
import org.clechasseur.adventofcode2019.dij.Graph
import org.clechasseur.adventofcode2019.manhattan
object Day15 {
... | 0 | Kotlin | 0 | 0 | 187acc910eccb7dcb97ff534e5f93786f0341818 | 2,586 | adventofcode2019 | MIT License |
src/main/kotlin/Day25.kt | N-Silbernagel | 573,145,327 | false | {"Kotlin": 118156} | import kotlin.math.pow
fun main() {
val input = readFileAsList("Day25")
println(Day25.part1(input))
println(Day25.part2(input))
}
object Day25 {
val charNumberMap = mapOf(
'=' to -2,
'-' to -1,
'0' to 0,
'1' to 1,
'2' to 2,
)
fun part1(input: List<Strin... | 0 | Kotlin | 0 | 0 | b0d61ba950a4278a69ac1751d33bdc1263233d81 | 1,168 | advent-of-code-2022 | Apache License 2.0 |
advent-of-code-2022/src/test/kotlin/Day 7 No Space Left On Device.kt | yuriykulikov | 159,951,728 | false | {"Kotlin": 1666784, "Rust": 33275} | import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
class `Day 7 No Space Left On Device` {
data class ElfFile(
val name: String,
val parent: ElfFile? = null,
val size: Int = 0,
val contents: MutableList<ElfFile> = mutableListOf(),
) {
val totalSize: Int by lazy { size ... | 0 | Kotlin | 0 | 1 | f5efe2f0b6b09b0e41045dc7fda3a7565cb21db3 | 2,305 | advent-of-code | MIT License |
src/main/kotlin/aoc23/Day07.kt | tahlers | 725,424,936 | false | {"Kotlin": 65626} | package aoc23
object Day07 {
enum class Card {
JOKER, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE,
}
enum class HandType {
HIGH_CARD, ONE_PAIR, TWO_PAIR, THREE_OF_A_KIND, FULL_HOUSE, FOUR_OF_A_KIND, FIVE_OF_A_KIND
}
data class Hand(val cards: List... | 0 | Kotlin | 0 | 0 | 0cd9676a7d1fec01858ede1ab0adf254d17380b0 | 4,032 | advent-of-code-23 | Apache License 2.0 |
Kotlin for Java Developers. Week 5/Games/Task/src/games/gameOfFifteen/GameOfFifteenHelper.kt | Anna-Sentyakova | 186,426,055 | false | null | package games.gameOfFifteen
/*
* This function should return the parity of the permutation.
* true - the permutation is even
* false - the permutation is odd
* https://en.wikipedia.org/wiki/Parity_of_a_permutation
* If the game of fifteen is started with the wrong parity, you can't get the correct result
* (n... | 0 | Kotlin | 0 | 1 | e5db4940fa844aa8a5de7f90dd872909a06756e6 | 1,297 | coursera | Apache License 2.0 |
AdventOfCodeDay08/src/nativeMain/kotlin/Day08.kt | bdlepla | 451,510,571 | false | {"Kotlin": 165771} | class Day08(private val lines:List<String>) {
fun solvePart1() =
//.onEach{println(it.second)}
//.onEach{println(it)}
dataFromLines(lines)
.flatMap { it.second.trim().split(" ") }
.count { it.length in setOf(2, 3, 4, 7) }
fun solvePart2():Int = dataFromLines(lines).s... | 0 | Kotlin | 0 | 0 | 1d60a1b3d0d60e0b3565263ca8d3bd5c229e2871 | 3,774 | AdventOfCode2021 | The Unlicense |
advent/src/test/kotlin/org/elwaxoro/advent/y2021/Dec10.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2021
import org.elwaxoro.advent.PuzzleDayTester
/**
* Syntax Scoring
*/
class Dec10 : PuzzleDayTester(10, 2021) {
override fun part1(): Any = parse().mapNotNull { line ->
line.analyze(scoreCorrupt = true)
}.sum()
override fun part2(): Any = parse().mapNotNull { lin... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 2,075 | advent-of-code | MIT License |
src/main/kotlin/de/jball/aoc2022/day03/Day03.kt | fibsifan | 573,189,295 | false | {"Kotlin": 43681} | package de.jball.aoc2022.day03
import de.jball.aoc2022.Day
class Day03(test: Boolean = false) : Day<Long>(test, 157, 70) {
private val letterMapping = (
('a'..'z').zip(1L..26L) +
('A'..'Z').zip(27L..52L))
.toMap()
private val rucksacks = input
.map { it.toCharArray().toLis... | 0 | Kotlin | 0 | 3 | a6d01b73aca9b54add4546664831baf889e064fb | 1,136 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/Day10.kt | SimonMarquis | 434,880,335 | false | {"Kotlin": 38178} | class Day10(raw: List<String>) {
private val input: List<String> = raw.map { it.solve() }
fun part1() = input.filter {
it.any { c -> c in CTRL.keys }
}.sumOf {
it.first { c -> c in CTRL.keys }.toInvalidScore()
}
fun part2() = input.filter {
it.none { c -> c in CTRL.keys }
... | 0 | Kotlin | 0 | 0 | 8fd1d7aa27f92ba352e057721af8bbb58b8a40ea | 1,393 | advent-of-code-2021 | Apache License 2.0 |
src/main/kotlin/com/chriswk/aoc/advent2020/Day24.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2020
import com.chriswk.aoc.AdventDay
import com.chriswk.aoc.util.HexDirection
import com.chriswk.aoc.util.Point2D
import com.chriswk.aoc.util.Point3D
import com.chriswk.aoc.util.report
class Day24: AdventDay(2020, 24) {
companion object {
@JvmStatic
fun main(args: Ar... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 3,555 | adventofcode | MIT License |
src/Day21.kt | jinie | 572,223,871 | false | {"Kotlin": 76283} | /*
Solution from https://todd.ginsberg.com/post/advent-of-code/2022/day21/
*/
class Day21(input: List<String>) {
private val monkeys: Set<Monkey> = parseInput(input)
private val root: Monkey = monkeys.first { it.name == "root" }
fun solvePart1(): Long =
root.yell()
fun solvePart2(): Long =
... | 0 | Kotlin | 0 | 0 | 4b994515004705505ac63152835249b4bc7b601a | 4,104 | aoc-22-kotlin | Apache License 2.0 |
2018/kotlin/day4p1/src/kotlin/main.kt | sgravrock | 47,810,570 | false | {"Rust": 1263100, "Swift": 1167766, "Ruby": 641843, "C++": 529504, "Kotlin": 466600, "Haskell": 339813, "Racket": 264679, "HTML": 200276, "OpenEdge ABL": 165979, "C": 89974, "Objective-C": 50086, "JavaScript": 40960, "Shell": 33315, "Python": 29781, "Elm": 22980, "Perl": 10662, "BASIC": 9264, "Io": 8122, "Awk": 5701, "... | import java.lang.Exception
import java.util.*
fun main(args: Array<String>) {
val start = Date()
val classLoader = Time::class.java.classLoader
val input = classLoader.getResource("input.txt").readText()
println(puzzleSolution(parseInput(input)))
println("in ${Date().time - start.time}ms")
}
data ... | 0 | Rust | 0 | 0 | ea44adeb128cf1e3b29a2f0c8a12f37bb6d19bf3 | 2,872 | adventofcode | MIT License |
src/iii_conventions/MyDate.kt | michaelsergio | 92,528,745 | false | null | package iii_conventions
data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int)
operator fun MyDate.rangeTo(other: MyDate): DateRange = DateRange(this, other)
operator fun MyDate.compareTo(other: MyDate): Int {
if (this.year < other.year) return -1
else if (this.year > other.year) return 1
... | 0 | Kotlin | 0 | 0 | 558455d39da4a680c4ce9980a27b51963966fc99 | 2,126 | kotlinkoans | MIT License |
src/main/kotlin/Problem25.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | import kotlin.math.max
/**
* 1000-digit Fibonacci number
*
* The Fibonacci sequence is defined by the recurrence relation:
* Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
* Hence the first 12 terms will be:
* F1 = 1
* F2 = 1
* F3 = 2
* F4 = 3
* F5 = 5
* F6 = 8
* F7 = 13... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 1,619 | project-euler | MIT License |
src/Day11.kt | wbars | 576,906,839 | false | {"Kotlin": 32565} | import java.math.BigInteger
class Monkey(var items: ArrayDeque<Long>, val test: Int, val trueMonkey: Int, val falseMonkey: Int, val operation: (Long) -> Long)
fun main() {
fun part1(input: List<String>): Int {
val monkeys = listOf(
Monkey(ArrayDeque(listOf(53, 89, 62, 57, 74, 51, 83, 97)), ... | 0 | Kotlin | 0 | 0 | 344961d40f7fc1bb4e57f472c1f6c23dd29cb23f | 3,137 | advent-of-code-2022 | Apache License 2.0 |
src/Day01.kt | zsmb13 | 572,719,881 | false | {"Kotlin": 32865} | import java.util.TreeSet
fun main() {
fun part1(input: List<String>): Int {
var max = 0
var sum = 0
fun checkAndUpdate() {
if (sum > max) {
max = sum
}
sum = 0
}
for (line in input) {
if (line.isEmpty()) {
... | 0 | Kotlin | 0 | 6 | 32f79b3998d4dfeb4d5ea59f1f7f40f7bf0c1f35 | 1,431 | advent-of-code-2022 | Apache License 2.0 |
kotlin/src/main/kotlin/dev/egonr/leetcode/04_MedianTwoSortedArrays.kt | egon-r | 575,970,173 | false | null | package dev.egonr.leetcode
/* Hard
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
Median: The middle number; found by ordering all data points and picking out the one in the middle
(or if there are two middle numbers, taking the mean of those two numb... | 0 | Kotlin | 0 | 0 | b9c59e54ca2d1399d34d1ee844e03c16a580cbcb | 1,570 | leetcode | The Unlicense |
src/main/kotlin/aoc22/Day07.kt | asmundh | 573,096,020 | false | {"Kotlin": 56155} | package aoc22
import readInput
fun Char.parseToCommand(): String {
return when (this) {
'$' -> "Command"
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0' -> "File"
'd' -> "Directory"
else -> throw Exception("nei nei - $this")
}
}
fun Pair<Int, String>.cdToFolder(cdDestination:... | 0 | Kotlin | 0 | 0 | 7d0803d9b1d6b92212ee4cecb7b824514f597d09 | 6,532 | advent-of-code | Apache License 2.0 |
dataStructuresAndAlgorithms/src/main/java/dev/funkymuse/datastructuresandalgorithms/sort/HeapSort.kt | FunkyMuse | 168,687,007 | false | {"Kotlin": 1728251} | package dev.funkymuse.datastructuresandalgorithms.sort
import dev.funkymuse.datastructuresandalgorithms.swap
import dev.funkymuse.datastructuresandalgorithms.swapAt
/**
Inventor: <NAME>
Worst complexity: n*log(n)
Average complexity: n*log(n)
Best complexity: n*log(n)
Space complexity: 1
*/
private fun <T : Compa... | 0 | Kotlin | 92 | 771 | e2afb0cc98c92c80ddf2ec1c073d7ae4ecfcb6e1 | 2,321 | KAHelpers | MIT License |
solutions/aockt/y2021/Y2021D03.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2021
import io.github.jadarma.aockt.core.Solution
object Y2021D03 : Solution {
/**
* Given a list of numbers, generates a mask number based on the [predicate].
* @param mask The mask of relevant bits to keep. Should always be 2^n - 1, where n is the numbers of bits in use.
* @param ... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 3,936 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/solutions/Day2RockPaperScissors.kt | aormsby | 571,002,889 | false | {"Kotlin": 80084} | package solutions
import utils.Input
import utils.Solution
// run only this day
fun main() {
Day2RockPaperScissors()
}
class Day2RockPaperScissors : Solution() {
private val diff = 'X' - 'A'
private val win = 'w'
private val loss = 'l'
private val draw = 'd'
private val points = mapOf(
... | 0 | Kotlin | 0 | 0 | 1bef4812a65396c5768f12c442d73160c9cfa189 | 2,033 | advent-of-code-2022 | MIT License |
src/day/_7/Day07.kt | Tchorzyksen37 | 572,924,533 | false | {"Kotlin": 42709} | package day._7
import java.io.File
fun main() {
data class File(val name: String, val size: Long) {
}
data class Directory(
val name: String,
val parentDirectory: Directory?
) {
var totalSize: Long? = null
var nestedDirectories: MutableSet<Directory> = mutableSetOf()
var files: MutableSet<File> = mut... | 0 | Kotlin | 0 | 0 | 27d4f1a6efee1c79d8ae601872cd3fa91145a3bd | 3,442 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ShoppingOffers.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 | 2,166 | kotlab | Apache License 2.0 |
13/part_two.kt | ivanilos | 433,620,308 | false | {"Kotlin": 97993} | import java.io.File
fun readInput() : Paper {
val lines = File("input.txt")
.readLines()
val dots = mutableListOf<Pair<Int, Int>>()
val instructions = mutableListOf<Pair<Char, Int>>()
parseInput(lines, dots, instructions)
return Paper(dots, instructions)
}
fun parseInput(inputLines : Lis... | 0 | Kotlin | 0 | 3 | a24b6f7e8968e513767dfd7e21b935f9fdfb6d72 | 2,627 | advent-of-code-2021 | MIT License |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions40.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
import com.qiaoyuang.algorithm.round0.PriorityQueue
import com.qiaoyuang.algorithm.round0.partition
fun test40() {
printResult(intArrayOf(5, 4, 1, 6, 2, 7, 3, 8), 4)
}
/**
* Questions40: Find the smallest k numbers in an IntArray
*/
private infix fun IntArray.findSmalles... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,490 | Algorithm | Apache License 2.0 |
src/Day22.kt | illarionov | 572,508,428 | false | {"Kotlin": 108577} | fun main() {
val testInput = readInput("Day22_test")
val input = readInput("Day22")
part1(testInput).also {
println("Part 1, test input: $it")
check(it == 6032)
}
part1(input).also {
println("Part 1, real input: $it")
check(it == 146092)
}
// part2(testInput... | 0 | Kotlin | 0 | 0 | 3c6bffd9ac60729f7e26c50f504fb4e08a395a97 | 16,159 | aoc22-kotlin | Apache License 2.0 |
src/Day07.kt | catcutecat | 572,816,768 | false | {"Kotlin": 53001} | import kotlin.system.measureTimeMillis
fun main() {
measureTimeMillis {
Day07.run {
solve1(95437) // 1749646
solve2(24933642) // 1498966
}
}.let { println("Total: $it ms") }
}
object Day07 : Day.LineInput<Day07.Directory, Int>("07") {
class Directory(
val p... | 0 | Kotlin | 0 | 2 | fd771ff0fddeb9dcd1f04611559c7f87ac048721 | 1,839 | AdventOfCode2022 | Apache License 2.0 |
calendar/day03/Day3.kt | divgup92 | 573,352,419 | false | {"Kotlin": 15497} | package day03
import Day
import Lines
import kotlin.streams.toList
class Day3 : Day() {
override fun part1(input: Lines): Any {
return input.stream().map { line -> getScore(line) }.toList().sum()
}
private fun getScore(input: String): Int {
val firstHalf = input.substring(0, input.length/... | 0 | Kotlin | 0 | 0 | dcd221197ecb374efa030a7993a0152099409f14 | 1,353 | advent-of-code-2022 | Apache License 2.0 |
src/Day09.kt | fmborghino | 573,233,162 | false | {"Kotlin": 60805} | import kotlin.math.absoluteValue
import kotlin.math.sign
fun main() {
@Suppress("unused")
fun log(message: Any?) {
println(message)
}
fun parse(input: List<String>): List<Pair<Int, Int>> {
val moves: MutableList<Pair<Int, Int>> = mutableListOf()
var x = 0
var y = 0
... | 0 | Kotlin | 0 | 0 | 893cab0651ca0bb3bc8108ec31974654600d2bf1 | 2,271 | aoc2022 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.