Rhonda numbers: Difference between revisions

Added FreeBASIC
(Replaced "isOdd" with "isEven".)
(Added FreeBASIC)
 
(2 intermediate revisions by 2 users not shown)
Line 533:
In base 36: rs 3pc 4di 6bi 8hi 9ks a9g c5i cz9 hrc 13to 14ou 1g9s 1iq9 1lw6
</pre>
 
=={{header|FreeBASIC}}==
{{trans|ALGOL 68}}
<syntaxhighlight lang="vbnet">'#include "isprime.bas"
 
Function FactorSum(n As Uinteger) As Uinteger
Dim As Uinteger result = 0
Dim As Uinteger v = Abs(n)
While v > 1 And v Mod 2 = 0
result += 2
v \= 2
Wend
For f As Uinteger = 3 To v Step 2
While v > 1 And v Mod f = 0
result += f
v \= f
Wend
Next f
Return result
End Function
 
Function DigitProduct(n As Uinteger, base_ As Uinteger) As Uinteger
If n = 0 Then Return 0
Dim As Uinteger result = 1
Dim As Uinteger v = Abs(n)
While v > 0
result *= v Mod base_
v \= base_
Wend
Return result
End Function
 
Function isRhonda(n As Uinteger, base_ As Uinteger) As Uinteger
Return base_ * FactorSum(n) = DigitProduct(n, base_)
End Function
 
Function ToBaseString(n As Uinteger, base_ As Uinteger) As String
If n = 0 Then Return "0"
Dim As Uinteger under10 = Asc("0")
Dim As Uinteger over9 = Asc("a") - 10
Dim As String result = ""
Dim As Uinteger v = Abs(n)
While v > 0
Dim As Uinteger d = v Mod base_
result = Chr(d + Iif(d < 10, under10, over9)) + result
v \= base_
Wend
Return result
End Function
 
Dim As Uinteger maxRhonda = 10, maxBase = 16
For base_ As Uinteger = 2 To maxBase
If Not isPrime(base_) Then
Print "The first "; maxRhonda; " Rhonda numbers in base "; base_; ":"
Dim As Uinteger rCount = 0
Dim As Uinteger rhonda(1 To maxRhonda)
Dim As Uinteger n = 1
While rCount < maxRhonda
If isRhonda(n, base_) Then
rCount += 1
rhonda(rCount) = n
End If
n += 1
Wend
Print " in base 10: ";
For i As Uinteger = 1 To maxRhonda
Print " "; rhonda(i);
Next i
Print
If base_ <> 10 Then
Print Using " in base ##: "; base_;
For i As Uinteger = 1 To maxRhonda
Print " "; ToBaseString(rhonda(i), base_);
Next i
Print
End If
End If
Next base_
 
Sleep</syntaxhighlight>
{{out}}
<pre>Same as ALGOL 68 entry.</pre>
 
=={{header|Go}}==
Line 1,766 ⟶ 1,848:
In base 10: 1000 4800 5670 8190 10998 12412 13300 15750 16821 23016
In base 36: rs 3pc 4di 6bi 8hi 9ks a9g c5i cz9 hrc
</pre>
 
=={{header|PARI/GP}}==
{{trans|Julia}}
<syntaxhighlight lang="PARI/GP">
isRhonda(n, b) =
{
local(mydigits, product, mysum, factors, pairProduct);
mydigits = digits(n, b);
product = vecprod(mydigits);
factors = factor(n);
mysum= 0;
for(i = 1, matsize(factors)[1],
pairProduct = factors[i, 1] * factors[i, 2];
mysum += pairProduct;
);
product == b * mysum;
}
 
