Coprimes: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "{{Draft task}} ;Task: p and q are coprimes if they have no common factors other than 1. Let input: [21,15],[17,23],[36,12],[18,29],[60,15] <br><br> =={{header|Ring}}== <lang...")
 
No edit summary
Line 3: Line 3:
;Task:
;Task:
p and q are coprimes if they have no common factors other than 1.
p and q are coprimes if they have no common factors other than 1.
Let input: [21,15],[17,23],[36,12],[18,29],[60,15]
<br>Let input: [21,15],[17,23],[36,12],[18,29],[60,15]
<br><br>
<br><br>



Revision as of 11:35, 20 April 2021

Coprimes 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

p and q are coprimes if they have no common factors other than 1.
Let input: [21,15],[17,23],[36,12],[18,29],[60,15]

Ring

<lang ring> see "working..." + nl see "Coprimes are:" + nl see "p q" + nl row = 0 Coprimes = [[21,15],[17,23],[36,12],[18,29],[60,15]]

lncpr = len(Coprimes) for n = 1 to lncpr

   flag = 1
   if Coprimes[n][1] < Coprimes[n][2]
      test = Coprimes[n][1]
   else
      test = Coprimes[n][2]
   ok
   for m = 2 to test
       if Coprimes[n][1]%m = 0 and Coprimes[n][2]%m = 0 
          flag = 0
          exit
       ok 
   next  
   if flag = 1
      row = row + 1
      see "" + Coprimes[n][1] + " " + Coprimes[n][2] + nl
   ok     

next

see "Found " + row + " coprimes" + nl see "done..." + nl </lang>

Output:
working...
Coprimes are:
p q
17 23
18 29
Found 2 coprimes
done...