[ create a new paste ] login | about

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

mohit_at_codepad - Haskell, pasted on Mar 7:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- Written by Mohit to solve Pikachu problem
-- Pikachu is a character from Pokemon and he can speak
-- only 3 syllables: pi, ka and chu.
-- Aim of this program is to write a function that can verify
-- whether pikachu can speak a sentence or not
-- Input contains string (all lowercase, no spaces), output is true or false

module Main where

checkSyllables :: String -> Bool
checkSyllables [] = True
checkSyllables ('p':'i':rest)     = checkSyllables rest
checkSyllables ('k':'a':rest)     = checkSyllables rest
checkSyllables ('c':'h':'u':rest) = checkSyllables rest
checkSyllables _ = False

checkPikachu :: String -> String
checkPikachu str = str ++ " " ++ show (checkSyllables str)

main = putStrLn $ unlines $ map checkPikachu ["", "pi", "chu", "chupi", "p", "pika", "pipipikapikakachuchupichuchukapi", "pipipikapikakaachuchupichuchukapi"]


Output:
1
2
3
4
5
6
7
8
9
 True
pi True
chu True
chupi True
p False
pika True
pipipikapikakachuchupichuchukapi True
pipipikapikakaachuchupichuchukapi False



Create a new paste based on this one


Comments:
posted by mohit_at_codepad on Mar 20
Review Comments:
Line number 20 is very large. Long lines should be broken down to smaller lines.
reply