Skip to content
Merged
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
8 changes: 5 additions & 3 deletions exercises/practice/armstrong-numbers/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Instructions

An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits.
An [Armstrong number][armstrong-number] is a number that is the sum of its own digits each raised to the power of the number of digits.

For example:

- 9 is an Armstrong number, because `9 = 9^1 = 9`
- 10 is *not* an Armstrong number, because `10 != 1^2 + 0^2 = 1`
- 10 is _not_ an Armstrong number, because `10 != 1^2 + 0^2 = 1`
- 153 is an Armstrong number, because: `153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153`
- 154 is *not* an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190`
- 154 is _not_ an Armstrong number, because: `154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190`

Write some code to determine whether a number is an Armstrong number.

[armstrong-number]: https://en.wikipedia.org/wiki/Narcissistic_number
8 changes: 8 additions & 0 deletions exercises/practice/armstrong-numbers/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ description = "Seven-digit number that is an Armstrong number"

[7ee45d52-5d35-4fbd-b6f1-5c8cd8a67f18]
description = "Seven-digit number that is not an Armstrong number"

[5ee2fdf8-334e-4a46-bb8d-e5c19c02c148]
description = "Armstrong number containing seven zeroes"
comment = "Upper bound of Nat type is 18446744073709551615"

[12ffbf10-307a-434e-b4ad-c925680e1dd4]
description = "The largest and last Armstrong number"
comment = "Upper bound of Nat type is 18446744073709551615"
2 changes: 1 addition & 1 deletion exercises/practice/bob/.meta/testAnnotation.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
},
{
"name": "Multiple line question",
"test_code": "verify do\n labeled \"Multiple line question\" do\n expected = \"Whatever.\"\n actual = response \"\\nDoes this cryogenic chamber make me look fat?\\nNo.\"\n label \"expected\" expected\n label \"actual\" actual\n ensureEqual expected actual"
"test_code": "verify do\n labeled \"Multiple line question\" do\n expected = \"Sure.\"\n actual = response \"\\nDoes this cryogenic chamber make\\n me look fat?\"\n label \"expected\" expected\n label \"actual\" actual\n ensureEqual expected actual"
},
{
"name": "Starting with whitespace",
Expand Down
5 changes: 5 additions & 0 deletions exercises/practice/bob/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,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 @@ -83,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"
4 changes: 2 additions & 2 deletions exercises/practice/bob/bob.test.u
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ bob.test.ex20 = verify do

bob.test.ex21 = verify do
labeled "Multiple line question" do
expected = "Whatever."
actual = response "\nDoes this cryogenic chamber make me look fat?\nNo."
expected = "Sure."
actual = response "\nDoes this cryogenic chamber make\n me look fat?"
label "expected" expected
label "actual" actual
ensureEqual expected actual
Expand Down
16 changes: 4 additions & 12 deletions exercises/practice/change/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# Instructions

Correctly determine the fewest number of coins to be given to a customer such
that the sum of the coins' value would equal the correct amount of change.
Determine the fewest number of coins to give a customer so that the sum of their values equals the correct amount of change.

## For example
## Examples

- An input of 15 with [1, 5, 10, 25, 100] should return one nickel (5)
and one dime (10) or [5, 10]
- An input of 40 with [1, 5, 10, 25, 100] should return one nickel (5)
and one dime (10) and one quarter (25) or [5, 10, 25]

## Edge cases

- Does your algorithm work for any given set of coins?
- Can you ask for a change value smaller than the smallest coin value?
- An amount of 15 with available coin values [1, 5, 10, 25, 100] should return one coin of value 5 and one coin of value 10, or [5, 10].
- An amount of 40 with available coin values [1, 5, 10, 25, 100] should return one coin of value 5, one coin of value 10, and one coin of value 25, or [5, 10, 25].
26 changes: 26 additions & 0 deletions exercises/practice/change/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Introduction

In the mystical village of Coinholt, you stand behind the counter of your bakery, arranging a fresh batch of pastries.
The door creaks open, and in walks Denara, a skilled merchant with a keen eye for quality goods.
After a quick meal, she slides a shimmering coin across the counter, representing a value of 100 units.

You smile, taking the coin, and glance at the total cost of the meal: 88 units.
That means you need to return 12 units in change.

Denara holds out her hand expectantly.
"Just give me the fewest coins," she says with a smile.
"My pouch is already full, and I don't want to risk losing them on the road."

You know you have a few options.
"We have Lumis (worth 10 units), Viras (worth 5 units), and Zenth (worth 2 units) available for change."

You quickly calculate the possibilities in your head:

- one Lumis (1 × 10 units) + one Zenth (1 × 2 units) = 2 coins total
- two Viras (2 × 5 units) + one Zenth (1 × 2 units) = 3 coins total
- six Zenth (6 × 2 units) = 6 coins total

"The best choice is two coins: one Lumis and one Zenth," you say, handing her the change.

Denara smiles, clearly impressed.
"As always, you've got it right."
4 changes: 4 additions & 0 deletions exercises/practice/change/.meta/testAnnotation.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@
{
"name": "error if no combination can add up to target",
"test_code": "verify do\n labeled \"error if no combination can add up to target\" do\n expected = None\n actual = findFewestCoins [5,10] 94\n label \"expected\" expected\n label \"actual\" actual\n ensureEqual expected actual"
},
{
"name": "a greedy approach is not optimal",
"test_code": "verify do\n labeled \"a greedy approach is not optimal\" do\n expected = Some [10, 10]\n actual = findFewestCoins [1, 10, 11] 20\n label \"expected\" expected\n label \"actual\" actual\n ensureEqual expected actual"
}
]
3 changes: 3 additions & 0 deletions exercises/practice/change/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ description = "possible change without unit coins available"
[9a166411-d35d-4f7f-a007-6724ac266178]
description = "another possible change without unit coins available"

[ce0f80d5-51c3-469d-818c-3e69dbd25f75]
description = "a greedy approach is not optimal"

[bbbcc154-e9e9-4209-a4db-dd6d81ec26bb]
description = "no coins make 0 change"

Expand Down
11 changes: 10 additions & 1 deletion exercises/practice/change/change.test.u
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ change.test.ex11 = verify do
label "actual" actual
ensureEqual expected actual

change.test.ex12 = verify do
labeled "a greedy approach is not optimal" do
expected = Some [10, 10]
actual = findFewestCoins [1, 10, 11] 20
label "expected" expected
label "actual" actual
ensureEqual expected actual

test> change.tests = join [
change.test.ex1,
change.test.ex2,
Expand All @@ -97,5 +105,6 @@ test> change.tests = join [
change.test.ex8,
change.test.ex9,
change.test.ex10,
change.test.ex11
change.test.ex11,
change.test.ex12
]
31 changes: 12 additions & 19 deletions exercises/practice/crypto-square/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ Implement the classic method for composing secret messages called a square code.

Given an English text, output the encoded version of that text.

First, the input is normalized: the spaces and punctuation are removed
from the English text and the message is down-cased.
First, the input is normalized: the spaces and punctuation are removed from the English text and the message is down-cased.

Then, the normalized characters are broken into rows. These rows can be
regarded as forming a rectangle when printed with intervening newlines.
Then, the normalized characters are broken into rows.
These rows can be regarded as forming a rectangle when printed with intervening newlines.

For example, the sentence

Expand All @@ -22,18 +21,16 @@ is normalized to:
"ifmanwasmeanttostayonthegroundgodwouldhavegivenusroots"
```

