exercism

Exercism solutions.
Log | Files | Refs

commit 782b624edd671b2c913418b17bd365573d04017a
parent 4566ec687f1212d875c723019722a277ca93560e
Author: dwrz <dwrz@dwrz.net>
Date:   Thu,  7 Feb 2019 03:13:50 +0000

Add elisp/rna-transcription

Diffstat:
Aelisp/rna-transcription/README.md | 25+++++++++++++++++++++++++
Aelisp/rna-transcription/rna-transcription-test.el | 32++++++++++++++++++++++++++++++++
Aelisp/rna-transcription/rna-transcription.el | 23+++++++++++++++++++++++
3 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/elisp/rna-transcription/README.md b/elisp/rna-transcription/README.md @@ -0,0 +1,25 @@ +# Rna Transcription + +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 + +Rosalind [http://rosalind.info/problems/rna](http://rosalind.info/problems/rna) + +## Submitting Incomplete Solutions +It's possible to submit an incomplete solution so you can see how others have completed the exercise. diff --git a/elisp/rna-transcription/rna-transcription-test.el b/elisp/rna-transcription/rna-transcription-test.el @@ -0,0 +1,32 @@ +;;; rna-transcription-test.el --- Tests for RNA Transcription (exercism) + +;;; Commentary: + + +;;; Code: + +(require 'cl) + +(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/elisp/rna-transcription/rna-transcription.el b/elisp/rna-transcription/rna-transcription.el @@ -0,0 +1,23 @@ +;;; rna-transcription.el -- RNA Transcription (exercism) + +;;; Commentary: + +;;; Code: + +(provide 'rna-transcription) + +(defun transcribe (nucleotide) +"Return the matching RNA pair for DNA NUCLEOTIDE." + (cond ((char-equal nucleotide ?C) "G") + ((char-equal nucleotide ?G) "C") + ((char-equal nucleotide ?A) "U") + ((char-equal nucleotide ?T) "A") + ((error "Unrecognized nucleotide")))) + +(defun to-rna (dna) +"Transcribe a string representing DNA nucleotides. +Return a string representing RNA nucleotides." + (cl-loop for nucleotide being the elements of dna + concat (transcribe nucleotide))) + +;;; rna-transcription.el ends here