-
-
Notifications
You must be signed in to change notification settings - Fork 20
London | 25-SDC-July | Fatma Arslantas | Sprint 2 | Improve code with caches #76
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
London | 25-SDC-July | Fatma Arslantas | Sprint 2 | Improve code with caches #76
Conversation
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.
Better to make cache local inside ways_to_make_change(), and define
ways_to_make_change_helper() as an inner function inside ways_to_make_change().
Since that's not the purpose of this exercise, change is optional.
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.
From line 45, we know coins can only be one of the following 9 lists:
[200, 100, 50, 20, 10, 5, 2, 1]
[100, 50, 20, 10, 5, 2, 1]
[50, 20, 10, 5, 2, 1]
...
[1]
[]
We could further improve the performance if we can
- avoid repeatedly creating the same sub-lists at line 45, and
- create key as
(total, a_value_identifiying_one_of_the_sublists)instead of as(total, tuple(coins))
I don't think this exercise expects trainees to optimize the code to this level. So change is optional.
Uh oh!
There was an error while loading. Please reload this page.
Learners, PR Template
Self checklist
Changelist
I improved the performance of
fibonacciandmaking_changefunctions using caching (memoisation).memodictionary to store calculated results.cachedictionary usingtuplekeys.if len(coins) == 1) to solve the problem with math instead of looping.Questions
I don’t have any questions, thank you!