subject

Rick is a fan of logic-based games. However, he is bored of the classic ones, like Sudoku and Mastermind, since he has solved so many of them. Recently he found a new game in which one is given a string with some question marks in it. The objective is to replace all of the question marks with letters (one letter per question mark) in such a way that no letter appears next to another letter of the same kind. Write a function:
def solution(riddle)
that, given a string riddle, returns a copy of the string with all of the question marks replaced by lowercase letters (a-z) in such a way that the same letters do not occur next to each other. The result can be any of the possible answers as long as it fulfils the above requirements.
Examples:
1. Given riddle = "ab?ac?", your function might return "abcaca". Some other possible results are 'abzacd", "abfacf".
2. Given riddle = "rd?e?wg??", your function might return "rdveawgab".
3. Given riddle = "", your function might return "codility".
Write an efficient algorithm for the following assumptions:
• the length of the string is within the range [1..100,000);
• string riddle consists only of lowercases letters (a - z) or '?';
• it is always possible to turn string 'riddle' into a string without two identical consecutive letters.
1 # you can write to stdout for debugging purposes, e. g.
2 # print("this is a debug message")
3
4 def solution (riddle):
5
6 # write your code in Python 3.6
7 pass

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 10:50
The volume v and paper surface area a of a conical paper cup are given by where r is the radius of the base of the cone and h is the height of the cone. a. by eliminating h, obtain the expression for a as a function of r and v. b. create a user-de ned function that accepts r as the only argument and computes a for a given value of v. declare v to be global within the function. c. for v ! 10 in.3 , use the function with the fminbnd function to compute the value of r that minimizes the area a. what is the corresponding value of the height h? investigate the sensitivity of the solution by plotting v versus r. how much can r vary about its optimal value before the area increases 10 percent above its minimum value?
Answers: 1
question
Computers and Technology, 24.06.2019 06:00
Hey i really need some solving this problem: 1. encrypt this binary string into cipher text: 110000. include in your answer the formula the decoder would use to decrypt your cipher text in the format (coded answer) x n mod (m) = y & 2. decrypt this cipher text into a binary string: 106 you.
Answers: 2
question
Computers and Technology, 24.06.2019 11:20
Every telecommunication setup uses two devices: one device to transmit data and one device to receive data. which device transmits frequencies to mobile phones? towers transmit frequencies to mobile phones.
Answers: 1
question
Computers and Technology, 24.06.2019 21:30
What need most led to the creation of the advanced research projects agency network? darpa wanted scientists to be able to collaborate and share research easily. darpa wanted american and russian politicians to be able to communicate. darpa wanted astronauts to be able to contact nasa and the white house. darpa wanted factory owners to be able to coordinate supply chains.
Answers: 1
You know the right answer?
Rick is a fan of logic-based games. However, he is bored of the classic ones, like Sudoku and Master...
Questions
Questions on the website: 13722363