Skip to content

Instantly share code, notes, and snippets.

@niinpatel
Created April 2, 2019 08:36
Show Gist options
  • Save niinpatel/d84df4cd60f7687f3f9c6a0bb0973fc6 to your computer and use it in GitHub Desktop.
Save niinpatel/d84df4cd60f7687f3f9c6a0bb0973fc6 to your computer and use it in GitHub Desktop.
breakingRecords :: [Int] -> [Int]
updateMinMax [maxRec,minRec,max, min] score =
[newMaxRec,newMinRec,newMax,newMin]
where
newMax = if score > max then score else max
newMin = if score < min then score else min
newMaxRec = if newMax > max then (maxRec + 1) else maxRec
newMinRec = if newMin < min then (minRec + 1) else minRec
breakingRecords scores = take 2 $ foldl updateMinMax [0,0,head scores, head scores] scores
main = interact $ unwords . map show . breakingRecords . map read . tail . words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment