text:
Display the result of doing 8 perfect shuffles of a deck of cards
Explanation
A perfect shuffle is where a deck of cards is split exactly in half and the cards from each pile are alternately interleaved. The original bottom cards and the original top card must be preserved after a perfect shuffle.
After 8 perfect shuffles, a standard 52 card deck returns to its original order.
Challenge
Write a program that displays the state of a deck of cards as it goes through 8 consecutive perfect shuffles. You may use any human-readable representation of a deck, provided that it displays the number and suit of each card in the deck in sequential order. It must display a representation of all of the cards, for all nine states.
This is code golf, so the shortest solution wins.
Example Output
Here is an example output produced by this example implementation in Javascript
AS,AC,AD,AH,2S,2C,2D,2H,3S,3C,3D,3H,4S,4C,4D,4H,5S,5C,5D,5H,6S,6C,6D,6H,7S,7C,7D,7H,8S,8C,8D,8H,9S,9C,9D,9H,10S,10C,10D,10H,JS,JC,JD,JH,QS,QC,QD,QH,KS,KC,KD,KH
AS,7D,AC,7H,AD,8S,AH,8C,2S,8D,2C,8H,2D,9S,2H,9C,3S,9D,3C,9H,3D,10S,3H,10C,4S,10D,4C,10H,4D,JS,4H,JC,5S,JD,5C,JH,5D,QS,5H,QC,6S,QD,6C,QH,6D,KS,6H,KC,7S,KD,7C,KH
AS,4C,7D,10H,AC,4D,7H,JS,AD,4H,8S,JC,AH,5S,8C,JD,2S,5C,8D,JH,2C,5D,8H,QS,2D,5H,9S,QC,2H,6S,9C,QD,3S,6C,9D,QH,3C,6D,9H,KS,3D,6H,10S,KC,3H,7S,10C,KD,4S,7C,10D,KH
AS,9S,4C,QC,7D,2H,10H,6S,AC,9C,4D,QD,7H,3S,JS,6C,AD,9D,4H,QH,8S,3C,JC,6D,AH,9H,5S,KS,8C,3D,JD,6H,2S,10S,5C,KC,8D,3H,JH,7S,2C,10C,5D,KD,8H,4S,QS,7C,2D,10D,5H,KH
AS,5S,9S,KS,4C,8C,QC,3D,7D,JD,2H,6H,10H,2S,6S,10S,AC,5C,9C,KC,4D,8D,QD,3H,7H,JH,3S,7S,JS,2C,6C,10C,AD,5D,9D,KD,4H,8H,QH,4S,8S,QS,3C,7C,JC,2D,6D,10D,AH,5H,9H,KH
AS,3S,5S,7S,9S,JS,KS,2C,4C,6C,8C,10C,QC,AD,3D,5D,7D,9D,JD,KD,2H,4H,6H,8H,10H,QH,2S,4S,6S,8S,10S,QS,AC,3C,5C,7C,9C,JC,KC,2D,4D,6D,8D,10D,QD,AH,3H,5H,7H,9H,JH,KH
AS,2S,3S,4S,5S,6S,7S,8S,9S,10S,JS,QS,KS,AC,2C,3C,4C,5C,6C,7C,8C,9C,10C,JC,QC,KC,AD,2D,3D,4D,5D,6D,7D,8D,9D,10D,JD,QD,KD,AH,2H,3H,4H,5H,6H,7H,8H,9H,10H,JH,QH,KH
AS,AD,2S,2D,3S,3D,4S,4D,5S,5D,6S,6D,7S,7D,8S,8D,9S,9D,10S,10D,JS,JD,QS,QD,KS,KD,AC,AH,2C,2H,3C,3H,4C,4H,5C,5H,6C,6H,7C,7H,8C,8H,9C,9H,10C,10H,JC,JH,QC,QH,KC,KH
AS,AC,AD,AH,2S,2C,2D,2H,3S,3C,3D,3H,4S,4C,4D,4H,5S,5C,5D,5H,6S,6C,6D,6H,7S,7C,7D,7H,8S,8C,8D,8H,9S,9C,9D,9H,10S,10C,10D,10H,JS,JC,JD,JH,QS,QC,QD,QH,KS,KC,KD,KH

Whilst not an exact duplicate, this is essentially about half of the task from Mix the nuts (at least as implemented by the current answers).

Is the starting order of the cards important?

@chron No, the cards can start out in any order.

J, 66 65 54 52 50 47 43 characters
26({.,@,.}.)^:(i.9),{'A23456789TJQK';'SCDH'

Output:
┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
│AS│AC│AD│AH│2S│2C│2D│2H│3S│3C│3D│3H│4S│4C│4D│4H│5S│5C│5D│5H│6S│6C│6D│6H│7S│7C│7D│7H│8S│8C│8D│8H│9S│9C│9D│9H│TS│TC│TD│TH│JS│JC│JD│JH│QS│QC│QD│QH│KS│KC│KD│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│7D│AC│7H│AD│8S│AH│8C│2S│8D│2C│8H│2D│9S│2H│9C│3S│9D│3C│9H│3D│TS│3H│TC│4S│TD│4C│TH│4D│JS│4H│JC│5S│JD│5C│JH│5D│QS│5H│QC│6S│QD│6C│QH│6D│KS│6H│KC│7S│KD│7C│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│4C│7D│TH│AC│4D│7H│JS│AD│4H│8S│JC│AH│5S│8C│JD│2S│5C│8D│JH│2C│5D│8H│QS│2D│5H│9S│QC│2H│6S│9C│QD│3S│6C│9D│QH│3C│6D│9H│KS│3D│6H│TS│KC│3H│7S│TC│KD│4S│7C│TD│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│9S│4C│QC│7D│2H│TH│6S│AC│9C│4D│QD│7H│3S│JS│6C│AD│9D│4H│QH│8S│3C│JC│6D│AH│9H│5S│KS│8C│3D│JD│6H│2S│TS│5C│KC│8D│3H│JH│7S│2C│TC│5D│KD│8H│4S│QS│7C│2D│TD│5H│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│5S│9S│KS│4C│8C│QC│3D│7D│JD│2H│6H│TH│2S│6S│TS│AC│5C│9C│KC│4D│8D│QD│3H│7H│JH│3S│7S│JS│2C│6C│TC│AD│5D│9D│KD│4H│8H│QH│4S│8S│QS│3C│7C│JC│2D│6D│TD│AH│5H│9H│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│3S│5S│7S│9S│JS│KS│2C│4C│6C│8C│TC│QC│AD│3D│5D│7D│9D│JD│KD│2H│4H│6H│8H│TH│QH│2S│4S│6S│8S│TS│QS│AC│3C│5C│7C│9C│JC│KC│2D│4D│6D│8D│TD│QD│AH│3H│5H│7H│9H│JH│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│2S│3S│4S│5S│6S│7S│8S│9S│TS│JS│QS│KS│AC│2C│3C│4C│5C│6C│7C│8C│9C│TC│JC│QC│KC│AD│2D│3D│4D│5D│6D│7D│8D│9D│TD│JD│QD│KD│AH│2H│3H│4H│5H│6H│7H│8H│9H│TH│JH│QH│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│AD│2S│2D│3S│3D│4S│4D│5S│5D│6S│6D│7S│7D│8S│8D│9S│9D│TS│TD│JS│JD│QS│QD│KS│KD│AC│AH│2C│2H│3C│3H│4C│4H│5C│5H│6C│6H│7C│7H│8C│8H│9C│9H│TC│TH│JC│JH│QC│QH│KC│KH│
├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
│AS│AC│AD│AH│2S│2C│2D│2H│3S│3C│3D│3H│4S│4C│4D│4H│5S│5C│5D│5H│6S│6C│6D│6H│7S│7C│7D│7H│8S│8C│8D│8H│9S│9C│9D│9H│TS│TC│TD│TH│JS│JC│JD│JH│QS│QC│QD│QH│KS│KC│KD│KH│
└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘

I'm being forced further and further into J's tutorials and reference manuals to stay ahead here. :-S

Your 1st and last arrays are identical. Moreover, your 1st card is always AS and last is all the time KH.

@ArtemIce They're supposed to be. It's required in the question. Re-read the first paragraph.

@Gareth ok sorry

Haskell, 103
m(a:s,b:t)=a:b:m(s,t);m _=[]
main=mapM_ putStrLn.take 9.iterate(m.splitAt 26)$take 13.enumFrom=<<""

Output:

Don't know if there are any UTF-8 problems around here, shouldn't... this is a hex dump of the program
0000000 286d 3a61 2c73 3a62 2974 613d 623a 6d3a
0000010 7328 742c 3b29 206d 3d5f 5d5b 6d0a 6961
0000020 3d6e 616d 4d70 205f 7570 5374 7274 6e4c
0000030 742e 6b61 2065 2e39 7469 7265 7461 2865
0000040 2e6d 7073 696c 4174 2074 3632 2429 6174
0000050 656b 3120 2e33 6e65 6d75 7246 6d6f 3c3d
0000060 223c 9ff0 a182 9ff0 9183 9ff0 8183 9ff0
0000070 b182 0a22
0000074

and of the first output line
0000000 9ff0 a182 9ff0 a282 9ff0 a382 9ff0 a482
0000010 9ff0 a582 9ff0 a682 9ff0 a782 9ff0 a882
0000020 9ff0 a982 9ff0 aa82 9ff0 ab82 9ff0 ac82
0000030 9ff0 ad82 9ff0 9183 9ff0 9283 9ff0 9383
0000040 9ff0 9483 9ff0 9583 9ff0 9683 9ff0 9783
0000050 9ff0 9883 9ff0 9983 9ff0 9a83 9ff0 9b83
0000060 9ff0 9c83 9ff0 9d83 9ff0 8183 9ff0 8283
0000070 9ff0 8383 9ff0 8483 9ff0 8583 9ff0 8683
0000080 9ff0 8783 9ff0 8883 9ff0 8983 9ff0 8a83
0000090 9ff0 8b83 9ff0 8c83 9ff0 8d83 9ff0 b182
00000a0 9ff0 b282 9ff0 b382 9ff0 b482 9ff0 b582
00000b0 9ff0 b682 9ff0 b782 9ff0 b882 9ff0 b982
00000c0 9ff0 ba82 9ff0 bb82 9ff0 bc82 9ff0 bd82
00000d0 000a
00000d1

(the unicode playing cards)

The output is whitespace...

Erm, no it isn't! What do you mean?

Ok this is interesting, directly after editing Stack Exchange also shows me whitespace. Weird... after posting this comment it works again, though.

You lack the font to view such lovely codepoints like 'PLAYING CARD JACK OF CLUBS' (U+1F0DB).

Python 2, 79 chars
d=zip("23456789TJQKA"*4,"CDHS"*13)
exec'print d;d[::2],d[1::2]=d[:26],d[26:];'*9

The output is a bit ugly but I believe it should count.
[('2', 'C'), ('3', 'D'), ('4', 'H'), ('5', 'S'), ('6', 'C'), ('7', 'D'), ('8', 'H'), ('9', 'S'), ('T', 'C'), ('J', 'D'), ('Q', 'H'), ('K', 'S'), ('A', 'C'), ('2', 'D'), ('3', 'H'), ('4', 'S'), ('5', 'C'), ('6', 'D'), ('7', 'H'), ('8', 'S'), ('9', 'C'), ('T', 'D'), ('J', 'H'), ('Q', 'S'), ('K', 'C'), ('A', 'D'), ('2', 'H'), ('3', 'S'), ('4', 'C'), ('5', 'D'), ('6', 'H'), ('7', 'S'), ('8', 'C'), ('9', 'D'), ('T', 'H'), ('J', 'S'), ('Q', 'C'), ('K', 'D'), ('A', 'H'), ('2', 'S'), ('3', 'C'), ('4', 'D'), ('5', 'H'), ('6', 'S'), ('7', 'C'), ('8', 'D'), ('9', 'H'), ('T', 'S'), ('J', 'C'), ('Q', 'D'), ('K', 'H'), ('A', 'S')]
[('2', 'C'), ('2', 'H'), ('3', 'D'), ('3', 'S'), ('4', 'H'), ('4', 'C'), ('5', 'S'), ('5', 'D'), ('6', 'C'), ('6', 'H'), ('7', 'D'), ('7', 'S'), ('8', 'H'), ('8', 'C'), ('9', 'S'), ('9', 'D'), ('T', 'C'), ('T', 'H'), ('J', 'D'), ('J', 'S'), ('Q', 'H'), ('Q', 'C'), ('K', 'S'), ('K', 'D'), ('A', 'C'), ('A', 'H'), ('2', 'D'), ('2', 'S'), ('3', 'H'), ('3', 'C'), ('4', 'S'), ('4', 'D'), ('5', 'C'), ('5', 'H'), ('6', 'D'), ('6', 'S'), ('7', 'H'), ('7', 'C'), ('8', 'S'), ('8', 'D'), ('9', 'C'), ('9', 'H'), ('T', 'D'), ('T', 'S'), ('J', 'H'), ('J', 'C'), ('Q', 'S'), ('Q', 'D'), ('K', 'C'), ('K', 'H'), ('A', 'D'), ('A', 'S')]
[('2', 'C'), ('2', 'D'), ('2', 'H'), ('2', 'S'), ('3', 'D'), ('3', 'H'), ('3', 'S'), ('3', 'C'), ('4', 'H'), ('4', 'S'), ('4', 'C'), ('4', 'D'), ('5', 'S'), ('5', 'C'), ('5', 'D'), ('5', 'H'), ('6', 'C'), ('6', 'D'), ('6', 'H'), ('6', 'S'), ('7', 'D'), ('7', 'H'), ('7', 'S'), ('7', 'C'), ('8', 'H'), ('8', 'S'), ('8', 'C'), ('8', 'D'), ('9', 'S'), ('9', 'C'), ('9', 'D'), ('9', 'H'), ('T', 'C'), ('T', 'D'), ('T', 'H'), ('T', 'S'), ('J', 'D'), ('J', 'H'), ('J', 'S'), ('J', 'C'), ('Q', 'H'), ('Q', 'S'), ('Q', 'C'), ('Q', 'D'), ('K', 'S'), ('K', 'C'), ('K', 'D'), ('K', 'H'), ('A', 'C'), ('A', 'D'), ('A', 'H'), ('A', 'S')]
[('2', 'C'), ('8', 'C'), ('2', 'D'), ('8', 'D'), ('2', 'H'), ('9', 'S'), ('2', 'S'), ('9', 'C'), ('3', 'D'), ('9', 'D'), ('3', 'H'), ('9', 'H'), ('3', 'S'), ('T', 'C'), ('3', 'C'), ('T', 'D'), ('4', 'H'), ('T', 'H'), ('4', 'S'), ('T', 'S'), ('4', 'C'), ('J', 'D'), ('4', 'D'), ('J', 'H'), ('5', 'S'), ('J', 'S'), ('5', 'C'), ('J', 'C'), ('5', 'D'), ('Q', 'H'), ('5', 'H'), ('Q', 'S'), ('6', 'C'), ('Q', 'C'), ('6', 'D'), ('Q', 'D'), ('6', 'H'), ('K', 'S'), ('6', 'S'), ('K', 'C'), ('7', 'D'), ('K', 'D'), ('7', 'H'), ('K', 'H'), ('7', 'S'), ('A', 'C'), ('7', 'C'), ('A', 'D'), ('8', 'H'), ('A', 'H'), ('8', 'S'), ('A', 'S')]
[('2', 'C'), ('5', 'C'), ('8', 'C'), ('J', 'C'), ('2', 'D'), ('5', 'D'), ('8', 'D'), ('Q', 'H'), ('2', 'H'), ('5', 'H'), ('9', 'S'), ('Q', 'S'), ('2', 'S'), ('6', 'C'), ('9', 'C'), ('Q', 'C'), ('3', 'D'), ('6', 'D'), ('9', 'D'), ('Q', 'D'), ('3', 'H'), ('6', 'H'), ('9', 'H'), ('K', 'S'), ('3', 'S'), ('6', 'S'), ('T', 'C'), ('K', 'C'), ('3', 'C'), ('7', 'D'), ('T', 'D'), ('K', 'D'), ('4', 'H'), ('7', 'H'), ('T', 'H'), ('K', 'H'), ('4', 'S'), ('7', 'S'), ('T', 'S'), ('A', 'C'), ('4', 'C'), ('7', 'C'), ('J', 'D'), ('A', 'D'), ('4', 'D'), ('8', 'H'), ('J', 'H'), ('A', 'H'), ('5', 'S'), ('8', 'S'), ('J', 'S'), ('A', 'S')]
[('2', 'C'), ('T', 'C'), ('5', 'C'), ('K', 'C'), ('8', 'C'), ('3', 'C'), ('J', 'C'), ('7', 'D'), ('2', 'D'), ('T', 'D'), ('5', 'D'), ('K', 'D'), ('8', 'D'), ('4', 'H'), ('Q', 'H'), ('7', 'H'), ('2', 'H'), ('T', 'H'), ('5', 'H'), ('K', 'H'), ('9', 'S'), ('4', 'S'), ('Q', 'S'), ('7', 'S'), ('2', 'S'), ('T', 'S'), ('6', 'C'), ('A', 'C'), ('9', 'C'), ('4', 'C'), ('Q', 'C'), ('7', 'C'), ('3', 'D'), ('J', 'D'), ('6', 'D'), ('A', 'D'), ('9', 'D'), ('4', 'D'), ('Q', 'D'), ('8', 'H'), ('3', 'H'), ('J', 'H'), ('6', 'H'), ('A', 'H'), ('9', 'H'), ('5', 'S'), ('K', 'S'), ('8', 'S'), ('3', 'S'), ('J', 'S'), ('6', 'S'), ('A', 'S')]
[('2', 'C'), ('6', 'C'), ('T', 'C'), ('A', 'C'), ('5', 'C'), ('9', 'C'), ('K', 'C'), ('4', 'C'), ('8', 'C'), ('Q', 'C'), ('3', 'C'), ('7', 'C'), ('J', 'C'), ('3', 'D'), ('7', 'D'), ('J', 'D'), ('2', 'D'), ('6', 'D'), ('T', 'D'), ('A', 'D'), ('5', 'D'), ('9', 'D'), ('K', 'D'), ('4', 'D'), ('8', 'D'), ('Q', 'D'), ('4', 'H'), ('8', 'H'), ('Q', 'H'), ('3', 'H'), ('7', 'H'), ('J', 'H'), ('2', 'H'), ('6', 'H'), ('T', 'H'), ('A', 'H'), ('5', 'H'), ('9', 'H'), ('K', 'H'), ('5', 'S'), ('9', 'S'), ('K', 'S'), ('4', 'S'), ('8', 'S'), ('Q', 'S'), ('3', 'S'), ('7', 'S'), ('J', 'S'), ('2', 'S'), ('6', 'S'), ('T', 'S'), ('A', 'S')]
[('2', 'C'), ('4', 'H'), ('6', 'C'), ('8', 'H'), ('T', 'C'), ('Q', 'H'), ('A', 'C'), ('3', 'H'), ('5', 'C'), ('7', 'H'), ('9', 'C'), ('J', 'H'), ('K', 'C'), ('2', 'H'), ('4', 'C'), ('6', 'H'), ('8', 'C'), ('T', 'H'), ('Q', 'C'), ('A', 'H'), ('3', 'C'), ('5', 'H'), ('7', 'C'), ('9', 'H'), ('J', 'C'), ('K', 'H'), ('3', 'D'), ('5', 'S'), ('7', 'D'), ('9', 'S'), ('J', 'D'), ('K', 'S'), ('2', 'D'), ('4', 'S'), ('6', 'D'), ('8', 'S'), ('T', 'D'), ('Q', 'S'), ('A', 'D'), ('3', 'S'), ('5', 'D'), ('7', 'S'), ('9', 'D'), ('J', 'S'), ('K', 'D'), ('2', 'S'), ('4', 'D'), ('6', 'S'), ('8', 'D'), ('T', 'S'), ('Q', 'D'), ('A', 'S')]
[('2', 'C'), ('3', 'D'), ('4', 'H'), ('5', 'S'), ('6', 'C'), ('7', 'D'), ('8', 'H'), ('9', 'S'), ('T', 'C'), ('J', 'D'), ('Q', 'H'), ('K', 'S'), ('A', 'C'), ('2', 'D'), ('3', 'H'), ('4', 'S'), ('5', 'C'), ('6', 'D'), ('7', 'H'), ('8', 'S'), ('9', 'C'), ('T', 'D'), ('J', 'H'), ('Q', 'S'), ('K', 'C'), ('A', 'D'), ('2', 'H'), ('3', 'S'), ('4', 'C'), ('5', 'D'), ('6', 'H'), ('7', 'S'), ('8', 'C'), ('9', 'D'), ('T', 'H'), ('J', 'S'), ('Q', 'C'), ('K', 'D'), ('A', 'H'), ('2', 'S'), ('3', 'C'), ('4', 'D'), ('5', 'H'), ('6', 'S'), ('7', 'C'), ('8', 'D'), ('9', 'H'), ('T', 'S'), ('J', 'C'), ('Q', 'D'), ('K', 'H'), ('A', 'S')]

nice product!

Python2, 104
This is similar to Ev_Genus's solution.  I put suit before rank because it enables me to save a character.
d=[s+[r,`10`][r>"Q"]for r in'A23456789ZJQK'for s in"SCDH"]
exec'print d;d=sum(zip(d[:26],d[26:]),());'*9

Output
['SA', 'CA', 'DA', 'HA', 'S2', 'C2', 'D2', 'H2', 'S3', 'C3', 'D3', 'H3', 'S4', 'C4', 'D4', 'H4', 'S5', 'C5', 'D5', 'H5', 'S6', 'C6', 'D6', 'H6', 'S7', 'C7', 'D7', 'H7', 'S8', 'C8', 'D8', 'H8', 'S9', 'C9', 'D9', 'H9', 'S10', 'C10', 'D10', 'H10', 'SJ', 'CJ', 'DJ', 'HJ', 'SQ', 'CQ', 'DQ', 'HQ', 'SK', 'CK', 'DK', 'HK']
('SA', 'D7', 'CA', 'H7', 'DA', 'S8', 'HA', 'C8', 'S2', 'D8', 'C2', 'H8', 'D2', 'S9', 'H2', 'C9', 'S3', 'D9', 'C3', 'H9', 'D3', 'S10', 'H3', 'C10', 'S4', 'D10', 'C4', 'H10', 'D4', 'SJ', 'H4', 'CJ', 'S5', 'DJ', 'C5', 'HJ', 'D5', 'SQ', 'H5', 'CQ', 'S6', 'DQ', 'C6', 'HQ', 'D6', 'SK', 'H6', 'CK', 'S7', 'DK', 'C7', 'HK')
('SA', 'C4', 'D7', 'H10', 'CA', 'D4', 'H7', 'SJ', 'DA', 'H4', 'S8', 'CJ', 'HA', 'S5', 'C8', 'DJ', 'S2', 'C5', 'D8', 'HJ', 'C2', 'D5', 'H8', 'SQ', 'D2', 'H5', 'S9', 'CQ', 'H2', 'S6', 'C9', 'DQ', 'S3', 'C6', 'D9', 'HQ', 'C3', 'D6', 'H9', 'SK', 'D3', 'H6', 'S10', 'CK', 'H3', 'S7', 'C10', 'DK', 'S4', 'C7', 'D10', 'HK')
('SA', 'S9', 'C4', 'CQ', 'D7', 'H2', 'H10', 'S6', 'CA', 'C9', 'D4', 'DQ', 'H7', 'S3', 'SJ', 'C6', 'DA', 'D9', 'H4', 'HQ', 'S8', 'C3', 'CJ', 'D6', 'HA', 'H9', 'S5', 'SK', 'C8', 'D3', 'DJ', 'H6', 'S2', 'S10', 'C5', 'CK', 'D8', 'H3', 'HJ', 'S7', 'C2', 'C10', 'D5', 'DK', 'H8', 'S4', 'SQ', 'C7', 'D2', 'D10', 'H5', 'HK')
('SA', 'S5', 'S9', 'SK', 'C4', 'C8', 'CQ', 'D3', 'D7', 'DJ', 'H2', 'H6', 'H10', 'S2', 'S6', 'S10', 'CA', 'C5', 'C9', 'CK', 'D4', 'D8', 'DQ', 'H3', 'H7', 'HJ', 'S3', 'S7', 'SJ', 'C2', 'C6', 'C10', 'DA', 'D5', 'D9', 'DK', 'H4', 'H8', 'HQ', 'S4', 'S8', 'SQ', 'C3', 'C7', 'CJ', 'D2', 'D6', 'D10', 'HA', 'H5', 'H9', 'HK')
('SA', 'S3', 'S5', 'S7', 'S9', 'SJ', 'SK', 'C2', 'C4', 'C6', 'C8', 'C10', 'CQ', 'DA', 'D3', 'D5', 'D7', 'D9', 'DJ', 'DK', 'H2', 'H4', 'H6', 'H8', 'H10', 'HQ', 'S2', 'S4', 'S6', 'S8', 'S10', 'SQ', 'CA', 'C3', 'C5', 'C7', 'C9', 'CJ', 'CK', 'D2', 'D4', 'D6', 'D8', 'D10', 'DQ', 'HA', 'H3', 'H5', 'H7', 'H9', 'HJ', 'HK')
('SA', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'SJ', 'SQ', 'SK', 'CA', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'CJ', 'CQ', 'CK', 'DA', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'DJ', 'DQ', 'DK', 'HA', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'HJ', 'HQ', 'HK')
('SA', 'DA', 'S2', 'D2', 'S3', 'D3', 'S4', 'D4', 'S5', 'D5', 'S6', 'D6', 'S7', 'D7', 'S8', 'D8', 'S9', 'D9', 'S10', 'D10', 'SJ', 'DJ', 'SQ', 'DQ', 'SK', 'DK', 'CA', 'HA', 'C2', 'H2', 'C3', 'H3', 'C4', 'H4', 'C5', 'H5', 'C6', 'H6', 'C7', 'H7', 'C8', 'H8', 'C9', 'H9', 'C10', 'H10', 'CJ', 'HJ', 'CQ', 'HQ', 'CK', 'HK')
('SA', 'CA', 'DA', 'HA', 'S2', 'C2', 'D2', 'H2', 'S3', 'C3', 'D3', 'H3', 'S4', 'C4', 'D4', 'H4', 'S5', 'C5', 'D5', 'H5', 'S6', 'C6', 'D6', 'H6', 'S7', 'C7', 'D7', 'H7', 'S8', 'C8', 'D8', 'H8', 'S9', 'C9', 'D9', 'H9', 'S10', 'C10', 'D10', 'H10', 'SJ', 'CJ', 'DJ', 'HJ', 'SQ', 'CQ', 'DQ', 'HQ', 'SK', 'CK', 'DK', 'HK')

+1.  [r,'10'][r>"Q"] is nifty.  I don't think you need backticks around the 10.  Quotes would do fine.

@StevenRumbalski, I used backticks for the lulz.  Quotes take the same amount of space.

If it were allowable (it isn't) to have the results in reverse order, this would work: exec'print d;d=d[::2]+d[1::2];'*9.

Shame to me. I've forgot about sum.

APL (42)
{↑{⍉2 26⍴⍵}⍣⍵,'A23456789TJQK'∘.,'SCDH'}¨⍳9

Output is top-down instead of left-right (but it's still human readable so I guess it's not against the rules).
Output:

 AS  AS  AS  AS  AS  AS  AS  AS  AS
 7D  4C  9S  5S  3S  2S  AD  AC  7D

 AC  7D  4C  9S  5S  3S  2S  AD  AC
 7H  TH  QC  KS  7S  4S  2D  AH  7H

 AD  AC  7D  4C  9S  5S  3S  2S  AD
 8S  4D  2H  8C  JS  6S  3D  2C  8S

 AH  7H  TH  QC  KS  7S  4S  2D  AH
 8C  JS  6S  3D  2C  8S  4D  2H  8C

 2S  AD  AC  7D  4C  9S  5S  3S  2S
 8D  4H  9C  JD  6C  TS  5D  3C  8D

 2C  8S  4D  2H  8C  JS  6S  3D  2C
 8H  JC  QD  6H  TC  QS  6D  3H  8H

 2D  AH  7H  TH  QC  KS  7S  4S  2D
 9S  5S  3S  2S  AD  AC  7D  4C  9S

 2H  8C  JS  6S  3D  2C  8S  4D  2H
 9C  JD  6C  TS  5D  3C  8D  4H  9C

 3S  2S  AD  AC  7D  4C  9S  5S  3S
 9D  5C  9D  5C  9D  5C  9D  5C  9D

 3C  8D  4H  9C  JD  6C  TS  5D  3C
 9H  JH  QH  KC  KD  7C  TD  5H  9H

 3D  2C  8S  4D  2H  8C  JS  6S  3D
 TS  5D  3C  8D  4H  9C  JD  6C  TS

 3H  8H  JC  QD  6H  TC  QS  6D  3H
 TC  QS  6D  3H  8H  JC  QD  6H  TC

 4S  2D  AH  7H  TH  QC  KS  7S  4S
 TD  5H  9H  JH  QH  KC  KD  7C  TD

 4C  9S  5S  3S  2S  AD  AC  7D  4C
 TH  QC  KS  7S  4S  2D  AH  7H  TH

 4D  2H  8C  JS  6S  3D  2C  8S  4D
 JS  6S  3D  2C  8S  4D  2H  8C  JS

 4H  9C  JD  6C  TS  5D  3C  8D  4H
 JC  QD  6H  TC  QS  6D  3H  8H  JC

 5S  3S  2S  AD  AC  7D  4C  9S  5S
 JD  6C  TS  5D  3C  8D  4H  9C  JD

 5C  9D  5C  9D  5C  9D  5C  9D  5C
 JH  QH  KC  KD  7C  TD  5H  9H  JH

 5D  3C  8D  4H  9C  JD  6C  TS  5D
 QS  6D  3H  8H  JC  QD  6H  TC  QS

 5H  9H  JH  QH  KC  KD  7C  TD  5H
 QC  KS  7S  4S  2D  AH  7H  TH  QC

 6S  3D  2C  8S  4D  2H  8C  JS  6S
 QD  6H  TC  QS  6D  3H  8H  JC  QD

 6C  TS  5D  3C  8D  4H  9C  JD  6C
 QH  KC  KD  7C  TD  5H  9H  JH  QH

 6D  3H  8H  JC  QD  6H  TC  QS  6D
 KS  7S  4S  2D  AH  7H  TH  QC  KS

 6H  TC  QS  6D  3H  8H  JC  QD  6H
 KC  KD  7C  TD  5H  9H  JH  QH  KC

 7S  4S  2D  AH  7H  TH  QC  KS  7S
 KD  7C  TD  5H  9H  JH  QH  KC  KD

 7C  TD  5H  9H  JH  QH  KC  KD  7C
 KH  KH  KH  KH  KH  KH  KH  KH  KH

K, 55 53 51
{$,/(,').`$2 26#x}\[8;,/"A23456789TJQK",/:\:"SCDH"]

Shaved 2 chars by changing from symbol representation to string
output
k){$,/(,').`$(2 26)#x}\[8;,/"A23456789TJQK",/:\:"SCDH"]
"AS" "AC" "AD" "AH" "2S" "2C" "2D" "2H" "3S" "3C" "3D" "3H" "4S" "4C" "4D" "4H" "5S" "5C" "5D" "5H" "6S" "6C" "6D" "6H" "7S" "7C" "7D" "7H" "8S" "8C" "8D" "8H" "9S" "9C" "9D" "9H" "TS" "TC" "TD" "TH" "JS" "JC" "JD" "JH" "QS" "QC" "QD" "QH" "KS" "KC" "KD" "KH"
"AS" "7D" "AC" "7H" "AD" "8S" "AH" "8C" "2S" "8D" "2C" "8H" "2D" "9S" "2H" "9C" "3S" "9D" "3C" "9H" "3D" "TS" "3H" "TC" "4S" "TD" "4C" "TH" "4D" "JS" "4H" "JC" "5S" "JD" "5C" "JH" "5D" "QS" "5H" "QC" "6S" "QD" "6C" "QH" "6D" "KS" "6H" "KC" "7S" "KD" "7C" "KH"
"AS" "4C" "7D" "TH" "AC" "4D" "7H" "JS" "AD" "4H" "8S" "JC" "AH" "5S" "8C" "JD" "2S" "5C" "8D" "JH" "2C" "5D" "8H" "QS" "2D" "5H" "9S" "QC" "2H" "6S" "9C" "QD" "3S" "6C" "9D" "QH" "3C" "6D" "9H" "KS" "3D" "6H" "TS" "KC" "3H" "7S" "TC" "KD" "4S" "7C" "TD" "KH"
"AS" "9S" "4C" "QC" "7D" "2H" "TH" "6S" "AC" "9C" "4D" "QD" "7H" "3S" "JS" "6C" "AD" "9D" "4H" "QH" "8S" "3C" "JC" "6D" "AH" "9H" "5S" "KS" "8C" "3D" "JD" "6H" "2S" "TS" "5C" "KC" "8D" "3H" "JH" "7S" "2C" "TC" "5D" "KD" "8H" "4S" "QS" "7C" "2D" "TD" "5H" "KH"
"AS" "5S" "9S" "KS" "4C" "8C" "QC" "3D" "7D" "JD" "2H" "6H" "TH" "2S" "6S" "TS" "AC" "5C" "9C" "KC" "4D" "8D" "QD" "3H" "7H" "JH" "3S" "7S" "JS" "2C" "6C" "TC" "AD" "5D" "9D" "KD" "4H" "8H" "QH" "4S" "8S" "QS" "3C" "7C" "JC" "2D" "6D" "TD" "AH" "5H" "9H" "KH"
"AS" "3S" "5S" "7S" "9S" "JS" "KS" "2C" "4C" "6C" "8C" "TC" "QC" "AD" "3D" "5D" "7D" "9D" "JD" "KD" "2H" "4H" "6H" "8H" "TH" "QH" "2S" "4S" "6S" "8S" "TS" "QS" "AC" "3C" "5C" "7C" "9C" "JC" "KC" "2D" "4D" "6D" "8D" "TD" "QD" "AH" "3H" "5H" "7H" "9H" "JH" "KH"
"AS" "2S" "3S" "4S" "5S" "6S" "7S" "8S" "9S" "TS" "JS" "QS" "KS" "AC" "2C" "3C" "4C" "5C" "6C" "7C" "8C" "9C" "TC" "JC" "QC" "KC" "AD" "2D" "3D" "4D" "5D" "6D" "7D" "8D" "9D" "TD" "JD" "QD" "KD" "AH" "2H" "3H" "4H" "5H" "6H" "7H" "8H" "9H" "TH" "JH" "QH" "KH"
"AS" "AD" "2S" "2D" "3S" "3D" "4S" "4D" "5S" "5D" "6S" "6D" "7S" "7D" "8S" "8D" "9S" "9D" "TS" "TD" "JS" "JD" "QS" "QD" "KS" "KD" "AC" "AH" "2C" "2H" "3C" "3H" "4C" "4H" "5C" "5H" "6C" "6H" "7C" "7H" "8C" "8H" "9C" "9H" "TC" "TH" "JC" "JH" "QC" "QH" "KC" "KH"
"AS" "AC" "AD" "AH" "2S" "2C" "2D" "2H" "3S" "3C" "3D" "3H" "4S" "4C" "4D" "4H" "5S" "5C" "5D" "5H" "6S" "6C" "6D" "6H" "7S" "7C" "7D" "7H" "8S" "8C" "8D" "8H" "9S" "9C" "9D" "9H" "TS" "TC" "TD" "TH" "JS" "JC" "JD" "JH" "QS" "QC" "QD" "QH" "KS" "KC" "KD" "KH"

k)@[a;0]~@[;8]a:{$,/(,').`$(2 26)#x}\[8;,/"A23456789TJQK",/:\:"SCDH"]  /8th iteration identical to the first?
1b

You can cut a further 2 chars (and beat J) by changing (2;26) to 2 26

Excellent. I've been having an ongoing battle with that J solution. 65-55-54-53-52-51

Ruby 1.9 (95 93 87)
a=(0..51).map{|i|:A23456789TJQK[i/4]+:SCDH[i%4]}
9.times{p a;a=a.zip(a.pop 26).flatten}

Output:
["AS", "AC", "AD", "AH", "2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH"]
["AS", "7D", "AC", "7H", "AD", "8S", "AH", "8C", "2S", "8D", "2C", "8H", "2D", "9S", "2H", "9C", "3S", "9D", "3C", "9H", "3D", "TS", "3H", "TC", "4S", "TD", "4C", "TH", "4D", "JS", "4H", "JC", "5S", "JD", "5C", "JH", "5D", "QS", "5H", "QC", "6S", "QD", "6C", "QH", "6D", "KS", "6H", "KC", "7S", "KD", "7C", "KH"]
["AS", "4C", "7D", "TH", "AC", "4D", "7H", "JS", "AD", "4H", "8S", "JC", "AH", "5S", "8C", "JD", "2S", "5C", "8D", "JH", "2C", "5D", "8H", "QS", "2D", "5H", "9S", "QC", "2H", "6S", "9C", "QD", "3S", "6C", "9D", "QH", "3C", "6D", "9H", "KS", "3D", "6H", "TS", "KC", "3H", "7S", "TC", "KD", "4S", "7C", "TD", "KH"]
["AS", "9S", "4C", "QC", "7D", "2H", "TH", "6S", "AC", "9C", "4D", "QD", "7H", "3S", "JS", "6C", "AD", "9D", "4H", "QH", "8S", "3C", "JC", "6D", "AH", "9H", "5S", "KS", "8C", "3D", "JD", "6H", "2S", "TS", "5C", "KC", "8D", "3H", "JH", "7S", "2C", "TC", "5D", "KD", "8H", "4S", "QS", "7C", "2D", "TD", "5H", "KH"]
["AS", "5S", "9S", "KS", "4C", "8C", "QC", "3D", "7D", "JD", "2H", "6H", "TH", "2S", "6S", "TS", "AC", "5C", "9C", "KC", "4D", "8D", "QD", "3H", "7H", "JH", "3S", "7S", "JS", "2C", "6C", "TC", "AD", "5D", "9D", "KD", "4H", "8H", "QH", "4S", "8S", "QS", "3C", "7C", "JC", "2D", "6D", "TD", "AH", "5H", "9H", "KH"]
["AS", "3S", "5S", "7S", "9S", "JS", "KS", "2C", "4C", "6C", "8C", "TC", "QC", "AD", "3D", "5D", "7D", "9D", "JD", "KD", "2H", "4H", "6H", "8H", "TH", "QH", "2S", "4S", "6S", "8S", "TS", "QS", "AC", "3C", "5C", "7C", "9C", "JC", "KC", "2D", "4D", "6D", "8D", "TD", "QD", "AH", "3H", "5H", "7H", "9H", "JH", "KH"]
["AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "TS", "JS", "QS", "KS", "AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "TC", "JC", "QC", "KC", "AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "TD", "JD", "QD", "KD", "AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "TH", "JH", "QH", "KH"]
["AS", "AD", "2S", "2D", "3S", "3D", "4S", "4D", "5S", "5D", "6S", "6D", "7S", "7D", "8S", "8D", "9S", "9D", "TS", "TD", "JS", "JD", "QS", "QD", "KS", "KD", "AC", "AH", "2C", "2H", "3C", "3H", "4C", "4H", "5C", "5H", "6C", "6H", "7C", "7H", "8C", "8H", "9C", "9H", "TC", "TH", "JC", "JH", "QC", "QH", "KC", "KH"]
["AS", "AC", "AD", "AH", "2S", "2C", "2D", "2H", "3S", "3C", "3D", "3H", "4S", "4C", "4D", "4H", "5S", "5C", "5D", "5H", "6S", "6C", "6D", "6H", "7S", "7C", "7D", "7H", "8S", "8C", "8D", "8H", "9S", "9C", "9D", "9H", "TS", "TC", "TD", "TH", "JS", "JC", "JD", "JH", "QS", "QC", "QD", "QH", "KS", "KC", "KD", "KH"]

Symbols instead of strings will save you 2 characters a=(0..51).map{|i|:A23456789TJQK[i/4]+:SCDH[i%4]}

@ArtemIce Good call, for some reason I thought I had tried that unsuccessfully already.  Thanks for the tip!

You are welcome! One more idea is that we can use pop instead of slice! and save 6 characters. 9.times{p a;a=a.zip(a.pop 26).flatten}

Python3, 180 179
from itertools import*;i=list(map("".join,product("A23456789XJQK","SCDH")));exec('print(",".join(i).replace("X","10"));i=list(chain(*zip(islice(i,0,26,1),islice(i,26,52,1))));'*8)

Outputs lines like in task.
Native Format 151
from itertools import*;i=list(map("".join,product("A23456789TJQK","SCDH")));exec('print(i);i=list(chain(*zip(islice(i,0,26,1),islice(i,26,52,1))));'*8)

Output is like in Ruby version.

I think you can save a char by dropping the space between import and *: http://ideone.com/kQTbs

If you use 2.x, you should be able to drop the first list(), since map() returns a list not a generator.

Mathematica 131 129 120 114 100 86 chars
With help from Mr.Wizard:
NestList[Riffle @@ #~Partition~26 &, # <> "" & /@ Tuples@Characters@
{"A23456789TJQK", "HDCS"}, 8]

Output:

MrWizard suggests reducing this to 86 chars as NestList[Riffle@@#~Partition~26&,#<>""&/@Tuples@Characters@{"A23456789TJQK","HDCS"},8]

I did. Very nice streamlining. I especially liked the trick to reduce StringJoin.

GolfScript, 51 50 46 characters
"A23456789TJQK"4*"SCDH"13*]{zip""*2/.p 26/}9*;

This GolfScript code yields the following output (see here):
["AS" "2C" "3D" "4H" "5S" "6C" "7D" "8H" "9S" "TC" "JD" "QH" "KS" "AC" "2D" "3H" "4S" "5C" "6D" "7H" "8S" "9C" "TD" "JH" "QS" "KC" "AD" "2H" "3S" "4C" "5D" "6H" "7S" "8C" "9D" "TH" "JS" "QC" "KD" "AH" "2S" "3C" "4D" "5H" "6S" "7C" "8D" "9H" "TS" "JC" "QD" "KH"]
["AS" "AD" "2C" "2H" "3D" "3S" "4H" "4C" "5S" "5D" "6C" "6H" "7D" "7S" "8H" "8C" "9S" "9D" "TC" "TH" "JD" "JS" "QH" "QC" "KS" "KD" "AC" "AH" "2D" "2S" "3H" "3C" "4S" "4D" "5C" "5H" "6D" "6S" "7H" "7C" "8S" "8D" "9C" "9H" "TD" "TS" "JH" "JC" "QS" "QD" "KC" "KH"]
["AS" "AC" "AD" "AH" "2C" "2D" "2H" "2S" "3D" "3H" "3S" "3C" "4H" "4S" "4C" "4D" "5S" "5C" "5D" "5H" "6C" "6D" "6H" "6S" "7D" "7H" "7S" "7C" "8H" "8S" "8C" "8D" "9S" "9C" "9D" "9H" "TC" "TD" "TH" "TS" "JD" "JH" "JS" "JC" "QH" "QS" "QC" "QD" "KS" "KC" "KD" "KH"]
["AS" "7S" "AC" "7C" "AD" "8H" "AH" "8S" "2C" "8C" "2D" "8D" "2H" "9S" "2S" "9C" "3D" "9D" "3H" "9H" "3S" "TC" "3C" "TD" "4H" "TH" "4S" "TS" "4C" "JD" "4D" "JH" "5S" "JS" "5C" "JC" "5D" "QH" "5H" "QS" "6C" "QC" "6D" "QD" "6H" "KS" "6S" "KC" "7D" "KD" "7H" "KH"]
["AS" "4S" "7S" "TS" "AC" "4C" "7C" "JD" "AD" "4D" "8H" "JH" "AH" "5S" "8S" "JS" "2C" "5C" "8C" "JC" "2D" "5D" "8D" "QH" "2H" "5H" "9S" "QS" "2S" "6C" "9C" "QC" "3D" "6D" "9D" "QD" "3H" "6H" "9H" "KS" "3S" "6S" "TC" "KC" "3C" "7D" "TD" "KD" "4H" "7H" "TH" "KH"]
["AS" "9S" "4S" "QS" "7S" "2S" "TS" "6C" "AC" "9C" "4C" "QC" "7C" "3D" "JD" "6D" "AD" "9D" "4D" "QD" "8H" "3H" "JH" "6H" "AH" "9H" "5S" "KS" "8S" "3S" "JS" "6S" "2C" "TC" "5C" "KC" "8C" "3C" "JC" "7D" "2D" "TD" "5D" "KD" "8D" "4H" "QH" "7H" "2H" "TH" "5H" "KH"]
["AS" "5S" "9S" "KS" "4S" "8S" "QS" "3S" "7S" "JS" "2S" "6S" "TS" "2C" "6C" "TC" "AC" "5C" "9C" "KC" "4C" "8C" "QC" "3C" "7C" "JC" "3D" "7D" "JD" "2D" "6D" "TD" "AD" "5D" "9D" "KD" "4D" "8D" "QD" "4H" "8H" "QH" "3H" "7H" "JH" "2H" "6H" "TH" "AH" "5H" "9H" "KH"]
["AS" "3D" "5S" "7D" "9S" "JD" "KS" "2D" "4S" "6D" "8S" "TD" "QS" "AD" "3S" "5D" "7S" "9D" "JS" "KD" "2S" "4D" "6S" "8D" "TS" "QD" "2C" "4H" "6C" "8H" "TC" "QH" "AC" "3H" "5C" "7H" "9C" "JH" "KC" "2H" "4C" "6H" "8C" "TH" "QC" "AH" "3C" "5H" "7C" "9H" "JC" "KH"]
["AS" "2C" "3D" "4H" "5S" "6C" "7D" "8H" "9S" "TC" "JD" "QH" "KS" "AC" "2D" "3H" "4S" "5C" "6D" "7H" "8S" "9C" "TD" "JH" "QS" "KC" "AD" "2H" "3S" "4C" "5D" "6H" "7S" "8C" "9D" "TH" "JS" "QC" "KD" "AH" "2S" "3C" "4D" "5H" "6S" "7C" "8D" "9H" "TS" "JC" "QD" "KH"]

Since the cards can start in any order, and since gcd(13, 4) = 1, you can replace {...}% by 4*.

@PeterTaylor Thank you. Didn't read that "in any order" comment.

Perl, 91 chars
Any suggestions on a more concise way of building the initial deck? My approach uses 2 substitutions to build $_ and then a global match in list context to initialize @_.
The shuffling is then done by repeatedly spliceing @_ onto @a and interleaving the two lists with map back into @_.
s//A23456789TJQK/,s/(.)/$1S$1C$1D$1H/g,@_=/../g;say@_=map{shift@_,$_}@a=splice@_,26for 0..8

CJam, 34 bytes
CJam is newer than the question, so this answer doesn't compete for the green checkmark, but I thought this would be a nice problem to try in CJam.
A,2>s"TJQKA"+"SCDH"m*{_p26/z:~}8*p

Test it here.
It prints the output like
["2S" "2C" "2D" "2H" "3S" "3C" "3D" "3H" "4S" "4C" "4D" "4H" "5S" "5C" "5D" "5H" "6S" "6C" "6D" "6H" "7S" "7C" "7D" "7H" "8S" "8C" "8D" "8H" "9S" "9C" "9D" "9H" "TS" "TC" "TD" "TH" "JS" "JC" "JD" "JH" "QS" "QC" "QD" "QH" "KS" "KC" "KD" "KH" "AS" "AC" "AD" "AH"]
["2S" "8D" "2C" "8H" "2D" "9S" "2H" "9C" "3S" "9D" "3C" "9H" "3D" "TS" "3H" "TC" "4S" "TD" "4C" "TH" "4D" "JS" "4H" "JC" "5S" "JD" "5C" "JH" "5D" "QS" "5H" "QC" "6S" "QD" "6C" "QH" "6D" "KS" "6H" "KC" "7S" "KD" "7C" "KH" "7D" "AS" "7H" "AC" "8S" "AD" "8C" "AH"]
["2S" "5C" "8D" "JH" "2C" "5D" "8H" "QS" "2D" "5H" "9S" "QC" "2H" "6S" "9C" "QD" "3S" "6C" "9D" "QH" "3C" "6D" "9H" "KS" "3D" "6H" "TS" "KC" "3H" "7S" "TC" "KD" "4S" "7C" "TD" "KH" "4C" "7D" "TH" "AS" "4D" "7H" "JS" "AC" "4H" "8S" "JC" "AD" "5S" "8C" "JD" "AH"]
["2S" "TS" "5C" "KC" "8D" "3H" "JH" "7S" "2C" "TC" "5D" "KD" "8H" "4S" "QS" "7C" "2D" "TD" "5H" "KH" "9S" "4C" "QC" "7D" "2H" "TH" "6S" "AS" "9C" "4D" "QD" "7H" "3S" "JS" "6C" "AC" "9D" "4H" "QH" "8S" "3C" "JC" "6D" "AD" "9H" "5S" "KS" "8C" "3D" "JD" "6H" "AH"]
["2S" "6S" "TS" "AS" "5C" "9C" "KC" "4D" "8D" "QD" "3H" "7H" "JH" "3S" "7S" "JS" "2C" "6C" "TC" "AC" "5D" "9D" "KD" "4H" "8H" "QH" "4S" "8S" "QS" "3C" "7C" "JC" "2D" "6D" "TD" "AD" "5H" "9H" "KH" "5S" "9S" "KS" "4C" "8C" "QC" "3D" "7D" "JD" "2H" "6H" "TH" "AH"]
["2S" "4S" "6S" "8S" "TS" "QS" "AS" "3C" "5C" "7C" "9C" "JC" "KC" "2D" "4D" "6D" "8D" "TD" "QD" "AD" "3H" "5H" "7H" "9H" "JH" "KH" "3S" "5S" "7S" "9S" "JS" "KS" "2C" "4C" "6C" "8C" "TC" "QC" "AC" "3D" "5D" "7D" "9D" "JD" "KD" "2H" "4H" "6H" "8H" "TH" "QH" "AH"]
["2S" "3S" "4S" "5S" "6S" "7S" "8S" "9S" "TS" "JS" "QS" "KS" "AS" "2C" "3C" "4C" "5C" "6C" "7C" "8C" "9C" "TC" "JC" "QC" "KC" "AC" "2D" "3D" "4D" "5D" "6D" "7D" "8D" "9D" "TD" "JD" "QD" "KD" "AD" "2H" "3H" "4H" "5H" "6H" "7H" "8H" "9H" "TH" "JH" "QH" "KH" "AH"]
["2S" "2D" "3S" "3D" "4S" "4D" "5S" "5D" "6S" "6D" "7S" "7D" "8S" "8D" "9S" "9D" "TS" "TD" "JS" "JD" "QS" "QD" "KS" "KD" "AS" "AD" "2C" "2H" "3C" "3H" "4C" "4H" "5C" "5H" "6C" "6H" "7C" "7H" "8C" "8H" "9C" "9H" "TC" "TH" "JC" "JH" "QC" "QH" "KC" "KH" "AC" "AH"]
["2S" "2C" "2D" "2H" "3S" "3C" "3D" "3H" "4S" "4C" "4D" "4H" "5S" "5C" "5D" "5H" "6S" "6C" "6D" "6H" "7S" "7C" "7D" "7H" "8S" "8C" "8D" "8H" "9S" "9C" "9D" "9H" "TS" "TC" "TD" "TH" "JS" "JC" "JD" "JH" "QS" "QC" "QD" "QH" "KS" "KC" "KD" "KH" "AS" "AC" "AD" "AH"]

Explanation
A,2>s"TJQKA"+"SCDH"m*{_p26/z:~}8*p
A,                                 "Get the range from 0 to 9.";
  2>                               "Slice off first two elements.";
    s                              "Convert to string '23456789'.";
     "TJQKA"+                      "Append this string.";
             "SCDH"                "Push the suits.";
                   m*              "Take the Cartesian product. This yields the first line.";
                     {        }8*  "Execute this block 8 times.";
                      _p           "Duplicate the last line and print it.";
                        26/        "Split the array into halves.";
                           z       "Zip, i.e. transpose the array.";
                            :~     "Flatten the array.";
                                 p "Print the final deck.";

Could you please explain your code? I'm curious.

@Thrax Done. Totally forgot about that.

Nice, thanks. Great solution, i love the A,2> to get the numbers, good thinking!

R, 97 bytes
Saved a few bytes with a convenient out-of-order deck
d=paste(rep(c(2:10,"A","J","Q","K"),4),quote(S(C,D,H)))
for(i in 1:9)print(d<-c(t(matrix(d,26))))

Try it online!

///, 753 bytes
/*/\/\///}/S,*'/C,*"/D,*;/H,*b/A'*c/A"*d/A;*e/2}*f/2'*g/2"*h/2;*i/3}*j/3'*k/3"*l/3;*m/4}*n/4'*o/4"*p/4;*q/5}*r/5'*s/5"*t/5;*u/6}*v/6'*w/6"*x/6;*y/7}*z/7'*-/7"*B/7;*+/8}*!/8'*E/8"*F/8;*G/9}*@/9'*I/9"*_/9;*(/10}*L/10'*M/10"*N/10;*O/J}*P/J'*)/J"*R/J;*$/Q}*T/Q'*U/Q"*V/Q;*W/K}*X/K'*Y/K"*{/KH
A}/A}bcdefghijklmnopqrstuvwxyz-B+!EFG@I_(LMNOP)R$TUVWXY{-bBc+d!eEfFgGh@iIj_k(lLmMnNoOpPq)rRs$tTuUvVwWxXyYz{n-NboBOcp+Pdq!)erERfsF$gtGThu@UivIVjw_Wkx(XlyLYmzM{GnT-hNub@oUBiOvcIpV+jPwd_qW!k)xe(rXElRyfLsYFm$zgMt{qGWn!Tk-)hxNeu(br@XoEUlBRiyOfvLcsIYpFVm+$jzPgwMdt_{iqyGOWfnv!LTcks-I)YhpxFNVemu+($bjrz@PXgowEMUdltB_R{eimquy+G(O$Wbfjnrvz!@LPTXcgkosw-EIM)UYdhlptxBF_NRV{cegikmoqsuwy-+EGI(MO)$UWYbdfhjlnprtvxzB!F@_LNPRTVX{bcdefghijklmnopqrstuvwxyz-B+!EFG@I_(LMNOP)R$TUVWXYKH

Try it online!
Uses the example output (it's pretty fit for this purpose) without the trailing spaces.

Japt, 31 bytes
9o åÈó c}"SCDH"ï"TJQKA"i2ò9 ¬¹w

Try it!
Although Japt has a reasonable "interleave two lists" function, it does not have a great "separate into halves" option. Instead I opted to unshuffle a deck and just display those steps in reverse.
Explanation:
9o                           ¹     Generate 9 rows, starting with...
         "SCDH"                      The suits
               ï                     Cartesian product with...
                "TJQKA"                The "special" card values
                       i               Concatenated with...
                        2ò9 ¬          Digits 2-9 as a string; i.e. "23456789"
   å    }                          And getting each subsequent row by "unshuffling":
    Èó                               Separate every-other card; e.g. [1,2,3,4,5,6] -> [[1,3,5],[2,4,6]]
       c                             and flatten the two lists; e.g. [[1,3,5],[2,4,6]] -> [1,3,5,2,4,6]
                              w    Display in reverse order

I could save 2 bytes if I could use 1 for aces instead of A, but none of the other answers did that

05AB1E, 24 bytes
2TŸ.•-Ÿ•S«.•ôì•âJ9F=2äζ˜

Uses lowercase cards to save 2 bytes with compression, since any human-readable output is allowed.
Starting/ending deck is:
['2c','2d','2h','2s','3c','3d','3h','3s','4c','4d','4h','4s','5c','5d','5h','5s','6c','6d','6h','6s','7c','7d','7h','7s','8c','8d','8h','8s','9c','9d','9h','9s','10c','10d','10h','10s','ac','ad','ah','as','jc','jd','jh','js','qc','qd','qh','qs','kc','kd','kh','ks']

Try it online (PS: Uses the legacy TIO because it is much faster.. All builtins that were used in this answer are the same in both the Python legacy and Elixir rewrite versions of 05AB1E however.)
Explanation:
2TŸ           # List in the range [2,10]: [2,3,4,5,6,7,8,9,10]
   .•-Ÿ•      # Compressed string "ajqk"
        S     # As a list of characters: ["a","j","q","k"]
         «    # Merge the lists together: [2,3,4,5,6,7,8,9,10,"a","j","q","k"]
.•ôì•         # Compressed string "cdhs"
     â        # Create each possible pair (cartesian product)
      J       # Join each pair together (now we have our deck of cards)
9F            # Loop 9 times:
  =           #  Print the deck with trailing newline, without popping the deck
   2ä         #  Split it in two equal parts
     ζ        #  Zip it (swap rows/columns)
      ˜       #  Flatten the list of lists

See this 05AB1E tip of mine (section How to compress strings not part of the dictionary?) to understand why .•-Ÿ• is "ajqk" and .•ôì• is "cdhs".

Perl 6, 69 bytes
([o] {.say;.[flat ^26 Z 26..*]}xx 9)(«A {2..10} J Q K»X~ <S C D H>)

Try it online!

{ .say; .[flat ^26 Z 26..*] } is an anonymous function that prints its argument list, then returns a perfect shuffle of that list
xx 9 produces a list containing nine copies of that anonymous function
[o] reduces that list with the function composition operator o, producing a function that calls the original anonymous function nine times, passing the shuffled list down each level
Finally, the original unshuffled deck is passed to that composed function.  «A {2..10} J Q K» is a list of the ranks, <S C D H> is a list of the suits, and X~ produces the cross product of those lists with the string concatenation operator ~.

65 bytes


text:
Program that outputs a program that outputs a program ... that outputs "Hello!"
Challenge
Write the shortest program P such that

P takes any positive integer n as input, and outputs a program string P1
executing P1 (with no input) outputs a program string P2,
executing P2 (with no input) outputs a program string P3,
...
executing Pn (with no input) outputs exactly "Hello!" (without the quotes).

Schematically:
                P(n) → P1 → P2 → ... → Pn → Hello!
Criteria

I/O is via stdin/stdout.
Program length is measured in bytes.
Programs consist only of ASCII printable characters.
There must be no duplicates among the programs P, P1,...,Pn.

EDIT: Programs P, P1,...,Pn are meant to be source code, and "executing the program" refers to whatever processing produces the output (i.e., interpretation, compilation & execution, etc.).

Related: http://codegolf.stackexchange.com/questions/5510/can-you-meta-quine

@dmckee - The relationship, if any, seems very remote. Schematically, a quine's behavior is like P-->P, and the linked programs' behavior is like P-->Q-->P; but here the behavior is like P(n)-->...-->Hello!, where P is not required to resemble any of the outputs.

That's not a criticism, r.e.s., just a note that people who like this problem might like the other one as well.

Golfscript 39 14
~'Hello!'{`}@*

Example:
Assuming that n=4 and our program is P, these are the steps:

Run P with parameter 4. The output is "\"\\\"\\\\\\\"Hello!\\\\\\\"\\\"\"" (P1)
Running P1 outputs "\"\\\"Hello!\\\"\"" (P2)
Running P2 outputs "\"Hello!\"" (P3)
Running P3 outputs "Hello!"(P4)
Running P4 outputs Hello!. If you don't trust me, follow this link ☺.

I find your P1,P2,P3,P4 behaving as required, but with input from stdin your P doesn't output P1 -- instead, it outputs \'\\\'\\\\\\\'Hello!\\\\\\\'\\\'\' (i.e., missing the outer quotes), when I run it both under Linux and under Win 7 (using echo 4 | ... at a command prompt). Any idea what the problem might be?

@r.e.s. You are right; that's a shortcoming of the Golfscript testing website I made. I managed to fix that by adding three chars, but in the meantime I found a much shorter version and edited my post.

@r.e.s. The correct version of the old approach is ~''\(,{)2\?('\\'*}/]"'"*:z"'Hello!"z-1%"'"

At 14 bytes, impressive! ... and nice website btw. (It seems that stdin can be simulated by preceding a program by ;"...", where ... is the input. E.g., ;"4" would have revealed the missing-quote problem above, whereas simply preceding the program by "4" does not.) ...

@r.e.s. Thanks a lot! You are absolutely right about the leading ;. When I wrote the first program I forgot about this along the way, although it was me who wrote about it on the meta site: http://meta.codegolf.stackexchange.com/a/521/3527

Perl (45 36)
say"say q("x($m=<>),"Hello!",")"x$m

Run with perl -M5.010 to use say.
For n=1, outputs say q(Hello!)
For n=2, outputs say q(say q(Hello!))
For n=3, outputs say q(say q(say q(Hello!)))
and so on.

JavaScript, 58 chars
function $(_){alert(_?$+'$('+--_+')':'Hello!')}$(prompt())

How does it works?

@thepirat000 If the argument _ is 0, it outputs "Hello!", otherwise it outputs the function definition and call with _ minus one

+1 for abusing rules by using a counter rather than elongating the code...

Python3, 66
r="print(%r)";e=eval;n=e(input())+1;e(e("(r%"*n+"'Hello!'"+")"*n))

Common Lisp, 68 characters
(do((n(read)(1- n))(s'(princ"Hello!")`(print',s)))((= 0 n)(eval s)))

(do ((n (read) (1- n))
     (s '(princ "Hello!") `(print ',s)))
    ((= 0 n) (eval s)))

The only non-straightforward thing: it generates one more level of program than needed and evaluates it, because eval is one character shorter than print.

Common Lisp: 65
#1=(SETF N(READ)(CADDR'#1#)(1- N)W(PRINT(IF(= N 0)"Hello!"'#1#)))

This version is smaller than the existing CL-answer. In case your Lisp croaks with a stackoverflow, then you have to use this, 81 bytes:
#1=(SETF N(READ)*PRINT-CIRCLE* T(CADDR'#1#)(1- N)W(PRINT(IF(= N 0)"Hello!"'#1#)))

I know I'm late to the party, and I'm sure this could still be optimized.
Demonstration (careful, some online REPLs don't work correctly):
* #1=(SETF N(READ)*PRINT-CIRCLE* T(CADDR'#1#)(1- N)W(PRINT(IF(= N 0)"Hello!"'#1#)))
2
#1=(SETF N 1
         *PRINT-CIRCLE* T
         (CADDR '#1#) (1- N)
         W
           (PRINT
            (IF (= N 0)
                "Hello!"
                '#1#)))
#1=(SETF N 1
         *PRINT-CIRCLE* T
         (CADDR '#1#) (1- N)
         W
           (PRINT
            (IF (= N 0)
                "Hello!"
                '#1#)))
* (eval *)

#1=(SETF N 0
         *PRINT-CIRCLE* T
         (CADDR '#1#) (1- N)
         W
           (PRINT
            (IF (= N 0)
                "Hello!"
                '#1#)))
#1=(SETF N 0
         *PRINT-CIRCLE* T
         (CADDR '#1#) (1- N)
         W
           (PRINT
            (IF (= N 0)
                "Hello!"
                '#1#)))
* (eval *)
"Hello!"
"Hello!"
*

Note that:

Tested using SBCL 1.2.11.debian
There are lots of warnings because I'm doing things that are seriously not supposed to be done. Thankfully, all warnings are printed with a semi-colon, so they would be treated as comments anyway.
Duplication is because one is the return value and one actual output. If the return value would also count, then it simplifies to 58 bytes: #1=(SETF N(READ)(CADDR'#1#)(1- N)W(IF(= N 0)"Hello!"'#1#))
I still know I'm late to the party

Python 2.7, 57
print reduce(lambda x,y:y+`x`,input()*["print"],"Hello!")

Haskell, 62
main=interact$(iterate(("main=putStr"++).show)"Hello!"!!).read

Bash, 47 or 12 (if I use golfbash)
Code:
read x;for((;x>=0;x--)){ O+=" echo";};$O Hello!

golfbash code:
R;n e Hello!

Previous code (49):
read x;E=echo;eval \"\${E[0]\"{0..$x}\"}\" Hello!

Use:
Make program P
$ echo '<paste code here>' > P

$ chmod +x P

Example
Make P1:
$> echo 4 | ./P >
echo echo echo echo Hello!

Make P2:
$> echo 4 | ./P | bash
echo echo echo Hello!

Make P3:
$ echo 4 | ./P | bash | bash
echo echo Hello!

Make P4:
$ echo 4 | ./P | bash | bash | bash
echo Hello!

Run P4:
$ echo 4 |./P | bash | bash | bash | bash
Hello!

Say that I make a new general purpose language called golfbash - at bit like golfscript - that has some useful commands like these:
R which reads stdin and places result into variable $REPLY.
n $1 $2 which echo's $1 $REPLY times followed by $2.
e which echo's all parameters to stdout.

Then I could write this:
R;n e Hello!

This would be legal, would't it?

That's rude. -1 for what?

+1. I guess the downvote was for your invented language that appears to be specifically for this challenge. See http://meta.codegolf.stackexchange.com/questions/871/creating-new-language-would-it-be-legal

Fine, but I did it in bash as well.

F#, 182
let say msg = sprintf "%s" msg
let gen num =
    let rec g n a =
        match n with
        | i when i > 0 -> g (i-1) ("say \"" + a + "\"")
        | _ -> say a
    g num "Hello!"

When I run your program, it does not appear to input anything from stdin, nor to output anything to stdout.

J - 31 char
Keep in mind that J uses Pascal-style strings: 'It''s too easy!'
'Hello!'(],,)''''#~<:2^".1!:1]1

Explained:

".1!:1]1 - Read in a line from stdin and convert it to a number.
<:2^ - Take 2 to the power of this number, and decrement.
''''#~ - Make a string with that many copies of the single quote character.
'Hello!'(],,) - Append these quotes to the front and back of Hello!.

Usage:
   'Hello!'(],,)''''#~<:2^".1!:1]1   NB. let's try 3
3
'''''''Hello!'''''''
   '''''''Hello!'''''''  NB. P1
'''Hello!'''
   '''Hello!'''          NB. P2
'Hello!'
   'Hello!'              NB. and P3 prints Hello!
Hello!

Python 2.7: 75
def h(n):
 return "Hello"if n<1 else'print %s' % `h(n-1)`
print h(input())

First time golfing, not sure if I'm doing it right ;p

Doesn't that assume that the definition of h is also known in the subsequent programs? (So that this would have to be run in a REPL or something?)

Clojure, 36 bytes
(str(apply str(repeat 5\'))"Hello!")

Symbol
'something

evaluates to
something

Build up a symbol with 5 single quotes and run the result until no quotes left.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Christmas Lists
The challenge is to create one program that will accept as arguments (arrays of arrays) or on standard input (line-by-line, separated by commas) a collection of families and names, like so:
John,Anna
Mark,James
Elizabeth,Daniel,Isabelle
Ryan,Ruth

As well as two other arguments (two more arrays of pairs, as arrays) or on standard input (a blank line after the preceding input, followed by two comma-separated lists on two lines with an = separating pairings; see example) that represent the two previous years' Christmas lists:
John=Mark,James=Anna,Elizabeth=Ryan,...
John=Isabelle,Ryan=Elizabeth,Daniel=Mark,...

The function/program must return/output (in any format) a way that each person is assigned somebody to give a present to, following these rules:

A person cannot give a present to him or herself.
A person cannot give a present to anybody in his or her own family.
A person cannot be assigned the same person he or she was assigned in any of the two previous years.

If such a matching is impossible for every person, output/return null or nothing or something appropriate.
This is a code golf, so shortest code wins, but I'll also give a bounty to the code that runs fastest (on my computer, at least, though results shouldn't vary much).

Are the gift assignments symmetric?  The text doesn't say so, but using = to represent the assignments suggests it...

Shouldn't the number of people be guaranteed to be even?

@KeithRandall: No, they aren't symmetric.

@PeterTaylor: No, because they aren't symmetric. (Dan=Marge,Marge=Carolyn,Carolyn=Don,Don=Bob,Bob=Dan)

-1: Bad timing, imho. Summertime, and the living is easy. Instead we shall work out xmas stuff?

@userunknown What, we can't prepare early for christmas? I like to buy my christmas cards in January in the sales. :-) Seriously though, I think -1 for being unseasonal is a little harsh.

@userunknown: Summer is the best time to shop for winter holidays because you're often going shoppable places, and nobody else is thinking to do it :) [Also, -1? Okay, then...]

Related (but not a duplicate as this version has additional restrictions): http://codegolf.stackexchange.com/questions/838/holiday-gift-exchange

GolfScript, 90 characters
+:q;:f[]*:^[]:r\{.,{(^3${1=}%-f{2$\?)},~-q{(3$={-.}*;}/{.[[2$\]]4$|3$c;}%;;;}{;:r}if;}:c~r

The program does a simple recursive search on the names. It actually calculates all possible lists but saves them to a variable for output, so only the last one is returned.
The input/output is on the interpreter stack (first families then two previous years` assignments), e.g.
#PREPARE INPUT
;
[["John" "Anna"]["Mark" "James"]["Elizabeth" "Daniel" "Isabelle"]["Ryan" "Ruth"]]
[["Ruth" "John"] ["Ryan" "Daniel"] ["Isabelle" "Mark"] ["Daniel" "Anna"] ["Elizabeth" "James"] ["James" "Elizabeth"] ["Mark" "Ryan"] ["Anna" "Isabelle"] ["John" "Ruth"]]
[["Ruth" "Anna"] ["Ryan" "Elizabeth"] ["Isabelle" "John"] ["Daniel" "James"] ["Elizabeth" "Mark"] ["James" "Daniel"] ["Mark" "Isabelle"] ["Anna" "Ruth"] ["John" "Ryan"]]

#PROGRAM
+:q;:f[]*:^[]:r\{.,{(^3${1=}%-f {2$\?)},~-q{(3$={-.}*;}/{.[[2$\]]4$|3$c;}%;;;}{;:r}if;}:c~r

#SHOW OUTPUT
p

prints the output
[["Ruth" "Elizabeth"] ["Ryan" "John"] ["Isabelle" "James"] ["Daniel" "Mark"] ["Elizabeth" "Anna"] ["James" "Ruth"] ["Mark" "Daniel"] ["Anna" "Ryan"] ["John" "Isabelle"]]

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Finding duplicate balls in a basket?
A basket is full with \$n\$ colored balls. For each color except one, there are at least 2 balls with that color. Find the color which only has one ball. in \$O(n)\$ space complexity.
What if each ball is repeated exactly  twice?
You can consider the input to be an array or a list or any container of colors as strings with a maximum length of 100
This is code-golf so the shortest code in bytes wins.

Unless you specify some kind of input and output format (or the flexibility of what you allow) people are going to make vastly different assumptions.

This question isn't suited for CodeGolf.  You need to specify a winning criteria. Otherwise, try StackOverflow.com if you are needing help.

Do you want us to find the duplicate balls as the title suggests?

@PrinceJohnWesley Yes thats the whole idea!!

-1 no input format specified, no output format specified... How you output the repeated ball? Index? Is it one indexed or zero indexed?

Python - 17 chars
Solely as an expression:
min(B,key=B.count)

Full, standalone program with input and output, 34 chars:
B=input()
print min(B,key=B.count)

edit: What gnibbler said.

Python3 would be a little shorter - use input instead of raw_input and () around the print. Since the input format isn't specified, why not assign single letter codes to each colour? eg "rrgbb", then you can drop the split(). And use min instead of sorted FTW

Thanks! Yeah, I guess a string is within the bounds of 'any container' :D The question doesn't even mention input, so I think it's legit with 2.x's input() and have the user wrap quotes around it too.

K, 17 15
&1=#:'=" "\:0:0

Takes input from stdin as a space separated list
k)&1=#:'=" "\:0:0
red red green blue blue
"green"

I think you've got me beat this time - it takes me 15 characters just to get the separate strings.

...or maybe not - I've got the input down to 8 which at least gives me a fighting chance... :-)

Given the way you successively golfed the last one I wouldn't be surprised to see you beat me again. My solution can't get any shorter, I think.

No, I think 20 is my limit here.

No need to wrap this in a function, &1=#:'=" "\:0:0 runs fine for 15.

J, 31 24 20 characters
{.(~./:#/.~);:1!:1[1

A lot prettier than the previous attempt. Takes input from keyboard.
Makes an assumption that wasn't necessary in the previous version - that there is exactly one colour with one ball. If there are 2 colours with one ball you'll get the first that appears in the list, if there are no colours with only one ball you'll get the colour with the least balls.
Example:
   {.(~./:#/.~);:1!:1[1
green green red blue blue
┌───┐
│red│
└───┘

SQL - 44
Find Unique Color
SELECT C FROM B GROUP BY C HAVING COUNT(C)=1

Find Duplicate Colors
SELECT C FROM B GROUP BY C HAVING COUNT(C)>1

The right tool for the job!

Python 2.7, 44 chars
Using the same sort of format as Keith Randall's answer of a function that takes an array and returns the element/colour that only occurs once.
R=lambda B:[a for a in B if B.count(a)<2][0]

Alternatively, if I need to read in colours  from the command line and output the colour that is unique (which takes 60 chars):
B=raw_input().split();print[a for a in B if B.count(a)<2][0]

This is O(1) space complexity - which is usually better than O(n), but technically isn't what the question asks for :)

I think you could use <2 rather than ==1 to save a char.

@gnibbler: O(1) is a subset of O(n).

@grc: Thanks, amended the solution.

Clojure - 44
#(some(fn[[c n]](if(= n 1)c))(frequencies%))

That's a lambda function. Example:
(#(some(fn[[c n]](if(= n 1)c))(frequencies%))
  [:red :red :red :blue :green :blue :yellow :yellow])
=> :green

GolfScript, 23
After a tremendous amount of help from w0lf, here's the source code.
' '/:x.&{x{1$=},,1=\;},

DEMO

28 characters with the error checking ? is displayed if there is not one unique color.  For the sake of keeping the number of characters down to a minimum, the question mark was used (this of course can be changed to something more meaningful).
' '/:x.&{x{1$=},,1=\;},'?'or

DEMO

Commentary
' '/:x        # split up each element and assign it to 'x'
.&            # copy the last element in the stack and do a "setwise and"
{x            # start filtration process and invoke 'x'
{1$=}         # checks for an equality comparison
,,            # find the count of each unique character
1=            # compare value to '1'
\;            # leave only value that has count of '1' on the stack
},            # close filtration process and print element on stack
'?'or         # OPTIONAL: is printed if no element with a count of '1' is found

Mathematica 23
n contains the list.
Cases[Tally@n,{x_,1}:>x]

05AB1E, 2 bytes
.m

Try it online!
.m is a builtin function which return the least frequent element in a list.
If you are not allowed to use a builtin to solve the challenge, then
it's 4 2 bytes:
-2 thanks to @caird coinheringaahing
ʒ¢

Try it online!

-2 bytes

Python 2.7, 67 chars
from collections import*
R=lambda B:Counter(B).most_common()[-1][0]

R - 18 chars
which(table(x)==1)

APL (14)
B/⍨1=+/B∘.≡B←⎕

Takes input from the keyboard in the form of an APL list, so you need to put quotes around the colors 'like' 'this'. (Or use numbers.)

      B/⍨1=+/B∘.≡B←⎕
⎕:
      'green' 'green' 'red' 'blue' 'blue'
 red

As a function (that takes a list, also 14 characters):
{⍵/⍨1=+/⍵∘.≡⍵}

Groovy - 22 chars
it.min{a->it.count(a)}

Attribution and test case:
lone={it.min{a->it.count(a)}}

l = ['red','green', 'red', 'blue', 'green']

assert lone(l) == 'blue'
assert lone(l) != 'red'

You might want to put a link to TIO, like Try it online!

@CommandMaster Keep in mind that this question and answer were posting 8 years ago, and that the answerer hasn't been on the site since 2018

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Tips for golfing in J
GolfScript gets its own way far too often and I feel that a repository of handy hints for golfing in J might help in the fight against the evil empire. What tips do you have for making this already terse language shorter?
For those wanting to learn J, the obvious place to begin is the jsoftware site and particularly the vocabulary, the Learning J guide and the J for C programmers guide.

There is something funny about reading GolfScript gets its own way far too often in 2019.

What tips do you have for making this already terse language shorter? You're predicting the existence of CJam...

There are a number of subtleties to squeezing out the last few characters in J. For the following, assume that each capital letters is a primitive verb (i.e. I am removing the spaces that would otherwise be required to delimit names).

When you have a train going, and you need to apply a function atop another partway through, ([:FLGR) and (LF@:GR) have the same number of characters, but (LF@GR) saves one. If the frame of G is greater than or equal to the monad rank of F, this is a valid transformation. Notably, all trains have infinite rank, as do , ,. ,: ~. /: \: [ ] and most uses of # and |..
If you have to pick strings out of a list, and these strings have no spaces, use >i{ab`cd`ef. It's dirty, but it saves characters for each new string you have to deal with, unless you're just pulling single characters, and even then the charlist has to be length 4 to be shorter. What's happening is that undefined names are treated as references to verbs, and when you take the gerunds of those verbs you get a boxed string of the name. Any names that are already defined as having type noun, adverb, or conjunction cannot be used in this fashion, because those names get resolved before ` can have at them.
If you're lucky enough to have an expression to work with and not just a tacit verb, it's almost always worth it to assign any bits you reuse to variables, be they nouns, verbs, or adverbs. The parens will sometimes pay themselves back by fitting right into where you had spaces before, and most such definitions are worth it if they're reused even once more.
Conjunctions like (FGH)^:(u`v`w) can be rewritten u`v`w(FGH^:). This works for any length of train, even 1, though you only save anything if this trick removes parens from the right argument. This trick only works when you preload the left operand. (Have no idea what just happened? Look up 'tacit adverbs', and study the Parsing and Execution section of the J Dictionary.)
Don't use a.&i., use u:! {&a. and 3&u: are equivalent on length, though, and the former might be more useful in a conjunction (depending on the conjunction).
Things like (2%~F) and (F%2:) are equivalent in length. This is useful because sometimes, depending on what the rest of your train looks like, you can restructure it with @ tricks as written in the first point, to save some desperate characters. (And of course, if F is ] and the train is a monad, using %&2 saves a char, duh.)
Hook-like trains with ] or [ as the leftmost verb, e.g. (]FGH).

] lets you break up a dyadic application and use the right argument only. (Swap to left with (]FGH)~, at a penalty of at least 1 character, maybe more.) Saves a char over (FGH)@], and is very handy in gerunds!
[ in a hook applied monadically allows you to do something for the side effects on the right side, then return the argument again. Most common usage is with 1!:2, possibly with formatting junk.

I/O sucks. Speed up the process by making loops out of everything you can. 1!:1 has rank 0, and both of 1!:2 3 have rank _ 0, for example, so utilise this by making arrays of 1s and run 1!:1 directly over them. Note that ". also has rank 1, so you can usually just put that directly after 1!:1, too, and not have to attach it via @ or rank shenanigans.
It's not easy to find places to put this, but :: can be useful.

::]^:_ is a particularly powerful combination, for example, that lets you do something dangerous until you can't do it anymore. (Subject to the usual ^:_-as-a-loop caveats.)
This also lets you use { on lists that don't have the desired index, because it throws a domain error when that happens. Useful to e.g. take the head of a list only if it exists (try using ::] to return the empty list, or ::_1: to return an error code, and so on).

]`($:@u)@.v can usually be made shorter than u^:v^:_, especially on definitions of u and v that can be played around with. A similar case holds for the conditional-like u^:(1-v) vs. ]`u@.v. Consider your options, especially when you have lots of named verbs floating about. It's also a little more flexible, but remember, if using $:, there is a recursion depth that it's easy to bump up against. (Usually something like 1800 iterations?)

The adverse trick is really cool.

"save some desperate characters"
When you're studying lit, everything looks like a transferred epithet! :)

"using %&2 saves a char, duh." And -: saves another!

Be wary of using loops.
While J has looping structures (for. do. end., while. do. end. and variations), if you find yourself using them there's a possibility that your algorithm is not playing to J's golfing strengths and that there are character savings to be made.
^: the power conjunction is your friend. To execute a verb x times:
verb^:x

If you need the result of each iteration in a list:
verb^:(i.x)

You can also use ^: to execute a verb conditionally:
  +:^:(3<])"0[ 1 2 3 4 5 6
1 2 3 8 10 12

Double +: if ^: the item is greater than 3 3<] (the "0 changes the rank of the verb so it works an item at a time).

Boxed values act like the (i.x) example, i.e. f^:(<x) is equivalent to f^:(i.x).

The most important thing when golfing in J is to not only understand the problem, but to reduce the problem to a series of array transformations. You need to understand this way of thinking to have any success with J code.
For example, a recent challenge asked to solve the largest subarray problem. The stock algorithm to solve this problem is Kadane's algorithm has the following informal description:

Go through the array and at each position and find the sum of the largest subarray ending here, which is the maximum of 0 or the value at the current index plus the sum of the largest subarray ending at the previous position. Compute the maximum of these subarrays as you go to find the largest subarray in the entire array.

A translation into imperative code is straightforward:

let A be the input array.
h ← m ← i ← 0.
if i ≥ len(A) return m.
h ← max(0, h + A[i]).
m ← max(m, h).
i ← i + 1.
goto 3.

This algorithms seems complicated for J at a glance as there is an explicit loop that doesn't look like a reduction at first. If you realize what the algorithm is doing you can untangle the individual steps and see that it actually performs two simple array operations:

Scan through the array to compute the lengths of the largest subarrays ending at each index.
Reduce these lengths with the max function to find the maximum.

Now these two steps are very easy to implement in J. Here is a translation:

(0 >. +)/\. y , 0 – This step operates from the other end of the array to better fit J's paradigm. 0 >. + is tacit for 0 >. x + y.
>./ y

Put together, we get a very terse implementation of the algorithm:
>./ (0 >. +)/\. y , 0

If you learn this way of approaching the implementation of algorithms, your solutions will be as terse as this code.
Here are some tricks I accumulated over time. This list will be expanded as I get more knowledge in J golfing.

Learn the dictionary. It contains a lot of really obscure verbs that don't make any sense until you see how useful they are. For instance, monadic = is strange at first but is very useful in ASCII art challenges.
Use dyadic & in tacit contexts when you want a power conjunction. The vocabulary suggests u@[&0 as a tacit replacement to 4 : 'u^:x y and so do I.
In many cases you can avoid a [: or @: in a sequence like u@v by choosing a variant of u that has a left argument. For instance, to drop the first item of the result of v, use 1}.v instead of [:}.v if }.@v isn't possible for some reason.
] v is often shorter than v@] if you want to use monadic v in a dyadic context. This comes in useful especially when v is a long train of verbs.
Sometimes you can write m (n v w) y instead of (n v m&w) y. This may make it possible to avoid spaces and parentheses.
#\ instead of >:@i.@#.
u &. v is useful when v has an obverse. When not, you might want to use [: vinv u & v or u & (v :. vinv) instead.
Understand rank and how to use it. Try to fiddle around with the rank conjunction until you get something that fits. It helps understanding how rank influences your code.
^:_ is extremely useful for algorithms where you want to reach convergence, like a flood-fill or simulations.
Know your standard library. It contains very useful functions that save you tons of characters.
The copulæ =. and =: can be embedded anywhere in a phrase. Use this to make one-liners where tacit notation isn't enough.
Use monadic , instead of multiple reductions when reducing multi-dimensional arrays.
Understand what phrases are supported by special code when the challenge imposes runtime boundaries. Some useful things operate in O(n) instead of O(n2) counter-intuitively.
Boxes are useful for trees.

Is J smart enough to run your max subarray solution in O(n) by caching re-used calculations, or will it do the straightforward thing and run it in O(n^2)?

@Jonah I think it runs in quadratic time.

Input
1!:1[1 will take one line of input terminated by pressing the enter key.
1!:1[3 will take a number of lines of input (terminated by Ctrl-D on my Mac, Ctrl-C on Windows).
If you're trying to input numbers, using ". will evaluate the string and return a list of numbers ready to be manipulated. If you're taking in one number but need to operate on the digits individually, ".,. (thanks to Jan Dvorak's comment for this) or "."0 will split the string into separate digits:
   "."0[1!:1[1
12345
1 2 3 4 5

   ".,.1!:1[1
12345
1 2 3 4 5

If you're reading in strings, the shortest way to get a boxed list of separate strings is to use ;:. This works best for space separated strings:
   ;:1!:1[1
hello world
┌─────┬─────┐
│hello│world│
└─────┴─────┘

Out of curiosity, (I've only played with J a little) what would 1!:1[2 work out as (if anything)?

From what I can gather on the 1!: page (I'm no J expert) 2 is the screen, so input from screen doesn't make much sense.

Thanks for the link. From there, it actually looks like 2 is not valid? I don't have my J computer on me to try it out at the moment. Where I see 2, just below the notes about 1!:1, it is for 1!:2.

@Gaffi The file numbers for input and output seem to be sequential, so I'm guessing that those are fixed and that 2, 4 and 5 only appear under output because it doesn't make any sense to try and input from them. Same goes the other way around for 1 and 3.

Since ". is rank 1-x-x and ,. always produces a 2D array, ".,' ',. (stitch with space, ravel and evaluate; 8 characters) can be replaced with just ".,. (ravel items and evaluate; 4 characters).

Consider using explicit definition instead of writing a tacit verb; sure the 3 :' and ' cost 5 bytes, but you can save a lot of @, @: and [: that way.

{{...}} is one byte shorter than 3 :'...'

Sure is, @Sʨɠɠan! My answer is from before that syntax existed!

Using iteration to compute sequences
Typically, solving an OEIS sequence challenge will require using one of the formulas given on its page. Some of these adapt well for J, and others not so much. Recursive formulas are straight-forward, however, iteration might not be simple. A pattern I've begun to use is
(s(]f)^:[~]) n
          ]  Gets n
 s           The first value in the sequence
         ~   Commute the argument order, n is LHS and s is RHS
        [    Gets n
      ^:     Nest n times with an initial argument s
  (]f)         Compute f s
             Returns (f^n) s

where s is the first value in the sequence, f is a verb that will compute the next term given the previous term, and n is the zero-based index of the term you want to compute. This method relies on the fact that when computing the power of a dyad, the LHS is bound to the dyad to form a new monad, and that monad is nested on the initial value. The dyad given to the power adverb is a hook where (]f) is given the index n on the LHS and the value of a term in the sequence s. The hook will apply f on s as a monad, and then ignore n to return the result of f s.
Standard library
Sometimes, you might find that J will have support for a verb in its standard library. For example, most of the bitwise integer operations are bound to names which are shorter than using the primitive call.
AND =: (17 b.) NB. it is actually '$:/ :(17 b.)'

Date and time builtins are also available.
Ranges
If you have a set of values [a, b, c] and you want to form a range based on their product like [0, 1, 2, ..., a*b*c-1], the typical approach would be to find their product and then form a range which might be [:i.*/ which costs 6 bytes. A shorter way is ,@i. for 4 bytes since i. can form multidimensional arrays while still counting up, and flattening it will produce an equivalent range.
Printing continuously
A tacit way to print a value and continue to use it without an explicit loop is ([echo) for a monadic case. echo is a verb in the standard library that prints its contents to stdout in the same format used in the interpreter. The hook then passes the same input value out using the left [ verb.
Base 10 digits of an integer
The standard way of acquiring the base 10 digits of an integer is 10#.inv] which costs 8 bytes, too much! An alternative is to convert it to a string and parse it at rank 0 "."0@": which saves a byte, but an even better way is ,.&.": which saves another byte making the final cost 6 bytes instead of 8.

Shorter ways to mess with ranks
Sometimes, you'll have code like <"0 i.3 3, where you want to apply a verb v at rank r. However, if you use a noun (like 0), you'll often have to include a space. To avoid this, you can use another verb u of equivalent rank and use u"v instead. For example, since + has rank 0 0 0, we can use <"+ instead of <"0.
Here is a table of all verbs and their ranks (obtainable by using v b. 0):
0 0 0     > + * - % ^ | ! ? <. <: >. >: +. +: *. *: %: ^. j. o. q: r.
0 _ _     -. -: E. i: p:
1 0 1     p..
1 0 _     { A.
1 1 0     p.
1 1 1     #.
1 1 _     C.
1 _ _     ;: ". i. I.
2 _ 2     %.
_ 0 0     = < ~. ~: {: }: ?. L.
_ 1 0     #:
_ 1 _     $ # |. |: {. }. ": {::
_ _ _     , ; [ ] _: $. $: ,. ,: /: \: [: e. s: u: x: 0:

To use this table, find the desired rank r on the left hand side, then choose an appropriate verb v from the right hand side. E.g., if I need to vectorize a verb v at depth 2 _ 2, then I find that rank on the left and choose %. from the right. Then I use v"%. instead of v"2 _ 2.

Some (fairly) common tricks I've seen
I'm sharing a few things that have come in handy for me. Basically all of these are tips I've received myself, but I don't have credits for most.
Sum of a rank one array
Instead of using +/@:(FGH) use (1#.FGH). This means debase to base 1, which effectively means summing an array. Although it's longer than +/, it doesn't require a cap or composition, which often makes it much shorter than using +/.
Counting trailing truths
If you have a boolean list and you want to count the number of trailing truths, use #.~. See here. The APL answer provides a good explanation for how this works. Granted, this has only been helpful to me twice but I figured I'd share it anyways.
Under (&.)
Not a specific trick, but just a general suggestion: the adverb &.-under often leads to elegant and (more importantly) short solutions. Keep it in mind when you're golfing.
Often times it's useful for binary and other base conversion challenges, e.g. this code which removes the most significant bit from a number: }.&.#: (convert to list of binary digits, remove the first digit, then undo the conversion to a list of binary digits and convert back to decimal). The straightforward solution is two more bytes: #.@}.@#:.
Under is also helpful for challenges where you need to work with decimal digits, since you can use u&.":. For example, the short way miles gives to split to decimal digits uses under: ,.&.":.
A final example is finding the magnitude of a vector: +/&.:*:, note that you need to collect all of the results from *:-square with &.:-under since *:-square is rank zero.

Tacit programming
Basics
Dyadic verb
x (F G H) y == (x F y) G (x H y)
x (F G) y == x F (G y)
x ([: G H) y == G (x H y)  NB. G is called monadically

NB. Verbs are grouped from the right by units of 3.
NB. For the following, think like G, I, K are replaced by the results of (x G y) etc.
NB. and then the sentence is run as usual.
x (F G H I J K) y == x (F (G H (I J K))) y
                  == x F ((x G y) H ((x I y) J (x K y)))

NB. Using conjunctions for dyadic verb
x F@G y == F (x G y)  NB. Atop; Same as x ([: F G) y; Consider as golfing alternatives
x F&G y == (G x) F (G y)  NB. Compose; G is applied monadically to both arguments

Monadic verb
(F G H) y == (F y) G (H y)
(G H) y == y G (H y)  NB. Note that this is different from APL
([: G H) y == G (H y)
(F G H I J K) y == (F (G H (I J K))) y
                == y F ((G y) H ((I y) J (K y)))
F@G y == F (G y)

Misc
x&F y == x F y
F&y x == x F y
y F~ x == x F y
F~ y == y F y

Tricks
(F x) G (H y)
Tacit solution: (G~F)~H; depending on the actual verbs, consider rearranging the left and right arguments to remove ~.
x ((G~F)~H) y
x (G~F)~ (H y)
(H y) (G~F) x
(H y) G~ (F x)
(F x) G (H y)

Monadic-Dyadic replacements
>:y == 1+y
<:y == 1-~y or _1+y
+:y == 2*y
-.y == 1-y
-:y == 2%~y
*:y == 2^~y
#.y == 2#.y
#.inv y == 2#.inv y  NB. #: doesn't work this way
{.y == 0{y
{:y == _1{y
}.y == 1}.y
+/y == 1#.y  NB. Vectors only
+/"1 y == 1#.y  NB. Higher-dimension arrays

(G~F)~H is pure bubbly goodness!

strings library: golfing tips
The strings library is vastly helpful for doing anything with string manipulation. Sure, it takes include'strings' (which is very costly, considering J), but you may at times reap the benefits.
stringreplace
Find yourself using string replace? Observe that A stringreplace B is the same as B rplc A.
In fact, this is how rplc is implemented:
   rplc
 stringreplace~

cuts
The verb cuts provides thus:

cut y at x (conjunction)
string (verb cuts n) text
  n=_1  up to but not including string
  n= 1  up to and including string
  n=_2  after but not including string
  n= 2  after and including string

So it's really slicing a string.

Getting numbers from 0 to 4
If there’s a restriction on using numbers in your code:
0 %_: one divided by infinity.
1 #_: how many infinities?
2 #_ _: two infinities.
3 verb: there’s a built-in.
4 dyad: another built-in.
Getting numbers from 10 to 35
Base-inifinity literals: 11:_bb, 26:_bq etc.

Miscellaneous ideas
Cross-post of my own APL tip, because APL and J are so closely related that the two can share many ideas.
If you're facing [:-~/, use _1#. instead
A common reason to use -~/ is to reverse-subtract over a length-2 axis, e.g. given a 2-element array x y, compute y-x.
If this is the case, _1#. is an equivalent expression; just like 2#.x y computes 2x+y, _1#.x y computes -x+y. While -~/ most likely requires the use of [: (capped fork) or @ (atop), _1#. is likely to fit just well in trains as-is.
Note that, if you apply it to longer axis, _1#. gives you more similar result to -/ (alternating sum), with negated result when the length is even.
Construct a boolean square matrix where the border is ones/zeros and the interior is the opposite
This is mainly for large fixed-size matrices, say 6 by 6.
The matrix
1 1 1 1 1 1
1 0 0 0 0 1
1 0 0 0 0 1
1 0 0 0 0 1
1 0 0 0 0 1
1 1 1 1 1 1

can be generated by +./~ -ing the boolean vector 1 0 0 0 0 1. The shortest known way to generate that vector is #:33, so we can get the matrix above in just 8 bytes:
+./~#:33

If we're to put this in a train, a constant function +./~@#:@33 and parenthesized noun left arg (+./~#:33) have equal length of 10 bytes. The two forms have their own pros and cons: the former can be placed at the right end of a train, while the latter may serve better by not messing up with something that comes on its right (e.g. 33e. is a syntax error).
We can also get negation of it at no extra cost, by swapping +. with +:! (Remember that J, like APL, has NOR +: and NAND *:; they are rarely needed, but definitely are a byte saver when we do need them.)

& is your friend, use it wisely
v is a verb, n is a noun, x and y are left and right arguments, respectively.
Monad &: Introduce ~ inside adverb/conjunction chain
An adverb/conjunction chain evaluates from the left. So something like _2&+/\&.> won't work because it parses like (_2&+)/\&.> while we want _2&(+/\)&.>. In this case, swapping the left/right of +/\ can save a byte, as in +/\~&_2&.> because this one parses as ((+/\)~)&_2&.>. To see why this works:
+/\~&_2 y
is equivalent to
y +/\~ _2
is equivalent to
_2 +/\ y
is equivalent to
_2&(+/\) y

Dyad &: Repeat x times
Did you know that if you give a left argument x to &, the function applies it x times to y? Quite a few challenges ask you to do certain operation x times. It is mainly achievable in two ways:

Use the power operator ^: without right operand

If the operation is v, then v^: becomes an adverb train that, when given a left operand, becomes a monadic verb. So v is applied to y, x times.
x(v^:)y
is equivalent to
(v^:x)y

Use the dyadic & as the outermost conjunction

To use this, you need to identify a constant n and a dyadic verb u, so that either n u y or y u n is equivalent to v. Then you can write n&u or u&n to solve the entire task. This form is most effective when the choice of the constant is obvious, e.g. 3 in 3 u: (convert chars to ASCII values).
Also, u&n is slightly preferred over n&u when the outermost structure of u is a conjunction or adverb (in which case n&u should be n&(u); you can do u~&n instead).
Note that you can place the dyadic & anywhere in a train to achieve repeating arbitrary function to arbitrary argument, in the similar sense to dynamic ^:.

x$y does something different than you think
Dyadic $ is called reshape. If you're coming from APL, you'd know ⍴ under the same name which lists down all elements of y before creating the x-shaped array.
J handles it differently: it does not flatten y; instead it uses y's items, or major cells, to fill in each cell of the x-shaped array. So the resulting shape becomes x,}.$y. It doesn't look very useful by this description.
There is one use case where this becomes useful in code golf: when x is a positive singleton. Then x$y acts like a take or repeated overtake.

When x <: #y (x is smaller than or equal to length of y), the result of x $ y is exactly same as x {. y, directly shaving one byte no matter what. The verb ranks are identical (1 _), so the replacement is safe even in a rank-sensitive context (e.g. @/&).
When x > #y, the result becomes y cyclically extended to length x. This is different from x {. y (which would fill the missing places with zeros/blanks), but it could have its own uses.

Note that, in both cases, the result is equivalent to using the individual elements to fill in x,}.$y-shaped array.

Know (and abuse) J's truthy/falsy (decision-problem)
When truthy/falsy is not defined by the language spec, it is defined as the one that is accepted by an if statement. Truthy ones are those that make the if clause run, and falsy ones are the opposite.
Unlike APL (where only 1/0 are truthy/falsy respectively), J is quite liberal. J's if. clause accepts any array, and evaluates to falsy if and only if the array is nonempty and its first atom is a numeric zero. Any other arrays (including empty arrays, character or boxed arrays) are truthy.
Demonstration:
f =: 3 : 0
if. 0         do. echo 'yes 0' end.
if. 1         do. echo 'yes 1' end.
if. 2         do. echo 'yes 2' end.
if. 0 1 2 3 4 do. echo 'yes 3' end.
if. 2 0 0 1 3 do. echo 'yes 4' end.
if. 0$0       do. echo 'yes 5' end.
if. 'abcd'    do. echo 'yes 6' end.
if. '';'def'  do. echo 'yes 7' end.
)
f ''

Output:
yes 1
yes 2
yes 4
yes 5
yes 6
yes 7

yes 0 and yes 3 were not printed because the array is nonempty and the first element is zero. Having zeros at any other positions does not affect the truthy/falsy interpretation. Try it online!

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Topographic Strings
Here is some example input, so I can explain what the problem is:
((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo)))

Think of this line of text as a topographic map of some mountains. Each set of parentheses illustrates one unit of altitude.
If we "view" this from the side, so that we see the mountains vertically, we will see:
          4 5                cherries    woohoo
  1 2  3       moo       lik          e
                      i

Given one of these topographic maps, output the map, but on a vertical scale, like the output above. Seperate the different items in the map with the number of characters to the next item. For example, there are 4 spaces in the output between moo and i. Likewise, there are 4 characters in the input between moo and i.
The code which does this in the least amount of characters wins.

Is it safe to assume that heights will always be positive? For example, the input ((1 2))))))))))3 should be invalid if negative heights are forbidden.

@w0lf: yep, the parentheses will always match up.

J, 87 79 72 70 67 57 56 characters
'( ) 'charsub|.|:(+/\@('('&=-')'&=)(],~' '$~[)"0])1!:1[1

Takes input from the keyboard. Example:
   '( ) 'charsub|.|:(+/\@('('&=-')'&=)(],~' '$~[)"0])1!:1[1
((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo)))
          4 5                cherries    woohoo
  1 2  3       moo       lik          e
                      i

Explanation:
This explanation is based on the first version of my program:
|.|:('( ) 'charsub x)((' '$~{.@]),[{~{:@])"1(('('&([:+/=)-')'&([:+/=))\,.i.@#)x=.1!:1[1

x=.1!:1[1 take input from keyboard and put it into x for later
(('('&([:+/=)-')'&([:+/=))\,.i.@#) creates a list of all indeces into the string (i.@#) and stitches (,.) it together with the result of the (('('&([:+/=)-')'&([:+/=))\ verb.
(('('&([:+/=)-')'&([:+/=))\ this verb is applied to all the prefixes of the string (so on input hello it would apply to h,he,hel,hell, and hello. It is a fork, which counts the number of open brackets ('('&([:+/=) and then subtracts the number of close brackets ')'&([:+/=). This gives me list of indeces into the string and the level the character at that index should be at in the output. On simple input this gives me the following:
   (('('&([:+/=)-')'&([:+/=))\,.i.@#)x=.1!:1[1
(one(two(three)))
1  0
1  1
1  2
1  3
2  4
2  5
2  6
2  7
3  8
3  9
3 10
3 11
3 12
3 13
2 14
1 15
0 16

((' '$~{.@]),[{~{:@])"1 this is a verb which takes the list I just generated and also the output of ('( ) 'charsub x) (which just does a string replacement to replace all brackets with spaces in x). It takes the tail of each item of the list {:@] and uses it as an index into the string to get the character [{~{:@]. Then it prefixes it , with the number of spaces as indicated by the head of each item in the list(' '$~{.@]). On the previous example this gives me:
   ('( ) 'charsub x)((' '$~{.@]),[{~{:@])"1(('('&([:+/=)-')'&([:+/=))\,.i.@#)x=.1!:1[1
(one(two(three)))

 o
 n
 e

  t
  w
  o

   t
   h
   r
   e
   e

I then transpose the array |: and reverse it |. to get the desired output.

GolfScript  69
0:§;{.'()'?))3%(.§+:§' ':s*\@s\if\n}%n/.{,}%$)\;:μ;{.,μ\-s*\+}%zip n*

Online demo here.
Explanation:
0:§;                # declare the variable §, representing the
                    # current vertical level and initialize it at 0

{                   # iterate for each char in the string:

    .'()'?))3% (    # add on the stack the amount by which
                    # the current vertical level should be
                    # adjusted:
                    #   * +1 if the character is '('
                    #   * -1 if the character is ')'
                    #   * 0 otherwise

    .§+:§           # adjust the value of §

    ' ':s*          # add as many spaces as § tells us
                    # and save the space in variable s

    \@s\if\         # return current char, if it's printable,
                    # or a space if it's '(' or ')'

    n               # add a newline char

}%

n/                  # split by newline char; now we have
                    # an array of strings on the stack.
                    # Each string is a vertical line of the
                    # final output.

.{,}%$)\;:μ;        # Iterate through the strings and find the
                    # maximum length

{
    .,μ\-s*\+       # Add spaces at the end to make all the strings
                    # the same length
}%

zip                 # Transpose the strings

n*                  # Join the transposed strings by newline characters

@Gareth Yes, we both do :)

Care to add an explanation how it works?

@Timwi I've edited my answer to include an explanation

APL (59)
⊖↑{⊃,/T\¨⍨⍵×P=0}¨R∘=¨(⍴T)∘⍴¨⍳⌈/R←1++\P←+/¨1 ¯1∘×¨'()'∘=¨T←⍞

I have assumed that the 'base' needs to be usable as well. (i.e. (a(b))c(d) is valid).
If this is not necessary two characters can be saved.
Explanation:

T←⍞: store a line of input in T
'()'∘=¨T: for each character in T, see if it is an opening or closing parenthesis. This gives a list of lists of booleans.
1 ¯1∘×¨: multiply the second element in each of these lists by -1 (so an opening parenthesis is 1, a closing one is -1 and any other character is 0).
+/¨: take the sum of each inner list. We now have the ∆y value for each character.
P←: store in P.
R←1++\P: take a running total of P, giving the height for each character. Add one to each character so that characters outside of the parentheses are on the first line.
(⍴T)∘⍴¨⍳⌈/R: for each possible y-value, make a list as long as T, consisting of only that value. (i.e. 1111..., 2222...., etc.)
R∘=¨: for each element in this list, see if it is equal to R. (For each level, we now have a list of zeroes and ones corresponding to whether or not a character should appear on that level).
⍵×P=0: for each of these lists, set it to zero if P is not zero at that spot. This gets rid of the characters with a non-zero delta-y, so that gets rid of the parentheses.
⊃,/T\¨⍨: for each depth, select from T the characters that should appear.
⊖↑: create a matrix and put it right-side-up.

Which APL implementation are you using? Is it free?

@FUZxxl I've been using Dyalog APL, the Windows version can be downloaded for free.

Tcl, 50
puts \33\[9A[string map {( \33\[A ) \33\[B} $argv]

Kind of cheating, but well..
I use ascii escape sequences to get the line difference, ^[[A means move the curser 1 line up, ^[[B is move curser 1 line down.

APL, 41 chars/bytes*
{⊖⍉⊃(↑∘''¨-⌿+/¨p∘.=,\⍵),¨⍵/⍨1-2×⍵∊p←'()'}

Tested on Dyalog, with a ⎕IO←1 and ⎕ML←3 environment. It's a function that takes the required input and returns the output. Given the question's wording, I believe it's acceptable. In case it's not, here is a version that reads from stdin and writes to stdout, for 4 chars more:
⍞←⊖⍉⊃(↑∘''¨-⌿+/¨'()'∘.=,\a),¨a/⍨1-2×'()'∊⍨a←⍞

Explanation:
{                                 p←'()'}  p is the string made of two parentheses
                                ⍵∊ ______  check which characters from ⍵ are parens
                            1-2× ________  -1 for every par., 1 for every other char
                         ⍵/⍨ ____________  replace () with spaces in the orig. string
    (                 ),¨ _______________  append every char to the following items
                   ,\⍵ _____________________  for every prefix of the original string
               p∘.= ________________________  check which chars are '(' and which ')'
            +/¨ ____________________________  sum: compute the number of '(' and ')'
          -⌿ _______________________________  subtract the no. of ')' from that of '('
     ↑∘''¨ _________________________________  generate as many spaces as that number
 ⊖⍉⊃ ____________________________________  make it into a table, transpose and flip

Examples:
topo '((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo)))'
          4 5                cherries    woohoo
  1 2  3       moo       lik          e
                      i

topo 'a  (  b ( c(d)e ) f  )  g'
            d
          c   e
      b           f
a                       g

*: APL can be saved in a variety of legacy single-byte charsets that map APL symbols to the upper 128 bytes. Therefore, for the purpose of golfing, a program that only uses ASCII characters and APL symbols can be scored as chars = bytes.

I'm searching the APL character set here and I can't find the ⍨ symbol. It looks like a combination of the ¨ and ~ characters?

Hi @Gareth No, it was not in IBM APL2. You can find it in Dyalog (commercial, but there's a nagware version buried in their website, and that's good enough for golfing; IMHO the best APL available today), Nars2000 (best open source APL), GNU APL, and ngn's APL, among others.

@Gareth Graphically it's the combination of ~ and ¨, although it's a different character from both. It's an operator called Commute. In its dyadic form it flips the arguments of the dyadic function it's applied to: (5-2)=(2-⍨5). As a monadic operator it turns a dyadic function into monadic, duplicating the right argument: (2*2)=(*⍨2). It's mostly used to write an uninterrupted stream of functions from right to left, without having to put parentheses around large expressions and jump your eyes around them. In golfing it's useful because 3*⍨1-2 is one char less than (1-2)*3 :-)

So it's the equivalent of ~ in J then.

J, 56 chars
'( ) 'charsub|.|:((,~#&' ')"0[:+/\1 _1 0{~'()'&i.)1!:1]1

Another 56-character J solution... I count depth by translating ( into ⁻1, ) into 1 and all other characters into 0, and then taking the running sum of this: [: +/\ 1 _1 0 {~ '()'&i..  The rest is largely similar to @Gareth's solution.

Python, 161 chars
S=raw_input()
R=range(len(S))
H=[S[:i].count('(')-S[:i].count(')')for i in R]+[0]
for h in range(max(H),0,-1):print''.join((' '+S[i])[H[i]==H[i+1]==h]for i in R)

Ruby 1.9 (129)
Reads from stdin.
l=0
$><<gets.split('').map{|c|x=[?(]*99;x[l+=c==?(?-1:c==?)?1:0]=c;x}.transpose.map(&:join).*(?\n).tr('()',' ').gsub(/^\s+\n/,'')

Nice! you discovered a bug in the Ruby highlighter :)

I've tested and SQL highlighting works better for your program.

@w0lf ha, you're right.  I changed the // to '' which keeps the character count the same and avoids the bug in the highlighter.

Python, 130
a=[""]*9
l=8
i=0
for c in raw_input():o=l;l+=c==')';l-=c=='(';a[l]=a[l].ljust(i)+c*(o==l);i+=1
print"\n".join(filter(str.strip,a))

C, 132 characters
char*p,b[999];n;
main(m){for(p=gets(memset(b,32,999));*p;++p)*p-41?*p-40?p[n*99]=*p:++n>m?m=n:0:--n;
for(;m;puts(b+m--*99))p[m*99]=0;}

The description failed to specify how much input the submission had to accept in order to be accepted, so I settled on limits that were most consistent with my golfing needs (while still working with the one given example input). Allow me to take this opportunity to remind folks that it's often a good idea to specify minimum maximums in your challenge descriptions.
There are two main loops in the code. The first loop farms out all the non-parenthesis characters to the appropriate line of output, and the second loop prints each line.

C,  149 chars
#define S for(i=0;c=v[1][i++];)h+=a=c-'('?c-')'?0:-1:1,
c,i,h=0,m=0;main(int a,char**v){S m=h>m?h:m;for(;m;m--){S putchar(a||h-m?32:c);putchar(10);}}

run with quoted arg, e.g.  a.out "((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo)))"

Charcoal, 14 bytes
ＦＳ≡ι(«↘»)«↗»«ι

Try it online! Link is to verbose version of code.

Octave, 128
Very similar to my last answer...
p=1;x=[0];y=input(0);for j=1:numel(y);p-=(y(j)==")");x(p,j)=y(j);p+=(y(j)=="(");end;x(x==40)=x(x==41)=x(x==0)=32;char(flipud(x))

Test
Input: "((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo)))"
Output:

          4 5                cherries    woohoo
  1 2  3       moo       lik          e
                      i

C#, 229 bytes
If there's no restriction on leading vertical space, you can use this (indented for clarity.)  It'll initialise the cursor down one line for every ( found before printing, then move the cursor up and down as brackets are read.
using C=System.Console;
class P{
    static void Main(string[]a){
        int l=a[0].Length,i=l;
        while(i>0)
            if(a[0][--i]=='(')C.CursorTop++;
        while(++i<l){
            char c=a[0][i];
            if(c=='('){
                c=' ';
                C.CursorTop--;
            }
            if(c==')'){
                c=' ';
                C.CursorTop++;
            }
            C.Write(c);
        }
    }
}

PowerShell, 120 119 bytes
(($h=($c=$args|% t*y)|%{($l+=(1,-1)[$_-40])})|sort)[-1]..0|%{$x=0;$y=$_
-join($c|%{"$_ "[$h[$x++]-ne$y-or$_-in40,41]})}

Try it online!
Side effects: Chars & and ' changes height as ( and ), but displays. Compare results for:
&$f "((1 2)(3 (4 5) moo)) (i (lik(cherries)e (woohoo)))"
&$f "&&1 2'&3 &4 5' moo'' &i &lik&cherries'e &woohoo'''"

Less golfed:
$chars=$args|% toCharArray

$heights=$chars|%{
    $level+=(1,-1)[$_-40]       # 40 is ASCII for '(', 41 is ASCII for ')'
    $level
}

$maxHeight=($heights|sort)[-1]

$maxHeight..0|%{
    $x=0;$y=$_
    $line=$chars|%{
        "$_ "[$heights[$x++]-ne$y -or $_-in40,41]
    }
    -join($line)
}

AWK, 145 bytes
x=split($0,a,b){for(;""!=e=a[++b];d+=(e=="(")-(e==")"))for(c=0;c++<x;f=f<d?d:f)z[c]=z[c](c==d?e=="("||e==")"?" ":e:" ")}END{for(;f;)print z[f--]}

Try it online!
This code takes advantage of the spacing rules of the contest, which makes it possible to process single characters and build up a set of output lines one character at time.
For each character in the input string, one character is appended to all the output lines.  All but one line get   (space) characters.  Only the line associated with the current topological height get a non-space character.
Here's a breakdown...
x=split($0,a,b){ ... }

The input line is split into a character array stored in a with the number of characters found saved in x.
for(;""!=e=a[++b];d+=(e=="(")-(e==")"))

The code block is one statement, a for loop with one statement, which is also a for loop.  The outer loop just iterates over all the characters.  The top of loop test ""!=e=a[++b] stores the current character in e to save some characters later.
The annoying ""!= check is needed to keep AWK from bailing if a 0 is included in the input...
The "end of loop" statement d+=(e=="(")-(e==")" increments and decrements the d topological depth indicator.
for(c=0;c++<x;f=f<d?d:f)

The inner for loop appends a character to all the output strings the code is assembling.  It uses x (the number of characters in the input string) as the upper bound for the number of strings to construct since we don't know now many parenthesis are in the input.  That's at least 2x too large, but the code is shorter if we just assemble lines that are never used.
The "end of loop" statement f=f<d?d:f just sets f to the maximum topological depth the code sees, which is used to figure out how many lines to print out later.
z[c]=z[c](c==d?e=="("||e==")"?" ":e:" ")

The body of the inner loop just appends a character to the current output string z[c].  The input character is appended only if the current line matches the topological depth, and the character isn't a paren.
END{for(;f;)print z[f--]}

One all the characters have been processed, the code just prints all the assembled lines up and including the largest topological depth reached while parsing the input.

VB.net (For S&G)
Not the prettiest of code.
Module Q
 Sub Main(a As String())
  Dim t = a(0)
  Dim h = 0
  For Each m In (From G In (t.Select(Function(c)
                                     h += If(c = "(", 1, If(c = ")", -1, 0))
                                     Return h
                                   End Function).Select(Function(y, i) New With {.y = y, .i = i}))
             Group By G.y Into Group
             Order By   y Descending
            Select Group.ToDictionary(Function(x) x.i)
               ).Select(Function(d) New String(
                          t.Select(Function(c,i)If(d.ContainsKey(i),If(c="("c Or c=")"c," "c,c)," "c)).ToArray))
   Console.WriteLine(m)
  Next
 End Sub
End Module