This file contains hidden or 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
/** | |
* consider all positive integers starting at 2. | |
* add 2 to the results. cross off every 2nd remaining number. | |
* The next number is 3, add it to the results. cross off every 3rd remaining number. | |
* The next number is 5, add it to the results. cross off every 5th remaining number. | |
* The next number is 7, add it to the results. cross off every 7th remaining number. | |
* etc | |
*/ | |
private fun lordicNumbers(size: Int): List<Int> { | |
if (size <= 0) return emptyList() |
This file contains hidden or 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
package aoc2015 | |
import kotlinx.coroutines.TimeoutCancellationException | |
import kotlinx.coroutines.async | |
import kotlinx.coroutines.coroutineScope | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
import kotlinx.coroutines.withTimeout | |
import kotlinx.coroutines.withTimeoutOrNull |
This file contains hidden or 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.io.FileInputStream | |
import java.util.* | |
// https://www.hackerrank.com/challenges/picking-numbers/problem | |
// Complete the pickingNumbers function below. | |
fun pickingNumbers(a: Array<Int>): Int { | |
val counts = a.groupingBy{ it }.eachCount() | |
val entries = counts.entries.asSequence().sortedBy { e -> e.key }.toList() | |
var maxLen = 0 |
This file contains hidden or 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.Duration; | |
import java.util.concurrent.CountDownLatch; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.LinkedBlockingQueue; | |
import java.util.concurrent.ThreadFactory; | |
import java.util.concurrent.ThreadPoolExecutor; | |
import java.util.concurrent.TimeUnit; | |
import java.util.concurrent.atomic.AtomicInteger; | |
/** |
This file contains hidden or 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.*; | |
import org.junit.jupiter.api.*; | |
public class LargestRectangleUnderHistogram { | |
public static int largestRectangleArea(int[] heights) { | |
if (heights.length < 1) return 0; | |
int maxArea = 0; | |
Deque<Integer> stack = new ArrayDeque<>(heights.length); |
This file contains hidden or 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 std.algorithm; | |
import std.array; | |
import std.conv; | |
import std.exception; | |
import std.stdio; | |
import std.string; | |
import std.traits; | |
alias Digit = bool[7]; |
This file contains hidden or 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
def make_change(amount, coins): | |
coins.sort() | |
def _make_change(amount, idx, result): | |
if amount == 0: | |
print result | |
return | |
for i in range(idx, len(coins)): | |
coin = coins[i] |
This file contains hidden or 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
object LargestProductOf3 | |
{ | |
def largestProductOf3(a: Array[Int]): Int = { | |
var (max, max2, max3) = (a(0), a(0), a(0)) | |
var (min, min2) = (a(0), a(0)) | |
a.foreach(i => { | |
if (i >= max) { | |
max3 = max2 | |
max2 = max |
This file contains hidden or 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 std.stdio, std.string, std.conv; | |
import std.algorithm; | |
import std.array; | |
auto readArray(T)() | |
{ | |
return array(map!(a => to!T(a))(stdin.readln().split())); | |
} | |
void main() |
This file contains hidden or 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 std.stdio; | |
auto search(int[] array, int target) | |
{ | |
int low = 0; | |
int high = array.length-1; | |
debug writeln("target = ", target); | |
while (low <= high) { | |
debug writefln("low=%d, high=%d", low, high); | |
auto mid = (low + high + 1) / 2; |