Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Turning in mp2 #4

wants to merge 4 commits into from

Conversation

ewesterhoff
Copy link

No description provided.

@@ -0,0 +1,190 @@
"""TODO: Put your header comment here."""

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

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')

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants