Rhonda numbers: Difference between revisions

(added Arturo)
Line 1,172:
In base 36: rs 3pc 4di 6bi 8hi 9ks a9g c5i cz9 hrc 13to 14ou 1g9s 1iq9 1lw6
 
</pre>
 
=={{header|jq}}==
'''Works with jq and gojq, that is, the C and Go implementations of jq.'''
 
'''Adapted from [[#Wren|Wren]]'''
 
'''Generic stream-oriented utility functions'''
<syntaxhighlight lang=jq>
def prod(s): reduce s as $_ (1; . * $_);
 
def sigma(s): reduce s as $_ (0; . + $_);
 
# If s is a stream of JSON entities that does not include null, butlast(s) emits all but the last.
def butlast(s):
label $out
| foreach (s,null) as $x ({};
if $x == null then break $out else .emit = .prev | .prev = $x end)
| select(.emit).emit;
 
def multiple(s):
first(foreach s as $x (0; .+1; select(. > 1))) // false;
 
# From: rc-prime-decomposition.jq
# Output: a stream of the prime factors of the input
# e.g.
# 2 | factors #=> 2
# 24 | factors #=> 2 2 2 3
def factors:
. as $in
| [2, $in, false]
| recurse(
. as [$p, $q, $valid, $s]
| if $q == 1 then empty
elif $q % $p == 0 then [$p, $q/$p, true]
elif $p == 2 then [3, $q, false, $s]
else ($s // ($q | sqrt)) as $s
| if $p + 2 <= $s then [$p + 2, $q, false, $s]
else [$q, 1, true]
end
end )
| if .[2] then .[0] else empty end ;
</syntaxhighlight>
'''Other generic functions'''
<syntaxhighlight lang=jq>
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
def is_prime:
multiple(factors) | not;
def tobase($b):
def digit: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[.:.+1];
def mod: . % $b;
def div: ((. - mod) / $b);
def digits: recurse( select(. > 0) | div) | mod ;
# For jq it would be wise to protect against `infinite` as input, but using `isinfinite` confuses gojq
select( (tostring|test("^[0-9]+$")) and 2 <= $b and $b <= 36)
| if . == 0 then "0"
else [digits | digit] | reverse[1:] | add
end;
 
# emit the decimal values of the "digits"
def digits($b):
def mod: . % $b;
def div: ((. - mod) / $b);
butlast(recurse( select(. > 0) | div) | mod) ;
</syntaxhighlight>
'''Rhonda numbers'''
<syntaxhighlight lang=jq>
# Emit a stream of Rhonda numbers in the given base
def rhondas($b):
range(1; infinite) as $n
| ($n | [digits($b)]) as $digits
| select($digits|index(0)|not)
| select(($b != 10) or (($digits|index(5)) and ($digits | any(. % 2 == 0))))
| select(prod($digits[]) == ($b * sigma($n | factors)))
| $n ;
</syntaxhighlight>
'''The task'''
<syntaxhighlight lang=jq>
def task($count):
range (2; 37) as $b
| select( $b | is_prime | not)
| [ limit($count; rhondas($b)) ]
| select(length > 0)
|"First \($count) Rhonda numbers in base \($b):",
( (map(tostring)) as $rhonda2
| (map(tobase($b))) as $rhonda3
| (($rhonda2|map(length)) | max) as $maxLen2
| (($rhonda3|map(length)) | max) as $maxLen3
| ( ([$maxLen2, $maxLen3]|max) + 1) as $maxLen
| "In base 10: \($rhonda2 | map(lpad($maxLen)) | join(" ") )",
"In base \($b|lpad(2)): \($rhonda3 | map(lpad($maxLen)) | join(" ") )",
"") ;
 
task(10)
</syntaxhighlight>
{{output}}
<pre>
First 10 Rhonda numbers in base 4:
In base 10: 10206 11935 12150 16031 45030 94185 113022 114415 191149 244713
In base 4: 2133132 2322133 2331312 3322133 22333212 112333221 123211332 123323233 232222231 323233221
 
First 10 Rhonda numbers in base 6:
In base 10: 855 1029 3813 5577 7040 7304 15104 19136 35350 36992
In base 6: 3543 4433 25353 41453 52332 53452 153532 224332 431354 443132
 
First 10 Rhonda numbers in base 8:
In base 10: 1836 6318 6622 10530 14500 14739 17655 18550 25398 25956
In base 8: 3454 14256 14736 24442 34244 34623 42367 44166 61466 62544
 
First 10 Rhonda numbers in base 9:
In base 10: 15540 21054 25331 44360 44660 44733 47652 50560 54944 76857
In base 9: 23276 31783 37665 66758 67232 67323 72326 76317 83328 126376
 
First 10 Rhonda numbers in base 10:
In base 10: 1568 2835 4752 5265 5439 5664 5824 5832 8526 12985
In base 10: 1568 2835 4752 5265 5439 5664 5824 5832 8526 12985
 
First 10 Rhonda numbers in base 12:
In base 10: 560 800 3993 4425 4602 4888 7315 8296 9315 11849
In base 12: 3A8 568 2389 2689 27B6 29B4 4297 4974 5483 6A35
 
First 10 Rhonda numbers in base 14:
In base 10: 11475 18655 20565 29631 31725 45387 58404 58667 59950 63945
In base 14: 4279 6B27 76CD AB27 B7C1 1277D 173DA 17547 17BC2 19437
 
First 10 Rhonda numbers in base 15:
In base 10: 2392 2472 11468 15873 17424 18126 19152 20079 24388 30758
In base 15: A97 AEC 35E8 4A83 5269 5586 5A1C 5E39 735D 91A8
 
First 10 Rhonda numbers in base 16:
In base 10: 1000 1134 6776 15912 19624 20043 20355 23946 26296 29070
In base 16: 3E8 46E 1A78 3E28 4CA8 4E4B 4F83 5D8A 66B8 718E
 
First 10 Rhonda numbers in base 18:
In base 10: 1470 3000 8918 17025 19402 20650 21120 22156 26522 36549
In base 18: 49C 94C 1998 2G9F 35FG 39D4 3B36 3E6G 49F8 64E9
 
First 10 Rhonda numbers in base 20:
In base 10: 1815 11050 15295 21165 22165 30702 34510 34645 42292 44165
In base 20: 4AF 17CA 1I4F 2CI5 2F85 3GF2 465A 46C5 55EC 5A85
 
First 10 Rhonda numbers in base 21:
In base 10: 1632 5390 8512 12992 15678 25038 29412 34017 39552 48895
In base 21: 3EF C4E J67 189E 1EBC 2EG6 33EC 3E2I 45E9 55I7
 
First 10 Rhonda numbers in base 22:
In base 10: 2695 4128 7865 28800 31710 37030 71875 74306 117760 117895
In base 22: 5CB 8BE G5B 2FB2 2LB8 3AB4 6GB1 6LBC B16G B1CJ
 
First 10 Rhonda numbers in base 24:
In base 10: 2080 2709 3976 5628 5656 7144 8296 9030 10094 17612
In base 24: 3EG 4GL 6LG 9IC 9JG C9G E9G FG6 HCE 16DK
 
First 10 Rhonda numbers in base 25:
In base 10: 6764 9633 13260 22022 53382 57640 66015 69006 97014 140130
In base 25: AKE FA8 L5A 1A5M 3AA7 3H5F 45FF 4AA6 655E 8O55
 
First 10 Rhonda numbers in base 26:
In base 10: 7788 9322 9374 11160 22165 27885 34905 44785 47385 49257
In base 26: BDE DKE DME GD6 16KD 1F6D 1PGD 2E6D 2I2D 2KMD
 
First 10 Rhonda numbers in base 27:
In base 10: 4797 11844 12078 13200 14841 17750 24320 26883 27477 46455
In base 27: 6FI G6I GF9 I2O K9I O9B 169K 19NI 1AII 29JF
 
First 10 Rhonda numbers in base 28:
In base 10: 3094 5808 5832 7462 11160 13671 27270 28194 28638 39375
In base 28: 3QE 7BC 7C8 9EE E6G HC7 16LQ 17QQ 18EM 1M67
 
First 10 Rhonda numbers in base 30:
In base 10: 3024 3168 5115 5346 5950 6762 7750 7956 8470 9476
In base 30: 3AO 3FI 5KF 5S6 6IA 7FC 8IA 8P6 9CA AFQ
 
First 10 Rhonda numbers in base 32:
In base 10: 1944 3600 13520 15876 16732 16849 25410 25752 28951 47472
In base 32: 1SO 3GG D6G FG4 GAS GEH OQ2 P4O S8N 1EBG
 
First 10 Rhonda numbers in base 33:
In base 10: 756 7040 7568 13826 24930 30613 59345 63555 64372 131427
In base 33: MU 6FB 6VB CMW MTF S3M 1LGB 1PBU 1Q3M 3LML
 
First 10 Rhonda numbers in base 34:
In base 10: 5661 14161 15620 16473 22185 37145 125579 134692 135405 138472
In base 34: 4UH C8H DHE E8H J6H W4H 36LH 3EHI 3F4H 3HQO
 
First 10 Rhonda numbers in base 35:
In base 10: 8232 9476 9633 18634 30954 41905 52215 52440 56889 61992
In base 35: 6P7 7PQ 7U8 F7E P9E Y7A 17LU 17SA 1BFE 1FL7
 
First 10 Rhonda numbers in base 36:
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>
 
2,442

edits