How to resolve the algorithm Comma quibbling step by step in the Batch File programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Comma quibbling step by step in the Batch File 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 Batch File programming language
Source code in the batch programming language
@echo off
setlocal enabledelayedexpansion
::THE MAIN THING...
echo.
set inp=[]
call :quibble
set inp=["ABC"]
call :quibble
set inp=["ABC","DEF"]
call :quibble
set inp=["ABC","DEF","G","H"]
call :quibble
echo.
pause
exit /b
::/THE MAIN THING...
::THE FUNCTION
:quibble
set cont=0
set proc=%inp:[=%
set proc=%proc:]=%
for %%x in (%proc%) do (
set /a cont+=1
set x=%%x
set str!cont!=!x:"=!
)
set /a bef=%cont%-1
set output=%str1%
if %cont%==2 (set output=%str1% and %str2%)
if %cont% gtr 2 (
for /l %%y in (2,1,%bef%) do (
set output=!output!^, !str%%y!
)
set output=!output! and !str%cont%!
)
echo {!output!}
goto :EOF
::/THE FUNCTION
You may also check:How to resolve the algorithm Casting out nines step by step in the Java programming language
You may also check:How to resolve the algorithm OpenWebNet password step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the E programming language
You may also check:How to resolve the algorithm Terminal control/Inverse video step by step in the jq programming language
You may also check:How to resolve the algorithm Extensible prime generator step by step in the JavaScript programming language