A+B: Difference between revisions

Content deleted Content added
m added return 0;
Peak (talk | contribs)
jq
Line 1,598:
"output.txt" "w" fopen
get get + fput pop quit.</lang>
 
=={{header|jq}}==
Since the given task is simply to add two numbers, the simplest approach in jq is illustrated by the following transcript:
<lang jq>$ jq -s add
3 2
5 </lang>
This will work provided the numbers are neither too small nor too large. However, the above program will add **all** the numbers presented on the stream (assuming only numbers are presented). If the task were to add consecutive pairs of numbers, then the approach illustrated in the following transcript can be used, in conjunction with the jq "-s" option:<lang jq>
def addpairs:
if length < 2 then empty
else (.[0] + .[1]), (.[2:] | addpairs)
end;
 
addpairs</lang>
For example, here is a transcript that assumes the program is in a file named AB.jq:<lang jq>
$ jq -s -f AB.jq
1 2 3 4 5 6
3
7
11</lang>
 
=={{header|L++}}==