How to resolve the algorithm Comma quibbling step by step in the Oberon-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Comma quibbling step by step in the Oberon-2 programming language

Table of Contents

Problem Statement

Comma quibbling is a task originally set by Eric Lippert in his blog.

Write a function to generate a string output which is the concatenation of input words from a list/sequence where:

Test your function with the following series of inputs showing your output here on this page:

Note: Assume words are non-empty strings of uppercase characters for this task.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Comma quibbling step by step in the Oberon-2 programming language

Source code in the oberon-2 programming language

MODULE CommaQuibbling;
IMPORT 
  NPCT:Args,
  Strings,
  Out;
  
VAR
  str: ARRAY 256 OF CHAR;

  PROCEDURE Do(VAR s: ARRAY OF CHAR);
  VAR
    aux: ARRAY 128 OF CHAR;
    i,params: LONGINT;
  BEGIN
    params := Args.Number() - 1;
    CASE params OF
       0: 
        COPY("{}",s)
      |1:
        Args.At(1,aux);
        Strings.Append("{",s);
        Strings.Append(aux,s);
        Strings.Append("}",s); 
      ELSE
        Strings.Append("{",s);
        FOR i := 1 TO params - 1 DO
          Args.At(i,aux);
          Strings.Append(aux,s);
          IF i # params - 1 THEN 
            Strings.Append(", ",s)
          ELSE 
            Strings.Append(" and ", s) 
          END
        END;
        Args.At(params,aux);
        Strings.Append(aux,s);
        Strings.Append("}",s)
    END;
    
  END Do;
  
BEGIN
  Do(str);
  Out.String(":> ");Out.String(str);Out.Ln
END CommaQuibbling.

  

You may also check:How to resolve the algorithm Literals/String step by step in the JSON programming language
You may also check:How to resolve the algorithm Dot product step by step in the Scala programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Python programming language
You may also check:How to resolve the algorithm Juggler sequence step by step in the Python programming language
You may also check:How to resolve the algorithm Doubly-linked list/Element insertion step by step in the BBC BASIC programming language