Base 16 numbers needing a to f: Difference between revisions
m
syntax highlighting fixup automation
Drkameleon (talk | contribs) (Added Arturo implementation) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 8:
{{trans|Nim}}
<
print(‘Found ’l.len" numbers between 0 and 500:\n")
L(n) l
print(‘#3’.format(n), end' I (L.index + 1) % 19 == 0 {"\n"} E ‘ ’)
print()</
{{out}}
Line 37:
</pre>
=={{header|68000 Assembly}}==
<
MOVEM.L D0,D1-D6 ;clear data regs
Line 90:
RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</
=={{header|Action!}}==
<
DO
IF x MOD 16>9 THEN
Line 115:
OD
PrintF("%E%EFound %I numbers between %I and %I",count,min,max)
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Base_16_numbers_needing_a_to_f.png Screenshot from Atari 8-bit computer]
Line 134:
=={{header|Ada}}==
<
procedure Base_16_Numbers is
Line 167:
New_Line (2);
Put ("Total count: "); Natural_Io.Put (Count, Width => 3); New_Line;
end Base_16_Numbers;</
{{out}}
<pre> 10 11 12 13 14 15 26 27 28 29 30 31 42 43 44 45 46 47 58 59 60 61 62 63
Line 186:
=={{header|ALGOL 68}}==
<
INT h count := 0;
FOR i TO 500 DO
Line 200:
OD
OD
END</
{{out}}
<pre>
Line 222:
=={{header|ALGOL W}}==
<
begin
integer hCount;
Line 241:
end while_v_gt_0
end for_i
end.</
{{out}}
<pre>
Line 264:
=={{header|APL}}==
{{works with|Dyalog APL}}
<
{{out}}
<pre>10 11 12 13 14 15 26 27 28 29 30 31 42 43 44 45 46 47 58 59 60 61 62 63
Line 288:
=={{header|AppleScript}}==
===Procedural===
<
set output to {}
repeat with n from 0 to 500
Line 299:
if (ding) then set end of output to n
end repeat
return output</
{{output}}
<
===Functional===
Defining a simple predicate, and composing a test with formatted output from a set of generic functions:
<
-- p :: Int -> Bool
Line 506:
end repeat
v
end |until|</
{{Out}}
<pre>301 matches for the predicate:
Line 564:
=={{header|Arturo}}==
<
hex: as.hex x
loop `a`..`f` 'c [
Line 573:
]
print select 0..500 => needsAF?</
{{out}}
Line 580:
=={{header|AWK}}==
<
# syntax: GAWK -f BASE-16_REPRESENTATION.AWK
BEGIN {
Line 593:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 616:
=={{header|BASIC}}==
<
20 FOR I=1 TO 500
30 J=I
40 IF (J AND 15)>=10 THEN PRINT I, ELSE J=J/16: IF J>9 THEN 40
50 NEXT I</
{{out}}
<pre style='height:50ex'> 10 11 12 13 14
Line 686:
=={{header|BASIC256}}==
<
while n > 0
if (n % 16) > 9 then return true
Line 697:
if needs_af(i) then print i; " ";
next i
end</
=={{header|BCPL}}==
<
let nondec(x) =
Line 717:
$)
wrch('*N')
$)</
{{out}}
<pre> 10 11 12 13 14 15 26 27 28 29 30 31 42 43 44 45 46 47 58 59
Line 737:
=={{header|C++}}==
<
#include <iostream>
Line 759:
}
std::cout << "\n\n" << count << " such numbers found.\n";
}</
{{out}}
Line 789:
=={{header|CLU}}==
<
while x>9 do
if x//16>=10 then return(true) end
Line 808:
end
stream$putl(po, "\nFound " || int$unparse(count) || " numbers.")
end start_up</
{{out}}
<pre> 10 11 12 13 14 15 26 27 28 29 30 31 42 43 44 45 46 47 58 59
Line 829:
=={{header|COBOL}}==
<
PROGRAM-ID. BASE-16.
Line 883:
ELSE
MOVE N16 TO NTEMP
GO TO IS-NONDEC.</
{{out}}
<pre> 10 11 12 13 14 15 26 27 28 29 30 31 42 43 44 45 46 47
Line 906:
=={{header|Cowgol}}==
<
sub nondecimal(n: uint16): (r: uint8) is
Line 935:
i := i + 1;
end loop;
print_nl();</
{{out}}
<pre>10 11 12 13 14 15 26 27 28 29
Line 970:
=={{header|F_Sharp|F#}}==
<
// Base 16 representation: Nigel Galloway. June 3rd., 2021
let rec fN g=match g%16,g/16 with (n,0)->9<n |(n,g) when n<10->fN g |_->true
seq{1..500}|>Seq.filter fN|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
{{out}}
<pre>
Line 984:
{{works with|Factor|0.99 2021-02-05}}
<
lists.lazy math prettyprint sequences ;
Line 998:
1 lfrom [ non-decimal? ] lfilter [ 501 < ] lwhile
list>array dup 15 group [ [ "%3d " printf ] each nl ] each nl
length pprint " such numbers found." print</
{{out}}
<pre>
Line 1,027:
=={{header|FOCAL}}==
<
01.20 F N=1,500;D 2
01.30 T !
Line 1,041:
02.80 S C=C+1
02.90 I (C-10)2.99;T !;S C=0
02.99 R</
{{out}}
<pre>= 10= 11= 12= 13= 14= 15= 26= 27= 28= 29
Line 1,077:
=={{header|Forth}}==
{{works with|Gforth}}
<
\ non-decimal digit.
: non-decimal ( u -- ? )
Line 1,102:
main
bye</
{{out}}
Line 1,132:
=={{header|FreeBASIC}}==
<
while n>0
if n mod 16 > 9 then return true
Line 1,143:
if needs_af(i) then print i;" ";
next i
</syntaxhighlight>
{{out}}<pre>
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 110 111 122 123 124 125 126 127 138 139 140 141 142 143 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 266 267 268 269 270 271 282 283 284 285 286 287 298 299 300 301 302 303 314 315 316 317 318 319 330 331 332 333 334 335 346 347 348 349 350 351 362 363 364 365 366 367 378 379 380 381 382 383 394 395 396 397 398 399 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
Line 1,149:
=={{header|Frink}}==
<
{{out}}
<pre>
Line 1,157:
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 1,179:
}
fmt.Printf("\n\n%d such numbers found.\n", c)
}</
{{out}}
Line 1,209:
=={{header|Haskell}}==
<
import Data.List.Split (chunksOf)
import Text.Printf (printf)
Line 1,254:
justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)</
{{Out}}
<pre>301 matches up to 500:
Line 1,281:
=={{header|JavaScript}}==
<
"use strict";
Line 1,464:
// MAIN ---
return main();
})();</
{{Out}}
<pre>301 matches up to 500:
Line 1,523:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang=jq>
# decimal number to hex string using lower-case letters
def hex:
Line 1,549:
;
task
</syntaxhighlight>
{{out}}
<pre>
Line 1,586:
=={{header|Julia}}==
<
foreach(p -> print(rpad(p[2], 4), p[1] % 15 == 0 ? "\n" : ""), enumerate(usesletters))
</
<pre>
10 11 12 13 14 15 26 27 28 29 30 31 42 43 44
Line 1,615:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
{{out}}
<pre>{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, 110, 111, 122, 123, 124, 125, 126, 127, 138, 139, 140, 141, 142, 143, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 266, 267, 268, 269, 270, 271, 282, 283, 284, 285, 286, 287, 298, 299, 300, 301, 302, 303, 314, 315, 316, 317, 318, 319, 330, 331, 332, 333, 334, 335, 346, 347, 348, 349, 350, 351, 362, 363, 364, 365, 366, 367, 378, 379, 380, 381, 382, 383, 394, 395, 396, 397, 398, 399, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500}</pre>
=={{header|Modula-2}}==
<
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
Line 1,654:
WriteString(" numbers found.");
WriteLn;
END NonDecimal.</
{{out}}
<pre> 10 11 12 13 14 15 26 27 28 29 30 31 42 43 44 45 46 47 58 59
Line 1,676:
=={{header|Nim}}==
<
let list = collect(newSeq):
Line 1,685:
for i, n in list:
stdout.write ($n).align(3), if (i + 1) mod 19 == 0: '\n' else: ' '
echo()</
{{out}}
Line 1,708:
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Base-16_representation
Line 1,714:
print join( ' ', grep sprintf("%x", $_) =~ tr/a-z//, 1 .. 500 ) =~
s/.{71}\K /\n/gr, "\n";</
{{out}}
<pre>
Line 1,738:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">above9</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">max</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%x"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">))></span><span style="color: #008000;">'9'</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">500</span><span style="color: #0000FF;">),</span><span style="color: #000000;">above9</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"found"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">))})</span>
<!--</
{{out}}
<pre>
Line 1,748:
</pre>
{{trans|Raku|someone got their clever hat on there}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.0"</span><span style="color: #0000FF;">)</span>
Line 1,768:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">thresh</span><span style="color: #0000FF;">,</span><span style="color: #000000;">can</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cannot</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 1,782:
=={{header|PL/M}}==
<
/* CP/M BDOS SYSTEM CALL */
BDOS: PROCEDURE( FN, V ); DECLARE FN BYTE, V ADDRESS; GOTO 5; END;
Line 1,825:
END;
END;
EOF</
{{out}}
<pre>
Line 1,847:
=={{header|Python}}==
<
Line 1,904:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>301 matches for the predicate:
Line 1,962:
=={{header|Quackery}}==
<
[ dup 0 != while
16 /mod
Line 1,976:
[ i^ number$
nested join ] ]
60 wrap$</
{{out}}
Line 2,009:
Base 16 is not hexadecimal. Hexadecimal is ''an implementation'' of base 16.
<syntaxhighlight lang=raku
set-digits <⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ ㉑ ㉒ ㉓ ㉔ ㉕>;
say (7**35).&to-base(16);
# ⑭㉒⑱⑩⑰⑰⑳⑮⑱⑳⑩⑳⑱㉒㉑⑰㉒⑫⑭⑲⑯⑩㉔⑮⑰</
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.
Line 2,022:
Bah. Show which when written in base 16, contain a digit glyph with a value greater than 9:
<syntaxhighlight lang=raku
sub display ($list, :$cols = 10, :$fmt = '%6d', :$title = "{+$list} matching:\n" ) {
cache $list;
$title ~ $list.batch($cols)».fmt($fmt).join: "\n"
}</
{{out}}
<pre>301 matching:
Line 2,049:
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.
<syntaxhighlight lang=raku
put display :20cols, :fmt('%3d'), (^501).grep( { .&to-base(-16).contains: /<[A..F]>/ } );
Line 2,056:
cache $list;
$title ~ $list.batch($cols)».fmt($fmt).join: "\n"
}</
{{out}}
<pre>306 matching:
Line 2,078:
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'''''.
<syntaxhighlight lang=raku
for 500
Line 2,096:
say '';
}</
{{out}}
<pre>Quantity of numbers up to 500 that CAN be expressed in hexadecimal without using any alphabetics: 199
Line 2,112:
=={{header|REXX}}==
REXX automatically uses only uppercase when converting integers to hexadecimal, but the lowercase alphabetic letters were also included for boilerplate code.
<
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n = 501 /*Not specified? Then use the default.*/
Line 2,136:
say
say 'Found ' found title
exit 0 /*stick a fork in it, we're all done. */</
{{out|output|text= when using the default inputs:}}
<pre>
Line 2,178:
=={{header|Ring}}==
<
see "working..." + nl
baseList = ["a","b","c","d","e","f"]
Line 2,205:
see nl + "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 2,243:
</pre>
=={{header|Ruby}}==
<
{{out}}
<pre>
Line 2,251:
=={{header|Sidef}}==
{{trans|Ruby}}
<
{{out}}
<pre>
Line 2,259:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
var nondecimal = "abcdef"
Line 2,271:
}
}
System.print("\n\n%(c) such numbers found.")</
{{out}}
Line 2,302:
=={{header|XPL0}}==
Borrowed masking concept from C++, which was much more elegant than my first solution.
<
int N;
[while N do
Line 2,321:
CrLf(0);
IntOut(0, Cnt); Text(0, " such numbers found."); CrLf(0);
]</
{{out}}
Line 2,346:
=={{header|Yabasic}}==
<
while n > 0
if mod(n, 16) > 9 then return true : fi
Line 2,357:
if needs_af(i) then print i, " ", : fi
next i
end</
|