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

m
simplify
m (simplify)
Line 107:
 
=={{header|Julia}}==
<lang julia>dhstring(N) = [i for i in 0:N if sort(unique(collect(stringdigits(i)))) == sort(unique(collect(stringdigits(i, base=16))))]
The requirements seem to depend upon interpretations of set and duplicates. Hex number is shown to demonstrate how numbers fit the revised task. The revised task may or may not disallow leading zeros for the base 16 number.
<lang Julia>using Combinatorics
 
function dheq(N)
found = 0
for i in 0:N
d = digits(i)
dlen = length(unique(d))
for j in dlen:length(d), c in Iterators.filter(x -> length(unique(x)) == dlen,
Combinatorics.with_replacement_combinations(d, j)), p in permutations(c)
if evalpoly(16, p) == i && (length(p) == 1 || p[end] != 0 || count(x -> x == 0, p) > 1)
print(rpad(i, 5), " = 0x", rpad(evalpoly(10, p), 8), (found += 1) % 5 == 0 ? "\n" : "")
break
end
end
end
end
 
dheq(100000)
</lang>{{out}}
<pre>
0 = 0x0 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>
== with string representation ==
<lang julia>dhstring(N) = [i for i in 0:N if sort(unique(collect(string(i)))) == sort(unique(collect(string(i, base=16))))]
 
foreach(p -> print(rpad(p[2], 6), p[1] % 10 == 0 ? "\n" : ""), enumerate(dhstring(100000)))
4,105

edits