<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx</link><description>Jomo Fisher--Luke Hoban wrote something in a blog entry that resonated with me: One of the most striking features of F# code is that it is very terse - ideas can typically be expressed with a small amount of code. Don Syme once mentioned (I'm paraphrasing)</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6343577</link><pubDate>Sat, 17 Nov 2007 23:43:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6343577</guid><dc:creator>Jason Prado</dc:creator><description>&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; l = [['a','b','1'],['c','d','2'],['e','f','3']]&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; [list(i) for i in zip(*l)]&lt;/p&gt;
&lt;p&gt;[['a', 'c', 'e'], ['b', 'd', 'f'], ['1', '2', '3']]&lt;/p&gt;
&lt;p&gt;Is that what you're going for? 1 line of Python if it's not cheating to use zip.&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6343895</link><pubDate>Sun, 18 Nov 2007 00:01:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6343895</guid><dc:creator>pat marks</dc:creator><description>&lt;p&gt;let lolpivot (l : 'a list list) = [ for i in {0 .. (length (nth l 0))-1} -&amp;gt; [ for j in {0 .. (length l)-1} -&amp;gt; &amp;nbsp;nth (nth l j) i]];;&lt;/p&gt;
&lt;p&gt;It's not super pretty but it works&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6343950</link><pubDate>Sun, 18 Nov 2007 00:04:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6343950</guid><dc:creator>kfarmer@microsoft.com</dc:creator><description>&lt;p&gt;Matrix Transposition? &amp;nbsp;You could do it in (I think) 1 line of C#3, using indexing and List&amp;lt;T&amp;gt;'s ForEach method :)&lt;/p&gt;
&lt;p&gt;The immediate way I can see involves indexing operations, which can't be done directly in a singley-linked list, so my solution wouldn't be as efficient as James's, I suspect.&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6344656</link><pubDate>Sun, 18 Nov 2007 00:56:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6344656</guid><dc:creator>Keith</dc:creator><description>&lt;p&gt;let rec pivot = function&lt;/p&gt;
&lt;p&gt;| [] -&amp;gt; []&lt;/p&gt;
&lt;p&gt;| [l] -&amp;gt; List.map (fun x -&amp;gt; [x]) l&lt;/p&gt;
&lt;p&gt;| l::ls -&amp;gt; List.map2 (fun x xs -&amp;gt; x::xs) l (pivot ls)&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6345651</link><pubDate>Sun, 18 Nov 2007 01:53:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6345651</guid><dc:creator>Torsten</dc:creator><description>&lt;p&gt;One line in S (to be more specific, the R implementation of the S language, www.r-project.org):&lt;/p&gt;
&lt;p&gt;# normally, you wouldn't use a nested list in S for this kind of data&lt;/p&gt;
&lt;p&gt;have &amp;lt;- list(list(&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;1&amp;quot;), list(&amp;quot;c&amp;quot;, &amp;quot;d&amp;quot;, &amp;quot;2&amp;quot;), list(&amp;quot;e&amp;quot;, &amp;quot;f&amp;quot;, &amp;quot;3&amp;quot;))&lt;/p&gt;
&lt;p&gt;want &amp;lt;- do.call(&amp;quot;mapply&amp;quot;, args=c(list(FUN=c, SIMPLIFY=FALSE), have))&lt;/p&gt;
&lt;p&gt;This is similar to the Python example. Basically, I'm implementing the &amp;quot;zip&amp;quot; function on the fly. In contrast to &amp;quot;zip&amp;quot; in Python, the result isn't truncated to the length of the shortest entry if the entries of &amp;quot;have&amp;quot; aren't of the same length. Instead, shorter entries are &amp;quot;enlarged&amp;quot; by recycling their elements. If required, I'm sure one could change this to the Python behaviour in the very same line.&lt;/p&gt;
&lt;p&gt;Of course, if &amp;quot;have&amp;quot; is a matrix and you're after its transpose, you don't use a list in S:&lt;/p&gt;
&lt;p&gt;# turning &amp;quot;have&amp;quot; into a matrix (assuming each entry of &amp;quot;have&amp;quot; is a column&lt;/p&gt;
&lt;p&gt;have.matrix &amp;lt;- matrix(unlist(have), ncol=length(have))&lt;/p&gt;
&lt;p&gt;# its transpose&lt;/p&gt;
&lt;p&gt;t(have.matrix)&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6346464</link><pubDate>Sun, 18 Nov 2007 02:39:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6346464</guid><dc:creator>Ian McMeans</dc:creator><description>&lt;p&gt;What you're looking for is the &amp;quot;zip&amp;quot; operator, it's a list transpose. (Isn't Zip in F#? It seems like you used it in your solution...)&lt;/p&gt;
&lt;p&gt;Zip is in python, like Jason Prado pointed out. There's a more succinct want to do the zip inverse, though - (this is python interactive output, the &amp;gt;&amp;gt;&amp;gt; means my input to the shell)&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; listOfLists = [['a','b','1'],['c','d','2'],['e','f','3'],['g', 'h', '4']]&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; zip(*listOfLists)&lt;/p&gt;
&lt;p&gt;[('a', 'c', 'e', 'g'), ('b', 'd', 'f', 'h'), ('1', '2', '3', '4')]&lt;/p&gt;
&lt;p&gt;The python * syntax unpacks a collection as the arguments to a function - func(*args) is shorthand for apply(func, args). Does F# have functional Apply?&lt;/p&gt;
&lt;p&gt;Here's an alternate implementation of inverse zip, using array indexing:&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; [[x[i] for x in listOfLists] for i in range(len(listOfLists[0]))]&lt;/p&gt;
&lt;p&gt;[['a', 'c', 'e', 'g'], ['b', 'd', 'f', 'h'], ['1', '2', '3', '4']]&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6347680</link><pubDate>Sun, 18 Nov 2007 03:28:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6347680</guid><dc:creator>danieldsmith</dc:creator><description>&lt;p&gt;Just for fun, here's how I'd do it procedurally in traditional C#:&lt;/p&gt;
&lt;p&gt;string[,] list = { { &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;1&amp;quot; }, { &amp;quot;c&amp;quot;, &amp;quot;d&amp;quot;, &amp;quot;2&amp;quot; }, { &amp;quot;e&amp;quot;, &amp;quot;f&amp;quot;, &amp;quot;3&amp;quot; } };&lt;/p&gt;
&lt;p&gt;for (int i = 0; i &amp;lt; list.GetLength(0); i++)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;for (int j = 1 + i; j &amp;lt; list.GetLength(1); j++)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string tmp = list[i, j];&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;list[i, j] = list[j, i];&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;list[j, i] = tmp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6350995</link><pubDate>Sun, 18 Nov 2007 05:10:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6350995</guid><dc:creator>Dustin Campbell</dc:creator><description>&lt;p&gt;Sadly, this solution is five lines, but it'll do the trick:&lt;/p&gt;
&lt;p&gt;let rec pivot listOfLists = &lt;/p&gt;
&lt;p&gt; &amp;nbsp;if List.hd listOfLists = [] then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[]&lt;/p&gt;
&lt;p&gt; &amp;nbsp;else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;List.map (fun l -&amp;gt; List.hd l) listOfLists :: (pivot (List.map (fun l -&amp;gt; List.tl l) listOfLists))&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6351143</link><pubDate>Sun, 18 Nov 2007 05:17:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6351143</guid><dc:creator>Dustin Campbell</dc:creator><description>&lt;p&gt;let rec pivot listOfLists = &lt;/p&gt;
&lt;p&gt; &amp;nbsp;if List.hd listOfLists = [] then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[]&lt;/p&gt;
&lt;p&gt; &amp;nbsp;else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;List.map (fun l -&amp;gt; List.hd l) listOfLists :: (pivot (List.map (fun l -&amp;gt; List.tl l) listOfLists))&lt;/p&gt;
&lt;p&gt;Unfortunately, that's five lines. So close!&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6351212</link><pubDate>Sun, 18 Nov 2007 05:20:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6351212</guid><dc:creator>Dustin Campbell</dc:creator><description>&lt;p&gt;Got it to 4 lines:&lt;/p&gt;
&lt;p&gt;let rec pivot listOfLists = &lt;/p&gt;
&lt;p&gt; &amp;nbsp;match listOfLists with&lt;/p&gt;
&lt;p&gt; &amp;nbsp;| [] :: _ -&amp;gt; []&lt;/p&gt;
&lt;p&gt; &amp;nbsp;| _ -&amp;gt; List.map (fun l -&amp;gt; List.hd l) listOfLists :: (pivot (List.map (fun l -&amp;gt; List.tl l) listOfLists))&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6352288</link><pubDate>Sun, 18 Nov 2007 06:10:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6352288</guid><dc:creator>Derek</dc:creator><description>&lt;p&gt;I'm just beginning to learn OCaml / F#, so I'm sure this solution is ghastly to someone with better knowledge of the language. I'm looking forward to seeing the other solution.&lt;/p&gt;
&lt;p&gt;let rec combine a b = match a, b with&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| h1 :: t1, h2 :: t2 -&amp;gt; [ h1 :: h2 ] @ (combine t1 t2)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| h :: t, [] -&amp;gt; [ [ h ] ] @ (combine t [])&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| _ -&amp;gt; [];;&lt;/p&gt;
&lt;p&gt;let rec pivot = function [] -&amp;gt; []&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| h :: t -&amp;gt; combine h (pivot t);;&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6353229</link><pubDate>Sun, 18 Nov 2007 06:54:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6353229</guid><dc:creator>Bill Mill</dc:creator><description>&lt;p&gt;Jason, why so verbose? It's a well-known python idiom:&lt;/p&gt;
&lt;p&gt;In [4]: zip(*x)&lt;/p&gt;
&lt;p&gt;Out[4]: [('a', 'c', 'e'), ('b', 'd', 'f'), ('1', '2', '3')]&lt;/p&gt;
&lt;p&gt;Do I get a job? :)&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6353247</link><pubDate>Sun, 18 Nov 2007 06:55:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6353247</guid><dc:creator>Bill Mill</dc:creator><description>&lt;p&gt;Oh, nevermind, he just changed the tuples to lists. Note to self: read before posting.&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6353937</link><pubDate>Sun, 18 Nov 2007 07:26:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6353937</guid><dc:creator>Bill Mill</dc:creator><description>&lt;p&gt;So, to make up for my failure to read Jason's comment, I asked myself how I would implement this without zip available. The obvious answer was to reimplement zip, and I did a rough approximation as a one-liner:&lt;/p&gt;
&lt;p&gt;def azip(*args):&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return [tuple([iter[x] for iter in args]) for x in xrange(len(args[0]))]&lt;/p&gt;
&lt;p&gt;In [40]: azip(*x)&lt;/p&gt;
&lt;p&gt;Out[40]: [('a', 'c', 'e'), ('b', 'd', 'f'), ('1', '2', '3')]&lt;/p&gt;
&lt;p&gt;Of course, you could change tuple() to list() to get Jason's version without the somewhat unsightly list comp.&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6355184</link><pubDate>Sun, 18 Nov 2007 08:27:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6355184</guid><dc:creator>Daniel Tang</dc:creator><description>&lt;p&gt;Well this is my first F# program ever, and I'm no functional programmer, but here's what I have:&lt;/p&gt;
&lt;p&gt;let rec pivot(l: 'a list list) =&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;match List.hd l with&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| head::tail -&amp;gt; [for sub in l -&amp;gt; List.hd sub]::pivot [for sub in l -&amp;gt; List.tl sub]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| [] -&amp;gt; [];;&lt;/p&gt;
&lt;p&gt;It's four lines, unless you're shooting for 80 columns. &amp;nbsp;Kind of weird, but it works.&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6355449</link><pubDate>Sun, 18 Nov 2007 08:40:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6355449</guid><dc:creator>Bill Mill</dc:creator><description>&lt;p&gt;In haskell:&lt;/p&gt;
&lt;p&gt;Prelude&amp;gt; :m List&lt;/p&gt;
&lt;p&gt;Prelude List&amp;gt; transpose [[1,2,3],[3,4,5],[6,7,8]]&lt;/p&gt;
&lt;p&gt;[[1,3,6],[2,4,7],[3,5,8]]&lt;/p&gt;
&lt;p&gt;Where the definition of the transpose function is itself 4 lines long, and given in the List module: &lt;a rel="nofollow" target="_new" href="http://www.haskell.org/onlinelibrary/list.html"&gt;http://www.haskell.org/onlinelibrary/list.html&lt;/a&gt; . It's quite a clever bit of code; while extremely simple, it would have taken me a lot of simplification to arrive at that result, if I ever did.&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6355672</link><pubDate>Sun, 18 Nov 2007 08:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6355672</guid><dc:creator>Bill Mill</dc:creator><description>&lt;p&gt;And, finally, does the one-liner given here: &lt;a rel="nofollow" target="_new" href="http://caml.inria.fr/pub/ml-archives/caml-list/2007/03/9835735d060f8d8c7958467fa82914db.en.html"&gt;http://caml.inria.fr/pub/ml-archives/caml-list/2007/03/9835735d060f8d8c7958467fa82914db.en.html&lt;/a&gt; in Ocaml work in F#? I find it really to be the least syntactically pleasing of the solutions, but that could be my unfamiliarity with OCaml talking.&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6364822</link><pubDate>Sun, 18 Nov 2007 16:31:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6364822</guid><dc:creator>Steve Strong</dc:creator><description>&lt;p&gt;How about something like this in C# 3.0:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;static List&amp;lt;List&amp;lt;char&amp;gt;&amp;gt; Pivot(List&amp;lt;List&amp;lt;char&amp;gt;&amp;gt; have)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var x = new List&amp;lt;List&amp;lt;char&amp;gt;&amp;gt; { have.Select(l =&amp;gt; l.First()).ToList() };&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return have.First().Count == 1 ?&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x :&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x.Union(Pivot(have.Select(l =&amp;gt; l.GetRange(1, l.Count - 1)).ToList())).ToList();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;How many lines of code depends on how you count it; I think I could argue 3 - one for the function declaration, one to assign x and one to return, however if you laid it out just using 3 lines in the text editor, it would be pretty unreadable :) &amp;nbsp;I'll settle for 7.&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6371532</link><pubDate>Sun, 18 Nov 2007 20:27:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6371532</guid><dc:creator>Palladinos Nick</dc:creator><description>&lt;p&gt;C# FP solution...&lt;/p&gt;
&lt;p&gt;without indexing... &lt;/p&gt;
&lt;p&gt;First() like car, Skip(1) like cdr&lt;/p&gt;
&lt;p&gt;		static IEnumerable&amp;lt;IEnumerable&amp;lt;T&amp;gt;&amp;gt; Pivot&amp;lt;T&amp;gt;(IEnumerable&amp;lt;IEnumerable&amp;lt;T&amp;gt;&amp;gt; source)&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp; &amp;nbsp;if(!source.Any()) yield break;&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp; &amp;nbsp;yield return source.Select(list =&amp;gt; list.First());&lt;/p&gt;
&lt;p&gt;			foreach(var value in Pivot(source.Select(list =&amp;gt; list.Skip(1)).Where(list =&amp;gt; list.Count() != 0)))&lt;/p&gt;
&lt;p&gt;				yield return value;&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6374606</link><pubDate>Sun, 18 Nov 2007 22:36:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6374606</guid><dc:creator>Richard</dc:creator><description>&lt;p&gt;Mmmm...this is the best I could do in Java:&lt;/p&gt;
&lt;p&gt;static LinkedList&amp;lt;LinkedList&amp;gt; Pivot(LinkedList&amp;lt;LinkedList&amp;gt; list) {&lt;/p&gt;
&lt;p&gt;		LinkedList&amp;lt;LinkedList&amp;gt; newList = new LinkedList&amp;lt;LinkedList&amp;gt;();&lt;/p&gt;
&lt;p&gt;		//add new linkedlists&lt;/p&gt;
&lt;p&gt;		for (int i = 0; i &amp;lt; list.getFirst().size(); i++)&lt;/p&gt;
&lt;p&gt;			newList.add(new LinkedList());&lt;/p&gt;
&lt;p&gt;		//add the remaining objects to the linkedlists&lt;/p&gt;
&lt;p&gt;		for (LinkedList ll : list) {&lt;/p&gt;
&lt;p&gt;			Iterator&amp;lt;LinkedList&amp;gt; iter = newList.iterator();&lt;/p&gt;
&lt;p&gt;			for (Object obj : ll) {&lt;/p&gt;
&lt;p&gt;				iter.next().add(obj);&lt;/p&gt;
&lt;p&gt;			}&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		return newList;&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6379132</link><pubDate>Mon, 19 Nov 2007 01:23:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6379132</guid><dc:creator>Palladinos Nick</dc:creator><description>&lt;p&gt;Scheme solution&lt;/p&gt;
&lt;p&gt;(define (pivot source)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;(if (null? source) '()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (map car source) (pivot (filter (lambda(x) (not (null? x))) (map cdr source))))))&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6394603</link><pubDate>Mon, 19 Nov 2007 12:24:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6394603</guid><dc:creator>SteveStrong</dc:creator><description>&lt;p&gt;Completely forgot about using Skip(1), which cleans up my code a little:&lt;/p&gt;
&lt;p&gt;static IEnumerable&amp;lt;IEnumerable&amp;lt;char&amp;gt;&amp;gt; Pivot(IEnumerable&amp;lt;IEnumerable&amp;lt;char&amp;gt;&amp;gt; have)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; var x = new List&amp;lt;IEnumerable&amp;lt;char&amp;gt;&amp;gt; { have.Select(l =&amp;gt; l.First()) };&lt;/p&gt;
&lt;p&gt; &amp;nbsp; return have.First().Count() == 1 ?&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x :&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;x.Union(Pivot(have.Select(l =&amp;gt; l.Skip(1))));&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Gets rid of a load of those pesky ToList() calls that were making things look messy :)&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6395609</link><pubDate>Mon, 19 Nov 2007 13:08:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6395609</guid><dc:creator>d2bg</dc:creator><description>&lt;p&gt;In F#:&lt;/p&gt;
&lt;p&gt;let pivot = function&lt;/p&gt;
&lt;p&gt;| [] -&amp;gt; []&lt;/p&gt;
&lt;p&gt;| h::_ as l -&amp;gt; List.fold_right (List.map2 (fun x y -&amp;gt; x::y)) l [for i in h -&amp;gt; []];;&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6401463</link><pubDate>Mon, 19 Nov 2007 17:31:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6401463</guid><dc:creator>Jon Harrop</dc:creator><description>&lt;p&gt;(Math.Matrix.Generic.of_seq have).Transpose&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6402962</link><pubDate>Mon, 19 Nov 2007 18:45:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6402962</guid><dc:creator>d2bg</dc:creator><description>&lt;p&gt;Another obscuer:&lt;/p&gt;
&lt;p&gt;let pivot =&lt;/p&gt;
&lt;p&gt; &amp;nbsp;let rec aux c = function&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| [] | [[]] | []::[]::_ &amp;nbsp;-&amp;gt; c ([],[])&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| []::l -&amp;gt; aux (fun (rh,rt) -&amp;gt; c([],rh::rt)) (l@[[]])&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| (h::t)::l -&amp;gt; aux (fun (rh,rt) -&amp;gt; c (h::rh, rt)) (l@[t]) in&lt;/p&gt;
&lt;p&gt; &amp;nbsp;fun l -&amp;gt; aux snd ([]::l);;&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6411472</link><pubDate>Tue, 20 Nov 2007 00:51:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6411472</guid><dc:creator>Matt Youell</dc:creator><description>&lt;p&gt;I took a crack at this in Erlang, something I'm just learning. Erlang actually has a function to zip 3 lists together but making it work with a list of lists as input was awkward and didn't scale to lists &amp;gt; 3, etc. So I ended up with this:&lt;/p&gt;
&lt;p&gt;pivot([]) -&amp;gt; [];&lt;/p&gt;
&lt;p&gt;pivot(List) -&amp;gt;&lt;/p&gt;
&lt;p&gt;[ [Head || [Head | _] &amp;lt;- List] ] ++ pivot([Tail || [_ | Tail] &amp;lt;- List]).&lt;/p&gt;
&lt;p&gt;%% Then the calling code looks like:&lt;/p&gt;
&lt;p&gt;Want = pivot(Have).&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6412679</link><pubDate>Tue, 20 Nov 2007 01:44:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6412679</guid><dc:creator>tomasp</dc:creator><description>&lt;P&gt;If you choose the right representaton than you can do it with one character in Matlab, just as a matrix transposition :-) - similarly to the F# solution posted by Jon Harrop that uses F# matrices.. in Matlab it would look like this:&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt; have = ['a' 'b' '1'; 'c' 'd' '2'; 'e' 'f' '3'];&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt; have'&lt;/P&gt;
&lt;P&gt;['a' 'c' 'e'; 'b' 'd' 'f'; '1' '2' '3'];&lt;/P&gt;
&lt;P&gt;:-) ..but I think that the important question is - how to implement this directly on functional (linked) list type and without using inefficient 'nth' function and any built-in matrix transpositions. That's more tricky question :-). My F# solution looks like this:&lt;/P&gt;
&lt;P&gt;let rec transpose have = &lt;/P&gt;
&lt;P&gt;&amp;nbsp;let (res, rem, cont) = List.fold_right (fun (h::t) (res,tmp,_) -&amp;gt; (h::res,t::tmp,t&amp;lt;&amp;gt;[])) have ([],[],true)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;res::(if cont then transpose rem else [])&lt;/P&gt;
&lt;P&gt;It's doing fold_right for every returned row, which internally uses one List.rev, which is inefficient, but I think that it will have to be used in any solution... It also reports one compiler warning, but that's fine, because the problematic case cannot occur for non-empty input.&lt;/P&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6435827</link><pubDate>Tue, 20 Nov 2007 18:46:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6435827</guid><dc:creator>Christer</dc:creator><description>&lt;p&gt;I found the Haskell code and compared it with my Ruby version of transpose.&lt;/p&gt;
&lt;p&gt;(Array.transpose is built in, but I redefined it.)&lt;/p&gt;
&lt;p&gt;I think the Haskell code is better.&lt;/p&gt;
&lt;p&gt;# Haskell code:&lt;/p&gt;
&lt;p&gt;# transpose [] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = []&lt;/p&gt;
&lt;p&gt;# transpose ([] &amp;nbsp; &amp;nbsp; : xss) = transpose xss&lt;/p&gt;
&lt;p&gt;# transpose ((x:xs) : xss) = (x : [h | (h:t) &amp;lt;- xss]) : &lt;/p&gt;
&lt;p&gt;# &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;transpose (xs : [t | (h:t) &amp;lt;- xss])&lt;/p&gt;
&lt;p&gt;class Array&lt;/p&gt;
&lt;p&gt; &amp;nbsp;def transpose&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return [] if self == []&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;head,*tail = self&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return tail.transpose if head==[]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;h,*t = head&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[[h] + tail.collect{|_| _[0]}] + ([t] + tail.collect{|_| _[1,size-1]}).transpose&lt;/p&gt;
&lt;p&gt; &amp;nbsp;end&lt;/p&gt;
&lt;p&gt;end&lt;/p&gt;
&lt;p&gt;assert [['a','c','e'],['b','d','f'],['1','2','3']], [['a','b','1'],['c','d','2'],['e','f','3']].transpose&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6441105</link><pubDate>Tue, 20 Nov 2007 22:40:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6441105</guid><dc:creator>Christer</dc:creator><description>&lt;p&gt;That F# 4-liner was amazing!&lt;/p&gt;
&lt;p&gt;Inspired me to improve my Ruby code.&lt;/p&gt;
&lt;p&gt;But your F# is much more elegant!&lt;/p&gt;
&lt;p&gt; &amp;nbsp;def transpose&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return [] if self == []&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return tail.transpose if head==[]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;[map{|e| e.head}] + (map{|e| e.tail}).transpose&lt;/p&gt;
&lt;p&gt; &amp;nbsp;end&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6444639</link><pubDate>Wed, 21 Nov 2007 01:07:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6444639</guid><dc:creator>tomasp</dc:creator><description>&lt;p&gt;The Haskell solution is very elegant (and also more efficient than the code that I posted earlier). Using the F# syntax it looks like this:&lt;/p&gt;
&lt;p&gt;let rec transpose = function &lt;/p&gt;
&lt;p&gt; &amp;nbsp;| [] -&amp;gt; []&lt;/p&gt;
&lt;p&gt; &amp;nbsp;| []::xss -&amp;gt; transpose xss&lt;/p&gt;
&lt;p&gt; &amp;nbsp;| (x::xs)::xss -&amp;gt; (x::[for h::t in xss -&amp;gt; h])::&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(transpose(xs::[for h::t in xss -&amp;gt; t]))&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6478983</link><pubDate>Fri, 23 Nov 2007 09:38:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6478983</guid><dc:creator>bhrgunatha</dc:creator><description>&lt;p&gt;The scheme solution seems the most elegant to me. &lt;/p&gt;
&lt;p&gt;My solution is identical except I chose to bail at the end of the shortest list.&lt;/p&gt;
&lt;p&gt;(define (flip xss)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;(cond ((not (null? (filter (lambda (l) (null? l)) xss))) '()) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(exsse (cons (map car xss)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(flip (map cdr xss))))))&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6503182</link><pubDate>Sat, 24 Nov 2007 19:37:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6503182</guid><dc:creator>Raptor-75</dc:creator><description>&lt;P&gt;Here's my solution using C# 3.0 / LINQ:&lt;/P&gt;
&lt;P&gt;static IEnumerable&amp;lt;IEnumerable&amp;lt;T&amp;gt;&amp;gt; TransposeWithIndexGroupBy&amp;lt;T&amp;gt;(IEnumerable&amp;lt;IEnumerable&amp;lt;T&amp;gt;&amp;gt; source)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;return source.SelectMany(list =&amp;gt; (list.Select((value, index) =&amp;gt; new { Value = value, Index = index })))&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .GroupBy(tuple =&amp;gt; tuple.Index, tuple =&amp;gt; tuple.Value, (key, list) =&amp;gt; list);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;What it does is take each char and put it in an anonymous type together with its inner list index. It then flattens the whole thing to a single list (SelectMany) and finally groups by inner index. The last two paramaters to GroupBy gets rid of the anonymous type and the grouping key respectively. In reality though it's probably not executed one step at a time like I described it.&lt;/P&gt;
&lt;P&gt;It's actually at least 3 times faster than SteveStrong's solution and at least 5 times faster than Nick Palladinos' solution.&lt;/P&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6611783</link><pubDate>Fri, 30 Nov 2007 11:59:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6611783</guid><dc:creator>SteveStrong</dc:creator><description>&lt;p&gt;Nice one, Raptor-75. &amp;nbsp;I think I still prefer mine for it's readability, but there's no doubt you win hands-down on line count &amp;amp; perf!&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6692300</link><pubDate>Fri, 07 Dec 2007 15:20:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6692300</guid><dc:creator>Brian McNamara</dc:creator><description>&lt;p&gt;(C#)&lt;/p&gt;
&lt;p&gt;I think when trying to find an elegant solution to a problem like this, it can be handy to derive the solution from first principles - in the case of list-y stuff, &amp;quot;how do I get the first result?&amp;quot; and &amp;quot;how do I recurse to get the rest?&amp;quot; &amp;nbsp;Here we have&lt;/p&gt;
&lt;p&gt;[[ab1][cd2][ef3][gh4]]&lt;/p&gt;
&lt;p&gt;and we want&lt;/p&gt;
&lt;p&gt;[[aceg][bdfh][1234]]&lt;/p&gt;
&lt;p&gt;So we first ask, how can we get the first element of &amp;quot;want&amp;quot;? &amp;nbsp;It is clear that this is&lt;/p&gt;
&lt;p&gt;have.Select(l =&amp;gt; l.First())&lt;/p&gt;
&lt;p&gt;Having consumed those values, we now want to recurse with a have-like list that would yield the next wanted value, and we can see that we want to recurse with&lt;/p&gt;
&lt;p&gt;[[b1][d2][f3][h4]]&lt;/p&gt;
&lt;p&gt;in order for the same Select() call to produce the second element of want. &amp;nbsp;And we can see that&lt;/p&gt;
&lt;p&gt;[[b1][d2][f3][h4]]&lt;/p&gt;
&lt;p&gt;is just&lt;/p&gt;
&lt;p&gt;have.Select(l =&amp;gt; l.Skip(1))&lt;/p&gt;
&lt;p&gt;At that point there's enough insight to easily write the code.&lt;/p&gt;
&lt;p&gt;Anyway, that was my thought process, here's a full C# program.&lt;/p&gt;
&lt;p&gt;using System;&lt;/p&gt;
&lt;p&gt;using System.Collections.Generic;&lt;/p&gt;
&lt;p&gt;using System.Linq;&lt;/p&gt;
&lt;p&gt;static class Program&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public static IEnumerable&amp;lt;T&amp;gt; Cons&amp;lt;T&amp;gt;(T x, IEnumerable&amp;lt;T&amp;gt; rest)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yield return x;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;foreach (T t in rest)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yield return t;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public static bool IsEmpty&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; list)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return !list.GetEnumerator().MoveNext();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static IEnumerable&amp;lt;IEnumerable&amp;lt;T&amp;gt;&amp;gt; Transpose&amp;lt;T&amp;gt;(IEnumerable&amp;lt;IEnumerable&amp;lt;T&amp;gt;&amp;gt; lol)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return lol.IsEmpty() || lol.First().IsEmpty() &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;? Enumerable.Empty&amp;lt;IEnumerable&amp;lt;T&amp;gt;&amp;gt;()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: Cons(lol.Select(l =&amp;gt; l.First()), &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Transpose(lol.Select(l =&amp;gt; l.Skip(1)))); &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static void Display(IEnumerable&amp;lt;IEnumerable&amp;lt;char&amp;gt;&amp;gt; lol)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;foreach (IEnumerable&amp;lt;char&amp;gt; l in lol)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;foreach (char c in l)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.Write(c);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static void Main(string[] args)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IEnumerable&amp;lt;IEnumerable&amp;lt;char&amp;gt;&amp;gt; lol = new[]{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new [] { 'a', 'b', '1' }.AsEnumerable(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new [] { 'c', 'd', '2' }.AsEnumerable(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new [] { 'e', 'f', '3' }.AsEnumerable(),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new [] { 'g', 'h', '4' }.AsEnumerable() &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}.AsEnumerable();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Display(lol);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Display(Transpose(lol));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Here's a mental picture of the process:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// answer &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;remaining input&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [[ab1][cd2][ef3][gh4]]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Cons([aceg], ... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[ [b1] [d2] [f3] [h4]]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Cons([aceg], Cons([bdfh], ... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [ &amp;nbsp;[1] &amp;nbsp;[2] &amp;nbsp;[3] &amp;nbsp;[4]]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Cons([aceg], Cons([bdfh], Cons([1234], ... &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[ &amp;nbsp; [] &amp;nbsp; [] &amp;nbsp; [] &amp;nbsp; []]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.ReadKey();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6693617</link><pubDate>Fri, 07 Dec 2007 17:56:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6693617</guid><dc:creator>Tony Nassar</dc:creator><description>&lt;p&gt;I knew I'd seen this in a textbook, and I had. It's probably in lots of textbooks, but I remembered it from William Clocksin's &amp;lt;i&amp;gt;&amp;lt;a href =&amp;quot;&lt;a rel="nofollow" target="_new" href="http://books.google.com/books?id=QwzQwVUzR2MC&amp;amp;pg=PA70&amp;amp;lpg=PA70&amp;amp;dq=prolog+clocksin+transpose&amp;amp;source=web&amp;amp;ots=nFIOlNQkz_&amp;amp;sig=H8ZG9Hj9gVUNX7EJp-sDst7wVK0#PPA70,M1&amp;quot;&amp;gt;Clause"&gt;http://books.google.com/books?id=QwzQwVUzR2MC&amp;amp;pg=PA70&amp;amp;lpg=PA70&amp;amp;dq=prolog+clocksin+transpose&amp;amp;source=web&amp;amp;ots=nFIOlNQkz_&amp;amp;sig=H8ZG9Hj9gVUNX7EJp-sDst7wVK0#PPA70,M1&amp;quot;&amp;gt;Clause&lt;/a&gt; and Effect: Prolog Programming&amp;lt;/i&amp;gt;. Btw, I think that Raptor-75's solution is the only one that's &amp;quot;tail recursive.&amp;quot; Am I correct?&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#6817033</link><pubDate>Thu, 20 Dec 2007 16:09:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6817033</guid><dc:creator>secretGeek</dc:creator><description>&lt;p&gt;i just wish someone had posted an Excel solution to this ;-)&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#8801719</link><pubDate>Fri, 01 Aug 2008 22:46:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8801719</guid><dc:creator>Mr Wonderful</dc:creator><description>&lt;p&gt;If this is a language competition then Matlab clearly wins. &amp;nbsp;It takes less than a line. &amp;nbsp;Heck, it's barely a character:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;want = have'&lt;/p&gt;
&lt;p&gt;Transpose is done with the apostrophe char (').&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#9234953</link><pubDate>Thu, 18 Dec 2008 10:38:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9234953</guid><dc:creator>Ben</dc:creator><description>&lt;p&gt;That's a bit of a cheat, it's five lines if you include the &amp;quot;open List&amp;quot;, without which it don't compile...&lt;/p&gt;</description></item><item><title>re: Tight Code--A Puzzle in F#</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/11/17/tight-code-a-puzzle-in-f.aspx#9533112</link><pubDate>Mon, 06 Apr 2009 07:50:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9533112</guid><dc:creator>bistok</dc:creator><description>&lt;p&gt;From the Expert F# book, make it tail recursive:&lt;/p&gt;
&lt;p&gt;open List&lt;/p&gt;
&lt;p&gt;let rec transpose (haves: 'a List List) (acc : 'a List List) =&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;match haves with&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| (_::_)::_ -&amp;gt; &amp;nbsp;transpose (map tl haves) (map hd haves :: acc)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| _ -&amp;gt;rev acc&lt;/p&gt;</description></item></channel></rss>