-
-
Notifications
You must be signed in to change notification settings - Fork 420
feat: Added implementation for ugly numbers #146
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
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.
Could you add comments to the code?
I'm also not sure whether this should necessarily be a function giving you only the n-th number of the series. An iterator or returning the list of ugly numbers up to the n-th one might be a better design.
Okay, I'll add some comments to the code (though I thought adding the bits above the file was enough but I can add some more if required)
But the accompanying implementations in python, java and dart (though dart implementation also made a function isUgly) on the website do the same thing of returning the Nth ugly number, which is why I decided to code it in this way. |
I think you should choose the best design for this implementation, not mirror the poor design decisions of the other implementations. If I want the first ten ugly numbers, an iterator is much preferable over such a "getter". |
@appgurueu I would argue that getting the |
This algorithm generates a "stream" of numbers, since it needs the previous numbers to calculate the next ones. I think it is only reasonable to use an array or a generator to map this to code. The array may be wasteful though if only, say, the last number is needed, so I think a generator is better. Getting the n-th number from an array is easy; getting it from the generator would be slightly more work, but is pretty standard, at least in non-javascript spheres (Rust's iterators have an
This is fine from a pure "design"/"correctness" perspective, but it makes an otherwise linear time operation quadratic time. |
Sorry for the long hiatus (for personal reasons), I'm finally back. |
I've made the required changes (I'm not sure on whether the writing of the tests was optimal however, since I don't know how exactly I'm supposed to write tests for generators) |
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.
I don't know how exactly I'm supposed to write tests for generators
I rewrote your test to just generate the first 11 numbers and compare them against the expected numbers.
(The failing CI is due to something unrelated.)
That looks a lot cleaner than what I did, thanks!
Ah, understood. Thanks for the clarification! 😄 |
This pull request aims to add the implementation for Ugly Numbers. Lmk if there is any issue in this pull request