-
-
Notifications
You must be signed in to change notification settings - Fork 525
armstrong-numbers: port #988
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
I intend to make a test generator for this. It has been awhile since I have done so. I should have some work up for that later tonight or tomorrow. |
At first I thought I would add integer delimiting into the generator. Then I was sad when I realized that converting them back into integers destroys the formatting. Then I felt silly when I realized that the generator needs it in a string 🤣 |
exercises/armstrong-numbers/.meta/generator/armstrong_numbers_case.rb
Outdated
Show resolved
Hide resolved
Okay, I think I am finished messing with this. 😄 |
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.
Hi @guygastineau Thanks for bringing the exercise back to live :-)
config.json
Outdated
"slug": "armstrong-numbers", | ||
"uuid": "77c5c7e6-265a-4f1a-9bc4-851f8f825420", | ||
"core": false, | ||
"unlocked_by": "isogram", |
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.
@guygastineau I didn't realize before that Isogram has moved since the last time we discussed adding this exercise. Let's make it
"unlocked_by": "isogram", | |
"unlocked_by": "series", |
Sorry that I missed this.
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.
Note to self: without the lambda, it could be a level 1 side exercise. Then, it may need a more step by step help in the readme.
(This doesn't need to be addressed in this PR, unless you'd prefer to do so, Guy. )
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.
Great, I figured there might need to be some changes to it in the config.json
.
I'm on it 😃
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 mean, I will change it to unlock from series
I don't especially feel like writing step-by-step instructions for closures in a lvl 1 exercise readme extension.
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.
changed
def self.include?(number) | ||
raise_to_length = ->(n) { n ** number.digits.size } | ||
number.digits.sum(&raise_to_length) == number | ||
end |
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.
:-)
Since the solution file is sometimes consulted by (new) mentors and students, and to avoid miscommunications in general, I'd prefer to have a solution that is in sync with the solution that we strive for.
That's mostly a matter of opinion, I don't think we have a policy for this.
And I'm slightly confused too. ;-) Does this mean that you think the original solution is not good enough? Or?
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.
Oh, I just really wanted to use stabby lambda for the hell of it, and the guide for porting exercises on this track says the solution doesn't need to be ideal (although I think this one is fun 😃)
I have no problem reverting it. That is a simple fix 😃
(I think that porting guide was written before the profound track anatomy project happened, so wanting example solutions that fit the level of the exercise is a reasonable desire given all that you all have done to polish this track 😃)
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.
Reverted.
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.
The example solution is a proof of concept, and if it is not "normal" this means that we will likely spot it quickly, if for some reason it comes to be a solution submitted by a student. So there are some advantages to having a non ideal solution, as long as it "proves the concept".
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.
On the other hand, since this isn't example.rb
it may be being presented in the note as an acceptable solution... one to approve. In that situation, the story changes.
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.
Oh, I just really wanted to use stabby lambda for the hell of it
Yeah, you mentioned the lambda fun somewhere else, so that's what I thought it was 🤓 .
FYI:
My thinking is: The beauty of this exercise to me is that it does 'light math', that can be solved with 'early' Ruby methods without being scary mathy. And then it can be refactored to use digits.sum
.
For other purposes, this exercise would need more 'progressions' in other aspects, to make the learning curve between exercises steep enough on the higher levels.
Thanks for reverting :-)
Also, I noticed that you all have a very explicit merge history here. I am very impressed 😍 This PR has a load of commits, so I would be more than happy to rebase it into just a couple commits. Anyway, this is just an idea to keep both contributors in the history without having a 20 commit merge for this simple exercise. Let me know what you all would prefer, and if I should do anything about it 😄 |
def self.include?(number) | ||
exponent = number.digits.size | ||
|
||
number.digits.sum { |digit| digit ** exponent } == 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.
Don't use spaces around **
as it emulates how we expect to see it (similar to xy, very close together), and makes it clear it isn't a typographical error due to style showing intent.
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'll change it, but I strongly disagree. I think operators should always have spaces in languages where it is possible, but I would not consider myself a real rubyist yet (, so I defer to your opinion).
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.
done
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 case it's a comfort: no spaces around exponents is recommended by one of the Ruby Styleguides. Not saying I like it, but I settle for consistency :-)
https://rubystyle.guide/#spaces-operators
def self.include?(number) | ||
raise_to_length = ->(n) { n ** number.digits.size } | ||
number.digits.sum(&raise_to_length) == number | ||
end |
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.
The example solution is a proof of concept, and if it is not "normal" this means that we will likely spot it quickly, if for some reason it comes to be a solution submitted by a student. So there are some advantages to having a non ideal solution, as long as it "proves the concept".
def self.include?(number) | ||
raise_to_length = ->(n) { n ** number.digits.size } | ||
number.digits.sum(&raise_to_length) == number | ||
end |
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.
On the other hand, since this isn't example.rb
it may be being presented in the note as an acceptable solution... one to approve. In that situation, the story changes.
exercises/armstrong-numbers/.meta/generator/armstrong_numbers_case.rb
Outdated
Show resolved
Hide resolved
So, which solution do you all want? |
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.
Good work! Added a couple comments on ways I think we can simplify the generator 👍
This PR has a load of commits, so I would be more than happy to rebase it into just a couple commits.
Thank you - this is appreciated! Squashing this to two commits as you are suggesting sounds great to me.
exercises/armstrong-numbers/.meta/generator/armstrong_numbers_case.rb
Outdated
Show resolved
Hide resolved
exercises/armstrong-numbers/.meta/generator/armstrong_numbers_case.rb
Outdated
Show resolved
Hide resolved
Thanks for all the pointers everybody 😄 I will wait to squash into two commits until the work is approved (so I don't have to do it twice). |
Thanks @kotp I'll rebase this after dinner. |
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.
Thank you!
- not using Integer.digits as that is only available on Ruby 2.4
- fix conflicts - implement generator
23f9242
to
fe88c70
Compare
I suppose I could have done some squashes mixed in with the fixups, but at least both contributors are represented in the history (which was my main goal here). |
It's ready for you all now. Thanks for working with me on this ;) Are there any exercises that need generators? I think there used to be a file or an issue somewhere showing which ones needed a generator implemented. I'm happy to hunt them down and make them ;) |
I have rebased the last ten commits of @Tuxified's work from #893 onto the current master.
canonical-data.json