Positive decimal integers with the digit 1 occurring exactly twice: Difference between revisions

Content added Content deleted
m (clarified the task in that the numbers are positive decimal integers, and that the integer must contain exactly two '''1''' digits.)
(→‎{{header|REXX}}: added the computer programming language REXX.)
Line 138: Line 138:
119 121 131 141 151 161 171 181 191 211
119 121 131 141 151 161 171 181 191 211
311 411 511 611 711 811 911</pre>
311 411 511 611 711 811 911</pre>

=={{header|REXX}}==
Programming note: &nbsp; 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). */
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. */
p= pos(1, j); if p==0 then iterate /*integer doesn't have a one (1)? Skip.*/ /* ◄■■■■■■■ a filter.*/
p= pos(1, j, p+1); if p==0 then iterate /* " " " a 2nd one? " */ /* ◄■■■■■■■ a filter.*/
p= pos(1, j, p+1); if p>0 then iterate /* " does " a 3rd one? " */ /* ◄■■■■■■■ 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=&nbsp; when using the default inputs:}}
<pre>
index │ positive decimal integers which contain exactly two ones (1s) which are < 1000
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 11 101 110 112 113 114 115 116 117 118
11 │ 119 121 131 141 151 161 171 181 191 211
21 │ 311 411 511 611 711 811 911
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────

Found 27 positive decimal integers which contail exactly two ones (1s) which are < 1000
</pre>


=={{header|Ring}}==
=={{header|Ring}}==