Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit dc43ad1

Browse files
author
cd155
committed
complete fill up
1 parent 8a867c2 commit dc43ad1

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

‎src/Recursion.hs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ instance Eq Color where
384384
Red == Yellow = False
385385
Red == Blue = False
386386
Yellow == Yellow = True
387-
Yellow == Blue = True
387+
Yellow == Blue = False
388388
Yellow == Red = False
389389
Blue == Blue = True
390-
Blue == Yellow = True
391-
Blue == Red = True
390+
Blue == Yellow = False
391+
Blue == Red = False
392392

393393
data Direction = Up | Down | PLeft | PRight
394394

@@ -402,6 +402,13 @@ image = V.fromList
402402
V.fromList [Yellow, Yellow, Blue]
403403
]
404404

405+
image1 :: Image
406+
image1 = V.fromList
407+
[
408+
V.fromList [Red, Red],
409+
V.fromList [Red, Yellow]
410+
]
411+
405412
-- Paint a color in one location
406413
paint :: Image -> (Int, Int) -> Color -> Image
407414
paint vs (i, j) c =
@@ -415,6 +422,7 @@ paint vs (i, j) c =
415422
-- Find all locations which need to paint
416423
findArea :: Image -> (Int, Int) -> [(Int, Int)]
417424
findArea img (i,j) = uniq (
425+
(i,j):
418426
findAreaOnDir img (i,j) boundC Up ++
419427
findAreaOnDir img (i,j) boundC Down ++
420428
findAreaOnDir img (i,j) boundC PLeft ++
@@ -429,40 +437,40 @@ uniq (x:xs) buf
429437

430438
findAreaOnDir :: Image -> (Int, Int) -> Color -> Direction -> [(Int, Int)]
431439
findAreaOnDir img (i,j) c Up
432-
| isInBound img (i,j-1) && selectC ==c =
440+
| isInBoundAndSameColor img (i,j-1) c =
433441
(i,j-1): findAreaOnDir img (i,j-1) c PLeft
434-
| isInBound img (i-1,j) && selectC ==c =
442+
| isInBoundAndSameColor img (i-1,j) c =
435443
(i-1,j): findAreaOnDir img (i-1,j) c Up
436-
| isInBound img (i,j+1)&& selectC == c =
444+
| isInBoundAndSameColor img (i,j+1) c =
437445
(i,j+1): findAreaOnDir img (i,j+1) c PRight
438446
| otherwise = []
439-
where selectC = img V.! i V.! j
440447
findAreaOnDir img (i,j) c Down
441-
| isInBound img (i,j-1)&& selectC == c =
448+
| isInBoundAndSameColor img (i,j-1) c =
442449
(i,j-1): findAreaOnDir img (i,j-1) c PLeft
443-
| isInBound img (i+1,j) && selectC ==c =
450+
| isInBoundAndSameColor img (i+1,j) c =
444451
(i+1,j): findAreaOnDir img (i+1,j) c Down
445-
| isInBound img (i,j+1)&& selectC == c =
452+
| isInBoundAndSameColor img (i,j+1) c =
446453
(i,j+1): findAreaOnDir img (i,j+1) c PRight
447454
| otherwise = []
448-
where selectC = img V.! i V.! j
449455
findAreaOnDir img (i,j) c PLeft
450-
| isInBound img (i-1, j) && selectC == c =
456+
| isInBoundAndSameColor img (i-1,j) c =
451457
(i-1,j): findAreaOnDir img (i-1,j) c Up
452-
| isInBound img (i,j-1)&& selectC == c =
458+
| isInBoundAndSameColor img (i,j-1) c =
453459
(i,j-1): findAreaOnDir img (i,j-1) c PLeft
454-
| isInBound img (i+1,j)&& selectC == c =
460+
| isInBoundAndSameColor img (i+1,j) c =
455461
(i+1,j): findAreaOnDir img (i+1,j) c Down
456462
| otherwise = []
457-
where selectC = img V.! i V.! j
458463
findAreaOnDir img (i,j) c PRight
459-
| isInBound img (i-1,j)&& selectC == c =
464+
| isInBoundAndSameColor img (i-1,j) c =
460465
(i-1,j): findAreaOnDir img (i-1,j) c Up
461-
| isInBound img (i,j+1)&& selectC == c =
466+
| isInBoundAndSameColor img (i,j+1) c =
462467
(i,j+1): findAreaOnDir img (i,j+1) c PRight
463-
| isInBound img (i+1,j)&& selectC == c =
468+
| isInBoundAndSameColor img (i+1,j) c =
464469
(i+1,j): findAreaOnDir img (i+1,j) c Down
465470
| otherwise = []
471+
472+
isInBoundAndSameColor :: Image -> (Int, Int) -> Color -> Bool
473+
isInBoundAndSameColor img (i,j) c = isInBound img (i,j) && selectC == c
466474
where selectC = img V.! i V.! j
467475

468476
isInBound :: Image -> (Int, Int) -> Bool

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /