Summer Geek Quizz

Mitsu makes again his geek quizz in French which is some quizz on C# 3.0 and LINQ.

And I will do the same.

For my first quizz, the idea is to write a method which has an IEnumerable<IEnumerable<T>> parameter and which returns all the distinct elements which are on all sub-groups.

static void Main(string[] args)

{

    Console.WriteLine(“Test 1″);

    foreach (int i in GetElementsInAllGroups(new int[][] { new int[] { 1, 2, 3, 3 }, new int[] { 2, 2, 3, 4 } }))

        Console.WriteLine(“\t{0}”, i);

 

    Console.WriteLine(“Test 2″);

    foreach (int i in GetElementsInAllGroups(new int[][] { new int[] { 1, 2, 3, 3 }, new int[] { 2, 2, 3, 4 }, new int[]{1, 5, 6} }))

        Console.WriteLine(“\t{0}”, i);

 

    Console.WriteLine(“Test 3″);

    foreach (int i in GetElementsInAllGroups(new int[][] { new int[0] }))

        Console.WriteLine(“\t{0}”, i);

 

    Console.WriteLine(“Test 4″);

    foreach (int i in GetElementsInAllGroups(new int[][] { new int[] { 1, 2, 3, 3 }, new int[0] }))

        Console.WriteLine(“\t{0}”, i);

 

    Console.WriteLine(“Test 5″);

    foreach (int i in GetElementsInAllGroups(new int[][] { new int[] { 1, 2, 3, 3 }, null }))

        Console.WriteLine(“\t{0}”, i);

 

    Console.WriteLine(“Test 6″);

    foreach (int i in GetElementsInAllGroups(new int[][] { null, new int[] { 1, 2, 3, 3 } }))

        Console.WriteLine(“\t{0}”, i);

 

    Console.WriteLine(“Test 7″);

    foreach (int i in GetElementsInAllGroups(new int[][] { null }))

        Console.WriteLine(“\t{0}”, i);

 

    Console.WriteLine(“Test 8″);

    foreach (int i in GetElementsInAllGroups(new int[0][]))

        Console.WriteLine(“\t{0}”, i);

 

    Console.WriteLine(“Test 9″);

    foreach (int i in GetElementsInAllGroups<int>(null))

        Console.WriteLine(“\t{0}”, i);

}


 

public static IEnumerable<T> GetElementsInAllGroups<T>(IEnumerable<IEnumerable<T>> values)

{

    // Code it

}


The console result is:


Test 1
        2
        3
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9


Why 2 and 3 in the Test 1? Because 2 and 3 are the only ones on {1, 2, 3, 3} and {2, 2, 3, 4}.


Enjoy [:)]

This entry was posted in 7671, 7672, 8444. Bookmark the permalink.

2 Responses to Summer Geek Quizz

  1. Matthieu MEZIL says:

    Of course, I am waiting to a C#3 answer, not a C#2.
    Or a VB.Net 2008 if you prefer.

  2. Matthieu MEZIL says:

    Hey guys, are French the only one who know how to use LINQ ? [:P]

    blogs.codes-sources.com/…/comme-mitsu.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>