Last active
August 29, 2015 14:04
-
-
Save jarshwah/0998143317f5ccc093b3 to your computer and use it in GitHub Desktop.
goal in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def g(letters=None): | |
if letters: return 'gal' | |
goal = ['go'] | |
def o(letters=None): | |
assert letters is None or letters == 'al' | |
if letters: | |
goal.append(letters) | |
return ''.join(goal) | |
goal.append('o') | |
return o | |
return o | |
if __name__ == '__main__': | |
print(g('al')) | |
print(g()('al')) | |
print(g()()('al')) | |
print(g()()()()()('al')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
def f(times, letters=None): | |
if letters: | |
return 'g'+('o'*times)+letters | |
return partial(f, times+1) | |
g=partial(f, 0) | |
if __name__ == '__main__': | |
print(g('al')) | |
print(g()('al')) | |
print(g()()('al')) | |
print(g()()()()()('al')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment