diff options
| author | Mistivia <i@mistivia.com> | 2025-04-24 02:46:39 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-04-24 02:46:39 +0800 |
| commit | 2a9e59907868d12a2a3ea387ec90074e26cc90c3 (patch) | |
| tree | 8bc367c09ab4e1967481fd97abf1e29a81f62b04 /6-kyu | |
init
Diffstat (limited to '6-kyu')
| -rw-r--r-- | 6-kyu/does-my-number-look-big-in-this.hs | 16 | ||||
| -rw-r--r-- | 6-kyu/duplicate-encoder.hs | 18 | ||||
| -rw-r--r-- | 6-kyu/equal-side-of-an-array.hs | 11 | ||||
| -rw-r--r-- | 6-kyu/pyramid-array.rkt | 14 | ||||
| -rw-r--r-- | 6-kyu/valid-braces.hs | 22 |
5 files changed, 81 insertions, 0 deletions
diff --git a/6-kyu/does-my-number-look-big-in-this.hs b/6-kyu/does-my-number-look-big-in-this.hs new file mode 100644 index 0000000..3de21d8 --- /dev/null +++ b/6-kyu/does-my-number-look-big-in-this.hs @@ -0,0 +1,16 @@ +-- 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/6-kyu/duplicate-encoder.hs b/6-kyu/duplicate-encoder.hs new file mode 100644 index 0000000..1cb38eb --- /dev/null +++ b/6-kyu/duplicate-encoder.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/6-kyu/equal-side-of-an-array.hs b/6-kyu/equal-side-of-an-array.hs new file mode 100644 index 0000000..00717d7 --- /dev/null +++ b/6-kyu/equal-side-of-an-array.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/6-kyu/pyramid-array.rkt b/6-kyu/pyramid-array.rkt new file mode 100644 index 0000000..0d6a00b --- /dev/null +++ b/6-kyu/pyramid-array.rkt @@ -0,0 +1,14 @@ +#lang racket + +;; https://www.codewars.com/kata/515f51d438015969f7000013 + +(provide pyramid) + +(define (pyramid n) + (define (loop ret level cur) + (define next (cons 1 cur)) + (if (= level n) + (reverse ret) + (loop (cons next ret) (+ level 1) next))) + (loop '() 0 '())) + diff --git a/6-kyu/valid-braces.hs b/6-kyu/valid-braces.hs new file mode 100644 index 0000000..1df6f5c --- /dev/null +++ b/6-kyu/valid-braces.hs @@ -0,0 +1,22 @@ +-- 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 |
