I took a course in probability a few years ago and have not made my fortune in the casino yet. This program can help to count cards in single-deck blackjack and determine the odds of going bust based on your hand. The interface is quite crude :)

This is certainly not as cool as a system which is easy to memorize, but I think it's kindof cool. Here goes:
#!/usr/bin/perl ## # # Card Counter : This is a basic single-deck blackjack card counter. + It calculates the probability # of going bust based on the cards which have been pla +yed. I'd love to generalize # this some more as there are 5^12 possible states for + the deck when playing # from a single deck, and this is too much for me to m +emorize. # # Rohit Kumar Mehta # # 2003.07.17 # ## use strict; my @deck; my $num; sub showdeckstats { my @deck=@_; my $totalcards=0; my @prob; print "\t\t+---+---+---+---+---+---+---+---+---+---+---+---+---+\n"; print "card key\t| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 1 +2|\n"; print "\t\t+---+---+---+---+---+---+---+---+---+---+---+---+---+\n"; print "card value\t| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| J | Q | K | + A |\n"; print "\t\t+===+===+===+===+===+===+===+===+===+===+===+===+===+\n"; print "# in deck\t"; for (my $count=0; $count<=12; $count++) { print "| $deck[$count] "; $totalcards += $deck[$count]; } print "|\n\t\t+---+---+---+---+---+---+---+---+---+---+---+---+---+\ +n"; print "\n\t\t\t+----+----+----+----+----+----+----+----+----+\n"; print "value of your hand\t| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | + 20 |\n"; print "\t\t\t+====+====+====+====+====+====+====+====+====+\n"; print "prob bust next hit\t|"; for (my $val=12; $val<21; $val++) { my $bust=0; my $nobust=0; for (my $card=0; $card<=12; $card++) { my $cardval; if ($card == 12) { $cardval=1; } elsif ($card >7) { $cardval=10; } else { $cardval = $card +2 } if ( ($val + $cardval) > 21 ) { $bust=$bust+$deck[$card]; } else { $nobust=$nobust+$deck[$card]; } } my $prob; $prob = $bust/($bust+$nobust); printf ("%1.2f|",$prob); } print "\n\t\t\t+----+----+----+----+----+----+----+----+----+\n"; } ##### # # initialize cards # ##### for (my $card = 0; $card <=12; $card++) { $deck[$card]=4; } while (1) { showdeckstats(@deck); print "\nenter the key number of the card you wish to subtract: "; $num=<stdin>; chomp $num; $deck[$num]--; }

In reply to blackjack card counter by Cmdr_Tofu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.