Advertisement
Geometrian

Hash Search

Sep 4th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. #https://codegolf.stackexchange.com/questions/171168/without-using-numbers-get-the-highest-salary-you-can-but-dont-exaggerate
  2.  
  3. #Code takes one of the forms:
  4. #   "$%d"%hash(    <string>    )
  5. #   "$%d"%-hash(    <string>    )
  6. #   "$%d"%~hash(    <string>    )
  7. #Test strings by:
  8. #   print("\"%s\""%(bytearray(    <counters>    ).decode("utf-8")))
  9.  
  10. best = []
  11. maxs = []
  12. for i in range(64):
  13.     best.append(0)
  14.     if i==0: maxs.append("error")
  15.     else:    maxs.append(int( 1000000.0*(i**-0.75) ))
  16.  
  17. counters = [0]
  18. while True:
  19.     try:
  20.         s = bytearray(counters).decode("utf-8")
  21.         length1 = 14 + len(counters)
  22.         length2 = length1 + 1
  23.         length3 = length2
  24.         h1 = hash(s)
  25.         h2 = -h1
  26.         h3 = ~h1
  27.         if h1 > best[length1] and h1 <= maxs[length1]:
  28.             print(("Best (%6d/%d=%f) for length %d by "%( h1,maxs[length1],float(h1)/float(maxs[length1]), length1 ))+str(counters)+" (type 1)")
  29.             best[length1] = h1
  30.         if h2 > best[length2] and h2 <= maxs[length2]:
  31.             print(("Best (%6d/%d=%f) for length %d by "%( h2,maxs[length2],float(h2)/float(maxs[length2]), length2 ))+str(counters)+" (type 2)")
  32.             best[length2] = h2
  33.         if h3 > best[length3] and h3 <= maxs[length3]:
  34.             print(("Best (%6d/%d=%f) for length %d by "%( h3,maxs[length3],float(h3)/float(maxs[length3]), length3 ))+str(counters)+" (type 3)")
  35.             best[length3] = h3
  36.     except UnicodeDecodeError:
  37.         pass
  38.  
  39.     i = 0
  40.     while True:
  41.         counters[i] += 1
  42.         if counters[i]==256:
  43.             counters[i] = 0
  44.             i += 1
  45.             if i == len(counters):
  46.                 counters.append(0)
  47.                 break
  48.         else:
  49.             break
  50.  
  51. #"$%d"%hash("")
  52. #"$%d"%hash("ɒ&")
  53. #f"${hash("ɒ&")}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement