Anonymous user
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=
do j=1 for words($); #= word($, j)
parse value pells(#) with x y
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*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
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= when using the default inputs:}}
<pre>
x^2 - 61 * y^2 == 1 when x=
x^2 - 109 * y^2 == 1 when x=
x^2 - 181 * y^2 == 1 when x=
x^2 - 277 * y^2 == 1 when x=
</pre>
|