Question

ruby code to count how many letter occurrences there are in a string. Example dna1 =...

ruby code to count how many letter occurrences there are in a string.

Example

dna1 = ('ATTGCC')

output: {"A"=>1, "T"=>2, "G"=>1, "C"=>2}

Homework Answers

Answer #1

Answer-

Your code is here-

  • dna1 = ('ATTGCC')
  • W= dna1.count('A') //letter occurrences count function
  • X= dna1.count('T')
  • Y= dna1.count('G')
  • Z= dna1.count('C')
  • puts "{"+ "'A'=>" + "#{W}"+ "," + "'T'=>" + "#{X}" + "," +"'G'=>" + "#{Y}" +"," + "'C'=>" + "#{Z}" + "}"

screenshot of output-

Note- Please do upvote, if any problem then comment in box sure I will help.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
#include <stdio.h> /* Returns the number of occurrences of string t in s * * Example:...
#include <stdio.h> /* Returns the number of occurrences of string t in s * * Example: * substring_n("hello", "el") => 1 * substring_n("", "ab") => 0 * substring_n("utilities", "ti") => 2 * */ int substring_n(char *s, char *t) { return -1;
Write a ruby program to find the number of occurrences of a given word in a...
Write a ruby program to find the number of occurrences of a given word in a string. I managed to come up with this solution. class count    def words(string) words = string.downcase.split(/[\s,]+/).map {|w| remove_punctuation(w)} frequency = Hash.new(0) words.each do |word| frequency[word] += 1 end return frequency end but I need the format to be expected: [["love", 3], ["one", 1], ["the", 2], ["red", 1], ["to", 4], ["light", 1] , ["green", 1], ["leads", 3],, ["all", 2], ["you", 1]] obteve: {"light" =>...
The genetic code is three-letter code. If the code were a four-letter code, how many codons...
The genetic code is three-letter code. If the code were a four-letter code, how many codons would exist in the genetic code? The answer should be 256, please explain. Will give a thumbs up.
perform the following using Ruby language A DNA strand is represented by a string of the...
perform the following using Ruby language A DNA strand is represented by a string of the characters A, C, G, and T, each of which represents a nucleotide. Each nucleotide has its complement as indicated by this Ruby hash: NUCLEOTIDE_COMPLEMENT = { 'A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C' } The reverse-complement of a DNA string is a new string in which each nucleotide is replaced by its complement and the string is reversed. Reverse-complements...
How many 55​-letter code words can be formed from the letters U, G, S, E, A...
How many 55​-letter code words can be formed from the letters U, G, S, E, A if no letter is​ repeated? If letters can be​ repeated? If adjacent letters must be​ different?
Modify your mapper to count the number of occurrences of each character (including punctuation marks) in...
Modify your mapper to count the number of occurrences of each character (including punctuation marks) in the file. #!/usr/bin/env python #the above just indicates to use python to intepret this file #This mapper code will input a line of text and output <word, 1> # import sys sys.path.append('.') for line in sys.stdin: line = line.strip() #trim spaces from beginning and end keys = line.split() #split line by space for key in keys: value = 1 print ("%s\t%d" % (key,value)) #for...
Given a binary string of zeros (0) and ones (1). You have to build a circuit...
Given a binary string of zeros (0) and ones (1). You have to build a circuit that counts the number of occurrences of string '01' within the given string. For example, given string '01000110001001', there are 4 occurrences of '01' and output have to show number of occurance each time '01' occured. Use a FSM and a counter (built from D flip-flops) to implement this circuit. It is guaranteed that the number of occurrences is not more than 31 (you...
Given a binary string of zeros (0) and ones (1). You have to build a circuit...
Given a binary string of zeros (0) and ones (1). You have to build a circuit that counts the number of occurrences of string '01' within the given string. For example, given string '01000110001001', there are 4 occurrences of '01' and output have to show number of occurance each time '01' occured. Use a FSM and a counter (built from D flip-flops) to implement this circuit. It is guaranteed that the number of occurrences is not more than 31 (you...
Given a binary string of zeros (0) and ones (1). You have to build a circuit...
Given a binary string of zeros (0) and ones (1). You have to build a circuit that counts the number of occurrences of string '01' within the given string. For example, given string '01000110001001', there are 4 occurrences of '01' and output have to show number of occurance each time '01' occured. Use a FSM and a counter (built from D flip-flops) to implement this circuit. It is guaranteed that the number of occurrences is not more than 31 (you...
This is a code. In words how can I describe this? This is the code. Private...
This is a code. In words how can I describe this? This is the code. Private Sub btnDisplay_Click(...) Handles btnDisplay.Click Dim word As String = "courage" Dim letter As String = "" Dim numVowels As Integer = 0 For i As Integer = 0 To (word.Length − 1) letter = word.Substring(i, 1) If IsVowel(letter) Then numVowels += 1 End If Next txtBox.Text = CStr(numVowels) End Sub Function IsVowel(letter As String) As Boolean letter = letter.ToUpper If (letter = "A") Or...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT