[ create a new paste ] login | about

Link: http://codepad.org/Cq2m3Fru    [ raw code | output | fork | 1 comment ]

mohit_at_codepad - Haskell, pasted on Mar 19:
-- Written by Mohit Jain
-- Input: A string containing only letters 'a'-'z'
-- Output: True if string is a valid name, False otherwise
-- Rules: A name is valid if it follows all the rules given below.
--        1. Length of name is exactly 8 characters.
--        2. Name contains exactly 2 vowels.
--        3. Both vowels are same.

module Main where
main = ( putStrLn . unlines . map show . map isValid ) ["chammach",
                                                        "chamcham",
                                                        "chumchum",
                                                        "trezrent",
                                                        "abcdefgh",
                                                        "trezrents",
                                                        "martrent",
                                                        "mohit",
                                                        "mohitjain"]

isValid name = if (nameLen /= 8) then False else (eval nameVow) where
               nameLen = length name
               nameVow = filter (\x -> elem x "aeiou") name
               eval vow = if (length vow /= 2) then False else (vow!!0 == vow!!1)


Output:
1
2
3
4
5
6
7
8
9
10
True
True
True
True
False
False
False
False
False



Create a new paste based on this one


Comments:
posted by mohit_at_codepad on Mar 20
Review comment: Extra last line can be avoided by using putStr instead of putStrLn.
reply