Anonymous user
List comprehensions: Difference between revisions
m
→horizontal list: changed some comments and whitespace,
m (→horizontal list: changed a (title) comment.) |
m (→horizontal list: changed some comments and whitespace,) |
||
Line 2,105:
===horizontal list===
<lang rexx>/*REXX program shows a horizontal list of Pythagorean triples up to a specified number. */
parse arg n . /*
if n=='' | n=="," then n= 100 /*Not specified? Then use the default.*/
do k=1 for n; @.k= k*k /*precompute the squares of usable #'s.*/
end /*k*/
say 'Pythagorean triples (a² + b² = c², c ≤' n"):" /*display the list's title. */
$= /*assign a null to the triples list. */
do a=1
do
ab= @.a
do c=b+cump to n by cump
if ab<@.c then leave /*Too small? Then try the next B. */
if ab==@.c then do; $=$ '{'a"," || b','c"}"; leave; end
end /*c*/
end /*b*/
end /*a
#= words($)
▲#= words($) /*number of members in the list. */
if p\==0 then do; _= left($, p)
say strip(_)
$= substr($, p+1)
end
end /*j*/
say strip($)
say
say # ' members listed.' /*stick a fork in it, we're all done. */</lang>
{{out|output|text= when using the following input: <tt> 35 </tt>}}
<pre>
|