Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the below function that takes a string and applies the following rules repetitively until there is one character left and returns that character: -

Write the below function that takes a string and applies the following rules repetitively until there is one character left and returns that character:

- If the first two characters are "aa" then they are replaced by "b" - If the first two characters are "ba" then they are replaced by "c" - If the first two characters are "ab" then they are replaced by "c" - If the first two characters are "bb" then they are replaced by "a" - If the first character is "c", then it is replaced by the second character. However, if the second character is also "c" then the first "c" is removed. - For everything else, the first character is removed.

The input string contains only the letters "a", "b" and "c".

For example, the string "aabc" goes through the following transformations: "aabc" -> "bbc" -> "ac" -> "c"

Similarly, the string "bacbc" becomes "bacbc" -> "ccbc" -> "cbc" -> "bbc" -> "ac" -> "c"

NOTE: If you solve this question in a recursive fashion, you get 10 points bonus! The bonus will be applied if and only if you pass all the other tests.

"""

def shorten(s): return # Remove this line if you want to answer this question.

(ptyhon)

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

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

Find P ( 1 Answered: 1 week ago

Answered: 1 week ago