Rare numbers: Difference between revisions
Content added Content deleted
(Rare numbers en FreeBASIC) |
m (→{{header|FreeBASIC}}: made it more FreeBASIC, added simple test.) |
||
Line 1,246: | Line 1,246: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
Made some changes and added a simple test to speed things up. Results in about 1 minute. |
|||
About 16.5 minutes to find the first 5 rare numbers |
|||
{{trans|Phix}} |
{{trans|Phix}} |
||
<lang freebasic> |
<lang freebasic>Function revn(n As ULongInt, nd As ULongInt) As ULongInt |
||
⚫ | |||
#define floor(x) ((x*2.0-0.5) Shr 1) |
|||
⚫ | |||
#define remainder(n, m) (n-m*Int(n/m)) |
|||
⚫ | |||
⚫ | |||
Function revn(n As Integer, nd As Integer) As Integer |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Next i |
Next i |
||
Return r |
Return r |
||
End Function |
End Function |
||
Dim As |
Dim As UInteger nd = 2, count, lim = 90, n = 20 |
||
Do |
Do |
||
n += 1 |
n += 1 |
||
Dim As |
Dim As ULongInt r = revn(n,nd) |
||
If r < n Then |
If r < n Then |
||
Dim As |
Dim As ULongInt s = n + r, d = n - r |
||
If |
If nd And 1 Then |
||
If d Mod 1089 <> 0 Then GoTo jump |
|||
Else |
|||
If s Mod 121 <> 0 Then GoTo jump |
|||
End If |
|||
If Frac(Sqr(s)) = 0 And Frac(Sqr(d)) = 0 Then |
|||
count += 1 |
count += 1 |
||
Print count; ":"; n |
Print count; ": "; n |
||
If count = 5 Then Exit Do : End If |
If count = 5 Then Exit Do : End If |
||
End If |
End If |
||
End If |
End If |
||
jump: |
|||
If n = lim Then |
If n = lim Then |
||
lim = lim * 10 |
lim = lim * 10 |
||
nd += 1 |
nd += 1 |
||
n = (lim \ 9) * 2 |
|||
End If |
End If |
||
Loop |
Loop |
||
⚫ | |||
Print |
|||
Print "Done" |
|||
⚫ | |||
{{out}} |
|||
<pre>1: 65 |
|||
2: 621770 |
|||
3: 281089082 |
|||
4: 2022652202 |
|||
5: 2042832002</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |