Created
November 1, 2021 16:54
-
-
Save ellygaytor/52d10ddc6538f1eee15a4c7aa7173b86 to your computer and use it in GitHub Desktop.
Use Genie to show the prime factors of a number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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