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

m
(Add APL)
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 13:
<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!}}==
Line 921 ⟶ 1,000:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">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.")</syntaxhighlight>
 
9,476

edits