Skip to content

Instantly share code, notes, and snippets.

@aiya000
Created December 27, 2014 03:36
Show Gist options
  • Select an option

  • Save aiya000/c257c7a24c2fefea5608 to your computer and use it in GitHub Desktop.

Select an option

Save aiya000/c257c7a24c2fefea5608 to your computer and use it in GitHub Desktop.
import Control.Monad
type Bar = [Int]
type BarLen = Int
type SelectLen = Int
type Damage = Int
main :: IO ()
main = getLengths >>= \(rLen,bLen) ->
getBar bLen >>= \bar ->
print $ criticalDamage bar rLen
getLengths :: IO (BarLen,SelectLen)
getLengths = getLine >>=
return . map read . words >>= \(x:y:_) ->
return (x,y)
getBar :: BarLen -> IO Bar
getBar n = replicateM n getLine >>= return . map read
criticalDamage :: Bar -> SelectLen -> Damage
criticalDamage xs n = foldr max 0 $ damages xs n
where
damages ys m = foldr (\a b -> fst a + snd a : b) [] $ zip ys (tail ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment