Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def test(b:int) -> int:
- """
- `//` does "floor division", meaning it performs the division and then
- does a true floor operation - unlike C and Python2 which do "integer"
- division that merely truncates the remainder.
- """
- return (b + 16383) // 16384
- def foo(b:int) -> int:
- """
- Nothing to explain here, just the second of your three expressions.
- """
- return ( (b - 1) // 16384) + 1
- def quest(b:int) -> int:
- """
- "An upside-down ceiling is a floor" is the advice that led me to this;
- in Python3 `-(-x//y)` is ceil(x/y) because of the aforementioned
- "floor division" that will result in e.g. `-1//2` = `-1` and then a
- correcting inversion gives `-(-1//2) = -(-1) = 1 == ceil(1/2)`.
- """
- return -(-b // 16384)
- # this checks for any differences in the outputs by testing with each integer
- # on the interval from 0 (inclusive) to 163840 (exclusive), because
- # `NOT(x = y) or NOT(x = z)` is equivalent to `NOT( x = y AND x = z)` which by
- # transitive property covers all cases where any one output is different.
- for i in range(163840):
- if test(i) != quest(i) or test(i) != foo(i):
- print("i=", i, " test(i)=", test(i), " quest(i)=", quest(i), " foo(i)=", foo(i), sep='')
- break
- # At this point, nothing is output, meaning the entire loop was executed without
- # finding any differing outputs.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement