Skip to content

Commit

Permalink
Upload homework
Browse files Browse the repository at this point in the history
  • Loading branch information
IvoTod committed Nov 1, 2016
1 parent 9039144 commit 9bf71c4
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions exercises/secret-lang/Secret-lang.hs
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
import Data.Char(toLower)

vowels = "aeiou"

isChar :: Char -> Bool
isChar = undefined
isChar char
| toLower char >= 'a' && toLower char <= 'z' = True
isChar _ = False

isInString :: Char -> String -> Bool
isInString char [] = False
isInString char (first:rest)
| char == first = True
| char /= first = isInString char rest


isVowel :: Char -> Bool
isVowel = undefined
isVowel char
| isInString (toLower char) vowels == True = True
isVowel _ = False


isConsonant :: Char -> Bool
isConsonant = undefined
isConsonant char
| isVowel char == False && isChar char == True = True
| otherwise = False


encode :: String -> String
encode = undefined
encode [] = []
encode (first:rest)
| isConsonant first == True = first : 'o' : first : (encode rest)
| otherwise = first:(encode rest)


-- Bonus #1
encode' :: String -> String
encode' = undefined
encode' [] = []
encode' (first:rest)
| isConsonant first == True = first : 'o' : toLower first : (encode' rest)
| otherwise = first:(encode' rest)


-- Bonus #2
dropN :: Int -> String -> String
dropN = undefined
dropN number [] = []
dropN 0 string = string
dropN number (first:rest) = dropN (number-1) rest



--Assume we'll be decoding only valid words
decode :: String -> String
decode = undefined
decode [] = []
decode (x : 'o' : y : rest)
| x == y = x : decode (dropN 2 ('o':y:rest))
| otherwise = x : 'o' : y : (decode (rest))
decode (first : rest) = first : decode (rest)

0 comments on commit 9bf71c4

Please sign in to comment.