Talk:Casting out nines: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
(Go solution updated)
Line 22: Line 22:


::::OK, maybe you have misunderstood what I am trying to convey. Following Dr. Math at http://mathforum.org/library/drmath/view/55926.html describing casting out nines to the phrase "(You wouldn't normally get the same check digit for the result of the sum and the products; I just picked a weird example.)" I see that every Kaprekar is a "weird example". Using Dr. Maths "quick explanation of how to do it, without the big words" would be as slow as the String C++ Kaprekar solution. So we turn to http://mathworld.wolfram.com/CastingOutNines.html. What is said there is true for bases other than 10, therefore it is possible to develop a fast test. --[[User:Nigel Galloway|Nigel Galloway]] 12:47, 27 June 2012 (UTC)
::::OK, maybe you have misunderstood what I am trying to convey. Following Dr. Math at http://mathforum.org/library/drmath/view/55926.html describing casting out nines to the phrase "(You wouldn't normally get the same check digit for the result of the sum and the products; I just picked a weird example.)" I see that every Kaprekar is a "weird example". Using Dr. Maths "quick explanation of how to do it, without the big words" would be as slow as the String C++ Kaprekar solution. So we turn to http://mathworld.wolfram.com/CastingOutNines.html. What is said there is true for bases other than 10, therefore it is possible to develop a fast test. --[[User:Nigel Galloway|Nigel Galloway]] 12:47, 27 June 2012 (UTC)

:::(Comments moved from task page following Go solution.) I'm not seeing the connection. —[[User:Sonia]]

::::If you replace the line <code>if k%(base-1) == (k*k)%(base-1) {</code> with something like <code>if co9Peterson(k) == co9Peterson(k*k) {</code> in the C++ translation would it not solve the task? Obviously as written you would have to change k and k*k to strings and it would only work base10, but I think you have demonstrated the connection.--[[User:Nigel Galloway|Nigel Galloway]] 15:15, 28 June 2012 (UTC)

::: Done. Posted now are my two Go solutions combined, generalized to other bases, and then modified to demonstrate what the task seems to be asking for. I do think that people will protest that my casting out nines code is superfluous, and I will then repeat that the task should not be called casting out nines if nothing in the task is casting out nines. &mdash;[[User:Sonia|Sonia]] 19:20, 28 June 2012 (UTC)

Revision as of 19:20, 28 June 2012

I am trying to understand this task.

Would it be fair to change the final sentence to read:

The task is to write code that given a numeric base and two numbers that mark the begining and end of a range use only this test to eliminate numbers from the range which cannot be valid Kaprekar numbers -- the result is the rest of the numbers from that range.

Or have I completely misunderstood what you are trying to convey?

--Rdm 13:59, 25 June 2012 (UTC)

OK, you have not misunderstood what I am trying to convey. I wanted to accept any test based on the congruence B^n=1(mod B-1). The Kaprekar numbers are a good objective because they have the property k%(B-1) == (k*k)%(B-1) and are explained elswhere on this site. I would accept any other objective.
Ok! I think the current task description is a bit too coy about the filtering mechanism. It's almost equivalent to "filter numbers" since the description of the selection function is so general. I am currently thinking it should be:
Given two numbers which mark the beginning and end of a range of integers [LO,HI], and an integer base (BASE), return the integers which fall in that range where the remainder after dividing the number by BASE-1 is the same as the remainder after dividing the square of the number by BASE-1.
That is the test, but I also want to keep the explanation of why we are doing this. Note that Ledrug has implemented the test as ((k*k) - k)%(Base - 1) at http://rosettacode.org/wiki/Kaprekar_numbers#C which is another variation. --Nigel Galloway 13:03, 27 June 2012 (UTC)
--Rdm 14:02, 26 June 2012 (UTC)
I'd like to see a different title for the task. The current description states right up front that the task is not casting out nines. —Sonia 19:46, 26 June 2012 (UTC)
OK, maybe you have misunderstood what I am trying to convey. Following Dr. Math at http://mathforum.org/library/drmath/view/55926.html describing casting out nines to the phrase "(You wouldn't normally get the same check digit for the result of the sum and the products; I just picked a weird example.)" I see that every Kaprekar is a "weird example". Using Dr. Maths "quick explanation of how to do it, without the big words" would be as slow as the String C++ Kaprekar solution. So we turn to http://mathworld.wolfram.com/CastingOutNines.html. What is said there is true for bases other than 10, therefore it is possible to develop a fast test. --Nigel Galloway 12:47, 27 June 2012 (UTC)
(Comments moved from task page following Go solution.) I'm not seeing the connection. —User:Sonia
If you replace the line if k%(base-1) == (k*k)%(base-1) { with something like if co9Peterson(k) == co9Peterson(k*k) { in the C++ translation would it not solve the task? Obviously as written you would have to change k and k*k to strings and it would only work base10, but I think you have demonstrated the connection.--Nigel Galloway 15:15, 28 June 2012 (UTC)
Done. Posted now are my two Go solutions combined, generalized to other bases, and then modified to demonstrate what the task seems to be asking for. I do think that people will protest that my casting out nines code is superfluous, and I will then repeat that the task should not be called casting out nines if nothing in the task is casting out nines. —Sonia 19:20, 28 June 2012 (UTC)