Minimum positive multiple in base 10 using only 0 and 1: Difference between revisions

m
J: handle 1 exception differently (less efficient when y=1, but demonstrates the underlying equalities (and efficiency when y=1 is not a problem))
m (J: handle 1 exception differently (less efficient when y=1, but demonstrates the underlying equalities (and efficiency when y=1 is not a problem)))
Line 1,240:
 
<lang J>B10=: {{ NB. https://oeis.org/A004290
if. 1=y do. 1 return.end.
next=. {{ {: (u -) 10x^# }}
step=. ([>. [ {~ y|(i.y)+]) next
continue=. 0 = ({~y|]) next
L=. 1 0,~^:(y>1) (, step)^:continue^:_ ,:y{.1 1
k=. y|-r=.10x^<:#L
for_j. i.-<:#L do.
Line 1,252 ⟶ 1,251:
end.
end. r assert. 0=y|r
}}</lang>
</lang>
 
Task example:
6,962

edits