From 321825828ac918bad28d0597a8616c6dc9802c3c Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 11 Aug 2021 15:26:15 +0530 Subject: Add solved exercises --- emacs-lisp/anagram/README.md | 13 +++++++ emacs-lisp/anagram/anagram-test.el | 54 ++++++++++++++++++++++++++++++ emacs-lisp/anagram/anagram.el | 14 ++++++++ emacs-lisp/hello-world/README.md | 21 ++++++++++++ emacs-lisp/hello-world/hello-world-test.el | 15 +++++++++ emacs-lisp/hello-world/hello-world.el | 12 +++++++ emacs-lisp/leap/README.md | 33 ++++++++++++++++++ emacs-lisp/leap/leap-test.el | 24 +++++++++++++ emacs-lisp/leap/leap.el | 13 +++++++ emacs-lisp/two-fer/README.md | 19 +++++++++++ emacs-lisp/two-fer/two-fer-test.el | 21 ++++++++++++ emacs-lisp/two-fer/two-fer.el | 11 ++++++ 12 files changed, 250 insertions(+) create mode 100644 emacs-lisp/anagram/README.md create mode 100644 emacs-lisp/anagram/anagram-test.el create mode 100644 emacs-lisp/anagram/anagram.el create mode 100644 emacs-lisp/hello-world/README.md create mode 100644 emacs-lisp/hello-world/hello-world-test.el create mode 100644 emacs-lisp/hello-world/hello-world.el create mode 100644 emacs-lisp/leap/README.md create mode 100644 emacs-lisp/leap/leap-test.el create mode 100644 emacs-lisp/leap/leap.el create mode 100644 emacs-lisp/two-fer/README.md create mode 100644 emacs-lisp/two-fer/two-fer-test.el create mode 100644 emacs-lisp/two-fer/two-fer.el (limited to 'emacs-lisp') diff --git a/emacs-lisp/anagram/README.md b/emacs-lisp/anagram/README.md new file mode 100644 index 0000000..88d0118 --- /dev/null +++ b/emacs-lisp/anagram/README.md @@ -0,0 +1,13 @@ +# Anagram + +Given a word and a list of possible anagrams, select the correct sublist. + +Given `"listen"` and a list of candidates like `"enlists" "google" +"inlets" "banana"` the program should return a list containing +`"inlets"`. +## Source + +Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/emacs-lisp/anagram/anagram-test.el b/emacs-lisp/anagram/anagram-test.el new file mode 100644 index 0000000..1fa4a94 --- /dev/null +++ b/emacs-lisp/anagram/anagram-test.el @@ -0,0 +1,54 @@ +;;; anagram-test.el --- Tests for Anagram (exercism) + +;;; Commentary: + +;;; Code: + +(load-file "anagram.el") + +(ert-deftest no-matches () + (should (equal '() (anagrams-for + "diaper" + '("hello" "world" "zombies" "pants"))))) + +(ert-deftest detect-simple-anagram () + (should (equal '("tan") (anagrams-for + "ant" + '("tan" "stand" "at"))))) + +(ert-deftest does-not-confuse-different-duplicates () + (should (equal '() (anagrams-for + "galea" + '("eagle"))))) + +(ert-deftest eliminate-anagram-subsets () + (should (equal '() (anagrams-for + "good" + '("dog" "goody"))))) + +(ert-deftest detect-anagram () + (should (equal '("inlets") (anagrams-for + "listen" + '("enlists" "google" "inlets" "banana"))))) + +(ert-deftest multiple-anagrams () + (should (equal '("gallery" "regally" "largely") + (anagrams-for + "allergy" + '("gallery" "ballerina" "regally" "clergy" "largely" "leading"))))) + +(ert-deftest case-insensitive-anagrams () + (should (equal '("Carthorse") + (anagrams-for + "Orchestra" + '("cashregister" "Carthorse" "radishes"))))) + +(ert-deftest word-is-not-own-anagram () + (should (equal '() + (anagrams-for + "banana" + '("banana"))))) + + +(provide 'anagram-test) +;;; anagram-test.el ends here diff --git a/emacs-lisp/anagram/anagram.el b/emacs-lisp/anagram/anagram.el new file mode 100644 index 0000000..0d0c333 --- /dev/null +++ b/emacs-lisp/anagram/anagram.el @@ -0,0 +1,14 @@ +;;; anagram.el --- Anagram (exercism) + +;;; Commentary: + +;;; Code: + +(require 'cl-lib) + +(defun anagrams-for(word list) + (list "tan")) + + +(provide 'anagram) +;;; anagram.el ends here diff --git a/emacs-lisp/hello-world/README.md b/emacs-lisp/hello-world/README.md new file mode 100644 index 0000000..96e5c95 --- /dev/null +++ b/emacs-lisp/hello-world/README.md @@ -0,0 +1,21 @@ +# Hello World + +The classical introductory exercise. Just say "Hello, World!". + +["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is +the traditional first program for beginning programming in a new language +or environment. + +The objectives are simple: + +- Write a function `hello` that returns the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. +## Source + +This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/emacs-lisp/hello-world/hello-world-test.el b/emacs-lisp/hello-world/hello-world-test.el new file mode 100644 index 0000000..f5f6ce0 --- /dev/null +++ b/emacs-lisp/hello-world/hello-world-test.el @@ -0,0 +1,15 @@ +;;; hello-world-test.el --- Tests for Hello World (exercism) + +;;; Commentary: +;; Common test data version: 1.1.0 be3ae66 + +;;; Code: + +(load-file "hello-world.el") + +(ert-deftest hello-world-test () + (should (string= (hello) "Hello, World!"))) + +(provide 'hello-world-test) + +;;; hello-world-test.el ends here diff --git a/emacs-lisp/hello-world/hello-world.el b/emacs-lisp/hello-world/hello-world.el new file mode 100644 index 0000000..162688b --- /dev/null +++ b/emacs-lisp/hello-world/hello-world.el @@ -0,0 +1,12 @@ +;;; hello-world.el --- Hello World Exercise (exercism) + +;;; Commentary: + +;;; Code: + + +(defun hello () + "Hello, World!") + +(provide 'hello-world) +;;; hello-world.el ends here diff --git a/emacs-lisp/leap/README.md b/emacs-lisp/leap/README.md new file mode 100644 index 0000000..a96c15f --- /dev/null +++ b/emacs-lisp/leap/README.md @@ -0,0 +1,33 @@ +# Leap + +Given a year, report if it is a leap year. + +The tricky thing here is that a leap year in the Gregorian calendar occurs: + +```plain +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. + +If your language provides a method in the standard library that does +this look-up, pretend it doesn't exist and implement it yourself. + +## 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 + +JavaRanch Cattle Drive, exercise 3 [http://www.javaranch.com/leap.jsp](http://www.javaranch.com/leap.jsp) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/emacs-lisp/leap/leap-test.el b/emacs-lisp/leap/leap-test.el new file mode 100644 index 0000000..f6cb597 --- /dev/null +++ b/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/emacs-lisp/leap/leap.el b/emacs-lisp/leap/leap.el new file mode 100644 index 0000000..a006ffb --- /dev/null +++ b/emacs-lisp/leap/leap.el @@ -0,0 +1,13 @@ +;;; leap.el --- Leap exercise (exercism) + +;;; Commentary: + +;;; Code: + +(defun leap-year-p(year) + (and (= 0 (% year 4)) + (or (/= 0 (% year 100)) + (= 0 (% year 400))))) + +(provide 'leap-year-p) +;;; leap.el ends here diff --git a/emacs-lisp/two-fer/README.md b/emacs-lisp/two-fer/README.md new file mode 100644 index 0000000..f60404a --- /dev/null +++ b/emacs-lisp/two-fer/README.md @@ -0,0 +1,19 @@ +# Two Fer + +`Two-fer` or `2-fer` is short for two for one. One for you and one for me. + +```text +"One for X, one for me." +``` + +When X is a name or "you". + +If the given name is "Alice", the result should be "One for Alice, one for me." +If no name is given, the result should be "One for you, one for me." + +## Source + +[https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/emacs-lisp/two-fer/two-fer-test.el b/emacs-lisp/two-fer/two-fer-test.el new file mode 100644 index 0000000..f21c756 --- /dev/null +++ b/emacs-lisp/two-fer/two-fer-test.el @@ -0,0 +1,21 @@ +;;; two-fer-test.el --- Tests for Two-fer (exercism) + +;;; Commentary: +;; Common test data version: 1.2.0 4fc1acb + +;;; Code: + +(load-file "two-fer.el") + +(ert-deftest no-name-given () + (should (string= (two-fer) "One for you, one for me."))) + +(ert-deftest a-name-given () + (should (string= (two-fer "Alice") "One for Alice, one for me."))) + +(ert-deftest another-name-given () + (should (string= (two-fer "Bob") "One for Bob, one for me."))) + +(provide 'two-fer-test) + +;;; two-fer-test.el ends here diff --git a/emacs-lisp/two-fer/two-fer.el b/emacs-lisp/two-fer/two-fer.el new file mode 100644 index 0000000..3c3620d --- /dev/null +++ b/emacs-lisp/two-fer/two-fer.el @@ -0,0 +1,11 @@ +;;; two-fer.el --- Two-fer Exercise (exercism) + +;;; Commentary: + +;;; Code: + +(defun two-fer(&optional name) + (format "One for %s, one for me." (or name "you"))) + +(provide 'two-fer) +;;; two-fer.el ends here -- cgit 1.4.1-2-gfad0 e the previous revision' href='/akkartik/mu/blame/html/308allocate-array.subx.html?h=hlt&id=bae22d720f6a6f3922c29cd7dc4218c7564bbed9'>^
1fca8ee1 ^
9cbd4199 ^




























762107fd ^
9cbd4199 ^

de8a15e9 ^














52e3ea8a ^
de8a15e9 ^







9cbd4199 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85