Long multiplication: Difference between revisions
Content added Content deleted
(→{{header|J}}: formatting to improve clarity) |
(→{{header|J}}: simplify and reorganize) |
||
Line 642: | Line 642: | ||
=={{header|J}}== |
=={{header|J}}== |
||
'''Solution:''' |
|||
<lang j> digits =: ,.&.": |
|||
polymult =: +//.@(*/) |
|||
buildDecimal=: (+ 10x&*)/@|. |
|||
buildDecimal@polymult&digits/ ,~ 2x^64 |
|||
340282366920938463463374607431768211456</lang> |
340282366920938463463374607431768211456</lang> |
||
* digits: <code>,.&.": y</code> |
|||
'''Alternatives:'''<br> |
|||
The above definition may be written as a single verb without the components: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
<lang j> (10x&#.)@(+//.@(*/)&(,.&.":))/ ,~2x^64 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
340282366920938463463374607431768211456</lang> |
|||
'''Explaining the component verbs:''' |
|||
* <code>digits</code> |
|||
<lang j> ,.&.": 123 |
<lang j> ,.&.": 123 |
||
1 2 3</lang> |
1 2 3</lang> |
||
* |
* <code>polymult</code> (polynomial multiplication): '''ref.''' [http://www.jsoftware.com/help/dictionary/samp23.htm] |
||
<lang j> 1 2 3 (+//.@(*/)) 1 2 3 |
<lang j> 1 2 3 (+//.@(*/)) 1 2 3 |
||
1 4 10 12 9</lang> |
1 4 10 12 9</lang> |
||
* building the decimal result: |
* <code>buildDecimal</code> (building the decimal result): |
||
<lang j> (+ 10x&*)/|. 1 4 10 12 9 |
<lang j> (+ 10x&*)/|. 1 4 10 12 9 |
||
15129</lang> |
15129</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |