[Community Puzzle] Card Counting when easily distracted

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Lisa-Has-Ideas,validated by @cedricdd,@5922 and @_CG_XorMode.
If you have any issues, feel free to ping them.

1 Like

Another hit from Lisa-Has-Ideas. Reminds me of the movie “Rain Man” :smiley:

1 Like

Thanks. I’m so glad people enjoy my puzzles. I love creating them.


I loved this puzzle. It was educational and really fitting to its diffictulty. Its difficulty is visible at a glance and its description is clear.
Solving it in C++ was a challenge, but that was entirely my choice))

If I had any ideas or criticisms, I’d ask you to reduce the number of tests. I don’t see why you would need this many.
As for ideas, I expected thoughts to be more unique in those different test cases. I even thought that you could collaborate with someone and make an ARG where your answers would be part of a clue for something else. Since puzzle is easy enough, it’s rather accessible for anyone with a passing interest in programming.

And judging by other answers, I need to check out other puzzles of yours!


Ha, yes, there are a lot of tests. What I did was I created a program to generate (randomly) all the test cases, and since I had done that, I wanted to “get my money’s worth” out of it.:slight_smile:
True it is probably excessive, but from feedback on prior puzzles I created, people seem to really like lots of test cases. (I know I personally get a little “dopamine hit” every time I see something go green.)

I tried to put humor in the inputs for those interested enough to look (probably not many will, but its sort of like an Easter egg I guess… anyways that was my thought.).

I LOVE that idea about “your answers would be part of a clue for something else.”… I will keep that idea in mind and see how that might germinate into something. Thank you for that inspiration.

Yes, please do play all my other puzzles :slight_smile:

1 Like

Hi, is streamofconciousness a list type with one number (or word) for each cases or is it just kind of a big box with anything inside

in fact I just don’t understand why it doesn’t work, this is my code:
import sys

import math

Auto-generated code below aims at helping you parse

the standard input according to the problem statement.

stream_of_consciousness = input()

bust_threshold = int(input())




percentage = [4/52,4/52,4/52,4/52,4/52,4/52,4/52,4/52,4/52,16/52]



for i in stream_of_consciousness:

if i in card :


for i in res:


for i in range (len(percentage)):

if i <= bust_threshold :




Write an answer using print

To debug: print(“Debug messages…”, file=sys.stderr, flush=True)


Hey thanks for playing my puzzle. You can see in the test cases what stream of consciousness looks like.

It is one long string.

Remember that just because something is in the stream of consciousness doesn’t mean it’s a card.

For example if one chunk in the stream of consciousness is “2-for-1 buffet”, that doesn’t mean that you have seen a “2” card.

so double check on your logic

Hi @Lisa-Has-Ideas, sorry to annoy you,

I will describe what my program do with “Test 1” :

1 : I split stream_of_consciousness by ‘.’
2 : I remove invalid elements : ‘some distraction’ and ‘another distraction’
3 : So, there are 45 valids cards already played : 2223334445555678678678678TTTTJJJJQQQQKKKKAAAA
4 : Only 2 remainings cards : 2,3 are < 4 :bustThreshold

So my result is 2/7 : 29% and not 67%

I don’t understand in which step I’m wrong. Can you help me ^^ ?

Hi Stat –
You are not annoying … I learn from people’s questions. So thank you for the question.

Look back at the “Test 1” input. There are four 9s (in other words “9999”) that you have ignored. Don’t ignore those :slight_smile:

1 Like

Thanks a lot for your fast response,

it was just a stupid mistake of my part : write to fast ‘9,’ instead of ‘9’ in my list with all card values. Didn’t think the error would be from here x)

I just finished it now. Thanks for this great puzzle.

1 Like

HI could you explain the rules
for test1
it remains 2,3,4 in the deck.
so what is mean 2nd string 4 ? what the % of getting 4 ? 33%
also what is mean bustThreshold with simple words. google translate cant translate bust

1 Like

Hi Alex – Thanks for playing my puzzle.

The puzzle states: (The bustThreshold is what would make your hand “go-bust”/lose by going over 21. It isn’t anything you need to calculate; it is provided.)
See image from Wikipedia, especially the part I highlighted

In Blackjack, you do not want the cards in your hand to go over a value of 21. If you do, you lose. So in the puzzle I provide the value you do not want. For example, your hand has a value of 18, so you know that you do NOT want a 4 or higher, because that will make it total of 22 or more and will make you “go bust” (aka lose)

In other words: In the puzzle I could have said “your hand is 18, what is the chance of getting a card that doesn’t makes you bust (i.e., makes your hand-total not exceed 21)?” But I kept it simple and just provided the bust-threshold for you.

Does that help?


thank you for answer
so I understood bust is like burn down/out my score aka loose… ok… I know rules of blackjack… but I cant understand till the end what I should calculate

so from mentioned above task >> it remains 2,3,4 in the deck.
and the 2nd string (4) means if I get 4 I loose… ok… it’s mean that I have 18… ok…
but how from that I should get 67% ? do you mean we should calculate % for all cards that will not busted us (all cards that give us <= 21 )?

yes, exactly :slight_smile:

thank you sir

1 Like

finally I did :slight_smile:
your A=1 made me to think little bit :slight_smile:

1 Like

Is test #23 broken ?

bust : 2

thats clearly 3 cards on a possibility of 47 (52-5)
3/47 = 6.38% but the test says its supposed to be 4%
even if its rounded up from 3.51 to 4.49 I dont understand how it could be 4% for a 2 on next draw

thank you !

How’ve you got 3 cards? There are 4 aces, everything else is bust and 2 of the aces have already been dealt.


Hi. Thanks for playing my puzzle. I think RoboStac responded well to your concern. Two aces have been played. Therefore 2 aces remain. Hopefully that gets you going. :slight_smile:

1 Like