ctran (owner)

Revisions

gist: 121948 Download_button fork
public
Public Clone URL: git://gist.github.com/121948.git
Embed All Files: show embed
fctrl.hs #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- file: fctrl.hs
-- http://www.codechef.com/problems/FCTRL/
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -O2 #-}
module Main where
 
import qualified Data.ByteString.Char8 as S
import IO
 
main :: IO ()
main = mapM_ (print . fctrl) . tail . readInts =<< S.getContents
  where
    readInts s = case S.readInt s of -- lazily reads current line
                 Nothing -> []
                 Just (k,t) -> k : readInts (S.tail t)
 
fctrl :: Int -> Int
fctrl = fctrl' 0
    where
        fctrl' :: Int -> Int -> Int
        fctrl' r n | n < 5 = r
                   | otherwise = fctrl' (r + n') n'
          where n' = div n 5