|
cp9876 wrote: Not true, fails for 15, 27, 35
Observant and quick, I must say
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi
| Not true, fails for 15, 27, 35
ture...
i was trying with big numbers and found this working...didnt notice that it failed for small numbers, infact it fails for large numbers also.
Regards
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|
|
You ought to direct your reply to cp9876...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
It is pretty easy to see that it identifies any number of the form 4k+3 as prime.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Hey Gui you are giving some what like silly idea. Don't you know 15,27, 35 are not prime.
gyan
|
|
|
|
|
This idea is not clear cut for all primes. For example 13 is a prime number but 13-1=12 is divisible by 4. I mean that what happens if 4 perfectly divides p-1???
Gyan
|
|
|
|
|
Hi
Just found some wonderful properties of number 4.
1. 4 is the only perfect square whose reciprocal is also a perfect square.
2. Any perfect square when devided by 4 gives a reminder of either 1 or 0.
Is this something already known?
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Zainu wrote: Is this something already known?
probably for a few hundred years.
|
|
|
|
|
Zainu wrote: Is this something already known?
Technically, yes, I'm fairly sure that it is known by at least one person. I'm sure others will claim knowledge of it, too. Whether they do or not, you'll never know for sure.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Zainu wrote: 4 is the only perfect square whose reciprocal is also a perfect square.
hence 1/4 is a perfect square while, for instance, 1/9 not?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Sounds like you are just discovering the magic of Number Theory, you can find lots of interesting resources on the web.
I'm not sure what you are implying with (1), but (2) is very well known. 0 and 1 are called the quadratic residues mod 4. Some other examples, the same thing is true mod 3, but in mod 8 the residues are 0,1,4.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
|
Mathworld is a great website, alot of good stuff there
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hiya guys.. Using C++ does anyone know how i can tell if a line is linear or not? I want the user to enter 5 readings which i can plot on a chart. However i would like a function to find out if the plotted line is linear.
Any help would be greatly appreciated!
|
|
|
|
|
EDIT: Not sure if this is needed or not: if the slope between x_1,y_1 and x_5,y_5 is greater than 1, swap the x and y values for each coordinate pair. This swap is needed to keep the delta value in the next step smaller than 1.
Create a function for the line y = f(x) using points 1 and 5. Then of each of the 3 points in the middle calculate f(x_n), if ABS(f(x_n) - y_n) < 1, then x_n,y_n is on on the line (give or take the rounding error from forcing integral values).
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
Hi Dan,
Same idea, but without any math showing, the lazy approach:
- Create a GraphicsPath
- add the line connecting the end points
- widen with a pen (I guess width=3, more gives more tolerance)
- check all points fall within (that's GraphicsPath.IsVisible)
|
|
|
|
|
Hiya Luc. Thanks also for your reply. This is an interesting approach here, however GraphicsPath is a .net class while i am using native C++/MFC.
|
|
|
|
|
Cheers Dan. This is great..
Im just a little confused about the functions f(x) and f(x_n). What is the body of these functions?
|
|
|
|
|
The same function, f(x) is the generic function, x_n is x_1, x_2,... (the x points of your test coordinates). Probably best done using the slope-intercept form. Google if you need help getting the values from two points.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
ahh-ahhh..... the penny has dropped. Thanks again.
|
|
|
|
|
Try to apply Linear Regression to your points.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi CPallini,
it depends on what the points represent:
- for ideal (x,y) points, yes
- for graphic approximation (such as Bresenham), not so good
Greetings
|
|
|
|
|
It appears to me like a mathematical problem rather than a (digital) graphics one. Anyway, only the OP can clarify the point (I hope!)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
hi flippydeflippydebop
"entering 5 readings" u mean input 5 values then in each reading u will get a point's value mean(x,y)
it means
int x[5], y[5]
for( i=0; i<5; i++ )
read x[i], y[i]
resultX = x[0] - x[1] - x[2] - x[3] - x[4]
resultY = y[0] - y[1] - y[2] - y[3] - y[4]
if( ( resultX == 0 ) and ( resultY == 0 ) )
print "line is linear"
else
print "line is not linear"
i think this is the solution if it is true plz inform me if it is wrong then also inform me plz..
in case it is true u can further enhance and can be maked easy and powerful then this.
plz inform me about its correctness
habib bhutto
|
|
|
|
|
hi flippydeflippydebop
"entering 5 readings" u mean input 5 values then in each reading u will get a point's value mean(x,y)
it means
int x[5], y[5]
for( i=0; i<5; i++ )
read x[i], y[i]
resultX = x[0] - x[1] - x[2] - x[3] - x[4]
resultY = y[0] - y[1] - y[2] - y[3] - y[4]
if( ( resultX == 0 ) and ( resultY == 0 ) )
print "line is linear"
else
print "line is not linear"
i think this is the solution if it is true plz inform me if it is wrong then also inform me plz..
in case it is true u can further enhance and can be maked easy and powerful then this.
plz inform me about its correctness
habib bhutto
|
|
|
|