A+B: Difference between revisions
Content added Content deleted
(Task description formatting & slight wording changes that don't affect the goal of the task.) |
(Added J implementation) |
||
Line 232: | Line 232: | ||
The Icon solution also works in Unicon. |
The Icon solution also works in Unicon. |
||
=={{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 |
|||
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. |
|||
<lang J>+/".;.0 (_1}.(1!:1) 3)</lang> |
|||
Here's a little script, called "a+b.ijs": |
|||
<lang J>#!/Applications/j602/bin/jconsole |
|||
echo +/".;.0 (_1}.(1!:1) 3) |
|||
exit ''</lang> |
|||
Here is the execution of the script: |
|||
<lang>echo 2 3 | ./a+b.ijs |
|||
5</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |