Advertisement
07734willy

Optimization-PiecewiseNumberGenerator

Jul 13th, 2020
1,858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. A = 10394130495970210037
  2. B = 4290410973
  3. M = 2 ** 64
  4. S = 128
  5.  
  6. def compute(text):
  7.     value = B
  8.     for letter in text:
  9.         if letter == "L":
  10.             value = (value * A + B) % M
  11.         elif letter == "Q":
  12.             value = (value ** 2) % M
  13.     return value
  14.  
  15. def score_input(text):
  16.     if len(text) != S:
  17.         return "INVALID"
  18.  
  19.     if any(c not in "LQ" for c in text):
  20.         return "INVALID"
  21.    
  22.     value = compute(text)
  23.  
  24.     # just shrinks values to expand the "interesting"
  25.     # range of scores, relative to the entire spectrum
  26.     score = (256 - (M-value)**0.125) * 50
  27.     return score
  28.  
  29. def main():
  30.     text = input().strip()
  31.     print(score_input(text))
  32.  
  33. if __name__ == "__main__":
  34.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement