codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
def g(f, y, all_legal_inputs_to_f): "returns x for y = f(x)" for x in all_legal_inputs_to_f: if y == f(x): return x raise "y is not an output of f(x)" def f(x): if x >= 11 or x < 0: raise "invalid input" return (x*3 + 5) % 11 valid_inputs = range(11) for x in valid_inputs: fx = f(x); gfx = g(f, fx, valid_inputs) print "f(%s) = %s; g(%s) = %s" % (x, fx, fx, gfx)
Private
[
?
]
Run code
Submit