diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2021-11-28 13:03:48 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2021-11-28 13:03:48 -0500 |
commit | 17049953c08b7c783bf73fcb18ddbb7b05c8a671 (patch) | |
tree | 134b4db7e924b4cd803584bef1aef1c0de57d163 /exercism/emacs-lisp/difference-of-squares | |
parent | 65951ec5972aec2abbfc8d0dfa2a7227a0fa7223 (diff) |
add exercises
Diffstat (limited to 'exercism/emacs-lisp/difference-of-squares')
6 files changed, 165 insertions, 0 deletions
diff --git a/exercism/emacs-lisp/difference-of-squares/.exercism/config.json b/exercism/emacs-lisp/difference-of-squares/.exercism/config.json new file mode 100644 index 0000000..7d5d1e5 --- /dev/null +++ b/exercism/emacs-lisp/difference-of-squares/.exercism/config.json @@ -0,0 +1,24 @@ +{ + "blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.", + "authors": [ + "canweriotnow" + ], + "contributors": [ + "Scientifica96", + "vermiculus", + "yurrriq" + ], + "files": { + "solution": [ + "difference-of-squares.el" + ], + "test": [ + "difference-of-squares-test.el" + ], + "example": [ + ".meta/example.el" + ] + }, + "source": "Problem 6 at Project Euler", + "source_url": "http://projecteuler.net/problem=6" +} diff --git a/exercism/emacs-lisp/difference-of-squares/.exercism/metadata.json b/exercism/emacs-lisp/difference-of-squares/.exercism/metadata.json new file mode 100644 index 0000000..7051a2b --- /dev/null +++ b/exercism/emacs-lisp/difference-of-squares/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"emacs-lisp","exercise":"difference-of-squares","id":"d839accd4cc147648cf015b4a41e496d","url":"https://exercism.org/tracks/emacs-lisp/exercises/difference-of-squares","handle":"orbekk","is_requester":true,"auto_approve":false}
\ No newline at end of file diff --git a/exercism/emacs-lisp/difference-of-squares/HELP.md b/exercism/emacs-lisp/difference-of-squares/HELP.md new file mode 100644 index 0000000..23a6380 --- /dev/null +++ b/exercism/emacs-lisp/difference-of-squares/HELP.md @@ -0,0 +1,41 @@ +# Help + +## Running the tests + +Tests can be run several ways: + +1. Interactively and individually, with `M-x ert RET test-name RET` +2. Interactively and all at once, with `M-x ert RET t RET` +3. From the terminal, in batch mode, with `emacs -batch -l ert -l my-test.el -f ert-run-tests-batch-and-exit` +4. Other options can be found in the docs, `C-h i m ert RET` + +## Submitting your solution + +You can submit your solution using the `exercism submit difference-of-squares.el` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Emacs Lisp track's documentation](https://exercism.org/docs/tracks/emacs-lisp) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [The Emacs Wiki](http://emacswiki.org/) is invaluable. Spend lots of time here. +- [The Emacs Editor](http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html) is the official manual for GNU Emacs. +- IRC - there are [freenode](https://freenode.net/) channels for `#emacs`, `#prelude`, and many Emacs + packages, and many helpful folks around. And with emacs, IRC is as close as + `M-x erc`. +- [Exercism Support](https://gitter.im/exercism/support) Gitter chat is also a good place to get help from the + exercism community. +- [StackOverflow](http://stackoverflow.com/questions/tagged/elisp) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
\ No newline at end of file diff --git a/exercism/emacs-lisp/difference-of-squares/README.md b/exercism/emacs-lisp/difference-of-squares/README.md new file mode 100644 index 0000000..ae757fa --- /dev/null +++ b/exercism/emacs-lisp/difference-of-squares/README.md @@ -0,0 +1,38 @@ +# Difference Of Squares + +Welcome to Difference Of Squares on Exercism's Emacs Lisp Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Find the difference between the square of the sum and the sum of the squares of the first N natural numbers. + +The square of the sum of the first ten natural numbers is +(1 + 2 + ... + 10)² = 55² = 3025. + +The sum of the squares of the first ten natural numbers is +1² + 2² + ... + 10² = 385. + +Hence the difference between the square of the sum of the first +ten natural numbers and the sum of the squares of the first ten +natural numbers is 3025 - 385 = 2640. + +You are not expected to discover an efficient solution to this yourself from +first principles; research is allowed, indeed, encouraged. Finding the best +algorithm for the problem is a key skill in software engineering. + +## Source + +### Created by + +- @canweriotnow + +### Contributed to by + +- @Scientifica96 +- @vermiculus +- @yurrriq + +### Based on + +Problem 6 at Project Euler - http://projecteuler.net/problem=6
\ No newline at end of file diff --git a/exercism/emacs-lisp/difference-of-squares/difference-of-squares-test.el b/exercism/emacs-lisp/difference-of-squares/difference-of-squares-test.el new file mode 100644 index 0000000..56c5559 --- /dev/null +++ b/exercism/emacs-lisp/difference-of-squares/difference-of-squares-test.el @@ -0,0 +1,40 @@ +;;; difference-of-squares-test.el --- Tests for difference-of-squares (exercism) + +;;; Commentary: + +;;; Code: + +(load-file "difference-of-squares.el") + +(ert-deftest square-of-sum-to-5 () + (should (= 225 (square-of-sum 5)))) + +(ert-deftest sum-of-squares-to-5 () + (should (= 55 (sum-of-squares 5)))) + +(ert-deftest difference-of-squares-to-5 () + (should (= 170 (difference 5)))) + + +(ert-deftest square-of-sum-to-10 () + (should (= 3025 (square-of-sum 10)))) + +(ert-deftest sum-of-squares-to-10 () + (should (= 385 (sum-of-squares 10)))) + +(ert-deftest difference-of-squares-to-10 () + (should (= 2640 (difference 10)))) + + +(ert-deftest square-of-sum-to-100 () + (should (= 25502500 (square-of-sum 100)))) + +(ert-deftest sum-of-squares-to-100 () + (should (= 338350 (sum-of-squares 100)))) + +(ert-deftest difference-of-squares-to-100 () + (should (= 25164150 (difference 100)))) + + +(provide 'difference-of-squares-test) +;;; difference-of-squares-test.el ends here diff --git a/exercism/emacs-lisp/difference-of-squares/difference-of-squares.el b/exercism/emacs-lisp/difference-of-squares/difference-of-squares.el new file mode 100644 index 0000000..4b7e452 --- /dev/null +++ b/exercism/emacs-lisp/difference-of-squares/difference-of-squares.el @@ -0,0 +1,21 @@ +;;; difference-of-squares.el --- Difference of Squares (exercism) + +;;; Commentary: + +;;; Code: +(require 'cl) + +(defun square-of-sum (n) + (cl-loop for i from 1 to n + sum i into s + finally return (* s s))) + +(defun sum-of-squares (n) + (cl-loop for i from 1 to n + sum (* i i))) + +(defun difference (n) + (- (square-of-sum n) (sum-of-squares n))) + +(provide 'difference-of-squares) +;;; difference-of-squares.el ends here |