Skip to content

Sync problem specs #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions exercises/practice/bob/.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.

[e162fead-606f-437a-a166-d051915cea8e]
description = "stating something"
Expand Down Expand Up @@ -64,6 +71,7 @@ description = "alternate silence"

[66953780-165b-4e7e-8ce3-4bcb80b6385a]
description = "multiple line question"
include = false

[5371ef75-d9ea-4103-bcfa-2da973ddec1b]
description = "starting with whitespace"
Expand All @@ -76,3 +84,7 @@ description = "other whitespace"

[12983553-8601-46a8-92fa-fcaa3bc4a2a0]
description = "non-question ending with whitespace"

[2c7278ac-f955-4eb4-bf8f-e33eb4116a15]
description = "multiple line question"
reimplements = "66953780-165b-4e7e-8ce3-4bcb80b6385a"
12 changes: 7 additions & 5 deletions exercises/practice/bob/bob_test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,22 @@ program bob_test_main

! Test 20: alternate silence
!call assert_equal("Fine. Be that way!", hey(" "), "alternate silence")

! Test 21: multiple line question
call assert_equal("Whatever.", hey(""// &
& "Does this cryogenic chamber make me look fat?"// &
& "No."), "multiple line question")
& "Does this cryogenic chamber make me look fat?"), "multiple line question")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there supposed to be a newline in here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is dropping the No part so it’s a single sentence with a newline at the beginning. So that newline should still be there at the beginning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/exercism/problem-specifications/blob/main/exercises/bob/canonical-data.json#L236C10-L236C70

      "input": {
        "heyBob": "\nDoes this cryogenic chamber make\n me look fat?"
      },

The spec has two newlines.


! Test 22: starting with whitespace
call assert_equal("Whatever.", hey(" hmmmmmmm..."), "starting with whitespace")

! Test 23: ending with whitespace
call assert_equal("Sure.", hey("Okay if like my spacebar quite a bit? "), "ending with whitespace")

