トラック
/
Wren
Wren
/
演習
/
食物連鎖
食物連鎖

食物連鎖

中級

説明

『I Know an Old Lady Who Swallowed a Fly』という歌の歌詞を生成しましょう。

歌詞をそのままコピー&ペーストしたり、ファイルから読み込んだりしてもかまいませんが、アルゴリズム的に解いてみると、この問題はずっと面白くなります。

これは、作者不明の累積歌です。

よく知られている数あるバリエーションのうちのひとつです。

I know an old lady who swallowed a fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a spider.
It wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a bird.
How absurd to swallow a bird!
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a cat.
Imagine that, to swallow a cat!
She swallowed the cat to catch the bird.
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a dog.
What a hog, to swallow a dog!
She swallowed the dog to catch the cat.
She swallowed the cat to catch the bird.
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a goat.
Just opened her throat and swallowed a goat!
She swallowed the goat to catch the dog.
She swallowed the dog to catch the cat.
She swallowed the cat to catch the bird.
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a cow.
I don't know how she swallowed a cow!
She swallowed the cow to catch the goat.
She swallowed the goat to catch the dog.
She swallowed the dog to catch the cat.
She swallowed the cat to catch the bird.
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a horse.
She's dead, of course!

Wrenのメソッドシグネチャ

Wrenでは、メソッドを_引数の数_でオーバーロードできます。つまり、受け取る引数の数が違っていれば、クラスに同じ名前のメソッドを2つ(またはそれ以上)持たせることができます。

詳しくはシグネチャを参照してください。


出典

Wikipediaリンクは新しいウィンドウまたはタブで開きます
GitHubで編集する リンクは新しいウィンドウまたはタブで開きます
Wren Exercism

食物連鎖を始める準備はできましたか?

Exercismに登録すれば、117個の演習、そして本物の人間によるメンタリングとともに、Wrenを学んでマスターできます。すべて無料です。