-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpoints.hs
37 lines (26 loc) · 1.47 KB
/
points.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
listPoints :: [(Int, Int)] -> [(Int, Int)]
listPoints ((10, 10):l) = (10, 10) : l
listPoints (( x, 10):l) = listPoints ((x + 1, 0) : (x, 10) : l)
listPoints (( x, y):l) = listPoints ((x, y + 1) : (x, y) : l)
data Point = Point Int Int deriving (Eq,Show)
listPoints' :: [Point] -> [Point]
listPoints' ((Point 10 10):l) = Point 10 10 : l
listPoints' ((Point x 10):l) = listPoints' (Point (x + 1) 0 : Point x 10 : l)
listPoints' ((Point x y):l) = listPoints' (Point x (y + 1) : Point x y : l)
-- Make your thing with tuples above work with this datastructure below.
data Point3D = Point3D Int Int Int deriving (Eq, Show)
listPoints3D :: [Point3D] -> [Point3D]
listPoints3D ((Point3D 10 10 10):l) = Point3D 10 10 10 : l
listPoints3D ((Point3D x 10 10):l) = listPoints3D (Point3D (x + 1) 0 0 : Point3D x 10 10 : l)
listPoints3D ((Point3D x y 10):l) = listPoints3D (Point3D x (y + 1) 0 : Point3D x y 10 : l)
listPoints3D ((Point3D x y z):l) = listPoints3D (Point3D x y (z + 1) : Point3D x y z : l)
main = do
print . reverse $ listPoints [(0, 0)]
print . reverse $ listPoints' [Point 0 0]
print . reverse $ listPoints3D [(Point3D 0 0 0)]
{-
listPoints'' :: [Point3D] -> [Point3D]
listPoints'' ((Point3D 10 10 10):l) = Point3D 10 10 10 : l
listPoints'' ((Point3D x 10 10):l) = listPoints'' (Point3D (x + 1) 0 : Point3D x 10 : l)
listPoints'' ((Point3D x y z):l) = listPoints'' (Point3D x (y + 1) : Point3D x y : l)
-}