The Name Game: Difference between revisions

 
(5 intermediate revisions by 4 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
proc 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$
proc 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,235 ⟶ 1,168:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/The_Name_Game}}
 
'''Solution'''
 
[[File:Fōrmulæ - The Name Game 01.png]]
 
'''Test cases'''
 
[[File:Fōrmulæ - The Name Game 02.png]]
 
[[File:Fōrmulæ - The Name Game 03.png]]
 
=={{header|Go}}==
Line 3,167 ⟶ 3,110:
{{trans|Kotlin}}
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "./str" for Str
 
var printVerse = Fn.new { |name|
1,983

edits