-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d2c26c
commit 85132a3
Showing
7 changed files
with
347 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Description | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
@echo off | ||
setlocal enabledelayedexpansion | ||
|
||
set startVerse=%~1 | ||
set endVerse=%~2 | ||
|
||
goto :main | ||
|
||
:verse1 | ||
echo I know an old lady who swallowed a fly. | ||
echo I don't know why she swallowed the fly. Perhaps she'll die. | ||
goto :eof | ||
|
||
:verse2 | ||
echo I know an old lady who swallowed a spider. | ||
echo It wriggled and jiggled and tickled inside her. | ||
echo She swallowed the spider to catch the fly. | ||
echo I don't know why she swallowed the fly. Perhaps she'll die. | ||
goto :eof | ||
|
||
:verse3 | ||
echo I know an old lady who swallowed a bird. | ||
echo How absurd to swallow a bird! | ||
echo She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. | ||
echo She swallowed the spider to catch the fly. | ||
echo I don't know why she swallowed the fly. Perhaps she'll die. | ||
goto :eof | ||
|
||
:verse4 | ||
echo I know an old lady who swallowed a cat. | ||
echo Imagine that, to swallow a cat! | ||
echo She swallowed the cat to catch the bird. | ||
echo She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. | ||
echo She swallowed the spider to catch the fly. | ||
echo I don't know why she swallowed the fly. Perhaps she'll die. | ||
goto :eof | ||
|
||
:verse5 | ||
echo I know an old lady who swallowed a dog. | ||
echo What a hog, to swallow a dog! | ||
echo She swallowed the dog to catch the cat. | ||
echo She swallowed the cat to catch the bird. | ||
echo She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. | ||
echo She swallowed the spider to catch the fly. | ||
echo I don't know why she swallowed the fly. Perhaps she'll die. | ||
goto :eof | ||
|
||
:verse6 | ||
echo I know an old lady who swallowed a goat. | ||
echo Just opened her throat and swallowed a goat! | ||
echo She swallowed the goat to catch the dog. | ||
echo She swallowed the dog to catch the cat. | ||
echo She swallowed the cat to catch the bird. | ||
echo She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. | ||
echo She swallowed the spider to catch the fly. | ||
echo I don't know why she swallowed the fly. Perhaps she'll die. | ||
goto :eof | ||
|
||
:verse7 | ||
echo I know an old lady who swallowed a cow. | ||
echo I don't know how she swallowed a cow! | ||
echo She swallowed the cow to catch the goat. | ||
echo She swallowed the goat to catch the dog. | ||
echo She swallowed the dog to catch the cat. | ||
echo She swallowed the cat to catch the bird. | ||
echo She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. | ||
echo She swallowed the spider to catch the fly. | ||
echo I don't know why she swallowed the fly. Perhaps she'll die. | ||
goto :eof | ||
|
||
:verse8 | ||
echo I know an old lady who swallowed a horse. | ||
echo She's dead, of course! | ||
goto :eof | ||
|
||
:main | ||
for /l %%i in (%startVerse%,1,%endVerse%) do ( | ||
call :verse%%i | ||
echo. | ||
) | ||
|
||
exit /b 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"authors": ["GroophyLifefor"], | ||
"files": { | ||
"solution": [ | ||
"FoodChain.bat" | ||
], | ||
"test": [ | ||
"FoodChainTest.bat" | ||
], | ||
"example": [ | ||
".meta/Example.bat" | ||
] | ||
}, | ||
"blurb": "Generate the lyrics of the song 'I Know an Old Lady Who Swallowed a Fly'.", | ||
"source": "Wikipedia" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 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. | ||
|
||
[af9ffe10-dc13-42d8-a742-e7bdafac449d] | ||
description = "Say Hi!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@echo off | ||
setlocal enabledelayedexpansion | ||
|
||
set startVerse=%~1 | ||
set endVerse=%~2 | ||
set "result=" | ||
|
||
REM Your code goes here | ||
|
||
|
||
echo %result% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
@echo off | ||
setlocal enabledelayedexpansion | ||
REM --------------------------------------------------- | ||
REM FoodChain Unit Testing | ||
REM | ||
REM sUnit Testing Framework version: 0.3 | ||
REM --------------------------------------------------- | ||
|
||
set "successCount=0" | ||
set "failCount=0" | ||
|
||
:Main | ||
REM Initalize result variable | ||
set "slug=FoodChain" | ||
|
||
REM -------------------- | ||
REM Test Case Start \/\/ | ||
REM Resource: https://github.com/exercism/problem-specifications/blob/main/exercises/food-chain/canonical-data.json | ||
REM -------------------- | ||
set "expected=I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: fly" | ||
CALL :Assert "1" "1" | ||
|
||
set "expected=I know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: spider" | ||
CALL :Assert "2" "2" | ||
|
||
set "expected=I know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: bird" | ||
CALL :Assert "3" "3" | ||
|
||
set "expected=I know an old lady who swallowed a cat.\nImagine that, to swallow a cat!\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: cat" | ||
CALL :Assert "4" "4" | ||
|
||
set "expected=I know an old lady who swallowed a dog.\nWhat a hog, to swallow a dog!\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: dog" | ||
CALL :Assert "5" "5" | ||
|
||
set "expected=I know an old lady who swallowed a goat.\nJust opened her throat and swallowed a goat!\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: goat" | ||
CALL :Assert "6" "6" | ||
|
||
set "expected=I know an old lady who swallowed a cow.\nI don't know how she swallowed a cow!\nShe swallowed the cow to catch the goat.\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: cow" | ||
CALL :Assert "7" "7" | ||
|
||
set "expected=I know an old lady who swallowed a horse.\nShe's dead, of course!" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: horse" | ||
CALL :Assert "8" "8" | ||
|
||
set "expected=I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\nI know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die.\nI know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: multiple verses" | ||
CALL :Assert "1" "3" | ||
|
||
REM The reason for splitting into parts is that the batch language has a line limit | ||
set "expected=I know an old lady who swallowed a fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "expected=%expected%\nI know an old lady who swallowed a spider.\nIt wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "expected=%expected%\nI know an old lady who swallowed a bird.\nHow absurd to swallow a bird!\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "expected=%expected%\nI know an old lady who swallowed a cat.\nImagine that, to swallow a cat!\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "expected=%expected%\nI know an old lady who swallowed a dog.\nWhat a hog, to swallow a dog!\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "expected=%expected%\nI know an old lady who swallowed a goat.\nJust opened her throat and swallowed a goat!\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "expected=%expected%\nI know an old lady who swallowed a cow.\nI don't know how she swallowed a cow!\nShe swallowed the cow to catch the goat.\nShe swallowed the goat to catch the dog.\nShe swallowed the dog to catch the cat.\nShe swallowed the cat to catch the bird.\nShe swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\nShe swallowed the spider to catch the fly.\nI don't know why she swallowed the fly. Perhaps she'll die." | ||
set "expected=%expected%\nI know an old lady who swallowed a horse.\nShe's dead, of course!" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: full song" | ||
CALL :Assert "1" "8" | ||
|
||
REM -------------------- | ||
REM Test Case End /\/\/\ | ||
REM -------------------- | ||
|
||
CALL :ResolveStatus | ||
exit /b %errorlevel% | ||
REM End of Main | ||
|
||
REM --------------------------------------------------- | ||
REM Assert [..Parameters(up to 9)] | ||
REM --------------------------------------------------- | ||
GOTO :End REM Prevents the code below from being executed | ||
:Assert | ||
set "stdout=" | ||
|
||
REM Run the program and capture the output then delete the file | ||
CALL %slug%.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 > stdout.bin 2>&1 | ||
for /f "delims=" %%A in (stdout.bin) do ( | ||
set "line=%%A" | ||
if defined stdout ( | ||
set "stdout=!stdout!\n!line!" | ||
) else ( | ||
set "stdout=!line!" | ||
) | ||
) | ||
del stdout.bin | ||
|
||
REM Check if the result is correct | ||
if "%stdout%" == "%expected%" ( | ||
if defined if_success ( | ||
echo %if_success% | ||
|
||
REM Reset the variable to avoid duplicating the message. | ||
set "if_success=" | ||
set "if_failed=" | ||
) | ||
|
||
REM If the result is correct, exit with code 0 | ||
set /a successCount+=1 | ||
exit /b 0 | ||
) else ( | ||
if defined if_failed ( | ||
echo %if_failed% | ||
|
||
REM Reset the variable to avoid duplicating the message. | ||
set "if_success=" | ||
set "if_failed=" | ||
) | ||
|
||
REM If the result is incorrect, exit with code 1 | ||
set /a failCount+=1 | ||
exit /b 1 | ||
) | ||
GOTO :EOF REM Go back to the line after the call to :Assert | ||
|
||
:ResolveStatus | ||
set "status=" | ||
if %failCount% gtr 0 ( | ||
REM status: Fail | ||
REM message: The test failed. | ||
exit /b 1 | ||
|
||
) else ( | ||
REM status: Pass | ||
exit /b 0 | ||
|
||
) | ||
GOTO :EOF REM Go back to the line after the call to :ExportResultAsJson | ||
|
||
:End |