From edba00dfa6f8d5e625207bfeff936595dd794934 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Mon, 22 Nov 2021 20:46:48 -0500 Subject: elisp exercise --- .../rna-transcription/.exercism/config.json | 22 ++++++++++++ .../rna-transcription/.exercism/metadata.json | 1 + exercism/emacs-lisp/rna-transcription/HELP.md | 41 ++++++++++++++++++++++ exercism/emacs-lisp/rna-transcription/README.md | 38 ++++++++++++++++++++ .../rna-transcription/rna-transcription-test.el | 32 +++++++++++++++++ .../rna-transcription/rna-transcription.el | 19 ++++++++++ exercism/emacs-lisp/run-exercises.el | 4 +++ 7 files changed, 157 insertions(+) create mode 100644 exercism/emacs-lisp/rna-transcription/.exercism/config.json create mode 100644 exercism/emacs-lisp/rna-transcription/.exercism/metadata.json create mode 100644 exercism/emacs-lisp/rna-transcription/HELP.md create mode 100644 exercism/emacs-lisp/rna-transcription/README.md create mode 100644 exercism/emacs-lisp/rna-transcription/rna-transcription-test.el create mode 100644 exercism/emacs-lisp/rna-transcription/rna-transcription.el diff --git a/exercism/emacs-lisp/rna-transcription/.exercism/config.json b/exercism/emacs-lisp/rna-transcription/.exercism/config.json new file mode 100644 index 0000000..c3c7579 --- /dev/null +++ b/exercism/emacs-lisp/rna-transcription/.exercism/config.json @@ -0,0 +1,22 @@ +{ + "blurb": "Given a DNA strand, return its RNA Complement Transcription.", + "authors": [ + "canweriotnow" + ], + "contributors": [ + "vermiculus" + ], + "files": { + "solution": [ + "rna-transcription.el" + ], + "test": [ + "rna-transcription-test.el" + ], + "example": [ + ".meta/example.el" + ] + }, + "source": "Hyperphysics", + "source_url": "http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html" +} diff --git a/exercism/emacs-lisp/rna-transcription/.exercism/metadata.json b/exercism/emacs-lisp/rna-transcription/.exercism/metadata.json new file mode 100644 index 0000000..62b82fe --- /dev/null +++ b/exercism/emacs-lisp/rna-transcription/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"emacs-lisp","exercise":"rna-transcription","id":"ed4517e463054a3f873aff94ae2defbd","url":"https://exercism.org/tracks/emacs-lisp/exercises/rna-transcription","handle":"orbekk","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/exercism/emacs-lisp/rna-transcription/HELP.md b/exercism/emacs-lisp/rna-transcription/HELP.md new file mode 100644 index 0000000..190f375 --- /dev/null +++ b/exercism/emacs-lisp/rna-transcription/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 rna-transcription.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/rna-transcription/README.md b/exercism/emacs-lisp/rna-transcription/README.md new file mode 100644 index 0000000..5124dbe --- /dev/null +++ b/exercism/emacs-lisp/rna-transcription/README.md @@ -0,0 +1,38 @@ +# Rna Transcription + +Welcome to Rna Transcription on Exercism's Emacs Lisp Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a DNA strand, return its RNA complement (per RNA transcription). + +Both DNA and RNA strands are a sequence of nucleotides. + +The four nucleotides found in DNA are adenine (**A**), cytosine (**C**), +guanine (**G**) and thymine (**T**). + +The four nucleotides found in RNA are adenine (**A**), cytosine (**C**), +guanine (**G**) and uracil (**U**). + +Given a DNA strand, its transcribed RNA strand is formed by replacing +each nucleotide with its complement: + +* `G` -> `C` +* `C` -> `G` +* `T` -> `A` +* `A` -> `U` + +## Source + +### Created by + +- @canweriotnow + +### Contributed to by + +- @vermiculus + +### Based on + +Hyperphysics - http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html \ No newline at end of file diff --git a/exercism/emacs-lisp/rna-transcription/rna-transcription-test.el b/exercism/emacs-lisp/rna-transcription/rna-transcription-test.el new file mode 100644 index 0000000..b00de89 --- /dev/null +++ b/exercism/emacs-lisp/rna-transcription/rna-transcription-test.el @@ -0,0 +1,32 @@ +;;; rna-transcription-test.el --- Tests for RNA Transcription (exercism) + +;;; Commentary: + + +;;; Code: + +(require 'cl-lib) + +(load-file "rna-transcription.el") + +(ert-deftest transcribes-cytosine-to-guanine () + (should (string= "G" (to-rna "C")))) + +(ert-deftest transcribes-guanine-to-cytosine () + (should (string= "C" (to-rna "G")))) + +(ert-deftest transcribes-adenine-to-uracil () + (should (string= "U" (to-rna "A")))) + +(ert-deftest transcribes-thymine-to-adenine () + (should (string= "A" (to-rna "T")))) + +(ert-deftest it-transcribes-all-nucleotides () + (should (string= "UGCACCAGAAUU" + (to-rna "ACGTGGTCTTAA")))) + +(ert-deftest it-validates-dna-strands () + (should-error (to-rna "XCGFGGTDTTAA"))) + +(provide 'rna-transcription-test) +;;; rna-transcription-test.el ends here diff --git a/exercism/emacs-lisp/rna-transcription/rna-transcription.el b/exercism/emacs-lisp/rna-transcription/rna-transcription.el new file mode 100644 index 0000000..bb39f2b --- /dev/null +++ b/exercism/emacs-lisp/rna-transcription/rna-transcription.el @@ -0,0 +1,19 @@ +;;; rna-transcription.el -- RNA Transcription (exercism) +;;; Commentary: +;;; Code: + +(require 'seq) + +(defun char-to-rna (c) + (cond + ((eql ?G c) ?C) + ((eql ?C c) ?G) + ((eql ?T c) ?A) + ((eql ?A c) ?U) + (t (error 'invalid-char)))) + +(defun to-rna (str) + (apply 'string (seq-map 'char-to-rna str))) + +(provide 'rna-transcription) +;;; rna-transcription.el ends here diff --git a/exercism/emacs-lisp/run-exercises.el b/exercism/emacs-lisp/run-exercises.el index 39372e3..b243f0e 100644 --- a/exercism/emacs-lisp/run-exercises.el +++ b/exercism/emacs-lisp/run-exercises.el @@ -55,4 +55,8 @@ (kj-display "Hamming distance" (hamming-distance "GGACGGATTCTG" "AGGACGGATTCT")) +(load-file "rna-transcription/rna-transcription.el") +(kj-display "RNA transcription" + (to-rna "GGACGGATTCTG")) + (provide 'hello) -- cgit v1.2.3