Henk-Jan van Tuyl hjgtuyl at chello.nl
Thu Oct 26 16:29:56 EDT 2006

```Paul, other Haskell Cafe guests,

Remove the ']' from the line:
show_face f = (take 1) (drop (fromEnum f) "A23456789TJQK\$")]

An easier way to write this:
show_face f =  "A23456789TJQK\$" !! fromEnum f

Other improvements:

from_number n = (toEnum (n - 1 + fromEnum 'A'))
->
from_number n = ['A'..] !! (n - 1)

show_suit s = (take 1) (show s)
->
show_suit s = head (show s)
or:
show_suit (s:_) = show s

show c = (show_face (face c)) ++ (show_suit (suit c))
->
show (Cd s f) = show_face f ++ show_suit s
or:
show (Cd s f) = show f ++ " of " ++ show s

->
init l

drop 1 l
->
tail l

decode_ (s:ss) deck = let c = compute(deck)
in (from_number(wrap_zero ((26 + (to_number s) -
fst c) `mod` 26))):(decode_ ss (snd c))
->
decode_ (s:ss) deck = let (a, b) = compute(deck)
in (from_number(wrap_zero ((26 + (to_number s) -
a) `mod` 26))):(decode_ ss b)

quintets :: String -> [String]
quintets s = quintets' (s ++ "XXXX")
where
quintets' (a : b : c : d : e: s') = [a, b, c, d, e] : quintets' s'
quintets' _                       = []

Met vriendelijke groet (best regards),
Henk-Jan van Tuyl

On Thu, 26 Oct 2006 08:43:13 +0200, Paul Brown

> I brute-forced my way through a solution to the Solitaire cipher quiz
> challenge last night:
>
>
> Full source is linked from the entry, or look here:
>
> http://mult.ifario.us/files/solitaire.hs
>
> I think (i.e., know) that my list-based implementation of the
> shuffling is somewhat inelegant, and I can imagine one that uses a
> monad to encapsulate the state of the deck.  Nonetheless, I think I'm
> happy with the data structure for the deck.
>
>
> ---
> Paul R Brown
> paulrbrown at gmail.com
> http://mult.ifario.us/
> _______________________________________________

--
--
http://Van.Tuyl.eu/
--

Using Opera's revolutionary e-mail client: