How to resolve the algorithm The Name Game step by step in the Wren programming language
How to resolve the algorithm The Name Game step by step in the Wren 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 Wren programming language
Source code in the wren programming language
import "/str" for Str
var printVerse = Fn.new { |name|
var x = Str.capitalize(Str.lower(name))
var z = x[0]
var y = "AEIOU".contains(z) ? Str.lower(x) : x[1..-1]
var b = "b%(y)"
var f = "f%(y)"
var m = "m%(y)"
if (z == "B") {
b = y
} else if (z == "F") {
f = y
} else if (z == "M") {
m = y
}
System.print("%(x), %(x), bo-%(b)")
System.print("Banana-fana fo-%(f)")
System.print("Fee-fi-mo-%(m)")
System.print("%(x)!\n")
}
["Gary", "Earl", "Billy", "Felix", "Mary", "Steve"].each { |name| printVerse.call(name) }
You may also check:How to resolve the algorithm Formatted numeric output step by step in the Fantom programming language
You may also check:How to resolve the algorithm Exponentiation operator step by step in the Rust programming language
You may also check:How to resolve the algorithm Exceptions step by step in the RPL programming language
You may also check:How to resolve the algorithm Euler method step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Range extraction step by step in the ALGOL 68 programming language