Skip to content

Instantly share code, notes, and snippets.

@wasi0013
Created February 9, 2020 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wasi0013/bba3508007fe531e3899d0aac1f77ca2 to your computer and use it in GitHub Desktop.
Save wasi0013/bba3508007fe531e3899d0aac1f77ca2 to your computer and use it in GitHub Desktop.
# Compute 333.75y6 + x2(11x2y2 – y6 – 121y4 – 2) + 5.5y8 + x/(2y) where x = 77617, y = 33096
defmodule Pow do
# https://stackoverflow.com/a/32030190/3083094
require Integer
def pow(_, 0), do: 1
def pow(x, n) when Integer.is_odd(n), do: x * pow(x, n - 1)
def pow(x, n) do
result = pow(x, div(n, 2))
result * result
end
end
defmodule Solution do
def calc(x, y), do: 333.75 * Pow.pow(y, 6) + Pow.pow(x, 2) * (11 * Pow.pow(x, 2) * Pow.pow(y, 2) - Pow.pow(y, 6) - 121 * Pow.pow(y, 4) - 2) + 5.5 * Pow.pow(y, 8) + x / (2 * y)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment