summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2018-07-31 12:48:34 -0700
committerBen Sima <ben@bsima.me>2018-07-31 12:48:34 -0700
commit67212026f06925cd2d16ff425192890011ebd7eb (patch)
tree1124c379fd5a9285ab33191a28c89769386b1de0
parentfdc4766d7fb54864f695f6959797676415046941 (diff)
WIP basic structure
Cleaned up a bit from the interview
-rwxr-xr-xrain/main.hs71
1 files changed, 71 insertions, 0 deletions
diff --git a/rain/main.hs b/rain/main.hs
new file mode 100755
index 0000000..3c431a7
--- /dev/null
+++ b/rain/main.hs
@@ -0,0 +1,71 @@
+#!/usr/bin/env stack
+{- stack
+ --nix
+ --resolver lts-11.15
+ --install-ghc
+ runghc
+ --package random
+-}
+
+{-# LANGUAGE TypeSynonymInstances #-}
+
+{-
+
+Problem: Create a string array containing a representation of the 52 cards in a
+standard deck, and then a second array that shuffles the 52 cards.
+
+Start with two string arrays of the cards and suits:
+Cards: 2, 3, 4, 5, 6, 7, 8, 9, 10, J, K, Q, A
+Suits: Clubs, Diamonds, Aces, Spades
+
+-}
+
+import System.Random
+import Control.Monad
+
+data Name
+ = Two
+ | Three
+ | Four
+ | Five
+ | Six
+ | Seven
+ | Eight
+ | Nine
+ | Ten
+ | Jack
+ | King
+ | Queen
+ | Ace
+ deriving (Show, Enum, Bounded)
+
+names :: [Name]
+names = [ Two .. ]
+
+data Suit
+ = Club
+ | Diamond
+ | Heart
+ | Spade
+ deriving (Show, Enum)
+
+suits :: [Suit]
+suits = [ Club .. ]
+
+allCards :: [(Name, Suit)]
+allCards = concat $ map (\n -> map (\s -> (n, s)) suits) names
+
+data CardsGen = CardsGen
+ deriving (Show)
+
+--instance RandomGen CardsGen where
+-- genRange _ = (0, cardsLength)
+-- next CardsGen = stdNext (StdGen 0 cardsLength)
+-- split = stdSplit (StdGen 0 cardsLength)
+
+suffle :: [cards] -> [cards]
+suffle arr = undefined
+
+main :: IO [()]
+main = do
+ sequence $ map (putStrLn.show) allCards