How many of those glyphs are decimal digits? And yet it is in base 16, albeit with non-standard digit glyphs. So they all can be written without using a hexadecimal digit.
But wait a minute; is 2 a hexadecimal digit? Why yes, yes it is. So none of them can be written in hexadecimal without using a hexadecimal digit.
Bah. Show which when written in base 16, contain a digit glyph with a value greater than 9:
put display :20cols, :fmt('%3d'), (^501).grep( { so any |.map: { .polymod(16 xx *) »>» 9 } } );
sub display ($list, :$cols = 10, :$fmt = '%6d', :$title = "{+$list} matching:\n" ) {
cache $list;
$title ~ $list.batch($cols)».fmt($fmt).join: "\n"
}
But wait a minute. Let's take another look at the the task title. Base-16 representation. It isn't talking about Base 16 at all. It's talking about Base**-16**... so let's do it in base -16.
Of course, if you are looking for the count of the hexadecimal numbers up to some threshold that only use "decimal" digits, it is silly and counter-productive to iterate through them and check each when you really only need to check one.
use Lingua::EN::Numbers;
for 500
,10**8
,10**25
,10**35
-> $threshold {
my $limit = $threshold.base(16);
my $i = $limit.index: ['A'..'F'];
quietly $limit = $limit.substr(0, $i) ~ ('9' x ($limit.chars - $i)) if $i.Str;
for ' CAN ', $limit,
'CAN NOT', $threshold - $limit {
printf( "Quantity of numbers up to %s that %s be expressed in hexadecimal without using any alphabetics: %*s\n",
comma($threshold), $^a, comma($threshold).chars, comma($^c) )
}
say '';
}
Output:
Quantity of numbers up to 500 that CAN be expressed in hexadecimal without using any alphabetics: 199
Quantity of numbers up to 500 that CAN NOT be expressed in hexadecimal without using any alphabetics: 301
Quantity of numbers up to 100,000,000 that CAN be expressed in hexadecimal without using any alphabetics: 5,999,999
Quantity of numbers up to 100,000,000 that CAN NOT be expressed in hexadecimal without using any alphabetics: 94,000,001
Quantity of numbers up to 10,000,000,000,000,000,000,000,000 that CAN be expressed in hexadecimal without using any alphabetics: 845,951,614,014,849,999,999
Quantity of numbers up to 10,000,000,000,000,000,000,000,000 that CAN NOT be expressed in hexadecimal without using any alphabetics: 9,999,154,048,385,985,150,000,001
Quantity of numbers up to 100,000,000,000,000,000,000,000,000,000,000,000 that CAN be expressed in hexadecimal without using any alphabetics: 134,261,729,999,999,999,999,999,999,999
Quantity of numbers up to 100,000,000,000,000,000,000,000,000,000,000,000 that CAN NOT be expressed in hexadecimal without using any alphabetics: 99,999,865,738,270,000,000,000,000,000,000,001