Smallest square that begins with n

From Rosetta Code
Revision as of 08:10, 19 March 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task Find smallest squares that begin with n for 0 < n < 50 =={{header|Ring}}== <lang ring> load "stdlib.ring" see "working..." + nl see "smallest squares t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Smallest square that begins with n 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 smallest squares that begin with n for 0 < n < 50

Ring

<lang ring> load "stdlib.ring"

see "working..." + nl see "smallest squares that begin with n:" + nl

row = 0 limit1 = 49 limit2 = 45369

for n = 1 to limit1

   strn = string(n)
   lenn = len(strn)
   for m = 1 to limit2
       floor = sqrt(m)
       bool = (m % floor = 0)
       strm = string(m)
       if left(strm,lenn) = n and bool = 1
          row = row + 1
          see "" + strm + " "
          if row%5 = 0
             see nl
          ok
          exit
       ok
    next

next

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

Output:
working...
smallest squares that begin with n:
1 25 36 4 529 
64 729 81 9 100 
1156 121 1369 144 1521 
16 1764 1849 196 2025 
2116 225 2304 2401 25 
2601 2704 289 2916 3025 
3136 324 3364 3481 35344 
36 3721 3844 3969 400 
41209 4225 4356 441 45369 
4624 4761 484 49 
done...