🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of jaishreedhage

jaishreedhage's solution

to RNA Transcription in the Objective-C Track

Published at Jul 13 2018 · 0 comments
Test suite

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


There are two different methods of getting set up to run the tests with Objective-C:

  • Create an Xcode project with a test target which will run the tests.
  • Use the ruby gem objc as a test runner utility.

Both are described in more detail here: http://exercism.io/languages/objective-c

Submitting Exercises

When submitting an exercise, make sure your solution file is in the same directory as the test code.

The submit command will look something like:

exercism submit <path-to-exercism-workspace>/objective-c/rna-transcription/RnaTranscription.m

You can find the Exercism workspace by running exercism debug and looking for the line beginning with Workspace.


Hyperphysics http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


#import <XCTest/XCTest.h>

#if __has_include("RNATranscriptionExample.h")
# import "RNATranscriptionExample.h"
# else
# import "RNATranscription.h"

@interface RNATranscriptionTest : XCTestCase


@implementation RNATranscriptionTest

- (void)test1 {
    XCTAssertEqualObjects(@"G", [[[RNATranscription alloc] init] rnaFromDNAStrand:@"C"]);

- (void)test2 {
    XCTAssertEqualObjects(@"C", [[[RNATranscription alloc] init] rnaFromDNAStrand:@"G"]);

- (void)test3 {
    XCTAssertEqualObjects(@"A", [[[RNATranscription alloc] init] rnaFromDNAStrand:@"T"]);

- (void)test4 {
    XCTAssertEqualObjects(@"U", [[[RNATranscription alloc] init] rnaFromDNAStrand:@"A"]);

- (void)test5 {
    XCTAssertEqualObjects(@"UGCACCAGAAUU", [[[RNATranscription alloc] init] rnaFromDNAStrand:@"ACGTGGTCTTAA"]);

- (void)test6 {
    XCTAssertEqualObjects(nil, [[[RNATranscription alloc] init] rnaFromDNAStrand:@"U"]);

- (void)test7 {
    XCTAssertEqualObjects(nil, [[[RNATranscription alloc] init] rnaFromDNAStrand:@"XXX"]);

- (void)test8 {
    XCTAssertEqualObjects(nil, [[[RNATranscription alloc] init] rnaFromDNAStrand:@"ACGTXXXCTTAA"]);



//  RNATranscription.h
//  RNATranscription
//  Created by Jaishree Dhage on 12/12/17.
//  Copyright © 2017 Jaishree Dhage. All rights reserved.

#import <Foundation/Foundation.h>

@interface RNATranscription : NSObject

-(NSString *)rnaFromDNAStrand:(NSString *) dnaStrand;



//  RNATranscription.m
//  RNATranscription
//  Created by Jaishree Dhage on 12/12/17.
//  Copyright © 2017 Jaishree Dhage. All rights reserved.

#import "RNATranscription.h"

@implementation RNATranscription

-(NSString *)rnaFromDNAStrand:(NSString *)dnaStrand{
    NSMutableString *rna = [NSMutableString string];
    for(int i=0;i<dnaStrand.length;i++){
        unichar c = [dnaStrand characterAtIndex:i];
           [rna appendString:@"C"];
        else if(c=='C')
            [rna appendString:@"G"];
        else if(c=='A')
            [rna appendString:@"U"];
        else if(c=='T')
            [rna appendString:@"A"];
            return nil;
    return rna;


Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

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.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?