Ludic numbers: Difference between revisions
Content added Content deleted
(→{{header|Julia}}: A new entry for Julia) |
|||
Line 1,075:
2000th - 2005th Ludics: [21475, 21481, 21487, 21493, 21503, 21511]
Triplets up to 250: [[1, 3, 7], [5, 7, 11], [11, 13, 17], [23, 25, 29], [41, 43, 47], [173, 175, 179], [221, 223, 227], [233, 235, 239]]</pre>
=={{header|Julia}}==
<lang Julia>
function ludic_filter{T<:Integer}(n::T)
0 < n || throw(DomainError())
slud = trues(n)
for i in 2:(n-1)
slud[i] || continue
x = 0
for j in (i+1):n
slud[j] || continue
x += 1
x %= i
x == 0 || continue
slud[j] = false
end
end
return slud
end
ludlen = 10^5
slud = ludic_filter(ludlen)
ludics = collect(1:ludlen)[slud]
n = 25
println("Generate and show here the first ", 25, " ludic numbers.")
print(" ")
crwid = 76
wid = 0
for i in 1:(n-1)
s = @sprintf "%d, " ludics[i]
wid += length(s)
if crwid < wid
print("\n ")
wid = 0
end
print(s)
end
println(ludics[n])
n = 10^3
println()
println("How many ludic numbers are there less than or equal to ", n, "?")
println(" ", sum(slud[1:n]))
lo = 2000
hi = lo+5
println()
println("Show the ", lo, "..", hi, "'th ludic numbers.")
for i in lo:hi
println(" Ludic(", i, ") = ", ludics[i])
end
n = 250
println()
println("Show all triplets of ludic numbers < ", n)
for i = 1:n-7
slud[i] || continue
j = i+2
slud[j] || continue
k = i+6
slud[k] || continue
println(" ", i, ", ", j, ", ", k)
end
</lang>
{{out}}
<pre>
Generate and show here the first 25 ludic numbers.
1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43, 47, 53, 61, 67, 71, 77,
83, 89, 91, 97, 107
How many ludic numbers are there less than or equal to 1000?
142
Show the 2000..2005'th ludic numbers.
Ludic(2000) = 21475
Ludic(2001) = 21481
Ludic(2002) = 21487
Ludic(2003) = 21493
Ludic(2004) = 21503
Ludic(2005) = 21511
Show all triplets of ludic numbers < 250
1, 3, 7
5, 7, 11
11, 13, 17
23, 25, 29
41, 43, 47
173, 175, 179
221, 223, 227
233, 235, 239
</pre>
=={{header|Mathematica}}==
|