xabolxuux avatar xabolxuux committed 98aa022

typed deck of cards and deserializing it from file

Comments (0)

Files changed (2)

 import Text.Printf
 import System.Environment(getArgs)
 
+data Card = Card String String
+          deriving (Show, Read)
+
+data Deck = Deck [Card]
+          deriving (Show, Read)
+
+cardPair :: Card -> (String, String)
+cardPair (Card x y) = (x, y)
+
+deckPairs :: Deck -> [(String, String)]
+deckPairs (Deck cards) = map cardPair cards
+
 randHd :: [a] -> StdGen -> ([a], StdGen)
 randHd [] g = ([], g)
 randHd (x:[]) g = ([x], g)
          ans <- getLine
 	 if a == ans then f tl (q, a, ans) (good + 1) bad gg else f full (q, a, ans) good (bad + 1) gg
 
-getLines = liftM lines . readFile
-pair xs = map snd . filter fst . zip (iterate not True) $ zip xs (drop 1 xs)
-
 main = do
   args <- getArgs
-  xs <- getLines $ head args
+  xs <- readFile $ head args
   myg <- newStdGen
-  let deck = pair xs in
+  let deck = deckPairs (read xs :: Deck) in
     f deck ("", "", "") 0 0 myg
 
   
-a
-alfa
-b
-bravo
-c
-charlie
-d
-delta
-e
-echo
-f
-foxtrot
-g
-golf
-h
-hotel
-i
-india
-j
-juliett
-k
-kilo
-l
-lima
-m
-mike
-n
-november
-o
-oscar
-p
-papa
-q
-quebec
-r
-romeo
-s
-sierra
-t
-tango
-u
-uniform
-v
-viktor
-w
-whiskey
-x
-xray
-y
-yankee
-z
-zulu
+Deck [
+Card "a" "alfa",
+Card "b" "bravo",
+Card "c" "charlie",
+Card "d" "delta",
+Card "e" "echo",
+Card "f" "foxtrot",
+Card "g" "golf",
+Card "h" "hotel",
+Card "i" "india",
+Card "j" "juliett",
+Card "k" "kilo",
+Card "l" "lima",
+Card "m" "mike",
+Card "n" "november",
+Card "o" "oscar",
+Card "p" "papa",
+Card "q" "quebec",
+Card "r" "romeo",
+Card "s" "sierra",
+Card "t" "tango",
+Card "u" "uniform",
+Card "v" "viktor",
+Card "w" "whiskey",
+Card "x" "xray",
+Card "y" "yankee",
+Card "z" "zulu" ]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.