File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1
1
module Main where
2
2
3
+ import Control.Monad (forever )
4
+ import Data.Char (toLower )
5
+ import Data.Maybe (isJust )
6
+ import Data.List (intersperse )
7
+ import System.Exit (exitSuccess )
8
+ import System.Random (randomRIO )
9
+
3
10
main :: IO ()
4
11
main = do
5
12
putStrLn " hello world"
13
+
14
+ type WordList = [String ]
15
+
16
+ allWords :: IO WordList
17
+ allWords = do
18
+ dict <- readFile " data/dict.txt"
19
+ return (lines dict)
20
+
21
+ minWordLength :: Int
22
+ minWordLength = 5
23
+
24
+ maxWordLength :: Int
25
+ maxWordLength = 9
26
+
27
+ gameWords :: IO WordList
28
+ gameWords = do
29
+ aw <- allWords
30
+ return $ filter gameLength aw
31
+ where gameLength w =
32
+ let l = length (w :: String )
33
+ in l > minWordLength && l < maxWordLength
34
+
35
+ randomWord :: WordList -> IO String
36
+ randomWord wl = do
37
+ randomIndex <- randomRIO (0 , length wl - 1 )
38
+ return $ wl !! randomIndex
39
+
40
+ randomWord' :: IO String
41
+ randomWord' = gameWords >>= randomWord
You can’t perform that action at this time.
0 commit comments