Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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
+-++-++-+-++++-
++'
expand button
Transcribed Image Text:Expected result moves '-++--++-++++' 2 3 --++++---+-++ ++' 5 5 +-++---+-+-++-+++- --+++-++-+---+--+++++++++ 5 7 +' '+--++---+-++-+++ ++---++-+--++ 9 1 +-++-++-+-++++- ++'
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education