Let us know if the word chain game was played correctly! The object of the game is to form another word with the last letter of the previous word. The words are separated by a space. The words function can help you solve this problem.
Each of the following test cases must give a True:
validGame "alma asztal lo olalkodik kutya" == True
validGame "konverv veg golya abrosz zsifaf fules" == True
validGame "erdo osztokel nyugat tabortuz" == False
validGame "zokog guzsalyas sararany nyul leng" == False
CodePudding user response:
validGame :: String -> Bool
validGame (x:' ':z:xs) = (x==z) && validGame (z:xs)
validGame (x:xs) = validGame xs
validGame [] = True