Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Self-numbers/Julia/self-numbers-1.julia
Normal file
26
Task/Self-numbers/Julia/self-numbers-1.julia
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
gsum(i) = sum(digits(i)) + i
|
||||
isnonself(i) = any(x -> gsum(x) == i, i-1:-1:i-max(1, ndigits(i)*9))
|
||||
const last81 = filter(isnonself, 1:5000)[1:81]
|
||||
|
||||
function checkselfnumbers()
|
||||
i, selfcount = 1, 0
|
||||
while selfcount <= 100_000_000 && i <= 1022727208
|
||||
if !(i in last81)
|
||||
selfcount += 1
|
||||
if selfcount < 51
|
||||
print(i, " ")
|
||||
elseif selfcount == 51
|
||||
println()
|
||||
elseif selfcount == 100_000_000
|
||||
println(i == 1022727208 ?
|
||||
"Yes, $i is the 100,000,000th self number." :
|
||||
"No, instead $i is the 100,000,000th self number.")
|
||||
end
|
||||
end
|
||||
popfirst!(last81)
|
||||
push!(last81, gsum(i))
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
|
||||
checkselfnumbers()
|
||||
43
Task/Self-numbers/Julia/self-numbers-2.julia
Normal file
43
Task/Self-numbers/Julia/self-numbers-2.julia
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
const MAXCOUNT = 103 * 10000 * 10000 + 11 * 9 + 1
|
||||
|
||||
function dosieve!(sieve, digitsum9999)
|
||||
n = 1
|
||||
for a in 1:103, b in 1:10000
|
||||
s = digitsum9999[a] + digitsum9999[b] + n
|
||||
for c in 1:10000
|
||||
sieve[digitsum9999[c] + s] = true
|
||||
s += 1
|
||||
end
|
||||
n += 10000
|
||||
end
|
||||
end
|
||||
|
||||
initdigitsum() = reverse!(vec([sum(k) for k in Iterators.product(9:-1:0, 9:-1:0, 9:-1:0, 9:-1:0)]))
|
||||
|
||||
function findselves()
|
||||
sieve = zeros(Bool, MAXCOUNT+1)
|
||||
println("Sieve time:")
|
||||
@time begin
|
||||
digitsum = initdigitsum()
|
||||
dosieve!(sieve, digitsum)
|
||||
end
|
||||
cnt = 1
|
||||
for i in 1:MAXCOUNT+1
|
||||
if !sieve[i]
|
||||
cnt > 50 && break
|
||||
print(i, " ")
|
||||
cnt += 1
|
||||
end
|
||||
end
|
||||
println()
|
||||
limit, cnt = 1, 0
|
||||
for i in 0:MAXCOUNT
|
||||
cnt += 1 - sieve[i + 1]
|
||||
if cnt == limit
|
||||
println(lpad(cnt, 10), lpad(i, 12))
|
||||
limit *= 10
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@time findselves()
|
||||
Loading…
Add table
Add a link
Reference in a new issue