Difference between revisions of "FP Test3 2024"
Jump to navigation
Jump to search
Line 81: | Line 81: | ||
== Tasks == | == Tasks == | ||
</translate> | </translate> | ||
+ | |||
+ | <translate> | ||
+ | Create functions that: | ||
+ | </translate> | ||
+ | |||
+ | <translate> | ||
+ | *Place one maze above another. | ||
+ | </translate> | ||
+ | |||
+ | <syntaxhighlight lang="Haskell">above :: Maze -> Maze -> Maze</syntaxhighlight> | ||
+ | <syntaxhighlight lang="Haskell" class="myDark"> | ||
+ | *Main> printMaze(above arrow arrow) | ||
+ | ....#.... | ||
+ | ...###... | ||
+ | ..#.#.#.. | ||
+ | .#..#..#. | ||
+ | ....#.... | ||
+ | ....#.... | ||
+ | ....##### | ||
+ | ....#.... | ||
+ | ...###... | ||
+ | ..#.#.#.. | ||
+ | .#..#..#. | ||
+ | ....#.... | ||
+ | ....#.... | ||
+ | ....##### | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <translate> | ||
+ | *Place two mazes side by side (consider, that they have the same height). | ||
+ | </translate> | ||
+ | |||
+ | <syntaxhighlight lang="Haskell">sideBySide :: Maze -> Maze -> Maze</syntaxhighlight> | ||
+ | <syntaxhighlight lang="Haskell" class="myDark"> | ||
+ | *Main> printMaze(sideBySide arrow arrow) | ||
+ | ....#........#.... | ||
+ | ...###......###... | ||
+ | ..#.#.#....#.#.#.. | ||
+ | .#..#..#..#..#..#. | ||
+ | ....#........#.... | ||
+ | ....#........#.... | ||
+ | ....#####....##### | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <translate> | ||
+ | *Rotate maze to the left and to the right. | ||
+ | </translate> | ||
+ | |||
+ | <syntaxhighlight lang="Haskell"> | ||
+ | rotateR :: Maze -> Maze | ||
+ | rotateL :: Maze -> Maze | ||
+ | </syntaxhighlight> | ||
+ | <syntaxhighlight lang="Haskell" class="myDark"> | ||
+ | *Main> printMaze (rotateR arrow) | ||
+ | ....... | ||
+ | ...#... | ||
+ | ....#.. | ||
+ | .....#. | ||
+ | ####### | ||
+ | #....#. | ||
+ | #...#.. | ||
+ | #..#... | ||
+ | #...... | ||
+ | *Main> printMaze(rotateL arrow) | ||
+ | ......# | ||
+ | ...#..# | ||
+ | ..#...# | ||
+ | .#....# | ||
+ | ####### | ||
+ | .#..... | ||
+ | ..#.... | ||
+ | ...#... | ||
+ | ....... | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | |||
+ | <translate> | ||
+ | <!--T:25--> | ||
+ | * Define a function makePicture where the list arguments gives the positions of the black points (represented by sharp) and the two integer arguments give the width and height of the picture. | ||
+ | </translate> | ||
+ | <syntaxhighlight lang="Haskell">makePicture :: Int -> Int -> [(Int,Int)]-> Pic</syntaxhighlight> | ||
+ | <syntaxhighlight lang="Haskell" class="myDark"> | ||
+ | *Main> pp(makePicture 7 5 [(1,3),(3,2)]) | ||
+ | ....... | ||
+ | ...#... | ||
+ | ....... | ||
+ | ..#.... | ||
+ | ....... | ||
+ | </syntaxhighlight> |
Revision as of 10:52, 15 November 2024
Home Preparation For Test 3 - 2024
Data definition
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 :: Maze
sample1 = ["*********",
"* * * *",
"* * * * *",
"* * * * *",
"* * *",
"******* *",
" *",
"*********"]
sample2 :: Maze
sample2 = [" ",
" ",
" *** ",
" *** ",
" *** ",
" ",
" "]
sample3 :: Maze
sample3 = [" * * ",
" ##### ",
" *** ",
" * * ",
" *** ",
" * ",
" "]
arrow :: Maze
arrow = [ "....#....",
"...###...",
"..#.#.#..",
".#..#..#.",
"....#....",
"....#....",
"....#####"]
ghci> printMaze sample1
*********
* * * *
* * * * *
* * * * *
* * *
******* *
*
*********
Tasks
Create functions that:
- Place one maze above another.
above :: Maze -> Maze -> Maze
*Main> printMaze(above arrow arrow)
....#....
...###...
..#.#.#..
.#..#..#.
....#....
....#....
....#####
....#....
...###...
..#.#.#..
.#..#..#.
....#....
....#....
....#####
- Place two mazes side by side (consider, that they have the same height).
sideBySide :: Maze -> Maze -> Maze
*Main> printMaze(sideBySide arrow arrow)
....#........#....
...###......###...
..#.#.#....#.#.#..
.#..#..#..#..#..#.
....#........#....
....#........#....
....#####....#####
- Rotate maze to the left and to the right.
rotateR :: Maze -> Maze
rotateL :: Maze -> Maze
*Main> printMaze (rotateR arrow)
.......
...#...
....#..
.....#.
#######
#....#.
#...#..
#..#...
#......
*Main> printMaze(rotateL arrow)
......#
...#..#
..#...#
.#....#
#######
.#.....
..#....
...#...
.......
- Define a function makePicture where the list arguments gives the positions of the black points (represented by sharp) and the two integer arguments give the width and height of the picture.
makePicture :: Int -> Int -> [(Int,Int)]-> Pic
*Main> pp(makePicture 7 5 [(1,3),(3,2)])
.......
...#...
.......
..#....
.......