Advertisement
Guest User

My complete test

a guest
Aug 21st, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. def test(b:int) -> int:
  2.     """
  3.     `//` does "floor division", meaning it performs the division and then
  4.     does a true floor operation - unlike C and Python2 which do "integer"
  5.     division that merely truncates the remainder.
  6.     """
  7.     return (b + 16383) // 16384
  8.  
  9. def foo(b:int) -> int:
  10.     """
  11.     Nothing to explain here, just the second of your three expressions.
  12.     """
  13.     return ( (b - 1) // 16384) + 1
  14.  
  15. def quest(b:int) -> int:
  16.     """
  17.     "An upside-down ceiling is a floor" is the advice that led me to this;
  18.     in Python3 `-(-x//y)` is ceil(x/y) because of the aforementioned
  19.     "floor division" that will result in e.g. `-1//2` = `-1` and then a
  20.     correcting inversion gives `-(-1//2) = -(-1) = 1 == ceil(1/2)`.
  21.     """
  22.     return -(-b // 16384)
  23.  
  24.  
  25. # this checks for any differences in the outputs by testing with each integer
  26. # on the interval from 0 (inclusive) to 163840 (exclusive), because
  27. # `NOT(x = y) or NOT(x = z)` is equivalent to `NOT( x = y AND x = z)` which by
  28. # transitive property covers all cases where any one output is different.
  29. for i in range(163840):
  30.     if test(i) != quest(i) or test(i) != foo(i):
  31.             print("i=", i, " test(i)=", test(i), " quest(i)=", quest(i), " foo(i)=", foo(i), sep='')
  32.             break
  33.  
  34. # At this point, nothing is output, meaning the entire loop was executed without
  35. # finding any differing outputs.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement