Uh oh!
There was an error while loading. Please reload this page.
Remove duplicate implementation of Collatz sequence - #8836
Conversation
cclauss
left a comment
There was a problem hiding this comment.
Looking cool! Do these changes effect performance?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
tianyizheng02
commented
Jun 26, 2023
@cclauss I don't think performance is really affected in most cases since the algorithm itself is basically unchanged. However, I think there'd be slightly better performance if one were to iterate over the algorithm's output: fornumincollatz_sequence(n): # do something with numsince having a generator means not needing to create and store the entire sequence in memory. However, I haven't timed this generator implementation against the original list implementation, so I don't know how much of a difference it makes. |
Describe your change:
Fixes#8061
maths/3n_plus_1.pyin favor ofmaths/collatz_sequence.pybecause the latter is the more well-known name for the problemmaths/3n_plus_1.pytomaths/collatz_sequence.pycollatz_sequencefunction to a generator to save memoryChecklist: