# 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
.
.
.

• Can we use 'T' for 10, so every card is 2 characters? – captncraig Jan 18 '13 at 2:27
• I think our customers are clever enough to go for that. I'll add it to the description. – lochok Jan 18 '13 at 2:34

# Brainfuck - 1575 1365

I am horribly abusing the minimum number of unique deals. This will produce exactly 256 distinct outputs. It accepts one byte of input as its random seed.

,>++++[>++++++<-]<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>>[<+<<+>>>-]>[-]<
<-[>+<-]<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>[-]>[-]>[<<<+>>>-]>[-]+[>+<
+++++]>+++++[>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>
>+>>+>>+>>+>>+[<<]>-]>>>>>>>>>+>>+>>+>>+>++++++[>++++>>++++>>++++>>+++
+>>+++>>+++>>+++>>+++>>++++>>++++>>++++>>++++>>+++>>+++>>+++>>+++<<<<<
<<<<<<<<<<<<<<<<<<<<<<<<<<-]>++++>>++++>>++++>>++++>>>>>>>>>>+>>+>>+>>
+>>+>>+>>+>>+[<<]>>[>+<-<+>]>[<+>-]<<+++++++++++[>>+>>+>>+>>+>>+>>+>>+
>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+>>+[<<]>>-]>>>>+>>++++
+>>++++++++++++++++>>>>+>>+++++>>++++++++++++++++>>>>+>>+++++>>+++++++
+++++++++>>>>+>>+++++>>++++++++++++++++>>>>+>>+++++>>++++++++++++++++>
>>>+>>+++++>>++++++++++++++++[<<]<<<<<<[>>>>>>+<<<<<<-]>>>>>>[>[<<+>>-
]<[>+<-]>>[<<+>>-]<-[>+<-]>]>.[-]>.[-]>[[<<<<+>>>>-]>]<<<<<[<<]<++++[>
++++++++<-]>.[-]<<<[>>>+<<<-]>>>[>[<<+>>-]<[>+<-]>>[<<+>>-]<-[>+<-]>]>
.[-]>.[-]>[[<<<<+>>>>-]>]<<++++[>++++++++<-]>.[<<<+>>>-]<<<<<[.[-]>.[-
]>.[<<+>>-]<<<<]>>[>+>++>++<<<-]++++++++++.>>+>+++<.>.<<<.>>----------
-----.+>.<<.>.+>.<<<.>>.+>.<<.>.+>.<<.>.+>.<<<.>>.>.<<.>++++++++++.>+.
<<.>---------------.+>.<<.>.+>.<<<.>>.+>.<<.>.+>.<<.>.+>.<<.>.+>.<<.>+
++++++++.>++++.<<<.>>---------------.+>.<<.>.+>.<<.>.+>.<<.>.+>.<<.>.+
>.<<.>.+>.<<<.>>+++++++++.>+++++++++++.<<.>---------------.+>.<<.>.+>.
<<.>.+>.<<.>.+>.<<.>.+>.<<.>.+>.<<.


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