How to resolve the algorithm A+B step by step in the CFEngine programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm A+B step by step in the CFEngine 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 CFEngine programming language

Source code in the cfengine programming language

$ cat sum.cf
bundle agent main  
{
  vars:
    "line_count" int => readintarray(
      "input",
      "${this.promise_dirname}${const.dirsep}input.txt",
      "#[^\n]*",
      " ",
      "inf",
      "inf"
    );
    "indices" slist => getindices( "input" );
  reports:
    "${with}" with => format( "%d", eval( "${input[${indices}][0]} + ${input[${indices}][1]}" ));
    DEBUG::
      "line_count is ${line_count}";
      "input is ${with}" with => storejson( "input" );
      "input[${indices}] is ${with}" with => storejson( "input[${indices}]" );
}

$ cat input.txt
2 3
2 2

$ cf-agent -KIf ./sum.cf
R: 5
R: 4

  

You may also check:How to resolve the algorithm Copy a string step by step in the Red programming language
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the Elena programming language
You may also check:How to resolve the algorithm Keyboard macros step by step in the C programming language
You may also check:How to resolve the algorithm Dutch national flag problem step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Matrix transposition step by step in the Idris programming language