Positive decimal integers with the digit 1 occurring exactly twice

From Rosetta Code
Revision as of 09:44, 8 July 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task:Find numbers '''n''' in which number '''1''' occur twice, where '''n < 1,000''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib.ring" see "workin...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Positive decimal integers with the digit 1 occurring exactly twice 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 n in which number 1 occur twice, where n < 1,000



Ring

<lang ring> load "stdlib.ring" see "working..." + nl see "Numbers n in which number 1 occur twice:" + nl

row = 0 sum = 0 limit = 1000

for n = 1 to limit

   strn = string(n)
   ind = count(strn,"1")
   if ind = 2
      see "" + n + " " 
      row = row + 1
      if row%5 = 0
         see nl
      ok
   ok

next

see nl + "Found " + row + " numbers" + nl see "done..." + nl

func count(cstring,dstring)

    sum = 0
    while substr(cstring,dstring) > 0
          sum = sum + 1
          cstring = substr(cstring,substr(cstring,dstring)+len(string(sum)))
    end
    return sum

</lang>

Output:
working...
Numbers n in which number 1 occur twice:
11 101 110 112 113 
114 115 116 117 118 
119 121 131 141 151 
161 171 181 191 211 
311 411 511 611 711 
811 911 
Found 27 numbers
done...