Numbers in base-16 representation that cannot be written with decimal digits

From Rosetta Code
Numbers in base-16 representation that cannot be written with decimal digits is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

Find positive integers for which the base 16 (hexadecimal) representation does not contain any decimal digits '0'..'9',   where   n   <   50010

11l

L(n) 1..499
   L(c) hex(n)
      I c.is_digit()
         L.break
   L.was_no_break
      print(n, end' ‘ ’)
Output:
10 11 12 13 14 15 170 171 172 173 174 175 186 187 188 189 190 191 202 203 204 205 206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251 252 253 254 255 

Action!

BYTE FUNC IsHexWithoutDigits(INT x)
  DO
    IF x MOD 16<10 THEN
      RETURN (0)
    FI
    x==/16
  UNTIL x=0
  OD
RETURN (1)

PROC Main()
  INT i,count,min=[0],max=[499]

  count=0
  FOR i=min TO max
  DO
    IF IsHexWithoutDigits(i) THEN
      PrintI(i) Put(32)
      count==+1
    FI
  OD
  PrintF("%E%EFound %I numbers between %I and %I",count,min,max)
RETURN
Output:

Screenshot from Atari 8-bit computer

10 11 12 13 14 15 170 171 172 173 174 175 186 187 188 189 190 191 202 203 204 205
206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251 252 253 254 255

Found 42 numbers between 0 and 499

Ada

with Ada.Text_IO;

procedure Numbers_In_Base_16 is

   package Natural_IO is new Ada.Text_IO.Integer_IO (Natural);
   use Ada.Text_IO, Natural_IO;

   function Is_Hex_Only (Value : Natural) return Boolean
   is (Value = 0 or
         (Value mod 16 >= 10 and then Is_Hex_Only (Value / 16)));

   subtype Test_Range is Natural range 1 .. 499;
   Count : Natural := 0;
begin
   for A in Test_Range loop
      if Is_Hex_Only (A) then
         Count := Count + 1;
         Put (A, Width => 3); Put (" = ");
         Put (A, Width => 6, Base => 16); Put ("   ");
         if Count mod 5 = 0 then
            New_Line;
         end if;
      end if;
   end loop;
   New_Line;
   Default_Width := 0;
   Put ("There are "); Put (Count);
   Put (" numbers in range ");
   Put (Test_Range'First); Put (" .. ");
   Put (Test_Range'Last);
   Put (" without decimal digits in hex representation.");
   New_Line;
end Numbers_In_Base_16;
Output:
 10 =  16#A#    11 =  16#B#    12 =  16#C#    13 =  16#D#    14 =  16#E#
 15 =  16#F#   170 = 16#AA#   171 = 16#AB#   172 = 16#AC#   173 = 16#AD#
174 = 16#AE#   175 = 16#AF#   186 = 16#BA#   187 = 16#BB#   188 = 16#BC#
189 = 16#BD#   190 = 16#BE#   191 = 16#BF#   202 = 16#CA#   203 = 16#CB#
204 = 16#CC#   205 = 16#CD#   206 = 16#CE#   207 = 16#CF#   218 = 16#DA#
219 = 16#DB#   220 = 16#DC#   221 = 16#DD#   222 = 16#DE#   223 = 16#DF#
234 = 16#EA#   235 = 16#EB#   236 = 16#EC#   237 = 16#ED#   238 = 16#EE#
239 = 16#EF#   250 = 16#FA#   251 = 16#FB#   252 = 16#FC#   253 = 16#FD#
254 = 16#FE#   255 = 16#FF#
There are 42 numbers in range 1 .. 499 without decimal digits in hex representation.

ALGOL 68

Generates the numbers.

BEGIN # find numbers whose hex representation does not contain the digits 0-9 #
    # generate and print the numbers up to 499 #
    # 499 is 1F3 in hex, so we need to find numbers up to FF #
    INT h count := 0;
    # 1 hex digit numbers #
    FOR d1 FROM 10 TO 15 DO
        print( ( " ", whole( d1, -3 ) ) );
        h count +:= 1
    OD;
    # two hex digit numbers #
    FOR d1 FROM 10 TO 15 DO
        FOR d2 FROM 10 TO 15 DO
            print( ( " ", whole( ( d1 * 16 ) + d2, -3 ) ) );
            IF ( h count +:= 1 ) MOD 12 = 0 THEN print( ( newline ) ) FI
        OD
    OD
END
Output:
  10  11  12  13  14  15 170 171 172 173 174 175
 186 187 188 189 190 191 202 203 204 205 206 207
 218 219 220 221 222 223 234 235 236 237 238 239
 250 251 252 253 254 255

Arturo

nonDecimalNums: select 1..500 'x ->
    empty? intersection digits.base:16 x @0..9

loop split.every: 7 nonDecimalNums 'x ->
    print map x 's -> pad to :string s 4
Output:
  10   11   12   13   14   15  170 
 171  172  173  174  175  186  187 
 188  189  190  191  202  203  204 
 205  206  207  218  219  220  221 
 222  223  234  235  236  237  238 
 239  250  251  252  253  254  255

AWK

# syntax: GAWK -f NUMBERS_IN_BASE-16_REPRESENTATION_THAT_CANNOT_BE_WRITTEN_WITH_DECIMAL_DIGITS.AWK
BEGIN {
    start = 1
    stop = 499
    for (i=start; i<=stop; i++) {
      if (sprintf("%X",i) !~ /[0-9]/) {
        printf("%4d%1s",i,++count%10?"":"\n")
      }
    }
    printf("\nHexadecimal numbers without 0-9, %d-%d: %d\n",start,stop,count)
    exit(0)
}
Output:
  10   11   12   13   14   15  170  171  172  173
 174  175  186  187  188  189  190  191  202  203
 204  205  206  207  218  219  220  221  222  223
 234  235  236  237  238  239  250  251  252  253
 254  255
Hexadecimal numbers without 0-9, 1-499: 42

BASIC

10 DEFINT A-Z
20 H=0: GOSUB 50
30 FOR H=10 TO 15: GOSUB 50: NEXT
40 END
50 FOR L=10 TO 15
60 PRINT H*16+L,
70 NEXT
80 RETURN
Output:
 10            11            12            13            14
 15            170           171           172           173
 174           175           186           187           188
 189           190           191           202           203
 204           205           206           207           218
 219           220           221           222           223
 234           235           236           237           238
 239           250           251           252           253
 254           255

BASIC

BASIC256

Translation of: FreeBASIC
global fila
fila = 0
n = 0

print "Numbers in base-16 representation that cannot be written with decimal digits:"
call num(n)
for n = 10 to 15
	call num(n)
next n
print "Found "; fila; " numbers"
end

subroutine num(n)
	for i = 10 to 15
		print n * 16 + i; "  ";
		fila += 1
	next i
	print
end subroutine

FreeBASIC

Dim Shared As Integer fila = 0
Print "Numbers in base-16 representation that cannot be written with decimal digits:"

Sub num(n As Integer)
    For i As Integer = 10 To 15
        Print Using " #### "; n * 16 + i;
        fila += 1
    Next i
    Print
End Sub

Dim As Integer n = 0
num(n)
For n = 10 To 15
    num(n)
Next n

Print !"\nFound "; fila; " numbers"
Sleep
Output:
Numbers in base-16 representation that cannot be written with decimal digits:
   10    11    12    13    14    15
  170   171   172   173   174   175
  186   187   188   189   190   191
  202   203   204   205   206   207
  218   219   220   221   222   223
  234   235   236   237   238   239
  250   251   252   253   254   255

Found 42 numbers

PureBasic

Translation of: FreeBASIC
Global fila.i = 0

Procedure num(n.i)
  For i = 10 To 15
    Print(" " + Str(n * 16 + i) + "  ")
    fila + 1
  Next i
  PrintN("")
EndProcedure


OpenConsole()
PrintN("Numbers in base-16 representation that cannot be written with decimal digits:")

n.i = 0
num(n)

For n = 10 To 15
  num(n)
Next n
PrintN(#CRLF$ + "Found " + Str(fila) + " numbers")

Input()
CloseConsole()
End

True BASIC

Translation of: BASIC256
SUB num(n)
    FOR i = 10 to 15
        PRINT n * 16 + i; "  ";
        LET  fila = fila + 1
    NEXT i
    PRINT
END SUB

PRINT "Numbers in base-16 representation that cannot be written with decimal digits:"

LET fila = 0
LET n = 0
CALL NUM(n)
FOR n = 10 to 15
    CALL NUM(n)
NEXT n
PRINT "Found "; fila; " numbers"
END

Yabasic

Translation of: FreeBASIC
print "Numbers in base-16 representation that cannot be written with decimal digits:"
fila = 0
n = 0
num(n)
for n = 10 to 15
    num(n)
next n
print "\nFound ", fila, " numbers"
end

sub num(n)
    for i = 10 to 15
        print n * 16 + i using "####",
        fila = fila + 1
    next i
    print
end sub

BCPL

get "libhdr"

let lownybble(hi) be
    for lo=#XA to #XF do
        writef("%N*N", hi<<4 | lo)

let start() be
$(  lownybble(0)
    for hi=#XA to #XF do
        lownybble(hi)
$)
Output:
10
11
12
13
14
15
170
171
172
173
174
175
186
187
188
189
190
191
202
203
204
205
206
207
218
219
220
221
222
223
234
235
236
237
238
239
250
251
252
253
254
255

BQN

(16×+⌜˜) 10+↕6
Output:
┌─
╵  10  11  12  13  14  15
  170 171 172 173 174 175
  186 187 188 189 190 191
  202 203 204 205 206 207
  218 219 220 221 222 223
  234 235 236 237 238 239
  250 251 252 253 254 255
                          ┘

C

#include<stdio.h>

int main()
{
 int q,r;

 for(q=0;q<16;q++){
   for(r=10;r<16;r++){
     printf("%5d",16*q+r);
   }
 }

return 0;
}
Output:
   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  170  171  172  173  174  175  186  187  188  189  190  191  202  203  204  205  206  207  218  219  220  221  222  223  234  235  236  237  238  239  250  251  252  253  254  255

C++

#include<iostream>
using namespace std;

int main()
{
 int q,r;

 for(q=0;q<16;q++){
   for(r=10;r<16;r++){
     std::cout<<16*q+r<<" ";
   }
 }

return 0;
}
Output:
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 170 171 172 173 174 175 186 187 188 189 190 191 202 203 204 205 206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251 252 253 254 255

CLU

lownybble = proc (s: stream, hi: int)
    for lo: int in int$from_to(10, 15) do   
        stream$putl(s, int$unparse(hi*16 + lo))
    end
end lownybble

start_up = proc ()
    po: stream := stream$primary_output()
    lownybble(po, 0)
    for hi: int in int$from_to(10, 15) do
        lownybble(po, hi)
    end
end start_up
Output:
10
11
12
13
14
15
170
171
172
173
174
175
186
187
188
189
190
191
202
203
204
205
206
207
218
219
220
221
222
223
234
235
236
237
238
239
250
251
252
253
254
255

COBOL

       IDENTIFICATION DIVISION.
       PROGRAM-ID. NO-0-9-IN-HEX.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 HIGH-NYBBLE      PIC 99.
       01 LOW-NYBBLE       PIC 99.
       01 OUT-NUM          PIC 999.
       01 OUT-FMT          PIC ZZ9.
       
       PROCEDURE DIVISION.
       BEGIN.
           MOVE ZERO TO HIGH-NYBBLE, PERFORM LOOP-LOW-NYBBLE.
           PERFORM LOOP-LOW-NYBBLE VARYING HIGH-NYBBLE FROM 10 BY 1
               UNTIL HIGH-NYBBLE IS EQUAL TO 16.
           STOP RUN.
       
       LOOP-LOW-NYBBLE.
           PERFORM SHOW-DECIMAL VARYING LOW-NYBBLE FROM 10 BY 1
               UNTIL LOW-NYBBLE IS EQUAL TO 16.
       
       SHOW-DECIMAL.
           MULTIPLY HIGH-NYBBLE BY 16 GIVING OUT-NUM.
           ADD LOW-NYBBLE TO OUT-NUM.
           MOVE OUT-NUM TO OUT-FMT.
           DISPLAY OUT-FMT.
Output:
 10
 11
 12
 13
 14
 15
170
171
172
173
174
175
186
187
188
189
190
191
202
203
204
205
206
207
218
219
220
221
222
223
234
235
236
237
238
239
250
251
252
253
254
255

Cowgol

include "cowgol.coh";

sub lownybble(hi: uint8) is
    var lo: uint8 := 0xA;
    while lo <= 0xF loop
        print_i8(hi<<4 | lo);
        print_nl();
        lo := lo + 1;
    end loop;
end sub;

lownybble(0);
var hi: uint8 := 0xA;
while hi <= 0xF loop;
    lownybble(hi);
    hi := hi + 1;
end loop;
Output:
10
11
12
13
14
15
170
171
172
173
174
175
186
187
188
189
190
191
202
203
204
205
206
207
218
219
220
221
222
223
234
235
236
237
238
239
250
251
252
253
254
255

Draco

proc nonrec lownybble(word hi) void:
    word lo;
    for lo from 0xA upto 0xF do
        writeln(hi<<4 | lo)
    od
corp

proc nonrec main() void:
    word hi;
    lownybble(0);
    for hi from 0xA upto 0xF do
        lownybble(hi)
    od
corp
Output:
10
11
12
13
14
15
170
171
172
173
174
175
186
187
188
189
190
191
202
203
204
205
206
207
218
219
220
221
222
223
234
235
236
237
238
239
250
251
252
253
254
255

Delphi

Works with: Delphi version 6.0


function HasNoBase10(N: integer): boolean;
{Test N for decimal digits in hex string}
var I: integer;
var S: string;
begin
Result:=False;
S:=Format('%x',[N]);
for I:=1 to Length(S) do
 if S[I] in ['0'..'9'] then exit;
Result:=True;
end;



procedure ShowNoBase10inHex(Memo: TMemo);
var I,Cnt: integer;
var S: string;
begin
Cnt:=0;
for I:=0 to 500-1 do
 if HasNoBase10(I) then
	begin
	Inc(Cnt);
	S:=S+Format('%8D',[I]);
	If (Cnt mod 5)=0 then S:=S+#$0D#$0A;
	end;
Memo.Lines.Add('Count='+IntToStr(Cnt));
Memo.Lines.Add(S);
end;
Output:
Count=42
      10      11      12      13      14
      15     170     171     172     173
     174     175     186     187     188
     189     190     191     202     203
     204     205     206     207     218
     219     220     221     222     223
     234     235     236     237     238
     239     250     251     252     253
     254     255


F#

// Base16 numbers represented using only digits greater than 9. Nigel Galloway: June 25th., 2021
let rec fG n g=seq{yield! g; yield! fG n (g|>List.collect(fun g->n|>List.map(fun n->n+g*16)))}
fG [10..15] [10..15]|>Seq.takeWhile((>)5000)|>Seq.iter(fun n->printf "%d(%0x) " n n); printfn ""
Output:
10(a) 11(b) 12(c) 13(d) 14(e) 15(f) 170(aa) 171(ab) 172(ac) 173(ad) 174(ae) 175(af) 186(ba) 187(bb) 188(bc) 189(bd) 190(be) 191(bf) 202(ca) 203(cb) 204(cc) 205(cd) 206(ce) 207(cf) 218(da) 219(db) 220(dc) 221(dd) 222(de) 223(df) 234(ea) 235(eb) 236(ec) 237(ed) 238(ee) 239(ef) 250(fa) 251(fb) 252(fc) 253(fd) 254(fe) 255(ff) 2730(aaa) 2731(aab) 2732(aac) 2733(aad) 2734(aae) 2735(aaf) 2746(aba) 2747(abb) 2748(abc) 2749(abd) 2750(abe) 2751(abf) 2762(aca) 2763(acb) 2764(acc) 2765(acd) 2766(ace) 2767(acf) 2778(ada) 2779(adb) 2780(adc) 2781(add) 2782(ade) 2783(adf) 2794(aea) 2795(aeb) 2796(aec) 2797(aed) 2798(aee) 2799(aef) 2810(afa) 2811(afb) 2812(afc) 2813(afd) 2814(afe) 2815(aff) 2986(baa) 2987(bab) 2988(bac) 2989(bad) 2990(bae) 2991(baf) 3002(bba) 3003(bbb) 3004(bbc) 3005(bbd) 3006(bbe) 3007(bbf) 3018(bca) 3019(bcb) 3020(bcc) 3021(bcd) 3022(bce) 3023(bcf) 3034(bda) 3035(bdb) 3036(bdc) 3037(bdd) 3038(bde) 3039(bdf) 3050(bea) 3051(beb) 3052(bec) 3053(bed) 3054(bee) 3055(bef) 3066(bfa) 3067(bfb) 3068(bfc) 3069(bfd) 3070(bfe) 3071(bff) 3242(caa) 3243(cab) 3244(cac) 3245(cad) 3246(cae) 3247(caf) 3258(cba) 3259(cbb) 3260(cbc) 3261(cbd) 3262(cbe) 3263(cbf) 3274(cca) 3275(ccb) 3276(ccc) 3277(ccd) 3278(cce) 3279(ccf) 3290(cda) 3291(cdb) 3292(cdc) 3293(cdd) 3294(cde) 3295(cdf) 3306(cea) 3307(ceb) 3308(cec) 3309(ced) 3310(cee) 3311(cef) 3322(cfa) 3323(cfb) 3324(cfc) 3325(cfd) 3326(cfe) 3327(cff) 3498(daa) 3499(dab) 3500(dac) 3501(dad) 3502(dae) 3503(daf) 3514(dba) 3515(dbb) 3516(dbc) 3517(dbd) 3518(dbe) 3519(dbf) 3530(dca) 3531(dcb) 3532(dcc) 3533(dcd) 3534(dce) 3535(dcf) 3546(dda) 3547(ddb) 3548(ddc) 3549(ddd) 3550(dde) 3551(ddf) 3562(dea) 3563(deb) 3564(dec) 3565(ded) 3566(dee) 3567(def) 3578(dfa) 3579(dfb) 3580(dfc) 3581(dfd) 3582(dfe) 3583(dff) 3754(eaa) 3755(eab) 3756(eac) 3757(ead) 3758(eae) 3759(eaf) 3770(eba) 3771(ebb) 3772(ebc) 3773(ebd) 3774(ebe) 3775(ebf) 3786(eca) 3787(ecb) 3788(ecc) 3789(ecd) 3790(ece) 3791(ecf) 3802(eda) 3803(edb) 3804(edc) 3805(edd) 3806(ede) 3807(edf) 3818(eea) 3819(eeb) 3820(eec) 3821(eed) 3822(eee) 3823(eef) 3834(efa) 3835(efb) 3836(efc) 3837(efd) 3838(efe) 3839(eff) 4010(faa) 4011(fab) 4012(fac) 4013(fad) 4014(fae) 4015(faf) 4026(fba) 4027(fbb) 4028(fbc) 4029(fbd) 4030(fbe) 4031(fbf) 4042(fca) 4043(fcb) 4044(fcc) 4045(fcd) 4046(fce) 4047(fcf) 4058(fda) 4059(fdb) 4060(fdc) 4061(fdd) 4062(fde) 4063(fdf) 4074(fea) 4075(feb) 4076(fec) 4077(fed) 4078(fee) 4079(fef) 4090(ffa) 4091(ffb) 4092(ffc) 4093(ffd) 4094(ffe) 4095(fff)

Factor

Count up by letters A-F; convert from hexadecimal to decimal.

Works with: Factor version 0.99 2021-06-02
USING: kernel math.combinatorics math.parser prettyprint
sequences.extras ;

"ABCDEF" { 1 2 } [ [ hex> ] map-selections ] with map-concat .
Output:
{
    10
    11
    12
    13
    14
    15
    170
    171
    172
    173
    174
    175
    186
    187
    188
    189
    190
    191
    202
    203
    204
    205
    206
    207
    218
    219
    220
    221
    222
    223
    234
    235
    236
    237
    238
    239
    250
    251
    252
    253
    254
    255
}

Frink

println[select[1 to 500, {|x| base16[x] =~ %r/^[a-z]+$/i} ]]
Output:
[10, 11, 12, 13, 14, 15, 170, 171, 172, 173, 174, 175, 186, 187, 188, 189, 190, 191, 202, 203, 204, 205, 206, 207, 218, 219, 220, 221, 222, 223, 234, 235, 236, 237, 238, 239, 250, 251, 252, 253, 254, 255]

Go

package main
 
import (
    "fmt"
    "strconv"
    "strings"
)
 
func main() {
    const decimal = "0123456789"
    c := 0
    for i := int64(1); i < 500; i++ {
        hex := strconv.FormatInt(i, 16)
        if !strings.ContainsAny(decimal, hex) {
            fmt.Printf("%3d ", i)
            c++
            if c%14 == 0 {
                fmt.Println()
            }
        }
    }
    fmt.Printf("\n%d such numbers found.\n", c)
}
Output:
 10  11  12  13  14  15 170 171 172 173 174 175 186 187 
188 189 190 191 202 203 204 205 206 207 218 219 220 221 
222 223 234 235 236 237 238 239 250 251 252 253 254 255 

42 such numbers found.


Haskell

-- With the exception of an initial 0, this is a list of all numbers whose
-- base-16 representations contain no decimal digits.
allNonDecimal :: [Int]
allNonDecimal = 0 : concatMap mulAdd allNonDecimal
  where mulAdd n = let m = n * 16 in map (m +) [10..15]

main :: IO ()
main = print $ takeWhile (< 500) $ tail allNonDecimal
Output:
$ no_dec
[10,11,12,13,14,15,170,171,172,173,174,175,186,187,188,189,190,191,202,203,204,205,206,207,218,219,220,221,222,223,234,235,236,237,238,239,250,251,252,253,254,255]

J

Represented as decimal numbers:

   I.(9 */ .< 16 #.inv ])"0 i.500
10 11 12 13 14 15 170 171 172 173 174 175 186 187 188 189 190 191 202 203 204 205 206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251 252 253 254 255

Represented as hexadecimal numbers:

   require'convert'
   ;:inv hfd each I.(9 */ .< 16 #.inv ])"0 i.500
a b c d e f aa ab ac ad ae af ba bb bc bd be bf ca cb cc cd ce cf da db dc dd de df ea eb ec ed ee ef fa fb fc fd fe ff

jq

Works with: jq

Also works with gojq, the Go implementation of jq, and with fq

def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;

def hex_stream:
  recurse(if . >= 16 then ./16|floor else empty end) | . % 16 ;

# Emit a stream of the decimal integers in range(1; $upper+1) satisfying the condition
def no_hex_digits($upper):
  range(1; $upper)
  | select( all(hex_stream; . > 9) );

[no_hex_digits(500)]
| (_nwise(14) | map(lpad(3)) | join(" ")),
  "\n\(length) such numbers found."
Output:
 10  11  12  13  14  15 170 171 172 173 174 175 186 187
188 189 190 191 202 203 204 205 206 207 218 219 220 221
222 223 234 235 236 237 238 239 250 251 252 253 254 255

42 such numbers found.

Julia

usesnoletters = filter(n -> begin s = string(n, base = 16); all(c -> c in "abcdef", s) end, 1:500)

foreach(p -> print(rpad(p[2], 4), p[1] % 14 == 0 ? "\n" : ""), enumerate(usesnoletters))
Output:
10  11  12  13  14  15  170 171 172 173 174 175 186 187
188 189 190 191 202 203 204 205 206 207 218 219 220 221
222 223 234 235 236 237 238 239 250 251 252 253 254 255

Mathematica / Wolfram Language

Cases[Range[
  500], _?(Length@Intersection[IntegerDigits[#, 16], Range[0, 9]] == 
     0 &)]
Output:

{10,11,12,13,14,15,170,171,172,173,174,175,186,187,188,189,190,191,202,203,204,205,206,207,218,219,220,221,222,223,234,235,236,237,238,239,250,251,252,253,254,255}

Modula-2

MODULE Base16NoDecimalNumbers;
FROM InOut IMPORT WriteCard, WriteLn;

VAR hi: CARDINAL;

PROCEDURE LowNybble(hi: CARDINAL);
    VAR lo: CARDINAL;
BEGIN
    FOR lo := 10 TO 15 DO
        WriteCard(hi*16 + lo, 3);
        WriteLn
    END
END LowNybble;

BEGIN
    LowNybble(0);
    FOR hi := 10 TO 15 DO
        LowNybble(hi)
    END
END Base16NoDecimalNumbers.
Output:
10
11
12
13
14
15
170
171
172
173
174
175
186
187
188
189
190
191
202
203
204
205
206
207
218
219
220
221
222
223
234
235
236
237
238
239
250
251
252
253
254
255

Nim

import strutils, sugar

let list = collect(newSeq):
             for d1 in {0, 10..15}:
               for d2 in {10..15}:
                 if (let n = 16 * d1 + d2; n < 500): n

echo "Found ", list.len, " numbers < 500 which cannot be written in base 16 with decimal digits:"
for i, n in list:
  stdout.write ($n).align(3), if (i + 1) mod 7 == 0: '\n' else: ' '
Output:
Found 42 numbers < 500 which cannot be written in base 16 with decimal digits:
 10  11  12  13  14  15 170
171 172 173 174 175 186 187
188 189 190 191 202 203 204
205 206 207 218 219 220 221
222 223 234 235 236 237 238
239 250 251 252 253 254 255

Perl

use strict;
use warnings;

print join( ' ', grep sprintf("%x", $_) !~ /[0-9]/, 1 .. 500 ) =~ s/.{71}\K /\n/gr, "\n";
Output:
10 11 12 13 14 15 170 171 172 173 174 175 186 187 188 189 190 191 202 203
204 205 206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251
252 253 254 255

Phix

Spot the difference...

with javascript_semantics
function above9(integer n) return min(sprintf("%x",n))>'9' end function
printf(1,"%s\n",{join(shorten(apply(filter(tagset(500),above9),sprint),"found",10))})
Output:
10 11 12 13 14 15 170 171 172 173 ... 236 237 238 239 250 251 252 253 254 255  (42 found)

PL/M

100H: /* FIND NUMBERS WHOSE HEX REPRESENTATION DOES NOT CONTAIN DIGITS 0-9 */
   BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */
      DECLARE FN BYTE, ARG ADDRESS;
      GOTO 5;
   END BDOS;
   PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C );   END;
   PR$NL:   PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
   PR$BYTE: PROCEDURE( N );
      DECLARE N BYTE;
      DECLARE V BYTE;
      V = N;
      CALL PR$CHAR( ' ' );
      IF N < 100 THEN CALL PR$CHAR( ' ' );
      ELSE DO;
         CALL PR$CHAR( '0' + ( V / 100 ) );
         V = V MOD 100;
      END;
      IF N <  10 THEN CALL PR$CHAR( ' ' );
      ELSE DO;
         CALL PR$CHAR( '0' + ( V / 10 ) );
      END;
      CALL PR$CHAR( '0' + ( V MOD 10 ) );
   END PR$BYTE;
   /* GENERATE AND PRINT THE NUMBERS UP TO 499 */
   /* 499 IS 1FE IN HEX, SO WE ONLY NEED TO CONSIDER A-F ABD AA-FF */
   DECLARE ( H$COUNT, D1, D2 ) BYTE;
   H$COUNT = 0;
   /* 1 HEX DIGIT NUMBERS */
   DO D1 = 10 TO 15;
      CALL PR$BYTE( D1 );
      H$COUNT = H$COUNT + 1;
   END;
   /* TWO DIGIT HEX NUMBERS */
   DO D1 = 10 TO 15;
      DO D2 = 10 TO 15;
         CALL PR$BYTE( SHL( D1, 4 ) OR D2 );
         IF ( H$COUNT := H$COUNT + 1 ) > 11 THEN DO;
            CALL PR$NL;
            H$COUNT = 0;
         END;
      END;
   END;
EOF
Output:
  10  11  12  13  14  15 170 171 172 173 174 175
 186 187 188 189 190 191 202 203 204 205 206 207
 218 219 220 221 222 223 234 235 236 237 238 239
 250 251 252 253 254 255

Python

[print(16*q + r,end=' ') for q in range(0,16) for r in range(10,16)]
Output:
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 170 171 172 173 174 175 186 187 188 189 190 191 202 203 204 205 206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251 252 253 254 255

Quackery

  [ true swap
    [ 16 /mod 10 < iff
       [ dip not ] done
      dup 0 = until ]
    drop ]              is nodigits ( n --> b )

  [] 500 times
   [ i^ nodigits if
     [ i^ join ] ]

  say "In decimal." cr
  dup echo cr cr
  say "In hexadecimal."cr
  16 base put
  echo cr
  base release
Output:
In decimal.
[ 10 11 12 13 14 15 170 171 172 173 174 175 186 187 188 189 190 191 202 203 204 205 206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251 252 253 254 255 ]

In hexadecimal.
[ A B C D E F AA AB AC AD AE AF BA BB BC BD BE BF CA CB CC CD CE CF DA DB DC DD DE DF EA EB EC ED EE EF FA FB FC FD FE FF ]

Raku

Find numbers in base-16 representation that cannot be written with decimal digits, where n < 500

This is literally the exact same task as (the horribly named) Base-16 representation task.

Leaving aside the requirement that it be base 16 (well, base negative 16 according to the task title); assume it really means hexadecimal, otherwise all bets are off.

I challenge anyone to demonstrate how, say 46510, can be written in hexadecimal using only decimal digits.

The task as written:

put "{+$_} such numbers:\n", .batch(20)».fmt('%3d').join("\n")
    given (1..500).grep( { so any |.map: { .polymod(16 xx *) »>» 9 } } );
Output:
301 such numbers:
 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


What the task author probably meant.

Find numbers in decimal that when written in hexadecimal are expressed using only alphabetic glyphs.

Which is a tiny (2 character) change from Base-16 representation. Add some other (possibly useful) functionality.

#Filter out such numbers from a range:
put "Filter: {+$_} such numbers:\n", .batch(20)».fmt('%3d').join("\n")
    given (1..500).grep( { so all |.map: { .polymod(16 xx *) »>» 9 } } );

#Generate such numbers directly, up to a threshold:
put "\nGenerate: first {+$_}:\n", .batch(10)».map({ "{$_}({:16($_)})" })».fmt('%9s').join("\n") given
    ((1..^Inf).grep(* % 7).map( { .base(7).trans: [1..6] => ['A'..'F'] } )).grep(!*.contains: 0)[^42];

#Count such numbers directly, up to a threshold 
my $upto = 500;
put "\nCount: " ~ [+] flat (map {exp($_, 6)}, 1..($upto.log(16).floor)),
+(exp($upto.log(16).floor, 16) .. $upto).grep( { so all |.map: { .polymod(16 xx *) »>» 9 } });
Output:
Filter: 42 such numbers:
 10  11  12  13  14  15 170 171 172 173 174 175 186 187 188 189 190 191 202 203
204 205 206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251 252 253
254 255

Generate: first 42:
    A(10)     B(11)     C(12)     D(13)     E(14)     F(15)   AA(170)   AB(171)   AC(172)   AD(173)
  AE(174)   AF(175)   BA(186)   BB(187)   BC(188)   BD(189)   BE(190)   BF(191)   CA(202)   CB(203)
  CC(204)   CD(205)   CE(206)   CF(207)   DA(218)   DB(219)   DC(220)   DD(221)   DE(222)   DF(223)
  EA(234)   EB(235)   EC(236)   ED(237)   EE(238)   EF(239)   FA(250)   FB(251)   FC(252)   FD(253)
  FE(254)   FF(255)

Count: 42

REXX

version 1

/*REXX pgm finds positive integers when shown in hex that can't be written with dec digs*/
parse arg n cols .                               /*obtain optional argument from the CL.*/
if    n=='' |    n==","  then   n = 500          /*Not specified?  Then use the default.*/
if cols=='' | cols==","  then cols=  10          /* "      "         "   "   "     "    */
w= 10                                            /*width of a number in any column.     */
title= " positive integers when shown in hexadecimal that can't be written with"  ,
       'decimal digits,  where  N  < '    n
say ' index │'center(title, 1 + cols*(w+1)     ) /*display the title for the output.    */
say '───────┼'center(""   , 1 + cols*(w+1), '─') /*   "     a   sep   "   "     "       */
found= 0;       y= 0123456789;         idx= 1    /*# finds;  forbidden glyphs;  set IDX.*/
$=                                               /*list of numbers found  (so far).     */
    do j=1  for n-1                              /*find ints in hex with no dec. digits.*/
    if verify(y, d2x(j), 'M')\==0  then iterate  /*Any dec. digs in hex number?   Skip. */    /* ◄■■■■■■■■ the filter. */
    found= found + 1                             /*bump number of found such numbers.   */
    $= $  right(j, w)                            /*add the found number  ───►  $  list. */
    if found // cols \== 0        then iterate   /*have we populated a line of output?  */
    say center(idx, 7)'│'  substr($, 2);   $=    /*display what we have so far  (cols). */
    idx= idx + cols                              /*bump the  index  count for the output*/
    end   /*j*/

if $\==''  then say center(idx, 7)"│"  substr($, 2)  /*possible display residual output.*/
say '───────┴'center(""   , 1 + cols*(w+1), '─')     /*display the foot sep for output. */
say
say 'Found '          found          title
exit 0                                           /*stick a fork in it,  we're all done. */
output   when using the default inputs:
 index │    positive integers when shown in hexadecimal that can't be written with decimal digits,  where  N  <  500
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │         10         11         12         13         14         15        170        171        172        173
  11   │        174        175        186        187        188        189        190        191        202        203
  21   │        204        205        206        207        218        219        220        221        222        223
  31   │        234        235        236        237        238        239        250        251        252        253
  41   │        254        255
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────

Found  42  positive integers when shown in hexadecimal that can't be written with decimal digits,  where  N  <  500

version 2

This REXX version is exactly the same as version 1,   but the   filter   was "inverted" so as to achieve the same result.

/*REXX pgm finds positive integers when shown in hex that can't be written with dec digs*/
parse arg n cols .                               /*obtain optional argument from the CL.*/
if    n=='' |    n==","  then   n = 500          /*Not specified?  Then use the default.*/
if cols=='' | cols==","  then cols=  10          /* "      "         "   "   "     "    */
w= 10                                            /*width of a number in any column.     */
title= " positive integers when shown in hexadecimal that can't be written with"  ,
       'decimal digits,  where  N  < '    n
say ' index │'center(title, 1 + cols*(w+1)     ) /*display the title for the output.    */
say '───────┼'center(""   , 1 + cols*(w+1), '─') /*   "     a   sep   "   "     "       */
found= 0;                              idx= 1    /*count of #'s found (so far); set IDX.*/
$=                                               /*list of numbers found  (so far).     */
    do j=1  for n-1                              /*find ints in hex with no dec. digits.*/
    if \datatype( d2x(j), 'M')    then iterate   /*All digs in hex # alphabetic?  Skip. */    /* ◄■■■■■■■■ the filter. */
    found= found + 1                             /*bump number of found such numbers.   */
    $= $  right(j, w)                            /*add the found number  ───►  $  list. */
    if found // cols \== 0        then iterate   /*have we populated a line of output?  */
    say center(idx, 7)'│'  substr($, 2);   $=    /*display what we have so far  (cols). */
    idx= idx + cols                              /*bump the  index  count for the output*/
    end   /*j*/

if $\==''  then say center(idx, 7)"│"  substr($, 2)  /*possible display residual output.*/
say '───────┴'center(""   , 1 + cols*(w+1), '─')     /*display the foot sep for output. */
say
say 'Found '          found          title
exit 0                                           /*stick a fork in it,  we're all done. */
output   is identical to the 1st REXX version.



Ring

see "working..." + nl
see "Numbers in base-16 representation that cannot be written with decimal digits:" + nl

row = 0
baseList = "ABCDEF"
limit = 500

for n = 1 to limit
    flag = 1  
    hex = upper(hex(n))
    for m = 1 to len(hex)
        ind = substr(baseList,hex[m])
        if ind < 1
           flag = 0
           exit
        ok
    next
     
    if flag = 1
       see "" + n + " "
       row = row + 1
       if row%5 = 0
          see nl
       ok
    ok
next

see nl + "Found " + row + " numbers" + nl
see "done..." + nl
Output:
working...
Numbers in base-16 representation that cannot be written with decimal digits:
10 11 12 13 14 
15 170 171 172 173 
174 175 186 187 188 
189 190 191 202 203 
204 205 206 207 218 
219 220 221 222 223 
234 235 236 237 238 
239 250 251 252 253 
254 255 
Found 42 numbers
done...

RPL

Works with: Halcyon Calc version 4.2.7
≪ { 0 10 11 12 13 14 15 } → abc 
  ≪ { } 
     1 7 FOR a 1 7 FOR b 2 7 FOR c 
         abc a GET 256 * abc b GET 16 * + abc c GET + 
         IF DUP 500 ≤ THEN + ELSE DROP END 
     NEXT NEXT NEXT
≫ ≫ 'TASK' STO
Output:
1: { 10 11 12 13 14 15 170 171 172 173 174 175 186 187 188 189 190 191 202 203 204 205 206 207 218 219 220 221 222 223 234 235 236 237 238 239 250 251 252 253 254 255 }

Ruby

p (0..500).select{|n| n.digits(16).all?{|d| d > 9} }
Output:
[10, 11, 12, 13, 14, 15, 170, 171, 172, 173, 174, 175, 186, 187, 188, 189, 190, 191, 202, 203, 204, 205, 206, 207, 218, 219, 220, 221, 222, 223, 234, 235, 236, 237, 238, 239, 250, 251, 252, 253, 254, 255]

Sidef

Simple solution:

1..500 -> grep { .digits(16).min >= 10 }.say

More efficient approach:

func generate_from_prefix(limit, p, base, digits) {

    var seq = [p]

    for d in (digits) {
        var t = [d, p...]
        if (t.digits2num(base) <= limit) {
            seq << __FUNC__(limit, t, base, digits)...
        }
    }

    return seq
}

func numbers_with_non_decimal_digits(limit, base = 10) {
    var digits = @(10..^base)
    digits.map  {|p| generate_from_prefix(limit, [p], base, digits)... }\
          .map  {|t| digits2num(t, base) }\
          .sort
}

say numbers_with_non_decimal_digits(500, 16)
Output:
[10, 11, 12, 13, 14, 15, 170, 171, 172, 173, 174, 175, 186, 187, 188, 189, 190, 191, 202, 203, 204, 205, 206, 207, 218, 219, 220, 221, 222, 223, 234, 235, 236, 237, 238, 239, 250, 251, 252, 253, 254, 255]

UNIX Shell

for q in {0..15};do for r in {10..15};do echo -n $((16*q+r));done;done
Output:
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  170  171  172  173  174  175  186  187  188  189  190  191  202  203  204  205  206  207  218  219  220  221  222  223  234  235  236  237  238  239  250  251  252  253  254  255  

Wren

Library: Wren-fmt
import "./fmt" for Conv, Fmt
 
var decimal = "0123456789"
var c = 0
for (i in 1..499) {
    var hex = Conv.hex(i)
    if (!hex.any { |c| decimal.contains(c) }) {
        Fmt.write("$3s ", i)
        c = c + 1
        if (c % 14 == 0) System.print()
    }
}
System.print("\n%(c) such numbers found.")
Output:
 10  11  12  13  14  15 170 171 172 173 174 175 186 187 
188 189 190 191 202 203 204 205 206 207 218 219 220 221 
222 223 234 235 236 237 238 239 250 251 252 253 254 255 

42 such numbers found.

XPL0

func Hexed(N);  \Return 'true' if N contains a hex digit
int  N;
[while N do
    [if (N&$F) >= 10 then return true;
    N:= N>>4;
    ];
return false;
];

int Count, N;
[SetHexDigits(3);
Count:= 0;
for N:= 0 to 500-1 do
    if Hexed(N) then
        [HexOut(0, N);
        Count:= Count+1;
        if rem(Count/20) = 0 then CrLf(0) else ChOut(0, ^ );
        ];
CrLf(0);
IntOut(0, Count);
Text(0, " such numbers found.
");
]
Output:
00A 00B 00C 00D 00E 00F 01A 01B 01C 01D 01E 01F 02A 02B 02C 02D 02E 02F 03A 03B
03C 03D 03E 03F 04A 04B 04C 04D 04E 04F 05A 05B 05C 05D 05E 05F 06A 06B 06C 06D
06E 06F 07A 07B 07C 07D 07E 07F 08A 08B 08C 08D 08E 08F 09A 09B 09C 09D 09E 09F
0A0 0A1 0A2 0A3 0A4 0A5 0A6 0A7 0A8 0A9 0AA 0AB 0AC 0AD 0AE 0AF 0B0 0B1 0B2 0B3
0B4 0B5 0B6 0B7 0B8 0B9 0BA 0BB 0BC 0BD 0BE 0BF 0C0 0C1 0C2 0C3 0C4 0C5 0C6 0C7
0C8 0C9 0CA 0CB 0CC 0CD 0CE 0CF 0D0 0D1 0D2 0D3 0D4 0D5 0D6 0D7 0D8 0D9 0DA 0DB
0DC 0DD 0DE 0DF 0E0 0E1 0E2 0E3 0E4 0E5 0E6 0E7 0E8 0E9 0EA 0EB 0EC 0ED 0EE 0EF
0F0 0F1 0F2 0F3 0F4 0F5 0F6 0F7 0F8 0F9 0FA 0FB 0FC 0FD 0FE 0FF 10A 10B 10C 10D
10E 10F 11A 11B 11C 11D 11E 11F 12A 12B 12C 12D 12E 12F 13A 13B 13C 13D 13E 13F
14A 14B 14C 14D 14E 14F 15A 15B 15C 15D 15E 15F 16A 16B 16C 16D 16E 16F 17A 17B
17C 17D 17E 17F 18A 18B 18C 18D 18E 18F 19A 19B 19C 19D 19E 19F 1A0 1A1 1A2 1A3
1A4 1A5 1A6 1A7 1A8 1A9 1AA 1AB 1AC 1AD 1AE 1AF 1B0 1B1 1B2 1B3 1B4 1B5 1B6 1B7
1B8 1B9 1BA 1BB 1BC 1BD 1BE 1BF 1C0 1C1 1C2 1C3 1C4 1C5 1C6 1C7 1C8 1C9 1CA 1CB
1CC 1CD 1CE 1CF 1D0 1D1 1D2 1D3 1D4 1D5 1D6 1D7 1D8 1D9 1DA 1DB 1DC 1DD 1DE 1DF
1E0 1E1 1E2 1E3 1E4 1E5 1E6 1E7 1E8 1E9 1EA 1EB 1EC 1ED 1EE 1EF 1F0 1F1 1F2 1F3

300 such numbers found.