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?
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...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item...
Code Example 8-1 1. int count = 1; 2. int item_total = 0; 3. int item = 0; 4. while (count < 4) { 5.      cout << "Enter item cost: "; 6.      cin >> item; 7.      item_total += item; 8.      ++count; 9. } 10. int average_cost = round(item_total / count); 11. cout << "Total cost: " << item_total << "\nAverage cost: " << average_cost; (Refer to Code Example 8-1.) If the user enters 5, 10, and 15 at the prompts, the output is: Total...
The language of code in C#. Finds the number of times a word occurs by itself...
The language of code in C#. Finds the number of times a word occurs by itself (as a complete word) or as part of another word in the given "wordFragment" substring. For example in the string "The bon in bonbon", we count 2 occurrences of bon. Please write a simple code without the use of advanced features such as LINQ. It's recommended using the Dictionary feature. Returns the number of times wordFragment occurs in the file that WordCounter is associated...