Numbers in base-16 representation that cannot be written with decimal digits: Difference between revisions
Numbers in base-16 representation that cannot be written with decimal digits (view source)
Revision as of 11:40, 6 January 2024
, 4 months ago→{{header|Wren}}: Minor tidy
(Add Ada) |
m (→{{header|Wren}}: Minor tidy) |
||
(11 intermediate revisions by 10 users not shown) | |||
Line 6:
=={{header|11l}}==
<
L(c) hex(n)
I c.is_digit()
L.break
L.was_no_break
print(n, end' ‘ ’)</
{{out}}
Line 18:
=={{header|Action!}}==
<
DO
IF x MOD 16<10 THEN
Line 40:
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/Numbers_in_base-16_representation_that_cannot_be_written_with_decimal_digits.png Screenshot from Atari 8-bit computer]
Line 51:
=={{header|Ada}}==
<
procedure Numbers_In_Base_16 is
Line 83:
Put (" without decimal digits in hex representation.");
New_Line;
end Numbers_In_Base_16;</
{{out}}
<pre>
Line 100:
=={{header|ALGOL 68}}==
Generates the numbers.
<
# generate and print the numbers up to 499 #
# 499 is 1F3 in hex, so we need to find numbers up to FF #
Line 116:
OD
OD
END</
{{out}}
<pre>
Line 124:
250 251 252 253 254 255
</pre>
=={{header|Arturo}}==
<syntaxhighlight lang="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</syntaxhighlight>
{{out}}
<pre> 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</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f NUMBERS_IN_BASE-16_REPRESENTATION_THAT_CANNOT_BE_WRITTEN_WITH_DECIMAL_DIGITS.AWK
BEGIN {
Line 139 ⟶ 156:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 151 ⟶ 168:
=={{header|BASIC}}==
<
20 H=0: GOSUB 50
30 FOR H=10 TO 15: GOSUB 50: NEXT
Line 158 ⟶ 175:
60 PRINT H*16+L,
70 NEXT
80 RETURN</
{{out}}
<pre> 10 11 12 13 14
Line 173 ⟶ 190:
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<
fila = 0
n = 0
Line 191 ⟶ 208:
next i
print
end subroutine</
==={{header|FreeBASIC}}===
<
Print "Numbers in base-16 representation that cannot be written with decimal digits:"
Line 212 ⟶ 229:
Print !"\nFound "; fila; " numbers"
Sleep</
{{out}}
<pre>Numbers in base-16 representation that cannot be written with decimal digits:
Line 227 ⟶ 244:
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<
Procedure num(n.i)
Line 251 ⟶ 268:
Input()
CloseConsole()
End</
==={{header|True BASIC}}===
{{trans|BASIC256}}
<
FOR i = 10 to 15
PRINT n * 16 + i; " ";
Line 272 ⟶ 289:
NEXT n
PRINT "Found "; fila; " numbers"
END</
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<
fila = 0
n = 0
Line 292 ⟶ 309:
next i
print
end sub</
=={{header|BCPL}}==
<
let lownybble(hi) be
Line 305 ⟶ 322:
for hi=#XA to #XF do
lownybble(hi)
$)</
{{out}}
<pre style="height:24em">10
Line 349 ⟶ 366:
254
255</pre>
=={{header|BQN}}==
<syntaxhighlight lang="bqn">∾⟜(16⊸×⊸+⌜˜) 10+↕6</syntaxhighlight>
{{out}}
<pre>┌─
╵ 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
┘</pre>
=={{header|C}}==
<syntaxhighlight lang="c">
#include<stdio.h>
Line 366 ⟶ 396:
return 0;
}
</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 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
</pre>
=={{header|C++}}==
<
#include<iostream>
using namespace std;
Line 388 ⟶ 419:
return 0;
}
</syntaxhighlight>
{{out}}
<pre>
Line 394 ⟶ 425:
</pre>
=={{header|CLU}}==
<
for lo: int in int$from_to(10, 15) do
stream$putl(s, int$unparse(hi*16 + lo))
Line 406 ⟶ 437:
lownybble(po, hi)
end
end start_up</
{{out}}
<pre style='height:50ex;'>10
Line 452 ⟶ 483:
=={{header|COBOL}}==
<
PROGRAM-ID. NO-0-9-IN-HEX.
Line 477 ⟶ 508:
ADD LOW-NYBBLE TO OUT-NUM.
MOVE OUT-NUM TO OUT-FMT.
DISPLAY OUT-FMT.</
{{out}}
<pre style='height:24em;'> 10
Line 524 ⟶ 555:
=={{header|Cowgol}}==
<
sub lownybble(hi: uint8) is
Line 540 ⟶ 571:
lownybble(hi);
hi := hi + 1;
end loop;</
{{out}}
<pre style='height:50ex;'>10
Line 586 ⟶ 617:
=={{header|Draco}}==
<
word lo;
for lo from 0xA upto 0xF do
Line 599 ⟶ 630:
lownybble(hi)
od
corp</
{{out}}
<pre style='height:50ex;'>10
Line 643 ⟶ 674:
254
255</pre>
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
<syntaxhighlight lang="Delphi">
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;
</syntaxhighlight>
{{out}}
<pre>
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
</pre>
=={{header|F_Sharp|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 ""
</syntaxhighlight>
{{out}}
<pre>
Line 658 ⟶ 743:
Count up by letters A-F; convert from hexadecimal to decimal.
{{works with|Factor|0.99 2021-06-02}}
<
sequences.extras ;
"ABCDEF" { 1 2 } [ [ hex> ] map-selections ] with map-concat .</
{{out}}
<pre style="height:24em">
Line 708 ⟶ 793:
255
}
</pre>
=={{header|Frink}}==
<syntaxhighlight lang="frink">println[select[1 to 500, {|x| base16[x] =~ %r/^[a-z]+$/i} ]]</syntaxhighlight>
{{out}}
<pre>
[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]
</pre>
=={{header|Go}}==
<
import (
Line 733 ⟶ 825:
}
fmt.Printf("\n%d such numbers found.\n", c)
}</
{{out}}
Line 744 ⟶ 836:
</pre>
=={{header|Haskell}}==
<syntaxhighlight lang="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</syntaxhighlight>
{{out}}
<pre>
$ 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]
</pre>
=={{header|J}}==
Represented as decimal numbers:<syntaxhighlight lang="j"> 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</syntaxhighlight>
Represented as hexadecimal numbers:<syntaxhighlight lang="j"> 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</syntaxhighlight>
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq, and with fq'''
<syntaxhighlight lang=jq>
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."
</syntaxhighlight>
{{output}}
<pre>
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.
</pre>
=={{header|Julia}}==
<
foreach(p -> print(rpad(p[2], 4), p[1] % 14 == 0 ? "\n" : ""), enumerate(usesnoletters))
</
<pre>
10 11 12 13 14 15 170 171 172 173 174 175 186 187
Line 755 ⟶ 898:
222 223 234 235 236 237 238 239 250 251 252 253 254 255
</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
500], _?(Length@Intersection[IntegerDigits[#, 16], Range[0, 9]] ==
0 &)]</
{{out}}<pre>
Line 765 ⟶ 909:
=={{header|Modula-2}}==
<
FROM InOut IMPORT WriteCard, WriteLn;
Line 784 ⟶ 928:
LowNybble(hi)
END
END Base16NoDecimalNumbers.</
{{out}}
<pre style='height:50ex;'>10
Line 830 ⟶ 974:
=={{header|Nim}}==
<
let list = collect(newSeq):
Line 839 ⟶ 983:
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: ' '</
{{out}}
Line 851 ⟶ 995:
=={{header|Perl}}==
<
use warnings;
print join( ' ', grep sprintf("%x", $_) !~ /[0-9]/, 1 .. 500 ) =~ s/.{71}\K /\n/gr, "\n";</
{{out}}
<pre>10 11 12 13 14 15 170 171 172 173 174 175 186 187 188 189 190 191 202 203
Line 862 ⟶ 1,006:
=={{header|Phix}}==
[[Base-16_representation#Phix|Spot the difference...]]
<!--<
<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;">min</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 873 ⟶ 1,017:
=={{header|PL/M}}==
<
BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */
DECLARE FN BYTE, ARG ADDRESS;
Line 915 ⟶ 1,059:
END;
END;
EOF</
{{out}}
<pre>
Line 925 ⟶ 1,069:
=={{header|Python}}==
<syntaxhighlight lang="python">
[print(16*q + r,end=' ') for q in range(0,16) for r in range(10,16)]
</syntaxhighlight>
{{out}}
<pre>
Line 935 ⟶ 1,079:
=={{header|Quackery}}==
<
[ 16 /mod 10 < iff
[ dip not ] done
Line 950 ⟶ 1,094:
16 base put
echo cr
base release</
{{out}}
Line 971 ⟶ 1,115:
The task as written:
<syntaxhighlight lang="raku"
given (1..500).grep( { so any |.map: { .polymod(16 xx *) »>» 9 } } );</
{{out}}
<pre>301 such numbers:
Line 999 ⟶ 1,143:
Which is a '''tiny''' (2 character) change from [[Base-16 representation]]. Add some other (possibly useful) functionality.
<syntaxhighlight lang="raku"
put "Filter: {+$_} such numbers:\n", .batch(20)».fmt('%3d').join("\n")
given (1..500).grep( { so all |.map: { .polymod(16 xx *) »>» 9 } } );
Line 1,010 ⟶ 1,154:
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 } });</
{{out}}
<pre>Filter: 42 such numbers:
Line 1,028 ⟶ 1,172:
=={{header|REXX}}==
=== version 1 ===
<
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n = 500 /*Not specified? Then use the default.*/
Line 1,052 ⟶ 1,196:
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 1,069 ⟶ 1,213:
=== version 2 ===
This REXX version is exactly the same as version 1, but the ''filter'' was "inverted" so as to achieve the same result.
<
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n = 500 /*Not specified? Then use the default.*/
Line 1,093 ⟶ 1,237:
say
say 'Found ' found title
exit 0 /*stick a fork in it, we're all done. */</
{{out|output|text= is identical to the 1<sup>st</sup> REXX version.}} <br><br>
=={{header|Ring}}==
<
see "working..." + nl
see "Numbers in base-16 representation that cannot be written with decimal digits:" + nl
Line 1,127 ⟶ 1,271:
see nl + "Found " + row + " numbers" + nl
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 1,143 ⟶ 1,287:
Found 42 numbers
done...
</pre>
=={{header|RPL}}==
{{works with|Halcyon Calc|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
{{out}}
<pre>
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 }
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">p (0..500).select{|n| n.digits(16).all?{|d| d > 9} }</syntaxhighlight>
{{out}}
<pre>
[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]
</pre>
=={{header|Sidef}}==
Simple solution:
<
More efficient approach:
<
var seq = [p]
Line 1,171 ⟶ 1,336:
}
say numbers_with_non_decimal_digits(500, 16)</
{{out}}
<pre>
Line 1,178 ⟶ 1,343:
=={{header|UNIX Shell}}==
<
for q in {0..15};do for r in {10..15};do echo -n $((16*q+r));done;done
</syntaxhighlight>
{{out}}
<pre>
Line 1,188 ⟶ 1,353:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<
var decimal = "0123456789"
Line 1,200 ⟶ 1,365:
}
}
System.print("\n%(c) such numbers found.")</
{{out}}
Line 1,212 ⟶ 1,377:
=={{header|XPL0}}==
<
int N;
[while N do
Line 1,234 ⟶ 1,399:
Text(0, " such numbers found.
");
]</
{{out}}
|