CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate: Blackjack total algorithm: Edit Log


Oct 2, 2012, 11:44 AM

Views: 5178
Blackjack total algorithm


I'm trying to write a command line blackjack spinoff in Perl, but am stuck on writing the algorithm that will generate/process all the possible totals from a set of cards. The main issue is that an Ace can have a value of 1 or 11 (or configurably, whatever I desire).

Below, I have a hand, which is an array of arrays, representing each card and their possible values:

my $hand =  
[1,11],[2],[1,11],[10] # Represents the values of Ace, Two, Ace, King.

I would like to generate another array of arrays, representing every possible combination of values:

my $combinations = 

I can then use this data to return an appropriate total based on a number of blackjack rules. In this case "14".

However, I can't get my head round the type of processing $hand requires in order to generate $combinations. My thought is it will have to be some kind of recursive process, reiterating per value of cards with multiple values.

I would really appreciate some advise on how to approach this task. Where do I begin!

Thanks alot,


(This post was edited by Zhris on Oct 2, 2012, 11:46 AM)

Edit Log:
Post edited by Zhris (Enthusiast) on Oct 2, 2012, 11:46 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives