Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this Cloud9 Ruby programming project. Part A: Palindromes A palindrome is a word or phrase that reads the same forwards as

Please help me with this Cloud9 Ruby programming project.

Part A: Palindromes

A palindrome is a word or phrase that reads the same forwards as backwards, ignoring case, punctuation, and nonword characters. (A "nonword character" is defined for our purposes as "a character that Ruby regular expressions would treat as a nonword character".)

You will write a method palindrome? that returns true iff its receiver is a palindrome.

As you can see in the template fun_with_strings.rb, we arrange to mix your method into the String class so it can be called like this:

"redivider".palindrome? # => should return true "adam".palindrome? # => should return false or nil 

Your solution shouldn't use loops or iteration of any kind. Instead, you will find regular-expression syntax very useful; it's reviewed briefly in the book, and the Rubular website lets you try out Ruby regular expressions "live". Some methods that you might find useful (which you'll have to look up in the Ruby documentation) include String#downcase, String#gsub, and String#reverse.

Part B: Word Count

Define a function count_words that, given an input string, return a hash whose keys are words in the string and whose values are the number of times each word appears:

"To be or not to be" # => {"to"=>2, "be"=>2, "or"=>1, "not"=>1} 

Your solution shouldn't use for-loops, but iterators like each are permitted. As before, nonwords and case should be ignored. A word is defined as a string of characters between word boundaries.

Part C: Anagrams

An anagram group is a group of words such that any one can be converted into any other just by rearranging the letters. For example, "rats", "tars" and "star" are an anagram group.

Given a space separated list of words in a single string, write a method that groups them into anagram groups and returns a nested array of those groups (an array of arrays). Case doesn't matter in classifying string as anagrams (but case should be preserved in the output), and the order of the anagrams in the groups doesn't matter.

module FunWithStrings
def palindrome?
# your code here
end
def count_words
# your code here
end
def anagram_groups
# your code here
end
end
# make all the above functions available as instance methods on Strings:
class String
include FunWithStrings
end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago