Solitaire Dreams - Creating a winnable solitaire starting hand It's me. Cave Johnson.

It's May 21st. You are working at Aperture Science, finest company on Earth, and tomorrow we're releasing Version 3.0 of our flagship windowing system (or WindowS): CavOS. Unfortunately, tomorrow morning, our chief competitor is releasing Version 3.0 of their WindowS too! 

It's been leaked to me, Cave Johnson, CEO that the competing WindowS has one feature that CavOS lacks: A game of Klondike Solitaire. I, Cave Johnson, am concerned that this omission will lead to drastically lower sales. As such, I, Cave Johnson, have devised a competition between the programming interns to create a game of Solitaire. The programmer whose entry is chosen will get the opportunity to join the exciting GlaDOS AI project.

I, Cave Johnson, has a few requirements:


Due to the fact that the Software must ship tomorrow, the shortest program will be chosen such that it can fit in the spare sectors of the already printed, imaged floppies.
Don't worry about the gameplay. Our customers have printers don't they? All I need is for your program to produce a list showing: The order of the cards in the deck, and the contents of each of the 7 piles. The deck will be dealt from the top. The piles will be visible from the bottom. Use the abbreviations H, D, C, S for Hearts, Diamonds, Clubs and Spades. Use the abbreviations K, Q, J, A for King, Queen, Jack, and Ace. Each card should be separated by a space. The first line should show the deck, the second the card of the first and smallest pile, the third the cards of the second pile and so on. You are welcome to use T instead of 10 if you wish.
We're making lemonade here - not sucking lemons. I, Cave Johnson, don't like losing, and neither do our customers. Every game must be winnable
The game must be randomised. No attempting to encode a single game. There are  7000 trillion possible Klondike hands, and about 90% of them are winnable. I'd be happy with a program that can produce 256 or more different hands. If your language lacks a manner to get random numbers (from a timer or the like), then assume that you can get a seed in a manner appropriate for your language.
Our customers are reasonably clever. Assume for winnability that they're playing Draw 3, with no limits on times through the deck


On behalf of everybody (and everything) at Aperture, I wish you all good luck. We're counting on you.

"Caroline? How do I shut this damn thing off?"



Out of character: assume the rules of Windows, Draw 3, Not-vegas solitaire. I've attempted to cross every t and dot every i, but ask if you've any questions. Good luck.

Example output:

5H AS 7C 8S QH ...    
AH    
JS 10S    
JC JH 7C    
9D AC 8D 7C     
.    
.    
.
Brainfuck - 1575 1365

I am horribly abusing the minimum number of unique deals. This will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;&gt;[&gt;[&lt;&lt;+&gt;&gt;-]&lt;[&gt;+&lt;-]&gt;&gt;[&lt;&lt;+&gt;&gt;-]&lt;-[&gt;+&lt;-]&gt;]&gt;
.[-]&gt;.[-]&gt;[[&lt;&lt;&lt;&lt;+&gt;&gt;&gt;&gt;-]&gt;]&lt;&lt;++++[&gt;++++++++&lt;-]&gt;.[&lt;&lt;&lt;+&gt;&gt;&gt;-]&lt;&lt;&lt;&lt;&lt;[.[-]&gt;.[-
]&gt;.[&lt;&lt;+&gt;&gt;-]&lt;&lt;&lt;&lt;]&gt;&gt;[&gt;+&gt;++&gt;++&lt;&lt;&lt;-]++++++++++.&gt;&gt;+&gt;+++&lt;.&gt;.&lt;&lt;&lt;.&gt;&gt;----------
-----.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;&lt;.&gt;&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;&lt;.&gt;&gt;.&gt;.&lt;&lt;.&gt;++++++++++.&gt;+.
&lt;&lt;.&gt;---------------.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;&lt;.&gt;&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;+
++++++++.&gt;++++.&lt;&lt;&lt;.&gt;&gt;---------------.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+
&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;&lt;.&gt;&gt;+++++++++.&gt;+++++++++++.&lt;&lt;.&gt;---------------.+&gt;.&lt;&lt;.&gt;.+&gt;.
&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.&gt;.+&gt;.&lt;&lt;.


Could definitely be condensed more, but that is kinda the nature of the language. This is quick and dirty, and it works.

Example output (input = 98):

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


It is fairly intuitive that all decks of this format are winnable.