-
-
Notifications
You must be signed in to change notification settings - Fork 556
armstrong-numbers: new exercise #1018
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
armstrong-numbers: new exercise #1018
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.
Generally speaking, this looks good; thanks for your work contributing this! However, there are a few areas which I feel can be improved, noted below:
"expected": true | ||
}, | ||
{ | ||
"description": "10 is not an Armstrong number in base 8", |
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.
Isn't this a duplicate of L135?
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.
Removed, Thank you
An [Armstrong number](https://en.wikipedia.org/wiki/Narcissistic_number) is a number that is the sum of its own digits each raised to the power of the number of digits. | ||
It also depends on the base of the number being used (for example base = 10 for the decimal system or base = 2 for the binary system). | ||
|
||
For example:<sup></sup> |
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.
While HTML is valid Markdown, we're also aiming to keep these files readable without rendering. As such, let's get rid of empty tags.
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 removed the empty tag. Do you want no html at all in the description-Markdown then?
It also depends on the base of the number being used (for example base = 10 for the decimal system or base = 2 for the binary system). | ||
|
||
For example:<sup></sup> | ||
153<sub>10</sub> is an armstrong number in base 10, because: 153<sub>10</sub> = 1<sup>3</sup> + 5<sup>3</sup> + 3<sup>3</sup> = 1 + 125 + 27 = 154<sub>10</sub> |
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.
Why six non-breaking spaces in a row?
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.
It also doesn't render well.
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 idea was to keep the indentation for the two example the same, so that differences are more obvious. => Removed
@@ -0,0 +1,4 @@ | |||
--- | |||
blurb: "Given two decimal parameters (number and base) return True if the number 'number' is an armstrong number with respect to the numeral system with base 'base'." |
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.
Minor nitpick: instead of "return True if", possibly phrase this as "determine whether".
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.
"Determine if a number is an Armstrong number"
would be enough.
The blurb doesn't need to completely specify what you have to do. It should be a teaser to encourage the student to look at the detail of the problem.
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.
Ok, I wasn't really sure what the "blurb" was good for ... now i know 😄
=> Fixed as suggested
It also depends on the base of the number being used (for example base = 10 for the decimal system or base = 2 for the binary system). | ||
|
||
For example:<sup></sup> | ||
153<sub>10</sub> is an armstrong number in base 10, because: 153<sub>10</sub> = 1<sup>3</sup> + 5<sup>3</sup> + 3<sup>3</sup> = 1 + 125 + 27 = 154<sub>10</sub> |
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.
Although I agree that using <sup></sup>
makes for the best display of exponentiation, I don't really like using HTML in markdown. I've looked at the all-your-base exercise, and it's description uses the caret sign (^), which I think is still quite readable.
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.
To be consistent here, I'd also remove the "sub" additional to the "sup" then.
This would "cost" quite a bit of readability for the rendered version because we lose the hint in what base a number is represented. If we decide to drop all html, then I'd also vote for dropping the "base" completely and go with @Insti argument at the bottom. Do we have a consensus here?
It also depends on the base of the number being used (for example base = 10 for the decimal system or base = 2 for the binary system). | ||
|
||
For example:<sup></sup> | ||
153<sub>10</sub> is an armstrong number in base 10, because: 153<sub>10</sub> = 1<sup>3</sup> + 5<sup>3</sup> + 3<sup>3</sup> = 1 + 125 + 27 = 154<sub>10</sub> |
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.
It also doesn't render well.
"expected": false | ||
}, | ||
{ | ||
"description": "111 is not an Armstrong number in base 10", |
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.
(Feedback applies to all tests.)
The description here doesn't tell me anything already covered by the input and output values.
What is this test testing?
Why is 111 useful number to test?
If we had a solution that passed the previous n tests, what code would need to change that would make this test pass?
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 just wanted to have another false 3-digit 10-base test additionally to 100.
I guess you are right and this does not catch anything special additionally.
=> Removed
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.
Why is 100 useful to test?
Is this problem about Armstrong numbers or base calculations? Given one could express the Armstrong number portion of this exercise using only "standard" base 10. What does the additional base parameter add to the problem? |
This is a great first draft. 👍 Thanks. ❤️ |
@Insti I requested that @pheanex write the tests across several bases in #1017, when the idea was proposed. The reason is that whether a given integer is an Armstrong number varies according to the base in use. That is, I'd expect most students not to bother with base conversions on their own for most cases, instead using the relevant string formatting options of their chosen language to generate a string representation, and then iterating over the digits. If you like, we can restrict the options to octal, decimal, and hexadecimal in order to minimize the chance that students need to manually implement any kind of base conversion. |
@Insti Another relevant property to vary over is the number of digits in the number; that affects the way the property is computed. Therefore, looking at the tests, I'd expect to see for each of some number of bases, for each of some number of digits in that base, a few numbers to check which are Armstrong numbers, and a few which are not. This is what I observe in these tests, so I'm satisfied. The precise details of which bases are tested, which digit lengths are tested, and how many and which numbers are tested could be debated, but I don't have any objection to the examples already chosen. |
I think my point is that the base stuff adds unnecessary complexity to the problem. |
Armstrong numbers are different: whether or not a number is an Armstrong number is intrinsically linked to the base in which it is represented. That's precisely why Armstrong numbers are interesting; most numerical properties hold true regardless of representation, and this one doesn't. To test only a single base would ignore the property which makes Armstrong numbers interesting. Or, to put it otherwise: as the README states, Armstrong numbers come from recreational math. We could create an exercise which tested them in a single base, but it would be pure symbolic manipulation, uninteresting in itself. What makes it interesting is what makes it recreational: the fact that the representation changes the property. We're not even asking students to parse numbers of varying base; all the inputs are given as standard integers. We just ask them to compute a property which varies according to base. Testing only base 10 would both be less interesting for the student, and incomplete within the scope of the problem. |
@Insti @coriolinus I'm fine with both your versions. |
"exercise": "armstrong-number", | ||
"version": "1.0.0", | ||
"comments": [ | ||
"Both input-parameters are always given in base-10(decimal)." |
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 think "base-10(decimal)" should be "base-10 (decimal)"
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.
Missing space added
"expected": true | ||
}, | ||
{ | ||
"description": "370 is an Armstrong number in base 10", |
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 had no specific objection to 111, but rather a general objection to ALL the tests.
The description here doesn't tell me anything already covered by the input and output values.
What is this test testing?
Why is this number useful to test?
If we had a solution that passed the previous n tests, what code would need to change that would make this test pass?
What is it about each of these numbers that makes them interesting/important to test?
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 guess its easier if we turn this around:
What numbers do you suggest we test/are interesting to test?
It also depends on the base of the number being used (for example base = 10 for the decimal system or base = 2 for the binary system). | ||
|
||
For example: | ||
153<sub>10</sub> is an armstrong number in base 10, because: 153<sub>10</sub> = 1<sup>3</sup> + 5<sup>3</sup> + 3<sup>3</sup> = 1 + 125 + 27 = 154<sub>10</sub> |
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.
Use a capital A
for all usage of Armstrong
in English.
153<sub>10</sub> is an armstrong number in base 10, because: 153<sub>10</sub> = 1<sup>3</sup> + 5<sup>3</sup> + 3<sup>3</sup> = 1 + 125 + 27 = 154<sub>10</sub> | ||
154<sub>10</sub> is *not* an armstrong number in base 10, because: 154<sub>10</sub> ≠ 1<sup>3</sup> + 5<sup>3</sup> + 4<sup>3</sup> = 1 + 125 + 64 = 190<sub>10</sub> | ||
17<sub>10</sub> is an armstrong number in base 3, because: 17<sub>10</sub> = 122<sub>3</sub> = 1<sup>3</sup> + 2<sup>3</sup> + 2<sup>3</sup> = 1 + 8 + 8 = 17<sub>10</sub> | ||
18<sub>10</sub> is *not* an armstrong number in base 3, because: 18<sub>10</sub> = 200<sub>3</sub> ≠ 2<sup>3</sup> + 0<sup>3</sup> + 0<sup>3</sup> = 8 + 0 + 0 = 8<sub>10</sub> |
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.
Make sure all these lines are separated in the markdown rendered view.
They currently confusingly run into each other.
The README doesn't actually state this. Including more of the information from #1018 (comment) in the README would help.
It is still necessary to do base conversion to get the digits to test though? What do you think the core of this exercise is? |
I guess I just don't find it interesting. You're still just taking You could just as easily say the digits are "122" and you want them to equal 17. I suspect there is an interesting problem in here somewhere, but I don't think we've found it yet. |
I apologize, you're right; that info is in the wikipedia page which describes Armstrong numbers.
I think this is the key issue. You're absolutely right that we could just say "sum the digits 122 and compare them to 17", and we'd have an exercise which might introduce students to iterating through characters of a string and string to int conversion. However, without context, that exercise is pointless and boring. In contrast, if the exercise talks about Armstrong numbers and links me to a wiki page, and I know that 173 is I do see the point that we don't want to send students down a base-conversion rabbit hole, particularly if we expect this exercise to appear fairly early in the tracks. To that end, I propose that we limit the canonical data to using bases 8, 10, and 16. Most languages should have some equivalent to |
To phrase it more concisely, the point of this exercise could be to teach intermediate use of the chosen language's string formatting system, using Armstrong numbers so that it doesn't come across as too contrived. |
In this case the description would need to be significantly rewritten to emphasise this. BUT string formatting seems to be a rather implementation specific thing. But I think we've found the source of our differences. |
@pheanex As the person submitting this exercise, it's only fair that you get to pick the direction to take it. If in your mind this is more interesting with the bases, you'll need to remove the base-3 tests and update the description to suggest using string formatting to the student. If you think it's more interesting as a pure Armstrong number verification exercise, you'll need to remove the non-base-10 tests and refactor to remove mention of the bases. I'm ok with either variant. |
If it's decided to use the version with the bases, it might be desirable to put a phrase in the description similar to the following:
This suggests to the student that string formatting may be a simple way to implement the cases, without doing so explicitly. Simultaneously, it reminds them that there are other methods available for doing base conversion. This should serve the goals of maximizing student flexibility while hinting at a possible path for those who need help. |
We are nearly there. 😄
It is important that new exercises meet the current standards for formatting and clarity. There are already a lot of exercises, why should we add a new ones? |
9 is an Armstrong number, because 9 = 9^1 = 9 | ||
10 is *not* an Armstrong number, because 10 != 1^2 + 0^2 = 2 | ||
153 is an Armstrong number, because: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 | ||
154 is *not* an Armstrong number, because: 154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190 |
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.
These line all still need some way to separate them in the rendered output, they currently run into each other in one paragraph.
Is there anything still preventing this PR getting merged? |
This exercise is mostly fine. Thanks for all your work on it. ❤️ I'm not merging it because I still don't think the test case descriptions are good, and would like to see more logical and instructive test cases chosen. But I'm not the only one here. There are many others with commit access who have different opinions. Maybe they will review and merge this. It may also be that no-one has had a chance to review it yet, we're all volunteers here and do this in our spare time. |
"expected": false | ||
}, | ||
{ | ||
"description": "153 is an Armstrong 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.
"description": "Three digit number that is an Armstrong number",
"expected": false | ||
}, | ||
{ | ||
"description": "100 is not an Armstrong 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.
"description"; "Three digit number that is not an Armstrong number",
"expected": true | ||
}, | ||
{ | ||
"description": "370 is an Armstrong 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.
This test is redundant. Previous test already tests for three digit numbers, unless there is some other relevance regarding 370.
"expected": true | ||
}, | ||
{ | ||
"description": "9474 is an Armstrong 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.
"description": "Four digit Armstrong 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.
Perhaps a test of a non-Armstrong four digit number would be prudent here as well.
"expected": true | ||
}, | ||
{ | ||
"description": "9926314 is not an Armstrong 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.
"description": "Seven digit number that is not an Armstrong number",
"expected": false | ||
}, | ||
{ | ||
"description": "9926315 is an Armstrong 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.
"description": "Seven digit number that is an Armstrong number",
@Insti said:
I agree. I have taken a quick crack at the case descriptions... |
{ | ||
"exercise": "armstrong-numbers", | ||
"version": "1.0.0", | ||
"description": "There are no 2 digit Armstrong numbers", |
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 think this line is needed. It is also causing Travis CI to fail as it violates the canonical-schema.json
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.
This should be the description for a test of a 2 digit number.
It is, the version I was looking at was out of date.
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.
It is, the version I was looking at was out of date.
Wouldn't it still be 1.0.0
?
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 canonical-data version
key is correct.
It was an out of date "commit" I was looking at.
Confusing word choice by me there sorry.
"expected": true | ||
}, | ||
{ | ||
"description": "9 is an Armstrong 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.
Appears as though the first three tests could be consolidated into a single test since all single digit numbers are Armstrong numbers.
"description": "Single digit numbers are Armstrong numbers",
My wording may need some work. I don't want to imply that all single digit number need to be checked.
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.
Thanks for making these changes. Now lets allow some time for others to weigh in.
@Insti is there anything concrete (maybe on the test-cases?) i can do to get your approval as well? |
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 have just one small request. For consistency, could you order the test cases such that they always use the same "is"/"is not" order? For example, we now have "Three digit number that is not an Armstrong number" before "Three digit number that is an Armstrong number" and "Four digit number that is an Armstrong number" before "Four digit number that is not an Armstrong number". I think it would make sense to consistently use the same ordering. My preference would be to start with the "is a" case, followed by the "is not" case.
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.
Thanks for the hard work!
I am going to go ahead and Squash & Merge since everyone is holding their peace... If something is discovered later, a new issue/PR can be opened. Thanks @pheanex for all your time and energy and helping to improve Exercism! |
Sorry @pheanex, I've been busy the last few days. This looks fine. Thanks for all your work on it ❤️ |
How is this for a first draft on #1017 ?
Closes #1017.