How to resolve the algorithm Comma quibbling step by step in the UNIX Shell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Comma quibbling step by step in the UNIX Shell 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 UNIX Shell programming language

Source code in the unix programming language

quibble() {
	# Here awk(1) is easier than sed(1).
	awk 'BEGIN {
		for (i = 1; i < ARGC - 2; i++) s = s ARGV[i] ", "
		i = ARGC - 2; if (i > 0) s = s ARGV[i] " and "
		i = ARGC - 1; if (i > 0) s = s ARGV[i]
		printf "{%s}\n", s
		exit 0
	}' "$@"
}

quibble
quibble ABC
quibble ABC DEF
quibble ABC DEF G H


  

You may also check:How to resolve the algorithm Semiprime step by step in the Pascal programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the Nemerle programming language
You may also check:How to resolve the algorithm Bernoulli numbers step by step in the Frink programming language
You may also check:How to resolve the algorithm Arrays step by step in the Phixmonti programming language
You may also check:How to resolve the algorithm Archimedean spiral step by step in the MiniScript programming language