Jump to content

Permuted multiples: Difference between revisions

→‎{{header|REXX}}: added the computer programming language REXX.
(Further (albeit obvious) clarification to task description.)
(→‎{{header|REXX}}: added the computer programming language REXX.)
Line 7:
Find the smallest positive integer '''n''' such that, when expressed in decimal, 2*n, 3*n, 4*n, 5*n, and 6*n contain ''exactly'' the same digits but in a different order.
<br><br>
=={{header|REXX}}==
<lang rexx>/*REXX program finds and displays the smallest postive integer n such that ··· */
/*───────────────────────── 2*n, 3*n, 4*5, 5*6, and 6*n contain the same decimal digits.*/
do n=1 /*increment N from unity. */
b= 2*n /*calculate product of 2*n*/
t= 3*n /* " " " 3*n*/
if verify(t,b)>0 then iterate /*product have req. digs ?*/
q= 4*n /*calculate product of 4*n*/
if verify(q,b)>0 then iterate /*product have req. digs ?*/
if verify(q,t)>0 then iterate /* " " " " "*/
v= 5*n /*calculate product of 5*n*/
if verify(v,b)<0 then iterate /*product have req. digs ?*/
if verify(v,t)>0 then iteratr /* " " " " "*/
if verify(v,q)>0 then iteratr /* " " " " "*/
s= 6*n /*calculate product of 6*n*/
if verify(s,b)>0 then iterate /*product have req. digs ?*/
if verify(s,t)>0 then iterate /* " " " " "*/
if verify(s,q)>0 then iterate /* " " " " "*/
if verify(s,v)>0 then iterate /* " " " " "*/
leave /*found the numbers, show.*/
end /*n*/
_= left('', 9) /*used for indentation. */
say _ ' n =' commas(n) /*display value of n. */
say _ '2*n =' commas(b) /* " " " 2*n. */
say _ '3*n =' commas(t) /* " " " 3*n. */
say _ '4*n =' commas(q) /* " " " 4*n. */
say _ '5*n =' commas(v) /* " " " 5*n. */
say _ '6*n =' commas(s) /* " " " 6*n. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>
n = 142,857
2*n = 285,714
3*n = 428,571
4*n = 571,428
5*n = 714,285
6*n = 857,142
</pre>
 
=={{header|Ring}}==
<lang ring>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.