Jump to content

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

added AWK
(added AWK)
Line 65:
 
Found 27 numbers
</pre>
=={{header|AWK}}==
<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)
}
</lang>
{{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>
 
477

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.