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
private operator fun <E> List<E>.times(num: Int) = (1..num).flatMap { this } |
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
class Hand private constructor(val cards: List<Int>) { | |
val points = cards.sum() | |
val unusedAces = cards.count { it == 11 } | |
val canSplit = cards.size == 2 && cards[0] == cards[1] | |
val blackjack get() = cards.size == 2 && points == 21 | |
operator fun plus(card: Int) = Hand.fromCards(cards + card) | |
companion object { | |
fun fromCards(cards: List<Int>): Hand { |
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
class Hand private constructor(val cards: List<Int>) { | |
val points = cards.sum() | |
val unusedAces = cards.count { it == 11 } | |
val canSplit = cards.size == 2 && cards[0] == cards[1] | |
val blackjack get() = cards.size == 2 && points == 21 | |
} |
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 getBetSize(trueCount: Int, bankroll: Double): Double { | |
val bettingUnit = bankroll / 1000 | |
return (bettingUnit * (trueCount - 1)).coerceIn(25.0, 1000.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
sealed class Result<out T, out R> | |
class Success<out T>(val resp: T): Result<T, Nothing>() | |
class ErrorResult<out R>(val error: R): Result<Nothing, R>() |
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 org.junit.Test | |
open class KMeansSolver<P : Any>( | |
val createInitialMean: (List<P>) -> P, | |
val distanceBetween: (P, P) -> Double, | |
val calculateMean: (List<P>) -> P | |
) { | |
fun solve( | |
points: List<P>, | |
maxAvgError: Double |
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.math.abs | |
open class VectorQuantifier<P : Any>( | |
val distanceBetween: (P, P) -> Double, | |
val calculateMean: (List<P>) -> P, | |
val times: (P, Double) -> P | |
) { | |
fun quantify( | |
points: List<P>, | |
maxError: Double = 0.00001, |
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
for ((bet, playerHand) in betsAndHands) { | |
when { | |
playerHand.blackjack -> bankroll += bet * if (casinoHand.blackjack) 1.0 else 1.5 | |
playerHand.points > 21 -> bankroll -= bet | |
casinoHand.points > 21 -> bankroll += bet | |
casinoHand.points > playerHand.points -> bankroll -= bet | |
casinoHand.points < playerHand.points -> bankroll += bet | |
else -> bankroll -= bet | |
} | |
} |
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
cards.pop(6) |
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
val differenceInBankroll = bankroll - initialMoney | |
return differenceInBankroll |