Jump to content

Pell's equation: Difference between revisions

m
→‎{{header|REXX}}: added commas to the huge numbers, simplified the SAY expressions for the output of X and Y.
(→‎{{header|Python}}: It's far more Pythonic to use multiple assignment than a helper method which uses arrays for pass-by-reference)
m (→‎{{header|REXX}}: added commas to the huge numbers, simplified the SAY expressions for the output of X and Y.)
Line 962:
 
=={{header|REXX}}==
A little extra code was added to align and commatize the gihugeic numbers for readability.
<lang rexx>/*REXX program to solve Pell's equation for the smallest solution of positive integers. */
numeric digits 2200 /*ensure enough decimal digs for answer*/
parse arg $ /*obtain optional arguments from the CL*/
if $=='' | $=="," then $= 61 109 181 277 /*Not specified? Then use the defaults*/
d= 2228 /*used for aligning the output numbers.*/
do j=1 for words($); #= word($, j) /*process all the numbers in the list. */
parse value pells(#) with x y /*extract the two values of X and Y.*/
say 'x^2cx= -'rightcomma(#,max(4,x); Lcx= length(#))cx); "* y^2 =cy= 1 comma(y); when x Lcy="right(x, max(d,length(x)cy); L#= length(#),
say 'x^2 -'right(#, max(4, L#)) "* y^2 == 1" ,
' and y='right(y, max(d,length(y)))
' when x='right(cx, max(d, Lcx)) " and y="right(cy, max(d, Lcy))
end /*j*/
exit /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're andall y='right(y,done. max(d,length(y)))*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
comma: parse arg ?; do jc=length(?)-3 to 1 by -3; ?= insert(',', ?, jc); end; return ?
floor: procedure; parse arg x; _= x % 1; return _ - (x < 0) * (x \= _)
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 993 ⟶ 996:
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
x^2 - 61 * y^2 == 1 when x= 1766319049 1,766,319,049 and y= 226153980 226,153,980
x^2 - 109 * y^2 == 1 when x= 158070671986249 158,070,671,986,249 and y= 15140424455100 15,140,424,455,100
x^2 - 181 * y^2 == 1 when x= 24696454238241858012,469,645,423,824,185,801 and y= 183567298683461940 183,567,298,683,461,940
x^2 - 277 * y^2 == 1 when x= 159150073798980475849159,150,073,798,980,475,849 and y= 95624011738780270209,562,401,173,878,027,020
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.