Rhonda numbers: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 49: Line 49:


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <algorithm>
<syntaxhighlight lang="cpp">#include <algorithm>
#include <cassert>
#include <cassert>
#include <iomanip>
#include <iomanip>
Line 124: Line 124:
std::cout << "\n\n";
std::cout << "\n\n";
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 228: Line 228:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
{{works with|Factor|0.99 2022-04-03}}
<lang factor>USING: formatting grouping io kernel lists lists.lazy math
<syntaxhighlight lang="factor">USING: formatting grouping io kernel lists lists.lazy math
math.parser math.primes math.primes.factors prettyprint ranges
math.parser math.primes math.primes.factors prettyprint ranges
sequences sequences.extras ;
sequences sequences.extras ;
Line 246: Line 246:
base "In base %d: " printf r base list. ;
base "In base %d: " printf r base list. ;


2 36 [a..b] [ prime? not ] filter [ rhonda. nl ] each</lang>
2 36 [a..b] [ prime? not ] filter [ rhonda. nl ] each</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:40ex">
<pre style="height:40ex">
Line 349: Line 349:
{{trans|Wren}}
{{trans|Wren}}
{{libheader|Go-rcu}}
{{libheader|Go-rcu}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 421: Line 421:
}
}
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 524: Line 524:
=={{header|J}}==
=={{header|J}}==


<lang J>tobase=: (a.{~;48 97(+ i.)each 10 26) {~ #.inv
<syntaxhighlight lang="j">tobase=: (a.{~;48 97(+ i.)each 10 26) {~ #.inv
isrhonda=: (*/@:(#.inv) = (* +/@q:))"0
isrhonda=: (*/@:(#.inv) = (* +/@q:))"0


Line 543: Line 543:


task''
task''
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre style="height:40ex;overflow:scroll;">
<pre style="height:40ex;overflow:scroll;">
Line 644: Line 644:


=={{header|Java}}==
=={{header|Java}}==
<lang java>public class RhondaNumbers {
<syntaxhighlight lang="java">public class RhondaNumbers {
public static void main(String[] args) {
public static void main(String[] args) {
final int limit = 15;
final int limit = 15;
Line 705: Line 705:
return digitProduct(base, n) == base * primeFactorSum(n);
return digitProduct(base, n) == base * primeFactorSum(n);
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 808: Line 808:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Primes
<syntaxhighlight lang="julia">using Primes


isRhonda(n, b) = prod(digits(n, base=b)) == b * sum([prod(pair) for pair in factor(n).pe])
isRhonda(n, b) = prod(digits(n, base=b)) == b * sum([prod(pair) for pair in factor(n).pe])
Line 826: Line 826:


displayrhondas(2, 16, 15)
displayrhondas(2, 16, 15)
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre style="height:40ex;overflow:scroll;">
<pre style="height:40ex;overflow:scroll;">
First 15 Rhondas in base 4:
First 15 Rhondas in base 4:
Line 866: Line 866:


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>ClearAll[RhondaNumberQ]
<syntaxhighlight lang="mathematica">ClearAll[RhondaNumberQ]
RhondaNumberQ[b_Integer][n_Integer] := Module[{l, r},
RhondaNumberQ[b_Integer][n_Integer] := Module[{l, r},
l = Times @@ IntegerDigits[n, b];
l = Times @@ IntegerDigits[n, b];
Line 877: Line 877:
,
,
{b, bases}
{b, bases}
]</lang>
]</syntaxhighlight>
{{out}}
{{out}}
<pre>base 4:{10206,11935,12150,16031,45030,94185,113022,114415,191149,244713,259753,374782,392121,503773,649902}
<pre>base 4:{10206,11935,12150,16031,45030,94185,113022,114415,191149,244713,259753,374782,392121,503773,649902}
Line 906: Line 906:
=={{header|Perl}}==
=={{header|Perl}}==
{{libheader|ntheory}}
{{libheader|ntheory}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;
use feature 'say';
use feature 'say';
Line 928: Line 928:
EOT
EOT
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre style="height:20ex">First 15 Rhonda numbers to base 4:
<pre style="height:20ex">First 15 Rhonda numbers to base 4:
Line 1,027: Line 1,027:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
<span style="color: #008080;">constant</span> <span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
Line 1,060: Line 1,060:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre style="height:40ex;overflow:scroll;">
<pre style="height:40ex;overflow:scroll;">
Line 1,162: Line 1,162:
=={{header|Raku}}==
=={{header|Raku}}==
Find and show the first 15 so as to display the namesake Rhonda number 25662.
Find and show the first 15 so as to display the namesake Rhonda number 25662.
<lang perl6>use Prime::Factor;
<syntaxhighlight lang="raku" line>use Prime::Factor;


my @factor-sum;
my @factor-sum;
Line 1,178: Line 1,178:
put "In base 10: " ~ @rhonda».fmt("%{$ch}s").join: ', ';
put "In base 10: " ~ @rhonda».fmt("%{$ch}s").join: ', ';
put $b.fmt("In base %2d: ") ~ @rhonda».base($b)».fmt("%{$ch}s").join: ', ';
put $b.fmt("In base %2d: ") ~ @rhonda».base($b)».fmt("%{$ch}s").join: ', ';
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:40ex;overflow:scroll;">First 15 Rhonda numbers to base 4:
<pre style="height:40ex;overflow:scroll;">First 15 Rhonda numbers to base 4:
Line 1,277: Line 1,277:


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>// [dependencies]
<syntaxhighlight lang="rust">// [dependencies]
// radix_fmt = "1.0"
// radix_fmt = "1.0"


Line 1,355: Line 1,355:
print!("\n\n");
print!("\n\n");
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,458: Line 1,458:


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>func is_rhonda_number(n, base = 10) {
<syntaxhighlight lang="ruby">func is_rhonda_number(n, base = 10) {
base.is_composite || return false
base.is_composite || return false
n > 0 || return false
n > 0 || return false
Line 1,467: Line 1,467:
say ("First 10 Rhonda numbers to base #{b}: ",
say ("First 10 Rhonda numbers to base #{b}: ",
10.by { is_rhonda_number(_, b) })
10.by { is_rhonda_number(_, b) })
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,482: Line 1,482:


=={{header|Swift}}==
=={{header|Swift}}==
<lang swift>func digitProduct(base: Int, num: Int) -> Int {
<syntaxhighlight lang="swift">func digitProduct(base: Int, num: Int) -> Int {
var product = 1
var product = 1
var n = num
var n = num
Line 1,557: Line 1,557:
}
}
print("\n")
print("\n")
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,662: Line 1,662:
{{libheader|Wren-math}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "./math" for Math, Int, Nums
<syntaxhighlight lang="ecmascript">import "./math" for Math, Int, Nums
import "./fmt" for Fmt, Conv
import "./fmt" for Fmt, Conv


Line 1,694: Line 1,694:
Fmt.print("In base $-2d: $*s", b, maxLen, rhonda3)
Fmt.print("In base $-2d: $*s", b, maxLen, rhonda3)
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}