Jump to content

Base-16 representation: Difference between revisions

m
→‎{{header|Raku}}: More generic display code
m (→‎{{header|Phix}}: decimal -> "decimal-looking")
m (→‎{{header|Raku}}: More generic display code)
Line 1,619:
Bah. Show which when written in base 16, contain a digit glyph with a value greater than 9:
 
<lang perl6>put "{+$_}display such numbers:\n"20cols, .batch(20)».:fmt('%3d'), (^501).joingrep("\n" { so any |.map: { .polymod(16 xx *) »>» 9 } } );
 
given (^501).grep( { so any |.map: { .polymod(16 xx *) »>» 9 } } );</lang>
sub display ($list, :$cols = 10, :$fmt = '%6d', :$title = "{+$list} matching:\n" ) {
cache $list;
$title ~ $list.batch(20$cols)».fmt('%3d'$fmt).join(: "\n")
}</lang>
{{out}}
<pre>301 such numbersmatching:
10 11 12 13 14 15 26 27 28 29 30 31 42 43 44 45 46 47 58 59
60 61 62 63 74 75 76 77 78 79 90 91 92 93 94 95 106 107 108 109
Line 1,643 ⟶ 1,647:
 
<lang perl6>use Base::Any;
 
put "Integers from 0 to 500 that when expressed in Base -16 in standard notation, contain an alphabetic: {+$_}\n",
put display :20cols, given:fmt('%3d'), (^501).grep( { .&to-base(-16).contains: /<[A..F]>/ } );</lang>
.batch(20)».fmt('%3d').join("\n")
 
given (^501).grep( { .&to-base(-16).contains: /<[A..F]>/ } );</lang>
sub display ($list, :$cols = 10, :$fmt = '%6d', :$title = "{+$list} matching:\n" ) {
cache $list;
$title ~ $list.batch($cols)».fmt($fmt).join: "\n"
}</lang>
{{out}}
<pre>306 matching:
<pre>Integers from 0 to 500 that when expressed in Base -16 in standard notation, contain an alphabetic: 306
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
10,339

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.