def scylla_or_charybdis(moves, n): This problem was inspired by the article "A Magical Answer to the 80-Year-Old Puzzle" in Quanta Magazine. Thanks to your recent cunning stunts, your nemesis in life is trapped inside a devious game where, for a refreshing change from the usual way of things, you get to be the Final Boss. (Everyone is the hero in their own story until they become a villain in somebody else's, after all.) This final level is a one-dimensional video game platform that reaches n-1 steps from its center to both directions. At each end of this platform exactly n steps away from the center, your two lethal friends Scylla and Charybdis are licking their lips in anticipation of a tasty morsel. Your nemesis starts at the center of this platform. To start this deadly combat of wits, she must immediately commit to her entire sequence of future moves, given to this function as a string of characters '+' (“� just a step to the ri-i-i-i-ight � ”) and '-' (move one step to the left). Your task is to find and return a positive integer k so that executing every k:th step of moves (so this subsequence starts from position k-1 and includes every k:th element from then on) makes your nemesis fall into one of the two possible dooms n steps away from the center to each direction. If several values of k would work, return the smallest value of the possible values of k that minimizes the number of steps before the downfall. Otherwise, those freaking Tolkien eagles will once again swoop down to rescue your nemesis. She will then return in a third year analysis of algorithms course as an adversary who puts your functions through a similar wringer of wits!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Scylla or Charybdis?
def scylla_or_charybdis(moves, n):

This problem was inspired by the article "A Magical Answer to the 80-Year-Old Puzzle" in Quanta
Magazine. Thanks to your recent cunning stunts, your nemesis in life is trapped inside a devious game where, for a refreshing change from the usual way of things, you get to be the Final Boss. (Everyone is the hero in their own story until they become a villain in somebody else's, after all.)
This final level is a one-dimensional video game platform that reaches n-1 steps from its center to both directions. At each end of this platform exactly n steps away from the center, your two lethal friends Scylla and Charybdis are licking their lips in anticipation of a tasty morsel.

Your nemesis starts at the center of this platform. To start this deadly combat of wits, she must immediately commit to her entire sequence of future moves, given to this function as a string of characters '+' (“� just a step to the ri-i-i-i-ight � ”) and '-' (move one step to the left). Your
task is to find and return a positive integer k so that executing every k:th step of moves (so this subsequence starts from position k-1 and includes every k:th element from then on) makes your nemesis fall into one of the two possible dooms n steps away from the center to each direction.

If several values of k would work, return the smallest value of the possible values of k that minimizes the number of steps before the downfall. Otherwise, those freaking Tolkien eagles will once again swoop down to rescue your nemesis. She will then return in a third year analysis of
algorithms course as an adversary who puts your functions through a similar wringer of wits!

Expected
result
moves
'-++--++-++++'
2
3
--++++---+-++
++'
5
5
+-++---+-+-++-+++-
--+++-++-+---+--+++++++++
5
7
+'
'+--++---+-++-+++
++---++-+--++
9
1
+-++-++-+-++++-
++'
Transcribed Image Text:Expected result moves '-++--++-++++' 2 3 --++++---+-++ ++' 5 5 +-++---+-+-++-+++- --+++-++-+---+--+++++++++ 5 7 +' '+--++---+-++-+++ ++---++-+--++ 9 1 +-++-++-+-++++- ++'
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education