# Can a valid Armstrong numbers be negative?

Posting here because problem-specifications repo automatically closing all new issues.

At present there are no test cases which use negative integers for the ‘Is an Armstrong number’ exercise.

This wikipedia article, the same one referenced in the problem description, would seem to imply that Armstrong numbers can be negative.

If negative numbers are legal or not. Either way do the test cases need updating?

Any mathematicians out there with a definitive answer?

1 Like

The article says they “can be extended” to negative numbers. Not that, “negative numbers are included”. The unit tests and the exercise don’t bother with negative values. The scope of the exercise is positive integers.

I don’t think there’s any need or reason to change anything. The purpose of the exercise isn’t to explore any and all extensions, or even uses/combinations of those values. The purpose of the exercise is to write code which efficiently and cleanly solves the problem in the limited scope the exercise handles. Broadly speaking, the scope of most things in life can be expanded; that doesn’t mean they should. The way exercises are scoped sets up the challenge and difficulty of the exercise. The scope shouldn’t be altered because it can be done; scopes should only be altered because there’s a very good reason to change the scope. If there’s a compelling reason to change the scope, then options for changing the scope become relevant.

That makes sense. Thanks for the prompt response.

Would it be worth just adding a note in the description saying “For this exercise, don’t worry about the possibility of negative armstrong numbers. Assume all inputs will be positive.”? Just to avoid any potential future questions and make it a bit more explicit to the learner?

That Wikipedia article talks about “signed-digit representation”, not signed numbers.

I had a hard time understanding the article about Signed-digit representation, but I guess an example would be Balanced Ternary which can represent all integers (positive and negative) with just three digits where one of them is negative.

But our armstrong-numbers exercise specifically deals with decimal digits which are all non-negative.

Of the participants in this thread up to now, I am probably the closest to being a ‘mathematician’.

It is not obvious to me how a negative integer might be considered an Armstrong number.

As neither Sieben (after research) nor I (at little more than a glance) understand the supposed extension, it seems safe to say that the exercise should not be extended to negative integers.

I’d be mildly interested to learn how that supposed extension works though.

It doesn’t. The very definition of Armstrong numbers excludes negative numbers.

In general, we pretty explicitly don’t spell out all the details about what inputs should and should not be expected. We’re pretty explicit that the unit tests are the source of truth and the documentation of those details.

Any chance that someone on this thread can reopen and merge this PR?

Add test. Negative numbers are not armstrong numbers by pfmaggi · Pull Request #2332 · exercism/problem-specifications (github.com)

1 Like

Based on all the responses in this thread, it seems to me like the consensus was more “there is no value in adding negative values to these tests” than “adding negative values to the tests adds value to this exercise”.

If the goal of the PR is to add input validation, having a bunch of tests with invalid inputs to check that input validation is done tends to be unpopular and distracts from the actual exercise unless the exercise is explicitly about input validation.

Did you get a different impression from the responses?