Skip to content

Instantly share code, notes, and snippets.

@chrissound
Created October 18, 2016 19:30
Show Gist options
  • Select an option

  • Save chrissound/fc3c72dea60abdbe70f11974f13c8f2f to your computer and use it in GitHub Desktop.

Select an option

Save chrissound/fc3c72dea60abdbe70f11974f13c8f2f to your computer and use it in GitHub Desktop.
import Control.Applicative
import Control.Monad
import System.IO
import Debug.Trace
getMultipleLines :: Int -> IO [String]
getMultipleLines n
| n <= 0 = return []
| otherwise = do
x <- getLine
xs <- getMultipleLines (n-1)
let ret = (x:xs)
return ret
getCountRepeatingChars :: String -> Int
getCountRepeatingChars [] = 0
getCountRepeatingChars (_:[]) = 0
getCountRepeatingChars (x:(xs@y:z))
| x == y = 1 + rest
| otherwise = rest
where rest = getCountRepeatingChars (y : z)
main :: IO ()
main = do
linesToGet <- getLine
a <- getMultipleLines (read linesToGet)
let repeatChars = map getCountRepeatingChars a
mapM_ print repeatChars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment