diff options
| author | Mistivia <i@mistivia.com> | 2024-01-27 14:02:35 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-01-27 14:02:35 +0800 |
| commit | 6580dcd9127f69aaa794472ec92bc46015dc4019 (patch) | |
| tree | dc2c7e102c75180f7bd98c2f3a14f8b55f83c0f2 /codewars/6-kyu | |
init
Diffstat (limited to 'codewars/6-kyu')
| -rw-r--r-- | codewars/6-kyu/Does my number look big in this?/solution.hs | 17 | ||||
| -rw-r--r-- | codewars/6-kyu/Duplicate Encoder/solution.hs | 18 | ||||
| -rw-r--r-- | codewars/6-kyu/Equal Sides Of An Array/solution.hs | 11 | ||||
| -rw-r--r-- | codewars/6-kyu/Valid Braces/solution.hs | 21 |
4 files changed, 67 insertions, 0 deletions
diff --git a/codewars/6-kyu/Does my number look big in this?/solution.hs b/codewars/6-kyu/Does my number look big in this?/solution.hs new file mode 100644 index 0000000..1b84d9f --- /dev/null +++ b/codewars/6-kyu/Does my number look big in this?/solution.hs @@ -0,0 +1,17 @@ +-- https://www.codewars.com/kata/5287e858c6b5a9678200083c + +module Narcissistic where + +splitNum n = reverse $ impl n + where + impl n + | n < 10 = [n] + | otherwise = (n `mod` 10):(impl (n `div` 10)) + +narcissistic :: Integral n => n -> Bool +narcissistic n + | (sum $ map (^ (length splited)) splited) == n = True + | otherwise = False + where + splited = splitNum n + diff --git a/codewars/6-kyu/Duplicate Encoder/solution.hs b/codewars/6-kyu/Duplicate Encoder/solution.hs new file mode 100644 index 0000000..1cb38eb --- /dev/null +++ b/codewars/6-kyu/Duplicate Encoder/solution.hs @@ -0,0 +1,18 @@ +-- https://www.codewars.com/kata/54b42f9314d9229fd6000d9c + +module Dups where + +import Data.Char + +count s c + | s == [] = 0 + | c == (head s) = 1 + count (tail s) c + | otherwise = count (tail s) c + +convert s c + | count s c > 1 = ')' + | otherwise = '(' + +duplicateEncode :: String -> String +duplicateEncode s = map (convert ls) ls + where ls = map toLower s diff --git a/codewars/6-kyu/Equal Sides Of An Array/solution.hs b/codewars/6-kyu/Equal Sides Of An Array/solution.hs new file mode 100644 index 0000000..00717d7 --- /dev/null +++ b/codewars/6-kyu/Equal Sides Of An Array/solution.hs @@ -0,0 +1,11 @@ +-- https://www.codewars.com/kata/5679aa472b8f57fb8c000047 + +module Codewars.G964.FindEven where + +findEvenIndex :: [Int] -> Int +findEvenIndex arr = findEvenIndexImpl [] 0 arr + +findEvenIndexImpl left n right + | right == [] = -1 + | sum left == sum (tail right) = n + | otherwise = findEvenIndexImpl (left ++ [head right]) (n + 1) (tail right) diff --git a/codewars/6-kyu/Valid Braces/solution.hs b/codewars/6-kyu/Valid Braces/solution.hs new file mode 100644 index 0000000..6b139fd --- /dev/null +++ b/codewars/6-kyu/Valid Braces/solution.hs @@ -0,0 +1,21 @@ +-- https://www.codewars.com/kata/5277c8a221e209d3f6000b56 +module Codewars.Kata.Braces where + +validBraces :: String -> Bool +validBraces xs = impl 0 0 0 xs where + impl cnt1 cnt2 cnt3 str = + if str == [] then + cnt1 == 0 && cnt2 == 0 && cnt3 == 0 + else let + x = head str + xs = tail str + in + if cnt1 < 0 || cnt2 < 0 || cnt3 < 0 then + False + else if x == '(' then impl (cnt1 + 1) cnt2 cnt3 xs + else if x == ')' then impl (cnt1 - 1) cnt2 cnt3 xs + else if x == '[' then impl cnt1 (cnt2 + 1) cnt3 xs + else if x == ']' then impl cnt1 (cnt2 - 1) cnt3 xs + else if x == '{' then impl cnt1 cnt2 (cnt3 + 1) xs + else if x == '}' then impl cnt1 cnt2 (cnt3 - 1) xs + else False |
