DEV Community

Discussion on: Daily Challenge #103 - Simple Symbols

Collapse
 
jvanbruegge profile image
Jan van Brügge

simple Haskell solution:

verify :: String -> Bool
verify [] = True
verify ('+':x:'+':xs)
    | isLetter x = verify $ '+':xs
verify (x:xs)
    | isLetter x = False
    | otherwise = verify xs
Collapse
 
aminnairi profile image
Amin • Edited

Whoa, I was comming with something that involved using an indexedMap but your solution is very clever. Thanks for sharing your awesome answer!

Also, isn't isLetter part of Data.Char? Or no need to import that to use the isLetter function?

Collapse
 
jvanbruegge profile image
Jan van Brügge

yes, that function is from Data.Char, I omitted the import together with the module header.

Collapse
 
idanarye profile image
Idan Arye

I took your solution and simplified it:

verify :: String -> Bool
verify [] = True
verify ('+':x:'+':xs) = verify $ '+':xs
verify ('+':xs) = verify xs
verify ('=':xs) = verify xs
verify (_) = False

Also note that nothing in the question indicates the characters other than = and + can only be letters. Your version would accept 1 even though 1 is a character and it is not surrounded by +s.

Collapse
 
jvanbruegge profile image
Jan van Brügge

This solution assumes that the only other character is =. No idea if you can assume this

Thread Thread
 
idanarye profile image
Idan Arye

The string will be composed of + and = symbols with several characters between them.

If I'm reading this correctly, it means that the characters are categorized into three categories:

  1. +
  2. =
  3. Other

So any character other than + and = must be surrounded by +s - which is exactly what my version checks.