The Name Game: Difference between revisions

 
(21 intermediate revisions by 13 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 55:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F print_verse(n)
V l = [String(‘b’), ‘f’, ‘m’]
V s = n[1..]
Line 66:
 
L(n) [‘Gary’, ‘Earl’, ‘Billy’, ‘Felix’, ‘Mary’]
print_verse(n)</langsyntaxhighlight>
 
=={{header|Ada}}==
{{works with|Ada|Ada|2012}}
 
<langsyntaxhighlight Adalang="ada">with Ada.Characters.Handling;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
Line 123:
Lyrics(+name);
end loop;
end The_Name_Game;</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 154:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G}}
<langsyntaxhighlight lang="algol68">
main:(
PROC print lyrics = (STRING name) VOID:
Line 183:
OD
)
</syntaxhighlight>
</lang>
 
=={{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}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">for i, x in StrSplit("Gary,Earl,Billy,Felix,Mary", ","){
BFM := false
if (SubStr(x, 1, 1) ~= "i)^[AEIOU]") ; Vowel
Line 201 ⟶ 247:
result .= output "`n`n"
}
MsgBox, 262144, ,% result</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 229 ⟶ 275:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f THE_NAME_GAME.AWK
BEGIN {
Line 247 ⟶ 293:
printf("%s!\n\n",x)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 284 ⟶ 330:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight BASIC256lang="basic256">subroutine TheGameName(nombre)
x = lower(nombre)
x = upper(mid(x,1,1)) + (mid(x,2,length(x)-1))
Line 319 ⟶ 365:
call TheGameName(listanombres[i])
next i
end</langsyntaxhighlight>
{{out}}
<pre>
Line 328 ⟶ 374:
=={{header|C}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
 
Line 366 ⟶ 412:
for (i = 0; i < 6; ++i) print_verse(names[i]);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 403 ⟶ 449:
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Text;
Line 440 ⟶ 486:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 474 ⟶ 520:
=={{header|C++}}==
{{trans|C#}}
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <iostream>
#include <string>
Line 532 ⟶ 578:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 570 ⟶ 616:
Note also the code on lines 30 and 75 to convert the case of the first letter... On some Commodore machines, the default is to render text in ALL CAPS, shifted letters become graphic symbols. This program sets the mode to display mixed case [chr$(14)] and then converts the first letter of the name for the purpose of uniform pattern matching in case the user types the name properly with a capitalized first letter.
 
<langsyntaxhighlight lang="gwbasic">1 rem name game
2 rem rosetta code
5 dim cn$(3),bl$(3,32):gosub 1000
Line 628 ⟶ 674:
2050 rem quadgraph
2060 data schr,schl
2069 data xx</langsyntaxhighlight>
 
{{out}}
Line 689 ⟶ 735:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.algorithm;
import std.array;
import std.conv;
Line 741 ⟶ 787:
printVerse(name);
}
}</langsyntaxhighlight>
 
=={{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}}==
 
<langsyntaxhighlight lang="dyalect">func printVerse(name) {
let x = name[..1].Upper() + name[1..].Lower();
let y = "AEIOU".IndexOf(x[0]) > -1 ? x.Lower() : x[1..]
Line 763 ⟶ 911:
for x in seq {
printVerse(x)
}</langsyntaxhighlight>
 
{{out}}
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#}}==
===The function===
<langsyntaxhighlight lang="fsharp">
// The Name Game. Nigel Galloway: March 28th., 2018
let fN g =
Line 809 ⟶ 987:
|'m' -> fG ("b"+g.[1..]) ("f"+g.[1..]) (g.[1..])
|_ -> fG ("b"+g.[1..]) ("f"+g.[1..]) ("m"+g.[1..])
</syntaxhighlight>
</lang>
===The Task===
<langsyntaxhighlight lang="fsharp">
fN "Nigel"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 821 ⟶ 999:
Nigel!
</pre>
<langsyntaxhighlight lang="fsharp">
fN "Earl"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 831 ⟶ 1,009:
Earl!
</pre>
<langsyntaxhighlight lang="fsharp">
fN "Billy"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 841 ⟶ 1,019:
Billy!
</pre>
<langsyntaxhighlight lang="fsharp">
fN "Fred"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 851 ⟶ 1,029:
Fred!
</pre>
<langsyntaxhighlight lang="fsharp">
fN "Mum"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 865 ⟶ 1,043:
{{trans|Kotlin}}
{{works with|Factor|0.98}}
<langsyntaxhighlight lang="factor">USING: ascii combinators interpolate io kernel locals
pair-rocket qw sequences ;
IN: rosetta-code.name-game
Line 888 ⟶ 1,066:
${Name}!I] nl nl ;
 
qw{ Gary Earl Billy Felix Milton Steve } [ name-game ] each</langsyntaxhighlight>
{{out}}
<pre>
Line 923 ⟶ 1,101:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">Sub TheGameName(nombre As String)
Dim As String x = Lcase(nombre)
x = Ucase(Mid(x,1,1)) + (Mid(x,2,Len(x)-1))
Line 953 ⟶ 1,131:
TheGameName(listanombres(i))
Next i
Sleep</langsyntaxhighlight>
{{out}}
<pre>
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}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,032 ⟶ 1,216:
printVerse(name)
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,068 ⟶ 1,252:
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">
<lang Haskell>
-- The Name Game, Ethan Riley, 22nd May 2018
import Data.Char
Line 1,110 ⟶ 1,294:
main =
mapM_ (putStrLn . theNameGame) ["Gary", "Earl", "Billy", "Felix", "Mike", "Steve"]
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,146 ⟶ 1,330:
=={{header|J}}==
Substitutions must conform to the region they replace. Cannot directly substitute 'Gary' where 'X' occurs in the template. Work instead with boxes, then at the end raze them to recover the verse.
<syntaxhighlight lang="j">
<lang J>
T=:TEMPLATE=: noun define
(X), (X), bo-b(Y)
Line 1,168 ⟶ 1,352:
; XBox
)
</syntaxhighlight>
</lang>
<pre>
nameGame&> ;:'Gary Earl Billy Felix Mary'
Line 1,199 ⟶ 1,383:
=={{header|Java}}==
{{trans|Kotlin}}
<langsyntaxhighlight Javalang="java">import java.util.stream.Stream;
 
