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 01:59, 28 August 2022
, 1 year agosyntax highlighting fixup automation
m (→{{header|J}}: last edit comment should have said "discard duplicates...") |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 6:
=={{header|11l}}==
<
I String(n).count(‘1’) == 2
print(n, end' ‘ ’)</
{{out}}
Line 15:
=={{header|Action!}}==
<
BYTE c,d
Line 38:
FI
OD
RETURN</
{{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]
Line 46:
=={{header|Ada}}==
<
procedure Positives_With_1_Twice is
Line 70:
end loop;
New_Line;
end Positives_With_1_Twice;</
{{out}}
<pre>
Line 77:
=={{header|ALGOL 68}}==
Generates the numbers. In order to print them in order, a table of double 1 numbers yes/no is generated.
<
[ 1 : 999 ]BOOL double 1; FOR i TO UPB double 1 DO double 1[ i ] := FALSE OD;
# generte the numbers #
Line 95:
FI
OD
END</
{{out}}
<pre>
Line 105:
=={{header|ALGOL W}}==
Generates the numbers and sorts them into order using [[Sorting algorithms/Quicksort#ALGOL W]].
<
integer double1Count;
integer array double1 ( 1 :: 100 ); % assume there will be at most 100 numbers %
Line 129:
write();
write( i_w := 1, s_w := 0, "Found ", double1Count, " numbers" )
end.</
{{out}}
<pre>
Line 137:
</pre>
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f NUMBERS_N_IN_WHICH_NUMBER_1_OCCUR_TWICE.AWK
BEGIN {
Line 150:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 163:
=={{header|F_Sharp|F#}}==
<
// 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>
Line 175:
{{trans|F#}}
{{works with|Factor|0.99 2021-06-02}}
<
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</
{{out}}
<pre>
Line 187:
=={{header|FreeBASIC}}==
<
'counts the number of occurrences of digit d in the number n
dim as uinteger m = 0
Line 200:
if numdig(i, 1) = 2 then print i;" ";
next i
print</
{{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>
Line 209:
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 238:
}
fmt.Println("\n\nFound", len(results), "such numbers.")
}</
{{out}}
Line 253:
=={{header|J}}==
Generating the numbers as the cartesian product of the eligible digits (and sorting the result, for "prettiness"):
<
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</
=={{header|jq}}==
Line 264:
'''Using `count`'''
<
range(1;1000)
| select( tostring | explode | 2 == count( select(.[] == 49))) # "1"</
'''Using `countEquals`'''
<
label $out
| foreach (s, null) as $x (-1;
Line 280:
range(1;1000)
| select( tostring
| countEquals(2; select(explode[] == 49))) # "1"</
{{out}}
<pre>
Line 313:
=={{header|Julia}}==
<
println(filter(totalddigisn, 1:1000))
</
<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}}==
<
Partition[sol, Max[FactorInteger[Length@sol][[All, 1]]]] // TableForm</
{{out}}<pre>
Line 337:
=={{header|Ksh}}==
<
#!/bin/ksh
Line 357:
[[ ${i} == *{2}(1)* ]] && printf "%d " ${i}
done
echo</
{{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>
Line 428:
</pre>
=={{header|Nim}}==
<
let result = collect(newSeq):
Line 434:
if count($n, '1') == 2: n
echo "Found ", result.len, " numbers:"
echo result.join(" ")</
{{out}}
Line 440:
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}}==
<
var
n: integer;
Line 451:
end
end
end.</
=={{header|Perl}}==
<
use strict; # https://rosettacode.org/wiki/Numbers_n_in_which_number_1_occur_twice
Line 460:
my @twoones = grep tr/1// =~ 2, 1 .. 1000;
print "@twoones\n" =~ s/.{60}\K /\n/gr;</
{{out}}
<pre>
Line 468:
=={{header|Phix}}==
<!--<
<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>
<!--</
{{out}}
<pre>
Line 482:
=={{header|Pike}}==
<
int limit = 1000;
Line 493:
return 0;
}</
{{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}}==
<
#Aamrun, 5th October 2021
Line 508:
baseList.append(i)
[print(int(''.join(map(str,j)))) for j in sorted(set(permutations(baseList)))]
</syntaxhighlight>
{{out}}
<pre>
Line 541:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
sub display {
cache $^c;
"{+$c} matching:\n" ~ $c.batch($^a)».fmt($^b).join: "\n"
}</
{{out|Yields}}
<pre>27 matching:
Line 556:
=== version 1 ===
Programming note: the three filters (marked below) could've been incorporated into one REXX statement if code golf is the desired goal.
<
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/
Line 580:
say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' found title</
{{out|output|text= when using the default inputs:}}
<pre>
Line 595:
=== version 2 ===
Programming note: not all REXXes have the '''countstr''' BIF.
<
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 1000 /*Not specified? Then use the default.*/
Line 617:
say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' found title</
{{out|output|text= is identical to the 1<sup>st</sup> REXX version.}} <br><br>
=={{header|Ring}}==
<
load "stdlib.ring"
see "working..." + nl
Line 652:
end
return sum
</syntaxhighlight>
{{out}}
<pre>
Line 668:
=={{header|Sidef}}==
<
{{out}}
<pre>
Line 678:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<
import "/seq" for Lst
import "/fmt" for Fmt
Line 685:
var results = (11..911).where { |i| Int.digits(i).count { |d| d == 1 } == 2 }.toList
for (chunk in Lst.chunks(results, 7)) Fmt.print("$5d", chunk)
System.print("\nFound %(results.count) such numbers.")</
{{out}}
Line 699:
=={{header|XPL0}}==
<
int N, Count;
[Count:= 0;
Line 719:
Text(0, " such numbers found below 1000.
");
]</
{{out}}
|