some problem question
Sun, 2 Sep 2001 06:24:57 +0100 (BST)
i am having some problem with the haskell question. if
u can help me in that will really be appreciated.
thanks for help.
MY PROBLEM IS WITH THE SEPERATING THE SHAPES IN A GRID
waiting for a sooner reply.THANKS
here is the question:
A rectangular grid is list of list of Char, where all
inner lists are of the same length ie. type Grid =
[[Char]] . Inside this grid, white space will be
denoted by a '.' and filled pixels will be denoted by
'*'. For example, a grid containing a square may look
square :: Grid
The shapes can be anywhere inside the grid and they
can can be of any size > 2 x 2 . That is, the only
restriction on the size of the shape is a minimum of 2
x 2 area on the grid. And in cases of non-square, the
shape will at least occupy 4 pixels. You can assume
that no shape given will be smaller than this and that
the shapes given will distinctly fall into one of the
categories and will not be ambiguous. There is no
restriction on the size of the grid itself, but
obviously, it must fully contain the shape(s).
There can be either one or two shape(s) inside a grid,
but if there are two shapes in the grid, then they are
guarenteed to be at least 1 pixel apart, and that they
can be separated by cutting the grid either
horizontally or vertically.
twoTriangles :: Grid
The following shapes are allowed inside a grid :
RECTANGLE - The very same rectangle as we all know it.
It will not be rotated.
TRIANGLE - If it looks like a triangle, then it's a
triangle. Note that this means the length of the three
edges can be different, and it can be rotated in any
way. (You'll notice that this is a very ambiguous
definition of a triangle. Within the restraints of
this specification, including that (1) all shapes
given will be valid. (2) there are only three shapes
to be identified. and (3) definition of the other
shapes are unambiguous and rigid. You should think
about how you can identify the triangle using the
simplist way you can think of.)
DIAMOND - Any thing that has a shape like
To make this easy, a diamond will have horizontal
symmetry as well as vertical symmetry.
You are to write the following functions:
areaOfOneShape:: Grid -> Int
For the shape in the grid, you should count the number
of pixels it occupies. (ie, count the number of '*'
for each shape), and return the count.
recogniseOneShape:: Grid -> String
The input Grid will be as describe above, with only
ONE shape in the grid, and the output String should be
the name of the shapes, eg, "RECTANGLE"
Note: You MUST capitalise the name of the shapes in
the string you returned, and you MUST spell the name
of the shapes correctly The ONLY names of the shapes
allowed are the ones described above in the Shapes
separateShapes :: Grid -> [Grid]
The input Grid will contain either one or two shapes.
You are to separate the shapes into separate Grids,
where each contains a whole shape respectively; ie, if
there are two shapes in the original Grid, then you
should return two Grids containing a shape each. If
there is only one shape in the orignal Grid, then you
should just return a list containing a single Grid.
The Grids returned must also be rectangular.
areaOfShapes :: Grid -> [Int]
You should return the area of the shapes. If there is
only one shape, then the output will just be a list
with one Int. If there are two shapes, then the output
will be a list of two Int. The order of the integer
returned does not matter. You should (but you don't
have to) write this function using functions already
recogniseShapes :: Grid -> [String]
Give a Grid containing one or two shapes, return a
list of String of the names of the shapes. If there
are two shapes, then you can return the name of the
two shapes in any order you like. Eg, If there is a
triangle and a diamond in the grid, then you should
return ["TRIANGLE", "DIAMOND"] (the order of the names
does not matter). If there is just a single shape,
then you just return a list with a single string, eg,
["RECTANGLE"]. You should (but you don't have to)
write this function using functions already defined above.
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie