Long multiplication: Difference between revisions
→{{header|J}}: simplify and reorganize
(→{{header|J}}: formatting to improve clarity) |
(→{{header|J}}: simplify and reorganize) |
||
Line 642:
=={{header|J}}==
'''Solution:'''
<lang j> digits =: ,.&.":
polymult =: +//.@(*/)
buildDecimal=: (+ 10x&*)/@|.
340282366920938463463374607431768211456</lang>
'''Alternatives:'''<br>
The above definition may be written as a single verb without the components:
340282366920938463463374607431768211456</lang>▼
<lang j> (10x&#.)@(+//.@(*/)&(,.&.":))/ ,~2x^64
340282366920938463463374607431768211456</lang>▼
Writing directly:▼
<lang j> (2x^64)*(2x^64)▼
340282366920938463463374607431768211456</lang>
'''Explaining the component verbs:'''
* <code>digits</code>
<lang j> ,.&.": 123
1 2 3</lang>
*
<lang j> 1 2 3 (+//.@(*/)) 1 2 3
1 4 10 12 9</lang>
* <code>buildDecimal</code> (building the decimal result):
<lang j> (+ 10x&*)/|. 1 4 10 12 9
15129</lang>
▲or using the primitive dyad <code>#.</code> instead of <code>(+ 10x&*)/@|.</code>
▲<lang j> (10x #. ,.&.":@[ +//.@(*/) ,.&.":@])/ ,~2x^64
▲340282366920938463463374607431768211456</lang>
▲Writing directly:
▲<lang j> (2x^64)*(2x^64)
▲340282366920938463463374607431768211456</lang>
=={{header|JavaScript}}==
|