Skip to content

Commit fd5632e

Browse files
committed
Shorten
1 parent a810c7a commit fd5632e

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

17.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ data Cell = Cell {
2525
data Neighbour = Neighbour { cell :: Cell, distance :: Int }
2626

2727
neighbours :: Grid Int -> [Int] -> Cell -> [Neighbour]
28-
neighbours Grid { items } range = filter inRange . adjacent
28+
neighbours Grid { items } range = filter inRange . concat . adjacent
2929
where
3030
adjacent Cell { node = (x, y), direction, moves } = case direction of
31-
L -> concat [cells (\m -> Cell (x + m, y) L (moves + m)),
32-
cells (\m -> Cell (x, y - m) U m),
33-
cells (\m -> Cell (x, y + m) D m)]
34-
R -> concat [cells (\m -> Cell (x - m, y) R (moves + m)),
35-
cells (\m -> Cell (x, y - m) U m),
36-
cells (\m -> Cell (x, y + m) D m)]
37-
U -> concat [cells (\m -> Cell (x, y - m) U (moves + m)),
38-
cells (\m -> Cell (x - m, y) R m),
39-
cells (\m -> Cell (x + m, y) L m)]
40-
D -> concat [cells (\m -> Cell (x, y + m) D (moves + m)),
41-
cells (\m -> Cell (x - m, y) R m),
42-
cells (\m -> Cell (x + m, y) L m)]
31+
L -> [cells (\m -> Cell (x + m, y) L (moves + m)),
32+
cells (\m -> Cell (x, y - m) U m),
33+
cells (\m -> Cell (x, y + m) D m)]
34+
R -> [cells (\m -> Cell (x - m, y) R (moves + m)),
35+
cells (\m -> Cell (x, y - m) U m),
36+
cells (\m -> Cell (x, y + m) D m)]
37+
U -> [cells (\m -> Cell (x, y - m) U (moves + m)),
38+
cells (\m -> Cell (x - m, y) R m),
39+
cells (\m -> Cell (x + m, y) L m)]
40+
D -> [cells (\m -> Cell (x, y + m) D (moves + m)),
41+
cells (\m -> Cell (x - m, y) R m),
42+
cells (\m -> Cell (x + m, y) L m)]
4343
cells c = snd (foldl (\(d, xs) m -> toNeighbour (c m) d xs) (0, []) extent)
4444
extent = [1..maximum range]
4545
toNeighbour cell d xs = case M.lookup (node cell) items of

17.leftist-heap.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ data Cell = Cell {
2828
data Neighbour = Neighbour { cell :: Cell, distance :: Int }
2929

3030
neighbours :: Grid Int -> [Int] -> Cell -> [Neighbour]
31-
neighbours Grid { items } range = filter inRange . adjacent
31+
neighbours Grid { items } range = filter inRange . concat . adjacent
3232
where
3333
adjacent Cell { node = (x, y), direction, moves } = case direction of
34-
L -> concat [cells (\m -> Cell (x + m, y) L (moves + m)),
35-
cells (\m -> Cell (x, y - m) U m),
36-
cells (\m -> Cell (x, y + m) D m)]
37-
R -> concat [cells (\m -> Cell (x - m, y) R (moves + m)),
38-
cells (\m -> Cell (x, y - m) U m),
39-
cells (\m -> Cell (x, y + m) D m)]
40-
U -> concat [cells (\m -> Cell (x, y - m) U (moves + m)),
41-
cells (\m -> Cell (x - m, y) R m),
42-
cells (\m -> Cell (x + m, y) L m)]
43-
D -> concat [cells (\m -> Cell (x, y + m) D (moves + m)),
44-
cells (\m -> Cell (x - m, y) R m),
45-
cells (\m -> Cell (x + m, y) L m)]
34+
L -> [cells (\m -> Cell (x + m, y) L (moves + m)),
35+
cells (\m -> Cell (x, y - m) U m),
36+
cells (\m -> Cell (x, y + m) D m)]
37+
R -> [cells (\m -> Cell (x - m, y) R (moves + m)),
38+
cells (\m -> Cell (x, y - m) U m),
39+
cells (\m -> Cell (x, y + m) D m)]
40+
U -> [cells (\m -> Cell (x, y - m) U (moves + m)),
41+
cells (\m -> Cell (x - m, y) R m),
42+
cells (\m -> Cell (x + m, y) L m)]
43+
D -> [cells (\m -> Cell (x, y + m) D (moves + m)),
44+
cells (\m -> Cell (x - m, y) R m),
45+
cells (\m -> Cell (x + m, y) L m)]
4646
cells c = snd (foldl (\(d, xs) m -> toNeighbour (c m) d xs) (0, []) extent)
4747
extent = [1..maximum range]
4848
toNeighbour cell d xs = case M.lookup (node cell) items of

17.skew-heap.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ data Cell = Cell {
3030
data Neighbour = Neighbour { cell :: Cell, distance :: Int }
3131

3232
neighbours :: Grid Int -> [Int] -> Cell -> [Neighbour]
33-
neighbours Grid { items } range = filter inRange . adjacent
33+
neighbours Grid { items } range = filter inRange . concat . adjacent
3434
where
3535
adjacent Cell { node = (x, y), direction, moves } = case direction of
36-
L -> concat [cells (\m -> Cell (x + m, y) L (moves + m)),
37-
cells (\m -> Cell (x, y - m) U m),
38-
cells (\m -> Cell (x, y + m) D m)]
39-
R -> concat [cells (\m -> Cell (x - m, y) R (moves + m)),
40-
cells (\m -> Cell (x, y - m) U m),
41-
cells (\m -> Cell (x, y + m) D m)]
42-
U -> concat [cells (\m -> Cell (x, y - m) U (moves + m)),
43-
cells (\m -> Cell (x - m, y) R m),
44-
cells (\m -> Cell (x + m, y) L m)]
45-
D -> concat [cells (\m -> Cell (x, y + m) D (moves + m)),
46-
cells (\m -> Cell (x - m, y) R m),
47-
cells (\m -> Cell (x + m, y) L m)]
36+
L -> [cells (\m -> Cell (x + m, y) L (moves + m)),
37+
cells (\m -> Cell (x, y - m) U m),
38+
cells (\m -> Cell (x, y + m) D m)]
39+
R -> [cells (\m -> Cell (x - m, y) R (moves + m)),
40+
cells (\m -> Cell (x, y - m) U m),
41+
cells (\m -> Cell (x, y + m) D m)]
42+
U -> [cells (\m -> Cell (x, y - m) U (moves + m)),
43+
cells (\m -> Cell (x - m, y) R m),
44+
cells (\m -> Cell (x + m, y) L m)]
45+
D -> [cells (\m -> Cell (x, y + m) D (moves + m)),
46+
cells (\m -> Cell (x - m, y) R m),
47+
cells (\m -> Cell (x + m, y) L m)]
4848
cells c = snd (foldl (\(d, xs) m -> toNeighbour (c m) d xs) (0, []) extent)
4949
extent = [1..maximum range]
5050
toNeighbour cell d xs = case M.lookup (node cell) items of

17.vis.hs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ enum :: [a] -> [(Int, a)]
2828
enum = zip [0..]
2929

3030
neighbours :: Grid Int -> [Int] -> Cell -> [Neighbour]
31-
neighbours Grid { items } range = filter inRange . adjacent
31+
neighbours Grid { items } range = filter inRange . concat . adjacent
3232
where
3333
adjacent Cell { node = (x, y), direction, moves } = case direction of
34-
L -> concat [cells (\m -> Cell (x + m, y) L (moves + m)),
35-
cells (\m -> Cell (x, y - m) U m),
36-
cells (\m -> Cell (x, y + m) D m)]
37-
R -> concat [cells (\m -> Cell (x - m, y) R (moves + m)),
38-
cells (\m -> Cell (x, y - m) U m),
39-
cells (\m -> Cell (x, y + m) D m)]
40-
U -> concat [cells (\m -> Cell (x, y - m) U (moves + m)),
41-
cells (\m -> Cell (x - m, y) R m),
42-
cells (\m -> Cell (x + m, y) L m)]
43-
D -> concat [cells (\m -> Cell (x, y + m) D (moves + m)),
44-
cells (\m -> Cell (x - m, y) R m),
45-
cells (\m -> Cell (x + m, y) L m)]
34+
L -> [cells (\m -> Cell (x + m, y) L (moves + m)),
35+
cells (\m -> Cell (x, y - m) U m),
36+
cells (\m -> Cell (x, y + m) D m)]
37+
R -> [cells (\m -> Cell (x - m, y) R (moves + m)),
38+
cells (\m -> Cell (x, y - m) U m),
39+
cells (\m -> Cell (x, y + m) D m)]
40+
U -> [cells (\m -> Cell (x, y - m) U (moves + m)),
41+
cells (\m -> Cell (x - m, y) R m),
42+
cells (\m -> Cell (x + m, y) L m)]
43+
D -> [cells (\m -> Cell (x, y + m) D (moves + m)),
44+
cells (\m -> Cell (x - m, y) R m),
45+
cells (\m -> Cell (x + m, y) L m)]
4646
cells c = snd (foldl (\(d, xs) m -> toNeighbour (c m) d xs) (0, []) extent)
4747
extent = [1..maximum range]
4848
toNeighbour cell d xs = case M.lookup (node cell) items of

0 commit comments

Comments
 (0)