How to resolve the algorithm A+B step by step in the jq programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm A+B step by step in the jq programming language
Table of Contents
Problem Statement
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Given two integers, A and B. Their sum needs to be calculated.
Two integers are written in the input stream, separated by space(s):
The required output is one integer: the sum of A and B.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm A+B step by step in the jq programming language
Source code in the jq programming language
$ jq -s add
3 2
5
def addpairs:
if length < 2 then empty
else (.[0] + .[1]), (.[2:] | addpairs)
end;
addpairs
$ jq -s -f AB.jq
1 2 3 4 5 6
3
7
11
You may also check:How to resolve the algorithm Random numbers step by step in the Frink programming language
You may also check:How to resolve the algorithm Largest number divisible by its digits step by step in the Red programming language
You may also check:How to resolve the algorithm Pascal matrix generation step by step in the VBScript programming language
You may also check:How to resolve the algorithm Subleq step by step in the Swift programming language
You may also check:How to resolve the algorithm Case-sensitivity of identifiers step by step in the Ring programming language