Snippet

rosalind/revc.rb
Code:
# Rosalind Problem REVC: Complementing a Strand of DNA

# https://rosalind.info/problems/revc/

require_relative './helpers.rb'

dataset = get_dataset(problem: 'REVC')[0]

def solve(dataset)
    complements = { 'A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C', }
    dataset.chars.map { |x| complements[x] }.join.reverse
end

puts solve('AAAACCCGGT')
puts solve(dataset)
Output:
ACCGGGTTTT
CCAGATAGTGATCTGCTCATGAACTATAATGCGAATGTCGCACTTTTCGGAAGCAGAATGCGGGCGGTAAGACGTCAACATTCAGGCGAATAAGCTCTGGTCAGGGGTCGGGATGGATACAACGAGCGCAACTCGACAATATGGTCACATCCTCCTCGTAAGGATGCAAATTGACAAGTGAAGCAGATCAGATGTCCGTGACAGCGGTGTGCCCTTCATATCTTTGCTAATAGTGAATGCTTCCACGTGTATACCACTTCTTAACAAAAACACCCTATTCGTAGGGGCAGACGGCGCCGTTTGAAGCTTCAACCAAGAGAATACGGGCCTTACCGCTAACCCCGGATACTTTACAAATCTGGATTAAATTGGTACTGGTCAGTTCGACGGAGGACCAGGGTACTGAGTCTTGAAATGTGGCCGCAAGTGCGTTACATTGCCCGCACGTCGACCTCCCTCCACTGGATCGGTGATTGTCTAGATCACCCTAAAACTCCGGTATATTATCACCCGTTCCTGGTTAGTATTCCATTCCAAGTTCACATACTTCAAATGCTAAGTCTACTCACTTACTGATAATTTAGGTCGACCGTTAGTGTTGGCACATAGACTAAAGCTCTAGTATCGGTATGCGATAACCGGGGCTTTGAGTATCATAGAACAAGAAGCATAAACTGACGAAACTTATAATGAAGTTAAATAAGAGTCGTCTAGCGTCAGACTTATCTTGAGAAAACGGCGCTTTAAACGTTAATGTGAGTGTTATCTTTGATGGCCGCTCCACGCAAGGAGTCCTATTAGTAACGAAACACGGGATGGTGCAAGCTCCGGCTTCAAGAAGTGTTGTCGCCGGTTATCATTCGGTTGCGTGGTGAGCTGCCAGGAGGACTGACAAGGAGTACAATTGTTTCGCAGGCCCCGATACGCCGTATCCACATAAGCGCAACCCGGGGCTAAAGATACAACTAGCCAATAAGCAGCTCGGCGCTGCGTGC