-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turning in mp2 #4
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,190 @@ | |||
"""TODO: Put your header comment here.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:P
if min_depth < 1: | ||
var = random.randint(1,2) | ||
if var == 1: | ||
return lambda x,y: x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your implementations of lambda functions are correct/functional, but you aren't quite realizing some of the benefits of lambda-izing - for example, lambda-izing functions allows you to choose/pass around functions instead of specifically checking things like rand_int values.
That being said, I do quite like how you've used them to make build_random_function also build the evaluation path - that's quite elegant, in my opinion! All in all, solidly done.
inner = build_random_function(min_depth, max_depth) | ||
return lambda x,y: math.sin(30 * math.pi * inner(x,y)) | ||
|
||
print('error') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out https://docs.python.org/3/tutorial/errors.html#raising-exceptions - you can also raise errors, rather than printing and then returning nothing. Essentially, you can make a custom error if you want that degree of control over the program.
(Though, unless the built-in random
library broke, this error should never appear - rand_int should always give you one of those values, so you should be fine either way.)
No description provided.