cleanup day 5 with destructuring in the diagonal list comprehension

This commit is contained in:
opfez 2021-12-05 11:40:17 +01:00
parent 78438fa736
commit c90c99a7b5
1 changed files with 2 additions and 2 deletions

View File

@ -31,8 +31,8 @@ pointsOfLine :: Line -> [Point]
pointsOfLine Line{..}
| x1 == x2 = [(x1, y) | y <- [min y1 y2 .. max y1 y2]]
| y1 == y2 = [(x, y1) | x <- [min x1 x2 .. max x1 x2]]
| otherwise = [(x1 + (fst off) * dx, y1 + (snd off) * dy)
| off <- zip [0..abs $ x1 - x2] [0..abs $ y1 - y2]]
| otherwise = [(x1 + xoff * dx, y1 + yoff * dy)
| (xoff, yoff) <- zip [0..abs $ x1 - x2] [0..abs $ y1 - y2]]
where dx = if x1 < x2 then 1 else -1
dy = if y1 < y2 then 1 else -1