Numbers with same digit set in base 10 and base 16: Difference between revisions
Content deleted Content added
Added Sidef |
|||
(33 intermediate revisions by 18 users not shown) | |||
Line 10:
The set of digits used, ignoring order and duplicates, is '''{2, 3, 9}''' in both cases and hence this number satisfies the task requirements.
<br><br>
=={{header|11l}}==
{{trans|Python}}
<syntaxhighlight lang="11l">V col = 0
L(i) 100000
I Set(Array(String(i))) == Set(Array(hex(i)))
col++
print(‘#7’.format(i), end' "\n"[0 .< Int(col % 10 == 0)])
print()</syntaxhighlight>
{{out}}
<pre>
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
</pre>
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO RETURN base digitset n:
PUT {} IN set
WHILE n>0:
PUT n mod base IN digit
IF digit not.in set: INSERT digit IN set
PUT floor(n/base) IN n
RETURN set
PUT 0 IN col
FOR n IN {0..100000}:
IF 10 digitset n = 16 digitset n:
WRITE n>>8
PUT col+1 IN col
IF col mod 10 = 0: WRITE /</syntaxhighlight>
{{out}}
<pre> 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</pre>
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_Io;
procedure Same_Digits is
Columns : constant := 10;
Width : constant := 8;
type Set_Type is array (0 .. 15) of Boolean;
function Digit_Set_Of (N : Natural; Base : Natural) return Set_Type is
Nn : Natural := N;
Set : Set_Type := (others => False);
begin
while Nn /= 0 loop
Set (Nn mod Base) := True;
Nn := Nn / Base;
end loop;
return Set;
end Digit_Set_Of;
package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
use Ada.Text_Io, Natural_Io;
Count : Natural := 0;
begin
for N in 0 .. 99_999 loop
if Digit_Set_Of (N, Base => 10) = Digit_Set_Of (N, Base => 16) then
Count := Count + 1;
Put (N, Width => Width);
if Count mod Columns = 0 then
New_Line;
end if;
end if;
end loop;
New_Line;
Put ("Total numbers: "); Put (Count, Width => 3); New_Line;
end Same_Digits;</syntaxhighlight>
{{out}}
<pre>
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
Total numbers: 69
</pre>
=={{header|ALGOL W}}==
Generates the candidate numbers (ones that only have the digits 0-9 in their hexadecimal representation) to cut down the numbers to check.
<
integer hdCount, h20, h300, h4000, h50000;
logical array hex, dec ( 0 :: 9 );
Line 74 ⟶ 168:
, "representations use the same digits"
);
end.</
{{out}}
<pre>
Line 90 ⟶ 184:
=={{header|APL}}==
{{works with|Dyalog APL}}
<
{{out}}
<pre>0 1 2 3 4 5 6 7 8 9 53 371 913 1040 2080 2339 4100 5141 5412 5441 6182
Line 100 ⟶ 194:
=={{header|AppleScript}}==
<
use sorter : script "Insertion sort" -- <https://www.rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#AppleScript>
Line 133 ⟶ 227:
if (sameDigitSetDecHex(n)) then set end of output to n
end repeat
return output</
{{output}}
<
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">valid?: function [n][
equal? sort unique digits n
sort unique digits.base:16 n
]
print select 0..100000 => valid?</syntaxhighlight>
{{out}}
<pre>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</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f DECIMAL_-_HEXADECIMAL_NUMBERS.AWK
BEGIN {
Line 168 ⟶ 275:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 182 ⟶ 289:
=={{header|C}}==
<
#define LIMIT 100000
Line 199 ⟶ 306:
printf("\n");
return 0;
}</
{{out}}
<pre> 0 1 2 3 4 5 6 7 8 9
Line 210 ⟶ 317:
=={{header|C++}}==
<
#include <iomanip>
#include <bitset>
Line 232 ⟶ 339:
std::cout << std::endl;
return 0;
}</
{{out}}
<pre> 0 1 2 3 4 5 6 7 8 9
Line 243 ⟶ 350:
=={{header|Cowgol}}==
<
const LIMIT := 100000;
Line 271 ⟶ 378:
i := i + 1;
end loop;
print_nl();</
{{out}}
<pre>0 1 2 3 4 5 6 7 8 9
Line 280 ⟶ 387:
71511 75120 75121 75122 75123 75124 75125 75126 75127 75128
75129 75621 86150 88165 91465 91769 96617 98711 99481</pre>
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec digitset(ulong n; byte b) word:
word set;
set := 0;
while n ~= 0 do
set := set | 1 << make(n % b, byte);
n := n / b
od;
set
corp
proc nonrec main() void:
ulong MAX = 100000;
ulong n;
byte col;
n := 0;
col := 0;
while n<MAX do
if digitset(n,10) = digitset(n,16) then
write(n:8);
col := col + 1;
if col % 10 = 0 then writeln() fi
fi;
n := n + 1;
od;
writeln()
corp</syntaxhighlight>
{{out}}
<pre> 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</pre>
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
function HasSameDigits1016(N: integer): boolean;
{Return true if base-10 string and base-16 string have same characters}
var S10,S16: string;
var I: integer;
begin
Result:=False;
{Get base-10 and -16 string}
S10:=IntToStr(N);
S16:=Format('%x',[N]);
{Compare S10 to S16}
for I:=1 to Length(S10) do
if Pos(S10[I],S16)=0 then exit;
{Compare S16 to S10}
for I:=1 to Length(S16) do
if Pos(S16[I],S10)=0 then exit;
Result:=True;
end;
procedure ShowSameDigits1016(Memo: TMemo);
var I,Cnt: integer;
var S: string;
begin
Cnt:=0;
for I:=0 to 100000-1 do
if HasSameDigits1016(I) then
begin
Inc(Cnt);
S:=S+Format('%8D',[I]);
If (Cnt mod 5)=0 then S:=S+CRLF;
end;
Memo.Lines.Add(S);
Memo.Lines.Add('Count='+IntToStr(Cnt));
end;
</syntaxhighlight>
{{out}}
<pre>
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
Count=69
Elapsed Time: 41.373 ms.
</pre>
=={{header|EasyLang}}==
<syntaxhighlight lang=text>
func digset n b .
while n > 0
h = bitshift 1 (n mod b)
set = bitor set h
n = n div b
.
return set
.
for i = 0 to 100000 - 1
if digset i 10 = digset i 16
write i & " "
.
.
</syntaxhighlight>
{{out}}
<pre>
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
</pre>
=={{header|F_Sharp|F#}}==
<
// Decimal-Hexdecimal: Nigel Galloway. June 7th., 2021
let rec fN g=function n when n<10->Some(Set.add n g)|n when n%16<10->fN(g.Add(n%16))(n/16) |_->None
let rec fG n g=match n/10,n%10 with (0,n)->Some(Set.add n g)|(n,i)->fG n (Set.add i g)
let g=Set.empty in seq{0..100000}|>Seq.filter(fun n->fN g n=fG n g)|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
{{out}}
<pre>
Line 295 ⟶ 524:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<
sequences sets ;
100,000 <iota> [ dup present swap >hex set= ] filter
10 group [ [ "%5d " printf ] each nl ] each</
{{out}}
<pre>
Line 309 ⟶ 538:
71511 75120 75121 75122 75123 75124 75125 75126 75127 75128
75129 75621 86150 88165 91465 91769 96617 98711 99481
</pre>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">function is_sds( byval n as integer ) as boolean
dim as boolean in_dec(0 to 9), in_hex(0 to 9)
dim as integer nd = n, dh
while nd
in_dec( nd mod 10 ) = true
nd \= 10
wend
while n
dh = n mod 16
if dh > 9 then return false
in_hex( dh ) = true
n \= 16
wend
for i as uinteger = 0 to 9
if in_dec(i) <> in_hex(i) then return false
next i
return true
end function
dim as integer i, c=0
for i = 0 to 99999
if is_sds(i) then
print using "##### ";i;
c+=1
if c mod 10 = 0 then print
end if
next i</syntaxhighlight>
{{out}}<pre> 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
</pre>
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 357 ⟶ 624:
}
fmt.Printf("\n\n%d such numbers found.\n", count)
}</
{{out}}
Line 369 ⟶ 636:
71,511 75,120 75,121 75,122 75,123 75,124 75,125 75,126 75,127 75,128
75,129 75,621 86,150 88,165 91,465 91,769 96,617 98,711 99,481
69 such numbers found.
</pre>
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import qualified Data.Set as S
import Numeric (showHex)
---- NUMBERS WITH THE SAME DIGIT SET IN DECIMAL AND HEX --
sameDigitSet :: (Integral a, Show a) => a -> [(a, String)]
sameDigitSet n =
[ (n, h)
| let h = showHex n "",
S.fromList h == S.fromList (show n)
]
--------------------------- TEST -------------------------
main = do
print ("decimal", "hex")
mapM_ print $ [0 .. 100000] >>= sameDigitSet</syntaxhighlight>
{{Out}}
<pre>("decimal","hex")
(0,"0")
(1,"1")
(2,"2")
(3,"3")
(4,"4")
(5,"5")
(6,"6")
(7,"7")
(8,"8")
(9,"9")
(53,"35")
(371,"173")
(913,"391")
(1040,"410")
(2080,"820")
(2339,"923")
(4100,"1004")
(5141,"1415")
(5412,"1524")
(5441,"1541")
(6182,"1826")
(8200,"2008")
(9241,"2419")
(13593,"3519")
(13665,"3561")
(13969,"3691")
(16406,"4016")
(20530,"5032")
(26946,"6942")
(30979,"7903")
(32803,"8023")
(33638,"8366")
(33840,"8430")
(33841,"8431")
(33842,"8432")
(33843,"8433")
(33844,"8434")
(33845,"8435")
(33846,"8436")
(33847,"8437")
(33848,"8438")
(33849,"8439")
(34883,"8843")
(37943,"9437")
(38931,"9813")
(38966,"9836")
(38995,"9853")
(66310,"10306")
(71444,"11714")
(71497,"11749")
(71511,"11757")
(75120,"12570")
(75121,"12571")
(75122,"12572")
(75123,"12573")
(75124,"12574")
(75125,"12575")
(75126,"12576")
(75127,"12577")
(75128,"12578")
(75129,"12579")
(75621,"12765")
(86150,"15086")
(88165,"15865")
(91465,"16549")
(91769,"16679")
(96617,"17969")
(98711,"18197")
(99481,"18499")</pre>
=={{header|J}}==
Decimal numbers on left:<syntaxhighlight lang="j"> require'convert'
(":,.' ',.;@hfd"1),.I.(": -:&~.&(/:~) hfd)"0 i.1e5
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
53 35
371 173
913 391
1040 410
2080 820
2339 923
4100 1004
5141 1415
5412 1524
5441 1541
6182 1826
8200 2008
9241 2419
13593 3519
13665 3561
13969 3691
16406 4016
20530 5032
26946 6942
30979 7903
32803 8023
33638 8366
33840 8430
33841 8431
33842 8432
33843 8433
33844 8434
33845 8435
33846 8436
33847 8437
33848 8438
33849 8439
34883 8843
37943 9437
38931 9813
38966 9836
38995 9853
66310 10306
71444 11714
71497 11749
71511 11757
75120 12570
75121 12571
75122 12572
75123 12573
75124 12574
75125 12575
75126 12576
75127 12577
75128 12578
75129 12579
75621 12765
86150 15086
88165 15865
91465 16549
91769 16679
96617 17969
98711 18197
99481 18499</syntaxhighlight>
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">(() => {
"use strict";
const main = () => [
"(dec, hex)",
...enumFromTo(1)(100000).flatMap(n => {
const
d = n.toString(10),
h = n.toString(16);
return eqSet(new Set(d))(
new Set(h)
) ? [
`(${d}, ${h})`
] : [];
})
].join("\n");
// --------------------- GENERIC ---------------------
// enumFromTo :: Int -> Int -> [Int]
const enumFromTo = m =>
n => Array.from({
length: 1 + n - m
}, (_, i) => m + i);
// eqSet :: Set a -> Set a -> Bool
const eqSet = a =>
// True if the two sets have
// the same size and members.
b => a.size === b.size && (
Array.from(a).every(x => b.has(x))
);
// MAIN ---
return main();
})();</syntaxhighlight>
{{Out}}
<pre>(dec, hex)
(1, 1)
(2, 2)
(3, 3)
(4, 4)
(5, 5)
(6, 6)
(7, 7)
(8, 8)
(9, 9)
(53, 35)
(371, 173)
(913, 391)
(1040, 410)
(2080, 820)
(2339, 923)
(4100, 1004)
(5141, 1415)
(5412, 1524)
(5441, 1541)
(6182, 1826)
(8200, 2008)
(9241, 2419)
(13593, 3519)
(13665, 3561)
(13969, 3691)
(16406, 4016)
(20530, 5032)
(26946, 6942)
(30979, 7903)
(32803, 8023)
(33638, 8366)
(33840, 8430)
(33841, 8431)
(33842, 8432)
(33843, 8433)
(33844, 8434)
(33845, 8435)
(33846, 8436)
(33847, 8437)
(33848, 8438)
(33849, 8439)
(34883, 8843)
(37943, 9437)
(38931, 9813)
(38966, 9836)
(38995, 9853)
(66310, 10306)
(71444, 11714)
(71497, 11749)
(71511, 11757)
(75120, 12570)
(75121, 12571)
(75122, 12572)
(75123, 12573)
(75124, 12574)
(75125, 12575)
(75126, 12576)
(75127, 12577)
(75128, 12578)
(75129, 12579)
(75621, 12765)
(86150, 15086)
(88165, 15865)
(91465, 16549)
(91769, 16679)
(96617, 17969)
(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.
Line 374 ⟶ 966:
=={{header|Julia}}==
<
foreach(p -> print(rpad(p[2], 6), p[1] % 10 == 0 ? "\n" : ""), enumerate(dhstring(100000)))
</
<pre>
0 1 2 3 4 5 6 7 8 9
Line 386 ⟶ 978:
71511 75120 75121 75122 75123 75124 75125 75126 75127 75128
75129 75621 86150 88165 91465 91769 96617 98711 99481
</pre>
=={{header|langur}}==
{{trans|Python}}
<syntaxhighlight lang="langur">
# using hash keys to create a pseudo-set
val makeset = fn n:foldfrom(fn h, v: h ~ {v: 0}, {:}, split(n))
var col = 1
for n in 0..99999 {
if makeset(n) == makeset(string(n, 16)) {
write "{{n:7}}"
if col div 10: writeln()
col += 1
}
}
writeln()
</syntaxhighlight>
{{out}}
<pre> 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
</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">ClearAll[Base1016SameDigitsQ]
Base1016SameDigitsQ[n_Integer] := Module[{id10, id16},
id10 = Union[IntegerDigits[n, 10]];
id16 = Union[IntegerDigits[n, 16]];
id10 === id16
]
Multicolumn[Select[Range[0, 10^5 - 1], Base1016SameDigitsQ], Appearance -> "Horizontal"]</syntaxhighlight>
{{out}}
<pre>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
</pre>
Line 391 ⟶ 1,030:
There are many ways to find the numbers. We chose to build directly the set of digits in base 10 and base 16 rather than using the string representations (more code but more efficient).
<
const Lim = 99_999
Line 415 ⟶ 1,054:
for i, n in list:
stdout.write ($n).align(5), if (i + 1) mod 10 == 0: '\n' else: ' '
echo()</
{{out}}
Line 426 ⟶ 1,065:
71511 75120 75121 75122 75123 75124 75125 75126 75127 75128
75129 75621 86150 88165 91465 91769 96617 98711 99481 </pre>
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">module CSet = Set.Make(struct
type t = char
let compare = compare
end)
let str2cset str = CSet.add_seq (String.to_seq str) CSet.empty
let has_same_digits n =
let deci = Format.sprintf "%d" n in
let hexa = Format.sprintf "%x" n in
(* Don't use '=' to compare sets, it only returns true
for sets that are structurally the same, (same elements added in same order)
use CSet.equal to check they have the same elements *)
CSet.equal (str2cset deci) (str2cset hexa)
let rec list_similar ?(acc=[]) n =
if n < 0 then acc
else if has_same_digits n then list_similar ~acc:(n::acc) (n-1)
else list_similar ~acc (n-1)
let () =
let same_digits = list_similar 100_000 in
List.iteri (fun i x ->
Format.printf "%6d:%#8x%s" x x (if i mod 6 = 5 then "\n" else " ")) same_digits;
print_newline ()</syntaxhighlight>
{{out}}
<pre> 0: 0 1: 0x1 2: 0x2 3: 0x3 4: 0x4 5: 0x5
6: 0x6 7: 0x7 8: 0x8 9: 0x9 53: 0x35 371: 0x173
913: 0x391 1040: 0x410 2080: 0x820 2339: 0x923 4100: 0x1004 5141: 0x1415
5412: 0x1524 5441: 0x1541 6182: 0x1826 8200: 0x2008 9241: 0x2419 13593: 0x3519
13665: 0x3561 13969: 0x3691 16406: 0x4016 20530: 0x5032 26946: 0x6942 30979: 0x7903
32803: 0x8023 33638: 0x8366 33840: 0x8430 33841: 0x8431 33842: 0x8432 33843: 0x8433
33844: 0x8434 33845: 0x8435 33846: 0x8436 33847: 0x8437 33848: 0x8438 33849: 0x8439
34883: 0x8843 37943: 0x9437 38931: 0x9813 38966: 0x9836 38995: 0x9853 66310: 0x10306
71444: 0x11714 71497: 0x11749 71511: 0x11757 75120: 0x12570 75121: 0x12571 75122: 0x12572
75123: 0x12573 75124: 0x12574 75125: 0x12575 75126: 0x12576 75127: 0x12577 75128: 0x12578
75129: 0x12579 75621: 0x12765 86150: 0x15086 88165: 0x15865 91465: 0x16549 91769: 0x16679
96617: 0x17969 98711: 0x18197 99481: 0x18499 </pre>
=={{header|Pascal}}==
simply adding 1 to a number and convert as if hex digits.
<
{$IFDEF FPC}
{$MODE DELPHI} {$OPTIMIZATION ON,ALL} {$COPERATORS ON}
Line 522 ⟶ 1,203:
writeln('count : ',count);
END.
</syntaxhighlight>
{{out}}
<pre>TIO.RUN
Line 549 ⟶ 1,230:
=={{header|Perl}}==
<
no warnings;
use feature 'say';
sub eqv { (join '', sort split '', $_[0]) eq (join '', sort split '', $_[1]) }
say join ' ', grep { eqv $_, sprintf '%x', $_ } 1..100_000;</
{{out}}
<pre>1 2 3 4 5 6 7 8 9 53 371 913 4100 5141 5412 6182 8200 9241 75120 75121 75122 75123 75124 75125 75126 75127 75128 75129 75621 86150 91465 98711 99481</pre>
=={{header|Phix}}==
<!--<
<span style="color: #008080;">function</span> <span style="color: #000000;">handusc</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">unique</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%x"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">))=</span><span style="color: #7060A8;">unique</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">))</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">100000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">),</span><span style="color: #000000;">handusc</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"found"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
<pre>
Line 570 ⟶ 1,251:
=={{header|Python}}==
===Procedural===
<
for i in range(100000):
if set(str(i)) == set(hex(i)[2:]):
col += 1
print("{:7}".format(i), end='\n'[:col % 10 == 0])
print()</
{{out}}
<pre> 0 1 2 3 4 5 6 7 8 9
Line 586 ⟶ 1,267:
===Functional===
<
Line 641 ⟶ 1,322:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre> 0 1 2 3 4 5 6 7 8 9
Line 650 ⟶ 1,331:
71511 75120 75121 75122 75123 75124 75125 75126 75127 75128
75129 75621 86150 88165 91465 91769 96617 98711 99481</pre>
or in terms of a list comprehension:
<syntaxhighlight lang="python">for nh in ([
(n, h) for n in range(0, 1 + 100000)
if (
(h := hex(n)[2:])
and set(str(n)) == set(h)
)
]):
print(nh)</syntaxhighlight>
<pre>(0, '0')
(1, '1')
(2, '2')
(3, '3')
(4, '4')
(5, '5')
(6, '6')
(7, '7')
(8, '8')
(9, '9')
(53, '35')
(371, '173')
(913, '391')
(1040, '410')
(2080, '820')
(2339, '923')
(4100, '1004')
(5141, '1415')
(5412, '1524')
(5441, '1541')
(6182, '1826')
(8200, '2008')
(9241, '2419')
(13593, '3519')
(13665, '3561')
(13969, '3691')
(16406, '4016')
(20530, '5032')
(26946, '6942')
(30979, '7903')
(32803, '8023')
(33638, '8366')
(33840, '8430')
(33841, '8431')
(33842, '8432')
(33843, '8433')
(33844, '8434')
(33845, '8435')
(33846, '8436')
(33847, '8437')
(33848, '8438')
(33849, '8439')
(34883, '8843')
(37943, '9437')
(38931, '9813')
(38966, '9836')
(38995, '9853')
(66310, '10306')
(71444, '11714')
(71497, '11749')
(71511, '11757')
(75120, '12570')
(75121, '12571')
(75122, '12572')
(75123, '12573')
(75124, '12574')
(75125, '12575')
(75126, '12576')
(75127, '12577')
(75128, '12578')
(75129, '12579')
(75621, '12765')
(86150, '15086')
(88165, '15865')
(91465, '16549')
(91769, '16679')
(96617, '17969')
(98711, '18197')
(99481, '18499')</pre>
=={{header|Quackery}}==
<
[ 10 base put
Line 667 ⟶ 1,428:
[ i^ number$
nested join ] ]
60 wrap$</
{{out}}
Line 685 ⟶ 1,446:
Several different interpretations of the (originally very vague) task instructions. It has now been clarified to mean the second.
<syntaxhighlight lang="raku"
are composed of the same digit glyphs. (All the same glyphs, all the same
quantity.)\n";
Line 712 ⟶ 1,473:
reduce( &op, (.fmt('%x'), $_).map: { .comb."$container"() } )
} )
}</
{{out}}
<pre>Numbers which when expressed in hexadecimal and in decimal are composed of
Line 778 ⟶ 1,539:
=={{header|REXX}}==
<
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n = 100000 /*Not specified? Then use the default.*/
Line 805 ⟶ 1,566:
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</
{{out|output|text= when using the default inputs:}}
<pre>
Line 823 ⟶ 1,584:
=={{header|Ring}}==
<
see "working..." + nl
Line 859 ⟶ 1,620:
see nl + "Found " + row + " numbers" + nl
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 880 ⟶ 1,641:
done...
</pre>
=={{header|RPL}}==
{{works with|HP|49}}
« → b
« #0
'''WHILE''' OVER '''REPEAT'''
SWAP b IDIV2
ROT SWAP ALOG R→B OR
'''END''' NIP
» » '<span style="color:blue">DIGSET</span>' STO
« { }
0 99999 '''FOR''' n
'''IF''' n 10 <span style="color:blue">DIGSET</span> n 16 <span style="color:blue">DIGSET</span> == '''THEN''' n + '''END'''
'''NEXT'''
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: { 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 }
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">p (1..100_000).select{|n| n.digits.to_set == n.digits(16).to_set}</syntaxhighlight>
{{out}}
<pre>
[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]
</pre>
=={{header|SETL}}==
<syntaxhighlight lang="setl">program Numbers_with_same_digit_set_in_base_10_and_base_16;
loop for i in [0..100000] | digitset(i,10) = digitset(i,16) do
nprint(lpad(str i, 8));
if (col +:= 1) mod 10 = 0 then print; end if;
end loop;
print;
proc digitset(n, b);
s := {};
loop until n=0 do
s with:= n mod b;
n div:= b;
end loop;
return s;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre> 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</pre>
=={{header|Sidef}}==
Simple solution:
<
Recursively generate the numbers (2x faster):
<
var seq = [p]
Line 909 ⟶ 1,723:
}
say numbers_with_same_digitset(1e5, 16)</
{{out}}
<pre>
Line 918 ⟶ 1,732:
{{libheader|Wren-fmt}}
{{libheader|Wren-set}}
<
import "./set" for Set
var limit = 1e5
Line 934 ⟶ 1,748:
}
}
System.print("\n\n%(count) such numbers found.")</
{{out}}
Line 951 ⟶ 1,765:
=={{header|XPL0}}==
<
\Return a bit array containing the set of digits in N divisible by D
int N, D;
Line 973 ⟶ 1,787:
CrLf(0); IntOut(0, Count); Text(0, " such numbers found.
")
]</
{{out}}
Line 986 ⟶ 1,800:
69 such numbers found.
</pre>
=={{header|Zig}}==
{{trans|C}}
<syntaxhighlight lang="zig">const print = @import("std").debug.print;
fn digitset(numinp: u32, base: u32) u32 {
var set: u32 = 0;
var num: u32 = numinp;
while (num != 0) : (num /= base) {
set |= @as(u32, 1) << @truncate(u5, num % base);
}
return set;
}
pub fn main() void {
var i: u32 = 0;
const LIMIT: u32 = 100000;
while (i < LIMIT) : (i += 1) {
if (digitset(i, 10) == digitset(i, 16)) {
print("{}\n", .{i});
}
}
}</syntaxhighlight>
|