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,...

1 answer below »


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<br>result<br>moves<br>'-++--++-++++'<br>2<br>3<br>--++++---+-++<br>++'<br>5<br>5<br>+-++---+-+-++-+++-<br>--+++-++-+---+--+++++++++<br>5<br>7<br>+'<br>'+--++---+-++-+++<br>++---++-+--++<br>9<br>1<br>+-++-++-+-++++-<br>++'<br>

Extracted text: Expected result moves '-++--++-++++' 2 3 --++++---+-++ ++' 5 5 +-++---+-+-++-+++- --+++-++-+---+--+++++++++ 5 7 +' '+--++---+-++-+++ ++---++-+--++ 9 1 +-++-++-+-++++- ++'
Answered 5 days AfterJun 10, 2022

Answer To: Scylla or Charybdis? def scylla_or_charybdis(moves, n): This problem was inspired by the article "A...

Aditi answered on Jun 16 2022
78 Votes
ASSIGNMENT
def scylla_or_charybdis(moves, n):
k = 1
numstep = set()
res = []
wh
ile k < (len(moves)/2 + 1):
count = 0
j = 0
for i in range(k-1, len(moves), k):
if moves[i] == '+':
count += 1
else:
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here