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
@file:Suppress("PackageDirectoryMismatch") | |
/* | |
* Copyright (c) 2018 Intrepid Pursuits,Inc. All rights reserved. | |
*/ | |
package kotlinx.coroutines.experimental.intrepid | |
import kotlinx.coroutines.experimental.* | |
import java.util.concurrent.PriorityBlockingQueue | |
import java.util.concurrent.TimeUnit |
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
040bce15188234923d3df6c460629e3af0d3d4d714d7da37d49d2d33de236f9ac5e1430a7d77617e6014b6884420a843dbdf27eac9f19a07976e57aeadc462211f |
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 kotlin.system.measureNanoTime | |
data class Product(val price: Double, val bought: Boolean) | |
fun main(args: Array<String>) { | |
val users = (1..50_000_000).map { Product(10.0, true) } | |
measureNanoTime { code1(users) } | |
measureNanoTime { code2(users) } |
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 kotlin.system.measureNanoTime | |
fun main(args: Array<String>) { | |
measureNanoTime { code1() } | |
measureNanoTime { code2() } | |
val tries = 100 | |
var sum1 = 0L | |
var sum2 = 0L | |
for (i in 1..tries) { |
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 Decision.* | |
import org.jetbrains.kotlin.backend.common.pop | |
fun generateDeck(): List<Int> = (List(4) { 10 } + (2..9) + 11) * 4 | |
fun generateDealerDeck() = (generateDeck() * 6).shuffled() | |
private operator fun <E> List<E>.times(num: Int) = (1..num).flatMap { this } | |
fun List<Int>.trueCount(): Int = -sumBy(::cardValue) * 52 / size |
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 decide(hand: Hand, casinoCard: Int, firstTurn: Boolean): Decision = when { | |
firstTurn && hand.canSplit && hand.cards[0] == 11 -> SPLIT | |
firstTurn && hand.canSplit && hand.cards[0] == 9 && casinoCard !in listOf(7, 10, 11) -> SPLIT | |
firstTurn && hand.canSplit && hand.cards[0] == 8 -> SPLIT | |
firstTurn && hand.canSplit && hand.cards[0] == 7 && casinoCard <= 7 -> SPLIT | |
firstTurn && hand.canSplit && hand.cards[0] == 6 && casinoCard <= 6 -> SPLIT | |
firstTurn && hand.canSplit && hand.cards[0] == 4 && casinoCard in 5..6 -> SPLIT | |
firstTurn && hand.canSplit && hand.cards[0] in 2..3 && casinoCard <= 7 -> SPLIT | |
hand.unusedAces >= 1 && hand.points >= 19 -> STAND | |
hand.unusedAces >= 1 && hand.points == 18 && casinoCard < 9 -> STAND |
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 List<Int>.trueCount(): Int = -sumBy(::cardValue) * 52 / size |
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 cardValue(card: Int) = when (card) { | |
in 2..6 -> 1 | |
10, 11 -> -1 | |
else -> 0 | |
} |
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 generateDeck(): List<Int> = (List(4) { 10 } + (2..9) + 11) * 4 |
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 generateDealerDeck() = (generateDeck() * 6).shuffled() |
OlderNewer