Smallest square that begins with n: Difference between revisions
→{{header|TXR}}: Condense vertically; don't fill [out 0] which is not required.
(→{{header|TXR}}: New section.) |
(→{{header|TXR}}: Condense vertically; don't fill [out 0] which is not required.) |
||
Line 2,395:
We generate successive squares using a recurrence relation.
We also avoid doing a <code>starts-with</code> test using digits. Rather, we take each successive square and begin repeatedly dividing it by 10, with a truncating division. Whenever the quotient fits into the range 0 to 49 (valid index for our output table) we check whether the entry at that position is <code>nil</code>. If so, this is the smallest square which begins with the digits of that position and we put it into the table there. When
<syntaxhighlight lang="txrlisp">(for ((cnt 49) (n 1) (sq 1) (st 2) (out (vector 50)))
((plusp cnt) (
(put-line (pic "## ########" x [out x]))))▼
▲ (put-line (pic "## ########" x [out x]))))
(let ((xsq sq))
(while* (plusp xsq)
Line 2,465 ⟶ 2,459:
48 484
49 49</pre>
=={{header|VTL-2}}==
|