Skip to content

Instantly share code, notes, and snippets.

@ellygaytor
Created November 1, 2021 16:54
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 ellygaytor/52d10ddc6538f1eee15a4c7aa7173b86 to your computer and use it in GitHub Desktop.
Save ellygaytor/52d10ddc6538f1eee15a4c7aa7173b86 to your computer and use it in GitHub Desktop.
Use Genie to show the prime factors of a number
using Genie, Genie.Router
using Genie.Renderer, Genie.Renderer.Html, Genie.Renderer.Json
function primefactors(x)
factors = []
i=2
while x != i
if x%i==0
push!(factors, i)
x = x/i
i = 2
else
i += 1
end
end
push!(factors, i)
return factors
end
route("/") do
num = params(:number, "14")
num = parse(Int64, num)
"Factors of $num: $(primefactors(num))"
end
up(8001, async = false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment