View Full Version : Another math question
nothing
07-16-2003, 10:51 PM
x % 10 = 8
How can I know what x is?
downpour
07-16-2003, 11:42 PM
I think mod gives you the remainder of division, right? I could be wrong, but I think I'm right. So...
x % 10 = 8 means x could be anything divisible by 10 that gives you a remainder of 8.
or so I think...
nothing
07-17-2003, 12:36 AM
The number is between the range 0 to 9
ChefNinja
07-17-2003, 04:27 AM
18
jamessan
07-17-2003, 08:35 AM
You can't unless you are given more information. Here's a little python to show why:>>> for i in range(18,128,10):
... print i%10
...
8
8
8
8
8
8
8
8
8
8
8Basically, any number that ends in an 8 will return 8 when modded by 10.
nothing
07-17-2003, 09:02 AM
No. The number will never be bigger than 9 or smallest than 0.
jamessan
07-17-2003, 10:58 AM
No, you are wrong. x % 10 divides x by 10 and returns the remainder. The remainder will always be between 0 and 9 inclusive, but x can be any number. In the case of the example you gave us, x % 10 = 8, x can be any number that has an 8 as the ones digit. If x was limited to the numbers 0 through 9, then the result of x % 10 would be x.
downpour
07-17-2003, 06:58 PM
Originally posted by jamessan
No, you are wrong. x % 10 divides x by 10 and returns the remainder. The remainder will always be between 0 and 9 inclusive, but x can be any number. In the case of the example you gave us, x % 10 = 8, x can be any number that has an 8 as the ones digit. If x was limited to the numbers 0 through 9, then the result of x % 10 would be x.
so I was right.
nothing
07-17-2003, 09:05 PM
The number that will be % 10 is never be greater than 9 or smaller than 0.
DNAunion2000
07-17-2003, 11:14 PM
DNAunion: The answer is 8
***********************
8 % 10 = 8
8 / 10 = 0 with a remainder of 8
And 8 is in the range 0 - 9
jamessan
07-17-2003, 11:18 PM
Originally posted by nothing
The number that will be % 10 is never be greater than 9 or smaller than 0. Either you're agreeing with part of my earlier explanation,The remainder will always be between 0 and 9 inclusiveor you are still not understanding this correctly.
Let's take a more generic form of the initial equation you gave us, e.g. 'X % 10 = Y'. No matter what X is, be at 8, 34, or 87352, Y will be the one's digit from each number (8, 4, and 2 respectively). This is because of our counting system being base 10. If we were to use hex instead, then X % 16/10 (decimal/hex) = Y, Y would still be the right-most hex digit of X.
downpour
07-17-2003, 11:20 PM
Originally posted by nothing
The number that will be % 10 is never be greater than 9 or smaller than 0.
jared@downpour:~$ python
Python 2.2.3+ (#1, Jul 5 2003, 11:04:18)
[GCC 3.3.1 20030626 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 48 % 10
8
>>> 58 % 10
8
>>> 68 % 10
8
>>> 208 % 10
8
>>> 2000008 % 10
8
>>>
SO WE ALL GET THIS CLEAR: ANY NUMBER, DIVISIBLE BY 10, THAT HAS A REMAINDER OF 8, CAN BE X. END OF STORY. ARE WE CLEAR?
(ps. this is not trying to piss anyone off, or prove anyone wrong. I want to clarify it, so we all agree on the language that describes what % does)
jamessan
07-17-2003, 11:22 PM
Originally posted by DNAunion2000
DNAunion: The answer is 8You can't say that for sure with the information given to us. If there was the stipulation that X had to be within the digits 0 through 9, then you would be correct. Without that stipulation, the correct answer could be 8, 18, 28, 38, ad infinitum.
DNAunion2000
07-17-2003, 11:23 PM
DownPour: SO WE ALL GET THIS CLEAR: ANY NUMBER, DIVISIBLE BY 10, THAT HAS A REMAINDER OF 8, CAN BE X. END OF STORY. ARE WE CLEAR?
DNAunion: No. There is only 1 solution that fits all parameters: 8 is the one and only answer.
DNAunion2000
07-17-2003, 11:26 PM
jamessan: [DNAunion] You can't say that [the answer is 8] for sure with the information given to us.
DNAunion: Yes, I can.
Jamessan: If there was the stipulation that X had to be within the digits 0 through 9, then you would be correct. Without that stipulation, the correct answer could be 8, 18, 28, 38, ad infinitum.
DNAunion: And that was stipulated....twice. Nothing stated twice (though after the original problem was posted) that x is between 0 and 9. Here's one of those times.
Nothing: The number that will be % 10 is never be greater than 9 or smaller than 0.
DNAunion: That narrows it down to a single solution: 8.
DNAunion2000
07-17-2003, 11:32 PM
DNAunion: Here's a sort of mathematical proof.
x % 10 = 8
That means x / 10 = y (a whole number) with a remainder of 8. Since the divisor is 10, that "remainder" is 8/10. That is:
x % 10 = 8
is the same as
x/10 = y + 8/10
Now we multiply through by the common denominator.
10(x/10) = 10(y + 8/10)
x = 10y + 8
We are told that x is an integer between 0 and 9 inclusive. So:
0 <= x <= 9
Since x = 10y + 8, we can plug that into the inequality in place of x.
0 <= 10y + 8 <= 9
Solving this for y:
0 - 8 <= 10y + 8 - 8 <= 9 - 8
-8 = 10y <= 1
-8/10 <= 10y/10 <= 1/10
-0.8 <= y <= 0.10
We know that y is a whole number, so it must be 0: that's the only whole number within that range. So
y = 0
Now we plug that back into our original equation.
x = 10y + 8
x = 10(0) + 8
x = 0 + 8
x = 8
jamessan
07-18-2003, 09:19 AM
Originally posted by DNAunion2000
DNAunion: Here's a sort of mathematical proof. Well, I obviously misunderstood that he was providing a limitation for the values of X. At any rate, a couple of us had already shown the range of numbers that could fit X, so pairing that with the added stipulation provides the correct answer as does your proof.
DNAunion2000
07-18-2003, 09:35 AM
jamessan: Well, I obviously misunderstood that he was providing a limitation for the values of X. At any rate, a couple of us had already shown the range of numbers that could fit X, so pairing that with the added stipulation provides the correct answer as does your proof.
DNAunion: Just so we are on the same page, my "mathematical proof" wasn't aimed at "proving" me right and others wrong. It was in response to Nothing's original question.
Nothing: x % 10 = 8
How can I know what x is?
DNAunion: To find out what x is, there is a step-by-step mathematical method: one isn't forced into trial and error.
****************************
PS: An estute mathematician may have spotted a "flaw" in my "mathematical proof". That is why I qualified it as being a SORT OF mathematical proof. It works only for whole numbers (hence my statement that y is a whole number). But whole numbers (i.e., integers restricted to being 0 or positive) are what we programmers deal with when we use % so I didn't see any reason to get TOO technical.
fortytwo
07-18-2003, 12:07 PM
DNAunion2000... like the proof... reminds me of that quarter where thats all i did
skidooer
07-20-2003, 02:58 PM
#include <stdio.h>
int main()
{
for(int i = 0; ; i++) {
if(i % 10 == 8)
printf("%d\n", i);
}
return 0;
}
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.