Anonymous user
Positive decimal integers with the digit 1 occurring exactly twice: Difference between revisions
Positive decimal integers with the digit 1 occurring exactly twice (view source)
Revision as of 23:04, 8 July 2021
, 2 years ago→{{header|REXX}}: added a 2nd version.
(→{{header|REXX}}: added the computer programming language REXX.) |
m (→{{header|REXX}}: added a 2nd version.) |
||
Line 140:
=={{header|REXX}}==
=== version 1 ===
Programming note: the three filters (marked below) could've been incorporated into one REXX statement if code golf is the desired goal.
<lang rexx>/*REXX program finds positive decimal integers which contain exactly two ones (1s). */
Line 175 ⟶ 176:
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
Found 27 positive decimal integers which
</pre>
=== version 2 ===
Programming note: not all REXXes have the '''countstr''' BIF.
<lang rexx>/*REXX program finds positive decimal integers which contain exactly two ones (1s). */
parse arg hi cols . /*obtain optional argument from the CL.*/
if HI=='' | HI=="," then HI= 1000 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*width of a number in any column. */
title= ' positive decimal integers which contain exactly two ones (1s) which are <' hi
say ' index │'center(title, 1 + cols*(w+1) )
say '───────┼'center("" , 1 + cols*(w+1), '─')
found= 0; idx= 1 /*initialize # integers and the index. */
$= /*a list of integers found (so far). */
do j=1 for hi-1 /*find positive integers within range. */
if countstr(1, j)\==2 then iterate /*Doesn't have exactly 2 one's? Skip. */ /* ◄■■■■■■■ a filter.*/
found= found + 1 /*bump the number of integers found. */
$= $ right(j, w) /*add an integer to the ──► $ list. */
if found//cols\==0 then iterate /*have we populated a line of output? */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
end /*j*/
/*stick a fork in it, we're all done. */
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' found title</lang>
{{out|output|text= is identical to the 1<sup>st</sup> REXX version.}} <br><br>
=={{header|Ring}}==
|