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

m
m (→‎{{header|Wren}}: Minor tidy)
 
(45 intermediate revisions by 29 users not shown)
Line 4:
Find positive decimal integers   '''n'''   in which the digit   '''1'''   occurs exactly twice,   where   '''n   <   1,000'''.
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">L(n) 1..999
I String(n).count(‘1’) == 2
print(n, end' ‘ ’)</syntaxhighlight>
 
{{out}}
<pre>
11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911 </pre>
 
=={{header|8080 Assembly}}==
<syntaxhighlight lang="asm"> org 100h
loop: lda tho ; Are we there yet?
cpi '0'
rnz
call incr ; If not, increment
lxi b,0203h ; Need two ones, 3 steps
mvi a,'1'
lxi h,acc
ones: cmp m ; Count the ones
jnz $+4
dcr b
dcr c
inx h
jnz ones
xra a ; If two ones, print
ora b
cz prn
jmp loop
 
incr: lxi h,acc ; Increment accumulator
mvi a,'9'+1
incrl: inr m
cmp m
rnz
mvi m,'0'
inx h
jmp incrl
 
prn: lxi h,acc+4 ; Print accumulator w/o leading zero
mvi a,'0'
skip: dcx h
cmp m
jz skip
prl: push h
mvi c,2 ; CP/M print character
mov e,m
call 5
pop h
dcx h
xra a
cmp m
jnz prl
mvi c,9 ; CP/M print newline
lxi d,nl
jmp 5
 
acc: db '000' ; Accumulator (stored backwards)
tho: db '0' ; Thousands digit (stop if not 0 anymore)
nl: db 13,10,'$' ; Newline</syntaxhighlight>
{{out}}
<pre>11
101
110
112
113
114
115
116
117
118
119
121
131
141
151
161
171
181
191
211
311
411
511
611
711
811
911</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">BYTE FUNC OnesCount(INT x)
BYTE c,d
 
c=0
WHILE x#0
DO
d=x MOD 10
IF d=1 THEN
c==+1
FI
x==/10
OD
RETURN (c)
 
PROC Main()
INT i
 
FOR i=0 TO 999
DO
IF OnesCount(i)=2 THEN
PrintI(i) Put(32)
FI
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Positive_decimal_integers_with_the_digit_1_occurring_exactly_twice.png Screenshot from Atari 8-bit computer]
<pre>
11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
 
procedure Positives_With_1_Twice is
 
function One_Twice (N : Positive) return Boolean is
NN : Natural := N;
One_Count : Natural := 0;
begin
while NN > 0 loop
if NN mod 10 = 1 then
One_Count := One_Count + 1;
end if;
NN := NN / 10;
end loop;
return One_Count = 2;
end One_Twice;
 
