Odd squarefree semiprimes: Difference between revisions

Content added Content deleted
m (C# - Edited code & output to reflect new task name)
m (→‎{{header|Ring}}: removed formatting kludge, added function call to primitive string formatter)
Line 348: Line 348:
<lang ring>? "working..." + nl + "Odd squarefree semiprimes are:"
<lang ring>? "working..." + nl + "Odd squarefree semiprimes are:"
limit = 1000
limit = 1000 Prim = []
Prim = []

# table of prime numbers from 3 to 1000/3
# table of prime numbers from 3 to 1000/3
pr = [ 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
pr = [ 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
131, 137, 139, 149, 151, 157, 163, 167, 173, 179,
181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
293, 307, 311, 313, 317, 331]
293, 307, 311, 313, 317, 331]
pl = len(pr)
pl = len(pr)

# calculate upper limit for n
# calculate upper limit for n
for nlim = 1 to pl
for nlim = 1 to pl
if pr[nlim] * pr[nlim] > limit
if pr[nlim] * pr[nlim] > limit exit ok
next nlim--
exit
ok
next
nlim--

# add items to result list and sort
# add items to result list and sort
for n = 1 to nlim
for n = 1 to nlim
for m = n + 1 to pl
for m = n + 1 to pl
amt = pr[n] * pr[m]
amt = pr[n] * pr[m]
if amt > limit
if amt > limit exit ok
exit
ok
add(Prim, amt)
add(Prim, amt)
next
next
next Prim = sort(Prim)
next
Prim = sort(Prim)

# display results
# display results
for n = 1 to len(Prim)
for n = 1 to len(Prim)
if Prim[n] < 100
see sf(Prim[n], 4) + " "
see " "
if n % 20 = 0 see nl ok
next n--
ok

see " " + Prim[n] + " "
? nl + nl + "Found " + n + " Odd squarefree semiprimes." + nl + "done..."
if n % 20 = 0

see nl
# a very plain string formatter, intended to even up columnar outputs
ok
def sf x, y
next
s = string(x) l = len(s)
n--
if l > y y = l ok
? nl + "Found " + n + " Odd squarefree semiprimes." + nl + "done..."</lang>
return substr(" ", 11 - y + l) + s </lang>
{{out}}
{{out}}
<pre>working...
<pre>working...
Line 406: Line 397:
817 831 835 843 849 851 865 869 871 879 889 893 895 899 901 905 913 917 921 923
817 831 835 843 849 851 865 869 871 879 889 893 895 899 901 905 913 917 921 923
933 939 943 949 951 955 959 965 973 979 985 989 993 995
933 939 943 949 951 955 959 965 973 979 985 989 993 995

Found 194 Odd squarefree semiprimes.
Found 194 Odd squarefree semiprimes.
done...</pre>
done...
</pre>


=={{header|Wren}}==
=={{header|Wren}}==