-
-
Notifications
You must be signed in to change notification settings - Fork 556
Armstrong-numbers: add test case for 21897142587612075 #1487
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'd guess this number does not fit in uint32, and I'm not even sure if it would fit it's 64 bit counterpart. Can current generators deal with such a value? In theory, according to JSON this would even be rounded to float, as it exceeds the guaranteed 32 bit... |
Addendum: I'm pretty sure the Erlang generators would accept this value without further ado. Golang might with small changes, but I have no clue about all the other generators. |
Python track does not currently have a generator in place (its in development), but Python language would have no trouble with this number. That said, I am fairly certain languages like Java and C++ would need to use a larger integer class. |
I'm not only concerned about representability in a given language as some test from the spec is easily droppable, but much more if generators are able to read such a large number from a JSON without loss, as JSON does not know anything about integers or floats, it only supports numbers and allows the implementor to coerce as necessary. I do know that the erlang library I use does parse numbers as erlang terms and due to the dynamic nature of the language, it will simply give me an int unless there is a dot I know the JSON parser in the go lang standard library circumvents the issue by providing a special type But I have no clue about other languages how they will be able to deal with such a large number in a JSON. |
I imagine that most track exercise generators are written in the track's language: if the generator can't handle this case, that's a good clue that the language probably wants to drop the case anyway. Rust's >>> big = 2**64 - 1
>>> big
18446744073709551615
>>> import json
>>> json.loads(json.dumps(big)) == big
True I just don't see generator compatibility being a huge issue here. |
I see that there is a discussion of numbers larger than 32 bits, as the number being discussed takes 55 bits. I recommend that if there is any decision made on them here, deciders should consider whether the decision equally applies to the following:
This comment should not be taken to mean either of "I {support, oppose} adding this test case to armstrong-numbers" |
I'm not sure, but in this case I would argue against adding this test case. Currently, |
As someone pointed out already the number does fit into 64 bit integers, which I do not consider extraordinary large, but instead common enough on modern platforms. Except for JavaScript, I do not see any language that were unable to deal with those numbers by simply using the next bigger integer, or even taking the exercise as the introduction to sized integers (if it hasn't already happened before with And this test case is explicitely not introducing floats, it just shall avoid students to use floats in intermediate steps of the computation. In erlang and elixir solutions are pretty common that use I'd be totally fine with finding a smaller number that fits into 32 bit as well. And to be honest, I do not even care if it produces false positives or negatives, as long as it produces a false result when using floating2integer conversion. |
@ErikSchierboom I agree with your sentiment regarding integer size and introducing a larger class. Is there another exercise where a larger class is introduced? A quick scan of config.json only ever reveals |
There are several: |
This is of course, the million dollar question :) |
In JavaScript we explicitly provide big-integer.js for |
I guess I was expecting something different. Like in config.json indicating a topic other than |
@chvanikoff: This message is just to inform you that this commit somewhat depends on #1492. |
Putting this on hold per #1560 |
So in this case, I'd argue that the added test case offers not much value over the existing test cases, with the downside being that track maintainers need to be careful implementing it due to possibly needing to change the involved data type. IMHO this goes against the goal of this exercise, which is to have a simple recursion/looping exercise. If anyone disagrees with me, let me know. Otherwise, I'll be closing this PR in a couple of weeks. |
Most of solutions are using some sort of built-in "power" function, which can (ex.: Clojure, Erlang/Elixir, JS) rely on floating-point arithmetics under the hood (even though the interface functions can accept integers). The number 21897142587612075 is known to be armstrong one (http://mathworld.wolfram.com/NarcissisticNumber.html), but depending on the floating point arithmetic implementation used might cause false negatives on solutions that convert between numeric types, because
9^17
returns16677181699666570
or16677181699666568
, but not16677181699666569
which is expected.