A+B: Difference between revisions

Content added Content deleted
(Added J implementation)
m (→‎{{header|J}}: Fixed explanation.)
Line 235: Line 235:
=={{header|J}}==
=={{header|J}}==


In the following line, <tt>(1!:1) 3</tt> reads a line from STDIN; <tt>_1}.</tt> drops the last newline character; <tt>:.0</tt> then cuts it into "words", each
In the following line, <tt>(1!:1) 3</tt> reads a line from STDIN; <tt>_1}.</tt> drops the last newline character; <tt>;.0</tt> then cuts it into "words", each
of which are converted into a number (by <tt>".:.0</tt>), resulting in a vector which is then reduced with addition using <tt>+/</tt>, producing the result.
of which are converted into a number (by <tt>".</tt> when applied with <tt>;.</tt>), resulting in a vector which is then reduced with addition using <tt>+/</tt>, producing the result.
<lang J>+/".;.0 (_1}.(1!:1) 3)</lang>
<lang J>+/".;.0 (_1}.(1!:1) 3)</lang>
Here's a little script, called "a+b.ijs":
Here's a little script, called "a+b.ijs":