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
Rosalind http://rosalind.info/problems/rna
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
;; Load SRFI-64 lightweight testing specification
(use-modules (srfi srfi-64))
;; Suppress log file output. To write logs, comment out the following line:
(module-define! (resolve-module '(srfi srfi-64)) 'test-log-to-file #f)
(add-to-load-path (dirname (current-filename)))
(use-modules (dna))
(test-begin "rna-transcription")
(test-equal "transcribes-cytosine-to-guanine"
"G"
(to-rna "C"))
(test-equal "transcribes-guanine-to-cytosine"
"C"
(to-rna "G"))
(test-equal "transcribes-adenine-to-uracil"
"U"
(to-rna "A"))
(test-equal "transcribes-thymine-to-adenine"
"A"
(to-rna "T"))
(test-equal "transcribes-all-nucleotides"
"UGCACCAGAAUU"
(to-rna "ACGTGGTCTTAA"))
(test-error "it-validates-dna-strands"
#t
(to-rna "XCGFGGTDTTAA"))
(test-end "rna-transcription")
(define-module (dna)
#:export (to-rna))
(define (dna-to-rna dna)
(cond
((char=? dna #\G) #\C)
((char=? dna #\C) #\G)
((char=? dna #\T) #\A)
((char=? dna #\A) #\U)))
(define (to-rna strand)
(list->string
(map dna-to-rna
(string->list strand))))
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.
Level up your programming skills with 3,450 exercises across 52 languages, and insightful discussion with our volunteer team of welcoming mentors. Exercism is 100% free forever.
Sign up Learn More
Community comments