The Name Game: Difference between revisions

(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
 
(15 intermediate revisions by 9 users not shown)
Line 34:
 
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 sangsung without the first letter of the name.
The verse for the name Billy looks like this:
 
Line 184:
)
</syntaxhighlight>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">nameGame: function [Name][
L: take Name 1
name: lower Name
unless in? L "AEIOU" -> drop 'name
[B F M]: ["b" "f" "m"]
 
if L="B" -> B: ""
if L="F" -> F: ""
if L="M" -> M: ""
 
~{
|Name|, |Name|, bo-|B||name|
Banana-fana fo-|F||name|
Fee-fi-mo-|M||name|
|Name|!
}
]
 
["Gary" "Earl" "Billy" "Felicia" "Marissa" "Sarah"]
| map => nameGame
| loop => [print & ++ "\n"]</syntaxhighlight>
 
{{out}}
 
<pre>Billy, Billy, bo-illy
Banana-fana fo-filly
Fee-fi-mo-milly
Billy!
 
Felicia, Felicia, bo-belicia
Banana-fana fo-elicia
Fee-fi-mo-melicia
Felicia!
 
Marissa, Marissa, bo-barissa
Banana-fana fo-farissa
Fee-fi-mo-arissa
Marissa!
 
Sarah, Sarah, bo-barah
Banana-fana fo-farah
Fee-fi-mo-marah
Sarah!</pre>
 
=={{header|AutoHotkey}}==
Line 742 ⟶ 788:
}
}</syntaxhighlight>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
function WaitForString(Memo: TMemo; Prompt: string): string;
{Wait for key stroke on TMemo component}
var KW: TKeyWaiter;
begin
{Use custom object to wait and capture key strokes}
KW:=TKeyWaiter.Create(Memo);
try
Memo.Lines.Add(Prompt);
Memo.SelStart:=Memo.SelStart-1;
Memo.SetFocus;
Result:=KW.WaitForString;
finally KW.Free; end;
end;
 
 
procedure NameGame(Memo: TMemo);
var Name: string;
var Str2: string;
var FL: Char;
 
function GetPattern: string;
var BStr,FStr,MStr: string;
begin
if FL='b' then BStr:='bo-' else BStr:='bo-b';
if FL='f' then FStr:='fo-' else FStr:='fo-f';
if FL='m' then MStr:='mo-' else MStr:='mo-m';
Result:=Format('%S, %S, %S%S',[Name,Name,BStr,Str2])+CRLF;
Result:=Result+Format('Banana-fana %S%S',[FStr,Str2])+CRLF;
Result:=Result+Format('Fee-fi-%S%S',[MStr,Str2])+CRLF;
Result:=Result+Format('%S!',[Name])+CRLF;
end;
 
begin
while true do
begin
Name:=WaitForString(Memo,'Enter a name: ');
if Name='' then break;
Str2:=LowerCase(Name);
FL:=Str2[1];
if not (FL in ['a','e','i','o','u']) then Delete(Str2,1,1);
 
Memo.Lines.Add(GetPattern);
end;
end;
 
 
 
</syntaxhighlight>
{{out}}
<pre>
Enter a name:
Gary
 
Gary, Gary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-mary
Gary!
 
Enter a name:
Earl
 
Earl, Earl, bo-bearl
Banana-fana fo-fearl
Fee-fi-mo-mearl
Earl!
 
Enter a name:
Billy
 
Billy, Billy, bo-illy
Banana-fana fo-filly
Fee-fi-mo-milly
Billy!
 
Enter a name:
Felix
 
Felix, Felix, bo-belix
Banana-fana fo-elix
Fee-fi-mo-melix
Felix!
 
Enter a name:
Mary
 
Mary, Mary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-ary
Mary!
 
Enter a name:
Elapsed Time: 01:18.249 min
</pre>
 
 
=={{header|Dyalect}}==
Line 796 ⟶ 944:
Fee-fi-mo-mTteve
STteve!,STteve</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
proc verse x$ . .
x1$ = substr x$ 1 1
y$ = substr x$ 2 99
if strpos "AEIOU" x1$ <> 0
h$ = strchar (strcode x1$ + 32)
y$ = h$ & y$
.
b$ = "b" & y$
f$ = "f" & y$
m$ = "m" & y$
if x1$ = "B"
b$ = y$
elif x1$ = "F"
f$ = y$
elif x1$ = "M"
m$ = y$
.
print x$ & ", " & x$ & ", bo-" & b$
print "Banana-fana fo-" & f$
print "Fee-fi-mo-" & m$
print x$ & "!"
.
for n$ in [ "Gary" "Earl" "Billy" "Felix" "Mary" ]
verse n$
print ""
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 989 ⟶ 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'''
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 01.png]]
In '''[https://formulae.org/?example=The_Name_Game this]''' page you can see the program(s) related to this task and their results.
 
'''Test cases'''
 
[[File:Fōrmulæ - The Name Game 02.png]]
 
[[File:Fōrmulæ - The Name Game 03.png]]
 
=={{header|Go}}==
Line 1,359 ⟶ 1,543:
Yannick!
</pre>
 
=={{header|jq}}==
'''Adapted from [[#Python]]'''
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq, and with fq.'''
<syntaxhighlight lang=jq>
def capitalize:
if length==0 then .
else .[0:1] as $c
| ($c|ascii_upcase) as $C
| if $c == $C then .
else $C + .[1:]
end
end;
def printVerse:
{x: (ascii_downcase|capitalize)}
| .x[0:1] as $x0
| .y = (if $x0|test("[AEIOU]") then .x | ascii_downcase else .x[1:] end)
| .b = ((select($x0 == "B") | "") // "b")
| .f = ((select($x0 == "F") | "") // "f")
| .m = ((select($x0 == "M") | "") // "m")
| "\(.x), \(.x), bo-\(.b)\(.y)",
"Banana-fana fo-\(.f)\(.y)",
"Fee-fi-mo-\(.m)\(.y)",
"\(.x)!\n" ;
 
"Gary", "Earl", "Billy", "Felix", "Mary", "Steve"
| printVerse
</syntaxhighlight>
{{output}}
As for [[#Wren|Wren]].
 
=={{header|Julia}}==
Line 2,440 ⟶ 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 2,879 ⟶ 3,110:
{{trans|Kotlin}}
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "./str" for Str
 
var printVerse = Fn.new { |name|
Line 2,934 ⟶ 3,165:
Fee-fi-mo-mteve
Steve!
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">proc PrintVerse(Name);
char Name;
int I, Vowel;
 
proc PrintLine(Str, Let);
int Str, Let;
[Text(0, Str);
if Name(0) # Let then ChOut(0, Let!$20); \bary
if Vowel then ChOut(0, Name(0)!$20); \earl
Text(0, Name+1);
CrLf(0);
];
 
[Name(0):= Name(0) & ~$20; \to uppercase
I:= 1;
while Name(I) do \to lowercase
[Name(I):= Name(I) ! $20; I:= I+1];
case Name(0) of
^A,^E,^I,^O,^U: Vowel:= true
other Vowel:= false;
Text(0, Name); Text(0, ", "); Text(0, Name);
PrintLine(", bo-", ^B);
PrintLine("Banana-fana fo-", ^F);
PrintLine("Fee-fi-mo-", ^M);
Text(0, Name); Text(0, "!^m^j^m^j");
];
 
int Names, I;
[Names:= ["gARY", "Earl", "Billy", "Felix", "Mary", "sHIRley"];
for I:= 0 to 6-1 do PrintVerse(Names(I));
]</syntaxhighlight>
{{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!
 
Felix, Felix, bo-belix
Banana-fana fo-elix
Fee-fi-mo-melix
Felix!
 
Mary, Mary, bo-bary
Banana-fana fo-fary
Fee-fi-mo-ary
Mary!
 
Shirley, Shirley, bo-bhirley
Banana-fana fo-fhirley
Fee-fi-mo-mhirley
Shirley!
 
</pre>
 
2,063

edits