Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit b3f39e5

Browse files
committed
more comments
1 parent bd911ad commit b3f39e5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Recursion.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ genPerm' = genPermHelper [[]]
392392
[Yellow,Yellow,Blue]
393393
]
394394
-}
395-
396395
data Color = Red | Yellow | Blue deriving Show
397396

398397
instance Eq Color where
@@ -410,6 +409,7 @@ data Direction = Up | Down | PLeft | PRight
410409

411410
type Image = V.Vector (V.Vector Color)
412411

412+
-- test case
413413
image :: Image
414414
image = V.fromList
415415
[
@@ -418,6 +418,7 @@ image = V.fromList
418418
V.fromList [Yellow, Yellow, Blue]
419419
]
420420

421+
-- fill up a color
421422
fillUpColor :: Image -> (Int, Int) -> Color -> Image
422423
fillUpColor img (i,j) c = foldl (\acc x -> paint acc x c ) img pList
423424
where pList = findArea img (i,j)
@@ -442,12 +443,14 @@ findArea img (i,j) = uniq (
442443
findAreaOnDir img (i,j) boundC PRight) []
443444
where boundC = img V.! i V.! j
444445

446+
-- remove duplicates
445447
uniq :: [(Int, Int)] -> [(Int, Int)]-> [(Int, Int)]
446448
uniq [] buf = buf
447449
uniq (x:xs) buf
448450
| x `elem` buf = uniq xs buf
449451
| otherwise = uniq xs (x:buf)
450452

453+
-- find potential position by direction
451454
findAreaOnDir :: Image -> (Int, Int) -> Color -> Direction -> [(Int, Int)]
452455
findAreaOnDir img (i,j) c Up
453456
| isInBoundAndSameColor img (i,j-1) c =
@@ -482,10 +485,12 @@ findAreaOnDir img (i,j) c PRight
482485
(i+1,j): findAreaOnDir img (i+1,j) c Down
483486
| otherwise = []
484487

488+
-- condition determine potential fill up position
485489
isInBoundAndSameColor :: Image -> (Int, Int) -> Color -> Bool
486490
isInBoundAndSameColor img (i,j) c = isInBound img (i,j) && selectC == c
487491
where selectC = img V.! i V.! j
488492

493+
-- check if position if in bound
489494
isInBound :: Image -> (Int, Int) -> Bool
490495
isInBound img (i,j)
491496
| (0 <= i && i < xBound) && (0 <= j && j < yBound) = True

0 commit comments

Comments
 (0)