Numbers with same digit set in base 10 and base 16: Difference between revisions
Content deleted Content added
→{{header|JavaScript}}: Added a JavaScript version. |
|||
Line 693: | Line 693: | ||
98711 18197 |
98711 18197 |
||
99481 18499</lang> |
99481 18499</lang> |
||
=={{header|JavaScript}}== |
|||
<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 set of members. |
|||
b => a.size === b.size && ( |
|||
Array.from(a).every(x => b.has(x)) |
|||
); |
|||
// MAIN --- |
|||
return main(); |
|||
})();</lang> |
|||
{{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|Julia}}== |
=={{header|Julia}}== |