displayrhondas(low, high, nshow) =
{
local(b, n, rhondas, count, basebRhondas);
for(b = low, high,
if(isprime(b), next);
n = 1; rhondas = [];
count = 0;
while(count < nshow,
if(isRhonda(n, b),
rhondas = concat(rhondas, n);
count++;
);
n++;
);
print("First " nshow " Rhondas in base " b ":");
print("In base 10: " rhondas);
basebRhondas = vector(#rhondas, i, (digits(rhondas[i], b)));
print("In base " b ": " basebRhondas);
print("\n");
);
}
 
displayrhondas(2, 16, 15);
</syntaxhighlight>
{{out}}
<pre style="height:40ex;overflow:scroll;">
First 15 Rhondas in base 4:
In base 10: [10206, 11935, 12150, 16031, 45030, 94185, 113022, 114415, 191149, 244713, 259753, 374782, 392121, 503773, 649902]
In base 4: [[2, 1, 3, 3, 1, 3, 2], [2, 3, 2, 2, 1, 3, 3], [2, 3, 3, 1, 3, 1, 2], [3, 3, 2, 2, 1, 3, 3], [2, 2, 3, 3, 3, 2, 1, 2], [1, 1, 2, 3, 3, 3, 2, 2, 1], [1, 2, 3, 2, 1, 1, 3, 3, 2], [1, 2, 3, 3, 2, 3, 2, 3, 3], [2, 3, 2, 2, 2, 2, 2, 3, 1], [3, 2, 3, 2, 3, 3, 2, 2, 1], [3, 3, 3, 1, 2, 2, 2, 2, 1], [1, 1, 2, 3, 1, 3, 3, 3, 3, 2], [1, 1, 3, 3, 2, 3, 2, 3, 2, 1], [1, 3, 2, 2, 3, 3, 3, 1, 3, 1], [2, 1, 3, 2, 2, 2, 2, 2, 3, 2]]
 
 
First 15 Rhondas in base 6:
In base 10: [855, 1029, 3813, 5577, 7040, 7304, 15104, 19136, 35350, 36992, 41031, 42009, 60368, 65536, 67821]
In base 6: [[3, 5, 4, 3], [4, 4, 3, 3], [2, 5, 3, 5, 3], [4, 1, 4, 5, 3], [5, 2, 3, 3, 2], [5, 3, 4, 5, 2], [1, 5, 3, 5, 3, 2], [2, 2, 4, 3, 3, 2], [4, 3, 1, 3, 5, 4], [4, 4, 3, 1, 3, 2], [5, 1, 3, 5, 4, 3], [5, 2, 2, 2, 5, 3], [1, 1, 4, 3, 2, 5, 2], [1, 2, 2, 3, 2, 2, 4], [1, 2, 4, 1, 5, 5, 3]]
 
 
First 15 Rhondas in base 8:
In base 10: [1836, 6318, 6622, 10530, 14500, 14739, 17655, 18550, 25398, 25956, 30562, 39215, 39325, 50875, 51429]
In base 8: [[3, 4, 5, 4], [1, 4, 2, 5, 6], [1, 4, 7, 3, 6], [2, 4, 4, 4, 2], [3, 4, 2, 4, 4], [3, 4, 6, 2, 3], [4, 2, 3, 6, 7], [4, 4, 1, 6, 6], [6, 1, 4, 6, 6], [6, 2, 5, 4, 4], [7, 3, 5, 4, 2], [1, 1, 4, 4, 5, 7], [1, 1, 4, 6, 3, 5], [1, 4, 3, 2, 7, 3], [1, 4, 4, 3, 4, 5]]
 
 
First 15 Rhondas in base 9:
In base 10: [15540, 21054, 25331, 44360, 44660, 44733, 47652, 50560, 54944, 76857, 77142, 83334, 83694, 96448, 97944]
In base 9: [[2, 3, 2, 7, 6], [3, 1, 7, 8, 3], [3, 7, 6, 6, 5], [6, 6, 7, 5, 8], [6, 7, 2, 3, 2], [6, 7, 3, 2, 3], [7, 2, 3, 2, 6], [7, 6, 3, 1, 7], [8, 3, 3, 2, 8], [1, 2, 6, 3, 7, 6], [1, 2, 6, 7, 3, 3], [1, 3, 6, 2, 7, 3], [1, 3, 6, 7, 2, 3], [1, 5, 6, 2, 6, 4], [1, 5, 8, 3, 1, 6]]
 
 
First 15 Rhondas in base 10:
In base 10: [1568, 2835, 4752, 5265, 5439, 5664, 5824, 5832, 8526, 12985, 15625, 15698, 19435, 25284, 25662]
In base 10: [[1, 5, 6, 8], [2, 8, 3, 5], [4, 7, 5, 2], [5, 2, 6, 5], [5, 4, 3, 9], [5, 6, 6, 4], [5, 8, 2, 4], [5, 8, 3, 2], [8, 5, 2, 6], [1, 2, 9, 8, 5], [1, 5, 6, 2, 5], [1, 5, 6, 9, 8], [1, 9, 4, 3, 5], [2, 5, 2, 8, 4], [2, 5, 6, 6, 2]]
 
 
First 15 Rhondas in base 12:
In base 10: [560, 800, 3993, 4425, 4602, 4888, 7315, 8296, 9315, 11849, 12028, 13034, 14828, 15052, 16264]
In base 12: [[3, 10, 8], [5, 6, 8], [2, 3, 8, 9], [2, 6, 8, 9], [2, 7, 11, 6], [2, 9, 11, 4], [4, 2, 9, 7], [4, 9, 7, 4], [5, 4, 8, 3], [6, 10, 3, 5], [6, 11, 6, 4], [7, 6, 6, 2], [8, 6, 11, 8], [8, 8, 6, 4], [9, 4, 11, 4]]
 
 
First 15 Rhondas in base 14:
In base 10: [11475, 18655, 20565, 29631, 31725, 45387, 58404, 58667, 59950, 63945, 67525, 68904, 91245, 99603, 125543]
In base 14: [[4, 2, 7, 9], [6, 11, 2, 7], [7, 6, 12, 13], [10, 11, 2, 7], [11, 7, 12, 1], [1, 2, 7, 7, 13], [1, 7, 3, 13, 10], [1, 7, 5, 4, 7], [1, 7, 11, 12, 2], [1, 9, 4, 3, 7], [1, 10, 8, 7, 3], [1, 11, 1, 7, 10], [2, 5, 3, 7, 7], [2, 8, 4, 2, 7], [3, 3, 10, 7, 5]]
 
 
First 15 Rhondas in base 15:
In base 10: [2392, 2472, 11468, 15873, 17424, 18126, 19152, 20079, 24388, 30758, 31150, 33004, 33550, 37925, 39483]
In base 15: [[10, 9, 7], [10, 14, 12], [3, 5, 14, 8], [4, 10, 8, 3], [5, 2, 6, 9], [5, 5, 8, 6], [5, 10, 1, 12], [5, 14, 3, 9], [7, 3, 5, 13], [9, 1, 10, 8], [9, 3, 6, 10], [9, 11, 10, 4], [9, 14, 1, 10], [11, 3, 8, 5], [11, 10, 7, 3]]
 
 
First 15 Rhondas in base 16:
In base 10: [1000, 1134, 6776, 15912, 19624, 20043, 20355, 23946, 26296, 29070, 31906, 32292, 34236, 34521, 36465]
In base 16: [[3, 14, 8], [4, 6, 14], [1, 10, 7, 8], [3, 14, 2, 8], [4, 12, 10, 8], [4, 14, 4, 11], [4, 15, 8, 3], [5, 13, 8, 10], [6, 6, 11, 8], [7, 1, 8, 14], [7, 12, 10, 2], [7, 14, 2, 4], [8, 5, 11, 12], [8, 6, 13, 9], [8, 14, 7, 1]]
 
 
 
</pre>
 
Line 2,526 ⟶ 2,700:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Math, Int, Nums
import "./fmt" for Fmt, Conv
 
2,122

edits