Skip to content

Commit

Permalink
Sync say with problem-specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Nov 14, 2023
1 parent 025710e commit 3480d15
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 105 deletions.
27 changes: 7 additions & 20 deletions exercises/practice/say/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ Given a number from 0 to 999,999,999,999, spell out that number in English.

Handle the basic case of 0 through 99.

If the input to the program is `22`, then the output should be
`'twenty-two'`.
If the input to the program is `22`, then the output should be `'twenty-two'`.

Your program should complain loudly if given a number outside the
blessed range.
Your program should complain loudly if given a number outside the blessed range.

Some good test cases for this program are:

Expand All @@ -23,15 +21,14 @@ Some good test cases for this program are:

### Extension

If you're on a Mac, shell out to Mac OS X's `say` program to talk out
loud. If you're on Linux or Windows, eSpeakNG may be available with the command `espeak`.
If you're on a Mac, shell out to Mac OS X's `say` program to talk out loud.
If you're on Linux or Windows, eSpeakNG may be available with the command `espeak`.

## Step 2

Implement breaking a number up into chunks of thousands.

So `1234567890` should yield a list like 1, 234, 567, and 890, while the
far simpler `1000` should yield just 1 and 0.
So `1234567890` should yield a list like 1, 234, 567, and 890, while the far simpler `1000` should yield just 1 and 0.

The program must also report any values that are out of range.

Expand All @@ -41,8 +38,8 @@ Now handle inserting the appropriate scale word between those chunks.

So `1234567890` should yield `'1 billion 234 million 567 thousand 890'`

The program must also report any values that are out of range. It's
fine to stop at "trillion".
The program must also report any values that are out of range.
It's fine to stop at "trillion".

## Step 4

Expand All @@ -51,13 +48,3 @@ Put it all together to get nothing but plain English.
`12345` should give `twelve thousand three hundred forty-five`.

The program must also report any values that are out of range.

### Extensions

Use _and_ (correctly) when spelling out the number in English:

- 14 becomes "fourteen".
- 100 becomes "one hundred".
- 120 becomes "one hundred and twenty".
- 1002 becomes "one thousand and two".
- 1323 becomes "one thousand three hundred and twenty-three".
20 changes: 20 additions & 0 deletions exercises/practice/say/.meta/additional-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"uuid": "ecafab60-89f2-4680-9286-56b423e8a7b9",
"description": "max i64",
"property": "say",
"input": {
"number": 9223372036854775807
},
"expected": "nine quintillion two hundred twenty-three quadrillion three hundred seventy-two trillion thirty-six billion eight hundred fifty-four million seven hundred seventy-five thousand eight hundred seven"
},
{
"uuid": "88808dac-dffb-46a6-95d4-68d5271a9c38",
"description": "max u64",
"property": "say",
"input": {
"number": 18446744073709551615
},
"expected": "eighteen quintillion four hundred forty-six quadrillion seven hundred forty-four trillion seventy-three billion seven hundred nine million five hundred fifty-one thousand six hundred fifteen"
}
]
4 changes: 2 additions & 2 deletions exercises/practice/say/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
]
},
"blurb": "Given a number from 0 to 999,999,999,999, spell out that number in English.",
"source": "A variation on JavaRanch CattleDrive, exercise 4a",
"source_url": "http://www.javaranch.com/say.jsp"
"source": "A variation on the JavaRanch CattleDrive, Assignment 4",
"source_url": "https://coderanch.com/wiki/718804"
}
12 changes: 12 additions & 0 deletions exercises/practice/say/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% for test in cases %}
#[test]
{% if loop.index != 1 -%}
#[ignore]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
let input = {{ test.input.number | json_encode() }};
let output = {{ crate_name }}::{{ fn_names[0] }}(input);
let expected = {{ test.expected | json_encode() }};
assert_eq!(output, expected);
}
{% endfor -%}
62 changes: 59 additions & 3 deletions exercises/practice/say/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# 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.

[5d22a120-ba0c-428c-bd25-8682235d83e8]
description = "zero"
Expand All @@ -13,3 +20,52 @@ description = "fourteen"

[f541dd8e-f070-4329-92b4-b7ce2fcf06b4]
description = "twenty"

[d78601eb-4a84-4bfa-bf0e-665aeb8abe94]
description = "twenty-two"

[f010d4ca-12c9-44e9-803a-27789841adb1]
description = "thirty"

[738ce12d-ee5c-4dfb-ad26-534753a98327]
description = "ninety-nine"

[e417d452-129e-4056-bd5b-6eb1df334dce]
description = "one hundred"

[d6924f30-80ba-4597-acf6-ea3f16269da8]
description = "one hundred twenty-three"

[2f061132-54bc-4fd4-b5df-0a3b778959b9]
description = "two hundred"

[feed6627-5387-4d38-9692-87c0dbc55c33]
description = "nine hundred ninety-nine"

[3d83da89-a372-46d3-b10d-de0c792432b3]
description = "one thousand"

[865af898-1d5b-495f-8ff0-2f06d3c73709]
description = "one thousand two hundred thirty-four"

[b6a3f442-266e-47a3-835d-7f8a35f6cf7f]
description = "one million"

[2cea9303-e77e-4212-b8ff-c39f1978fc70]
description = "one million two thousand three hundred forty-five"

[3e240eeb-f564-4b80-9421-db123f66a38f]
description = "one billion"

[9a43fed1-c875-4710-8286-5065d73b8a9e]
description = "a big number"

[49a6a17b-084e-423e-994d-a87c0ecc05ef]
description = "numbers below zero are out of range"
include = false
comment = "explanation in .docs/instructions.append.md"

[4d6492eb-5853-4d16-9d34-b0f61b261fd9]
description = "numbers above 999,999,999,999 are out of range"
include = false
comment = "explanation in .docs/instructions.append.md"
Loading

0 comments on commit 3480d15

Please sign in to comment.