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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm The Name Game step by step in the VBA 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 VBA programming language

Source code in the vba programming language

Option Explicit

Sub Main()
Dim a, r, i As Integer
Const SCHEM As String = "(X), (X), bo-b(Y)^Banana-fana fo-f(Y)^Fee-fi-mo-m(Y)^(X)!^"
   'init
   a = Array("GaRY", "Earl", "Billy", "Felix", "Mary", "Mike", "Frank")
   'compute
   r = TheGameName(a, SCHEM)
   'return
   For i = LBound(r) To UBound(r)
      Debug.Print r(i)
   Next i
End Sub

Private Function TheGameName(MyArr, S As String) As String()
Dim i As Integer, s1 As String, s2 As String, tp As String, t() As String
   ReDim t(UBound(MyArr))
   For i = LBound(MyArr) To UBound(MyArr)
      tp = Replace(S, "^", vbCrLf)
      s2 = LCase(Mid(MyArr(i), 2)): s1 = UCase(Left(MyArr(i), 1)) & s2
      Select Case UCase(Left(MyArr(i), 1))
         Case "A", "E", "I", "O", "U": tp = Replace(tp, "(Y)", LCase(MyArr(i)))
         Case "B", "F", "M"
            tp = Replace(tp, "(Y)", s2)
            tp = Replace(tp, LCase(MyArr(i)), s2)
         Case Else: tp = Replace(tp, "(Y)", s2)
      End Select
      t(i) = Replace(tp, "(X)", s1)
   Next
   TheGameName = t
End Function

  

You may also check:How to resolve the algorithm MD5/Implementation step by step in the C programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the Batch File programming language
You may also check:How to resolve the algorithm Copy a string step by step in the Zoomscript programming language
You may also check:How to resolve the algorithm Ordered words step by step in the Mathematica/Wolfram Language programming language