begin
for N in 1 .. 999 loop
if One_Twice (N) then
Put (N'Image); Put (" ");
end if;
end loop;
New_Line;
end Positives_With_1_Twice;</syntaxhighlight>
{{out}}
<pre>
11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911</pre>
 
=={{header|ALGOL 68}}==
Generates the numbers. In order to print them in order, a table of double 1 numbers yes/no is generated.
<langsyntaxhighlight lang="algol68">BEGIN # find numbers where the digit 1 occurs twice, up to 999 #
[ 1 : 999 ]BOOL double 1; FOR i TO UPB double 1 DO double 1[ i ] := FALSE OD;
# generte the numbers #
Line 25 ⟶ 174:
FI
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 35 ⟶ 184:
=={{header|ALGOL W}}==
Generates the numbers and sorts them into order using [[Sorting algorithms/Quicksort#ALGOL W]].
<langsyntaxhighlight lang="algolw">begin % find numbers where the digit 1 occurs twice, up to 999 %
integer double1Count;
integer array double1 ( 1 :: 100 ); % assume there will be at most 100 numbers %
Line 59 ⟶ 208:
write();
write( i_w := 1, s_w := 0, "Found ", double1Count, " numbers" )
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 66 ⟶ 215:
Found 27 numbers
</pre>
=={{header|APL}}==
<syntaxhighlight lang="apl">(⊢(/⍨)(2='1'+.=⍕)¨) ⍳1000</syntaxhighlight>
{{out}}
<pre>11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">prints [11 101 110]
loop 2..9 'd -> prints ~"|d|11 1|d|1 11|d| "</syntaxhighlight>
 
{{out}}
 
<pre>11 101 110 211 121 112 311 131 113 411 141 114 511 151 115 611 161 116 711 171 117 811 181 118 911 191 119</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f NUMBERS_N_IN_WHICH_NUMBER_1_OCCUR_TWICE.AWK
BEGIN {
start = 1
stop = 999
for (i=start; i<=stop; i++) {
if (gsub(/1/,"&",i) == 2) {
printf("%4d%1s",i,++count%10?"":"\n")
}
}
printf("\nNumber 1 occurs twice %d-%d: %d\n",start,stop,count)
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
11 101 110 112 113 114 115 116 117 118
119 121 131 141 151 161 171 181 191 211
311 411 511 611 711 811 911
Number 1 occurs twice 1-999: 27
</pre>
 
=={{header|COBOL}}==
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. TWO-ONES.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 NUM PIC 9999.
77 FMT PIC ZZ9.
77 ONES PIC 9.
PROCEDURE DIVISION.
BEGIN.
PERFORM COUNT-ONES
VARYING NUM FROM 1 BY 1 UNTIL NUM IS EQUAL TO 1000.
STOP RUN.
COUNT-ONES.
MOVE ZERO TO ONES.
INSPECT NUM TALLYING ONES FOR ALL '1'.
IF ONES IS EQUAL TO 2,
MOVE NUM TO FMT,
DISPLAY FMT.</syntaxhighlight>
{{out}}
<pre> 11
101
110
112
113
114
115
116
117
118
119
121
131
141
151
161
171
181
191
211
311
411
511
611
711
811
911</pre>
 
=={{header|Delphi}}==
''See [[#Pascal|Pascal]]''
 
=={{header|Euler}}==
As with the Arturo, F# etc. samples, generates the sequence but doesn't sort it into order.
'''begin''' '''new''' dPos; '''new''' non1digits; '''label''' digitLoop;
non1digits &lt;- ( 0, 2, 3, 4, 5, 6, 7, 8, 9 );
dPos &lt;- 0;
digitLoop: '''if''' [ dPos &lt;- dPos + 1 ] &lt;= '''length''' non1digits '''then''' '''begin'''
'''new''' d;
d &lt;- non1digits[ dPos ];
'''out''' [ d * 100 ] + 11; '''out''' [ d * 10 ] + 101; '''out''' 110 + d;
'''goto''' digitLoop
'''end''' '''else''' 0
'''end''' $
{{out}}
<pre>
NUMBER 11
NUMBER 101
NUMBER 110
NUMBER 211
NUMBER 121
NUMBER 112
NUMBER 311
NUMBER 131
NUMBER 113
NUMBER 411
NUMBER 141
NUMBER 114
NUMBER 511
NUMBER 151
NUMBER 115
NUMBER 611
NUMBER 161
NUMBER 116
NUMBER 711
NUMBER 171
NUMBER 117
NUMBER 811
NUMBER 181
NUMBER 118
NUMBER 911
NUMBER 191
NUMBER 119
</pre>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// 3 digit numbers with 2 ones. Nigel Galloway: July 6th., 2021
[0;2;3;4;5;6;7;8;9]|>List.collect(fun g->[[g;1;1];[1;g;1];[1;1;g]])|>List.iter(fun(n::g::l::_)->printf "%d " (n*100+g*10+l)); printfn ""
</syntaxhighlight>
{{out}}
<pre>
11 101 110 211 121 112 311 131 113 411 141 114 511 151 115 611 161 116 711 171 117 811 181 118 911 191 119
</pre>
 
=={{header|Factor}}==
{{trans|F#}}
{{works with|Factor|0.99 2021-06-02}}
<syntaxhighlight lang="factor">USING: io math math.functions prettyprint sequences
sequences.extras ;
 
{ 0 2 3 4 5 6 7 8 9 }
[| n | { { n 1 1 } { 1 n 1 } { 1 1 n } } ] map-concat
[ <reversed> 0 [ 10^ * + ] reduce-index pprint bl ] each nl</syntaxhighlight>
{{out}}
<pre>
11 101 110 211 121 112 311 131 113 411 141 114 511 151 115 611 161 116 711 171 117 811 181 118 911 191 119
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">function numdig(byval n as integer, d as const integer) as uinteger
'counts the number of occurrences of digit d in the number n
dim as uinteger m = 0
while n
if n mod 10 = d then m+=1
n\=10
wend
return m
end function
 
for i as uinteger = 1 to 999
if numdig(i, 1) = 2 then print i;" ";
next i
print</syntaxhighlight>
{{out}}<pre>11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911</pre>
 
=={{header|Free Pascal}}==
''See [[#Pascal|Pascal]]''
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 99 ⟶ 425:
}
fmt.Println("\n\nFound", len(results), "such numbers.")
}</langsyntaxhighlight>
 
{{out}}
Line 110 ⟶ 436:
 
Found 27 such numbers.
</pre>
 
=={{header|J}}==
Generating the numbers as the cartesian product of the eligible digits (and sorting the result, for "prettiness"):
<syntaxhighlight lang="j"> ~./:~10 #. >,{~.(2 1#1;i.10){~(! A.&i. ])3
11 101 110 111 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911</syntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
This entry contains two solutions: the first is fast for this problem, but algorithmically inefficient;
the second uses `countEquals` so candidates can be discarded quickly. The output is the same in both cases and so is shown only once.
 
'''Using `count`'''
<syntaxhighlight lang="jq">def count(s): reduce s as $x (0; .+1);
 
range(1;1000)
| select( tostring | explode | 2 == count( select(.[] == 49))) # "1"</syntaxhighlight>
'''Using `countEquals`'''
<syntaxhighlight lang="jq">def countEquals($n; s):
label $out
| foreach (s, null) as $x (-1;
. + 1;
if $x == null then . == $n
elif . > $n then false, break $out
else empty
end);
range(1;1000)
| select( tostring
| countEquals(2; select(explode[] == 49))) # "1"</syntaxhighlight>
{{out}}
<pre>
11
101
110
112
113
114
115
116
117
118
119
121
131
141
151
161
171
181
191
211
311
411
511
611
711
811
911
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">totalddigisn(x, d = 1, n = 2; base=10) = count(j -> j == d, digits(x; base)) == n
 
println(filter(totalddigisn, 1:1000))
</syntaxhighlight>{{out}}
<pre>
[11, 101, 110, 112, 113, 114, 115, 116, 117, 118, 119, 121, 131, 141, 151, 161, 171, 181, 191, 211, 311, 411, 511, 611, 711, 811, 911]
</pre>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">sol = Cases[Range[999], _?(Count[IntegerDigits@#, 1] == 2 &)];
Partition[sol, Max[FactorInteger[Length@sol][[All, 1]]]] // TableForm</syntaxhighlight>
 
{{out}}<pre>
11 101 110
112 113 114
115 116 117
118 119 121
131 141 151
161 171 181
191 211 311
411 511 611
711 811 911
</pre>
 
=={{header|Ksh}}==
<syntaxhighlight lang="ksh">
#!/bin/ksh
 
# Positive decimal integers with the digit 1 occurring twice
 
# # Variables:
#
integer MAX=999
 
# # Functions:
#
 
 
######
# main #
######
 
for ((i=10; i<MAX; i++)); do
[[ ${i} == *{2}(1)* ]] && printf "%d " ${i}
done
echo</syntaxhighlight>
{{out}}<pre>11 110 111 112 113 114 115 116 117 118 119 211 311 411 511 611 711 811 911
</pre>
 
=={{header|MiniZinc}}==
<syntaxhighlight lang="minizinc">
%Permutations with some identical elements. Nigel Galloway: July 6th., 2021
include "count.mzn";
array [1..3] of var 0..9: N; constraint count(N,1,2);
output [show((N[1]*100)+(N[2]*10)+N[3])]
</syntaxhighlight>
{{out}}
<pre>
110
----------
101
----------
11
----------
211
----------
311
----------
411
----------
511
----------
611
----------
711
----------
811
----------
911
----------
121
----------
131
----------
141
----------
151
----------
161
----------
171
----------
181
----------
191
----------
112
----------
113
----------
114
----------
115
----------
116
----------
117
----------
118
----------
119
----------
==========
Finished in 206msec
</pre>
=={{header|Nim}}==
<syntaxhighlight lang="nim">import sugar, strutils
 
let result = collect(newSeq):
for n in 1..<1000:
if count($n, '1') == 2: n
echo "Found ", result.len, " numbers:"
echo result.join(" ")</syntaxhighlight>
 
{{out}}
<pre>Found 27 numbers:
11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911</pre>
=={{header|Pascal}}==
<syntaxhighlight lang="pascal">program positiveDecimalIntegersWithTheDigit1occurringExactlyTwice(output);
var
n: integer;
begin
for n := 1 to 999 do
begin
if ord(n mod 10 = 1) + ord(n mod 100 div 10 = 1) + ord(n div 100 = 1) = 2 then
begin
writeLn(n)
end
end
end.</syntaxhighlight>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Numbers_n_in_which_number_1_occur_twice
use warnings;
 
my @twoones = grep tr/1// =~ 2, 1 .. 1000;
print "@twoones\n" =~ s/.{60}\K /\n/gr;</syntaxhighlight>
{{out}}
<pre>
11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161
171 181 191 211 311 411 511 611 711 811 911
</pre>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">two_ones</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">find_all</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'1'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">))=</span><span style="color: #000000;">2</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">999</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">),</span><span style="color: #000000;">two_ones</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d found:\n %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n "</span><span style="color: #0000FF;">)})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 125 ⟶ 667:
191 211 311 411 511 611 711 811 911
</pre>
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">int main() {
int limit = 1000;
 
for(int i = 0; i < limit + 1; i++) {
if(String.count((string)i, "1") == 2) {
write((string)i + " ");
}
}
write("\n");
 
return 0;
}</syntaxhighlight>
{{out}}
<pre>11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911</pre>
 
=={{header|PL/M}}==
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<syntaxhighlight lang="plm">
100H: /* FIND NUMBERS BELOW 1000 WHERE 1 OCCURS TWICE IN THIER DECIMAL */
/* REPRESENTATION */
 
/* CP/M SYSTEM CALL AND I/O ROUTINES */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
 
/* TASK */
DECLARE ( I, V, COUNT, ONE$COUNT ) ADDRESS;
COUNT = 0;
DO I = 10 TO 999;
V = I;
ONE$COUNT = 0;
DO WHILE V > 0;
IF V MOD 10 = 1 THEN DO;
ONE$COUNT = ONE$COUNT + 1;
END;
V = V / 10;
END;
IF ONE$COUNT = 2 THEN DO;
CALL PR$CHAR( ' ' );
IF I < 100 THEN CALL PR$CHAR( ' ' );
CALL PR$NUMBER( I );
IF ( COUNT := COUNT + 1 ) MOD 10 = 0 THEN CALL PR$NL;
END;
END;
 
EOF
</syntaxhighlight>
{{out}}
<pre>
11 101 110 112 113 114 115 116 117 118
119 121 131 141 151 161 171 181 191 211
311 411 511 611 711 811 911
</pre>
 
=={{header|PROMAL}}==
<syntaxhighlight lang="promal">
;;; find numbers below 1000 where 1 occurs twice in their decimal representation
PROGRAM oneTwice
INCLUDE LIBRARY
 
WORD i
WORD v
WORD count
WORD oneCount
 
BEGIN
count = 0
FOR i = 10 TO 999
v = i
oneCount = 0
WHILE v > 0
IF v % 10 = 1
oneCount = oneCount + 1
v = v / 10
IF oneCount = 2
OUTPUT " #3I", i
count = count + 1
IF count % 10 = 0
OUTPUT "#C"
END
</syntaxhighlight>
{{out}}
<pre>
11 101 110 112 113 114 115 116 117 118
119 121 131 141 151 161 171 181 191 211
311 411 511 611 711 811 911
</pre>
 
=={{header|Python}}==
<syntaxhighlight lang="python">
#Aamrun, 5th October 2021
 
from itertools import permutations
 
for i in range(0,10):
if i!=1:
baseList = [1,1]
baseList.append(i)
[print(int(''.join(map(str,j)))) for j in sorted(set(permutations(baseList)))]
</syntaxhighlight>
{{out}}
<pre>
11
101
110
112
121
211
113
131
311
114
141
411
115
151
511
116
161
611
117
171
711
118
181
811
119
191
911
</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ 0 swap
[ dup 0 != while
10 /mod 1 = if
[ dip 1+ ]
again ]
drop 2 = ] is two-1s ( n --> b )
 
[] 1000 times
[ i^ two-1s if
[ i^ join ] ]
echo</syntaxhighlight>
 
{{out}}
 
<pre>[ 11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911 ]</pre>
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>say display 10, '%3d', ^1000 .grep: { .comb.Bag{'1'} == 2 };
 
sub display {
cache $^c;
"{+$c} matching:\n" ~ $c.batch($^a)».fmt($^b).join: "\n"
}</langsyntaxhighlight>
{{out|Yields}}
<pre>27 matching:
Line 142 ⟶ 848:
=== version 1 ===
Programming note: &nbsp; the three filters (marked below) could've been incorporated into one REXX statement if code golf is the desired goal.
<langsyntaxhighlight 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.*/
Line 166 ⟶ 872:
say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' found title</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 181 ⟶ 887:
=== version 2 ===
Programming note: &nbsp; &nbsp; not all REXXes have the &nbsp; '''countstr''' &nbsp; BIF.
<langsyntaxhighlight 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.*/
Line 203 ⟶ 909:
say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' found title</langsyntaxhighlight>
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
see "working..." + nl
Line 234 ⟶ 940:
sum = 0
while substr(cstring,dstring) > 0
sum = sum + 1+
cstring = substr(cstring,substr(cstring,dstring)+len(string(sum)))
end
return sum
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 251 ⟶ 957:
Found 27 numbers
done...
</pre>
 
=={{header|RPL}}==
≪ →STR 0
1 3 PICK SIZE '''FOR''' j
OVER j DUP SUB "1" == + '''NEXT'''
SWAP DROP 2 ==
≫ '<span style="color:blue">ONLY2?</span>' STO
≪ { }
1 1000 '''FOR''' j
'''IF''' j <span style="color:blue">ONLY2?</span> '''THEN''' j + '''END NEXT'''
≫ EVAL
 
{{out}}
<pre>
1: { 11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911 }
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">p (1..1000).select{|n| n.digits.count(1) == 2}
</syntaxhighlight>
{{out}}
<pre>
[11, 101, 110, 112, 113, 114, 115, 116, 117, 118, 119, 121, 131, 141, 151, 161, 171, 181, 191, 211, 311, 411, 511, 611, 711, 811, 911]
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program two_ones;
print([n : n in [1..999] | 2 = #[d : d in str n | val d = 1]]);
end program;</syntaxhighlight>
{{out}}
<pre>[11 101 110 112 113 114 115 116 117 118 119 121 131 141 151 161 171 181 191 211 311 411 511 611 711 811 911]</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">say (1..1000 -> grep { .digits.count { _ == 1 } == 2 })</syntaxhighlight>
{{out}}
<pre>
[11, 101, 110, 112, 113, 114, 115, 116, 117, 118, 119, 121, 131, 141, 151, 161, 171, 181, 191, 211, 311, 411, 511, 611, 711, 811, 911]
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
import "./seqfmt" for LstFmt
import "/fmt" for Fmt
 
System.print("Decimal numbers under 1,000 whose digits include two 1's:")
var results = (11..911).where { |i| Int.digits(i).count { |d| d == 1 } == 2 }.toList
Fmt.tprint("$5d", results, 7)
for (chunk in Lst.chunks(results, 7)) Fmt.print("$5d", chunk)
System.print("\nFound %(results.count) such numbers.")</langsyntaxhighlight>
 
{{out}}
Line 278 ⟶ 1,021:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func Ones(N); \Return count of 1's in N
int N, Count;
[Count:= 0;
Line 298 ⟶ 1,041:
Text(0, " such numbers found below 1000.
");
]</langsyntaxhighlight>
 
{{out}}
9,476

edits