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

→‎{{header|Raku}}: DRY. Factor out common code
(→‎{{header|Raku}}: DRY. Factor out common code)
Line 688:
are composed of the same digit glyphs. (All the same glyphs, all the same
quantity.)\n";
display-numbers calculated-with &infix:<eqv>, <Bag>;
say .elems ~ " found:\n" ~ .batch(20)».fmt('%5d').join("\n") given
(^18699).map( {:16(.Str)} ).hyper(:1000batch).grep( { [eqv] (.fmt('%x'), $_).map( *.comb.Bag ) } ).cache;
 
 
say "\nNumbers up to 100,000 which when expressed in hexadecimal and in decimal
are composed from the same digit glyphs. (All the same glyphs are present,
possibly different quantity.)\n";
display-numbers calculated-with &infix:<eqv>, <Set>;
say .elems ~ " found:\n" ~ .batch(20)».fmt('%5d').join("\n") given
(^18699).map( {:16(.Str)} ).hyper(:1000batch).grep( { [eqv] (.fmt('%x'), $_).map( *.comb.Set ) } ).cache;
 
 
say "\nNumbers up to 100,000 which, when expressed in hexadecimal use glyphs
that are a subset of those used when expressed in decimal. (Every glyph in
decimal is present in hexadecimal the same or fewer (possibly zero) times)\n";
display-numbers calculated-with &infix:<⊆>, <Bag>;
say .elems ~ " found:\n" ~ .batch(20)».fmt('%5d').join("\n") given
(^18699).map( {:16(.Str)} ).hyper(:1000batch).grep( { [⊆] (.fmt('%x'), $_).map( *.comb.Bag ) } ).cache;
 
 
say "\nNumbers up to 100,000 which, when expressed in hexadecimal use glyphs
Line 710 ⟶ 704:
decimal is present in hexadecimal in some quantity, possibly zero, possibly more
than in decimal)\n";
display-numbers calculated-with &infix:<⊆>, <Set>;
say .elems ~ " found:\n" ~ .batch(20)».fmt('%5d').join("\n") given
 
(^18699).map( {:16(.Str)} ).hyper(:1000batch).grep( { [⊆] (.fmt('%x'), $_).map( *.comb.Set ) } ).cache;</lang>
sub display-numbers ($_) { say .elems ~ " found:\n" ~ .batch(20)».fmt('%5d').join(: "\n") given}
 
sub calculated-with ( &op, $container ) {
( cache ^18699) .map( {:16(.Str)} ).hyper(:1000batch).grep( { [eqv] (.fmt('%x'), $_).map( *.comb.Bag ) } ).cache;
reduce( &op, (.fmt('%x'), $_).map: { .comb."$container"() } )
} )
}</lang>
{{out}}
<pre>Numbers which when expressed in hexadecimal and in decimal are composed of
10,327

edits