How to resolve the algorithm Comma quibbling step by step in the EchoLisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Comma quibbling step by step in the EchoLisp 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 EchoLisp programming language
Source code in the echolisp programming language
(lib 'match)
(define (quibble words)
(match words
[ null "{}"]
[ (a) (format "{ %a }" a)]
[ (a b) (format "{ %a and %a }" a b)]
[( a ... b c) (format "{ %a %a and %a }" (for/string ([w a]) (string-append w ", ")) b c)]
[else 'bad-input]))
;; output
(for ([t '(() ("ABC") ("ABC" "DEF") ("ABC" "DEF" "G" "H"))])
(writeln t '----> (quibble t)))
null ----> "{}"
("ABC") ----> "{ ABC }"
("ABC" "DEF") ----> "{ ABC and DEF }"
("ABC" "DEF" "G" "H") ----> "{ ABC, DEF, G and H }"
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the Nim programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the Ol programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the Logo programming language
You may also check:How to resolve the algorithm Retrieve and search chat history step by step in the Wren programming language
You may also check:How to resolve the algorithm Gray code step by step in the Common Lisp programming language