Knuth's power tree: Difference between revisions
m
J: create J section
(→{{header|Python}}: simplify a little) |
m (J: create J section) |
||
Line 73:
See: link to Rosetta Code [http://rosettacode.org/wiki/Addition-chain_exponentiation addition-chain exponentiation].
<br>
=={{header|J}}==
{{eff note|J|^}}
<lang J>kpt=:3 :0
L=: %P=: (1+y){.1 1
for_n. 1+i.y do.
findpath=: [: |. {&P^:a:
for_a. findpath n do.
j=. n+a
l=. 1+n{L
if. j>y do. break. end.
if. l>:j{ L do. continue. end.
L=: l j} L
P=: n j} P
end.
end.
P
)
usepath=:4 :0
path=. findpath y
exp=. 1x,({:path)#x:x
for_ex.(,.~2 -~/\"1])2 ,\path do.
'ea eb ec'=. ex
exp=.((ea{exp)*eb{exp) ec} exp
end.
{:exp
)</lang>
Task examples:
FIXME
=={{header|Python}}==
|