The plaintext should be organized in to a rectangle. The size of the
rectangle should be decided by the length of the message.
The plaintext should be organized into a rectangle as square as possible.
The size of the rectangle should be decided by the length of the message.

If `c` is the number of columns and `r` is the number of rows, then for
the rectangle `r` x `c` find the smallest possible integer `c` such that:
If `c` is the number of columns and `r` is the number of rows, then for the rectangle `r` x `c` find the smallest possible integer `c` such that:

- `r * c >= length(message)`,
- `r * c >= length of message`,
- and `c >= r`,
- and `c - r <= 1`.

Our normalized text is 54 characters long, dictating a rectangle with
`c = 8` and `r = 7`:
Our normalized text is 54 characters long, dictating a rectangle with `c = 8` and `r = 7`:

```text
"ifmanwas"
Expand All @@ -45,26 +42,22 @@ Our normalized text is 54 characters long, dictating a rectangle with
"sroots "
```

The coded message is obtained by reading down the columns going left to
right.
The coded message is obtained by reading down the columns going left to right.

The message above is coded as:

```text
"imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau"
```

Output the encoded text in chunks that fill perfect rectangles `(r X c)`,
with `c` chunks of `r` length, separated by spaces. For phrases that are
`n` characters short of the perfect rectangle, pad each of the last `n`
chunks with a single trailing space.
Output the encoded text in chunks that fill perfect rectangles `(r X c)`, with `c` chunks of `r` length, separated by spaces.
For phrases that are `n` characters short of the perfect rectangle, pad each of the last `n` chunks with a single trailing space.

```text
"imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau "
```

Notice that were we to stack these, we could visually decode the
ciphertext back in to the original message:
Notice that were we to stack these, we could visually decode the ciphertext back in to the original message:

```text
"imtgdvs"
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/crypto-square/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
},
"blurb": "Implement the classic method for composing secret messages called a square code.",
"source": "J Dalbey's Programming Practice problems",
"source_url": "http://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html"
"source_url": "https://users.csc.calpoly.edu/~jdalbey/103/Projects/ProgrammingPractice.html"
}
8 changes: 6 additions & 2 deletions exercises/practice/crypto-square/.meta/testAnnotation.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
"test_code": "verify do\n labeled \"8 character plaintext results in 3 chunks, the last one with a trailing space\" do\n expected = \"clu hlt io \"\n actual = ciphertext \"Chill out.\"\n label \"expected\" expected\n label \"actual\" actual\n ensureEqual expected actual"
},
{
"name": "54 character plaintext results in 7 chunks, the last two with trailing spaces",
"test_code": "verify do\n labeled \"54 character plaintext results in 7 chunks, the last two with trailing spaces\" do\n expected = \"imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau \"\n actual = ciphertext \"If man was meant to stay on the ground, god would have given us roots.\"\n label \"expected\" expected\n label \"actual\" actual\n ensureEqual expected actual"
"name": "54 character plaintext results in 8 chunks, the last two with trailing spaces",
"test_code": "verify do\n labeled \"54 character plaintext results in 8 chunks, the last two with trailing spaces\" do\n expected = \"imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau \"\n actual = ciphertext \"If man was meant to stay on the ground, god would have given us roots.\"\n label \"expected\" expected\n label \"actual\" actual\n ensureEqual expected actual"
},
{
"name": "normalization results in empty plaintext",
"test_code": "verify do\n labeled \"normalization results in empty plaintext\" do\n expected = \"\"\n actual = ciphertext \"... --- ...\"\n label \"expected\" expected\n label \"actual\" actual\n ensureEqual expected actual"
}
]
8 changes: 8 additions & 0 deletions exercises/practice/crypto-square/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
[407c3837-9aa7-4111-ab63-ec54b58e8e9f]
description = "empty plaintext results in an empty ciphertext"

[aad04a25-b8bb-4304-888b-581bea8e0040]
description = "normalization results in empty plaintext"

[64131d65-6fd9-4f58-bdd8-4a2370fb481d]
description = "Lowercase"

Expand All @@ -29,3 +32,8 @@ description = "8 character plaintext results in 3 chunks, the last one with a tr

[fbcb0c6d-4c39-4a31-83f6-c473baa6af80]
description = "54 character plaintext results in 7 chunks, the last two with trailing spaces"
include = false

[33fd914e-fa44-445b-8f38-ff8fbc9fe6e6]
description = "54 character plaintext results in 8 chunks, the last two with trailing spaces"
reimplements = "fbcb0c6d-4c39-4a31-83f6-c473baa6af80"
13 changes: 11 additions & 2 deletions exercises/practice/crypto-square/crypto.test.u
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,28 @@ cryptoSquare.test.ex6 = verify do
ensureEqual expected actual

cryptoSquare.test.ex7 = verify do
labeled "54 character plaintext results in 7 chunks, the last two with trailing spaces" do
labeled "54 character plaintext results in 8 chunks, the last two with trailing spaces" do
expected = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau "
actual = ciphertext "If man was meant to stay on the ground, god would have given us roots."
label "expected" expected
label "actual" actual
ensureEqual expected actual

cryptoSquare.test.ex8 = verify do
labeled "normalization results in empty plaintext" do
expected = ""
actual = ciphertext "... --- ..."
label "expected" expected
label "actual" actual
ensureEqual expected actual

test> cryptoSquare.tests = join [
cryptoSquare.test.ex1,
cryptoSquare.test.ex2,
cryptoSquare.test.ex3,
cryptoSquare.test.ex4,
cryptoSquare.test.ex5,
cryptoSquare.test.ex6,
cryptoSquare.test.ex7
cryptoSquare.test.ex7,
cryptoSquare.test.ex8
]
13 changes: 7 additions & 6 deletions exercises/practice/hello-world/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Instructions

The classical introductory exercise. Just say "Hello, World!".
The classical introductory exercise.
Just say "Hello, World!".

["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
the traditional first program for beginning programming in a new language
or environment.
["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment.

The objectives are simple:

- Write a function that returns the string "Hello, World!".
- Modify the provided code so that it produces the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.

If everything goes well, you will be ready to fetch your first real exercise.
If everything goes well, you will be ready to fetch your first real exercise.

[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program
4 changes: 2 additions & 2 deletions exercises/practice/hello-world/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
".meta/examples/hello.example.u"
]
},
"blurb": "The classical introductory exercise. Just say \"Hello, World!\"",
"blurb": "Exercism's classic introductory exercise. Just say \"Hello, World!\".",
"source": "This is an exercise to introduce users to using Exercism",
"source_url": "http://en.wikipedia.org/wiki/%22Hello,_world!%22_program"
"source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program"
}
13 changes: 13 additions & 0 deletions exercises/practice/hello-world/.meta/tests.toml
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!"
8 changes: 4 additions & 4 deletions exercises/practice/knapsack/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Instructions

Your task is to determine which items to take so that the total value of his selection is maximized, taking into account the knapsack's carrying capacity.
Your task is to determine which items to take so that the total value of her selection is maximized, taking into account the knapsack's carrying capacity.

Items will be represented as a list of items.
Each item will have a weight and value.
All values given will be strictly positive.
Bob can take only one of each item.
Lhakpa can take only one of each item.

For example:

Expand All @@ -21,5 +21,5 @@ Knapsack Maximum Weight: 10
```

For the above, the first item has weight 5 and value 10, the second item has weight 4 and value 40, and so on.
In this example, Bob should take the second and fourth item to maximize his value, which, in this case, is 90.
He cannot get more than 90 as his knapsack has a weight limit of 10.
In this example, Lhakpa should take the second and fourth item to maximize her value, which, in this case, is 90.
She cannot get more than 90 as her knapsack has a weight limit of 10.
12 changes: 7 additions & 5 deletions exercises/practice/knapsack/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Introduction

Bob is a thief.
After months of careful planning, he finally manages to crack the security systems of a fancy store.
Lhakpa is a [Sherpa][sherpa] mountain guide and porter.
After months of careful planning, the expedition Lhakpa works for is about to leave.
She will be paid the value she carried to the base camp.

In front of him are many items, each with a value and weight.
Bob would gladly take all of the items, but his knapsack can only hold so much weight.
Bob has to carefully consider which items to take so that the total value of his selection is maximized.
In front of her are many items, each with a value and weight.
Lhakpa would gladly take all of the items, but her knapsack can only hold so much weight.

[sherpa]: https://en.wikipedia.org/wiki/Sherpa_people#Mountaineering
5 changes: 5 additions & 0 deletions exercises/practice/knapsack/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

[a4d7d2f0-ad8a-460c-86f3-88ba709d41a7]
description = "no items"
include = false

[3993a824-c20e-493d-b3c9-ee8a7753ee59]
description = "no items"
reimplements = "a4d7d2f0-ad8a-460c-86f3-88ba709d41a7"

[1d39e98c-6249-4a8b-912f-87cb12e506b0]
description = "one item, too heavy"
Expand Down
Loading