Old lady swallowed a fly: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 309:
:done
pause>nul&exit/b 0</lang>
 
=={{header|Befunge}}==
We start with a collection of reusable phrases stored as a linked list. We then build up the sequence of indices into that list necessary to produce the song (this step is largely programmatic, because of the repetitive nature, although some of the verses require special case handling). Finally we iterate over the indices and print out the associated phrases.
 
<lang befunge>055*46*146*1->00p 36268>5\:4\:2v >\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v
>-#2:#\8#1`#:|#-1:-1\7_^#`g00:+<>\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
>$ 36 26 58 49 81 36 26 10 \1-:#^\_^#:-1\+<00_@#:>#<$<
DI know an old lady who swallowed a F.|I don't know why she swallowed the 8.|Pe
rhaps she'll die.||5.|She swallowed the / to catch the $fly0. To swallow a 'spi
derS.|That wriggled and jiggled and tickled inside her%Bird/.|Quite absurd$Cat-
.|Fancy that$Dog-.|What a hog$Pig7.|Her mouth was so big%Goat=.|She just opened
her throat$Cow3.|I don't know how'Donkey6.|It was rather wonky&Horse:.|She's d
ead, of course!|</lang>
 
=={{header|BBC BASIC}}==
Line 353 ⟶ 340:
ENDCASE
ENDPROC</lang>
 
=={{header|Befunge}}==
We start with a collection of reusable phrases stored as a linked list. We then build up the sequence of indices into that list necessary to produce the song (this step is largely programmatic, because of the repetitive nature, although some of the verses require special case handling). Finally we iterate over the indices and print out the associated phrases.
 
<lang befunge>055*46*146*1->00p 36268>5\:4\:2v >\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v
>-#2:#\8#1`#:|#-1:-1\7_^#`g00:+<>\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
>$ 36 26 58 49 81 36 26 10 \1-:#^\_^#:-1\+<00_@#:>#<$<
DI know an old lady who swallowed a F.|I don't know why she swallowed the 8.|Pe
rhaps she'll die.||5.|She swallowed the / to catch the $fly0. To swallow a 'spi
derS.|That wriggled and jiggled and tickled inside her%Bird/.|Quite absurd$Cat-
.|Fancy that$Dog-.|What a hog$Pig7.|Her mouth was so big%Goat=.|She just opened
her throat$Cow3.|I don't know how'Donkey6.|It was rather wonky&Horse:.|She's d
ead, of course!|</lang>
 
=={{header|C}}==
Line 388:
printf("%s\n", verses[0]);
}
}
}
}</lang>
 
=={{header|C sharp|C#}}==
<lang csharp>using System;
 
namespace OldLady
{
internal class Program
{
private const string reason = "She swallowed the {0} to catch the {1}";
private static readonly string[] creatures = {"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"};
 
private static readonly string[] comments =
{
"I don't know why she swallowed that fly.\nPerhaps she'll die\n",
"That wiggled and jiggled and tickled inside her",
"How absurd, to swallow a bird",
"Imagine that. She swallowed a cat",
"What a hog to swallow a dog",
"She just opened her throat and swallowed that goat",
"I don't know how she swallowed that cow",
"She's dead of course"
};
 
private static void Main()
{
int max = creatures.Length;
for (int i = 0; i < max; i++)
{
Console.WriteLine("There was an old lady who swallowed a {0}", creatures[i]);
Console.WriteLine(comments[i]);
for (int j = i; j > 0 && i < max - 1; j--)
{
Console.WriteLine(reason, creatures[j], creatures[j - 1]);
if (j == 1)
{
Console.WriteLine(comments[j - 1]);
}
}
}
Console.Read();
}
}
Line 482 ⟶ 525:
There was an old lady who swallowed a horse
She's dead of course</pre>
 
=={{header|C sharp|C#}}==
<lang csharp>using System;
 
namespace OldLady
{
internal class Program
{
private const string reason = "She swallowed the {0} to catch the {1}";
private static readonly string[] creatures = {"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse"};
 
private static readonly string[] comments =
{
"I don't know why she swallowed that fly.\nPerhaps she'll die\n",
"That wiggled and jiggled and tickled inside her",
"How absurd, to swallow a bird",
"Imagine that. She swallowed a cat",
"What a hog to swallow a dog",
"She just opened her throat and swallowed that goat",
"I don't know how she swallowed that cow",
"She's dead of course"
};
 
private static void Main()
{
int max = creatures.Length;
for (int i = 0; i < max; i++)
{
Console.WriteLine("There was an old lady who swallowed a {0}", creatures[i]);
Console.WriteLine(comments[i]);
for (int j = i; j > 0 && i < max - 1; j--)
{
Console.WriteLine(reason, creatures[j], creatures[j - 1]);
if (j == 1)
{
Console.WriteLine(comments[j - 1]);
}
}
}
Console.Read();
}
}
}</lang>
 
=={{header|COBOL}}==
Line 1,393:
 
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/printf.icn printf.icn provides printf formatting]
 
=={{header|J}}==
Line 2,107:
559fx8xqpsquRaFYV9I9fT6p7RrI/Gv/F3JFOFCQRJtf/Q==
====</lang>
=={{header|Perl 6}}==
<lang perl6>my @victims =
fly => " I don't know why S—",
spider => " That wriggled and jiggled and tickled inside her.",
bird => " How absurd, T!",
cat => " Fancy that, S!",
dog => " What a hog, T!",
goat => " She just opened her throat, and in walked the goat!",
cow => " I don't know how S!",
horse => " She's dead, of course...";
 
my @history = "I guess she'll die...\n";
 
for (flat @victims».kv) -> $victim, $_ is copy {
say "There was an old lady who swallowed a $victim...";
 
s/ «S» /she swallowed the $victim/;
s/ «T» /to swallow a $victim!/;
.say;
last when /dead/;
 
@history[0] ~~ s/^X/She swallowed the $victim/;
.say for @history;
@history.unshift($_) if @history < 5;
@history.unshift("X to catch the $victim,");
}</lang>
And that's how I larned it!
 
=={{header|Phix}}==
Line 2,357 ⟶ 2,330:
3KZdqvwDbfWhXPhY+S59RLX5dkTapF66/2/3fYMNMZklVJfAhlgjHKW2k8B7tbtRrw==
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>my @victims =
fly => " I don't know why S—",
spider => " That wriggled and jiggled and tickled inside her.",
bird => " How absurd, T!",
cat => " Fancy that, S!",
dog => " What a hog, T!",
goat => " She just opened her throat, and in walked the goat!",
cow => " I don't know how S!",
horse => " She's dead, of course...";
 
my @history = "I guess she'll die...\n";
 
for (flat @victims».kv) -> $victim, $_ is copy {
say "There was an old lady who swallowed a $victim...";
 
s/ «S» /she swallowed the $victim/;
s/ «T» /to swallow a $victim!/;
.say;
last when /dead/;
 
@history[0] ~~ s/^X/She swallowed the $victim/;
.say for @history;
@history.unshift($_) if @history < 5;
@history.unshift("X to catch the $victim,");
}</lang>
And that's how I larned it!
 
=={{header|REXX}}==
Line 2,482 ⟶ 2,484:
print "Perhaps she'll die.\n\n"
end</lang>
 
=={{header|Rust}}==
[https://play.rust-lang.org/?gist=294c9e29f206d7c8d8028aa5e7002d9a&version=nightly Rust Playground]
10,327

edits