Coding help needed

I’m trying to make a simple poker hand app where users can decide which hand is the winner quickly.
This is supposed to simulate a Texas hold’em style Poker game. I only have two hands since this is my first try. Once the 5 table cards and the two cards for each player is displayed, I’m trying to get all possible hands of 5 from 7 for each player. I’m trying to create code like this using Thunkable blocks.
List<List> p1Possible = new ArrayList<>();

    for (int i = 0; i < numbers.size(); i++) {
        int first = numbers.get(i);
        for (int j = i + 1; j < numbers.size(); j++) {
            int second = numbers.get(j);
            for (int k = j + 1; k < numbers.size(); k++) {
                int third = numbers.get(k);
                for (int l = k + 1; l < numbers.size(); l++) {
                    int fourth = numbers.get(l);
                    for (int m = l + 1; m < numbers.size(); m++) {
                        int fifth = numbers.get(m);
                        List<Integer> combination = new ArrayList<>();
                        combination.add(first);
                        combination.add(second);
                        combination.add(third);
                        combination.add(fourth);
                        combination.add(fifth);
                        p1Possible.add(combination);
                    }
                }
            }
        }
    }
   
    return p1Possible;

How can I do this?

This is what I have so far, and I only see 3 combinations.


Please help me!

1 Like

You are using the same variable (i) to all loops. You need to use a separate variable for each loop.

Use the dropdown menu to change the veriable
image

1 Like

Thank you so much.
When I tried renaming my variable it tried to rename all my i’s into j’s.
So I looked at the variable I have created elsewhere and used those.
And now I have way too many lists.
This is my fixed list. And I feel like there is something wrong since I see more than 21 combinations of 5 elements.
When I tried creating an app variable for each of my i’s and j’s, the code didn’t work at all.
I know it’s difficult to help me without seeing everything.
Can you help me a little more?

I spent a little time and I was able to fix my error. Special thanks to @muneer for reminding me to change the variables.
Here is the edited code that works for me now.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.