Python Forum
Need help with this coding puzzle - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Need help with this coding puzzle (/thread-11089.html)



Need help with this coding puzzle - torchtopher - Jun-21-2018

# Here is the problem (and the solution is supposedly hidden in the Python code!)

# Your friend has recommended that you go eat at this restaurant, insisting that they have amazing pasta. When you arrive, you realize that it's not # just amazing...it's arguably the best in the world.

# The problem? Well...it's so commonly requested that they've had to implement a security measure to prevent everyone from ordering it. Looks like
# this is going to be more complicated than you hoped. To actually eat the pasta, you're going to have to figure out what the secret password is.

# After several minutes, your server comes up to you. Your stomach growls. Better figure that password out quickly!

# Ravioli ravioli, what is the formuoli
# Finalized 6/13/18

"""
you may or may not need this
http://www.ssec.wisc.edu/~tomw/java/unicode.html
"""
spaghetti = 0
warming = int(bin(4)[2:])

def roast(nut):
  try:
    herring = str(nut)[1]
    cracker = int(str(nut)[:2])
    barrel = int(str(nut)[0])
    for beef in range(barrel, cracker):
      nut -= cracker
    return nut == cracker
  except:
    herring = "red"
    return False

def boil(fish):
  salmon = [0]*2 + [1] * (fish - 1)
  gill = 2
  while gill ** 2 <= fish:
    if salmon[gill] == 1:
      for fin in range(2, fish//gill + 1):
        salmon[gill*fin] = 0
    gill += 1
  filet = 0
  for cod in range(fish):
    if salmon[cod] == 1:
      filet += cod
  return roast(filet)
  
def salt(crystal): #Spagetii 0
  global warming, spaghetti
  spaghetti = 1 if (crystal/warming != crystal // warming) else crystal // warming
  
def served():
  global spaghetti,warming
  spaghetti = 0
  print("The waiter asks, 'What's the secret code?'")
  while True:
    try:
      pasta = ord(input("You reply: "))
      salt(pasta)
      print(salt)
      if boil(spaghetti):
        
        break
      
      else:
        print(salt)
        print("\nThe waiter is confused.")
        print("'I'm afraid that is not the correct code.'")
        print("You're incredibly hungry, but you don't want to miss out on the opportunity for some incredible pasta.")
        print("Fortunately, the waiter seems to be inviting you to try again, so...")
        
    except:
      print(salt)
      print("\nThe waiter frowns and shakes their head.")
      print("'Sorry, that's not a valid code.  Try again.'")
      print("Whoops! After apologizing...")
      continue
  print("\nThe waiter smiles and nods.")
  print("'We'll have your pasta out right away!'")
  print("Nice! You can finally eat. While you're waiting though, you should probably input your solution into the field below.")

if __name__ == '__main__':
  served()



RE: Need help with this coding puzzle - buran - Jun-22-2018

You need to reverse-engineer the correct password. Going trough the code you will understand what it does and how it checks that password is correct