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

Commit 2457d72

Browse files
author
cd155
committed
add 1.4 permutation of a palindrome
1 parent b646ac8 commit 2457d72

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Array.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Array where
2-
import Data.Map (Map, insert, member, adjust, empty)
2+
import Data.Map (Map, insert, member, adjust, empty, elems)
33
import Data.Char (ord)
44

55
{-
@@ -65,7 +65,7 @@ isPerm' xs ys = fillAccii xs acciiArr == fillAccii ys acciiArr
6565

6666
fillAccii :: String -> [Integer] -> [Integer]
6767
fillAccii [] arr = arr
68-
fillAccii (x:xs) arr =
68+
fillAccii (x:xs) arr =
6969
fillAccii xs (init firstHalf ++ [updated] ++ secondHalf)
7070
where (firstHalf, secondHalf) = splitAt (ord x) arr
7171
updated = (arr !! (ord x - 1)) + 1
@@ -88,3 +88,15 @@ repSpaceHelper (x:xs) isSpaPre
8888
| x == ' ' && isSpaPre = repSpaceHelper xs isSpaPre
8989
| otherwise = x:repSpaceHelper xs False
9090

91+
{-
92+
1.4
93+
Given a string, write a function to check if it is a
94+
permutation of a palin­drome.
95+
-}
96+
-- Lower case and Upper case are different
97+
isPermPalin :: String -> Bool
98+
isPermPalin xs
99+
| length validValues == 0 || length validValues == 1 = True
100+
| otherwise = False
101+
where values = elems (convToDict xs empty)
102+
validValues = filter odd values

0 commit comments

Comments
 (0)