Jump to content

The Name Game: Difference between revisions

Added Prolog implementation
(Added Prolog implementation)
Line 1,626:
Write-Host "$Name"
</lang>
 
=={{header|Prolog}}==
<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|Cs]) :-
\+ member(C, ['a','e','i','o','u']),
dif(C, Fc).
 
map_name(C, Cs, Fc, Name) :-
map_name1(C, Cs, Fc, NChars),
atom_chars(Name, NChars).
 
song(Name) :-
string_lower(Name, LName),
atom_chars(LName, [First|Chars]),
map_name(First, Chars, 'b', BName),
map_name(First, Chars, 'f', FName),
map_name(First, Chars, 'm', MName),
maplist(write,
[Name, ", ", Name, ", bo-", BName, '\n',
"Banana-fana fo-", FName, '\n',
"Fee-fi-mo-", MName, '\n',
Name, "!\n\n"]).
 
test :-
maplist(song, ["Gary", "Earl", "Billy", "Felix", "Mary"]).</lang>
{{out}}
<pre>
1 ?- test.
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!
 
true
</pre>
 
=={{header|Python}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.