How to resolve the algorithm The Name Game step by step in the REXX programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm The Name Game step by step in the REXX programming language

Table of Contents

Problem Statement

Write a program that accepts a name as input and outputs the lyrics to the Shirley Ellis song "The Name Game".

The regular verse Unless your name begins with a vowel (A, E, I, O, U), 'B', 'F' or 'M' you don't have to care about special rules. The verse for the name 'Gary' would be like this: At the end of every line, the name gets repeated without the first letter: Gary becomes ary If we take (X) as the full name (Gary) and (Y) as the name without the first letter (ary) the verse would look like this: Vowel as first letter of the name If you have a vowel as the first letter of your name (e.g. Earl) you do not truncate the name. The verse looks like this: 'B', 'F' or 'M' as first letter of the name In case of a 'B', an 'F' or an 'M' (e.g. Billy, Felix, Mary) there is a special rule. The line which would 'rebuild' the name (e.g. bo-billy) is sung without the first letter of the name. The verse for the name Billy looks like this: For the name 'Felix', this would be right:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm The Name Game step by step in the REXX programming language

Source code in the rexx programming language

/*REXX program  displays the lyrics of the song "The Name Game" by Shirley Ellis.  */
/* 20230526 Walter Pachl refurbished Gerald Schildberger's original program        */
Parse Arg namelist                          /*obtain optional argument(s) from C.L.*/
If namelist='' Then                         /*Not specified?                       */
  namelist="gAry, eARL, billy, FeLix, MarY" /*  Then use the default.              */
                                            /* [?]  names separated by commas.     */
Do While namelist>''
  namelist=space(namelist)                  /*elide superfluous blanks from list.  */
  Parse Var namelist name',' namelist       /*get name (could be 2 words) from list*/
  call song name                            /*invoke subroutine to display lyrics. */
  End
Exit                                        /*stick a fork in it,  we're all Done. */
/*---------------------------------------------------------------------------------*/
song:
  Parse Arg name
  Parse Value 'b f m' With bb ff mm
  lowercase='abcdefghijklmnopqrstuvwxyz'     /*build 2 alphabets*/
  uppercase=translate(lowercase)
  name =translate(left(name,1),uppercase,lowercase)||,
        translate(substr(name,2),lowercase,uppercase)
  namel=translate(name,lowercase,uppercase)
  Parse Var name first +1 rest
  Select
    When pos(first,'AEIOU')>0 Then Do
      Say name','  name", bo-b"namel
      Say 'Banana-fana fo-f'namel
      Say 'Fee-fi-mo-m'namel
      End
    When pos(first,'BFM')>0 Then Do
      Select
        When first=='B' Then bb=''
        When first=='F' Then ff=''
        When first=='M' Then mm=''
        End
      Say name',' name', bo-'bb||rest
      Say 'Banana-fana fo-'ff||rest
      Say 'Fee-fi-mo-'mm||rest
      End
    Otherwise Do
      Say name','  name', bo-b'rest
      Say 'Banana-fana fo-f'rest
      Say 'Fee-fi-mo-m'rest
      End
    End /*select*/
    Say name'!'
    Say ''
    Return


  

You may also check:How to resolve the algorithm Rosetta Code/Count examples step by step in the Julia programming language
You may also check:How to resolve the algorithm Abstract type step by step in the Fantom programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the C++ programming language
You may also check:How to resolve the algorithm Update a configuration file step by step in the Haskell programming language
You may also check:How to resolve the algorithm Parsing/Shunting-yard algorithm step by step in the Note 1 programming language