Skip to content

Commit

Permalink
Sync recent prob-spec changes
Browse files Browse the repository at this point in the history
  • Loading branch information
glennj committed Apr 10, 2024
1 parent 31ea47a commit 922cab8
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 44 deletions.
21 changes: 8 additions & 13 deletions exercises/practice/all-your-base/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
# Instructions

Convert a number, represented as a sequence of digits in one base, to any other base.
Convert a sequence of digits in one base, representing a number, into a sequence of digits in another base, representing the same number.

Implement general base conversion.
Given a number in base **a**, represented as a sequence of digits, convert it to base **b**.

## Note

- Try to implement the conversion yourself.
Do not use something else to perform the conversion for you.
~~~~exercism/note
Try to implement the conversion yourself.
Do not use something else to perform the conversion for you.
~~~~

## About [Positional Notation][positional-notation]

In positional notation, a number in base **b** can be understood as a linear combination of powers of **b**.

The number 42, _in base 10_, means:

`(4 * 10^1) + (2 * 10^0)`
`(4 × 10¹) + (2 × 10)`

The number 101010, _in base 2_, means:

`(1 * 2^5) + (0 * 2^4) + (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (0 * 2^0)`
`(1 × 2⁵) + (0 × 2⁴) + (1 × 2³) + (0 × 2²) + (1 × 2¹) + (0 × 2⁰)`

The number 1120, _in base 3_, means:

`(1 * 3^3) + (1 * 3^2) + (2 * 3^1) + (0 * 3^0)`

I think you got the idea!
`(1 × 3³) + (1 × 3²) + (2 × 3¹) + (0 × 3⁰)`

_Yes. Those three numbers above are exactly the same. Congratulations!_

Expand Down
8 changes: 8 additions & 0 deletions exercises/practice/all-your-base/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Introduction

You've just been hired as professor of mathematics.
Your first week went well, but something is off in your second week.
The problem is that every answer given by your students is wrong!
Luckily, your math skills have allowed you to identify the problem: the student answers _are_ correct, but they're all in base 2 (binary)!
Amazingly, it turns out that each week, the students use a different base.
To help you quickly verify the student answers, you'll be building a tool to translate between bases.
3 changes: 3 additions & 0 deletions exercises/practice/raindrops/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Introduction

Raindrops is a slightly more complex version of the FizzBuzz challenge, a classic interview question.
5 changes: 5 additions & 0 deletions exercises/practice/reverse-string/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Introduction

Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming.

For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance.
59 changes: 59 additions & 0 deletions exercises/practice/roman-numerals/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Description

Today, most people in the world use Arabic numerals (0–9).
But if you travelled back two thousand years, you'd find that most Europeans were using Roman numerals instead.

To write a Roman numeral we use the following Latin letters, each of which has a value:

| M | D | C | L | X | V | I |
| ---- | --- | --- | --- | --- | --- | --- |
| 1000 | 500 | 100 | 50 | 10 | 5 | 1 |

A Roman numeral is a sequence of these letters, and its value is the sum of the letters' values.
For example, `XVIII` has the value 18 (`10 + 5 + 1 + 1 + 1 = 18`).

There's one rule that makes things trickier though, and that's that **the same letter cannot be used more than three times in succession**.
That means that we can't express numbers such as 4 with the seemingly natural `IIII`.
Instead, for those numbers, we use a subtraction method between two letters.
So we think of `4` not as `1 + 1 + 1 + 1` but instead as `5 - 1`.
And slightly confusingly to our modern thinking, we write the smaller number first.
This applies only in the following cases: 4 (`IV`), 9 (`IX`), 40 (`XL`), 90 (`XC`), 400 (`CD`) and 900 (`CM`).

Order matters in Roman numerals!
Letters (and the special compounds above) must be ordered by decreasing value from left to right.

Here are some examples:

```text
105 => CV
---- => --
100 => C
+ 5 => V
```

```text
106 => CVI
---- => --
100 => C
+ 5 => V
+ 1 => I
```

```text
104 => CIV
---- => ---
100 => C
+ 4 => IV
```

And a final more complex example:

```text
1996 => MCMXCVI
----- => -------
1000 => M
+ 900 => CM
+ 90 => XC
+ 5 => V
+ 1 => I
```
3 changes: 3 additions & 0 deletions exercises/practice/roman-numerals/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,8 @@ description = "3000 is MMM"
[3bc4b41c-c2e6-49d9-9142-420691504336]
description = "3001 is MMMI"

[2f89cad7-73f6-4d1b-857b-0ef531f68b7e]
description = "3888 is MMMDCCCLXXXVIII"

[4e18e96b-5fbb-43df-a91b-9cb511fe0856]
description = "3999 is MMMCMXCIX"
8 changes: 8 additions & 0 deletions exercises/practice/roman-numerals/test-roman-numerals.bats
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,11 @@ load bats-extra
expected='MMMCMXCIX'
assert_equal "$output" "$expected"
}

@test '3888 is MMMDCCCLXXXVIII' {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run jq -r -f roman-numerals.jq <<< '{"number": 3888}'
assert_success
expected='MMMDCCCLXXXVIII'
assert_equal "$output" "$expected"
}
47 changes: 16 additions & 31 deletions exercises/practice/scrabble-score/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
# Instructions

Given a word, compute the Scrabble score for that word.
Your task is to compute a word's Scrabble score by summing the values of its letters.

## Letter Values
The letters are valued as follows:

You'll need these:
| Letter | Value |
| ---------------------------- | ----- |
| A, E, I, O, U, L, N, R, S, T | 1 |
| D, G | 2 |
| B, C, M, P | 3 |
| F, H, V, W, Y | 4 |
| K | 5 |
| J, X | 8 |
| Q, Z | 10 |

```text
Letter Value
A, E, I, O, U, L, N, R, S, T 1
D, G 2
B, C, M, P 3
F, H, V, W, Y 4
K 5
J, X 8
Q, Z 10
```

## Examples

"cabbage" should be scored as worth 14 points:
For example, the word "cabbage" is worth 14 points:

- 3 points for C
- 1 point for A, twice
- 3 points for B, twice
- 1 point for A
- 3 points for B
- 3 points for B
- 1 point for A
- 2 points for G
- 1 point for E

And to total:

- `3 + 2*1 + 2*3 + 2 + 1`
- = `3 + 2 + 6 + 3`
- = `5 + 9`
- = 14

## Extensions

- You can play a double or a triple letter.
- You can play a double or a triple word.
7 changes: 7 additions & 0 deletions exercises/practice/scrabble-score/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Introduction

[Scrabble][wikipedia] is a word game where players place letter tiles on a board to form words.
Each letter has a value.
A word's score is the sum of its letters' values.

[wikipedia]: https://en.wikipedia.org/wiki/Scrabble

0 comments on commit 922cab8

Please sign in to comment.