! Test 24: other whitespace
!call assert_equal("Fine. Be that way!", hey(""// &
! & "
! "), "other whitespace")
call assert_equal("Fine. Be that way!", hey(""// &
& "
"), "other whitespace")

! Test 25: non-question ending with whitespace
call assert_equal("Whatever.", hey("This is a statement ending with whitespace "), "non-question ending with whitespace")

Expand Down
14 changes: 5 additions & 9 deletions exercises/practice/grains/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Instructions

Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.
Calculate the number of grains of wheat on a chessboard.

There once was a wise servant who saved the life of a prince.
The king promised to pay whatever the servant could dream up.
Knowing that the king loved chess, the servant told the king he would like to have grains of wheat.
One grain on the first square of a chess board, with the number of grains doubling on each successive square.
A chessboard has 64 squares.
Square 1 has one grain, square 2 has two grains, square 3 has four grains, and so on, doubling each time.

There are 64 squares on a chessboard (where square 1 has one grain, square 2 has two grains, and so on).
Write code that calculates:

Write code that shows:

- how many grains were on a given square, and
- the number of grains on a given square
- the total number of grains on the chessboard
6 changes: 6 additions & 0 deletions exercises/practice/grains/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Introduction

There once was a wise servant who saved the life of a prince.
The king promised to pay whatever the servant could dream up.
Knowing that the king loved chess, the servant told the king he would like to have grains of wheat.
One grain on the first square of a chessboard, with the number of grains doubling on each successive square.
45 changes: 25 additions & 20 deletions exercises/practice/luhn/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instructions

Determine whether a credit card number is valid according to the [Luhn formula][luhn].
Determine whether a number is valid according to the [Luhn formula][luhn].

The number will be provided as a string.

Expand All @@ -10,54 +10,59 @@ Strings of length 1 or less are not valid.
Spaces are allowed in the input, but they should be stripped before checking.
All other non-digit characters are disallowed.

### Example 1: valid credit card number
## Examples

```text
4539 3195 0343 6467
```
### Valid credit card number

The first step of the Luhn algorithm is to double every second digit, starting from the right.
We will be doubling
The number to be checked is `4539 3195 0343 6467`.

The first step of the Luhn algorithm is to start at the end of the number and double every second digit, beginning with the second digit from the right and moving left.

```text
4539 3195 0343 6467
↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ (double these)
```

If doubling the number results in a number greater than 9 then subtract 9 from the product.
The results of our doubling:
If the result of doubling a digit is greater than 9, we subtract 9 from that result.
We end up with:

```text
8569 6195 0383 3437
```

Then sum all of the digits:
Finally, we sum all digits.
If the sum is evenly divisible by 10, the original number is valid.

```text
8+5+6+9+6+1+9+5+0+3+8+3+3+4+3+7 = 80
8 + 5 + 6 + 9 + 6 + 1 + 9 + 5 + 0 + 3 + 8 + 3 + 3 + 4 + 3 + 7 = 80
```

If the sum is evenly divisible by 10, then the number is valid.
This number is valid!
80 is evenly divisible by 10, so number `4539 3195 0343 6467` is valid!

### Invalid Canadian SIN

The number to be checked is `066 123 468`.

### Example 2: invalid credit card number
We start at the end of the number and double every second digit, beginning with the second digit from the right and moving left.

```text
8273 1232 7352 0569
066 123 478
↑ ↑ ↑ ↑ (double these)
```

Double the second digits, starting from the right
If the result of doubling a digit is greater than 9, we subtract 9 from that result.
We end up with:

```text
7253 2262 5312 0539
036 226 458
```

Sum the digits
We sum the digits:

```text
7+2+5+3+2+2+6+2+5+3+1+2+0+5+3+9 = 57
0 + 3 + 6 + 2 + 2 + 6 + 4 + 5 + 8 = 36
```

57 is not evenly divisible by 10, so this number is not valid.
36 is not evenly divisible by 10, so number `066 123 478` is not valid!

[luhn]: https://en.wikipedia.org/wiki/Luhn_algorithm
4 changes: 2 additions & 2 deletions exercises/practice/luhn/.docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

At the Global Verification Authority, you've just been entrusted with a critical assignment.
Across the city, from online purchases to secure logins, countless operations rely on the accuracy of numerical identifiers like credit card numbers, bank account numbers, transaction codes, and tracking IDs.
The Luhn algorithm is a simple checksum formula used to ensure these numbers are valid and error-free.
The Luhn algorithm is a simple checksum formula used to help identify mistyped numbers.

A batch of identifiers has just arrived on your desk.
All of them must pass the Luhn test to ensure they're legitimate.
If any fail, they'll be flagged as invalid, preventing errors or fraud, such as incorrect transactions or unauthorized access.
If any fail, they'll be flagged as invalid, preventing mistakes such as incorrect transactions or failed account verifications.

Can you ensure this is done right? The integrity of many services depends on you.
11 changes: 6 additions & 5 deletions exercises/practice/saddle-points/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ Or it might have one, or even several.
Here is a grid that has exactly one candidate tree.

```text
1 2 3 4
|-----------
1 | 9 8 7 8
2 | 5 3 2 4 <--- potential tree house at row 2, column 1, for tree with height 5
3 | 6 6 7 1
1 2 3 4
|-----------
1 | 9 8 7 8
→ 2 |[5] 3 2 4
3 | 6 6 7 1
```

- Row 2 has values 5, 3, 2, and 4. The largest value is 5.
Expand Down
75 changes: 67 additions & 8 deletions exercises/practice/sieve/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,96 @@ A prime number is a number larger than 1 that is only divisible by 1 and itself.
For example, 2, 3, 5, 7, 11, and 13 are prime numbers.
By contrast, 6 is _not_ a prime number as it not only divisible by 1 and itself, but also by 2 and 3.

To use the Sieve of Eratosthenes, you first create a list of all the numbers between 2 and your given number.
Then you repeat the following steps:
To use the Sieve of Eratosthenes, first, write out all the numbers from 2 up to and including your given number.
Then, follow these steps:

1. Find the next unmarked number in your list (skipping over marked numbers).
1. Find the next unmarked number (skipping over marked numbers).
This is a prime number.
2. Mark all the multiples of that prime number as **not** prime.

You keep repeating these steps until you've gone through every number in your list.
Repeat the steps until you've gone through every number.
At the end, all the unmarked numbers are prime.

~~~~exercism/note
The tests don't check that you've implemented the algorithm, only that you've come up with the correct list of primes.
To check you are implementing the Sieve correctly, a good first test is to check that you do not use division or remainder operations.
The Sieve of Eratosthenes marks off multiples of each prime using addition (repeatedly adding the prime) or multiplication (directly computing its multiples), rather than checking each number for divisibility.

The tests don't check that you've implemented the algorithm, only that you've come up with the correct primes.
~~~~

## Example

Let's say you're finding the primes less than or equal to 10.

- List out 2, 3, 4, 5, 6, 7, 8, 9, 10, leaving them all unmarked.
- Write out 2, 3, 4, 5, 6, 7, 8, 9, 10, leaving them all unmarked.

```text
2 3 4 5 6 7 8 9 10
```

- 2 is unmarked and is therefore a prime.
Mark 4, 6, 8 and 10 as "not prime".

```text
2 3 [4] 5 [6] 7 [8] 9 [10]
```

- 3 is unmarked and is therefore a prime.
Mark 6 and 9 as not prime _(marking 6 is optional - as it's already been marked)_.

```text
2 3 [4] 5 [6] 7 [8] [9] [10]
```

- 4 is marked as "not prime", so we skip over it.

```text
2 3 [4] 5 [6] 7 [8] [9] [10]
```

- 5 is unmarked and is therefore a prime.
Mark 10 as not prime _(optional - as it's already been marked)_.

```text
2 3 [4] 5 [6] 7 [8] [9] [10]
```

- 6 is marked as "not prime", so we skip over it.

```text
2 3 [4] 5 [6] 7 [8] [9] [10]
```

- 7 is unmarked and is therefore a prime.

```text
2 3 [4] 5 [6] 7 [8] [9] [10]
```

- 8 is marked as "not prime", so we skip over it.

```text
2 3 [4] 5 [6] 7 [8] [9] [10]
```

- 9 is marked as "not prime", so we skip over it.

```text
2 3 [4] 5 [6] 7 [8] [9] [10]
```

- 10 is marked as "not prime", so we stop as there are no more numbers to check.

You've examined all numbers and found 2, 3, 5, and 7 are still unmarked, which means they're the primes less than or equal to 10.
```text
2 3 [4] 5 [6] 7 [8] [9] [10]
```

You've examined all the numbers and found that 2, 3, 5, and 7 are still unmarked, meaning they're the primes less than or equal to 10.
Loading