|
Outer space is big—really big—and almost entirely empty. One thing done in a lot of sci-fi movies is having the characters fly through an asteroid field, dodging asteroids like road hazards. This is silly. You would be lucky to find one asteroid in the Asteroid Belt flying straight through it, yet alone having to worry about dodging such things. Everything in our solar system is separated by distances much larger then anything we can normally work with. In my story, ships are regularly required to travel to the outer edge of the solar system. Pluto's outer edge of it's orbit is about 50 AU, or 7.3 billion km, or 4.5 billion miles from the sun. So how long would it take to get there? If you could get a space craft to travel 500,000 mph (not too crazy for space travel), it would take about 1 3/4 years to travel the distance. It you would like to do that in one month, you would have to travel about 10 million miles an hour. Rocket engines are a source of force. Force in physics is usually measured in Newtons, which is kg·m/s2. Assuming the force exerted by a rocket engine is constant, we can determine it's acceleration (m/s2) on some given mass (kg). Our mass is the space ship, so knowing it's mass, we can determine acceleration. What's nice about acceleration is that it keeps increasing velocity. The standard physics equation x = x0 + v0 t + 1/2 a t2 will determine a position (x) after some time (t) with an initial position (x0) and initial velocity (v0). We we start of position 0 (x0 = 0) at a complete stop (v0=0), the equation simplifies to x = 1/2 a t2. And we can solve for t, so t = sqrt( 2 * x / a ). We know x—that is the distance we want to travel. So what is the optimal acceleration? Acceleration due to gravity naturally. This way, we have linear acceleration and perfect gravity. So acceleration is 9.81 m/s2. Thus, if you had the ability to provide a constant force with this rocket engine, it would take about 14 days to reach the outer orbit of Pluto from the Sun. That's not bad considering the distance. But in working this out, I was faced with one obvious problem. The ship I designed is rotating. It already has gravity. The gravity introduced by linear acceleration will be in the wrong direction. If the rotation provides 1 g in one direction, and linear acceleration provides 1 g in an other direction, people are going to be standing sideways just to stay upright. This isn't going to work. It was in the car ride back to Wisconsin talking this over with Mikala that a solution was presented. Mikala pointed out what should have been obvious: why not just have the spheres rotate? As the ship accelerates, turn the spheres such that the center of gravity at a 90 degree angle to the floor. In fact, one wouldn't even need to turn the spheres. The bottoms are heavier then the tops, because the tops are empty. If allowed to rotate, the spheres would naturally correct for the center of gravity. So as the ship accelerates, the rotation is slowed. Since the ship is likely to be large, we will have to gradually accelerate to avoid jarring everything. A change in acceleration is known as jerk. So some constant jerk factor would have to be obtained—likely from that rate at which the rotation could be slowed to a stop.
|
|
|
A couple of weeks ago, I started contemplating an idea of a large transport space ship. On occasion I like to write a little sci-fi, but I'm usually far more interested in the technology then the story. I started to wonder about how a large transport vessel might be laid out. Not much of a fiction reader, most of my exposure to sci-fi is from movies. And most movies don't try all that hard to create images of accurate space traveling vessels. Most somehow assume there is artificial gravity so they never have to address the issue. But how do you get gravity? There are two methods that are rather easy: rotation and linear acceleration. Rotation works well if the object is stationary, such as with a space station. Linear acceleration can work if you have the ability to accelerate at 9.8 m/s2—the same acceleration as gravity. That's an acceleration of 79,000 mph2—meaning if you start for a dead stop, after 1 hour would be traveling 79,000 mph—so a fairly hefty acceleration. So I started with rotation. Rotation provides centripetal force. Most of us as a kid have either tried or have seen someone spin a bucket of water over their head. The centripetal force from the rotation causes the water not to spill out even as the bucket is inverted. One can apply the same principals in space. Again, most movies get a rotation as a means of artificial gravity wrong. Gravity is a function of the radius of the rotating path, and the speed of rotation. g = R( pi r / 30 )2/9.81 where g is gravity with respect to Earth (so 1.0 is Earth's gravity), R is the radius of rotation and r is rounds/minute of rotation. Two things should stand out about this function: a faster rotation means much higher gravity because the RPM is squared, and gravity depends on the radius. If you picture a circle, the one would be standing on the inside edge. One's feet would be touching the inner edge, and one's head would extend toward the center of the circle. The head, being closer to the center of the circle, would experience less gravity then their feet, because the radius has been reduced by their body length. This effect would be significant for small circles. For example, we could use a radius of 10 meters (so 20 meters, or about 66 feet in diameter). To get gravity at the circles edge would require a rotational speed of about 9.5 RPM. A person who is 5'8" (1.7 meters) tall would only have 82% gravity at the top of their head. Someone lifting 10 pounds would to their head would find it weighting only 8 pounds when level with their head. This may not be terrible. However, there is an other problem. Humans experience the Coriolis effect (i.e. knowing that we are spinning) at speeds above 2 RPM. So someone in such a station would get dizzy. To get the speed down, it is necessary to increase the radius. One concept studies back in 1975 referred to as the "Stanford torus" was a torus (i.e. the doughnut shape) 900 meters in radius (about 1 mile in diameter). This would require about 1 RPM in order to hold gravity. The "O'Neill cylinder - Island Three" had an outer radius of 16 km (about 20 miles) and would rotate at one round ever 4 1/4 minutes. After a lot of reading (mostly on Wikipedia), I starting thinking about how to create my own living area. The "Island Three" concept was really neat because it is an open cylinder. You could look up and see the other side—a city scape above your head but not falling on top of you. But this concept was designed to be stationary—orbiting Earth for example. They used large mirrors to reflect in sunlight, which was used for lighting and plant life. My vessel had to move, and the further away from the sun, the less light you get. An other problem I had with this design was the possibility for catastrophic disasters. The entire atmosphere was contained in a single section. One hull breach, and you risk destroying the entire station. I wanted something more compartmentalized—something that worked in sections that were able to be isolated for other sections. In other stories I've worked on, I thought up a concept using domes to grow crops. A center light source would shine on a reflective ceiling, and fields would be cultivated by a rotating gantry crane. I wondered if this concept couldn't be expanded to the space port. Rather then just use a dome, I tried using a sphere. It was easier to draw, but after some thought, made more sense. A dome is just a sphere cut in half. So the upper half of this sphere would be the dome, and the lower half could be support equipment. The flat disk in the middle is the plane for which people could live. This idea seemed to work pretty well in my head, so I started to come up with numbers—which is really where I have my fun! My ring would be 30 km in radius (or 37 miles in diameter). At this size, it would rotate once every 5 3/4 minutes (0.17 RPM). Each dome would be 1 km in radius (1 1/4 miles in diameter), providing 776 acres of land (31 km2). The whole ring could fit 90 such domes for a total of almost 70,000 acres—109 sq. miles (2,800 km2). Because of the large size, even a building 100 meters tall (328 feet, or around 32 stories) will still have 99.67% gravity—so a 150 pound person would weight 149.5 pounds on the top floor. So far, everything was going well for my space port. But then I remember this thing had to move...
|
|
|
Yesterday I completed my basic bench layout, and for the most part, everything fits. Part of the reason is that I used Google Sketchup to do a drawing for placement first. The sleeping box has been redesigned. At first I considered cutting the box down to bench height. Our new place is quite small. I instead to use the top of the box as a bunk for our roommate James. So this leaves the box at a height of 4 feet. The biggest change is the door. Previously, the box opened by hinges in the front, done mainly to keep from having to make additional cuts when the box was first assembled. This was not a good design. It leaked a lot of light, and was quite heavy. The sliding door of my box at the Garage works much better. Since Jai sleeps in the box with me, I decided to recycle the sliding door, but add a second one. We both go to bed at different times, and this allows her to get into the box whenever she likes without having to crawl over me.  Here is a sketch of the box with one side removed, and the closest door transparent. In order to make the new sliding door system, I had to redesign the frame. My box at the Garage uses a double wall setup, with the door in between. This is functional, but I used a 2x4 for the gap, resulting in 1.5 inches of space for the 5/8" door. This means the door flops around and isn't very snug. I decided this new setup should be a little better. I omitted the inner wall, mainly because I didn't want all the extra wood it would require. So, I build a 2x4 skeleton, edged with 1x3" on the top, left and right, and 1x2" on the bottom. This frame provides the gab for the door to slide long. The door is just 1/2" plywood like the sides and top. It turned out quite well actually. The doors move very smooth in the space allotted, and close up tight. After some caulking, the system should be pretty light tight. I finished the main construction on Thursday, left for the weekend starting Friday, and caulked on Sunday night. Yesterday I installed the bench setup, and finished the ventilation. Still haven't had a full test of light though. Tonight I decided to finish up my model. I measured and drew the bedroom. I added a the monitors and chair, but most of the items in the bedroom I couldn't find good models for. Pictured is the sleeping box and my work bench as seen from the north east corner of the room.  Floor plan.
|
|
|
Having owned and operated a domain for over 5 years I'm use to people trying to sell me junk because the idiots shysters at Network Solutions won't keep my e-mail address private unless I pay for that "privilege". I've received e-mails in the past from people wanting to sell me a domain name similar to mine. I ignore them by changing my e-mail address. So when I received an e-mail the other day, I followed standard procedure. To my surprise, I received a second e-mail hour latter to the updated e-mail address. Seems the domain squatters have become more aggressive. To humor myself, I clicked on the "unsubscribe" link. Naturally, I received an e-mail today, this time from a different company. Let's have a look at the e-mails. The first one is from 2/20/2010 9:19 AM Priority Domain Availability Notice for drque.com:
In the next few days, drque.com will be listed for sale. Since you have a similar domain name, we thought you might be interested in acquiring drque.com.
You can confirm your interest in the domain drque.com by filling out the form here: http://initrustdomain.net/store/prioritynotice/f5e6fffd-fb88-456a-8d65-c3568bc2522c
After we receive a confirmation that you are interested in the domain drque.com, our sales staff will be in touch with you promptly to make arrangements.
We look forward to hearing back from you.
Kind regards, InTrust Domains 11605 Meridian Mkt V #124-134 Falcon, CO 80831
If you are not interested in future priority notices, please simply reply to this message
No more please: http://initrustdomain.net/store/unsub/f5e6fffd-fb88-456a-8d65-c3568bc2522c The next from 2/22/2010 7:13 AM Domain Sale Notice:
drque.com is coming available for sale in a few days.
Since you own the domain drque.net, we thought you'd be interested in drque.com.
If you do have interest in acquiring drque.com, please fill up priority notice form availble
here: http://initrustdomainnames.com/store/prioritynotice/f5e6fffd-fb88-456a-8d65-c3568bc2522c
and we will contact you as soon as the domain is available for purchase.
We look forward to hearing back from you.
Kind regards,
John Timmers
InTrust Domains
11590 Black Forest Road
Colorado Springs, CO 80908-6000
=========
This e-mail is for the sole use of the intended recipient(s) and contains information belonging to InTrust Domains. and/or John Timmers, which is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this e-mail information is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and destroy all copies of the original message.
No more please: http://initrustdomainnames.com/store/unsub/f5e6fffd-fb88-456a-8d65-c3568bc2522c
I received this e-mail at 2/23/2010 7:06 AM Domain Sale Notice:
drque.com is coming available for sale in a few days.
Since you own the domain drque.net, we thought you'd be interested in drque.com.
If you do have interest in acquiring drque.com, please fill up priority notice form availble
here: http://bestinitrustdomains.biz/store/prioritynotice/f5e6fffd-fb88-456a-8d65-c3568bc2522c
and we will contact you as soon as the domain is available for purchase.
We look forward to hearing back from you.
Kind regards,
John Timmers
InTrust Domains
11590 Black Forest Road
Colorado Springs, CO 80908-6000
=========
This e-mail is for the sole use of the intended recipient(s) and contains information belonging to InTrust Domains. and/or John Timmers, which is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this e-mail information is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and destroy all copies of the original message.
No more please: http://bestinitrustdomains.biz/store/unsub/f5e6fffd-fb88-456a-8d65-c3568bc2522c
Now I change my e-mail address. The next e-mail is to the new address at 2/23/2010 6:01 PM Hey
My name is Eric Taylor from Flex Media. drque.com will be available for a limited time purchase in a few days. Since you own drque.net, I thought you might be interested in drque.com.
If you do have an interest in purchasing drque.com, please visit: http://www.flexmediadomains.com/prioritysales/4b846b3f090cf12526ef82f704f38b09fdbc9deccaad84b84605bd89513c5d12580d3cd5dba07ea060e039ae39
If the link above doesn't work, please copy the address below and paste it into your web browser: http://www.flexmediadomains.com/prioritysales/4b846b3f090cf12526ef82f704f38b09fdbc9deccaad84b84605bd89513c5d12580d3cd5dba07ea060e039ae39
Once drque.com is available for purchase, one of my account specialists will contact you.
My goal is to make this the easiest transaction possible for both of us. I can guide you step-by-step over the phone, instant messenger or email on how to secure drque.com if you wish. If you have any concerns or questions, please do not hesitate to contact me. No question is a dumb question.
Thank you and have a great day.
Eric Taylor Flex Media Inc 7777 Davie Road Ext, Suite 106B Hollywood, FL 33024 954-584-3750 sales@flexmediadomains.com Skype: flexmediadomains ICQ: 576313997 AIM: sales@flexmediadomains.com MSN: flexmediadomains@live.com www.flexmediadomains.com
This e-mail is for the sole use of the intended recipient(s) and contains information belonging to Flex Media Inc and/or Eric Taylor, which is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking of any action in reliance on the contents of this e-mail information is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by reply e-mail and destroy all copies of the original message.
No more please: http://www.flexmediadomains.com/opt_out.php?prerelease=&id=4b846b3f090cf12526ef82f704f38b09fdbc9deccaad8 And the last e-mail from 2/26/2010 11:26 AM Hi,
We thought that you definitely need to know that right now the .com version of your domain is secured by Easy Domain Recovery and is available for purchase at our page.
What we do is take different measures to help you promote your brand on the Internet. Little things' effectiveness can compare to securing .com to a domain with any other extension. Everyone knows .com, a lot of users will intuitively seek you at .com extension so don't give a chance to anyone else to use that advantage of yours.
There are third parties who may be interested in your domain. Many people out there reserve .coms to existing sites and domains in order to make profit of 'em. We may sell the domain to any of these persons and businesses but this is you who decides whether or not we do so. Please choose one of the following:
Secure drque.com right now! Let it go (unsubscribe).
Best regards, Tom Harris, Easy Domain Recovery, mailto: tom@easydomainrecovery.com Some interesting things can be learned. First, the use of various domain names to push their products. They use initrustdomain.net, bestinitrustdomains.biz, flexmediadomains.com and easydomainrecovery.com. Both initrustdomain.net and bestinitrustdomains.biz are owned by "Moniker Online Services LLC" who according to "SPAM Trackers" wiki have a long history of criminal activity. The other two domains are "owned" by "DOMAINBULLIES, LLC" and "ENOM, INC." There isn't much information about them. What gets me is that the Internet is a major source of commerce. Isn't the FTC suppose to be doing something about this? Why then do places like SPAM Tracker talk about groups like Moniker Online Services and how they have operated for years? The more I deal with law and law enforcement, the more less I believe it functions. It is both incapibal of protecting people, and incapibal keeping law enforcement from harassing the people it aims to protect.
|
|
|
Everyone once and awhile I want to quick put a 3D drawing together, and I'll use Google Sketchup. Being the math nut that I am, I love it when I need to do a bit of geometry. Today, I happened to need to place an octagon (8=sides parallelogram) such that northern, and eastern edges were also the edges of a square, and the start of the north west corner (X), and south east corner (Z) of the octagon began at the these corners on the square. When you draw a polygon in sketchup, you need to have a center point (I) and an end point at one of the angles (such as A). So if I wanted an 8-sided polygon (octagon) to calculate where the center points, and some end point. If you happen to have Sketchup, try and see if you can eyeball this--you'll find it isn't easy. A geometric solution is needed. Luckily, it's easy. Every angle in an octagon is 45 degrees, which is 360 / 8. To find the center of an octagon, pick any edge, and measure 67.5 degrees (45 / 1.5) toward the center. An example in this drawing is line AB or BC. Where the angles meet is the center, point I. Note also that when drawing this polygon, it will be done from point I to one of the point A through H. In my requirement description, I want this octagon (call it octagon I) to meet up with square WXYZ such that vertex A meets vertex X, and D meets Z. Sides AB to XY, and DE to ZY and parallel, and vertex A and the same as X, D the same as Z. Now that we know the 2 verities, and two edges, we can find the center. Measure an angle starting at X along XY that measure 67.5 degrees clockwise. And 67.5 counter clockwise starting Z lone ZY. This is the center point. Draw your octagon starting at this location I, going to either vertex X or Z. That's it! :)
|
|
|
So my last article on prime numbers led me to ask the question "How many prime numbers are there between 2 and 232". I know the quick answer to this question is "a lot". 232 is over four billion—and that's a fair bit of space to check. It would be easy to make a for-loop and brute force the entire number range, but this is the age of multi-core CPUs—and single threaded is so 2000. Besides, my computer hasn't broken a sweat in awhile. I decided to do a straight C implementation. I've been doing C and C++ at work, and C++ has been irritating me lately because I tried to do a "quick and dirty" implementation without too much thought into the classes I'd need. That's a recipe for disaster, and how you end up with things like microsoft's windows ME. So vanilla C it was. Threads and semaphores I used the POSIX standards, and I've tried to demonstrate how to make a dispatcher foreground task with one or more worker threads. The key to this is the dispatch semaphore. Normally, semaphores are used to for mutually exclusive lock, or to send signals between threads. However, they can also be used as a count. Think of them like a library that has a set number (say 5) of books. That means 5 people can check that book out, but if a 6th person wants to check that book out, they will have to wait for one of the first 5 to return their copy. The semaphore does this by keeping a count. When that count reaches zero, the next task that tries to pend the semaphore will have to wait. So the dispatcher is a loop that starts by pending the semaphore. When it gets the semaphore, it will create a task. The task will do some work, then post the semaphore. The semaphore count determines how many tasks can run at the same time. If we limit the number of tasks that can run at once to the number of CPU cores, then we can utilize the CPU to 100%. First, the dispatcher skeleton code: pthread_t Threads[ NUMBER_OF_THREADS ]; sem_init( &Semaphore, NUMBER_OF_THREADS, NUMBER_OF_THREADS ); unsigned ThreadIndex = 0; while ( NumbersLeft ) { // Wait for a free worker thread. sem_wait( &Semaphore ); // Create a worker thread to check this number set. pthread_create ( &Threads[ ThreadIndex ], NULL, PrimeThread, (void *)&Data[ ThreadIndex ] ); ++ThreadIndex; if ( ThreadIndex >= NUMBER_OF_THREADS ) ThreadIndex = 0; } Then, the skeleton of the worker thread: static void * PrimeThread( void * ArgumentPointer ) { // // Do prime check. // // This thread is now complete. Release one count from the dispatch // semaphore. sem_post( &Semaphore ); // End this thread. pthread_exit( 0 ); return 0; } Now just launching a thread to check one number is a bit of a waste—it takes some overhead to start and stop the task. So we give each thread some range of numbers to check. A pthread can be passed parameters, and we pass the starting number, along with the amount of numbers to check. The parameter block is also used for storage of the results. So here is the full worker thread: static void * PrimeThread( void * ArgumentPointer ) { // Get the work data passed to the thread. WORK_TYPE * Data = (WORK_TYPE *)ArgumentPointer; uint32_t Number = Data->StartNumber; uint32_t Count = 0; unsigned Index; // For all the numbers to check... for ( Index = 0; Index < Data->NumberToCheck; ++Index ) { // Is this number a prime? if ( IsPrime( Number ) ) // Then count it. ++Count; // Next number. ++Number; } // Save results. Data->NumberFound = Count; // This thread is now complete. Release one count from the dispatch // semaphore. sem_post( &Semaphore ); // End this thread. pthread_exit( 0 ); // Never reached--here for language consistency. return 0; } // PrimeThread The dispatcher has to accumulate the results. Our could try using a global variable, but you can run into issues with non-atomic access. Adding 1 might seem a basic operation, but (at least in a RISC system) it takes 3 instructions to add one to a variable in memory: load the data to a register, add the register by 1, and store the register. You can not (without a semaphore) guarantee that those instructions will not be interrupted by an other thread. So, the accumulation happens in just one place—the dispatch loop. The dispatcher will assign all the work, but it is finished once all the work has been assigned. We still need to wait for the work to finish. So the last part of the process looks like this: for ( ThreadIndex = 0; ThreadIndex < NUMBER_OF_THREADS; ++ThreadIndex ) { if ( Data[ ThreadIndex ].NumberToCheck ) { // Wait for thread to finish. pthread_join( Threads[ ThreadIndex ], NULL ); // Accumulate the number of primes found in this thread. NumberOfPrimes += Data[ ThreadIndex ].NumberFound; } } // Let go of dispatch semaphore. sem_destroy( &Semaphore ); Now we can print the results to the screen, and we're done. I knew this code would tax the CPU rather hard, so I wanted to measure how long the process would take. "time.h" is a C standard unit. Unfortunately, "time_spec", which has a high-resolution method for checking the time, it's part of the C99 standard. But we can get time in the resolution of seconds, and that's good enough. To do this, we simply mark the time when the process begins, and mark it again at the end. The difference (for which there is a function to compute) is the total number of seconds that has elapsed. The answer: There are 203,280,221 primes between 2 and 4,294,967,295, and it took 6,054 seconds (1 hour, 41 minutes) on a quad-core clocked at 2.5 GHz. The full source code is here.
|
|
|
So I mentioned yesterday that I wrote a simple program to check to see if some numbers in a list were prime or not. I didn't post it because I wanted to spend a little more time with it—giving it an article on it's own. Finding prime numbers goes back a long time. The easiest way to see if a number is prime is to simply check and see if the number is divisible by all the prime numbers up to the square root of the number in question. A number (call it x) is prime if there are no two number (call them a and b) such that a * b = x. All non-prime numbers can be expressed as the product of two or more prime numbers. For example, 125 can be made from 5 * 25, but 25 can be made from 5 * 5. So 5 * 5 * 5 = 125, and represents the most factored version of 125. This is true of any number. Since it takes at least two prime numbers to create a factor, we only need to check the primes up to √x (or the square root) of the number. This is because the if x = a * a, then √x = a. If x = a * b, and b is greater a, then a must be less then √x. Thus, we only need to check primes up to √x. This makes for a nice brute-force test method, and it's pretty simple to implement. If we're going to test a number, we need all the primes up to the square root of that number. For what I needed, the number was capped at 32-bits—or 232. √232 = (232)1/2 = 216 = 65536. So I need a list of all the prime numbers up to 216. We can make the list fairly quick. Have a look at this function: enum { NUMBER_OF_LOOKUP_PRIMES = 6542 }; unsigned PrimeNumbers[ NUMBER_OF_LOOKUP_PRIMES ]; void GeneratePrimeNumberLookup() { unsigned Index; unsigned PrimeNumberCount = 0; PrimeNumbers[ PrimeNumberCount++ ] = 2; for ( Index = 3; Index < 0x10000ul; ++Index ) { bool IsPrime = true; unsigned SubIndex = 0; while ( ( SubIndex < PrimeNumberCount ) && ( IsPrime ) ) { // Does it divide evenly by this prime number? if ( 0 == ( Index % PrimeNumbers[ SubIndex ] ) ) { IsPrime = false; break; // <- We can stop checking. } ++SubIndex; } if ( IsPrime ) PrimeNumbers[ PrimeNumberCount++ ] = Index; } } We have an array to hold our prime numbers. We set the first entry in the array to two—the first prime number (1 is prime, but who cares). From this, we can test to check the rest of the numbers. We loop from 3 to 216. For each number, we see if any of the primes already in the list will divide evenly into the number under question. If any of them do, they are not prime. It happens that there are 6542 prime numbers between 2 and 216. Knowing that, we can cap the array size of our lookup table at this value—the number of primes in this range will never change. We now have enough prime numbers to check any number up to 232. Unlike the function that generates the prime lookup table, we can throw in one more speed improvement: we only need to check up to the square root of the number in question. So here are the guts of the prime test function: bool IsPrime( uint32_t Number ) { bool IsPrime = true; uint16_t Root = SquareRoot( Number ); unsigned Index = 0; while ( ( Index < NUMBER_OF_LOOKUP_PRIMES ) && ( PrimeNumbers[ Index ] <= Root ) && ( IsPrime ) ) { if ( 0 == ( Number % PrimeNumbers[ Index ] ) ) IsPrime = false; ++Index; } return IsPrime; } Note that can add two short cuts. First, checking up to the root of the number like we discussed. And second, we test to see if the number is even—2 is the only even number that is prime. That's it. Now we have a simple to implement prime number test that works on numbers up to 232. Here is the full source code to a command line version of the test. Compile it, pass it a number (or several), and the program will tell you if the number is prime or not.
(thanks Erica for the correction)
|
|
|
|
|
|