How to resolve the algorithm A+B step by step in the Golo programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm A+B step by step in the Golo 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 Golo programming language
Source code in the golo programming language
#!/usr/bin/env golosh
----
This module asks for two numbers, adds them, and prints the result.
----
module Aplusb
import gololang.IO
function main = |args| {
let line = readln("Please enter two numbers (just leave a space in between them) ")
let numbers = line: split("[ ]+"): asList()
require(numbers: size() == 2, "we need two numbers")
try {
let a, b = numbers: map(|i| -> i: toInt())
require(a >= -1000 and a <= 1000 and b >= -1000 and b <= 1000, "both numbers need to be between -1000 and 1000")
println(a + b)
} catch (e) {
println("they both need to be numbers for this to work")
}
}
You may also check:How to resolve the algorithm Pentagram step by step in the Racket programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Insitux programming language
You may also check:How to resolve the algorithm Binary strings step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Function definition step by step in the C# programming language
You may also check:How to resolve the algorithm Password generator step by step in the REXX programming language