Permuted multiples

From Rosetta Code
Revision as of 07:05, 17 August 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task:Find the smallest positive integer '''n''' such that 2*n, 3*n, 4*n, 5*n, and 6*n contain the same digits. <br><br> =={{header|Ring}}== <lang ring> load...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Permuted multiples 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 the smallest positive integer n such that 2*n, 3*n, 4*n, 5*n, and 6*n contain the same digits.



Ring

<lang ring> load "stdlib.ring"

see "working..." + nl see "Permuted multiples are:" + nl perm2 = [] perm3 = [] perm4 = [] perm5 = [] perm6 = []

for n = 1 to 1000000

   perm2 = []
   perm3 = []
   perm4 = []
   perm5 = []
   perm6 = []
   per2 = 2*n
   perStr2 = string(per2)
   for m = 1 to len(perStr2)
       add(perm2,perStr2[m])
   next
   per3 = 3*n
   perStr3 = string(per3)
   for m = 1 to len(perStr3)
       add(perm3,perStr3[m])
   next
   per4 = 4*n
   perStr4 = string(per4)
   for m = 1 to len(perStr4)
       add(perm4,perStr4[m])
   next
   per5 = 5*n
   perStr5 = string(per5)
   for m = 1 to len(perStr5)
       add(perm5,perStr5[m])
   next
   per6 = 6*n
   perStr6 = string(per6)
   for m = 1 to len(perStr6)
       add(perm6,perStr6[m])
   next
   perm2 = sort(perm2)
   perm3 = sort(perm3)
   perm4 = sort(perm4)
   perm5 = sort(perm5)
   perm6 = sort(perm6)
   perStr2 = list2str(perm2)
   perStr3 = list2str(perm3)
   perStr4 = list2str(perm4)
   perStr5 = list2str(perm5)
   perStr6 = list2str(perm6)
   perStr2 = substr(perStr2,nl,"")
   perStr3 = substr(perStr3,nl,"")
   perStr4 = substr(perStr4,nl,"")
   perStr5 = substr(perStr5,nl,"")
   perStr6 = substr(perStr6,nl,"")
   
   if perStr2 = perStr3 and perStr2 = perStr4 and perStr2 = perStr5 and perStr2 = perStr6
      see "n = " + n + nl
      see "2*n = " + (n*2) + nl
      see "3*n = " + (n*3) + nl
      see "4*n = " + (n*4) + nl
      see "5*n = " + (n*5) + nl
      see "6*n = " + (n*6) + nl
      exit
   ok

next

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

Output:
working...
Permuted multiples are:
n   = 142857
2*n = 285714
3*n = 428571
4*n = 571428
5*n = 714285
6*n = 857142
done...