summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2021-11-21 07:32:36 -0500
committerKjetil Orbekk <kj@orbekk.com>2021-11-21 07:32:36 -0500
commit6e73544775e99026edab513e4ee1bb7fd610ebb4 (patch)
tree6e686a3b278b078290a361b6c12e036f340ddc93
parent9ebec329bf25548f21401f7e3690012845348d29 (diff)
exercism exercises
-rw-r--r--elisp/flake.nix16
-rw-r--r--exercism/emacs-lisp/leap/.exercism/config.json22
-rw-r--r--exercism/emacs-lisp/leap/.exercism/metadata.json1
-rw-r--r--exercism/emacs-lisp/leap/HELP.md41
-rw-r--r--exercism/emacs-lisp/leap/README.md43
-rw-r--r--exercism/emacs-lisp/leap/leap-test.el24
-rw-r--r--exercism/emacs-lisp/leap/leap.el15
-rw-r--r--exercism/emacs-lisp/run-exercises.el4
-rw-r--r--exercism/flake.lock43
9 files changed, 193 insertions, 16 deletions
diff --git a/elisp/flake.nix b/elisp/flake.nix
deleted file mode 100644
index b68fbf2..0000000
--- a/elisp/flake.nix
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- inputs = {
- utils.url = "github:numtide/flake-utils";
- nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05";
- };
-
- outputs = { self, nixpkgs, utils }:
- # Note: This has only been tested on x86_64-linux.
- utils.lib.eachDefaultSystem (system: let
- pkgs = nixpkgs.legacyPackages."${system}";
- in rec {
- devShell = pkgs.mkShell {
- nativeBuildInputs = with pkgs; [ exercism ];
- };
- });
-}
diff --git a/exercism/emacs-lisp/leap/.exercism/config.json b/exercism/emacs-lisp/leap/.exercism/config.json
new file mode 100644
index 0000000..5394efb
--- /dev/null
+++ b/exercism/emacs-lisp/leap/.exercism/config.json
@@ -0,0 +1,22 @@
+{
+ "blurb": "Given a year, report if it is a leap year.",
+ "authors": [
+ "canweriotnow"
+ ],
+ "contributors": [
+ "fominok"
+ ],
+ "files": {
+ "solution": [
+ "leap.el"
+ ],
+ "test": [
+ "leap-test.el"
+ ],
+ "example": [
+ ".meta/example.el"
+ ]
+ },
+ "source": "JavaRanch Cattle Drive, exercise 3",
+ "source_url": "http://www.javaranch.com/leap.jsp"
+}
diff --git a/exercism/emacs-lisp/leap/.exercism/metadata.json b/exercism/emacs-lisp/leap/.exercism/metadata.json
new file mode 100644
index 0000000..cdc4a09
--- /dev/null
+++ b/exercism/emacs-lisp/leap/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"emacs-lisp","exercise":"leap","id":"49558470ec7d4f4dbc32eea122c430d6","url":"https://exercism.org/tracks/emacs-lisp/exercises/leap","handle":"orbekk","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/exercism/emacs-lisp/leap/HELP.md b/exercism/emacs-lisp/leap/HELP.md
new file mode 100644
index 0000000..f1b4d5c
--- /dev/null
+++ b/exercism/emacs-lisp/leap/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 leap.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/leap/README.md b/exercism/emacs-lisp/leap/README.md
new file mode 100644
index 0000000..ab0cd63
--- /dev/null
+++ b/exercism/emacs-lisp/leap/README.md
@@ -0,0 +1,43 @@
+# Leap
+
+Welcome to Leap on Exercism's Emacs Lisp Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Given a year, report if it is a leap year.
+
+The tricky thing here is that a leap year in the Gregorian calendar occurs:
+
+```text
+on every year that is evenly divisible by 4
+ except every year that is evenly divisible by 100
+ unless the year is also evenly divisible by 400
+```
+
+For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap
+year, but 2000 is.
+
+## Notes
+
+Though our exercise adopts some very simple rules, there is more to
+learn!
+
+For a delightful, four minute explanation of the whole leap year
+phenomenon, go watch [this youtube video][video].
+
+[video]: http://www.youtube.com/watch?v=xX96xng7sAE
+
+## Source
+
+### Created by
+
+- @canweriotnow
+
+### Contributed to by
+
+- @fominok
+
+### Based on
+
+JavaRanch Cattle Drive, exercise 3 - http://www.javaranch.com/leap.jsp \ No newline at end of file
diff --git a/exercism/emacs-lisp/leap/leap-test.el b/exercism/emacs-lisp/leap/leap-test.el
new file mode 100644
index 0000000..f6cb597
--- /dev/null
+++ b/exercism/emacs-lisp/leap/leap-test.el
@@ -0,0 +1,24 @@
+;;; leap-test.el --- Tests for Leap exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+(load-file "leap.el")
+
+(ert-deftest vanilla-leap-year ()
+ (should (leap-year-p 1996)))
+
+(ert-deftest any-old-year ()
+ (should-not (leap-year-p 1997)))
+
+(ert-deftest non-leap-even-year ()
+ (should-not (leap-year-p 1997)))
+
+(ert-deftest century ()
+ (should-not (leap-year-p 1900)))
+
+(ert-deftest exceptional-century ()
+ (should (leap-year-p 2000)))
+
+(provide 'leap-test)
+;;; leap-test.el ends here
diff --git a/exercism/emacs-lisp/leap/leap.el b/exercism/emacs-lisp/leap/leap.el
new file mode 100644
index 0000000..234c14c
--- /dev/null
+++ b/exercism/emacs-lisp/leap/leap.el
@@ -0,0 +1,15 @@
+;;; leap.el --- Leap exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+(defun divisible-by-p (n d)
+ (equal 0 (% n d)))
+
+(defun leap-year-p (year)
+ (and (divisible-by-p year 4)
+ (or (not (divisible-by-p year 100))
+ (divisible-by-p year 400))))
+
+(provide 'leap-year-p)
+;;; leap.el ends here
diff --git a/exercism/emacs-lisp/run-exercises.el b/exercism/emacs-lisp/run-exercises.el
index 38b097b..229a46a 100644
--- a/exercism/emacs-lisp/run-exercises.el
+++ b/exercism/emacs-lisp/run-exercises.el
@@ -33,4 +33,8 @@
(load-file "two-fer/two-fer.el")
(kj-display "Two-fer" (two-fer "Annie"))
+(load-file "leap/leap.el")
+(kj-display "* Leap years"
+ (leap-year-p 1996))
+
(provide 'hello)
diff --git a/exercism/flake.lock b/exercism/flake.lock
new file mode 100644
index 0000000..ebe722a
--- /dev/null
+++ b/exercism/flake.lock
@@ -0,0 +1,43 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1637316267,
+ "narHash": "sha256-hfAA/0W3tycKKOSwP7Xt6FXLG9h/FgCu45wdGubHtV0=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "24528474d2b3370f2f23879a557ae2cc92a5d50b",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-21.05",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs",
+ "utils": "utils"
+ }
+ },
+ "utils": {
+ "locked": {
+ "lastModified": 1637014545,
+ "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}