User Tools

Site Tools


notes:comporg:projects:pnc0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:comporg:projects:pnc0 [2018/01/21 01:43] – [Program Specifications] ahought2notes:comporg:projects:pnc0 [2018/01/22 13:51] (current) – [Program Output Format] bstrong2
Line 100: Line 100:
 ** primereg.c / primeregb.c / primeregs.c / primeregbs.c are all REQUIRED** ** primereg.c / primeregb.c / primeregs.c / primeregbs.c are all REQUIRED**
  
-Break on composite Once you can determine a number is NOT prime you can break from the the rest of the checks.  For example if you are checking if 25 is prime number, you can start by checking if 2 is a factor of 20 then 3, 4, and 5.  Once you hit 5 you see this is NOT prime.  Then you do not need to calculate the rest of the checks: 6, 7, 8, 9 etc...+**Brute Force** This is the no optimization method.  Check 2 - quantity and check all factors of the prime as stated ABOVE.  You do NOT break once you find a number is prime you continue through checking every single check.  For example:  25 will check all numbers from 2 - 24, you will not break once you get to 5.
  
-Square root trickYou can use the <math.h> include file with **sqrt()** function or approximate the square root process using logic (this could potentially save runtime because you are not checking as many things as the sqrt function would check through).  The premisis is that you only need to check factors of a number up until the Square root of that number.  For example the square root of 25 is 5.  This tells us that you only need to check factors 2 through 5 to find if this number is a prime or not.+**Break on composite** - Once you can determine a number is NOT prime you can break from the the rest of the checks.  For example if you are checking if 25 is a prime number, you can start by checking if 2 is a factor of 20 then 3, 4, and 5.  Once you hit 5 you see this is NOT prime.  Then you do not need to calculate the rest of the checks: 6, 7, 8, 9 etc... 
 + 
 +**Square root trick** - You can use the <math.h> include file with **sqrt()** function or approximate the square root process using logic (this could potentially save runtime because you are not checking as many things as the sqrt function would check through).  The premisis is that you only need to check factors of a number up until the Square root of that number.  For example the square root of 25 is 5.  This tells us that you only need to check factors 2 through 5 to find if this number is a prime or not
 +<code> 
 +#include <math.h> 
 +</code> 
 + 
 +**sqrt()-less square root approximation (a)-** This is optional, you would do this instead of the sqrt() function. (If you've taken discrete then you know how to do it, if you haven't taken discrete and are looking for moar then this is an option.) The sqrt function in the math library does an exact calculation of a square root. Since we are only dealing with whole numbers for our prime project it is possible to create your own logic to approximate the square root. Since the sqrt function will run for every number that is being checked you are looking at quite a performance increase.
 ---- ----
-**primereg** - baseline program (Brute force, no break)\\ \\ +**primereg.c** - baseline program (Brute force, no break)\\ \\ 
-**primeregs** - baseline, plus square root trick (Use <cmath> or <math.h> header for sqrt())\\ \\ +**primeregs.c** - baseline, plus square root trick (Use <cmath> or <math.h> header for sqrt())\\ \\ 
-**primeregb** - baseline, plus break on composite\\ \\ +**primeregb.c** - baseline, plus break on composite\\ \\ 
-**primeregbs** - baseline, plus square root trick, plus break on composite\\ \\+**primeregbs.c** - baseline, plus square root trick, plus break on composite\\ \\
 **__Choice of A, R, or L__** \\ **__Choice of A, R, or L__** \\
-**primeregAbs** - baseline, array, square root trick, break on composite \\ \\+**primeregAbs.c** - baseline, array, square root trick, break on composite \\ \\
 **Note**: (Store prime divisors into array and check against the array) \\  **Note**: (Store prime divisors into array and check against the array) \\ 
 Array size(amount of elements) == argument 1(number of primes) \\ \\ Array size(amount of elements) == argument 1(number of primes) \\ \\
-**primeregRbs** - Recursive brain melter ? \\ +**primeregRbs.c** - Recursive brain melter ? \\ 
-**primeregLbs** - Linked List - similar to primeregAbs - save primes in a linked list rather than an array.  Also include the break on composite and square root trick.+**primeregLbs.c** - Linked List - similar to primeregAbs - save primes in a linked list rather than an array.  Also include the break on composite and square root trick.
  
  
Line 128: Line 135:
  
 -**Put all c files in gcc directory from pnc0 grabit** \\ -**Put all c files in gcc directory from pnc0 grabit** \\
--Numbers go to stderr, time goes to stdout \\+-Numbers go to stderr, **time goes to stdout** \\
  
 =====Testing===== =====Testing=====
notes/comporg/projects/pnc0.1516499028.txt.gz · Last modified: 2018/01/21 01:43 by ahought2