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/_2018/Day4.kt | thebrightspark | 227,161,060 | false | {"Kotlin": 548420} | package _2018
import aocRun
import format
import java.time.Duration
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.regex.Pattern
private val pattern = Pattern.compile("\\[(?<timestamp>[\\d-: ]+)]( Guard #(?<guardId>\\d+))?[ ]?(?<message>.*)")
private val dateFormat = DateTim... | 0 | Kotlin | 0 | 0 | ac62ce8aeaed065f8fbd11e30368bfe5d31b7033 | 43,059 | AdventOfCode | Creative Commons Zero v1.0 Universal |
src/main/kotlin/Day09.kt | AlmazKo | 576,500,782 | false | {"Kotlin": 26733} | import kotlin.math.abs
object Day09 : Task {
@JvmStatic
fun main(args: Array<String>) = execute(false)
override fun part1(input: Iterable<String>): Any {
val rope = Rope(2)
input.map(::parse).forEach(rope::move)
return rope.visited.size
}
override fun part2(input: Iterabl... | 0 | Kotlin | 0 | 1 | 109cb10927328ce296a6b0a3600edbc6e7f0dc9f | 2,861 | advent2022 | MIT License |
2015/src/main/kotlin/com/koenv/adventofcode/Day11.kt | koesie10 | 47,333,954 | false | null | package com.koenv.adventofcode
object Day11 {
public fun satisfiesRequirements(input: String): Boolean {
val satisfies1 = input.mapIndexed { i, c ->
if (i == 0 || i == 1) {
return@mapIndexed false
}
val previous1 = input[i - 2].toInt()
val pre... | 0 | Kotlin | 0 | 0 | 29f3d426cfceaa131371df09785fa6598405a55f | 1,859 | AdventOfCode-Solutions-Kotlin | MIT License |
src/day4/Day04.kt | dean95 | 571,923,107 | false | {"Kotlin": 21240} | package day4
import readInput
private fun main() {
fun part1(input: List<String>): Int {
var result = 0
input.forEach { line ->
val (range1, range2) = line.split(",").map {
val (s, e) = it.split("-")
s.toInt() to e.toInt()
}
val ... | 0 | Kotlin | 0 | 0 | 0ddf1bdaf9bcbb45116c70d7328b606c2a75e5a5 | 1,536 | advent-of-code-2022 | Apache License 2.0 |
src/Day13.kt | zt64 | 572,594,597 | false | null | import kotlin.math.min
private object Day13 : Day(13) {
private fun buildPacket(string: String) = buildList<Any> {
val stack = mutableListOf<MutableList<Any>>()
var tempNum = ""
string.forEach { char ->
if (char.isDigit()) {
tempNum += char.digitToInt()
... | 0 | Kotlin | 0 | 0 | 4e4e7ed23d665b33eb10be59670b38d6a5af485d | 2,721 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/AverageOfLevelsInBinaryTree.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 | 2,520 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/FruitIntoBaskets.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,951 | kotlab | Apache License 2.0 |
algorithms/src/main/kotlin/com/kotlinground/algorithms/twopointers/mergesortedarray/merge.kt | BrianLusina | 113,182,832 | false | {"Kotlin": 483489, "Shell": 7283, "Python": 1725} | package com.kotlinground.algorithms.twopointers.mergesortedarray
/**
* Uses a 2 pointer approach to merge to sorted arrays.
* The first pointer i points to the last element of the subarray of size m in the nums1 array,
* the second pointer j points to the last element of the nums2 array of size n.
* The pointer k ... | 1 | Kotlin | 1 | 0 | 5e3e45b84176ea2d9eb36f4f625de89d8685e000 | 1,145 | KotlinGround | MIT License |
src/main/kotlin/day5/Solution.kt | krazyglitch | 573,086,664 | false | {"Kotlin": 31494} | package day5
import util.Utils
import java.time.Duration
import java.time.LocalDateTime
import kotlin.collections.ArrayList
class Solution {
private val stacks = ArrayList<ArrayDeque<Char>>()
private val instructionRegex = Regex("move (\\d+) from (\\d) to (\\d)")
// Parse the crate diagram and return on... | 0 | Kotlin | 0 | 0 | db6b25f7668532f24d2737bc680feffc71342491 | 3,604 | advent-of-code2022 | MIT License |
src/commonMain/kotlin/advent2020/day08/Day08Puzzle.kt | jakubgwozdz | 312,526,719 | false | null | package advent2020.day08
import advent2020.day08.OpCode.*
import advent2020.utils.binaryInsert
val regex by lazy { """(nop|acc|jmp) ([+\-])(\d+)""".toRegex() }
enum class OpCode { nop, acc, jmp, }
data class Instruction(val opCode: OpCode, val argument: Int)
private fun program(input: String): List<Instruction> = i... | 0 | Kotlin | 0 | 2 | e233824109515fc4a667ad03e32de630d936838e | 2,142 | advent-of-code-2020 | MIT License |
src/main/kotlin/dayTwo/DayTwo.kt | janreppien | 573,041,132 | false | {"Kotlin": 26432} | package dayTwo
import AocSolution
import java.io.File
class DayTwo : AocSolution(2) {
private val input = readInput()
private fun readInput(): MutableList<List<Int>> {
val inputs = mutableListOf<List<Int>>()
val file = File("src/main/resources/inputs/dayTwo/input.txt")
file.forEachL... | 0 | Kotlin | 0 | 0 | b53f6c253966536a3edc8897d1420a5ceed59aa9 | 2,039 | aoc2022 | MIT License |
src/main/kotlin/utilities/MathSample.kt | kirimin | 197,707,422 | false | null | package utilities
import java.math.BigDecimal
import java.math.MathContext
import java.util.*
import kotlin.math.pow
object MathSample {
/***
* 10^9 + 7
*/
val mod: Long = (Math.pow(10.0, 9.0) + 7).toLong()
/**
* Doubleを使わないpow
*/
fun longPow(a: Long, b: Long): Long {
var... | 0 | Kotlin | 1 | 5 | 23c9b35da486d98ab80cc56fad9adf609c41a446 | 11,106 | AtCoderLog | The Unlicense |
src/Day10.kt | jmorozov | 573,077,620 | false | {"Kotlin": 31919} | fun main() {
val inputData = readInput("Day10")
part1(inputData)
part2(inputData)
}
private fun part1(inputData: List<String>) {
var cycleCounter = 0
var cycleStrengthCounter = FIRST_STRENGTH_MARK
var x = 1
var signalStrength = 0
for (line in inputData) {
val command = line.trim... | 0 | Kotlin | 0 | 0 | 480a98838949dbc7b5b7e84acf24f30db644f7b7 | 3,258 | aoc-2022-in-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/BrickWall.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,294 | kotlab | Apache License 2.0 |
src/Day17.kt | asm0dey | 572,860,747 | false | {"Kotlin": 61384} | val HashSet<Point17>.top
get() = if (isEmpty()) -1 else maxOf(Point17::y)
fun main() {
fun windVector(wind: Iterator<Char>): Point17 {
val windVector = when (wind.next()) {
'>' -> Point17(1, 0)
'<' -> Point17(-1, 0)
else -> error("Unsupported wind speed")
}... | 1 | Kotlin | 0 | 1 | f49aea1755c8b2d479d730d9653603421c355b60 | 6,480 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/me/peckb/aoc/_2023/calendar/day22/Day22.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2023.calendar.day22
import javax.inject.Inject
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
class Day22 @Inject constructor(
private val generatorFactory: InputGeneratorFactory,
) {
fun partOne(filename: String) = generatorFactory.forFile(filename).readAs(::brick) { i... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 2,746 | advent-of-code | MIT License |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2022/2022-20.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2022
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputLines
import java.util.LinkedList
fun main() {
val input = readInputLines(2022, "20-input")
val testInput1 = readInputLines(2022, "20-test1")
println("Part1:")... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,358 | advent-of-code | MIT License |
src/day10/day10.kt | kacperhreniak | 572,835,614 | false | {"Kotlin": 85244} | package day10
import readInput
const val NEXT_CHECK = 40
const val LIT_PIXEL = '#'
const val DARK_PIXEL = '.'
private fun getParams(line: String): Pair<Int, Int> {
val parts = line.split(" ")
val instruction = parts[0]
val cycles = when (instruction) {
"noop" -> 1
"addx" -> 2
els... | 0 | Kotlin | 1 | 0 | 03368ffeffa7690677c3099ec84f1c512e2f96eb | 1,491 | aoc-2022 | Apache License 2.0 |
Minimum_Size_Subarray_Sum_v2.kt | xiekch | 166,329,519 | false | {"C++": 165148, "Java": 103273, "Kotlin": 97031, "Go": 40017, "Python": 22302, "TypeScript": 17514, "Swift": 6748, "Rust": 6579, "JavaScript": 4244, "Makefile": 349} | // Given an array of n positive integers and a positive integer s, find the minimal
// length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.
// two points
class Solution {
fun minSubArrayLen(s: Int, nums: IntArray): Int {
if (nums.isEmpty()) return 0
var res =... | 0 | C++ | 0 | 0 | eb5b6814e8ba0847f0b36aec9ab63bcf1bbbc134 | 1,026 | leetcode | MIT License |
aoc2023/src/main/kotlin/de/havox_design/aoc2023/day16/TheFloorWillBeLava.kt | Gentleman1983 | 737,309,232 | false | {"Kotlin": 746488, "Java": 441473, "Scala": 33415, "Groovy": 5725, "Python": 3319} | package de.havox_design.aoc2023.day16
import de.havox_design.aoc.utils.kotlin.model.directions.GeoDirection
import de.havox_design.aoc.utils.kotlin.model.positions.Position2d
class TheFloorWillBeLava(private var filename: String) {
fun solvePart1(): Long =
getEnergy(parseTiles(getResourceAsText(filename))... | 4 | Kotlin | 0 | 1 | 35ce3f13415f6bb515bd510a1f540ebd0c3afb04 | 4,617 | advent-of-code | Apache License 2.0 |
src/main/kotlin/no/uib/inf273/extra/IntArray_.kt | elgbar | 237,403,030 | false | {"Kotlin": 141160} | package no.uib.inf273.extra
import no.uib.inf273.Main
import kotlin.random.Random
/**
* Exchange the elements at the two given indices.
*/
fun IntArray.exchange(first: Int, second: Int) {
//we don't change the array so do nothing
if (first != second) {
//swap the two elements, yes this is kotlin ma... | 0 | Kotlin | 0 | 3 | 1f76550a631527713b1eba22817e6c1215f5d84e | 3,441 | INF273 | The Unlicense |
src/Day01.kt | tblechmann | 574,236,696 | false | {"Kotlin": 5756} | fun main() {
fun part1(input: List<String>): Int {
val values = arrayListOf<Int>(0)
input.forEach {
if (it.isEmpty()) {
values.add(0)
} else {
values[values.lastIndex] = values.last() + Integer.parseInt(it)
}
}
ret... | 0 | Kotlin | 0 | 0 | 4a65f6468a0cddd8081f2f0e3c1a96935438755f | 976 | aoc2022 | Apache License 2.0 |
src/main/kotlin/me/giacomozama/adventofcode2022/days/Day16.kt | giacomozama | 572,965,253 | false | {"Kotlin": 75671} | package me.giacomozama.adventofcode2022.days
import java.io.File
class Day16 : Day() {
private lateinit var inputFlowRates: IntArray
private lateinit var inputGraph: Array<IntArray>
override fun parseInput(inputFile: File) {
val inputLines = inputFile.readLines()
var lastIndex = 0
... | 0 | Kotlin | 0 | 0 | c30f4a37dc9911f3e42bbf5088fe246aabbee239 | 6,056 | aoc2022 | MIT License |
codeforces/kotlinheroes3/f.kt | mikhail-dvorkin | 93,438,157 | false | {"Java": 2219540, "Kotlin": 615766, "Haskell": 393104, "Python": 103162, "Shell": 4295, "Batchfile": 408} | package codeforces.kotlinheroes3
private fun solve() {
val (n, m) = readInts()
data class Segment(val start: Int, val end: Int, val id: Int)
val segments = List(n) { val data = readInts(); Segment(data[0], data[1], it) }
val byOpening = segments.sortedByDescending { it.start }.toMutableList()
val ans = MutableLis... | 0 | Java | 1 | 9 | 30953122834fcaee817fe21fb108a374946f8c7c | 1,072 | competitions | The Unlicense |
solver/src/commonMain/kotlin/org/hildan/sudoku/solver/techniques/HiddenTuples.kt | joffrey-bion | 9,559,943 | false | {"Kotlin": 51198, "HTML": 187} | package org.hildan.sudoku.solver.techniques
import org.hildan.sudoku.model.*
/**
* Trivially sets the digit in a cell when this is the only cell of the unit with this candidate.
*/
object HiddenSingles : Technique {
override fun attemptOn(grid: Grid): List<HiddenSinglesStep> {
val actions = grid.units.... | 0 | Kotlin | 0 | 0 | 441fbb345afe89b28df9fe589944f40dbaccaec5 | 4,323 | sudoku-solver | MIT License |
src/Day13.kt | IvanChadin | 576,061,081 | false | {"Kotlin": 26282} | fun main() {
val inputName = "Day13_test"
fun parseLine(s: String): ArrayList<Any> {
val list = ArrayList<Any>()
val stack = ArrayDeque<ArrayList<Any>>()
stack.addLast(list)
val numBuilder = StringBuilder()
for (c in s) {
when (c) {
'[' -> {
... | 0 | Kotlin | 0 | 0 | 2241437e6c3a20de70306a0cb37b6fe2ed8f9e3a | 3,429 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/leetcode/kotlin/unionfind/200. Number of Islands.kt | sandeep549 | 251,593,168 | false | null | package leetcode.kotlin.unionfind
private fun numIslands(grid: Array<CharArray>): Int {
var seen = mutableSetOf<Pair<Int, Int>>()
fun dfs(r: Int, c: Int): Boolean {
if (r < 0 || r >= grid.size || c < 0 || c >= grid[0].size) return false
if (grid[r][c] == '0' || seen.contains(Pair(r, c))) return... | 0 | Kotlin | 0 | 0 | 9cf6b013e21d0874ec9a6ffed4ae47d71b0b6c7b | 1,265 | kotlinmaster | Apache License 2.0 |
2023/kotlin/1.kt | maquirag | 723,632,326 | false | {"Kotlin": 1261} | // Advent of Code 2023, Day 1
fun Boolean.toInt() = if (this) 1 else 0
fun main() {
getTestsPart1()
.map(::findDigits)
.map { it.first() * 10 + it.last() }
.sum()
.also(::println)
getTestsPart2()
.map(::findNumbers)
.map { it.first() * 10 + it.last() }
.... | 0 | Kotlin | 0 | 1 | 297f806990ee83233fda82f7d2b2d7d332611734 | 1,261 | aoc | The Unlicense |
src/main/kotlin/com/hj/leetcode/kotlin/problem2231/Solution.kt | hj-core | 534,054,064 | false | {"Kotlin": 619841} | package com.hj.leetcode.kotlin.problem2231
/**
* LeetCode page: [2231. Largest Number After Digit Swaps by Parity](https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity/);
*/
class Solution {
/* Complexity:
* Time O(NLogN) and Space O(N) where N is the number of digits that num has;
... | 1 | Kotlin | 0 | 1 | 14c033f2bf43d1c4148633a222c133d76986029c | 1,637 | hj-leetcode-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/DiagonalTraverse2.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,713 | kotlab | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LongestArithmeticSubsequence.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,422 | kotlab | Apache License 2.0 |
src/Day11.kt | RandomUserIK | 572,624,698 | false | {"Kotlin": 21278} | import java.io.File
private const val WORRY_LEVEL_DIVISOR = 3
private const val TOP_ACTIVE_MONKEYS = 2
private data class InspectAndPlayResult(
val worryLevel: Long,
val throwTo: Int,
)
private data class Monkey(
val index: Int,
val items: MutableList<Long> = mutableListOf(),
val inspectOperation: (Long) -> Lon... | 0 | Kotlin | 0 | 0 | f22f10da922832d78dd444b5c9cc08fadc566b4b | 2,947 | advent-of-code-2022 | Apache License 2.0 |
p04/src/main/kotlin/ReposeRecord.kt | jcavanagh | 159,918,838 | false | null | package p04
import common.file.readLines
import java.text.SimpleDateFormat
import java.util.*
enum class GuardEventType(val value: String) {
BEGIN_SHIFT("begins shift"),
FALL_ASLEEP("falls asleep"),
WAKE_UP("wakes up");
companion object {
fun from(search: String): GuardEventType = requireNotNull(values()... | 0 | Kotlin | 0 | 0 | 289511d067492de1ad0ceb7aa91d0ef7b07163c0 | 3,624 | advent2018 | MIT License |
Problems/Algorithms/410. Split Array Largest Sum/SplitArrayLargestSum1.kt | xuedong | 189,745,542 | false | {"Kotlin": 332182, "Java": 294218, "Python": 237866, "C++": 97190, "Rust": 82753, "Go": 37320, "JavaScript": 12030, "Ruby": 3367, "C": 3121, "C#": 3117, "Swift": 2876, "Scala": 2868, "TypeScript": 2134, "Shell": 149, "Elixir": 130, "Racket": 107, "Erlang": 96, "Dart": 65} | class Solution {
private val results = Array(1001) { IntArray(51) }
fun splitArray(nums: IntArray, m: Int): Int {
val n = nums.size
val prefix = IntArray(n+1)
for (i in 0..n-1) {
prefix[i+1] = prefix[i] + nums[i]
}
return getMinMax(prefi... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 1,103 | leet-code | MIT License |
src/main/kotlin/Day23.kt | Yeah69 | 317,335,309 | false | {"Kotlin": 73241} | class Day23 : Day() {
override val label: String get() = "23"
private val initialCups by lazy { input.asSequence().mapNotNull { it.toString().toIntOrNull() }.toList() }
class Node(val value: Int) {
lateinit var next: Node
}
private fun circularlyLinkedCupsZero(): Triple<Node, Map<Int, Nod... | 0 | Kotlin | 0 | 0 | 23121ede8e3e8fc7aa1e8619b9ce425b9b2397ec | 2,884 | AdventOfCodeKotlin | The Unlicense |
src/main/kotlin/leetcode/advanceds/Trie1.kt | sandeep549 | 262,513,267 | false | {"Kotlin": 530613} | package leetcode.advanceds
/**
* A sample Trie to store only lower case alphabets.
*/
class Trie {
private val root = TrieNode()
/**
* Insert string into Trie.
*/
fun insert(str: String) {
var node: TrieNode = root
for (c in str) {
val index: Int = c - 'a' // index i... | 1 | Kotlin | 0 | 0 | cf357cdaaab2609de64a0e8ee9d9b5168c69ac12 | 2,485 | leetcode-kotlin | Apache License 2.0 |
src/com/ssynhtn/medium/Permutations.kt | ssynhtn | 295,075,844 | false | {"Java": 639777, "Kotlin": 34064} | package com.ssynhtn.medium
class Permutations {
var swapCount = 0;
fun permute(nums: IntArray): List<List<Int>> {
val collect = mutableListOf<List<Int>>()
permute(nums, 0, collect)
return collect
}
fun permute2(nums: IntArray): List<List<Int>> {
val collect = mutableLis... | 0 | Java | 0 | 0 | 511f65845097782127bae825b07a51fe9921c561 | 2,740 | leetcode | Apache License 2.0 |
src/main/java/challenges/cracking_coding_interview/moderate/q3_intersection/Question.kt | ShabanKamell | 342,007,920 | false | null | package challenges.cracking_coding_interview.moderate.q3_intersection
object Question {
/* Checks if middle is between start and end. */
fun isBetween(start: Double, middle: Double, end: Double): Boolean {
return if (start > end) {
end <= middle && middle <= start
} else {
... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 4,064 | CodingChallenges | Apache License 2.0 |
src/main/kotlin/com/github/davio/aoc/y2023/Day3.kt | Davio | 317,510,947 | false | {"Kotlin": 405939} | package com.github.davio.aoc.y2023
import com.github.davio.aoc.general.Day
import com.github.davio.aoc.general.Point
import com.github.davio.aoc.general.getInputAsMatrix
/**
* See [Advent of Code 2023 Day 3](https://adventofcode.com/2023/day/3#part2])
*/
object Day3 : Day() {
private val matrix = getInputAsMat... | 1 | Kotlin | 0 | 0 | 4fafd2b0a88f2f54aa478570301ed55f9649d8f3 | 2,264 | advent-of-code | MIT License |
advent/src/test/kotlin/org/elwaxoro/advent/y2021/Dec19.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2021
import org.elwaxoro.advent.Coord3D
import org.elwaxoro.advent.PuzzleDayTester
import org.elwaxoro.advent.Rotation4
/**
* Beacon Scanner
*/
class Dec19 : PuzzleDayTester(19, 2021) {
override fun part1(): Any = parse().alignTheScanners().map { it.beacons }.flatten().toSet().size... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 3,250 | advent-of-code | MIT License |
src/main/kotlin/org/rgoussey/aoc2023/day3/Main.kt | RobinGoussey | 727,877,956 | false | {"Kotlin": 5214} | package org.rgoussey.aoc2023.day3
import java.io.File
import kotlin.math.max
import kotlin.math.min
fun main() {
val lines = File({}.javaClass.getResource("/day3/input.txt")!!.toURI()).readLines();
process(lines);
}
fun process(lines: List<String>) {
val characters = mutableListOf<MutableList<Char>>()
... | 0 | Kotlin | 0 | 0 | b1421c04b403755617684480a4ffabf14f125aeb | 3,652 | advent_of_code23 | Apache License 2.0 |
src/main/kotlin/arr/Median.kt | yx-z | 106,589,674 | false | null | package arr
import java.util.*
fun main(args: Array<String>) {
// given two sorted arrays (may be different length)
// get median of their merged sorted array
val test1 = intArrayOf(1, 3, 8)
val test2 = intArrayOf(2, 7, 9, 10)
println(Arrays.toString(test1))
println(Arrays.toString(test2))
// merge all and re... | 0 | Kotlin | 0 | 1 | 15494d3dba5e5aa825ffa760107d60c297fb5206 | 2,828 | AlgoKt | MIT License |
src/Day24.kt | abeltay | 572,984,420 | false | {"Kotlin": 91982, "Shell": 191} | fun main() {
val right = 0
val down = 1
val left = 2
val up = 3
data class Blizzard(
var x: Int,
var y: Int,
val direction: Int
)
fun parseInput(input: List<String>): MutableList<Blizzard> {
val blizzard = mutableListOf<Blizzard>()
for (y in input.in... | 0 | Kotlin | 0 | 0 | a51bda36eaef85a8faa305a0441efaa745f6f399 | 4,168 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/RankTeams.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,055 | kotlab | Apache License 2.0 |
src/twentytwo/Day02.kt | mihainov | 573,105,304 | false | {"Kotlin": 42574} | package twentytwo
import readInputTwentyTwo
abstract class Shape {
abstract val score: Int
abstract fun fightWith(shape: Shape): Int
abstract fun lose(): Int
abstract fun draw(): Int
abstract fun win(): Int
companion object {
fun getItem(string: String): Shape {
return whe... | 0 | Kotlin | 0 | 0 | a9aae753cf97a8909656b6137918ed176a84765e | 3,148 | kotlin-aoc-1 | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year22/Day21.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year22
import com.grappenmaker.aoc.PuzzleSet
import kotlin.random.Random
fun PuzzleSet.day21() = puzzle {
val monkeys = inputLines.associate { line ->
val (name, job) = line.split(": ")
val sp = job.split(" ")
name to (job.toDoubleOrNull()?.let { NumberJob(it) ... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 1,903 | advent-of-code | The Unlicense |
src/main/kotlin/com/jaspervanmerle/aoc2021/day/Day21.kt | jmerle | 434,010,865 | false | {"Kotlin": 60581} | package com.jaspervanmerle.aoc2021.day
import kotlin.math.max
class Day21 : Day("888735", "647608359455719") {
private val startingPositionOne = input.lines()[0].split(" ").last().toInt()
private val startingPositionTwo = input.lines()[1].split(" ").last().toInt()
override fun solvePartOne(): Any {
... | 0 | Kotlin | 0 | 0 | dcac2ac9121f9bfacf07b160e8bd03a7c6732e4e | 2,376 | advent-of-code-2021 | MIT License |
src/main/kotlin/Day9.kt | ueneid | 575,213,613 | false | null | import kotlin.math.abs
import kotlin.math.sign
class Day9(inputs: List<String>) {
val commands = parse(inputs)
private fun parse(inputs: List<String>): List<Pair<String, Int>> {
return inputs.asSequence().map { line ->
val commands = line.split(" ")
Pair(commands[0], commands[1... | 0 | Kotlin | 0 | 0 | 743c0a7adadf2d4cae13a0e873a7df16ddd1577c | 4,017 | adventcode2022 | MIT License |
src/main/kotlin/info/jukov/adventofcode/y2021/Day8.kt | jukov | 572,271,165 | false | {"Kotlin": 78755} | package info.jukov.adventofcode.y2021
import info.jukov.adventofcode.Day
import java.io.BufferedReader
import kotlin.math.pow
object Day8 : Day() {
override val year: Int = 2021
override val day: Int = 8
override fun part1(reader: BufferedReader): String {
reader.useLines { lines ->
... | 0 | Kotlin | 1 | 0 | 5fbdaf39a508dec80e0aa0b87035984cfd8af1bb | 3,716 | AdventOfCode | The Unlicense |
leetcode2/src/leetcode/find-first-and-last-position-of-element-in-sorted-array.kt | hewking | 68,515,222 | false | null | package leetcode
/**
* 34. 在排序数组中查找元素的第一个和最后一个位置
* https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/
* @program: leetcode
* @description: ${description}
* @author: hewking
* @create: 2019-10-28 14:11
* 给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。
你的算法时间复杂度必须... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 2,391 | leetcode | MIT License |
src/main/kotlin/leetcode/Problem1824.kt | fredyw | 28,460,187 | false | {"Java": 1280840, "Rust": 363472, "Kotlin": 148898, "Shell": 604} | package leetcode
import kotlin.math.min
/**
* https://leetcode.com/problems/minimum-sideway-jumps/
*/
class Problem1824 {
fun minSideJumps(obstacles: IntArray): Int {
return minSideJumps(obstacles, lane = 2, index = 0,
memo = Array(obstacles.size) { IntArray(4) { -1 } })
}
private f... | 0 | Java | 1 | 4 | a59d77c4fd00674426a5f4f7b9b009d9b8321d6d | 1,206 | leetcode | MIT License |
src/main/kotlin/me/grison/aoc/y2022/Day17.kt | agrison | 315,292,447 | false | {"Kotlin": 267552} | package me.grison.aoc.y2022
import me.grison.aoc.*
class Day17 : Day(17, 2022) {
override fun title() = "Pyroclastic Flow"
override fun partOne() = solve(2022)
override fun partTwo() = solve(1_000_000_000_000L)
// all start at x = 2
private val ROCKS = listOf(
listOf(p(2L, 0), p(3L, 0),... | 0 | Kotlin | 3 | 18 | ea6899817458f7ee76d4ba24d36d33f8b58ce9e8 | 2,919 | advent-of-code | Creative Commons Zero v1.0 Universal |
src/problems/1805-numDifferentIntegers.kt | w1374720640 | 352,006,409 | false | null | package problems
/**
* 1805. 字符串中不同整数的数目 https://leetcode-cn.com/problems/number-of-different-integers-in-a-string/
*
* 解:遍历String,找到所有的数字,加入HashSet中,最后统计Set的大小就是不同整数的数量
* 需要注意数字可能超过Int的大小,可以用String(需要手动去除前导0)或BitInteger代替
*/
fun numDifferentIntegers(word: String): Int {
val set = HashSet<String>()
var i ... | 0 | Kotlin | 0 | 0 | 21c96a75d13030009943474e2495f1fc5a7716ad | 1,329 | LeetCode | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/MinimumSwap.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,240 | kotlab | Apache License 2.0 |
day02/part1.kts | bmatcuk | 726,103,418 | false | {"Kotlin": 214659} | // --- Day 2: Cube Conundrum ---
// You're launched high into the atmosphere! The apex of your trajectory just
// barely reaches the surface of a large island floating in the sky. You gently
// land in a fluffy pile of leaves. It's quite cold, but you don't see much
// snow. An Elf runs over to greet you.
//
// The Elf... | 0 | Kotlin | 0 | 0 | a01c9000fb4da1a0cd2ea1a225be28ab11849ee7 | 3,392 | adventofcode2023 | MIT License |
src/main/kotlin/days/Day7.kt | teunw | 573,164,590 | false | {"Kotlin": 20073} | package days
import kotlin.io.path.Path
class Day7 : Day(7) {
private fun getDirSizes(): Pair<MutableMap<String, Int>, List<Pair<String, Int>>> {
var files = mutableMapOf<String, Int>()
var dirs = mutableListOf<String>("/")
var currentDir = ""
var listingDirectory = false;
... | 0 | Kotlin | 0 | 0 | 149219285efdb1a4d2edc306cc449cce19250e85 | 2,211 | advent-of-code-22 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/ru/timakden/aoc/year2023/Day14.kt | timakden | 76,895,831 | false | {"Kotlin": 321649} | package ru.timakden.aoc.year2023
import ru.timakden.aoc.util.measure
import ru.timakden.aoc.util.readInput
import ru.timakden.aoc.year2023.Day14.Direction.*
/**
* [Day 14: Parabolic Reflector Dish](https://adventofcode.com/2023/day/14).
*/
object Day14 {
@JvmStatic
fun main(args: Array<String>) {
me... | 0 | Kotlin | 0 | 3 | acc4dceb69350c04f6ae42fc50315745f728cce1 | 3,920 | advent-of-code | MIT License |
src/main/kotlin/kr/co/programmers/P12952.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package kr.co.programmers
import kotlin.math.abs
// https://github.com/antop-dev/algorithm/issues/535
class P12952 {
fun solution(n: Int): Int {
return dfs(IntArray(n), 0)
}
private fun dfs(arr: IntArray, row: Int): Int {
if (row == arr.size) { // n번째 행까지 퀸을 다 놓았다.
return 1
... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,167 | algorithm | MIT License |
src/main/kotlin/com/github/ferinagy/adventOfCode/aoc2015/2015-11.kt | ferinagy | 432,170,488 | false | {"Kotlin": 787586} | package com.github.ferinagy.adventOfCode.aoc2015
import com.github.ferinagy.adventOfCode.println
import com.github.ferinagy.adventOfCode.readInputText
fun main() {
val input = readInputText(2015, "11-input")
val test1 = readInputText(2015, "11-test1")
println("Part1:")
part1(test1).println()
part... | 0 | Kotlin | 0 | 1 | f4890c25841c78784b308db0c814d88cf2de384b | 1,615 | advent-of-code | MIT License |
src/Day14.kt | anisch | 573,147,806 | false | {"Kotlin": 38951} | private typealias Cave = Array<Array<String>>
private fun Cave.isFreeDown(row: Int, col: Int) = this[row + 1][col] == "."
private fun Cave.isFreeLeftDown(row: Int, col: Int) = this[row + 1][col - 1] == "."
private fun Cave.isFreeRightDown(row: Int, col: Int) = this[row + 1][col + 1] == "."
private fun Cave.nextIsNotFr... | 0 | Kotlin | 0 | 0 | 4f45d264d578661957800cb01d63b6c7c00f97b1 | 4,676 | Advent-of-Code-2022 | Apache License 2.0 |
advent-of-code2015/src/main/kotlin/day4/Advent4.kt | REDNBLACK | 128,669,137 | false | null | package day4
import toHex
import toMD5
/**
--- Day 4: The Ideal Stocking Stuffer ---
Santa needs help mining some AdventCoins (very similar to bitcoins) to use as gifts for all the economically forward-thinking little girls and boys.
To do this, he needs to find MD5 hashes which, in hexadecimal, start with at least... | 0 | Kotlin | 0 | 0 | e282d1f0fd0b973e4b701c8c2af1dbf4f4a149c7 | 1,621 | courses | MIT License |
src/datastructure/graphs/RootenOranges.kt | minielectron | 332,678,510 | false | {"Java": 127791, "Kotlin": 48336} | package datastructure.graphs
/**
* You are given an m x n grid where each cell can have one of three values: ● 0 representing an empty cell, ● 1 representing a fresh orange,
* or ● 2 representing a rotten orange. Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten.
* Re... | 0 | Java | 0 | 0 | f2aaff0a995071d6e188ee19f72b78d07688a672 | 2,889 | data-structure-and-coding-problems | Apache License 2.0 |
day02/src/main/kotlin/Main.kt | ickybodclay | 159,694,344 | false | null | import java.io.File
fun main() {
val input = File(ClassLoader.getSystemResource("input.txt").file)
// Write solution here!
var checksumA = 0
var checksumB = 0
val idList = ArrayList<String>()
input.readLines().map{line ->
idList.add(line)
val letterCountMap = HashMap<Char, In... | 0 | Kotlin | 0 | 0 | 9a055c79d261235cec3093f19f6828997b7a5fba | 1,974 | aoc2018 | Apache License 2.0 |
archive/src/main/kotlin/com/grappenmaker/aoc/year20/Day18.kt | 770grappenmaker | 434,645,245 | false | {"Kotlin": 409647, "Python": 647} | package com.grappenmaker.aoc.year20
import com.grappenmaker.aoc.PuzzleSet
import com.grappenmaker.aoc.queueOf
import com.grappenmaker.aoc.removeLastN
fun PuzzleSet.day18() = puzzle(day = 18) {
fun lexer(l: String): List<Token> {
var ptr = 0
val partials = mutableListOf<Token>()
val groupSt... | 0 | Kotlin | 0 | 7 | 92ef1b5ecc3cbe76d2ccd0303a73fddda82ba585 | 3,572 | advent-of-code | The Unlicense |
src/Day08.kt | MatthiasDruwe | 571,730,990 | false | {"Kotlin": 47864} | import java.lang.Error
fun main() {
fun part1(input: List<String>): Int {
val output = input.map { line -> line.toCharArray().map { it.toString().toInt() } }
val visibleFromLeft = output. map { row->
row.mapIndexed{index, value->
var visible = true
repe... | 0 | Kotlin | 0 | 0 | f35f01cea5075cfe7b4a1ead9b6480ffa57b4989 | 4,415 | Advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/patbeagan/days/Day12.kt | patbeagan1 | 576,401,502 | false | {"Kotlin": 57404} | package dev.patbeagan.days
import dev.patbeagan.List2D
import org.jgrapht.alg.shortestpath.DijkstraShortestPath
import org.jgrapht.graph.DefaultEdge
import org.jgrapht.graph.SimpleGraph
/**
* [Day 12](https://adventofcode.com/2022/day/12)
*/
class Day12 : AdventDay<Int> {
override fun part1(input: String): Int ... | 0 | Kotlin | 0 | 0 | 4e25b38226bcd0dbd9c2ea18553c876bf2ec1722 | 3,163 | AOC-2022-in-Kotlin | Apache License 2.0 |
src/Day04.kt | sushovan86 | 573,586,806 | false | {"Kotlin": 47064} | fun main() {
fun String.itemsAsRange(): IntRange {
val (start, end) = split("-")
return start.toInt()..end.toInt()
}
fun String.splitByComma() = split(",")
operator fun IntRange.contains(other: IntRange): Boolean =
first <= other.first && last >= other.last
infix fun IntR... | 0 | Kotlin | 0 | 0 | d5f85b6a48e3505d06b4ae1027e734e66b324964 | 1,120 | aoc-2022 | Apache License 2.0 |
puzzles/src/main/kotlin/com/kotlinground/puzzles/arrays/maxaveragesubarray/maxAverageSubarray.kt | BrianLusina | 113,182,832 | false | {"Kotlin": 483489, "Shell": 7283, "Python": 1725} | package com.kotlinground.puzzles.arrays.maxaveragesubarray
import kotlin.math.max
/**
* Finds the maximum average in a sub array of length k from the provided list/array.
*
* Uses a sliding window to find the maximum average.
* This traverses over nums just once, and on the go keep determining the sums possible f... | 1 | Kotlin | 1 | 0 | 5e3e45b84176ea2d9eb36f4f625de89d8685e000 | 1,428 | KotlinGround | MIT License |
src/day_11/Day11.kt | BrumelisMartins | 572,847,918 | false | {"Kotlin": 32376} | package day_11
import day_04.Group
import readInput
fun main() {
val testMonkey0 = Monkey(startingItems = ArrayDeque(listOf(79, 98)), operation = { return@Monkey it * 19 }, divisor = 23, test = { return@Monkey if (it % 23 == 0L) 2 else 3 })
val testMonkey1 = Monkey(startingItems = ArrayDeque(listOf(54, 65, 7... | 0 | Kotlin | 0 | 0 | 3391b6df8f61d72272f07b89819c5b1c21d7806f | 3,707 | aoc-2022 | Apache License 2.0 |
app/src/main/java/andrew/studio/com/ultrabuddymvvm/corealgorithms/models/Circle2D.kt | levulinh | 186,353,048 | false | null | package andrew.studio.com.ultrabuddymvvm.corealgorithms.models
import andrew.studio.com.ultrabuddymvvm.corealgorithms.constants.Const.EPS
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.sqrt
class Circle2D(val center: Point2D, val radius: Float) {
constructor(center: Point2D, pointOnCircle: Poin... | 0 | Kotlin | 0 | 3 | 30ad2172e3454498c650a67725dc67402d5fd908 | 3,240 | UltraBuddyMVVM | Creative Commons Attribution 3.0 Unported |
4_kyu/The_observed_PIN.kt | UlrichBerntien | 439,630,417 | false | {"Go": 293606, "Rust": 191729, "Python": 184557, "Lua": 137612, "Assembly": 89144, "C": 76738, "Julia": 35473, "Kotlin": 33204, "R": 27633, "C#": 20860, "Shell": 14326, "Forth": 3750, "PLpgSQL": 2117, "C++": 122} | /**
* Generates all possible PINs based on the observed PIN. The true PIN is around the observed PIN.
* Each key could be also the key around the observed key.
*
* @param The observed PIN.
* @return All possible PINs.
*/
fun getPINs(observed: String): List<String> =
when (observed.length) {
0 -> empty... | 0 | Go | 0 | 0 | 034d7f2bdcebc503b02877f2241e4dd143188b43 | 1,760 | Codewars-Katas | MIT License |
aoc16/src/main/kotlin/io/github/ajoz/workshop/day1/solution/Day1Solution.kt | ajoz | 77,487,554 | false | null | package io.github.ajoz.workshop.day1.solution
import io.github.ajoz.workshop.sequences.firstRepeated
import io.github.ajoz.workshop.sequences.scan
/**
* -------------------- Part 1 -----------------------
*/
/**
* Describes all possible directions that we can take in a taxi cab geometry.
*/
private enum class Di... | 0 | Kotlin | 0 | 0 | 3275cb1c7638e734634dc9270b460c08b214eda5 | 8,269 | kotlin-workshop | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round0/Questions56.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round0
import kotlin.math.*
fun test56() {
val array1 = intArrayOf(2, 4, 3, 6, 3, 2, 5, 5)
val array2 = intArrayOf(1, 3, 9, 6, 6, 8, 1, 3, 8, 0)
print("重复数字:")
findNumAppearOnce(array1).forEach { print("$it ") }
print("\n重复数字:")
findNumAppearOnce(array2).forEach { print("$it ") }... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 1,875 | Algorithm | Apache License 2.0 |
src/_2022/Day07.kt | albertogarrido | 572,874,945 | false | {"Kotlin": 36434} | package _2022
import printlnSuccess
import readInput
fun main() {
runTests()
runScenario(readInput("2022", "day07"))
}
private fun runScenario(input: List<String>) {
println("Result Part 1: ${part1(input)}")
println("Result Part 2: ${part2(input)}")
}
private fun part1(input: List<String>): Int {
... | 0 | Kotlin | 0 | 0 | ef310c5375f67d66f4709b5ac410d3a6a4889ca6 | 4,461 | AdventOfCode.kt | Apache License 2.0 |
src/day03/Day03.kt | tschens95 | 573,743,557 | false | {"Kotlin": 32775} | package day03
import readInput
fun main() {
fun part1(input: List<String>): Int {
var totalSum = 0
for (s in input) {
val half = s.length / 2
val parts = s.chunked(half)
val set1 = parts[0].toSet()
val set2 = parts[1].toSet()
for (c in s... | 0 | Kotlin | 0 | 2 | 9d78a9bcd69abc9f025a6a0bde923f53c2d8b301 | 1,980 | AdventOfCode2022 | Apache License 2.0 |
kotlin/2423_Remove_Letter_To_Equalize_Frequency/solution.kt | giovanniPepi | 607,763,568 | false | null | // Solution for the Leet Code problem 2423, Remove Letter To Equalize Frequency
// The problem descrition is found on the following link:
// https://leetcode.com/problems/remove-letter-to-equalize-frequency/description/
class Solution {
fun equalFrequency(word: String): Boolean {
// map for associating a ... | 0 | Kotlin | 1 | 0 | ccb853bce41206f30cbfb1ff4ca8e8f22feb0ee2 | 1,775 | bastterCode | MIT License |
src/Day01.kt | A55enz10 | 573,364,112 | false | {"Kotlin": 15119} | fun main() {
fun part1(input: List<String>): Int {
return getElvesKcalList(input).maxOrNull()!!
}
fun part2(input: List<String>): Int {
val elvesKcal = getElvesKcalList(input)
elvesKcal.sortDescending()
return elvesKcal[0] + elvesKcal[1] + elvesKcal[2]
}
// test... | 0 | Kotlin | 0 | 1 | 8627efc194d281a0e9c328eb6e0b5f401b759c6c | 959 | advent-of-code-2022 | Apache License 2.0 |
2020/05/Solution.kt | AdrianMiozga | 588,519,359 | false | {"Kotlin": 110785, "Python": 11275, "Assembly": 3369, "C": 2378, "Pawn": 1390, "Dart": 732} | import java.io.File
private const val FILENAME = "2020/05/input.txt"
fun main() {
partOne()
partTwo()
}
private fun partOne() {
val lines = File(FILENAME).readLines()
var max = 0
for (line in lines) {
val rows = line.slice(0..6).toList()
val row = bsp(0, 127, rows)
val ... | 0 | Kotlin | 0 | 0 | c9cba875089d8d4fb145932c45c2d487ccc7e8e5 | 1,669 | Advent-of-Code | MIT License |
src/day03/day03.kt | PS-MS | 572,890,533 | false | null | package day03
import readInput
fun main() {
val alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()
fun part1(input: List<String>): Int {
return input.sumOf {
val one = it.substring(0, it.length / 2)
val two = it.substring(it.length / 2)
... | 0 | Kotlin | 0 | 0 | 24f280a1d8ad69e83755391121f6107f12ffebc0 | 1,223 | AOC2022 | Apache License 2.0 |
src/main/kotlin/com/leetcode/P130.kt | antop-dev | 229,558,170 | false | {"Kotlin": 695315, "Java": 213000} | package com.leetcode
// https://github.com/antop-dev/algorithm/issues/313
class P130 {
fun solve(board: Array<CharArray>) {
val m = board.size
val n = board[0].size
// [0] : 방문 여부
// [1] : 'O' 여부
val visited = Array(m) { Array(n) { IntArray(2) } }
for (j in 0 until ... | 1 | Kotlin | 0 | 0 | 9a3e762af93b078a2abd0d97543123a06e327164 | 1,355 | algorithm | MIT License |
src/main/kotlin/dec2/Main.kt | dladukedev | 318,188,745 | false | null | package dec2
data class PasswordItem(
val minInt: Int,
val maxInt: Int,
val targetChar: Char,
val password: String
)
fun parseInput(input: String): PasswordItem {
val (rangeBlock, targetBlock, password) = input.split(' ')
val (minCountString, maxCountString) = rangeBlock.split('-')
val m... | 0 | Kotlin | 0 | 0 | d4591312ddd1586dec6acecd285ac311db176f45 | 1,716 | advent-of-code-2020 | MIT License |
src/Day01.kt | pydaoc | 573,843,750 | false | {"Kotlin": 8484} | import kotlin.math.*
fun main() {
fun part1(input: List<String>): Int {
var referenceCalories = 0
var currentCalories = 0
for (line in input) {
if (line.isEmpty()) {
referenceCalories = max(referenceCalories, currentCalories)
currentCalories = 0
... | 0 | Kotlin | 0 | 0 | 970dedbfaf09d12a29315c6b8631fa66eb394054 | 1,250 | advent-of-code-kotlin-2022 | Apache License 2.0 |
src/day13/Day13.kt | Oktosha | 573,139,677 | false | {"Kotlin": 110908} | package day13
import pass
import java.io.File
import kotlin.math.min
import kotlin.math.sign
sealed class PacketElement {
class Num(val value: Int) : PacketElement() {
override fun toString(): String {
return value.toString()
}
}
class Lst(val elements: MutableList<PacketElemen... | 0 | Kotlin | 0 | 0 | e53eea61440f7de4f2284eb811d355f2f4a25f8c | 4,924 | aoc-2022 | Apache License 2.0 |
src/Day15.kt | GarrettShorr | 571,769,671 | false | {"Kotlin": 82669} | import kotlin.math.abs
import kotlin.properties.Delegates
import kotlin.system.measureNanoTime
fun main() {
data class Point(val x: Int, val y: Int) {
fun manhattanDistanceTo(other: Point): Int {
return abs(x - other.x) + abs(y - other.y)
}
}
data class Sensor(val location: Point, val nearestBeaco... | 0 | Kotlin | 0 | 0 | 391336623968f210a19797b44d027b05f31484b5 | 4,637 | AdventOfCode2022 | Apache License 2.0 |
code/src/main/kotlin/substring/TwoWay.kt | illarionov | 500,219,308 | false | {"Kotlin": 16978, "HTML": 1856, "Makefile": 561, "SCSS": 63} | package substring
import java.lang.Integer.MAX_VALUE
import kotlin.math.abs
private val IntProgression.length get() = when (this.step) {
1, -1 -> if (!this.isEmpty()) abs(this.last - this.first) + 1 else 0
else -> count()
}
class TwoWay {
internal data class Factorization(val pattern: String,
... | 1 | Kotlin | 0 | 2 | 2ead4380e8b6ccd92af6329a1c9a6b78ce3a5c8b | 4,897 | strstr | Creative Commons Zero v1.0 Universal |
src/main/kotlin/days/Day2.kt | vovarova | 572,952,098 | false | {"Kotlin": 103799} | package days
class Day2 : Day(2) {
object GameRules {
const val winGamePoint = 6
const val loseGamePoint = 0
const val drawGamePoint = 3
val gameElements = listOf(
GameElement(name = "Rock", id = 'A', point = 1, winsFromId = 'C', looseFromId = 'B'),
GameEle... | 0 | Kotlin | 0 | 0 | e34e353c7733549146653341e4b1a5e9195fece6 | 2,503 | adventofcode_2022 | Creative Commons Zero v1.0 Universal |
src/Day08/Day08.kt | AllePilli | 572,859,920 | false | {"Kotlin": 47397} | package Day08
import checkAndPrint
import getElementsUntilEdges
import measureAndPrintTimeMillis
import multOf
import onEdge
import readInput
fun main() {
fun List<String>.prepareInput() = map { line -> line.map(Char::digitToInt) }
fun part1(input: List<List<Int>>): Int {
fun isVisible(rowIdx: Int, c... | 0 | Kotlin | 0 | 0 | 614d0ca9cc925cf1f6cfba21bf7dc80ba24e6643 | 1,622 | AdventOfCode2022 | Apache License 2.0 |
src/day_3.kt | gardnerdickson | 152,621,962 | false | null | import java.io.File
fun main(args: Array<String>) {
val input = "res/day_3_input.txt"
val answer1 = Day3.part1(input)
println("Part 1: $answer1")
val answer2 = Day3.part2(input)
println("Part 2: $answer2")
}
object Day3 {
private enum class Turn {
SANTA, ROBO_SANTA;
fun nextT... | 0 | Kotlin | 0 | 0 | 4a23ab367a87cae5771c3c8d841303b984474547 | 2,343 | advent-of-code-2015 | MIT License |
src/main/kotlin/2.kt | torland-klev | 730,585,319 | false | {"Kotlin": 74157} | package klev
import klev.`2`.Game.Companion.toGame
import klev.`2`.Round.Companion.toRound
import java.math.BigDecimal
object `2` : Day {
private data class Game(
val id: Int,
val rounds: List<Round>,
) {
companion object {
val gameRegex = Regex("\\d+(?=:)")
fu... | 0 | Kotlin | 0 | 0 | e18afa4a7c0c7b7e12744c38c1a57f42f055dcdf | 13,220 | advent-of-code-2023 | MIT License |
src/main/java/challenges/educative_grokking_coding_interview/top_k_elements/_4/FrequentElements.kt | ShabanKamell | 342,007,920 | false | null | package challenges.educative_grokking_coding_interview.top_k_elements._4
import java.util.*
/**
Given an array of integers, arr, and an integer, k, return the k most frequent elements.
Note: You can return the answer in any order.
https://www.educative.io/courses/grokking-coding-interview-patterns-java/m2ND3J3GY2n
... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 2,307 | CodingChallenges | Apache License 2.0 |
year2021/day03/part1/src/main/kotlin/com/curtislb/adventofcode/year2021/day03/part1/Year2021Day03Part1.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | /*
--- Day 3: Binary Diagnostic ---
The submarine has been making some odd creaking noises, so you ask it to produce a diagnostic report
just in case.
The diagnostic report (your puzzle input) consists of a list of binary numbers which, when decoded
properly, can tell you many useful things about the conditions of th... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 2,439 | AdventOfCode | MIT License |
src/main/kotlin/no/chriswk/aoc2019/Point.kt | chriswk | 317,863,220 | false | {"Kotlin": 481061} | package com.chriswk.aoc.advent2019
import kotlin.math.abs
enum class Direction {
U, D, L, R;
fun cmd(): Long {
return when(this) {
U -> 1L
D -> 2L
L -> 3L
R -> 4L
}
}
fun back(): Long {
return when(this) {
U -> D.cmd()
... | 116 | Kotlin | 0 | 0 | 69fa3dfed62d5cb7d961fe16924066cb7f9f5985 | 4,538 | adventofcode2019 | MIT License |
kotlinLeetCode/src/main/kotlin/leetcode/editor/cn/[665]非递减数列.kt | maoqitian | 175,940,000 | false | {"Kotlin": 354268, "Java": 297740, "C++": 634} | //给你一个长度为 n 的整数数组,请你判断在 最多 改变 1 个元素的情况下,该数组能否变成一个非递减数列。
//
// 我们是这样定义一个非递减数列的: 对于数组中所有的 i (0 <= i <= n-2),总满足 nums[i] <= nums[i + 1]。
//
//
//
// 示例 1:
//
// 输入: nums = [4,2,3]
//输出: true
//解释: 你可以通过把第一个4变成1来使得它成为一个非递减数列。
//
//
// 示例 2:
//
// 输入: nums = [4,2,1]
//输出: false
//解释: 你不能在只改变一个元素的情况下将其变为非递减数列。
//
//
/... | 0 | Kotlin | 0 | 1 | 8a85996352a88bb9a8a6a2712dce3eac2e1c3463 | 1,260 | MyLeetCode | Apache License 2.0 |
src/org/aoc2021/Day18.kt | jsgroth | 439,763,933 | false | {"Kotlin": 86732} | package org.aoc2021
import java.nio.file.Files
import java.nio.file.Path
object Day18 {
data class TreeNode(val left: TreeNode? = null, val right: TreeNode? = null, val value: Int? = null)
private fun solvePart1(lines: List<String>): Int {
val snailfishNumbers = lines.map(Day18::parseSnailfishNumber)... | 0 | Kotlin | 0 | 0 | ba81fadf2a8106fae3e16ed825cc25bbb7a95409 | 5,510 | advent-of-code-2021 | The Unlicense |
src/main/kotlin/d23/d23.kt | LaurentJeanpierre1 | 573,454,829 | false | {"Kotlin": 118105} | package d23
import readInput
enum class Directions {
North, South, West, East
}
data class Elf (var x: Int, var y: Int) {
var direction : Directions? = null
var arrival : Elf? = null
}
fun part1(input: List<String>): Int {
val elves = readPuzzle(input)
repeat(10) {round ->
//First Half
... | 0 | Kotlin | 0 | 0 | 5cf6b2142df6082ddd7d94f2dbde037f1fe0508f | 5,621 | aoc2022 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/com/colinodell/advent2021/Day10.kt | colinodell | 433,864,377 | true | {"Kotlin": 111114} | package com.colinodell.advent2021
class Day10 (private val input: List<String>) {
private val syntax = mapOf('(' to ')', '[' to ']', '{' to '}', '<' to '>')
private val syntaxErrorPoints = mapOf(')' to 3, ']' to 57, '}' to 1197, '>' to 25137)
private val autocompletePoints = mapOf(')' to 1, ']' to 2, '}' t... | 0 | Kotlin | 0 | 1 | a1e04207c53adfcc194c85894765195bf147be7a | 1,705 | advent-2021 | Apache License 2.0 |
src/Day21.kt | fedochet | 573,033,793 | false | {"Kotlin": 77129} | private sealed interface MonkeyTask
private data class NumberTask(val number: Long) : MonkeyTask
private data class OpTask(val left: String, val op: String, val right: String) : MonkeyTask
private const val ROOT = "root"
private const val HUMAN = "humn"
fun main() {
fun compute(left: Long, op: String, right: Long... | 0 | Kotlin | 0 | 1 | 975362ac7b1f1522818fc87cf2505aedc087738d | 4,067 | aoc2022 | Apache License 2.0 |
src/main/kotlin/aoc2018/day5/Polymer.kt | arnab | 75,525,311 | false | null | package aoc2018.day5
data class PolymerUnit(val type: Char, val polarity: Boolean = type.isUpperCase())
object Polymer {
fun reduce(units: List<PolymerUnit>, debug: Boolean = false): List<PolymerUnit> {
var reducedUnits = units
var pass = 1
do {
var reduced = false
... | 0 | Kotlin | 0 | 0 | 1d9f6bc569f361e37ccb461bd564efa3e1fccdbd | 2,136 | adventofcode | MIT License |
src/leetcode_problems/easy/FindGivenDifference.kt | MhmoudAlim | 451,633,139 | false | {"Kotlin": 31257, "Java": 586} | package leetcode_problems.easy
import kotlin.math.*
/*Given an unsorted array,
return 1 if there exists a pair or more of elements in the array whose difference is 1.
else return 0
Examples:
-Input: arr[] = {5, 20, 3, 2, 6}
=Output: 1
-Input: arr[] = {90, 7, 2, 9, 50}
=Output: 0
*/
fun findPairDifference(nums: I... | 0 | Kotlin | 0 | 0 | 31f0b84ebb6e3947e971285c8c641173c2a60b68 | 1,107 | Coding-challanges | MIT License |
src/me/bytebeats/algo/kt/design/FileSystem.kt | bytebeats | 251,234,289 | false | null | package me.bytebeats.algo.kt.design
class FileSystem() {
//588
private val root = File()
fun ls(path: String): List<String> {
val fileNames = mutableListOf<String>()
var file = root
if (path == "/") {
fileNames.addAll(file.files.map { it.name })
} else {
... | 0 | Kotlin | 0 | 1 | 7cf372d9acb3274003bb782c51d608e5db6fa743 | 3,790 | Algorithms | MIT License |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.