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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
lib/src/main/kotlin/io/nexure/fsm/StateMachineValidator.kt | venture-falcon | 532,830,962 | false | {"Kotlin": 24164, "Makefile": 53} | package io.nexure.fsm
import java.util.Deque
import java.util.LinkedList
internal object StateMachineValidator {
fun <S : Any, E : Any> validate(initialState: S, transitions: List<Edge<S, E>>) {
rejectDuplicates(transitions)
findIllegalCombinations(transitions)
isConnected(initialState, tr... | 0 | Kotlin | 0 | 0 | aa12b389ad0e8c0650868d28383ada5f5d6286c0 | 4,930 | fsm | MIT License |
subprojects/common/graph/src/main/kotlin/com/avito/graph/ShortestPath.kt | avito-tech | 230,265,582 | false | {"Kotlin": 3574228, "Java": 67252, "Shell": 27656, "Dockerfile": 12799, "Makefile": 7970} | package com.avito.graph
import org.jgrapht.Graph
import org.jgrapht.GraphPath
import org.jgrapht.alg.shortestpath.BellmanFordShortestPath
import org.jgrapht.graph.DefaultWeightedEdge
import org.jgrapht.graph.DirectedWeightedMultigraph
/**
* @operations nodes describing a DAG
*/
public class ShortestPath<T : Operati... | 10 | Kotlin | 48 | 390 | 9d60abdd26fc779dd57aa4f1ad51658b6a245d1e | 6,361 | avito-android | MIT License |
src/lib/Geometry.kt | HGilman | 572,891,570 | false | {"Kotlin": 109639, "C++": 5375, "Python": 400} | package lib
import kotlin.math.abs
import kotlin.math.sign
import kotlin.math.sqrt
data class Point2D(val x: Int, val y: Int) {
override fun toString(): String {
return "x: $x, y: $y"
}
fun toRight() = Point2D(x + 1, y)
fun toLeft() = Point2D(x - 1, y)
fun higher() = Point2D(x, y + 1)
... | 0 | Kotlin | 0 | 1 | d05a53f84cb74bbb6136f9baf3711af16004ed12 | 3,516 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/HouseRobber.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,444 | kotlab | Apache License 2.0 |
src/main/kotlin/ru/nrcki/biokotlin/Distance.kt | laxeye | 164,879,760 | false | null | package ru.nrcki.biokotlin
import kotlin.math.abs
import kotlin.math.ln
import kotlin.math.sqrt
class Distance(){
fun rawDistance(seq1: IBioSequence, seq2: IBioSequence): Double {
if(seq1.gaplength == seq1.length) {
throw Exception("Error! Impossible to calculate distance: ${seq1.id} contains only gaps")
... | 7 | Kotlin | 0 | 0 | fb86e738ee31a082bb71e2c8a73d34e65197f2eb | 4,242 | BioKotlin | MIT License |
day03/kotlin/corneil/src/main/kotlin/solution.kt | timgrossmann | 224,991,491 | true | {"HTML": 2739009, "Python": 169603, "Java": 157274, "Jupyter Notebook": 116902, "TypeScript": 113866, "Kotlin": 89503, "Groovy": 73664, "Dart": 47763, "C++": 43677, "CSS": 34994, "Ruby": 27091, "Haskell": 26727, "Scala": 11409, "Dockerfile": 10370, "JavaScript": 6496, "PHP": 4152, "Go": 2838, "Shell": 2493, "Rust": 208... | package com.github.corneil.aoc2019.day3
import java.io.BufferedReader
import java.io.File
import java.io.FileReader
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
data class Coord(val x: Int, val y: Int) {
fun distance(target: Coord): Int {
return abs(x - target.x) + abs(y - target.y... | 0 | HTML | 0 | 1 | bb19fda33ac6e91a27dfaea27f9c77c7f1745b9b | 5,606 | aoc-2019 | MIT License |
src/main/kotlin/Problem30.kt | jimmymorales | 496,703,114 | false | {"Kotlin": 67323} | import kotlin.math.pow
/**
* Digit fifth powers
*
* Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
*
* 1634 = 1^4 + 6^4 + 3^4 + 4^4
* 8208 = 8^4 + 2^4 + 0^4 + 8^4
* 9474 = 9^4 + 4^4 + 7^4 + 4^4
*
* As 1 = 14 is not a sum it is not included.
*
* The... | 0 | Kotlin | 0 | 0 | e881cadf85377374e544af0a75cb073c6b496998 | 1,153 | project-euler | MIT License |
src/main/kotlin/days/Day17.kt | andilau | 433,504,283 | false | {"Kotlin": 137815} | package days
import kotlin.math.sign
@AdventOfCodePuzzle(
name = "<NAME>",
url = "https://adventofcode.com/2021/day/17",
date = Date(day = 17, year = 2021)
)
class Day17(input: String) : Puzzle {
private val targetArea = input
.substringAfter("target area: ")
.split(", ")
.map... | 0 | Kotlin | 0 | 0 | b3f06a73e7d9d207ee3051879b83e92b049a0304 | 1,778 | advent-of-code-2021 | Creative Commons Zero v1.0 Universal |
src/com/hlq/leetcode/array/Question1.kt | HLQ-Struggle | 310,978,308 | false | null | package com.hlq.leetcode.array
/**
* @author HLQ_Struggle
* @date 2020/11/09
* @desc LeetCode 1. 两数之和 https://leetcode-cn.com/problems/two-sum/
*/
fun main() {
val nums = intArrayOf(3, 2, 4)
val target = 6
// 暴力解法 一
twoSum(nums, target)
// 优化
twoSum2(nums, target)
twoSum3(nums, targe... | 0 | Kotlin | 0 | 2 | 76922f46432783218ddd34e74dbbf3b9f3c68f25 | 2,908 | LeetCodePro | Apache License 2.0 |
src/Day14.kt | pavlo-dh | 572,882,309 | false | {"Kotlin": 39999} | fun main() {
data class Point(val x: Int, val y: Int) {
operator fun plus(other: Point) = Point(x + other.x, y + other.y)
}
fun parseInput(input: List<String>): MutableMap<Point, Char> {
val cave = mutableMapOf<Point, Char>()
input.forEach { line ->
val points = line.spl... | 0 | Kotlin | 0 | 2 | c10b0e1ce2c7c04fbb1ad34cbada104e3b99c992 | 4,523 | aoc-2022-in-kotlin | Apache License 2.0 |
src/algorithms/HungarianAlgorithm.kt | aaronoe | 186,243,764 | false | null | package de.aaronoe.algorithms
import de.aaronoe.models.Seminar
import de.aaronoe.models.Student
import org.jgrapht.alg.matching.KuhnMunkresMinimalWeightBipartitePerfectMatching
import org.jgrapht.graph.DefaultWeightedEdge
import org.jgrapht.graph.SimpleWeightedGraph
import kotlin.system.measureTimeMillis
object Hunga... | 0 | Kotlin | 0 | 1 | 8265e6553aca23c3bf2c5236ba56d46ab7e2b3f3 | 3,421 | matching_server | MIT License |
kotlin/src/com/daily/algothrim/leetcode/NumWays.kt | idisfkj | 291,855,545 | false | null | package com.daily.algothrim.leetcode
/**
* 1269. 停在原地的方案数
* 有一个长度为 arrLen 的数组,开始有一个指针在索引 0 处。
*
* 每一步操作中,你可以将指针向左或向右移动 1 步,或者停在原地(指针不能被移动到数组范围外)。
*
* 给你两个整数 steps 和 arrLen ,请你计算并返回:在恰好执行 steps 次操作以后,指针仍然指向索引 0 处的方案数。
*
* 由于答案可能会很大,请返回方案数 模 10^9 + 7 后的结果。
*/
class NumWays {
companion object {
@Jvm... | 0 | Kotlin | 9 | 59 | 9de2b21d3bcd41cd03f0f7dd19136db93824a0fa | 2,421 | daily_algorithm | Apache License 2.0 |
src/nativeMain/kotlin/com.qiaoyuang.algorithm/round1/Questions22.kt | qiaoyuang | 100,944,213 | false | {"Kotlin": 338134} | package com.qiaoyuang.algorithm.round1
fun test22() {
val head = SingleDirectionNode(0u)
var current = head
repeat(9) {
val next = SingleDirectionNode(it.toUInt() + 1u)
current.next = next
current = next
}
printlnResult1(8u, head)
printlnResult1(3u, head)
printlnResu... | 0 | Kotlin | 3 | 6 | 66d94b4a8fa307020d515d4d5d54a77c0bab6c4f | 2,461 | Algorithm | Apache License 2.0 |
2016/04/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 = "2016/04/input.txt"
private val REGEX = Regex("""([a-z\-]+)(\d+)\[([a-z]+)]""")
fun main() {
partOne()
partTwo()
}
private fun partOne() {
var sum = 0
val lines = File(FILENAME).readLines()
for (line in lines) {
val (encryptedName, sectorI... | 0 | Kotlin | 0 | 0 | c9cba875089d8d4fb145932c45c2d487ccc7e8e5 | 1,352 | Advent-of-Code | MIT License |
src/main/java/kam/wardrober/algorithm/Genetic.kt | kudryaA | 166,642,234 | false | null | package kam.wardrober.algorithm
import kam.wardrober.struct.ListClothes
import kam.wardrober.struct.Temperature
import kam.wardrober.struct.clothes.Set
import java.util.*
import java.util.stream.Collectors
fun geneticSolve(list: ListClothes, temperature: Temperature): Set? {
var gen = Generation(temperature)
... | 0 | Kotlin | 0 | 0 | 7685418dd0a96187d0ca53c4223e711e869aeb82 | 3,204 | Wardrober-genetic-algorithm | MIT License |
src/main/kotlin/solved/p1679/Solution.kt | mr-nothing | 469,475,608 | false | {"Kotlin": 162430} | package solved.p1679
class Solution {
class SortingApproach {
fun maxOperations(nums: IntArray, k: Int): Int {
val sorted = nums.sorted()
var operations = 0
var head = 0
var tail = nums.lastIndex
while (head < tail) {
while (tail... | 0 | Kotlin | 0 | 0 | 0f7418ecc8675d8361ef31cbc1ee26ea51f7708a | 2,110 | leetcode | Apache License 2.0 |
src/main/kotlin/day3/Part1.kt | Pinaki93 | 573,867,953 | false | {"Kotlin": 4415, "Assembly": 10} | package day3
import util.readFileFromResources
val alphabetMap: Map<Char, Int> = ('a'..'z')
.zip((1..26).toList()).toMap() + ('A'..'Z').zip((27..52).toList()).toMap()
fun findCommonCharacter(list1: List<Char>, list2: List<Char>): Char {
val sortedList1 = list1.sorted()
val sortedList2 = list2.sorted()
... | 0 | Kotlin | 0 | 0 | c1518c3adfb1aee49838fe439e1913f4f6f825dd | 1,294 | advent-of-code-2022 | MIT License |
src/iii_conventions/MyDate.kt | vavrajosef | 155,741,898 | true | {"Kotlin": 72636, "Java": 3851} | package iii_conventions
import iii_conventions.nextDay
import iii_conventions.addTimeIntervals
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 == ... | 0 | Kotlin | 0 | 0 | 839c58cd2901c3901ec0c259ea7afe00d4cb85cc | 1,635 | kotlin-koans | MIT License |
src/chapter4/section3/ex41_LongestMSTEdge.kt | w1374720640 | 265,536,015 | false | {"Kotlin": 1373556} | package chapter4.section3
import extensions.formatDouble
import kotlin.math.PI
import kotlin.math.log2
import kotlin.math.sqrt
/**
* 最小生成树中的最长边
* 运行实验并根据经验分析最小生成树中最长边的长度以及图中不长于该边的边的总数
*/
fun ex41_LongestMSTEdge(graph: EWG, mst: MST): Pair<Edge, Int> {
val iterator = mst.edges().iterator()
require(iterator.... | 0 | Kotlin | 1 | 6 | 879885b82ef51d58efe578c9391f04bc54c2531d | 2,183 | Algorithms-4th-Edition-in-Kotlin | MIT License |
src/day19/Day19.kt | armanaaquib | 572,849,507 | false | {"Kotlin": 34114} | package day19
import readInputAsText
fun main() {
fun parseInput(input: String) = input.split("\n\n")
.map { elf -> elf.split("\n").map { it.toInt() } }
fun part1(input: String): Int {
val data = parseInput(input)
return data.maxOf { it.sum() }
}
fun part2(input: String): In... | 0 | Kotlin | 0 | 0 | 47c41ceddacb17e28bdbb9449bfde5881fa851b7 | 875 | aoc-2022 | Apache License 2.0 |
src/main/kotlin/com/vaclavbohac/advent2023/day3/GearRatios.kt | vaclavbohac | 725,991,261 | false | {"Kotlin": 15155} | package com.vaclavbohac.advent2023.day3
class GearRatios(private val lines: List<String>) {
fun getSumOfAllParts(): Int {
val validNumbers = mutableListOf<Int>()
lines.forEachIndexed { i, line ->
var j = 0
var number = StringBuffer()
var indexStart = 0
... | 0 | Kotlin | 0 | 0 | daa1feb960c4e3d26c3c75842afbd414ecc2f008 | 3,249 | advent-of-code-2023 | MIT License |
2022/src/main/kotlin/day3_func.kt | madisp | 434,510,913 | false | {"Kotlin": 388138} | import utils.Parser
import utils.Solution
import utils.badInput
import utils.map
import utils.mapItems
import utils.split
fun main() {
Day3Func.run()
}
typealias Day3Input = List<Pair<Set<Char>, Set<Char>>>
val Char.priority: Int get() = when (this) {
in ('A' .. 'Z') -> this - 'A' + 26
else -> this - 'a'
}
ob... | 0 | Kotlin | 0 | 1 | 3f106415eeded3abd0fb60bed64fb77b4ab87d76 | 899 | aoc_kotlin | MIT License |
src/main/kotlin/aoc23/Day01.kt | tahlers | 725,424,936 | false | {"Kotlin": 65626} | package aoc23
object Day01 {
private val word2NumberRegex = """(one|two|three|four|five|six|seven|eight|nine|\d)""".toRegex()
private val word2NumberRegexRev = """(eno|owt|eerht|ruof|evif|xis|neves|thgie|enin|\d)""".toRegex()
fun calculateCalibrationSum(input: String): Int =
input.trim().lines().... | 0 | Kotlin | 0 | 0 | 0cd9676a7d1fec01858ede1ab0adf254d17380b0 | 1,697 | advent-of-code-23 | Apache License 2.0 |
src/Lesson3TimeComplexity/FrogJmp.kt | slobodanantonijevic | 557,942,075 | false | {"Kotlin": 50634} | /**
* 100/100
* @param X
* @param Y
* @param D
* @return
*/
fun solution(X: Int, Y: Int, D: Int): Int {
return Math.ceil((Y - X).toDouble() / D).toInt()
}
/**
* A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or... | 0 | Kotlin | 0 | 0 | 155cf983b1f06550e99c8e13c5e6015a7e7ffb0f | 1,167 | Codility-Kotlin | Apache License 2.0 |
src/main/kotlin/dev/siller/aoc2023/Day09.kt | chearius | 725,594,554 | false | {"Kotlin": 50795, "Shell": 299} | package dev.siller.aoc2023
data object Day09 : AocDayTask<Int, Int>(
day = 9,
exampleInput =
"""
|0 3 6 9 12 15
|1 3 6 10 15 21
|10 13 16 21 30 45
""".trimMargin(),
expectedExampleOutputPart1 = 114,
expectedExampleOutputPart2 = 2
) {
override fun runPart1(inp... | 0 | Kotlin | 0 | 0 | fab1dd509607eab3c66576e3459df0c4f0f2fd94 | 1,492 | advent-of-code-2023 | MIT License |
src/main/kotlin/g0001_0100/s0095_unique_binary_search_trees_ii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0001_0100.s0095_unique_binary_search_trees_ii
// #Medium #Dynamic_Programming #Tree #Binary_Tree #Backtracking #Binary_Search_Tree
// #2023_07_10_Time_167_ms_(100.00%)_Space_36.6_MB_(100.00%)
import com_github_leetcode.TreeNode
/*
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a b... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,732 | LeetCode-in-Kotlin | MIT License |
src/main/kotlin/com/sherepenko/leetcode/challenges/Algorithms.kt | asherepenko | 264,648,984 | false | null | package com.sherepenko.leetcode.challenges
import com.sherepenko.leetcode.Solution
import com.sherepenko.leetcode.data.ListNode
import com.sherepenko.leetcode.solutions.AddTwoNumbers
import com.sherepenko.leetcode.solutions.Fibonacci
import com.sherepenko.leetcode.solutions.LengthOfLongestUniqueSubstring
import com.sh... | 0 | Kotlin | 0 | 0 | 49e676f13bf58f16ba093f73a52d49f2d6d5ee1c | 2,188 | leetcode | The Unlicense |
leetcode2/src/leetcode/shuffle-an-array.kt | hewking | 68,515,222 | false | null | package leetcode
import java.util.*
/**
* 384. 打乱数组
* https://leetcode-cn.com/problems/shuffle-an-array/
* Created by test
* Date 2019/7/19 1:18
* Description
* 打乱一个没有重复元素的数组。
示例:
// 以数字集合 1, 2 和 3 初始化数组。
int[] nums = {1,2,3};
Solution solution = new Solution(nums);
// 打乱数组 [1,2,3] 并返回结果。任何 [1,2,3]的排列返回的概率应该... | 0 | Kotlin | 0 | 0 | a00a7aeff74e6beb67483d9a8ece9c1deae0267d | 1,969 | leetcode | MIT License |
aoc2016/src/main/kotlin/io/github/ajoz/sequences/Sequences.kt | ajoz | 116,427,939 | false | null | package io.github.ajoz.sequences
/**
* Returns a sequence containing the results of applying the given [transform] function to each element in the original
* sequence and the result of previous application. For the case of first element in the sequence the [initial] value
* will be used as the "previous result" and... | 0 | Kotlin | 0 | 0 | 49ba07dd5fbc2949ed3c3ff245d6f8cd7af5bebe | 2,039 | kotlin-workshop | Apache License 2.0 |
src/Day01.kt | kritanta | 574,453,685 | false | {"Kotlin": 8568} | fun main() {
fun getCalories(input: List<String>, numberToTake: Int): Int {
var elfTotals = mutableMapOf<Int,Int>()
var elfNumber = 0
input.forEach {
s ->
if(s.isNullOrEmpty()){
elfNumber++
}
else{
elfTota... | 0 | Kotlin | 0 | 0 | 834259cf076d0bfaf3d2e06d1bc1d5df13cffd6c | 950 | AOC-2022-Kotlin | Apache License 2.0 |
src/main/kotlin/nl/kelpin/fleur/advent2018/Extensions.kt | fdlk | 159,925,533 | false | null | package nl.kelpin.fleur.advent2018
import java.util.*
fun String.matchingChars(other: String): String =
this.zip(other).filter { it.first == it.second }
.map { it.first }
.joinToString("")
fun IntRange.overlaps(other: IntRange): Boolean =
start <= other.endInclusive &&... | 0 | Kotlin | 0 | 3 | a089dbae93ee520bf7a8861c9f90731eabd6eba3 | 1,830 | advent-2018 | MIT License |
src/main/kotlin/g2401_2500/s2415_reverse_odd_levels_of_binary_tree/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g2401_2500.s2415_reverse_odd_levels_of_binary_tree
// #Medium #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
// #2023_07_04_Time_499_ms_(87.50%)_Space_47.7_MB_(12.50%)
import com_github_leetcode.TreeNode
import java.util.LinkedList
import java.util.Queue
/*
* Example:
* var ti = TreeNode(5)
... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,776 | LeetCode-in-Kotlin | MIT License |
src/test/kotlin/adventofcode/day11/Day11.kt | jwcarman | 573,183,719 | false | {"Kotlin": 183494} | /*
* Copyright (c) 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to i... | 0 | Kotlin | 0 | 0 | d6be890aa20c4b9478a23fced3bcbabbc60c32e0 | 4,172 | adventofcode2022 | Apache License 2.0 |
src/main/kotlin/com/jacobhyphenated/advent2022/day21/Day21.kt | jacobhyphenated | 573,603,184 | false | {"Kotlin": 144303} | package com.jacobhyphenated.advent2022.day21
import com.jacobhyphenated.advent2022.Day
/**
* Day 21: Monkey Math
*
* Monkey math involves monkeys yelling out numbers.
* Some always yell out a single number.
* Others yell out the math result of two other monkey's numbers.
*
* The puzzle input shows each monkey'... | 0 | Kotlin | 0 | 0 | 9f4527ee2655fedf159d91c3d7ff1fac7e9830f7 | 5,834 | advent2022 | The Unlicense |
src/main/kotlin/net/voldrich/aoc2023/Day01.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2023
import net.voldrich.BaseDay
// https://adventofcode.com/2023/day/1
fun main() {
Day01().run()
}
class Day01 : BaseDay() {
override fun task1() : Int {
return input.lines().filter { it.isNotBlank() }.sumOf { line ->
val digits = line.filter { it.isDigit() }
... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 1,249 | advent-of-code | Apache License 2.0 |
src/main/kotlin/github/walkmansit/aoc2020/Day17.kt | walkmansit | 317,479,715 | false | null | package github.walkmansit.aoc2020
class Day17(val input: List<String>) : DayAoc<Int, Int> {
private class Simulation(val inpLines: List<String>, val turns: Int) {
private fun increaseRange(range: IntRange): IntRange {
return range.first - 1..range.last + 1
}
fun simulate3DAnd... | 0 | Kotlin | 0 | 0 | 9c005ac4513119ebb6527c01b8f56ec8fd01c9ae | 7,573 | AdventOfCode2020 | MIT License |
src/main/kotlin/advent/of/code/day17/Solution.kt | brunorene | 160,263,437 | false | null | package advent.of.code.day17
import java.io.File
import java.util.*
class Position(name1: String, val1: Int, val2: Int) : Comparable<Position> {
val x: Int
val y: Int
init {
if (name1 == "x") {
x = val1
y = val2
} else {
x = val2
y = val1
... | 0 | Kotlin | 0 | 0 | 0cb6814b91038a1ab99c276a33bf248157a88939 | 2,139 | advent_of_code_2018 | The Unlicense |
src/main/kotlin/days/Day2.kt | butnotstupid | 571,247,661 | false | {"Kotlin": 90768} | package days
class Day2 : Day(2) {
// A < B < C < A
// X < Y < Z < X
private val winsTo = mapOf('A' to 'B', 'B' to 'C', 'C' to 'A')
private val loseTo = mapOf('B' to 'A', 'C' to 'B', 'A' to 'C')
override fun partOne(): Any {
return inputList.sumOf {
val (one, another) = it[0] ... | 0 | Kotlin | 0 | 0 | 4760289e11d322b341141c1cde34cfbc7d0ed59b | 1,016 | aoc-2022 | Creative Commons Zero v1.0 Universal |
src/Day01.kt | georgiizorabov | 573,050,504 | false | {"Kotlin": 10501} | fun main() {
fun read(input: List<String>): List<Int> {
var input1 = input
val list: MutableList<Int> = arrayListOf()
var i = 0
repeat(input1.size) {
i += 1
list.add(input1.takeWhile { elem -> elem != "" }.sumOf { it.toInt() })
input1 = input1.drop... | 0 | Kotlin | 0 | 0 | bf84e55fe052c9c5f3121c245a7ae7c18a70c699 | 817 | aoc2022 | Apache License 2.0 |
src/main/kotlin/me/peckb/aoc/_2018/calendar/day03/Day03.kt | peckb1 | 433,943,215 | false | {"Kotlin": 956135} | package me.peckb.aoc._2018.calendar.day03
import me.peckb.aoc.generators.InputGenerator.InputGeneratorFactory
import javax.inject.Inject
class Day03 @Inject constructor(private val generatorFactory: InputGeneratorFactory) {
fun partOne(filename: String) = generatorFactory.forFile(filename).readAs(::pattern) { input... | 0 | Kotlin | 1 | 3 | 2625719b657eb22c83af95abfb25eb275dbfee6a | 1,907 | advent-of-code | MIT License |
src/Day10.kt | chrisjwirth | 573,098,264 | false | {"Kotlin": 28380} | import kotlin.math.abs
fun main() {
class SignalCalculator(
val input: List<String>,
val cyclesToConsider: List<Int>,
val shouldUpdateScreen: Boolean
) {
private var cycle = 1
private var registerValue = 1
private var sumOfConsideredCycles = 0
private val... | 0 | Kotlin | 0 | 0 | d8b1f2a0d0f579dd23fa1dc1f7b156f728152c2d | 3,078 | AdventOfCode2022 | Apache License 2.0 |
advent-of-code-2022/src/main/kotlin/eu/janvdb/aoc2022/day13/IntTree.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2022.day13
interface TreeItem : Comparable<TreeItem>
class TreeLeaf(val value: Int) : TreeItem {
override fun compareTo(other: TreeItem): Int {
if (other is TreeLeaf) {
return this.value.compareTo(other.value)
}
return TreeNode(listOf(this)).compareTo(other)
}
override fun toString()... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 1,691 | advent-of-code | Apache License 2.0 |
year2021/day12/caves/src/main/kotlin/com/curtislb/adventofcode/year2021/day12/caves/CaveSystem.kt | curtislb | 226,797,689 | false | {"Kotlin": 2146738} | package com.curtislb.adventofcode.year2021.day12.caves
/**
* A system of large and small caves, connected by undirected edges (representing passages).
*
* @param cavesString A string representing the cave system. Each line must be of the form
* `"${caveA}-${caveB}"`, indicating that an edge exists between `caveA`... | 0 | Kotlin | 1 | 1 | 6b64c9eb181fab97bc518ac78e14cd586d64499e | 4,986 | AdventOfCode | MIT License |
aoc-2018/src/main/kotlin/nl/jstege/adventofcode/aoc2018/days/Day02.kt | JStege1206 | 92,714,900 | false | null | package nl.jstege.adventofcode.aoc2018.days
import nl.jstege.adventofcode.aoccommon.days.Day
import nl.jstege.adventofcode.aoccommon.utils.extensions.*
class Day02 : Day(title = "Inventory Management System") {
override fun first(input: Sequence<String>): Any = input
.asSequence()
.map { id -> id.... | 0 | Kotlin | 0 | 0 | d48f7f98c4c5c59e2a2dfff42a68ac2a78b1e025 | 1,751 | AdventOfCode | MIT License |
advent-of-code-2020/src/main/kotlin/eu/janvdb/aoc2020/day11/Seating.kt | janvdbergh | 318,992,922 | false | {"Java": 1000798, "Kotlin": 284065, "Shell": 452, "C": 335} | package eu.janvdb.aoc2020.day11
enum class Seat(val symbol: Char) {
FLOOR('.'), EMPTY('L'), FILLED('#')
}
fun toSeat(symbol: Char): Seat {
return Seat.values()
.find { it.symbol == symbol }!!
}
class Seating {
private val width: Int
private val height: Int
private val seats: List<Seat>
constructor(input: L... | 0 | Java | 0 | 0 | 78ce266dbc41d1821342edca484768167f261752 | 3,148 | advent-of-code | Apache License 2.0 |
src/main/kotlin/days/Day19.kt | andilau | 399,220,768 | false | {"Kotlin": 85768} | package days
@AdventOfCodePuzzle(
name = "<NAME>",
url = "https://adventofcode.com/2020/day/19",
date = Date(day = 19, year = 2020)
)
class Day19(lines: List<String>) : Puzzle {
private val dictionary: MutableMap<String, List<List<String>>> = readRules(lines)
private val messages = readMessages(lin... | 7 | Kotlin | 0 | 0 | 2809e686cac895482c03e9bbce8aa25821eab100 | 1,757 | advent-of-code-2020 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/io/github/clechasseur/adventofcode2021/Day12.kt | clechasseur | 435,726,930 | false | {"Kotlin": 315943} | package io.github.clechasseur.adventofcode2021
object Day12 {
private val data = """
start-kc
pd-NV
start-zw
UI-pd
HK-end
UI-kc
pd-ih
ih-end
start-UI
kc-zw
end-ks
MF-mq
HK-zw
LF-ks
HK-kc
... | 0 | Kotlin | 0 | 0 | 4b893c001efec7d11a326888a9a98ec03241d331 | 1,453 | adventofcode2021 | MIT License |
src/main/kotlin/dev/shtanko/algorithms/leetcode/ChampagneTower.kt | ashtanko | 203,993,092 | false | {"Kotlin": 5856223, "Shell": 1168, "Makefile": 917} | /*
* Copyright 2022 <NAME>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in w... | 4 | Kotlin | 0 | 19 | 776159de0b80f0bdc92a9d057c852b8b80147c11 | 1,478 | kotlab | Apache License 2.0 |
src/main/kotlin/days/Day09.kt | TheMrMilchmann | 571,779,671 | false | {"Kotlin": 56525} | /*
* Copyright (c) 2022 <NAME>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, dis... | 0 | Kotlin | 0 | 1 | 2e01ab62e44d965a626198127699720563ed934b | 2,896 | AdventOfCode2022 | MIT License |
src/main/kotlin/com/felipecsl/OfflineBalancedBinPacking.kt | felipecsl | 140,735,494 | false | {"Kotlin": 8689} | package com.felipecsl
import java.util.*
/**
* Collection of bin packing algorithms optimized for evenly filling the available bins (balanced).
* Offline means the full list of items is known beforehand.
*/
class OfflineBalancedBinPacking {
/** https://www.sciencedirect.com/science/article/pii/0885064X85900226?v... | 0 | Kotlin | 0 | 1 | 27136b336e001ca35cb2c6f6e2d99ca7d2ff3443 | 3,750 | bin-packing | MIT License |
src/main/adventofcode/Day11Solver.kt | eduardofandrade | 317,942,586 | false | null | package adventofcode
import java.io.InputStream
import java.util.stream.Collectors
class Day11Solver(stream: InputStream) : Solver {
private val processedInput: List<ArrayList<Char>>
private var numberOfRows = 0
private var numberOfColumns = 0
init {
processedInput = processInput(stream)
... | 0 | Kotlin | 0 | 0 | 147553654412ae1da4b803328e9fc13700280c17 | 4,921 | adventofcode2020 | MIT License |
src/main/kotlin/g1901_2000/s1986_minimum_number_of_work_sessions_to_finish_the_tasks/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g1901_2000.s1986_minimum_number_of_work_sessions_to_finish_the_tasks
// #Medium #Array #Dynamic_Programming #Bit_Manipulation #Backtracking #Bitmask
// #2023_06_21_Time_153_ms_(100.00%)_Space_35.6_MB_(100.00%)
class Solution {
fun minSessions(tasks: IntArray, sessionTime: Int): Int {
val len = tas... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,571 | LeetCode-in-Kotlin | MIT License |
src/day20/Parser.kt | g0dzill3r | 576,012,003 | false | {"Kotlin": 172121} | package day20
import readInput
data class Coordinate (val value: Long, val index: Int) {
override fun toString(): String = "($value, @$index)"
}
data class Coordinates (val input: List<Long>) {
val data = input.mapIndexed { i, coord -> Coordinate (coord, i) }.toMutableList ()
fun get (index: Int): Coordi... | 0 | Kotlin | 0 | 0 | 6ec11a5120e4eb180ab6aff3463a2563400cc0c3 | 3,396 | advent_of_code_2022 | Apache License 2.0 |
src/day13/Day13.kt | ritesh-singh | 572,210,598 | false | {"Kotlin": 99540} | package day13
import readInput
import java.util.*
sealed class Packet {
data class ListsPacket(val packet: MutableList<Packet>) : Packet() {
override fun toString(): String {
return packet.toString()
}
}
data class IntegerPacket(val packet: Int) : Packet() {
fun toLis... | 0 | Kotlin | 0 | 0 | 17fd65a8fac7fa0c6f4718d218a91a7b7d535eab | 5,320 | aoc-2022-kotlin | Apache License 2.0 |
src/Day09.kt | chrisjwirth | 573,098,264 | false | {"Kotlin": 28380} | import kotlin.math.abs
fun main() {
open class TailTracker(numberOfKnots: Int) {
private val head = Knot(0, 0)
private val tail = Knot(0, 0)
private val knots = if (numberOfKnots == 2) {
arrayOf(head, tail)
} else {
val middleKnots = Array(numberOfKnots - 2) ... | 0 | Kotlin | 0 | 0 | d8b1f2a0d0f579dd23fa1dc1f7b156f728152c2d | 4,524 | AdventOfCode2022 | Apache License 2.0 |
Problems/Algorithms/542. 01 Matrix/01Matrix2.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 {
fun updateMatrix(mat: Array<IntArray>): Array<IntArray> {
val n = mat.size
val m = mat[0].size
val queue = ArrayDeque<IntArray>()
val results: Array<IntArray> = Array(n) { IntArray(m) { Int.MAX_VALUE } }
for (i in 0..n-1) {
for (j in 0..m... | 0 | Kotlin | 0 | 1 | 5e919965b43917eeee15e4bff12a0b6bea4fd0e7 | 1,350 | leet-code | MIT License |
day03/kotlin/bit-jkraushaar/solution.kts | timgrossmann | 224,991,491 | true | {"HTML": 2739009, "Python": 169603, "Java": 157274, "Jupyter Notebook": 116902, "TypeScript": 113866, "Kotlin": 89503, "Groovy": 73664, "Dart": 47763, "C++": 43677, "CSS": 34994, "Ruby": 27091, "Haskell": 26727, "Scala": 11409, "Dockerfile": 10370, "JavaScript": 6496, "PHP": 4152, "Go": 2838, "Shell": 2493, "Rust": 208... | #!/usr/bin/env -S kotlinc-jvm -script
import java.io.File
import java.lang.RuntimeException
import kotlin.math.absoluteValue
// tag::point[]
typealias Point = Pair<Int, Int>
fun Point.manhattanDistance(): Int = this.first.absoluteValue + this.second.absoluteValue
// end::point[]
// tag::line[]
typealias Line = Tripl... | 0 | HTML | 0 | 1 | bb19fda33ac6e91a27dfaea27f9c77c7f1745b9b | 3,142 | aoc-2019 | MIT License |
internal/test-utils/src/commonMain/kotlin/coil3/test/utils/maths.kt | coil-kt | 201,684,760 | false | {"Kotlin": 967712, "Shell": 1710, "JavaScript": 209} | package coil3.test.utils
import kotlin.math.pow
import kotlin.math.roundToInt
import kotlin.math.sqrt
/**
* Returns the cross correlation between two arrays.
*
* https://en.wikipedia.org/wiki/Cross-correlation
*/
fun crossCorrelation(x: IntArray, y: IntArray): Double {
require(x.count() == y.count()) { "Input... | 42 | Kotlin | 629 | 10,059 | 75ed843355778bd62840e91762bd01f1a4e2e901 | 1,962 | coil | Apache License 2.0 |
advent/src/test/kotlin/org/elwaxoro/advent/y2021/Dec02.kt | elwaxoro | 328,044,882 | false | {"Kotlin": 376774} | package org.elwaxoro.advent.y2021
import org.elwaxoro.advent.PuzzleDayTester
/**
* Dive!
*/
class Dec02 : PuzzleDayTester(2, 2021) {
override fun part1(): Any = loadMaster().fold(SubCoord(), Instruction::diveDiveDive).whereAmI()
override fun part2(): Any = loadMaster().fold(SubCoord(), Instruction::diveBu... | 0 | Kotlin | 4 | 0 | 1718f2d675f637b97c54631cb869165167bc713c | 1,698 | advent-of-code | MIT License |
week7matchnumberseasy/MatchNumbersEasy.kt | laitingsheng | 341,616,623 | false | null | class MatchNumbersEasy {
private fun compare(sb1: StringBuilder, sb2: StringBuilder): Int {
if (sb1.isEmpty() || sb2.isEmpty())
return sb1.length - sb2.length
var nz1 = sb1.indexOfFirst { c -> c != '0' }
if (nz1 == -1)
nz1 = sb1.length - 1
var nz2 = sb2.index... | 0 | Kotlin | 0 | 0 | 2fc3e7a23d37d5e81cdf19a9ea19901b25941a49 | 1,699 | 2020S1-COMP-SCI-7007 | ISC License |
src/Day01.kt | ricardorlg-yml | 573,098,872 | false | {"Kotlin": 38331} | fun main() {
fun parseInput(input: List<String>): List<Long> {
val tot = mutableListOf<Long>()
var accum = 0L
input.forEach { v ->
if (v.isNotBlank()) {
accum += v.toLong()
} else {
tot.add(accum)
accum = 0L
... | 0 | Kotlin | 0 | 0 | d7cd903485f41fe8c7023c015e4e606af9e10315 | 903 | advent_code_2022 | Apache License 2.0 |
src/Day01.kt | RisenAsh | 573,606,790 | false | {"Kotlin": 2330} | fun main() {
fun part1(input: List<String>): Int {
var i = 0
var highest = 0
input.forEach {
if (it != "") {
// Count = Count + value from that line converted into an Integer
i += it.toInt()
}
else {
if (i >... | 0 | Kotlin | 0 | 0 | 752ac6ce9a4a06798fae5bd9da037290f7f42ecd | 1,686 | aoc-2022-kotlin | Apache License 2.0 |
src/main/kotlin/dev/shtanko/algorithms/leetcode/LeafSimilarTrees.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 | 1,468 | kotlab | Apache License 2.0 |
src/main/kotlin/io/github/dca/tax/Optimization.kt | laguiar | 476,662,074 | false | {"Kotlin": 43279} | package io.github.dca.tax
import io.github.dca.ZERO
/**
* From a given list of transactions, this function calculates the balance among all BUY and SELL transactions.
*
* The remaining list contains only BUY transactions with adjusted quantities and ready to be used for
* tax allowance calculations.
*
* @return... | 0 | Kotlin | 1 | 0 | 2b07dc89982390cf990765ac414f676aba69bf45 | 3,657 | dca-optimizer | MIT License |
compiler/src/main/kotlin/edu/cornell/cs/apl/viaduct/syntax/Operators.kt | s-ren | 386,161,765 | true | {"Kotlin": 878757, "Java": 43761, "C++": 13898, "Python": 11991, "Lex": 6620, "Dockerfile": 1844, "Makefile": 1785, "SWIG": 1212, "Shell": 698} | package edu.cornell.cs.apl.viaduct.syntax
import edu.cornell.cs.apl.prettyprinting.Document
import edu.cornell.cs.apl.prettyprinting.PrettyPrintable
import edu.cornell.cs.apl.viaduct.syntax.types.FunctionType
import edu.cornell.cs.apl.viaduct.syntax.values.Value
/**
* Determines how operators of the same [Precedence... | 0 | null | 0 | 0 | 337b3873e10f642706b195b10f939e9c1c7832ef | 7,890 | viaduct | MIT License |
src/main/java/challenges/cracking_coding_interview/object_oriented_design/jigsaw/Question.kt | ShabanKamell | 342,007,920 | false | null | package challenges.cracking_coding_interview.object_oriented_design.jigsaw
import java.util.*
/**
* Jigsaw: Implement an NxN jigsaw puzzle. Design the data structures and explain an algorithm to solve the puzzle.
* You can assume that you have a fitsWith method which, when passed two puzzle edges,
* returns true i... | 0 | Kotlin | 0 | 0 | ee06bebe0d3a7cd411d9ec7b7e317b48fe8c6d70 | 5,867 | CodingChallenges | Apache License 2.0 |
src/main/kotlin/g0901_1000/s0980_unique_paths_iii/Solution.kt | javadev | 190,711,550 | false | {"Kotlin": 4420233, "TypeScript": 50437, "Python": 3646, "Shell": 994} | package g0901_1000.s0980_unique_paths_iii
// #Hard #Array #Matrix #Bit_Manipulation #Backtracking
// #2023_05_09_Time_134_ms_(100.00%)_Space_34.8_MB_(76.92%)
class Solution {
private val row = intArrayOf(0, 0, 1, -1)
private val col = intArrayOf(1, -1, 0, 0)
private fun isSafe(grid: Array<IntArray>, rows... | 0 | Kotlin | 14 | 24 | fc95a0f4e1d629b71574909754ca216e7e1110d2 | 1,726 | LeetCode-in-Kotlin | MIT License |
src/com/talkspace/exercises/sum3.kt | BobString | 149,514,840 | false | null | package com.talkspace.exercises
// Write a function that takes as its arguments a sorted array of unique integers, `intArray`, and an integer, `int`, and returns 3 integers from `intArray` that sum up to `int`.
fun main(args: Array<String>) {
println(threeSum(listOf(-1, 2, 3, 4, 5, 7, 8, 12), 6)) // [4, 3, -1]
... | 0 | Kotlin | 0 | 0 | a3ef2830cf8266f7565250a841432abcea710efc | 1,246 | kotlin-exercises | MIT License |
백준/문제 추천 시스템 Version 2.kt | jisungbin | 382,889,087 | false | null | import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.util.TreeMap
private enum class ProblemLevelType {
EASY, HARD
}
private enum class ProblemNumberType {
SMALL, BIG
}
private data class ProblemInfo(val level: Int, val gro... | 0 | Kotlin | 1 | 10 | ee43375828ca7e748e7c79fbed63a3b4d27a7a2c | 8,420 | algorithm-code | MIT License |
src/aoc2022/Day01.kt | anitakar | 576,901,981 | false | {"Kotlin": 124382} | package aoc2022
import println
import readInput
import java.util.*
fun main() {
fun part1(input: List<String>): Int {
var sum = 0;
var maxSum = 0;
for (cur in input) {
if (cur.isEmpty()) {
if (sum > maxSum) {
maxSum = sum
}
... | 0 | Kotlin | 0 | 1 | 50998a75d9582d4f5a77b829a9e5d4b88f4f2fcf | 1,265 | advent-of-code-kotlin | Apache License 2.0 |
dcp_kotlin/src/main/kotlin/dcp/day250/day250.kt | sraaphorst | 182,330,159 | false | {"C++": 577416, "Kotlin": 231559, "Python": 132573, "Scala": 50468, "Java": 34742, "CMake": 2332, "C": 315} | //package dcp.day250
//
//import java.lang.NumberFormatException
//
//
//fun <T> List<T>.indexOfOrNull(t: T): Int? {
// val idx = this.indexOf(t)
// return if (idx == -1) null else idx
//}
//
//fun crypto_solve(word1: String, word2: String, wordSum: String): Map<Char, Int>? {
// // Collect all the characters a... | 0 | C++ | 1 | 0 | 5981e97106376186241f0fad81ee0e3a9b0270b5 | 4,523 | daily-coding-problem | MIT License |
app/src/main/java/com/keridano/soccersim/model/Match.kt | keridano | 489,078,382 | false | null | package com.keridano.soccersim.model
import com.keridano.soccersim.model.enum.Bonus
/**
* A football [Match] between two [Team]s
*
* @param homeTeam the home team
* @param awayTeam the away team
* @param homeTeamGoals the number of goals scored by the home team
* @param awayTeamGoals the number of goals scored ... | 0 | Kotlin | 0 | 0 | e2917b70246c42dd0c1b147270b8cf643ec1c96a | 2,549 | Soccer-Sim | MIT License |
src/Day21.kt | spaikmos | 573,196,976 | false | {"Kotlin": 83036} | fun main() {
fun parseInput(input: List<String>): Pair<MutableMap<String, Long>, MutableMap<String, List<String>>> {
val nums = mutableMapOf<String, Long>()
val ops = mutableMapOf<String, List<String>>()
val regexNum = """(.{4}): (\d+)""".toRegex()
val regexString = """(.{4}): (.{4})... | 0 | Kotlin | 0 | 0 | 6fee01bbab667f004c86024164c2acbb11566460 | 4,141 | aoc-2022 | Apache License 2.0 |
src/Day06.kt | 6234456 | 572,616,769 | false | {"Kotlin": 39979} | fun main() {
fun part1(input: List<String>): Int {
val s = input.first()
val l = s.length
val dp = Array<IntArray>(l+1){ IntArray(l+1){0} }
val lastPos = IntArray(26){0}
lastPos[s[0] - 'a'] = 1
var j = 1
var i = j + 1
while (j <= l){
whi... | 0 | Kotlin | 0 | 0 | b6d683e0900ab2136537089e2392b96905652c4e | 975 | advent-of-code-kotlin-2022 | Apache License 2.0 |
solutions/aockt/y2022/Y2022D05.kt | Jadarma | 624,153,848 | false | {"Kotlin": 435090} | package aockt.y2022
import aockt.y2022.Y2022D05.CraneDialect.*
import io.github.jadarma.aockt.core.Solution
object Y2022D05 : Solution {
/** Parses the input and returns the initial [CraneStackState] and a list of instructions. */
private fun parseInput(input: String): Pair<CraneStackState, List<CraneMove>> ... | 0 | Kotlin | 0 | 3 | 19773317d665dcb29c84e44fa1b35a6f6122a5fa | 4,241 | advent-of-code-kotlin-solutions | The Unlicense |
src/main/kotlin/day2.kt | tianyu | 574,561,581 | false | {"Kotlin": 49942} | import Move.*
import Outcome.*
import java.lang.IllegalStateException
private fun main() {
part1("The total score of (not) following the strategy guide is:") {
playRockPaperScissors { theirs, ours ->
val ourMove = ours.asMove()
val theirMove = theirs.asMove()
val outcome = outcome(theirMove, ou... | 0 | Kotlin | 0 | 0 | 6144cc0ccf1a51ba2e28c9f38ae4e6dd4c0dc1ea | 1,716 | AdventOfCode2022 | MIT License |
Advent-of-Code-2023/src/Day16.kt | Radnar9 | 726,180,837 | false | {"Kotlin": 93593} | private const val AOC_DAY = "Day16"
private const val TEST_FILE = "${AOC_DAY}_test"
private const val INPUT_FILE = AOC_DAY
/**
* Calculates the number of energized tiles starting from the initial position/movement.
*/
private fun energizedTiles(initialMovement: Movement, input: List<String>): Int {
val seen = mu... | 0 | Kotlin | 0 | 0 | e6b1caa25bcab4cb5eded12c35231c7c795c5506 | 4,158 | Advent-of-Code-2023 | Apache License 2.0 |
y2017/src/main/kotlin/adventofcode/y2017/Day13.kt | Ruud-Wiegers | 434,225,587 | false | {"Kotlin": 503769} | package adventofcode.y2017
import adventofcode.io.AdventSolution
object Day13 : AdventSolution(2017, 13, "Packet Scanners") {
override fun solvePartOne(input: String): String = parseInput(input)
.filter { (depth, range) -> depth % (range * 2 - 2) == 0 }
.entries
.sumOf { (depth, range) -> depth * range }
... | 0 | Kotlin | 0 | 3 | fc35e6d5feeabdc18c86aba428abcf23d880c450 | 794 | advent-of-code | MIT License |
com/ztoais/dailycoding/algoexpert/hard/FourNumberSum.kt | RanjithRagavan | 479,563,314 | false | {"Kotlin": 7371} | package com.ztoais.dailycoding.algoexpert.hard
/*
Write a function that takes in a non-empty array of distinct integers and an integer representing a target sum. The
function should find all quadruplets in the array that sum up to the target sum and return a tow-dimensional array of
all these quadruplets in no part... | 0 | Kotlin | 0 | 0 | a5f29dd82c0c50fc7d2490fd1be6234cdb4d1d8a | 2,435 | daily-coding | MIT License |
src/main/kotlin/days/Day11.kt | hughjdavey | 433,597,582 | false | {"Kotlin": 53042} | package days
import util.Utils
class Day11 : Day(11) {
private fun octos() = inputList.flatMapIndexed { y, s -> s.mapIndexed { x, c -> Octopus(c.toString().toInt(), Utils.Coord(x, y)) } }
override fun partOne(): Any {
return (1..100).fold(0 to octos()) { (flashes, octos), _ ->
flashes + ... | 0 | Kotlin | 0 | 0 | a3c2fe866f6b1811782d774a4317457f0882f5ef | 1,662 | aoc-2021 | Creative Commons Zero v1.0 Universal |
src/main/kotlin/days/Day3Data.kt | yigitozgumus | 572,855,908 | false | {"Kotlin": 26037} | package days
import utils.SolutionData
import utils.Utils.getPriority
fun main() = with(Day3Data()) {
solvePart1()
solvePart2()
}
class Day3Data : SolutionData(inputFile = "inputs/day3.txt") {
val part1Data = rawData.map { it.toList() }.map { it.chunked(it.size / 2) }
val part2Data = rawData.map { it.toList() }.... | 0 | Kotlin | 0 | 0 | 9a3654b6d1d455aed49d018d9aa02d37c57c8946 | 768 | AdventOfCode2022 | MIT License |
src/algorithmdesignmanualbook/datastructures/MatrixMultiplication.kt | realpacific | 234,499,820 | false | null | package algorithmdesignmanualbook.datastructures
import utils.PrintUtils
import kotlin.test.assertFails
typealias Matrix = Array<Array<Int>>
typealias Dimen = Pair<Int, Int>
fun main() {
val matA = arrayOf(arrayOf(1, 2, 3), arrayOf(3, 3, 3), arrayOf(5, 4, 3))
val matB = arrayOf(arrayOf(1, 3), arrayOf(2, 3)... | 4 | Kotlin | 5 | 93 | 22eef528ef1bea9b9831178b64ff2f5b1f61a51f | 1,449 | algorithms | MIT License |
_14_Longest_Common_Prefix/src/main/kotlin/LongestCommonPrefix.kt | Edsonctm | 584,187,846 | false | null | fun main() {
val strs = arrayOf("flower","flow","flight")
val strs2 = arrayOf("dog","racecar","car")
val strs3 = arrayOf("a")
val strs4 = arrayOf("reflower","flow","flight")
val strs5 = arrayOf("aaa","aa","aaa")
longestCommonPrefix(strs)
longestCommonPrefix(strs2)
longestCommonPrefix(st... | 0 | Kotlin | 0 | 0 | 5e9ae01b7ae68d2681f496bafa21bade33974535 | 1,305 | LeetCodeKotlin | MIT License |
2022/main/day_04/Main.kt | Bluesy1 | 572,214,020 | false | {"Rust": 280861, "Kotlin": 94178, "Shell": 996} | package day_04_2022
import java.io.File
fun part1(input: List<String>) {
val res = input.stream().mapToInt {
val range1str = it.split(',')[0]
val range2str = it.split(',')[1]
val range1 = (range1str.split('-')[0].toInt()..range1str.split('-')[1].toInt()).toSet()
val range2 = (range... | 0 | Rust | 0 | 0 | 537497bdb2fc0c75f7281186abe52985b600cbfb | 1,232 | AdventofCode | MIT License |
src/Day06.kt | sebastian-heeschen | 572,932,813 | false | {"Kotlin": 17461} | fun main() {
fun findMarker(input: List<String>, markerSize: Int) = input
.first()
.let { line ->
val packetMarker = line.windowed(markerSize)
.first { marker -> marker.toCharArray().distinct().count() == markerSize }
line.indexOf(packetMarker) + markerSize
... | 0 | Kotlin | 0 | 0 | 4432581c8d9c27852ac217921896d19781f98947 | 1,254 | advent-of-code-2022 | Apache License 2.0 |
src/Day03.kt | oleksandrbalan | 572,863,834 | false | {"Kotlin": 27338} | import kotlin.math.log2
fun main() {
val input = readInput("Day03")
.filterNot { it.isEmpty() }
val part1 = input.sumOf {
val first = it.substring(0, it.length / 2)
val second = it.substring(it.length / 2, it.length)
val result = first.content and second.content
log2(re... | 0 | Kotlin | 0 | 2 | 1493b9752ea4e3db8164edc2dc899f73146eeb50 | 897 | advent-of-code-2022 | Apache License 2.0 |
src/main/java/com/marcinmoskala/math/PermutationsExt.kt | MarcinMoskala | 87,302,297 | false | null | @file:JvmName("DiscreteMath")
@file:JvmMultifileClass
package com.marcinmoskala.math
/**
* Permutations are all different ways to arrange elements from some collection (https://en.wikipedia.org/wiki/Permutation).
* For sets it's number is n!, for lists it is n! / (n1! * n2! * ...) where n1, n2... are numbers eleme... | 4 | Kotlin | 17 | 178 | 17a7329af042c5de232051027ec1155011d57da8 | 1,801 | KotlinDiscreteMathToolkit | Apache License 2.0 |
src/main/kotlin/net/voldrich/aoc2022/Day03.kt | MavoCz | 434,703,997 | false | {"Kotlin": 119158} | package net.voldrich.aoc2022
import net.voldrich.BaseDay
// https://adventofcode.com/2022/day/3
fun main() {
Day03().run()
}
// Written mostly by copilot
class Day03 : BaseDay() {
override fun task1() : Int {
return input.lines().map { line ->
val (left, right) = splitStringIntoHalf(line... | 0 | Kotlin | 0 | 0 | 0cedad1d393d9040c4cc9b50b120647884ea99d9 | 1,665 | advent-of-code | Apache License 2.0 |
src/ad/kata/aoc2021/day08/DisplayTroubleshooting.kt | andrej-dyck | 433,401,789 | false | {"Kotlin": 161613} | package ad.kata.aoc2021.day08
import ad.kata.aoc2021.PuzzleInput
import ad.kata.aoc2021.extensions.splitTrim
class DisplayTroubleshooting(val entries: List<TroubleshootingEntry>) {
constructor(vararg entries: TroubleshootingEntry) : this(entries.toList())
fun deducedOutputValues() = entries.map { it.deduceO... | 0 | Kotlin | 0 | 0 | 28d374fee4178e5944cb51114c1804d0c55d1052 | 1,229 | advent-of-code-2021 | MIT License |
src/main/kotlin/com/psmay/exp/advent/y2021/Day02.kt | psmay | 434,705,473 | false | {"Kotlin": 242220} | package com.psmay.exp.advent.y2021
object Day02 {
enum class Direction(val keyword: String) {
FORWARD("forward"),
DOWN("down"),
UP("up");
companion object {
private val byKeyword = values().associateBy({ it.keyword }, { it })
fun valueOfKeyword(keyword: S... | 0 | Kotlin | 0 | 0 | c7ca54612ec117d42ba6cf733c4c8fe60689d3a8 | 3,031 | advent-2021-kotlin | Creative Commons Zero v1.0 Universal |
algorithms/src/main/kotlin/io/nullables/api/playground/algorithms/PrimMST.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,437 | gradle-kotlin-sample | Apache License 2.0 |
challenges/hacker-rank/kotlin/src/main/kotlin/com/raphaelnegrisoli/hackerrank/hashmaps/CountTriplets.kt | rbatista | 36,197,840 | false | {"Scala": 34929, "Kotlin": 23388} | /**
* https://www.hackerrank.com/challenges/count-triplets-1/
*/
package com.raphaelnegrisoli.hackerrank.hashmaps
import java.math.BigInteger
fun countTriplets(arr: List<Long>, ratio: Long): BigInteger {
val singlets = mutableMapOf<Long, BigInteger>()
val doublets = mutableMapOf<Pair<Long, Long>, BigInteg... | 2 | Scala | 0 | 0 | f1267e5d9da0bd5f6538b9c88aca652d9eb2b96c | 1,347 | algorithms | MIT License |
src/com/ncorti/aoc2022/Day03.kt | cortinico | 571,724,497 | false | {"Kotlin": 5773} | package com.ncorti.aoc2022
fun Char.priority(): Int = when {
this.isLowerCase() -> this - 'a' + 1
else -> this - 'A' + 27
}
fun String.splitHalf(): List<String> =
listOf(this.substring(0, this.length / 2), this.substring(this.length / 2))
fun List<String>.findCommonChar(): Char {
var commonChars = this.first... | 4 | Kotlin | 0 | 1 | cd9ad108a1ed1ea08f9313c4cad5e52a200a5951 | 777 | adventofcode-2022 | MIT License |
src/Day06.kt | JohannesPtaszyk | 573,129,811 | false | {"Kotlin": 20483} | fun main() {
fun List<String>.findMarkerWithLength(markerLength: Int) = map { line ->
var marker = ""
for (i in 0..line.length) {
val markerCandidate = line.substring(i, i + markerLength)
val chars = markerCandidate.toList().distinct()
val hasDuplicates = chars.s... | 0 | Kotlin | 0 | 1 | 6f6209cacaf93230bfb55df5d91cf92305e8cd26 | 987 | advent-of-code-2022 | Apache License 2.0 |
src/exercises/Day02.kt | Njko | 572,917,534 | false | {"Kotlin": 53729} | // ktlint-disable filename
package exercises
import readInput
fun main() {
fun part1(input: List<String>): Int {
var playerWin = 0
input.forEach { line ->
when (line) {
"B X" -> playerWin += 1 // loss with rock
"C Y" -> playerWin += 2 // loss with paper
... | 0 | Kotlin | 0 | 2 | 68d0c8d0bcfb81c183786dfd7e02e6745024e396 | 2,145 | advent-of-code-2022 | Apache License 2.0 |
src/main/kotlin/nl/tiemenschut/aoc/y2023/day14.kt | tschut | 723,391,380 | false | {"Kotlin": 61206} | package nl.tiemenschut.aoc.y2023
import nl.tiemenschut.aoc.lib.dsl.aoc
import nl.tiemenschut.aoc.lib.dsl.day
import nl.tiemenschut.aoc.lib.util.grid.CharGridParser
import nl.tiemenschut.aoc.lib.util.grid.Grid
import nl.tiemenschut.aoc.lib.util.points.by
fun main() {
aoc(CharGridParser) {
puzzle { 2023 day... | 0 | Kotlin | 0 | 1 | a1ade43c29c7bbdbbf21ba7ddf163e9c4c9191b3 | 2,950 | aoc-2023 | The Unlicense |
src/main/kotlin/days/day02.kt | josergdev | 573,178,933 | false | {"Kotlin": 20792} | package days
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.streams.asSequence
sealed interface Option
object Rock : Option
object Paper : Option
object Scissors : Option
fun String.parseOption() = when (this) {
"A", "X" -> Rock
"B", "Y" -> Paper
"C", "Z" -> Scissors
else -> thro... | 0 | Kotlin | 0 | 0 | ea17b3f2a308618883caa7406295d80be2406260 | 1,700 | aoc-2022 | MIT License |
endlessRunnersGame/src/main/kotlin/cz/woitee/endlessRunners/game/algorithms/dfs/SearchStatsSummer.kt | woitee | 219,872,458 | false | null | package cz.woitee.endlessRunners.game.algorithms.dfs
import java.util.*
import kotlin.repeat
/**
* A methods that averages statistics of searches to batches and prints them once in a while.
*
* @param sumEvery Number of iterations after we perform the averaging and print.
* @param callback What should happen afte... | 0 | Kotlin | 0 | 1 | 5c980f44397f0b4f122e7b2cb51b82cf1c0419df | 2,756 | endlessRunners | Apache License 2.0 |
src/Day05.kt | amelentev | 573,120,350 | false | {"Kotlin": 87839} | fun main() {
val input = readInput("Day05")
run {
var seeds = input[0].substringAfter("seeds: ").split(' ').map { it.toLong() }.toMutableSet()
var next = mutableSetOf<Long>()
var i = 3
while (i < input.size) {
if (input[i].isBlank()) {
seeds = (seeds +... | 0 | Kotlin | 0 | 0 | a137d895472379f0f8cdea136f62c106e28747d5 | 2,157 | advent-of-code-kotlin | Apache License 2.0 |
src/Day11.kt | MartinsCode | 572,817,581 | false | {"Kotlin": 77324} |
fun main() {
class Monkey(details: List<String>) {
val items = ArrayDeque<Long>()
var operation: String = ""
var test: Int = 0 // seems like all are "divisible by", so we only save the int
var trueReceiver: Int = 0
var falseReceiver: Int = 0
var myNumber: Int = 0
... | 0 | Kotlin | 0 | 0 | 1aedb69d80ae13553b913635fbf1df49c5ad58bd | 8,000 | AoC-2022-12-01 | Apache License 2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.