The Name Game: Difference between revisions

2,879 bytes removed ,  2 months ago
No edit summary
 
(10 intermediate revisions by 5 users not shown)
Line 190:
L: take Name 1
name: lower Name
unless in? L "AEIOU" -> drop 'name 1
[B F M]: ["b" "f" "m"]
 
Line 946:
 
=={{header|EasyLang}}==
<syntaxhighlight>
Unlike most other implementations presented in this page, this one actually handles consonant clusters, just like the original song.
proc verse x$ . .
 
x1$ = substr x$ 1 1
<syntaxhighlight lang="easylang">
y$ = substr x$ 2 99
func toLowercase string$ . result$ .
if strpos "AEIOU" x1$ <> 0
for i = 1 to len string$
codeh$ = strcodestrchar substr(strcode stringx1$ i+ 132)
ify$ code >= 65h$ and code <=& 90y$
code += 32
.
result$ &= strchar code
.
b$ = "b" & y$
.
f$ = "f" & y$
func findInStrArray array$[] item$ . index .
for im$ = 1 to"m" len& arrayy$[]
if arrayx1$[i] = item$"B"
indexb$ = iy$
elif x1$ = break 2"F"
.f$ = y$
elif x1$ = "M"
m$ = y$
.
print x$ & ", " & x$ & ", bo-" & b$
index = 0
print "Banana-fana fo-" & f$
print "Fee-fi-mo-" & m$
print x$ & "!"
.
for n$ in [ "Gary" "Earl" "Billy" "Felix" "Mary" ]
# This version actually handles consonant clusters
verse n$
name$ = input
print ""
call toLowercase name$ lowerName$
vowels$[] = [ "a" "e" "i" "o" "u" ]
for i = 1 to len lowerName$
letter$ = substr lowerName$ i 1
call findInStrArray vowels$[] letter$ index
if index <> 0
truncName1$ = substr lowerName$ i len lowerName$
break 1
.
truncName1$ = ""
.
firstLetter$ = substr lowerName$ 1 1
if firstLetter$ <> "b"
b$ = "b"
.
if firstLetter$ <> "f"
f$ = "f"
.
if firstLetter$ <> "m"
m$ = "m"
.
if b$ = "" or f$ = "" or m$ = ""
truncName2$ = substr lowerName$ 2 len lowerName$
.
# Determine the appropriate name for each line
if b$ = ""
bName$ = truncName2$
else
bName$ = truncName1$
.
if f$ = ""
fName$ = truncName2$
else
fName$ = truncName1$
.
if m$ = ""
mName$ = truncName2$
else
mName$ = truncName1$
.
# Print the song
print name$ & ", " & name$ & ", " & "bo-" & b$ & bName$
print "Banana-fana fo-" & f$ & fName$
print "Fee-fi-mo-" & m$ & mName$
print name$ & "!"
</syntaxhighlight>
{{in}}
<pre>
Gary
Earl
Billy
Shirley
</pre>
{{out}}
<pre>
Gary, Gary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-mary
Gary!
Earl, Earl, bo-bearl
Banana-fana fo-fearl
Fee-fi-mo-mearl
Earl!
Billy, Billy, bo-illy
Banana-fana fo-filly
Fee-fi-mo-milly
Billy!
Shirley, Shirley, bo-birley
Banana-fana fo-firley
Fee-fi-mo-mirley
Shirley!
</pre>
 
=={{header|F_Sharp|F#}}==
Line 1,234 ⟶ 1,167:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/The_Name_Game}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
 
[[File:Fōrmulæ - The Name Game 01.png]]
 
'''Test cases'''
 
[[File:Fōrmulæ - The Name Game 02.png]]
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - The Name Game 03.png]]
In '''[https://formulae.org/?example=The_Name_Game this]''' page you can see the program(s) related to this task and their results.
 
=={{header|Go}}==
Line 2,717 ⟶ 2,656:
Extra code was added to the REXX program to capitalize the name (and lowercase all characters in the name except the 1<sup>st</sup> character).
<br>Also, dual names are supported &nbsp;(like Mary Ann).
<syntaxhighlight lang="rexx">/*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 $ /*obtain optional argument(s) from C.L.*/
Parse Arg namelist /*obtain optional argument(s) from C.L.*/
if $='' then $="gAry, eARL, billy, FeLix, MarY" /*Not specified? Then use the default.*/
If namelist='' Then /*Not specified? /* [↑] names separated by commas. */
namelist="gAry, eARL, billy, FeLix, doMarY" j=1/* untilThen $='';use the default. $=space($) /*elide superfluous blanks from list. */
parse var $ name',' $ /*get name[?] names separated by (couldcommas. be 2 words) from list*/
Do While namelist>''
call song name /*invoke subroutine to display lyrics. */
namelist=space(namelist) /*elide superfluous blanks from list. */
end /*j*/
Parse Var namelist name',' namelist /*get name (could be 2 words) from list*/
exit /*stick a fork in it, we're all done. */
call song name /*invoke subroutine to display lyrics. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
End
song: arg c 2 1 z; @b='b'; @f="f"; @m='m' /*obtain name; assign three variables.*/
Exit /*stick a fork in it, we're all Done. */
@abc= 'abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU /*build 2 alphabets*/
/*---------------------------------------------------------------------------------*/
z=c || translate( substr(z, 2),@abc,@abcU) /*capitalize name, lowercase the rest. */
song:
parse var z f 2 '' 1 z /*get name, 1st letter, rest of name. */
Parse Arg name
y=substr(z, 2); zl=translate(z, @abc, @abcU) /*lowercase 2 vars.*/
Parse Value 'b f m' With bb ff selectmm
lowercase='abcdefghijklmnopqrstuvwxyz' /*build 2 alphabets*/
when pos(f, 'AEIOU')\==0 then do; say z',' z", bo-b"zl
uppercase=translate(lowercase)
say 'Banana-fana fo-f'zl
name =translate(left(name,1),uppercase,lowercase)||,
say 'Fee-fi-mo-m'zl
translate(substr(name,2),lowercase,uppercase)
end
namel=translate(name,lowercase,uppercase)
when pos(f, 'BFM' )\==0 then do; if f=='B' then @b=
Parse Var name first +1 rest
if f=='F' then @f=
Select
if f=='M' then @m=
When pos(first,'AEIOU')>0 Then Do
say z',' z", bo-"@b || y
Say name',' name", bo-b"namel
say 'Banana-fana fo-'@f || y
Say 'Banana-fana fo-f'namel
say 'Fee-fi-mo-'@m || y
Say 'Fee-fi-mo-m'namel
end
End
otherwise say z',' z", bo-b"y
When pos(first,'BFM')>0 Then Do
say 'Banana-fana fo-f'y
Select
say 'Fee-fi-mo-m'y
When first=='B' Then end /*select*/bb=''
When first=='F' Then ff=''
say z'!'; say
When first=='M' Then mm=''
return</syntaxhighlight>
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
</syntaxhighlight>
{{out|output|text= &nbsp; when using the default (internal) names:}}
<pre>
Line 3,156 ⟶ 3,110:
{{trans|Kotlin}}
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "./str" for Str
 
var printVerse = Fn.new { |name|
2,041

edits