Skip to content

Instantly share code, notes, and snippets.

@wende
Last active December 15, 2015 19:18
Show Gist options
  • Save wende/dc32bc28bca78f30f263 to your computer and use it in GitHub Desktop.
Save wende/dc32bc28bca78f30f263 to your computer and use it in GitHub Desktop.
Enum.take_while( IO.stream(:stdio, :line), fn
"\n" -> false
_ -> true
end)
|> Enum.map(fn line ->
String.split(line, "x")
|> Enum.map(&Integer.parse/1)
|> (fn [{a,_},{b,_},{c,_}] ->
2*(a*b + a*c + b*c) + (
Enum.sort([a,b,c])
|> Enum.take(2)
|> (fn [a,b] -> a*b end).()
)
end).()
end)
|> Enum.sum
println(io.Source.stdin.getLines.map { line =>
val nums = line.split("x").map(_.toInt)
val Array(a, b, c) = nums
2*(a*b + a*c + b*c) + nums.sorted.take(2).product
}.sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment