Skip to content

Commit

Permalink
add missing reverse-string tests, exercism#364
Browse files Browse the repository at this point in the history
update docs fix exercism#364 (exercism#411)

add missing reverse-string tests, exercism#364
  • Loading branch information
kmarker1101 committed Jun 16, 2024
1 parent 787cfaa commit 5a1cf89
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 35 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/bank-account/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Your task is to implement bank accounts supporting opening/closing, withdrawals, and deposits of money.

As bank accounts can be accessed in many different ways (internet, mobile phones, automatic charges), your bank software must allow accounts to be safely accessed from multiple threads/processes (terminology depends on your programming language) in parallel.
For example, there may be many deposits and withdrawals occurring in parallel; you need to ensure there is no [race conditions][wikipedia] between when you read the account balance and set the new balance.
For example, there may be many deposits and withdrawals occurring in parallel; you need to ensure there are no [race conditions][wikipedia] between when you read the account balance and set the new balance.

It should be possible to close an account; operations against a closed account must fail.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ The band colors are encoded as follows:
- White: 9

From the example above:
brown-green should return 15
brown-green should return 15, and
brown-green-violet should return 15 too, ignoring the third color.
26 changes: 25 additions & 1 deletion exercises/practice/reverse-string/.meta/example.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,33 @@

;;; Code:

(require 'cl-lib)
(require 'ucs-normalize)

(defun combining-mark-p (char)
(let ((category (get-char-code-property char 'general-category)))
(or (string= category "Mn") ; Nonspacing_Mark
(string= category "Mc") ; Spacing_Mark
(string= category "Me")))) ; Enclosing_Mark

(defun split-grapheme-clusters (str)
(let ((clusters '())
(i 0)
(len (length str)))
(while (< i len)
(let ((start i)
(char (aref str i)))
(setq i (1+ i))
(while (and (< i len)
(combining-mark-p (aref str i)))
(setq i (1+ i)))
(push (substring str start i) clusters)))
(nreverse clusters)))

(defun reverse-string (value)
(reverse value))
(let* ((decomposed (ucs-normalize-NFD-string value))
(clusters (split-grapheme-clusters decomposed)))
(apply #'concat (reverse clusters))))


(provide 'reverse-string)
Expand Down
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ description = "a palindrome"

[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
description = "an even-sized word"

[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
description = "wide characters"

[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
description = "grapheme cluster with pre-combined form"

[1028b2c1-6763-4459-8540-2da47ca512d9]
description = "grapheme clusters"
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/reverse-string-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
(ert-deftest an-even-sized-word ()
(should (string= (reverse-string "drawer") "reward")))

(ert-deftest wide-characters ()
(should (string= (reverse-string "子猫") "猫子")))

(ert-deftest grapheme-cluster-with-pre-combined-form ()
(should (string= (reverse-string "Würstchenstand") "dnatsnehctsrüW")))

(ert-deftest grapheme-cluster ()
(should (string= (reverse-string "ผู้เขียนโปรแกรม") "มรกแรปโนยขีเผู้")))


(provide 'reverse-string-test)
;;; reverse-string-test.el ends here
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
2 changes: 1 addition & 1 deletion exercises/practice/spiral-matrix/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instructions

Given the size, return a square matrix of numbers in spiral order.
Your task is to return a square matrix of a given size.

The matrix should be filled with natural numbers, starting from 1 in the top-left corner, increasing in an inward, clockwise spiral order, like these examples:

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

In a small village near an ancient forest, there was a legend of a hidden treasure buried deep within the woods.
Despite numerous attempts, no one had ever succeeded in finding it.
This was about to change, however, thanks to a young explorer named Elara.
She had discovered an old document containing instructions on how to locate the treasure.
Using these instructions, Elara was able to draw a map that revealed the path to the treasure.

To her surprise, the path followed a peculiar clockwise spiral.
It was no wonder no one had been able to find the treasure before!
With the map in hand, Elara embarks on her journey to uncover the hidden treasure.

0 comments on commit 5a1cf89

Please sign in to comment.