Pan base non-primes: Difference between revisions

added RPL
(→‎{{header|PARI/GP}}: fix jump anchor problem)
(added RPL)
 
(One intermediate revision by one other user not shown)
Line 511:
print "Percent even up to and including " & limit & ": " & 100 - p
</syntaxhighlight>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">#include "isprime.bas"
 
Const lim As Integer = 2500
Dim As Integer pbnp(lim)
Dim As Integer n, base_, d, c, tc, oc, ec
Dim As String digits
Dim As Boolean composite
 
For n = 3 To lim
digits = Str(n)
composite = True
For base_ = 2 To n
d = 0
For c = 1 To Len(digits)
d = d * base_ + Val(Mid(digits, c, 1))
Next c
If IsPrime(d) Then
composite = False
Exit For
End If
Next base_
If composite Then
tc += 1
pbnp(tc) = n
If n Mod 2 <> 0 Then oc += 1
End If
Next n
 
ec = tc - oc
 
Print "First 50 pan-base composites:"
For n = 1 To 50
Print Using "### "; pbnp(n);
If n Mod 10 = 0 Then Print
Next n
 
Print !"\nFirst 20 odd pan-base composites:"
c = 0
For n = 1 To 115
If pbnp(n) Mod 2 Then
Print Using "### "; pbnp(n);
'Print Using "### "; odds(n);
c += 1
If c Mod 10 = 0 Then Print
End If
Next n
 
Print !"\nCount of pan-base_ composites up to and including "; lim; ": "; tc
Print Using "Number odd = ### or ##.######%"; oc; oc/tc*100
Print Using "Number even = ### or ##.######%"; ec; ec/tc*100
 
Sleep</syntaxhighlight>
{{out}}
<pre>Same as Wren entry.</pre>
 
=={{header|J}}==
Line 1,226 ⟶ 1,282:
Percent odd up to and including 2500: 16.894019
Percent even up to and including 2500: 83.105981</pre>
 
=={{header|RPL}}==
{{works with|RPL|HP-49C}}
« { } SWAP
'''WHILE''' DUP '''REPEAT''' 10 IDIV2 ROT + SWAP '''END'''
DROP
» '<span style="color:blue">→DIGL</span>' STO
« { } 3 ROT '''FOR''' n
1 CF
'''CASE'''
n 10 > LASTARG MOD NOT AND '''THEN''' 1 SF '''END'''
n
'''IF''' DUP 9 > '''THEN'''
<span style="color:blue">→DIGL</span>
'''IF''' DUP « GCD » STREAM 1 > '''THEN''' DROP 1 SF '''END'''
'''END'''
1 FC? '''THEN'''
1 SF
2 n '''FOR''' b
DUP
'''IF''' DUP TYPE 5 == '''THEN''' « SWAP b * + » STREAM '''END'''
'''IF''' ISPRIME? '''THEN''' 1 CF n 'b' STO '''END'''
'''NEXT''' DROP
'''END'''
'''END'''
'''IF''' 1 FS? '''THEN''' n + '''END'''
'''NEXT'''
» '<span style="color:blue">TASK</span>' STO
« DUP 2 MOD OVER IFT
→ pbnp odds
« pbnp 1 50 SUB
odds 1 20 SUB
pbnp SIZE "pbnp ≤ 1000" →TAG
odds SIZE pbnp SIZE / 100 * "% odd" →TAG
» » '<span style="color:blue">PBNPVU</span>' STO
 
1000 <span style="color:blue">TASK</span> <span style="color:blue">PBNPVU</span>
{{out}}
<pre>
4: { 4 6 8 9 20 22 24 26 28 30 33 36 39 40 42 44 46 48 50 55 60 62 63 64 66 68 69 70 77 80 82 84 86 88 90 93 96 99 100 110 112 114 116 118 120 121 130 132 134 136 }
3: { 9 33 39 55 63 69 77 93 99 121 143 165 169 187 231 253 273 275 297 299 }
2: pbnp ≤ 1000: 377.
1: % odd: 16.7108753316
</pre>
 
=={{header|Ruby}}==
1,150

edits