The Name Game: Difference between revisions

Content added Content deleted
No edit summary
m (syntax highlighting fixup automation)
Line 55: Line 55:
{{trans|Python}}
{{trans|Python}}


<lang 11l>F print_verse(n)
<syntaxhighlight lang="11l">F print_verse(n)
V l = [String(‘b’), ‘f’, ‘m’]
V l = [String(‘b’), ‘f’, ‘m’]
V s = n[1..]
V s = n[1..]
Line 66: Line 66:


L(n) [‘Gary’, ‘Earl’, ‘Billy’, ‘Felix’, ‘Mary’]
L(n) [‘Gary’, ‘Earl’, ‘Billy’, ‘Felix’, ‘Mary’]
print_verse(n)</lang>
print_verse(n)</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
{{works with|Ada|Ada|2012}}
{{works with|Ada|Ada|2012}}


<lang Ada>with Ada.Characters.Handling;
<syntaxhighlight lang="ada">with Ada.Characters.Handling;
with Ada.Strings.Unbounded;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
with Ada.Text_IO;
Line 123: Line 123:
Lyrics(+name);
Lyrics(+name);
end loop;
end loop;
end The_Name_Game;</lang>
end The_Name_Game;</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 154: Line 154:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G}}
{{works with|ALGOL 68G}}
<lang algol68>
<syntaxhighlight lang="algol68">
main:(
main:(
PROC print lyrics = (STRING name) VOID:
PROC print lyrics = (STRING name) VOID:
Line 183: Line 183:
OD
OD
)
)
</syntaxhighlight>
</lang>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>for i, x in StrSplit("Gary,Earl,Billy,Felix,Mary", ","){
<syntaxhighlight lang="autohotkey">for i, x in StrSplit("Gary,Earl,Billy,Felix,Mary", ","){
BFM := false
BFM := false
if (SubStr(x, 1, 1) ~= "i)^[AEIOU]") ; Vowel
if (SubStr(x, 1, 1) ~= "i)^[AEIOU]") ; Vowel
Line 201: Line 201:
result .= output "`n`n"
result .= output "`n`n"
}
}
MsgBox, 262144, ,% result</lang>
MsgBox, 262144, ,% result</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 229: Line 229:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f THE_NAME_GAME.AWK
# syntax: GAWK -f THE_NAME_GAME.AWK
BEGIN {
BEGIN {
Line 247: Line 247:
printf("%s!\n\n",x)
printf("%s!\n\n",x)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 284: Line 284:
=={{header|BASIC256}}==
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
{{trans|FreeBASIC}}
<lang BASIC256>subroutine TheGameName(nombre)
<syntaxhighlight lang="basic256">subroutine TheGameName(nombre)
x = lower(nombre)
x = lower(nombre)
x = upper(mid(x,1,1)) + (mid(x,2,length(x)-1))
x = upper(mid(x,1,1)) + (mid(x,2,length(x)-1))
Line 319: Line 319:
call TheGameName(listanombres[i])
call TheGameName(listanombres[i])
next i
next i
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 328: Line 328:
=={{header|C}}==
=={{header|C}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
#include <string.h>


Line 366: Line 366:
for (i = 0; i < 6; ++i) print_verse(names[i]);
for (i = 0; i < 6; ++i) print_verse(names[i]);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 403: Line 403:
=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
{{trans|Java}}
{{trans|Java}}
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using System.Text;
Line 440: Line 440:
}
}
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 474: Line 474:
=={{header|C++}}==
=={{header|C++}}==
{{trans|C#}}
{{trans|C#}}
<lang cpp>#include <algorithm>
<syntaxhighlight lang="cpp">#include <algorithm>
#include <iostream>
#include <iostream>
#include <string>
#include <string>
Line 532: Line 532:


return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 570: Line 570:
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.
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.


<lang gwbasic>1 rem name game
<syntaxhighlight lang="gwbasic">1 rem name game
2 rem rosetta code
2 rem rosetta code
5 dim cn$(3),bl$(3,32):gosub 1000
5 dim cn$(3),bl$(3,32):gosub 1000
Line 628: Line 628:
2050 rem quadgraph
2050 rem quadgraph
2060 data schr,schl
2060 data schr,schl
2069 data xx</lang>
2069 data xx</syntaxhighlight>


{{out}}
{{out}}
Line 689: Line 689:


=={{header|D}}==
=={{header|D}}==
<lang d>import std.algorithm;
<syntaxhighlight lang="d">import std.algorithm;
import std.array;
import std.array;
import std.conv;
import std.conv;
Line 741: Line 741:
printVerse(name);
printVerse(name);
}
}
}</lang>
}</syntaxhighlight>


=={{header|Dyalect}}==
=={{header|Dyalect}}==


<lang dyalect>func printVerse(name) {
<syntaxhighlight lang="dyalect">func printVerse(name) {
let x = name[..1].Upper() + name[1..].Lower();
let x = name[..1].Upper() + name[1..].Lower();
let y = "AEIOU".IndexOf(x[0]) > -1 ? x.Lower() : x[1..]
let y = "AEIOU".IndexOf(x[0]) > -1 ? x.Lower() : x[1..]
Line 763: Line 763:
for x in seq {
for x in seq {
printVerse(x)
printVerse(x)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 799: Line 799:
=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
===The function===
===The function===
<lang fsharp>
<syntaxhighlight lang="fsharp">
// The Name Game. Nigel Galloway: March 28th., 2018
// The Name Game. Nigel Galloway: March 28th., 2018
let fN g =
let fN g =
Line 809: Line 809:
|'m' -> fG ("b"+g.[1..]) ("f"+g.[1..]) (g.[1..])
|'m' -> fG ("b"+g.[1..]) ("f"+g.[1..]) (g.[1..])
|_ -> fG ("b"+g.[1..]) ("f"+g.[1..]) ("m"+g.[1..])
|_ -> fG ("b"+g.[1..]) ("f"+g.[1..]) ("m"+g.[1..])
</syntaxhighlight>
</lang>
===The Task===
===The Task===
<lang fsharp>
<syntaxhighlight lang="fsharp">
fN "Nigel"
fN "Nigel"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 821: Line 821:
Nigel!
Nigel!
</pre>
</pre>
<lang fsharp>
<syntaxhighlight lang="fsharp">
fN "Earl"
fN "Earl"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 831: Line 831:
Earl!
Earl!
</pre>
</pre>
<lang fsharp>
<syntaxhighlight lang="fsharp">
fN "Billy"
fN "Billy"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 841: Line 841:
Billy!
Billy!
</pre>
</pre>
<lang fsharp>
<syntaxhighlight lang="fsharp">
fN "Fred"
fN "Fred"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 851: Line 851:
Fred!
Fred!
</pre>
</pre>
<lang fsharp>
<syntaxhighlight lang="fsharp">
fN "Mum"
fN "Mum"
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 865: Line 865:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{works with|Factor|0.98}}
{{works with|Factor|0.98}}
<lang factor>USING: ascii combinators interpolate io kernel locals
<syntaxhighlight lang="factor">USING: ascii combinators interpolate io kernel locals
pair-rocket qw sequences ;
pair-rocket qw sequences ;
IN: rosetta-code.name-game
IN: rosetta-code.name-game
Line 888: Line 888:
${Name}!I] nl nl ;
${Name}!I] nl nl ;


qw{ Gary Earl Billy Felix Milton Steve } [ name-game ] each</lang>
qw{ Gary Earl Billy Felix Milton Steve } [ name-game ] each</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 923: Line 923:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>Sub TheGameName(nombre As String)
<syntaxhighlight lang="freebasic">Sub TheGameName(nombre As String)
Dim As String x = Lcase(nombre)
Dim As String x = Lcase(nombre)
x = Ucase(Mid(x,1,1)) + (Mid(x,2,Len(x)-1))
x = Ucase(Mid(x,1,1)) + (Mid(x,2,Len(x)-1))
Line 953: Line 953:
TheGameName(listanombres(i))
TheGameName(listanombres(i))
Next i
Next i
Sleep</lang>
Sleep</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 997: Line 997:
=={{header|Go}}==
=={{header|Go}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,032: Line 1,032:
printVerse(name)
printVerse(name)
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,068: Line 1,068:


=={{header|Haskell}}==
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">
<lang Haskell>
-- The Name Game, Ethan Riley, 22nd May 2018
-- The Name Game, Ethan Riley, 22nd May 2018
import Data.Char
import Data.Char
Line 1,110: Line 1,110:
main =
main =
mapM_ (putStrLn . theNameGame) ["Gary", "Earl", "Billy", "Felix", "Mike", "Steve"]
mapM_ (putStrLn . theNameGame) ["Gary", "Earl", "Billy", "Felix", "Mike", "Steve"]
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,146: Line 1,146:
=={{header|J}}==
=={{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.
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
T=:TEMPLATE=: noun define
(X), (X), bo-b(Y)
(X), (X), bo-b(Y)
Line 1,168: Line 1,168:
; XBox
; XBox
)
)
</syntaxhighlight>
</lang>
<pre>
<pre>
nameGame&> ;:'Gary Earl Billy Felix Mary'
nameGame&> ;:'Gary Earl Billy Felix Mary'
Line 1,199: Line 1,199:
=={{header|Java}}==
=={{header|Java}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang Java>import java.util.stream.Stream;
<syntaxhighlight lang="java">import java.util.stream.Stream;


public class NameGame {
public class NameGame {
Line 1,233: Line 1,233:
Stream.of("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").forEach(NameGame::printVerse);
Stream.of("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").forEach(NameGame::printVerse);
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 1,266: Line 1,266:


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang javaScript>function singNameGame(name) {
<syntaxhighlight lang="javascript">function singNameGame(name) {


// normalize name
// normalize name
Line 1,312: Line 1,312:
'Gary Earl Billy Felix Mary Christine Brian Yvonne Yannick'.split(' ');
'Gary Earl Billy Felix Mary Christine Brian Yvonne Yannick'.split(' ');
for (let i = 0; i < names.length; i++)
for (let i = 0; i < names.length; i++)
document.write(singNameGame(names[i]));</lang>
document.write(singNameGame(names[i]));</syntaxhighlight>
{{out}}<pre>
{{out}}<pre>
Gary, Gary, bo-bary
Gary, Gary, bo-bary
Line 1,361: Line 1,361:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>import Compat: uppercasefirst
<syntaxhighlight lang="julia">import Compat: uppercasefirst


function printverse(name::AbstractString)
function printverse(name::AbstractString)
Line 1,378: Line 1,378:
end
end


foreach(TheNameGame.printverse, ("gARY", "Earl", "Billy", "Felix", "Mary", "sHIRley"))</lang>
foreach(TheNameGame.printverse, ("gARY", "Earl", "Billy", "Felix", "Mary", "sHIRley"))</syntaxhighlight>


{{out}}
{{out}}
Line 1,412: Line 1,412:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.2.31
<syntaxhighlight lang="scala">// version 1.2.31


fun printVerse(name: String) {
fun printVerse(name: String) {
Line 1,434: Line 1,434:
fun main(args: Array<String>) {
fun main(args: Array<String>) {
listOf("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").forEach { printVerse(it) }
listOf("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").forEach { printVerse(it) }
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,471: Line 1,471:
=={{header|Lua}}==
=={{header|Lua}}==
{{trans|C#}}
{{trans|C#}}
<lang lua>function printVerse(name)
<syntaxhighlight lang="lua">function printVerse(name)
local sb = string.lower(name)
local sb = string.lower(name)
sb = sb:gsub("^%l", string.upper)
sb = sb:gsub("^%l", string.upper)
Line 1,508: Line 1,508:
for _,name in pairs(nameList) do
for _,name in pairs(nameList) do
printVerse(name)
printVerse(name)
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 1,545: Line 1,545:
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")
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 {
Module The.Name.Game {
Flush
Flush
Line 1,572: Line 1,572:
}
}
The.Name.Game
The.Name.Game
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,600: Line 1,600:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>ClearAll[NameGame]
<syntaxhighlight lang="mathematica">ClearAll[NameGame]
NameGame[n_] := Module[{y, b, f, m},
NameGame[n_] := Module[{y, b, f, m},
If[StringStartsQ[ToLowerCase[n], "a" | "e" | "i" | "u" | "o"],
If[StringStartsQ[ToLowerCase[n], "a" | "e" | "i" | "u" | "o"],
Line 1,622: Line 1,622:
NameGame["Felix"]
NameGame["Felix"]
NameGame["Mary"]
NameGame["Mary"]
NameGame["Steve"]</lang>
NameGame["Steve"]</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 1,657: Line 1,657:
{{works with|min|0.19.3}}
{{works with|min|0.19.3}}
{{trans|Factor}}
{{trans|Factor}}
<lang min>("AEIOU" "" split swap in?) :vowel?
<syntaxhighlight lang="min">("AEIOU" "" split swap in?) :vowel?


(
(
Line 1,675: Line 1,675:
) :name-game
) :name-game


("Gary" "Earl" "Billy" "Felix" "Milton" "Steve") 'name-game foreach</lang>
("Gary" "Earl" "Billy" "Felix" "Milton" "Steve") 'name-game foreach</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,711: Line 1,711:
=={{header|MIPS Assembly}}==
=={{header|MIPS Assembly}}==
The cartridge header and print routines were omitted so that the reader can focus on the logic.
The cartridge header and print routines were omitted so that the reader can focus on the logic.
<lang mips> la $a0,theNameGame
<syntaxhighlight lang="mips"> la $a0,theNameGame
la $s0,theName
la $s0,theName
jal PrintString_NameGame
jal PrintString_NameGame
Line 1,860: Line 1,860:
.ascii "?!"
.ascii "?!"
.byte 0
.byte 0
.align 4</lang>
.align 4</syntaxhighlight>
{{out}}
{{out}}
[https://ibb.co/V9GcTFV Screenshot of emulator]
[https://ibb.co/V9GcTFV Screenshot of emulator]
Line 1,879: Line 1,879:


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE NameGame;
<syntaxhighlight lang="modula2">MODULE NameGame;
FROM Strings IMPORT Concat;
FROM Strings IMPORT Concat;
FROM ExStrings IMPORT Lowercase;
FROM ExStrings IMPORT Lowercase;
Line 1,944: Line 1,944:


ReadChar;
ReadChar;
END NameGame.</lang>
END NameGame.</syntaxhighlight>


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
{{trans|Python}}
{{trans|Python}}
<lang Nanoquery>def print_verse(n)
<syntaxhighlight lang="nanoquery">def print_verse(n)
l = {"b", "f", "m"}
l = {"b", "f", "m"}
s = n.substring(1)
s = n.substring(1)
Line 1,967: Line 1,967:
for n in names
for n in names
print_verse(n)
print_verse(n)
end</lang>
end</syntaxhighlight>




=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>import strutils
<syntaxhighlight lang="nim">import strutils


const
const
Line 1,997: Line 1,997:
for name in ["Gary", "Earl", "Billy", "Felix", "Mary"]:
for name in ["Gary", "Earl", "Billy", "Felix", "Mary"]:
echo name.lyrics()
echo name.lyrics()
echo()</lang>
echo()</syntaxhighlight>


{{out}}
{{out}}
Line 2,027: Line 2,027:
=={{header|Perl}}==
=={{header|Perl}}==
{{trans|Lua}}
{{trans|Lua}}
<lang perl>sub printVerse {
<syntaxhighlight lang="perl">sub printVerse {
$x = ucfirst lc shift;
$x = ucfirst lc shift;
$x0 = substr $x, 0, 1;
$x0 = substr $x, 0, 1;
Line 2,040: Line 2,040:
}
}


printVerse($_) for <Gary Earl Billy Felix Mary Steve>;</lang>
printVerse($_) for <Gary Earl Billy Felix Mary Steve>;</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 2,074: Line 2,074:
=={{header|Phix}}==
=={{header|Phix}}==
{{trans|Go}}
{{trans|Go}}
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">fmt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
<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
%s, %s, bo-%s
Line 2,099: Line 2,099:
<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;">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>
<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>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 2,135: Line 2,135:
=={{header|Picat}}==
=={{header|Picat}}==
{{works with|Picat}}
{{works with|Picat}}
<syntaxhighlight lang="picat">
<lang Picat>
print_name_game(Name), Name = [V|Rest], membchk(V, ['A', 'E', 'I', 'O', 'U']) =>
print_name_game(Name), Name = [V|Rest], membchk(V, ['A', 'E', 'I', 'O', 'U']) =>
L = to_lowercase(V),
L = to_lowercase(V),
Line 2,167: Line 2,167:
print_name_game(Name)
print_name_game(Name)
end.
end.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,199: Line 2,199:
=={{header|PowerShell}}==
=={{header|PowerShell}}==
{{trans|Chris}}
{{trans|Chris}}
<syntaxhighlight lang="powershell">
<lang Powershell>
## Clear Host from old Ouput
## Clear Host from old Ouput
Clear-Host
Clear-Host
Line 2,253: Line 2,253:
}
}
Write-Host "$Name"
Write-Host "$Name"
</syntaxhighlight>
</lang>


=={{header|Prolog}}==
=={{header|Prolog}}==
<lang Prolog>map_name1(C, Cs, C, Cs).
<syntaxhighlight lang="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,C|Cs]) :- member(C, ['a','e','i','o','u']).
map_name1(C, Cs, Fc, [Fc|Cs]) :-
map_name1(C, Cs, Fc, [Fc|Cs]) :-
Line 2,281: Line 2,281:


test :-
test :-
maplist(song, ["Gary", "Earl", "Billy", "Felix", "Mary"]).</lang>
maplist(song, ["Gary", "Earl", "Billy", "Felix", "Mary"]).</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,314: Line 2,314:


=={{header|Python}}==
=={{header|Python}}==
<lang Python>def print_verse(n):
<syntaxhighlight lang="python">def print_verse(n):
l = ['b', 'f', 'm']
l = ['b', 'f', 'm']
s = n[1:]
s = n[1:]
Line 2,325: Line 2,325:
# Assume that the names are in title-case and they're more than one character long
# Assume that the names are in title-case and they're more than one character long
for n in ['Gary', 'Earl', 'Billy', 'Felix', 'Mary']:
for n in ['Gary', 'Earl', 'Billy', 'Felix', 'Mary']:
print_verse(n)</lang>
print_verse(n)</syntaxhighlight>


=={{header|q}}==
=={{header|q}}==
===String search and replace===
===String search and replace===
<lang q>game_ssr:{[Name]
<syntaxhighlight lang="q">game_ssr:{[Name]
V:raze 1 lower\"AEIOUY"; / vowels
V:raze 1 lower\"AEIOUY"; / vowels
tn:lower((Name in V)?1b) _ Name; / truncated Name
tn:lower((Name in V)?1b) _ Name; / truncated Name
Line 2,335: Line 2,335:
s:"$1, $1, bo-b$2\nBanana-fana-fo-f$2\nFee-fimo-m$2\n$1!\n\n";
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)) }
(ssr/).(s;("$1";"$2";s3 0);(Name;tn;s3 1)) }
</syntaxhighlight>
</lang>
===Amend a list of strings===
===Amend a list of strings===
<lang q>game_amend:{[Name]
<syntaxhighlight lang="q">game_amend:{[Name]
pfx:Name,", ",Name,", "; / prefix
pfx:Name,", ",Name,", "; / prefix
n:lower Name;
n:lower Name;
Line 2,346: Line 2,346:
// test
// test
1 "\n"sv raze game_ssr each ("Gary";"Earl";"Felix";"Stephen";"Ryan";"Jo");
1 "\n"sv raze game_ssr each ("Gary";"Earl";"Felix";"Stephen";"Ryan";"Jo");
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 2,386: Line 2,386:
Meh. The rules leave out some corner cases (see Steve) but what the heck, technically correct is the best kind of correct.
Meh. The rules leave out some corner cases (see Steve) but what the heck, technically correct is the best kind of correct.


<lang perl6>sub mangle ($name, $initial) {
<syntaxhighlight lang="raku" line>sub mangle ($name, $initial) {
my $fl = $name.lc.substr(0,1);
my $fl = $name.lc.substr(0,1);
$fl ~~ /<[aeiou]>/
$fl ~~ /<[aeiou]>/
Line 2,404: Line 2,404:
}
}


say .&name-game for <Gary Earl Billy Felix Mike Steve></lang>
say .&name-game for <Gary Earl Billy Felix Mike Steve></syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 2,440: Line 2,440:
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).
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).
<br>Also, dual names are supported &nbsp;(like Mary Ann).
<lang rexx>/*REXX program displays the lyrics of the song "The Name Game" by Shirley Ellis. */
<syntaxhighlight lang="rexx">/*REXX program displays the lyrics of the song "The Name Game" by Shirley Ellis. */
parse arg $ /*obtain optional argument(s) from C.L.*/
parse arg $ /*obtain optional argument(s) from C.L.*/
if $='' then $="gAry, eARL, billy, FeLix, MarY" /*Not specified? Then use the default.*/
if $='' then $="gAry, eARL, billy, FeLix, MarY" /*Not specified? Then use the default.*/
Line 2,472: Line 2,472:
end /*select*/
end /*select*/
say z'!'; say
say z'!'; say
return</lang>
return</syntaxhighlight>
{{out|output|text= &nbsp; when using the default (internal) names:}}
{{out|output|text= &nbsp; when using the default (internal) names:}}
<pre>
<pre>
Line 2,505: Line 2,505:
More idiomatic Ruby while not being object-oriented.
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".
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".
<lang ruby>#!/usr/bin/env ruby
<syntaxhighlight lang="ruby">#!/usr/bin/env ruby


def print_verse(name)
def print_verse(name)
Line 2,544: Line 2,544:
end
end


</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 2,589: Line 2,589:


=={{header|Scala}}==
=={{header|Scala}}==
<lang Scala>object NameGame extends App {
<syntaxhighlight lang="scala">object NameGame extends App {
private def printVerse(name: String): Unit = {
private def printVerse(name: String): Unit = {
val x = name.toLowerCase.capitalize
val x = name.toLowerCase.capitalize
Line 2,609: Line 2,609:


Stream("gAry", "earl", "Billy", "Felix", "Mary", "Steve").foreach(printVerse)
Stream("gAry", "earl", "Billy", "Felix", "Mary", "Steve").foreach(printVerse)
}</lang>
}</syntaxhighlight>


See it running in your browser by [https://scastie.scala-lang.org/UilFJ0zFSJu4Qk2xaw2r4A Scastie (JVM)].
See it running in your browser by [https://scastie.scala-lang.org/UilFJ0zFSJu4Qk2xaw2r4A Scastie (JVM)].
Line 2,616: Line 2,616:
This implements the required rules and also attempts to handle names that start with consonant clusters.
This implements the required rules and also attempts to handle names that start with consonant clusters.


<lang sh>#!/usr/bin/env bash
<syntaxhighlight lang="sh">#!/usr/bin/env bash
namegame() {
namegame() {
local name=$1 b=b f=f m=m
local name=$1 b=b f=f m=m
Line 2,645: Line 2,645:
namegame "$name"
namegame "$name"
echo
echo
done</lang>
done</syntaxhighlight>


{{Out}}
{{Out}}
Line 2,681: Line 2,681:


=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>Option Explicit
<syntaxhighlight lang="vb">Option Explicit


Sub Main()
Sub Main()
Line 2,712: Line 2,712:
Next
Next
TheGameName = t
TheGameName = t
End Function</lang>
End Function</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 2,751: Line 2,751:
=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
{{trans|C#}}
{{trans|C#}}
<lang vbnet>Option Strict On
<syntaxhighlight lang="vbnet">Option Strict On


Imports System.Text
Imports System.Text
Line 2,790: Line 2,790:
End Sub
End Sub


End Module</lang>
End Module</syntaxhighlight>
{{out}}
{{out}}
<pre>Gary, Gary, bo-bary
<pre>Gary, Gary, bo-bary
Line 2,823: Line 2,823:


=={{header|Vlang}}==
=={{header|Vlang}}==
<lang vlang>fn main() {
<syntaxhighlight lang="vlang">fn main() {
list := ['Gary', 'Earl', 'Billy', 'Felix', 'Mary']
list := ['Gary', 'Earl', 'Billy', 'Felix', 'Mary']
for name in list {verse(name)}
for name in list {verse(name)}
Line 2,846: Line 2,846:
println('Fee-fi-mo-$m')
println('Fee-fi-mo-$m')
println('$x!\n')
println('$x!\n')
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 2,879: Line 2,879:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{libheader|Wren-str}}
{{libheader|Wren-str}}
<lang ecmascript>import "/str" for Str
<syntaxhighlight lang="ecmascript">import "/str" for Str


var printVerse = Fn.new { |name|
var printVerse = Fn.new { |name|
Line 2,901: Line 2,901:
}
}


["Gary", "Earl", "Billy", "Felix", "Mary", "Steve"].each { |name| printVerse.call(name) }</lang>
["Gary", "Earl", "Billy", "Felix", "Mary", "Steve"].each { |name| printVerse.call(name) }</syntaxhighlight>


{{out}}
{{out}}
Line 2,938: Line 2,938:
=={{header|Z80 Assembly}}==
=={{header|Z80 Assembly}}==
{{trans|MIPS Assembly}}
{{trans|MIPS Assembly}}
<lang z80>;;;;;;;;;;;;;;;;;;; HEADER ;;;;;;;;;;;;;;;;;;;
<syntaxhighlight lang="z80">;;;;;;;;;;;;;;;;;;; HEADER ;;;;;;;;;;;;;;;;;;;
read "\SrcCPC\winape_macros.asm"
read "\SrcCPC\winape_macros.asm"
read "\SrcCPC\MemoryMap.asm"
read "\SrcCPC\MemoryMap.asm"
Line 3,046: Line 3,046:
db "fee-fi-mo-%",13,10
db "fee-fi-mo-%",13,10
db "?!",13,10,13,10
db "?!",13,10,13,10
db 0</lang>
db 0</syntaxhighlight>
{{out}}
{{out}}
<pre>gary, gary, bo-bary
<pre>gary, gary, bo-bary
Line 3,065: Line 3,065:
=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<lang zkl>fcn printVerse(name){
<syntaxhighlight lang="zkl">fcn printVerse(name){
z,x := name[0].toLower(), z.toUpper() + name[1,*].toLower();
z,x := name[0].toLower(), z.toUpper() + name[1,*].toLower();
y:=( if("aeiou".holds(z)) name.toLower() else x[1,*] );
y:=( if("aeiou".holds(z)) name.toLower() else x[1,*] );
Line 3,073: Line 3,073:
println("Fee-fi-mo-",m);
println("Fee-fi-mo-",m);
println(x,"!\n");
println(x,"!\n");
}</lang>
}</syntaxhighlight>
<lang zkl>List("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").apply2(printVerse);</lang>
<syntaxhighlight lang="zkl">List("Gary", "Earl", "Billy", "Felix", "Mary", "Steve").apply2(printVerse);</syntaxhighlight>
{{out}}
{{out}}
<pre style="height:35ex">
<pre style="height:35ex">