My Weblog

Blog about programming and math

SPOJ Contest System Quality Assurance Tester

Contest System Quality Assurance Tester is also easy problem and i wrote solution for this one in more Haskellish way using the foldr function.

import Data.List

solve :: [Integer ]->String 
solve xs = 
     let 
	( a:b:c:d:e:f:_ ) = xs
	ys = [( a,d ) , ( b,e ) , ( c,f ) ] 
	( l_ , y_ ) = foldr ( \( x , y ) ( l , m ) -> if x > 0 then ( l+1 , m + x + ( y -1 ) * 20 * 60 ) else ( l , m ) ) ( 0 , 0 ) ys
     in ( show l_ ) ++ ", " ++ ( show y_ )


main = interact $ unlines .zipWith (++) [ "team " ++ show i ++ ": " |i <- [1..] ] .  map ( solve.map read.words ).lines
Advertisements

May 16, 2011 - Posted by | Programming

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: