Skip to content

Instantly share code, notes, and snippets.

@jaguilar
Created March 31, 2013 17:26
Show Gist options
  • Save jaguilar/5281365 to your computer and use it in GitHub Desktop.
Save jaguilar/5281365 to your computer and use it in GitHub Desktop.
hedgemony = (input) ->
lines = input.match(/[^\r\n]+/g);
numTests = parseInt(lines[0])
formatOutput i, solve lines[2*i] for i in [1..numTests]
solve = (line) ->
heights = (parseFloat s for s in line.split(" "))
n = 1
while n < heights.length - 1
average = (heights[n-1] + heights[n+1]) / 2.0
heights[n] = if heights[n] > average then average else heights[n]
++n
heights[heights.length - 2]
formatOutput = (problemNumber, solution) ->
"Case \##{problemNumber}: #{solution.toFixed(4)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment