-
-
Notifications
You must be signed in to change notification settings - Fork 525
Add Armstrong Numbers exercise #893
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
- not using Integer.digits as that is only available on Ruby 2.4
complying with name convention
Great. thanks! |
exercises/armstrong-numbers/.meta/solutions/armstrong_numbers.rb
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,10 @@ | |||
class ArmstrongNumbers | |||
def self.is_valid?(number) |
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.
in Ruby I try not to use 'is_' prefixes. See: https://github.com/rubocop-hq/ruby-style-guide#bool-methods-prefix
What about: def self.armstrong?
(The name used in the tests will also need updating.)
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 like self.valid?
better than self.armstrong?
, although it's not really about validity, is it? I can't think of a better name though. 🤔
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.
In response to this comment I heavily considered suggesting is?
because I thought it would be slightly amusing... but ArmstrongNumbers.is?(10)
actually works in the opposite direction compared to is_a?
so it would be unconventional.
If using include?
, then ArmstrongNumbers.include?(10)
does read naturally, but I think it would be surprising because it hints that you can use other Enumerable methods on ArmstrongNumbers (because include?
is on Enumerable) but you cannot.
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 really like include?
👍
It would be possible to implement this in a way that you could use Enumerable
if you wanted to.
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.
include?
sounds nice, but I wonder how you'd like to implement it to use Enumerable? Even if we choose to do this using Enumerable I wonder (and if) students would use other methods from Enumerable? Perhaps we can settle on a better name / other implementation? I saw the Python example defines just one function: def armstrong_number?(number)
?
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.
Including Enumerable
is not really relevant to this PR but is something that could be interesting to explore as part of a solution.
Looks good, I have noted a couple of things that need to be looked at. But it's overall a suitable implementation. |
What I like most is that it's an math exercise that doesn't ask to reimplement an existing Ruby method 👍 I feel using I don't think we should avoid Ruby 2.4 at all. It's an easy exercise regarding the math, but the Enumerable makes it more of a level unlocked by Isogram. Note
Thoughts? |
I really agree with your logic here. However the convention is that the class name always matches the exercise slug, so the See also: #854 |
|
Hey @Tuxified What's the status? |
and switch to Ruby 2.4 in the process
Apologies it took too long to respond, wasn't my intention to neglect your efforts. I've updated to include your comments, however I'm still unsure about the name of method and/or implementing it as an Enumerable. Are you adamant on the Enumerable implementation or are you open for a different method name? [edit] |
Hey Toni, thanks for the next round! Looks to me that there's some confusion in the Enumerable discussion.
Concluding:
I'm okay of any of those, and I'd say let's just 'vote' for our preferences and let Tony decide. @Insti will be better at assessing the tests thing. All I know: there are exercises that use Ruby 2.4 and they work. I didn't look into that. |
The tests and solution need to work with Ruby 2.1.2 so you'll need to either "downgrade" the code or write a "polyfill" to support the new syntax. Or create a new issue/PR to upgrade the minimum version of ruby we support. |
@Tuxified |
Is this abandoned? I am willing to take over implementation of this exercise. @Tuxified I don't want to step on your toes... If you aren't interested in finishing this I could build off of your work, so that you are still listed in the git history. |
Hi Guy, No problem, I lost track of this PR, so if you're willing to pick it up, plz do. No need to keep this PR BTW, I don't care that much about keeping git history :P |
Cool. I'm on it. |
Closing this, as #988 is a better choice :P |
canonical-data
As this is my first stab at a Ruby exercise I didn't use the test generator, hope that's ok.
The solution is not using Integer.digits as that is available on Ruby 2.4, not previous ones.
Let me know what you think :)
TODO:
As for the config .json metadata, difficulty 1 or 2, categories: integers, loops ?