Find possible variations of one item out of multiple baskets.

Posted by tugberk on Programmers See other posts from Programmers or by tugberk
Published on 2014-02-06T09:56:48Z Indexed on 2014/06/06 21:50 UTC
Read the original article Hit count: 194

Filed under:
|
|

I have three baskets of balls and each of them has 10 balls which have the following numbers:

Basket 1: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Basket 2: 11, 12, 13, 14, 15, 16, 17, 18, 19, 20

Basket 3: 21, 22, 23, 24, 25, 26, 27, 28, 29, 30

What would be the possible variations If I were to pick one ball from each basket? I guess this is called as Probability in Mathematics but not sure. How would you write this code in C# (or any other programming language) to get the correct results?

Edit:

Based on @Kilian Foth's comment, here is the solution in C#:

class Program
{
    static void Main(string[] args)
    {
        IEnumerable<string> basket1 = new List<string> { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
        IEnumerable<string> basket2 = new List<string> { "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" };
        IEnumerable<string> basket3 = new List<string> { "21", "22", "23", "24", "25", "26", "27", "28", "29", "30" };

        foreach (var item1 in basket1)
        foreach (var item2 in basket2)
        foreach (var item3 in basket3)
        {
            Console.WriteLine("{0}, {1}, {2}", item1, item2, item3);
        }

        Console.ReadLine();
    }
}

© Programmers or respective owner

Related posts about c#

Related posts about algorithms