Paul, other Haskell Cafe guests,
About
http://mult.ifario.us/articles/2006/10/25/solitaire-cipher-in-haskell:
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
head (reverse l)
->
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
<[EMAIL PROTECTED]> wrote:
I brute-forced my way through a solution to the Solitaire cipher quiz
challenge last night:
http://mult.ifario.us/articles/2006/10/25/solitaire-cipher-in-haskell
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.
Comments / criticism welcome.
---
Paul R Brown
[EMAIL PROTECTED]
http://mult.ifario.us/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
--
--
http://Van.Tuyl.eu/
--
Using Opera's revolutionary e-mail client:
https://secure.bmtmicro.com/opera/buy-opera.html?AID=789433
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe