3 Replies Latest reply: Jul 1, 2012 12:19 PM by twtwtw
Level 1 (0 points)

Hey guys,

Recently I posted a pokerscript, I want to test several solutions to calculating odds, I have this list: {"1-S", "2-S", "3-S", "4-S", "5-S", "6-S", "7-S", "8-S", "9-S", "10-S", "11-S", "12-S", "13-S", "14-S", "1-H", "2-H", "3-H", "4-H", "5-H", "6-H", "7-H", "8-H", "9-H", "10-H", "11-H", "12-H", "13-H", "14-H", "1-R", "2-R", "3-R", "4-R", "5-R", "6-R", "7-R", "8-R", "9-R", "10-R", "11-R", "12-R", "13-R", "14-R", "1-K", "2-K", "3-K", "4-K", "5-K", "6-K", "7-K", "8-K", "9-K", "10-K", "11-K", "12-K", "13-K", "14-K"} of which i want to have every combination of five possible ( not including doubles that are in a different sequence) added to a list.

Do you guys have any ideas how to fabricate an algorithm that does that, or do you have any advice in general?

this is an unfinished script i thought could work as soon as i correct it

"

spawnallcombos()

on spawnallcombos()

set total1 to {"1-S", "2-S", "3-S", "4-S", "5-S", "6-S", "7-S", "8-S", "9-S", "10-S", "11-S", "12-S", "13-S", "14-S", "1-H", "2-H", "3-H", "4-H", "5-H", "6-H", "7-H", "8-H", "9-H", "10-H", "11-H", "12-H", "13-H", "14-H", "1-R", "2-R", "3-R", "4-R", "5-R", "6-R", "7-R", "8-R", "9-R", "10-R", "11-R", "12-R", "13-R", "14-R", "1-K", "2-K", "3-K", "4-K", "5-K", "6-K", "7-K", "8-K", "9-K", "10-K", "11-K", "12-K", "13-K", "14-K"}

set a to 1

set b to 2

set c to 3

set d to 4

set e to 5

set f to {}

repeat 258960 times

if a ≤ 51 then

set bas1 to item a of total1

set bas2 to item b of total1

set bas3 to item c of total1

set bas4 to item d of total1

set bas5 to item e of total1

set f to f & {bas1, bas2, bas3, bas4, bas5}

end if

if e is equal to 56 then

set d to d + 1

set e to e + 1

else

set e to e + 1

end if

if d is equal to 55 then

set c to c + 1

set d to c + 1

else

set d to d + 1

end if

if c is equal to 54 then

set b to b + 1

set c to b + 1

else

set c to c + 1

end if

if b is equal to 55 then

set a to a + 1

set b to b + 1

else

set b to b + 1

end if

end repeat

return f

end spawnallcombos

"

Help and advice is very much appreciated, thank you so much in advance:)

• 1. Re: Creating combinations of list applescript
Level 5 (5,360 points)

Usually, such things are done through recursion:

5! = 5 * 4!

etc.

Robert

• 2. Re: Creating combinations of list applescript
Level 5 (4,690 points)

The algorithm to do this would be something like what follows.  be aware, however:

1. this only gives you a list of unique combinations, not how frequently they occur
2. even with the optimizations I've added this is going to take a **** of a long time to run.

you'd really be happier using statistical permutations and just calculating the values, but...

property cards : {"1-S", "2-S", "3-S", "4-S", "5-S", "6-S", "7-S", "8-S", "9-S", "10-S", "11-S", "12-S", "13-S", "14-S", "1-H", "2-H", "3-H", "4-H", "5-H", "6-H", "7-H", "8-H", "9-H", "10-H", "11-H", "12-H", "13-H", "14-H", "1-R", "2-R", "3-R", "4-R", "5-R", "6-R", "7-R", "8-R", "9-R", "10-R", "11-R", "12-R", "13-R", "14-R", "1-K", "2-K", "3-K", "4-K", "5-K", "6-K", "7-K", "8-K", "9-K", "10-K", "11-K", "12-K", "13-K", "14-K"}

property output : {}

repeat with i from 1 to (count of my cards) - 4

repeat with j from i + 1 to (count of my cards) - 3

repeat with k from j + 1 to (count of my cards) - 2

repeat with l from k + 1 to (count of my cards) - 1

repeat with m from l + 1 to count of my cards

set end of my output to {item i of my cards, item i of my cards, item i of my cards, item i of my cards, item i of my cards}

end repeat

end repeat

end repeat

end repeat

end repeat

Message was edited by: twtwtw - added a missing 'my' before the variable 'output'.  necessary for optimization

• 3. Re: Creating combinations of list applescript
Level 5 (4,690 points)

p.s. - forgot a 'my' keyword.  check the updated version in the forum.