1
0
Fork 0

new solution: emacs-lisp, grains.

main
Gökmen Görgen 2 months ago
parent 02ada56b04
commit 1c1ebaf2ee
  1. 41
      emacs-lisp/grains/HELP.md
  2. 48
      emacs-lisp/grains/README.md
  3. 38
      emacs-lisp/grains/grains-test.el
  4. 16
      emacs-lisp/grains/grains.el

@ -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 grains.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.

@ -0,0 +1,48 @@
# Grains
Welcome to Grains on Exercism's Emacs Lisp Track.
If you need help running the tests or submitting your code, check out `HELP.md`.
## Instructions
Calculate the number of grains of wheat on a chessboard given that the number
on each square doubles.
There once was a wise servant who saved the life of a prince. The king
promised to pay whatever the servant could dream up. Knowing that the
king loved chess, the servant told the king he would like to have grains
of wheat. One grain on the first square of a chess board, with the number
of grains doubling on each successive square.
There are 64 squares on a chessboard (where square 1 has one grain, square 2 has two grains, and so on).
Write code that shows:
- how many grains were on a given square, and
- the total number of grains on the chessboard
## For bonus points
Did you get the tests passing and the code clean? If you want to, these
are some additional things you could try:
- Optimize for speed.
- Optimize for readability.
Then please share your thoughts in a comment on the submission. Did this
experiment make the code better? Worse? Did you learn anything from it?
## Source
### Created by
- @canweriotnow
### Contributed to by
- @vermiculus
- @wasamasa
- @yurrriq
### Based on
JavaRanch Cattle Drive, exercise 6 - http://www.javaranch.com/grains.jsp

@ -0,0 +1,38 @@
;;; grains-test.el --- Test for Grains (exercism)
;;; Commentary:
;;; Code:
(load-file "grains.el")
(ert-deftest square-1 ()
(should (= 1 (square 1))))
(ert-deftest square-2 ()
(should (= 2 (square 2))))
(ert-deftest square-3 ()
(should (= 4 (square 3))))
(ert-deftest square-4 ()
(should (= 8 (square 4))))
(ert-deftest square-16 ()
(should (= 32768
(square 16))))
(ert-deftest square-32 ()
(should (= 2147483648
(square 32))))
(ert-deftest square-64 ()
(should (= 9223372036854775808
(square 64))))
(ert-deftest total-grains ()
(should (= 18446744073709551615
(total))))
(provide 'grains-test.el)
;;; grains-test.el ends here.

@ -0,0 +1,16 @@
;;; grains.el --- Grains exercise (exercism)
;;; Commentary:
;;; Code:
(defun square (n)
"how many grains were on a given square, and"
(expt 2 (- n 1)))
(defun total ()
"the total number of grains on the chessboard"
(- (* 2 (square 64)) 1))
(provide 'grains)
;;; grains.el ends here
Loading…
Cancel
Save