From 6b19b7545d97b3881b47946555966932c1f43259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Fri, 13 Sep 2024 22:11:44 -0700 Subject: [PATCH] Implement exercise 'food-chain' --- config.json | 8 + config.yaml | 7 + .../practice/food-chain/.docs/instructions.md | 64 +++++++ .../food-chain/.meta/.yamlscript/exercise.mk | 1 + exercises/practice/food-chain/.meta/Makefile | 28 +++ .../practice/food-chain/.meta/config.json | 23 +++ .../food-chain/.meta/food-chain-test.ys | 173 ++++++++++++++++++ .../practice/food-chain/.meta/food-chain.ys | 40 ++++ .../practice/food-chain/.meta/tests.toml | 40 ++++ .../food-chain/.yamlscript/exercise.mk | 1 + .../.yamlscript/exercism-ys-installer | 127 +++++++++++++ exercises/practice/food-chain/GNUmakefile | 49 +++++ exercises/practice/food-chain/Makefile | 8 + .../practice/food-chain/food-chain-test.ys | 163 +++++++++++++++++ exercises/practice/food-chain/food-chain.ys | 4 + 15 files changed, 736 insertions(+) create mode 100644 exercises/practice/food-chain/.docs/instructions.md create mode 100644 exercises/practice/food-chain/.meta/.yamlscript/exercise.mk create mode 100644 exercises/practice/food-chain/.meta/Makefile create mode 100644 exercises/practice/food-chain/.meta/config.json create mode 100644 exercises/practice/food-chain/.meta/food-chain-test.ys create mode 100644 exercises/practice/food-chain/.meta/food-chain.ys create mode 100644 exercises/practice/food-chain/.meta/tests.toml create mode 100644 exercises/practice/food-chain/.yamlscript/exercise.mk create mode 100644 exercises/practice/food-chain/.yamlscript/exercism-ys-installer create mode 100644 exercises/practice/food-chain/GNUmakefile create mode 100644 exercises/practice/food-chain/Makefile create mode 100644 exercises/practice/food-chain/food-chain-test.ys create mode 100644 exercises/practice/food-chain/food-chain.ys diff --git a/config.json b/config.json index 3b10924..f456bf1 100644 --- a/config.json +++ b/config.json @@ -428,6 +428,14 @@ "prerequisites": [], "difficulty": 5 }, + { + "slug": "food-chain", + "name": "Food Chain", + "uuid": "fb4bd2e9-9ca0-41e3-90c7-1adad92d0dd1", + "practices": [], + "prerequisites": [], + "difficulty": 5 + }, { "slug": "matching-brackets", "name": "Matching Brackets", diff --git a/config.yaml b/config.yaml index 7601252..ed512bc 100644 --- a/config.yaml +++ b/config.yaml @@ -386,6 +386,13 @@ exercises: prerequisites: [] difficulty: 5 + - slug: food-chain + name: Food Chain + uuid: fb4bd2e9-9ca0-41e3-90c7-1adad92d0dd1 + practices: [] + prerequisites: [] + difficulty: 5 + - slug: matching-brackets name: Matching Brackets uuid: a6c79db6-925c-45c3-8a59-aa9d96a4740b diff --git a/exercises/practice/food-chain/.docs/instructions.md b/exercises/practice/food-chain/.docs/instructions.md new file mode 100644 index 0000000..125820e --- /dev/null +++ b/exercises/practice/food-chain/.docs/instructions.md @@ -0,0 +1,64 @@ +# Instructions + +Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'. + +While you could copy/paste the lyrics, or read them from a file, this problem is much more interesting if you approach it algorithmically. + +This is a [cumulative song][cumulative-song] of unknown origin. + +This is one of many common variants. + +```text +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! +``` + +[cumulative-song]: https://en.wikipedia.org/wiki/Cumulative_song diff --git a/exercises/practice/food-chain/.meta/.yamlscript/exercise.mk b/exercises/practice/food-chain/.meta/.yamlscript/exercise.mk new file mode 100644 index 0000000..2506034 --- /dev/null +++ b/exercises/practice/food-chain/.meta/.yamlscript/exercise.mk @@ -0,0 +1 @@ +YS_VERSION := 0.1.75 diff --git a/exercises/practice/food-chain/.meta/Makefile b/exercises/practice/food-chain/.meta/Makefile new file mode 100644 index 0000000..08aff24 --- /dev/null +++ b/exercises/practice/food-chain/.meta/Makefile @@ -0,0 +1,28 @@ +SHELL := bash + +BASE := $(shell pwd) + +export YS_VERSION := 0.1.79 + +YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION) + +YS_LOCAL_BIN := $(YS_LOCAL_PREFIX)/bin + +YS_BIN := $(YS_LOCAL_BIN)/ys-$(YS_VERSION) + +TEST_FILE ?= $(wildcard *-test.ys) + + +export PATH := $(YS_LOCAL_BIN):$(PATH) + +export YSPATH := $(BASE) + + +default: + +test: $(YS_BIN) + prove -v $(TEST_FILE) + +$(YS_BIN): + curl -s https://yamlscript.org/install | \ + BIN=1 VERSION=$(YS_VERSION) PREFIX=$(YS_LOCAL_PREFIX) bash >/dev/null diff --git a/exercises/practice/food-chain/.meta/config.json b/exercises/practice/food-chain/.meta/config.json new file mode 100644 index 0000000..9ee23df --- /dev/null +++ b/exercises/practice/food-chain/.meta/config.json @@ -0,0 +1,23 @@ +{ + "authors": [ + "ingydotnet" + ], + "files": { + "solution": [ + "food-chain.ys" + ], + "test": [ + "food-chain-test.ys", + "GNUmakefile", + "Makefile", + ".yamlscript/exercise.mk", + ".yamlscript/exercism-ys-installer" + ], + "example": [ + ".meta/food-chain.ys" + ] + }, + "blurb": "Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'.", + "source": "Wikipedia", + "source_url": "https://en.wikipedia.org/wiki/There_Was_an_Old_Lady_Who_Swallowed_a_Fly" +} diff --git a/exercises/practice/food-chain/.meta/food-chain-test.ys b/exercises/practice/food-chain/.meta/food-chain-test.ys new file mode 100644 index 0000000..404d798 --- /dev/null +++ b/exercises/practice/food-chain/.meta/food-chain-test.ys @@ -0,0 +1,173 @@ +#!/usr/bin/env ys-0 + +require ys::taptest: :all + +use: food-chain + +# JSON doesn't allow for multi-line strings, so all verses are presented +# here as arrays of strings. It's up to the test generator to join the +# lines together with line breaks. +# Some languages test for the verse() method, which takes a start verse +# and optional end verse, but other languages have only tested for the full poem. +# For those languages in the latter category, you may wish to only +# implement the full song test and leave the rest alone, ignoring the start +# and end verse fields. + +test:: +- name: Fly + code: recite(1 1) + want: + - I know an old lady who swallowed a fly. + - I don't know why she swallowed the fly. Perhaps she'll die. + uuid: 751dce68-9412-496e-b6e8-855998c56166 + +- name: Spider + code: recite(2 2) + want: + - 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. + uuid: 6c56f861-0c5e-4907-9a9d-b2efae389379 + +- name: Bird + code: recite(3 3) + want: + - 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. + uuid: 3edf5f33-bef1-4e39-ae67-ca5eb79203fa + +- name: Cat + code: recite(4 4) + want: + - 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. + uuid: e866a758-e1ff-400e-9f35-f27f28cc288f + +- name: Dog + code: recite(5 5) + want: + - 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. + uuid: 3f02c30e-496b-4b2a-8491-bc7e2953cafb + +- name: Goat + code: recite(6 6) + want: + - 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. + uuid: 4b3fd221-01ea-46e0-825b-5734634fbc59 + +- name: Cow + code: recite(7 7) + want: + - 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. + uuid: 1b707da9-7001-4fac-941f-22ad9c7a65d4 + +- name: Horse + code: recite(8 8) + want: + - I know an old lady who swallowed a horse. + - She's dead, of course! + uuid: 3cb10d46-ae4e-4d2c-9296-83c9ffc04cdc + +- name: Multiple verses + code: recite(1 3) + want: + - 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. + uuid: 22b863d5-17e4-4d1e-93e4-617329a5c050 + +- name: Full song + code: recite(1 8) + want: + - 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! + uuid: e626b32b-745c-4101-bcbd-3b13456893db + +done: 10 diff --git a/exercises/practice/food-chain/.meta/food-chain.ys b/exercises/practice/food-chain/.meta/food-chain.ys new file mode 100644 index 0000000..dc7ba46 --- /dev/null +++ b/exercises/practice/food-chain/.meta/food-chain.ys @@ -0,0 +1,40 @@ +!yamlscript/v0 + +barn =:: +- fly: I don't know why she swallowed the fly. Perhaps she'll die. +- spider: It wriggled and jiggled and tickled inside her. +- bird: How absurd to swallow a bird! +- cat: Imagine that, to swallow a cat! +- dog: What a hog, to swallow a dog! +- goat: Just opened her throat and swallowed a goat! +- cow: I don't know how she swallowed a cow! +- horse: She's dead, of course! + +defn recite(start-verse end-verse): + drop-last: + reduce: add-verse [] (start-verse.-- .. end-verse.--) + +defn add-verse(lines verse): + animal =: barn.$verse.first().0 + lines =: conj(lines "I know an old lady who swallowed a $animal.") + lines =: conj(lines barn.$verse.first().1) + lines =: + if 0 < verse < barn.#.--: + conj _ barn.0:first.1: + reduce _ lines (verse .. 0): + fn(lines verse): + lines =: + if verse.?: + then: + animal1 animal2 =: + L(barn.$verse.first().0 barn.nth(verse.--):first.0) + line =: "She swallowed the $animal1 to catch the $animal2." + line =: + if animal2 == 'spider': + replace(line /\./ replace(barn.1:first.1 /It/ ' that')) + line + conj lines: line + else: lines + =>: lines + =>: lines + conj lines: '' diff --git a/exercises/practice/food-chain/.meta/tests.toml b/exercises/practice/food-chain/.meta/tests.toml new file mode 100644 index 0000000..30c5b98 --- /dev/null +++ b/exercises/practice/food-chain/.meta/tests.toml @@ -0,0 +1,40 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[751dce68-9412-496e-b6e8-855998c56166] +description = "fly" + +[6c56f861-0c5e-4907-9a9d-b2efae389379] +description = "spider" + +[3edf5f33-bef1-4e39-ae67-ca5eb79203fa] +description = "bird" + +[e866a758-e1ff-400e-9f35-f27f28cc288f] +description = "cat" + +[3f02c30e-496b-4b2a-8491-bc7e2953cafb] +description = "dog" + +[4b3fd221-01ea-46e0-825b-5734634fbc59] +description = "goat" + +[1b707da9-7001-4fac-941f-22ad9c7a65d4] +description = "cow" + +[3cb10d46-ae4e-4d2c-9296-83c9ffc04cdc] +description = "horse" + +[22b863d5-17e4-4d1e-93e4-617329a5c050] +description = "multiple verses" + +[e626b32b-745c-4101-bcbd-3b13456893db] +description = "full song" diff --git a/exercises/practice/food-chain/.yamlscript/exercise.mk b/exercises/practice/food-chain/.yamlscript/exercise.mk new file mode 100644 index 0000000..2506034 --- /dev/null +++ b/exercises/practice/food-chain/.yamlscript/exercise.mk @@ -0,0 +1 @@ +YS_VERSION := 0.1.75 diff --git a/exercises/practice/food-chain/.yamlscript/exercism-ys-installer b/exercises/practice/food-chain/.yamlscript/exercism-ys-installer new file mode 100644 index 0000000..ae3fa01 --- /dev/null +++ b/exercises/practice/food-chain/.yamlscript/exercism-ys-installer @@ -0,0 +1,127 @@ +#!/env/bin/env bash + +set -euo pipefail + +intro-prompt() ( + cat <<... +-------------------------------------------------------------------------------- + +This YAMLScript Exercism exercise requires the YAMLScript version $version +interpreter command file to be installed here: + + $prefix/bin/ys + +You can install it by pressing Enter now, or by running this command: + + $make install-ys + +This should only take a few seconds and you only need to do this once. +Other exercises will use the same file. + +See https://yamlscript.org/doc/install/ for more YAMLScript installation info. + +-------------------------------------------------------------------------------- + +Would you like to install the 'ys' file now? + +... + + printf "Press Enter to install. Ctl-C to Quit."; read -r +) + +main() { + setup "$@" + + install-from-local + + $auto && intro-prompt + + installed || install-from-release || true + installed || install-from-build || true + installed || + die "Installing '$installed' failed. Giving up." \ + "Consider filing an issue at: $gh_issue_url" + + echo + echo 'Success!' + echo "$installed is now installed." + echo +} + +installed() { + [[ -f $installed ]] +} + +install-from-local() { + local path + path=$(command -v "$ysfq") || true + if [[ -f $path ]]; then + mkdir -p "$bin" + cp "$path" "$bin"/ + ln -fs "$ysfq" "$bin/ys-0" + ln -fs "$ysfq" "$bin/ys" + (installed && $auto) && exit + true + fi +} + +install-from-release() ( + set -x + curl -s https://yamlscript.org/install | + BIN=1 VERSION="$version" PREFIX="$prefix" bash +) + +install-from-build() ( + cat <<... + +The binary release installation failed. +We can attempt to build and install $ysfq now. +This can take from 1 to 5 minutes to complete. + +... + + printf "Press Enter to install. Ctl-C to Quit."; read -r + + [[ -d /tmp && -w /tmp ]] || + die "Can't write to /tmp" \ + 'Giving up.' + + set -x + + rm -fr "$yamlscript_clone" + + git clone --branch="$version" "$yamlscript_repo" "$yamlscript_clone" + + "$make" -C "$yamlscript_clone/ys" install PREFIX="$prefix" +) + +setup() { + version=$1 + prefix=$2 + make=$3 + auto=false + [[ ${4-} ]] && auto=true + + [[ $version =~ ^0\.1\.[0-9]+$ ]] || + die "Invalid YS_VERSION '$version'" + + bin=$prefix/bin + ysfq=ys-$version + installed=$bin/$ysfq + + if installed; then + echo "'$installed' is already installed." + exit + fi + + yamlscript_repo=https://github.com/yaml/yamlscript + yamlscript_clone=/tmp/yamlscript-exercism + gh_issue_url=https://github.com/exercism/yamlscript/issues +} + +die() { + printf '%s\n' "$@" >&2 + exit 1 +} + +main "$@" diff --git a/exercises/practice/food-chain/GNUmakefile b/exercises/practice/food-chain/GNUmakefile new file mode 100644 index 0000000..e8fb5be --- /dev/null +++ b/exercises/practice/food-chain/GNUmakefile @@ -0,0 +1,49 @@ +SHELL := bash + +BASE := $(shell pwd) + +export YS_VERSION := 0.1.79 + +YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION) +ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok)) +YS_LOCAL_PREFIX := $(shell cd .. && pwd -P)/.local/v$(YS_VERSION) +endif + +YS_LOCAL_BIN := $(YS_LOCAL_PREFIX)/bin +YS_BIN := $(YS_LOCAL_BIN)/ys-$(YS_VERSION) + +YS_INSTALLER := .yamlscript/exercism-ys-installer +YS_INSTALLER_CMD := \ + bash $(YS_INSTALLER) $(YS_VERSION) $(YS_LOCAL_PREFIX) $(MAKE) + +TEST_FILE ?= $(wildcard *-test.ys) + +export PATH := $(YS_LOCAL_BIN):$(PATH) +export YSPATH := $(BASE) + + +#------------------------------------------------------------------------------- +default: + @echo " No default make rule. Try 'make test'." + +test: $(YS_BIN) + prove -v $(TEST_FILE) + +install-ys: + @$(YS_INSTALLER_CMD) + +uninstall-ys: + rm -fr $(YS_LOCAL_PREFIX) + + +#------------------------------------------------------------------------------- +ifdef EXERCISM_YAMLSCRIPT_GHA +$(YS_BIN): + +else ifeq (/mnt/,$(dir $(BASE))) +$(YS_BIN): + +else +$(YS_BIN): + @$(YS_INSTALLER_CMD) auto +endif diff --git a/exercises/practice/food-chain/Makefile b/exercises/practice/food-chain/Makefile new file mode 100644 index 0000000..06b6f00 --- /dev/null +++ b/exercises/practice/food-chain/Makefile @@ -0,0 +1,8 @@ +# This Makefile is a decoy to attempt to detect when a non-GNU make is being +# used and alert the user. + +test: + @echo "You appear to be using a non-GNU version of the 'make' program." + @echo "The YAMLScript Exercism track requires you to use GNU make." + @echo "Please try 'make $@' again using GNU make." + @exit 1 diff --git a/exercises/practice/food-chain/food-chain-test.ys b/exercises/practice/food-chain/food-chain-test.ys new file mode 100644 index 0000000..e1435b2 --- /dev/null +++ b/exercises/practice/food-chain/food-chain-test.ys @@ -0,0 +1,163 @@ +#!/usr/bin/env ys-0 + +require ys::taptest: :all + +use: food-chain + +# JSON doesn't allow for multi-line strings, so all verses are presented +# here as arrays of strings. It's up to the test generator to join the +# lines together with line breaks. +# Some languages test for the verse() method, which takes a start verse +# and optional end verse, but other languages have only tested for the full poem. +# For those languages in the latter category, you may wish to only +# implement the full song test and leave the rest alone, ignoring the start +# and end verse fields. + +test:: +- name: Fly + code: recite(1 1) + want: + - I know an old lady who swallowed a fly. + - I don't know why she swallowed the fly. Perhaps she'll die. + +- name: Spider + code: recite(2 2) + want: + - 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. + +- name: Bird + code: recite(3 3) + want: + - 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. + +- name: Cat + code: recite(4 4) + want: + - 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. + +- name: Dog + code: recite(5 5) + want: + - 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. + +- name: Goat + code: recite(6 6) + want: + - 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. + +- name: Cow + code: recite(7 7) + want: + - 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. + +- name: Horse + code: recite(8 8) + want: + - I know an old lady who swallowed a horse. + - She's dead, of course! + +- name: Multiple verses + code: recite(1 3) + want: + - 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. + +- name: Full song + code: recite(1 8) + want: + - 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! + +done: 10 diff --git a/exercises/practice/food-chain/food-chain.ys b/exercises/practice/food-chain/food-chain.ys new file mode 100644 index 0000000..698ad12 --- /dev/null +++ b/exercises/practice/food-chain/food-chain.ys @@ -0,0 +1,4 @@ +!yamlscript/v0 + +defn recite(start-verse end-verse): + # Implement the 'recite' function.