Skip navigation

Creating combinations of list applescript

307 Views 3 Replies Latest reply: Jul 1, 2012 12:19 PM by twtwtw RSS
s.i.m Level 1 Level 1 (0 points)
Currently Being Moderated
Jul 1, 2012 10:00 AM

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:)

  • rccharles Level 5 Level 5 (5,155 points)
    Currently Being Moderated
    Jul 1, 2012 10:37 AM (in response to s.i.m)

    Usually, such things are done through recursion:

    5! = 5 * 4!

     

    etc.

     

    Robert

  • twtwtw Level 5 Level 5 (4,585 points)
    Currently Being Moderated
    Jul 1, 2012 12:18 PM (in response to s.i.m)

    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

  • twtwtw Level 5 Level 5 (4,585 points)
    Currently Being Moderated
    Jul 1, 2012 12:19 PM (in response to twtwtw)

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

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.