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:
While Common Lisp doesn't care about indentation and layout of code, nor whether you use spaces or tabs, this is an important consideration for submissions to exercism.io. Excercism.io's code widget cannot handle mixing of tab and space characters well so using only spaces is recommended to make the code more readable to the human reviewers. Please review your editors settings on how to accomplish this. Below are instructions for popular editors for Common Lisp.
Use the following commands to ensure VIM uses only spaces for indentation:
:set tabstop=2 :set shiftwidth=2 :set expandtab
(or as a oneliner
:set tabstop=2 shiftwidth=2 expandtab). This can
be added to your
~/.vimrc file to use it all the time.
Emacs is very well suited for editing Common Lisp and has many powerful add-on packages available. The only thing that one needs to do with a stock emacs to make it work well with exercism.io is to evaluate the following code:
(setq-default indent-tabs-mode nil)
This can be placed in your
order to have it set whenever Emacs is launched.
One suggested add-on for Emacs and Common Lisp is SLIME which offers tight integration with the REPL; making iterative coding and testing very easy.
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
(ql:quickload "lisp-unit") #-xlisp-test (load "rna-transcription") (defpackage :rna-transcription-test (:use #:common-lisp #:lisp-unit)) (in-package #:rna-transcription-test) (define-test transcribes-cytidine-to-guanosine (assert-equal "G" (rna-transcription:to-rna "C"))) (define-test transcribes-guanosine-to-cytidine (assert-equal "C" (rna-transcription:to-rna "G"))) (define-test transcribes-adenosine-to-uracile (assert-equal "U" (rna-transcription:to-rna "A"))) (define-test it-transcribes-thymidine-to-adenosine (assert-equal "A" (rna-transcription:to-rna "T"))) (define-test it-transcribes-all-nucleotides (assert-equal "UGCACCAGAAUU" (rna-transcription:to-rna "ACGTGGTCTTAA"))) (define-test it-validates-dna-strands (assert-error 'error (rna-transcription:to-rna "XCGFGGTDTTAA"))) #-xlisp-test (let ((*print-errors* t) (*print-failures* t)) (run-tests :all :rna-transcription-test))
(in-package #:cl-user) (defpackage #:rna-transcription (:use #:cl) (:export #:to-rna)) (in-package #:rna-transcription) (defun to-rna (str) "Transcribe a string representing DNA nucleotides to RNA." (flet ((change-char (char) (case char (#\G #\C) (#\C #\G) (#\A #\U) (#\T #\A) (t (error "not valid DNA sequence"))))) (map 'string #'change-char str)))
A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.
Here are some questions to help you reflect on this solution and learn the most from it.