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 Smile

Published Fri, Aug 8 2008 8:37 by Matthieu MEZIL
Filed under: , ,

Comments

# re: Summer Geek Quizz

Of course, I am waiting to a C#3 answer, not a C#2.

Or a VB.Net 2008 if you prefer.

Friday, August 08, 2008 10:37 AM by Matthieu MEZIL

# re: Summer Geek Quizz

Hey guys, are French the only one who know how to use LINQ ? Stick out tongue

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

Saturday, August 09, 2008 3:08 PM by Matthieu MEZIL

Leave a Comment

(required) 
(required) 
(optional)
(required)