Skip to content

Commit

Permalink
resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
kmarker1101 committed Jun 28, 2024
2 parents a6d1892 + 03bbe90 commit 5dd897a
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,14 @@
"prerequisites": [],
"difficulty": 2
},
{
"slug": "proverb",
"name": "Proverb",
"uuid": "e946ec2a-749a-4018-877b-25c42d4ee5b0",
"practices": [],
"prerequisites": [],
"difficulty": 2
},
{
"slug": "say",
"name": "Say",
Expand Down
19 changes: 19 additions & 0 deletions exercises/practice/proverb/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Instructions

For want of a horseshoe nail, a kingdom was lost, or so the saying goes.

Given a list of inputs, generate the relevant proverb.
For example, given the list `["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]`, you will output the full text of this proverbial rhyme:

```text
For want of a nail the shoe was lost.
For want of a shoe the horse was lost.
For want of a horse the rider was lost.
For want of a rider the message was lost.
For want of a message the battle was lost.
For want of a battle the kingdom was lost.
And all for the want of a nail.
```

Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content.
No line of the output text should be a static, unchanging string; all should vary according to the input given.
19 changes: 19 additions & 0 deletions exercises/practice/proverb/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"kmarker1101"
],
"files": {
"solution": [
"proverb.el"
],
"test": [
"proverb-test.el"
],
"example": [
".meta/example.el"
]
},
"blurb": "For want of a horseshoe nail, a kingdom was lost, or so the saying goes. Output the full text of this proverbial rhyme.",
"source": "Wikipedia",
"source_url": "https://en.wikipedia.org/wiki/For_Want_of_a_Nail"
}
19 changes: 19 additions & 0 deletions exercises/practice/proverb/.meta/example.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;;; proverb.el --- Proverb (exercism) -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:


(defun recite (strings)
(let ((n (length strings)))
(cond ((= n 0) '())
((= n 1) (list (format "And all for the want of a %s." (car strings))))
(t (append (cl-loop for i from 0 to (- n 2)
collect (format "For want of a %s the %s was lost." (nth i strings) (nth (1+ i) strings)))
(list (format "And all for the want of a %s." (car strings))))))))


(provide 'proverb)
;;; proverb.el ends here

28 changes: 28 additions & 0 deletions exercises/practice/proverb/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

[e974b73e-7851-484f-8d6d-92e07fe742fc]
description = "zero pieces"

[2fcd5f5e-8b82-4e74-b51d-df28a5e0faa4]
description = "one piece"

[d9d0a8a1-d933-46e2-aa94-eecf679f4b0e]
description = "two pieces"

[c95ef757-5e94-4f0d-a6cb-d2083f5e5a83]
description = "three pieces"

[433fb91c-35a2-4d41-aeab-4de1e82b2126]
description = "full proverb"

[c1eefa5a-e8d9-41c7-91d4-99fab6d6b9f7]
description = "four pieces modernized"
48 changes: 48 additions & 0 deletions exercises/practice/proverb/proverb-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
;;; proverb-test.el --- Proverb (exercism) -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:


(load-file "proverb.el")
(declare-function recite "proverb.el" (strings))


(ert-deftest zero-pieces ()
(should (equal (recite '()) '())))


(ert-deftest one-piece ()
(should (equal (recite '("nail")) '("And all for the want of a nail."))))


(ert-deftest two-pieces ()
(should (equal (recite '("nail" "shoe")) '("For want of a nail the shoe was lost." "And all for the want of a nail."))))


(ert-deftest three-pieces ()
(should (equal (recite '("nail" "shoe" "horse")) '("For want of a nail the shoe was lost." "For want of a shoe the horse was lost." "And all for the want of a nail."))))


(ert-deftest full-proverb ()
(should (equal (recite '("nail" "shoe" "horse" "rider" "message" "battle" "kingdom"))
'("For want of a nail the shoe was lost."
"For want of a shoe the horse was lost."
"For want of a horse the rider was lost."
"For want of a rider the message was lost."
"For want of a message the battle was lost."
"For want of a battle the kingdom was lost."
"And all for the want of a nail."))))


(ert-deftest four-pieces-modernized ()
(should (equal (recite '("pin" "gun" "soldier" "battle"))
'("For want of a pin the gun was lost."
"For want of a gun the soldier was lost."
"For want of a soldier the battle was lost."
"And all for the want of a pin."))))


(provide 'proverb-test)
;;; proverb-test.el ends here
14 changes: 14 additions & 0 deletions exercises/practice/proverb/proverb.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;;; proverb.el --- Proverb (exercism) -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:


(defun recite (strings)
(error "Delete this S-Expression and write your own implementation"))


(provide 'proverb)
;;; proverb.el ends here

0 comments on commit 5dd897a

Please sign in to comment.