Skip to content

Instantly share code, notes, and snippets.

@ctran
Created June 2, 2009 02:39
Show Gist options
  • Save ctran/121948 to your computer and use it in GitHub Desktop.
Save ctran/121948 to your computer and use it in GitHub Desktop.
-- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment