#feed
Title
# feed
t

thomasnield

08/02/2018, 4:33 PM
Looking forward to read this in detail later. Honestly I'd love to see more topics like this that uncover mathematical patterns and models in programming, especially practical ones. This kind of curiosity is what the Kotlin community needs more of.
m

marcinmoskala

08/02/2018, 8:14 PM
Ow, I don't think this article will satisfy you then 😕 It is just a simulation. Title was changed by freeCodeCamp.
I wish to have a time to go into mathematics of card counting
t

thomasnield

08/03/2018, 2:33 AM
I think once you program against a non-deterministic problem that attempts to mitigate against uncertainty, you're entering probability and mathematical modeling realm.
c

cedric

08/06/2018, 6:49 PM
@marcinmoskala Nice article. I'm a bit puzzled by this piece of code though:
Copy code
``val blackjack get() = cards.size == 2 && points == 21``
``points``
should have multiple potential values depending on the number of aces
so your
``cards.sum()``
should return multiple values
m

marcinmoskala

08/06/2018, 7:11 PM
This is a good and probably more intuitive idea, but in my implementation I was trying to make it as simple as possible and Aces are always optimized (if there is less then 21 points, they are treated as 11, if more then we change them to 1 one after another)
Copy code
``````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 {
var hand = Hand(cards)
while (hand.unusedAces >= 1 && hand.points > 21) {
hand = Hand(hand.cards - 11 + 1)
}
return hand
}
}
}``````
c

cedric

08/07/2018, 11:43 PM
Then your algorithm is probably not as performant as it could be, which might explain why you didn't win as much money as you thought
m

marcinmoskala

08/08/2018, 9:38 AM
Why? Blackjack situation is only when you you have 21 in first 2 cards. "If a player receives 21 on the 1st and 2nd card it is considered a "natural" or "blackjack" and the player is paid out immediately unless dealer also has a natural" Wiki Also in all other situations it is fair to treat Ace as 11 if we have less then 21 points, and as 1 if we have more.
2 Views