-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload homework #2
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Няма нужда да сравняваш върнатия булев резултат с |
||
| otherwise = False | ||
|
||
|
||
encode :: String -> String | ||
encode = undefined | ||
encode [] = [] | ||
encode (first:rest) | ||
| isConsonant first == True = first : 'o' : first : (encode rest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant |
||
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Няма нужда от guard, тъй като резултатният тип е
Bool
, т.е.isVowel char = isInString (toLower char) vowels
е еквивалентно :)