From 67212026f06925cd2d16ff425192890011ebd7eb Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 31 Jul 2018 12:48:34 -0700 Subject: WIP basic structure Cleaned up a bit from the interview --- rain/main.hs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 rain/main.hs (limited to 'rain/main.hs') 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 -- cgit v1.2.3