Difference between revisions of "FP Test3 2024"
Jump to navigation
Jump to search
(Created page with "= Home Preparation For Test 3 - 2024 =") |
|||
| Line 1: | Line 1: | ||
= Home Preparation For Test 3 - 2024 = | = Home Preparation For Test 3 - 2024 = | ||
| + | |||
| + | <translate> | ||
| + | Consider following type representing a maze: | ||
| + | </translate> | ||
| + | |||
| + | <syntaxhighlight lang="Haskell">type Maze = [String]</syntaxhighlight> | ||
| + | |||
| + | <translate> | ||
| + | If you want to print this maze on a screen you can use: | ||
| + | </translate> | ||
| + | |||
| + | <syntaxhighlight lang="Haskell"> | ||
| + | printMaze :: Maze -> IO () | ||
| + | printMaze x = putStr (concat (map (++"\n") x)) | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <translate> | ||
| + | <!--T:14--> | ||
| + | Maze example: | ||
| + | </translate> | ||
| + | |||
| + | <syntaxhighlight lang="Haskell"> | ||
| + | sample1 :: [String] | ||
| + | sample1 = ["*********", | ||
| + | "* * * *", | ||
| + | "* * * * *", | ||
| + | "* * * * *", | ||
| + | "* * *", | ||
| + | "******* *", | ||
| + | " *", | ||
| + | "*********"] | ||
| + | |||
| + | sample2 :: [String] | ||
| + | sample2 = [" ", | ||
| + | " ", | ||
| + | " *** ", | ||
| + | " *** ", | ||
| + | " *** ", | ||
| + | " ", | ||
| + | " "] | ||
| + | |||
| + | |||
| + | sample3 :: [String] | ||
| + | sample3 = [" * * ", | ||
| + | " ##### ", | ||
| + | " *** ", | ||
| + | " * * ", | ||
| + | " *** ", | ||
| + | " * ", | ||
| + | " "] | ||
| + | </syntaxhighlight> | ||
| + | <syntaxhighlight lang="Haskell" class="myDark"> | ||
| + | ghci> printMaze sample1 | ||
| + | ********* | ||
| + | * * * * | ||
| + | * * * * * | ||
| + | * * * * * | ||
| + | * * * | ||
| + | ******* * | ||
| + | * | ||
| + | ********* | ||
| + | </syntaxhighlight> | ||
Revision as of 09:56, 15 November 2024
Home Preparation For Test 3 - 2024
Consider following type representing a maze:
type Maze = [String]
If you want to print this maze on a screen you can use:
printMaze :: Maze -> IO ()
printMaze x = putStr (concat (map (++"\n") x))
Maze example:
sample1 :: [String]
sample1 = ["*********",
"* * * *",
"* * * * *",
"* * * * *",
"* * *",
"******* *",
" *",
"*********"]
sample2 :: [String]
sample2 = [" ",
" ",
" *** ",
" *** ",
" *** ",
" ",
" "]
sample3 :: [String]
sample3 = [" * * ",
" ##### ",
" *** ",
" * * ",
" *** ",
" * ",
" "]
ghci> printMaze sample1
*********
* * * *
* * * * *
* * * * *
* * *
******* *
*
*********