Numbers with same digit set in base 10 and base 16: Difference between revisions

m (forgot lang attribute)
Line 804:
(98711, 18197)
(99481, 18499)</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''.
 
'''Also works with fq, a Go implementation of a large subset of jq'''
<syntaxhighlight lang=jq>
# The def of _nwise/1 is included here in case gojq or fq is used.
def _nwise($n):
def nw: if length <= $n then . else .[0:$n] , (.[$n:] | nw) end;
nw;
 
def chars: explode[] | [.] | implode;
 
# decimal number to hex string using lower-case letters
def hex:
def stream:
recurse(if . > 0 then ./16|floor else empty end) | . % 16 ;
if . == 0 then "0"
else [stream] | reverse | .[1:]
| map(if . < 10 then 48 + . else . + 87 end) | implode
end;
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
# Emit a stream of same-digit numbers, up to .
def sameDigitSettasktask:
def u: [tostring|chars] | unique;
range(0; .) | select((hex|u) == u);
# The task
1e5
| "Numbers under \(.) which use the same digits in decimal as in hex:",
( [sameDigitSettasktask]
| map(lpad(6))
| ((_nwise(10) | join(" ")),
"\n\(length) such numbers found." ) )
</syntaxhighlight>
{{output}}
<pre>
Numbers under 100000 which use the same digits in decimal as in hex:
0 1 2 3 4 5 6 7 8 9
53 371 913 1040 2080 2339 4100 5141 5412 5441
6182 8200 9241 13593 13665 13969 16406 20530 26946 30979
32803 33638 33840 33841 33842 33843 33844 33845 33846 33847
33848 33849 34883 37943 38931 38966 38995 66310 71444 71497
71511 75120 75121 75122 75123 75124 75125 75126 75127 75128
75129 75621 86150 88165 91465 91769 96617 98711 99481
 
69 such numbers found.
</pre>
 
=={{header|Julia}}==
2,451

edits