This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const mem = std.mem; | |
const testing = std.testing; | |
pub fn ArrayDequeue(comptime T: type) type { | |
return struct { | |
const Self = @This(); | |
allocator: mem.Allocator, | |
data: []T, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const print = std.debug.print; | |
pub fn main() anyerror!void { | |
const cwd = std.fs.cwd(); | |
const file = try cwd.openFile("input1.txt", .{}); | |
var gp = std.heap.GeneralPurposeAllocator(.{ .safety = true }){}; | |
defer _ = gp.deinit(); | |
const allocator = gp.allocator(); | |
const content = try file.readToEndAlloc(allocator, 1 << 32); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const print = std.debug.print; | |
// always prints values that are divisible by 256 | |
// i.e. 0x1087cdc00 or 0x1087c3a00 | |
var foo: u8 align(256) = 92; | |
pub fn main() anyerror!void { | |
const bar: u8 align(256) = 92; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.flow.* | |
fun Flow<ByteArray>.toLineFlow(): Flow<String> = flow { | |
val buffer = StringBuilder() | |
val decoder = Charsets.UTF_8.newDecoder() | |
collect { byteArray -> | |
val charBuffer = decoder.decode(java.nio.ByteBuffer.wrap(byteArray)) | |
buffer.append(charBuffer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.delay | |
import kotlin.time.Duration.Companion.milliseconds | |
import kotlin.time.Duration.Companion.seconds | |
suspend fun multiplyWithDelay(a: Int, b: Int): Int { | |
delay(10.seconds) | |
return a * b | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Comparator | |
import java.util.PriorityQueue | |
import kotlin.math.absoluteValue | |
import kotlin.math.ceil | |
fun main() { | |
val input = listOf( | |
"..f.......", | |
"..w.......", | |
".fxfxx....", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val s3Client = S3Client() | |
val httpClient = HttpClient() | |
val rabbitMqClient = RabbitMqClient() | |
val jsonMapper = JsonMapper() | |
val userRepo = UserRepo() | |
val orderRepo = OrderRepo() | |
val auth = Auth() | |
val inventoryClient = InventoryClient(httpClient, jsonMapper) | |
val taxesClient = TaxesClient(httpClient, jsonMapper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(){List(3){readLine()!!.toDouble()}.run{Math.pow(max(),min())}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
println(solve1(File("input1.txt").readLines())) | |
} | |
fun solve1(input: List<String>): Int = | |
input.fold(0 to 0) { (m, acc), str -> if (str.isEmpty()) Math.max(m, acc) to 0 else m to acc + str.toInt() }.first | |
fun solve2(input: List<String>): Int = | |
input.fold(arrayListOf(0)) { acc, str -> if (str == "") acc.add(0) else acc[acc.lastIndex] += str.toInt(); acc }.sortedBy { -it }.take(3).sum() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.LocalDate; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.TreeMap; | |
public class DaysCalculator { | |
public static int calculate(List<Interval> input) { | |
TreeMap<LocalDate, Boolean> map = new TreeMap<LocalDate, Boolean>(); // true - begin, false - end | |
for (Interval interval : input) { |
NewerOlder