#!/usr/bin/env python
# I, Danny Milosavljevic, hereby place this file into the public domain

import math

def memoize(f, argSimplifier = lambda arg: arg):
    knownResults = {}
    def g(arg):
        arg = argSimplifier(arg)
        if arg in knownResults:
            return(knownResults.get(arg))
        result = f(arg)
        knownResults[arg] = result
        #print("new"),arg
        return(result)
    return(g)

if __name__ == "__main__":
    cos = memoize(math.cos, lambda arg: arg % (2.0 * math.pi))
    i = 0.0
    while i < 10 * math.pi:
      print(cos(i))
      i += math.pi/2.0
