June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,19 +1,19 @@
n = 40
function hamming(n::Integer)
seq = collect(0:n)
pwrs2 = 2 .^ seq
pwrs3 = 3 .^ seq
pwrs5 = 5 .^ seq
powers_2 = 2.^[0:n-1]
powers_3 = 3.^[0:n-1]
powers_5 = 5.^[0:n-1]
matrix = pwrs2 * pwrs3'
pwrs23 = sort(reshape(matrix, length(matrix)))
matrix = powers_2 * powers_3'
powers_23 = sort(reshape(matrix,length(matrix),1),1)
matrix = pwrs23 * pwrs5'
if any(x -> x < 0, matrix) warn("overflow values in result, try to use big($n) instead") end
return sort(reshape(matrix, length(matrix)))
end
matrix = powers_23 * powers_5'
powers_235 = sort(reshape(matrix,length(matrix),1),1)
x = hamming(big(100))
#
# Remove the integer overflow values.
#
powers_235 = powers_235[powers_235 .> 0]
println(powers_235[1:20])
println(powers_235[1691])
println("First 20 hamming numbers: ", join(x[1:20], ", "))
println("1691-th hamming number: ", x[1691])
println("Million-th hamming number: ", x[1000000])