Numbers with same digit set in base 10 and base 16: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "{{Draft task}} ;Task:Find decimal numbers that when converted to '''hexadecimal''' produce a number that uses the same digits as the original number. <br><br> =={{header|Ri...")
 
No edit summary
Line 1: Line 1:
{{Draft task}}
{{Draft task}}


;Task:Find decimal numbers that when converted to '''hexadecimal''' produce a number that uses the same digits as the original number.
;Task:Find decimal numbers '''n''' that when converted to '''hexadecimal''' produce a number that uses the same digits as the original number, where '''n < 100000'''


<br><br>
<br><br>

Revision as of 07:12, 6 June 2021

Numbers with same digit set in base 10 and base 16 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 decimal numbers n that when converted to hexadecimal produce a number that uses the same digits as the original number, where n < 100000



Ring

<lang ring> see "working..." + nl

row = 0 limit = 100000

for n = 0 to limit

   flag1 = 1
   flag2 = 1
   decStr = string(n)
   hexStr = hex(n)
   for m = 1 to len(decStr)
       ind = substr(hexStr,decStr[m])
       if ind < 1
          flag1 = 0
          exit
       ok
   next
   for p = 1 to len(hexStr)
       ind = substr(decStr,hexStr[p])
       if ind < 1
          flag2 = 0
          exit
       ok
   next
   if flag1 = 1 and flag2 = 1
      row = row + 1
      see "" + n + " "
      if row%5 = 0
         see nl
      ok
   ok

next

see nl + "done..." + nl </lang>

Output:
working...
0 1 2 3 4 
5 6 7 8 9 
53 371 913 1040 2080 
2339 4100 5141 5412 5441 
6182 8200 9241 13593 13665 
13969 16406 20530 26946 30979 
32803 33638 33840 33841 33842 
33843 33844 33845 33846 33847 
33848 33849 34883 37943 38931 
38966 38995 66310 71444 71497 
71511 75120 75121 75122 75123 
75124 75125 75126 75127 75128 
75129 75621 86150 88165 91465 
91769 96617 98711 99481 
done...