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

From Rosetta Code
Revision as of 09:43, 24 June 2021 by PureFox (talk | contribs) (Added Go)
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 numbers in base-16 representation that cannot be written with decimal digits, where n < 500



Go

<lang go>package main

import (

   "fmt"
   "strconv"
   "strings"

)

func main() {

   const decimal = "0123456789"
   c := 0
   for i := int64(0); 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)

}</lang>

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.

Ring

<lang 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 </lang>

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...

Wren

Library: Wren-fmt

<lang ecmascript>import "/fmt" for Conv, Fmt

var decimal = "0123456789" var c = 0 for (i in 0..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.")</lang>

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.