Exercism: Go version of the 'Food Chain' exercise.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.9 KiB

9 years ago
  1. # Food Chain
  2. Write a program that generates the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'
  3. Write a program that generates the lyrics to the song
  4. "I know an old lady who swallowed a fly". While you could
  5. copy/paste the lyrics, or read them from a file, this
  6. problem is much more interesting if you approach it
  7. algorithmically.
  8. This is a [cumulative song](http://en.wikipedia.org/wiki/Cumulative_song) of unknown origin.
  9. This is one of many common variants.
  10. ```plain
  11. I know an old lady who swallowed a fly.
  12. I don't know why she swallowed the fly. Perhaps she'll die.
  13. I know an old lady who swallowed a spider.
  14. It wriggled and jiggled and tickled inside her.
  15. She swallowed the spider to catch the fly.
  16. I don't know why she swallowed the fly. Perhaps she'll die.
  17. I know an old lady who swallowed a bird.
  18. How absurd to swallow a bird!
  19. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
  20. She swallowed the spider to catch the fly.
  21. I don't know why she swallowed the fly. Perhaps she'll die.
  22. I know an old lady who swallowed a cat.
  23. Imagine that, to swallow a cat!
  24. She swallowed the cat to catch the bird.
  25. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
  26. She swallowed the spider to catch the fly.
  27. I don't know why she swallowed the fly. Perhaps she'll die.
  28. I know an old lady who swallowed a dog.
  29. What a hog, to swallow a dog!
  30. She swallowed the dog to catch the cat.
  31. She swallowed the cat to catch the bird.
  32. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
  33. She swallowed the spider to catch the fly.
  34. I don't know why she swallowed the fly. Perhaps she'll die.
  35. I know an old lady who swallowed a goat.
  36. Just opened her throat and swallowed a goat!
  37. She swallowed the goat to catch the dog.
  38. She swallowed the dog to catch the cat.
  39. She swallowed the cat to catch the bird.
  40. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
  41. She swallowed the spider to catch the fly.
  42. I don't know why she swallowed the fly. Perhaps she'll die.
  43. I know an old lady who swallowed a cow.
  44. I don't know how she swallowed a cow!
  45. She swallowed the cow to catch the goat.
  46. She swallowed the goat to catch the dog.
  47. She swallowed the dog to catch the cat.
  48. She swallowed the cat to catch the bird.
  49. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
  50. She swallowed the spider to catch the fly.
  51. I don't know why she swallowed the fly. Perhaps she'll die.
  52. I know an old lady who swallowed a horse.
  53. She's dead, of course!
  54. ```
  55. To run the tests simply run the command `go test` in the exercise directory.
  56. If the test suite contains benchmarks, you can run these with the `-bench`
  57. flag:
  58. go test -bench .
  59. For more detailed info about the Go track see the [help
  60. page](http://exercism.io/languages/go).
  61. ## Source
  62. Wikipedia [view source](http://en.wikipedia.org/wiki/There_Was_an_Old_Lady_Who_Swallowed_a_Fly)