# My Weblog

## SPOJ 8612. Penney Game

SPOJ 8612. Penney Game is an easy simulation problem . Accepted Haskell code , not very Haskellish but accepted .

```import Data.List
import qualified Data.ByteString.Char8 as BS

countfN :: String -> ( Int , Int , Int , Int , Int , Int , Int , Int ) -> String
countfN [ x , y ]( a , b , c , d , e , f , g , h )  = foldl ( \ x y ->  x ++ " " ++ show y ) ( show a ) [ b , c , d , e , f , g , h ]
countfN ( x : y : z : xs ) ( a , b , c , d , e , f , g , h )
| x : y : z :[] == "TTT" = countfN ( y : z : xs ) ( a + 1 , b , c , d , e , f , g , h )
| x : y : z :[] == "TTH" = countfN ( y : z : xs ) ( a  , b + 1 , c , d , e , f , g , h )
| x : y : z :[] == "THT" = countfN ( y : z : xs ) ( a  , b , c + 1 , d , e , f , g , h )
| x : y : z :[] == "THH" = countfN ( y : z : xs ) ( a  , b , c , d + 1 , e , f , g , h )
| x : y : z :[] == "HTT" = countfN ( y : z : xs ) ( a  , b , c , d , e + 1 , f , g , h )
| x : y : z :[] == "HTH" = countfN ( y : z : xs ) ( a  , b , c , d , e , f + 1 , g , h )
| x : y : z :[] == "HHT" = countfN ( y : z : xs ) ( a  , b , c , d , e , f , g + 1 , h )
| otherwise =  countfN ( y : z : xs ) ( a  , b , c , d , e , f , g , h + 1 )

solve :: String -> String
solve xs = countfN xs ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )

format :: [ String ] -> [ String ]
format [] = []
format ( x : y : xs ) = y : format xs

main = interact \$ unlines . zipWith (\x y -> show x ++ " " ++  y ) [1..] . map solve . format . tail . lines
```