public class NameGame {
Line 1,233 ⟶ 1,417:
Stream.of("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").forEach(NameGame::printVerse);
}
}</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 1,266 ⟶ 1,450:
 
=={{header|JavaScript}}==
<langsyntaxhighlight javaScriptlang="javascript">function singNameGame(name) {
 
// normalize name
Line 1,312 ⟶ 1,496:
'Gary Earl Billy Felix Mary Christine Brian Yvonne Yannick'.split(' ');
for (let i = 0; i < names.length; i++)
document.write(singNameGame(names[i]));</langsyntaxhighlight>
{{out}}<pre>
Gary, Gary, bo-bary
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}}==
<langsyntaxhighlight lang="julia">import Compat: uppercasefirst
 
function printverse(name::AbstractString)
Line 1,378 ⟶ 1,594:
end
 
foreach(TheNameGame.printverse, ("gARY", "Earl", "Billy", "Felix", "Mary", "sHIRley"))</langsyntaxhighlight>
 
{{out}}
Line 1,412 ⟶ 1,628:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.2.31
 
fun printVerse(name: String) {
Line 1,434 ⟶ 1,650:
fun main(args: Array<String>) {
listOf("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").forEach { printVerse(it) }
}</langsyntaxhighlight>
 
{{out}}
Line 1,471 ⟶ 1,687:
=={{header|Lua}}==
{{trans|C#}}
<langsyntaxhighlight lang="lua">function printVerse(name)
local sb = string.lower(name)
sb = sb:gsub("^%l", string.upper)
Line 1,508 ⟶ 1,724:
for _,name in pairs(nameList) do
printVerse(name)
end</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 1,545 ⟶ 1,761:
song$=format$("\r\n{0}, {0}, bo-{2}{1}\r\nBanana-fana fo-{3}{1}\r\nFee-fi-mo-{4}{1}\r\n{0}!\r\n")
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module The.Name.Game {
Flush
Line 1,572 ⟶ 1,788:
}
The.Name.Game
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,600 ⟶ 1,816:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[NameGame]
NameGame[n_] := Module[{y, b, f, m},
If[StringStartsQ[ToLowerCase[n], "a" | "e" | "i" | "u" | "o"],
Line 1,622 ⟶ 1,838:
NameGame["Felix"]
NameGame["Mary"]
NameGame["Steve"]</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 1,657 ⟶ 1,873:
{{works with|min|0.19.3}}
{{trans|Factor}}
<langsyntaxhighlight lang="min">("AEIOU" "" split swap in?) :vowel?
 
(
Line 1,675 ⟶ 1,891:
) :name-game
 
("Gary" "Earl" "Billy" "Felix" "Milton" "Steve") 'name-game foreach</langsyntaxhighlight>
{{out}}
<pre>
Line 1,711 ⟶ 1,927:
=={{header|MIPS Assembly}}==
The cartridge header and print routines were omitted so that the reader can focus on the logic.
<langsyntaxhighlight lang="mips"> la $a0,theNameGame
la $s0,theName
jal PrintString_NameGame
Line 1,860 ⟶ 2,076:
.ascii "?!"
.byte 0
.align 4</langsyntaxhighlight>
{{out}}
[https://ibb.co/V9GcTFV Screenshot of emulator]
<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!</pre>
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE NameGame;
FROM Strings IMPORT Concat;
FROM ExStrings IMPORT Lowercase;
Line 1,930 ⟶ 2,160:
 
ReadChar;
END NameGame.</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
{{trans|Python}}
<langsyntaxhighlight Nanoquerylang="nanoquery">def print_verse(n)
l = {"b", "f", "m"}
s = n.substring(1)
Line 1,953 ⟶ 2,183:
for n in names
print_verse(n)
end</langsyntaxhighlight>
 
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strutils
 
const
Line 1,983 ⟶ 2,213:
for name in ["Gary", "Earl", "Billy", "Felix", "Mary"]:
echo name.lyrics()
echo()</langsyntaxhighlight>
 
{{out}}
Line 2,013 ⟶ 2,243:
=={{header|Perl}}==
{{trans|Lua}}
<langsyntaxhighlight lang="perl">sub printVerse {
$x = ucfirst lc shift;
$x0 = substr $x, 0, 1;
Line 2,026 ⟶ 2,256:
}
 
printVerse($_) for <Gary Earl Billy Felix Mary Steve>;</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 2,060 ⟶ 2,290:
=={{header|Phix}}==
{{trans|Go}}
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
%s, %s, bo-%s
Line 2,085 ⟶ 2,315:
<span style="color: #008080;">constant</span> <span style="color: #000000;">tests</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"gARY"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Earl"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Billy"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Felix"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Mary"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"SHIRley"</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">printVerse</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,121 ⟶ 2,351:
=={{header|Picat}}==
{{works with|Picat}}
<syntaxhighlight lang="picat">
<lang Picat>
print_name_game(Name), Name = [V|Rest], membchk(V, ['A', 'E', 'I', 'O', 'U']) =>
L = to_lowercase(V),
Line 2,153 ⟶ 2,383:
print_name_game(Name)
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,185 ⟶ 2,415:
=={{header|PowerShell}}==
{{trans|Chris}}
<syntaxhighlight lang="powershell">
<lang Powershell>
## Clear Host from old Ouput
Clear-Host
Line 2,239 ⟶ 2,469:
}
Write-Host "$Name"
</syntaxhighlight>
</lang>
 
=={{header|Prolog}}==
<langsyntaxhighlight Prologlang="prolog">map_name1(C, Cs, C, Cs).
map_name1(C, Cs, Fc, [Fc,C|Cs]) :- member(C, ['a','e','i','o','u']).
map_name1(C, Cs, Fc, [Fc|Cs]) :-
Line 2,267 ⟶ 2,497:
 
test :-
maplist(song, ["Gary", "Earl", "Billy", "Felix", "Mary"]).</langsyntaxhighlight>
{{out}}
<pre>
Line 2,300 ⟶ 2,530:
 
=={{header|Python}}==
<langsyntaxhighlight Pythonlang="python">def print_verse(n):
l = ['b', 'f', 'm']
s = n[1:]
Line 2,311 ⟶ 2,541:
# Assume that the names are in title-case and they're more than one character long
for n in ['Gary', 'Earl', 'Billy', 'Felix', 'Mary']:
print_verse(n)</langsyntaxhighlight>
 
=={{header|q}}==
===String search and replace===
<langsyntaxhighlight lang="q">game_ssr:{[Name]
V:raze 1 lower\"AEIOUY"; / vowels
tn:lower((Name in V)?1b) _ Name; / truncated Name
Line 2,321 ⟶ 2,551:
s:"$1, $1, bo-b$2\nBanana-fana-fo-f$2\nFee-fimo-m$2\n$1!\n\n";
(ssr/).(s;("$1";"$2";s3 0);(Name;tn;s3 1)) }
</syntaxhighlight>
</lang>
===Amend a list of strings===
<langsyntaxhighlight lang="q">game_amend:{[Name]
pfx:Name,", ",Name,", "; / prefix
n:lower Name;
Line 2,332 ⟶ 2,562:
// test
1 "\n"sv raze game_ssr each ("Gary";"Earl";"Felix";"Stephen";"Ryan";"Jo");
</syntaxhighlight>
</lang>
{{out}}
<pre>Gary, Gary, bo-bary
Line 2,372 ⟶ 2,602:
Meh. The rules leave out some corner cases (see Steve) but what the heck, technically correct is the best kind of correct.
 
<syntaxhighlight lang="raku" perl6line>sub mangle ($name, $initial) {
my $fl = $name.lc.substr(0,1);
$fl ~~ /<[aeiou]>/
Line 2,390 ⟶ 2,620:
}
 
say .&name-game for <Gary Earl Billy Felix Mike Steve></langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 2,426 ⟶ 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).
<langsyntaxhighlight 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</lang>
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,491 ⟶ 2,736:
More idiomatic Ruby while not being object-oriented.
Also, like the Commodore Basic version, we handle consonants at the start of the name using a Regular Expression so we can handle appropriately names like Steve or Chris. Byron is an interesting edge-case because has a "y" and also starts with "b".
<langsyntaxhighlight lang="ruby">#!/usr/bin/env ruby
 
def print_verse(name)
Line 2,530 ⟶ 2,775:
end
 
</syntaxhighlight>
</lang>
{{out}}
<pre>Gary, Gary, bo-bary
Line 2,575 ⟶ 2,820:
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">object NameGame extends App {
private def printVerse(name: String): Unit = {
val x = name.toLowerCase.capitalize
Line 2,595 ⟶ 2,840:
 
Stream("gAry", "earl", "Billy", "Felix", "Mary", "Steve").foreach(printVerse)
}</langsyntaxhighlight>
 
See it running in your browser by [https://scastie.scala-lang.org/UilFJ0zFSJu4Qk2xaw2r4A Scastie (JVM)].
Line 2,602 ⟶ 2,847:
This implements the required rules and also attempts to handle names that start with consonant clusters.
 
<langsyntaxhighlight lang="sh">#!/usr/bin/env bash
namegame() {
local name=$1 b=b f=f m=m
Line 2,631 ⟶ 2,876:
namegame "$name"
echo
done</langsyntaxhighlight>
 
{{Out}}
Line 2,667 ⟶ 2,912:
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Option Explicit
 
Sub Main()
Line 2,698 ⟶ 2,943:
Next
TheGameName = t
End Function</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 2,737 ⟶ 2,982:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Option Strict On
 
Imports System.Text
Line 2,776 ⟶ 3,021:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>Gary, Gary, bo-bary
Line 2,807 ⟶ 3,052:
Fee-fi-mo-mteve
Steve!</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">fn main() {
list := ['Gary', 'Earl', 'Billy', 'Felix', 'Mary']
for name in list {verse(name)}
}
 
fn verse(name string) {
mut b, mut f, mut m, mut y :='','','',''
mut x := name.to_lower().title()
y = x.substr(1, x.len)
if 'AEIOU'.contains(x[0].ascii_str()) {y = x.to_lower()}
b = 'b' + y
f = 'f' + y
m = 'm' + y
match x[0].ascii_str() {
'B' {b = y}
'F' {f = y}
'M' {m = y}
else {}
}
println('$x, $x, bo-$b')
println('Banana-fana fo-$f')
println('Fee-fi-mo-$m')
println('$x!\n')
}</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!
</pre>
 
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|Wren-str}}
<langsyntaxhighlight ecmascriptlang="wren">import "./str" for Str
 
var printVerse = Fn.new { |name|
Line 2,833 ⟶ 3,132:
}
 
["Gary", "Earl", "Billy", "Felix", "Mary", "Steve"].each { |name| printVerse.call(name) }</langsyntaxhighlight>
 
{{out}}
Line 2,867 ⟶ 3,166:
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>
 
=={{header|Z80 Assembly}}==
{{trans|MIPS Assembly}}
<syntaxhighlight lang="z80">;;;;;;;;;;;;;;;;;;; HEADER ;;;;;;;;;;;;;;;;;;;
read "\SrcCPC\winape_macros.asm"
read "\SrcCPC\MemoryMap.asm"
read "\SrcALL\winapeBuildCompat.asm"
;;;;;;;;;;;;;;;;;;; PROGRAM ;;;;;;;;;;;;;;;;;;;
 
org &1000
 
ld hl,namegame
ld de,name1
call PrintString_NameGame
 
 
ld hl,namegame
ld de,name2
call PrintString_NameGame
 
 
ld hl,namegame
ld de,name3
call PrintString_NameGame
 
ret ;return to basic
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintString_NameGame:
ld a,(hl)
or a ;compare to zero
ret z ;exit on null terminator
cp '?'
jr z,printNameAsIs
cp '%'
jr z,insertName
;else, just print what you see.
call &bb5a ;amstrad CPC kernel will print the contents of A as an ascii character
 
continue_NameGame:
inc hl
jr PrintString_NameGame
;;;;;;;;;;;;;;;; execution will never fall through this line without a jump
printNameAsIs:
ex de,hl
push hl
call PrintString
pop hl
ex de,hl
jr continue_NameGame
;;;;;;;;;;;;;;;; execution will never fall through this line without a jump
insertName:
push hl
dec hl
dec hl
dec hl
ld c,(hl) ;get the b in "bo-%", or the f in "fo-%", etc.
pop hl
ex de,hl ;swap to the name we wish to print
push hl
ld a,(hl)
cp c
jr z,dontPrintC
cp 'a'
jr z,beginsWithVowel
cp 'e'
jr z,beginsWithVowel
cp 'i'
jr z,beginsWithVowel
cp 'o'
jr z,beginsWithVowel
cp 'u'
 
ld a,c
call PrintChar
dontPrintC:
inc hl
call PrintString
pop hl
ex de,hl
jr continue_NameGame
 
beginsWithVowel:
;if name begins with vowel, we print C then the name as-is
ld a,c
call PrintChar
call PrintString ;print name as is
 
pop hl
ex de,hl
jr continue_NameGame
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintString:
ld a,(hl)
or a
ret z
call &BB5A
inc hl
jr PrintString
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
name1:
db "gary",0
name2:
db "earl",0
name3:
db "billy",0
 
namegame:
db "?, ?, bo-%",13,10
db "banana-fana fo-%",13,10
db "fee-fi-mo-%",13,10
db "?!",13,10,13,10
db 0</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!</pre>
 
=={{header|zkl}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="zkl">fcn printVerse(name){
z,x := name[0].toLower(), z.toUpper() + name[1,*].toLower();
y:=( if("aeiou".holds(z)) name.toLower() else x[1,*] );
Line 2,878 ⟶ 3,370:
println("Fee-fi-mo-",m);
println(x,"!\n");
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">List("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").apply2(printVerse);</langsyntaxhighlight>
{{out}}
<pre style="height:35ex">
1,981

edits