Skip to content

Commit

Permalink
Iterate through digits directly in Julia munchausen implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Nov 10, 2019
1 parent 3c84d44 commit 9645891
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Julia/test_munchausen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ function find_munchausen_numbers()
num = 0
i = 0
while num < 4
if (i == sum(power_of_digits[x+1] for x in digits(i)))
thisnumber = i
# find the sum of the digits raised to themselves
sumofpowers = 0
while thisnumber > 0
digit = thisnumber % 10
sumofpowers += power_of_digits[digit+1]
thisnumber ÷= 10
end
if i == sumofpowers
num += 1
println("Munchausen number: ", num, " ", i)
end
Expand Down

0 comments on commit 9645891

Please sign in to comment.