Base 16 numbers needing a to f: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 8:
{{trans|Nim}}
 
<syntaxhighlight lang="11l">V l = (0..500).filter(n -> !hex(n).is_digit())
 
print(‘Found ’l.len" numbers between 0 and 500:\n")
Line 37:
</pre>
=={{header|68000 Assembly}}==
<syntaxhighlight lang="68000devpac">MOVEQ #0,D0 ;clear D0
MOVEM.L D0,D1-D6 ;clear data regs
 
Line 93:
 
=={{header|Action!}}==
<syntaxhighlight lang=Action"action!">BYTE FUNC IsHexWithLetter(INT x)
DO
IF x MOD 16>9 THEN
Line 134:
 
=={{header|Ada}}==
<syntaxhighlight lang=Ada"ada">with Ada.Text_Io;
 
procedure Base_16_Numbers is
Line 186:
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">BEGIN # show numbers that when represented in hex, have at least one a-f digit #
INT h count := 0;
FOR i TO 500 DO
Line 222:
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="algolw">% show numbers that when represented in hex, have at least one a-f digit %
begin
integer hCount;
Line 264:
=={{header|APL}}==
{{works with|Dyalog APL}}
<syntaxhighlight lang=APL"apl">(⊢(/⍨)(10∨.≤16(⊥⍣¯1)⊢)¨)⍳500</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
Line 288:
=={{header|AppleScript}}==
===Procedural===
<syntaxhighlight lang="applescript">local output, n, x, ding
set output to {}
repeat with n from 0 to 500
Line 302:
 
{{output}}
<syntaxhighlight lang="applescript">{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}</syntaxhighlight>
 
===Functional===
Defining a simple predicate, and composing a test with formatted output from a set of generic functions:
<syntaxhighlight lang="applescript">-------- INTEGERS NEEDING HEX DIGITS HIGHER THAN 9 -------
 
-- p :: Int -> Bool
Line 564:
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">needsAF?: function [x][
hex: as.hex x
loop `a`..`f` 'c [
Line 580:
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f BASE-16_REPRESENTATION.AWK
BEGIN {
Line 616:
 
=={{header|BASIC}}==
<syntaxhighlight lang="basic">10 DEFINT I,J
20 FOR I=1 TO 500
30 J=I
Line 686:
 
=={{header|BASIC256}}==
<syntaxhighlight lang="qbasic">function needs_af (n)
while n > 0
if (n % 16) > 9 then return true
Line 701:
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let nondec(x) =
Line 737:
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
 
Line 789:
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">nondec = proc (x: int) returns (bool)
while x>9 do
if x//16>=10 then return(true) end
Line 829:
 
=={{header|COBOL}}==
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. BASE-16.
Line 906:
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub nondecimal(n: uint16): (r: uint8) is
Line 970:
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// 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
Line 984:
 
{{works with|Factor|0.99 2021-02-05}}
<syntaxhighlight lang="factor">USING: combinators formatting grouping io kernel lists
lists.lazy math prettyprint sequences ;
 
Line 1,027:
 
=={{header|FOCAL}}==
<syntaxhighlight lang=FOCAL"focal">01.10 S C=0
01.20 F N=1,500;D 2
01.30 T !
Line 1,077:
=={{header|Forth}}==
{{works with|Gforth}}
<syntaxhighlight lang="forth">\ Returns true if the hexadecimal representation of n contains at least one
\ non-decimal digit.
: non-decimal ( u -- ? )
Line 1,132:
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">function needs_af( byval n as uinteger ) as boolean
while n>0
if n mod 16 > 9 then return true
Line 1,149:
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">select[1 to 500, {|n| base16[n] =~ %r/[a-f]/i}]</syntaxhighlight>
{{out}}
<pre>
Line 1,157:
=={{header|Go}}==
{{trans|Wren}}
<syntaxhighlight lang="go">package main
 
import (
Line 1,209:
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import Data.List (intercalate, transpose)
import Data.List.Split (chunksOf)
import Text.Printf (printf)
Line 1,281:
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">(() => {
"use strict";
 
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,586:
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">usesletters = filter(n -> begin s = string(n, base = 16); any(c -> c in s, collect("abcdef")) end, 1:500)
 
foreach(p -> print(rpad(p[2], 4), p[1] % 15 == 0 ? "\n" : ""), enumerate(usesletters))
Line 1,615:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">Select[Range[500], AnyTrue[IntegerDigits[#, 16], GreaterEqualThan[10]] &]</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}</pre>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE NonDecimal;
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
 
Line 1,676:
 
=={{header|Nim}}==
<syntaxhighlight lang=Nim"nim">import strutils, sugar
 
let list = collect(newSeq):
Line 1,708:
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Base-16_representation
Line 1,738:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<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>
Line 1,748:
</pre>
{{trans|Raku|someone got their clever hat on there}}
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<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,782:
 
=={{header|PL/M}}==
<syntaxhighlight lang="plm">100H: /* SHOW NUMBERS THAT WHEN REPRESENTED IN HEX, HAVE AT LEAST 1 A-F DIGIT */
/* CP/M BDOS SYSTEM CALL */
BDOS: PROCEDURE( FN, V ); DECLARE FN BYTE, V ADDRESS; GOTO 5; END;
Line 1,847:
 
=={{header|Python}}==
<syntaxhighlight lang="python">'''Integers needing any alpha digits in hex'''
 
 
Line 1,962:
=={{header|Quackery}}==
 
<syntaxhighlight lang=Quackery"quackery"> [ false swap
[ dup 0 != while
16 /mod
Line 2,009:
Base 16 is not hexadecimal. Hexadecimal is ''an implementation'' of base 16.
 
<syntaxhighlight lang="raku" linesline>use Base::Any;
set-digits <⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ ㉑ ㉒ ㉓ ㉔ ㉕>;
say (7**35).&to-base(16);
Line 2,022:
Bah. Show which when written in base 16, contain a digit glyph with a value greater than 9:
 
<syntaxhighlight lang="raku" linesline>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" ) {
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" linesline>use Base::Any;
 
put display :20cols, :fmt('%3d'), (^501).grep( { .&to-base(-16).contains: /<[A..F]>/ } );
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" linesline>use Lingua::EN::Numbers;
 
for 500
Line 2,112:
=={{header|REXX}}==
REXX automatically uses only uppercase when converting integers to hexadecimal, &nbsp; but the lowercase alphabetic letters were also included for boilerplate code.
<syntaxhighlight lang="rexx">/*REXX pgm finds positive integers when shown in hexadecimal require an alphabetic glyph*/
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n = 501 /*Not specified? Then use the default.*/
Line 2,178:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
see "working..." + nl
baseList = ["a","b","c","d","e","f"]
Line 2,243:
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">puts (0..500).select{|n| n.digits(16).any?{|d| d >= 10} }.join(" ")</syntaxhighlight>
{{out}}
<pre>
Line 2,251:
=={{header|Sidef}}==
{{trans|Ruby}}
<syntaxhighlight lang="ruby">(0..500).grep {|n| n.digits(16).any {|d| d >= 10} }.join(" ").say</syntaxhighlight>
{{out}}
<pre>
Line 2,259:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "/fmt" for Conv, Fmt
 
var nondecimal = "abcdef"
Line 2,302:
=={{header|XPL0}}==
Borrowed masking concept from C++, which was much more elegant than my first solution.
<syntaxhighlight lang=XPL0"xpl0">func HasHex(N);
int N;
[while N do
Line 2,346:
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">sub needs_af (n)
while n > 0
if mod(n, 16) > 9 then return true : fi
10,333

edits