'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!
이 연습 문제는 코드 리팩터링에 관한 것이에요. 그래서 이미 테스트를 통과하는 풀이를 함께 제공해 드려요.
도전 과제는 스스로 만족할 때까지 이 풀이를 다시 작성하고, 그 과정에서 무언가를 배우는 거예요.
어디서부터 시작해야 할지 모르겠다면, 몇 가지 아이디어를 드릴게요.
천천히 해도 괜찮아요.
한 번에 하나씩 바꾸고, 풀이가 여전히 테스트를 통과하는지 확인해요.
즐겁게 해봐요!
Exercism에 가입하고 Haskell 트랙을 연습 문제 107개, 그리고 실제 사람의 멘토링과 함께 배우고 익혀 보세요. 모두 무료예요.