[ create a new paste ] login | about

Link: http://codepad.org/Eo00RNEJ    [ raw code | fork ]

Python, pasted on May 4:
def normal_modulo(a, b):
    return a % b

def listify(x):
    if x == 0:
        return [0]
    result = []
    while x > 0:
        result.append(x % 256)
        x = x // 256
    return reversed(result)

def fancy_modulo(a, b):
    a_list = listify(a)
    result = 0
    for digit in a_list:
        result *= (256 % b)
        result %= b
        result += (digit % b)
        result %= b
    return result

if __name__ == "__main__":
    from random import randint
    while True:
        (p, q) = (randint(0, 100000), randint(1, 255))
        if fancy_modulo(p, q) != normal_modulo(p, q):
            print(p, q)
            break


Create a new paste based on this one


Comments: