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/18 15:03] – [Programs] ktodd3notes:comporg:projects:pnc0 [2018/01/22 13:51] (current) – [Program Output Format] bstrong2
Line 96: Line 96:
 </code> </code>
  
-=====Programs - Pick at least 5===== +=====Program Specifications===== 
-**primereg** - baseline program (Brute force, no break)\\ \\ +**You must write AT LEAST 5 of the choices below.**\\ 
-**primeregs** - baseline, plus square root trick (Use <cmath> header for sqrt())\\ \\ +** primereg.c / primeregb.c / primeregs.c / primeregbs.c are all REQUIRED** 
-**primeregb** - baseline, plus break on composite\\ \\ + 
-**primeregbs** - baseline, plus square root trick, plus break on composite\\ \\+**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. 
 + 
 +**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.c** - baseline program (Brute force, no break)\\ \\ 
 +**primeregs.c** - baseline, plus square root trick (Use <cmath> or <math.h> header for sqrt())\\ \\ 
 +**primeregb.c** - baseline, 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+**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.
  
  
-=====Program Format===== +=====Program Output Format===== 
-**./primereg numberOfPrimes **\\ +<cli> 
-The argument notates how many primes (starting from 2) that you want to print.  \\  +lab46:~/src/comporg/pnc0/gcc$ ./primereg 
-Example: ./primereg 8 results in printing out: 2 3 5 7 11 13 17 19 \\ +2 3 5 7 11 13 17 19 
-\\+  0.0001 
 +lab46:~/src/comporg/pnc0/gcc$ 
 +</cli> 
 + 
 +The primereg files will take One argument.  That argument (argv[1]) will be for QUANTITY.\\ 
 +Clarification: How many primes (starting from 2) that you want to print.  \\  
 -**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** \\ 
--Use **pncrun** executable to test programs+ 
 +=====Testing===== 
 +To test your output of STDERR vs STDOUT:\\ 
 +Redirect your STDERR to **/dev/null** to only output the STDOUT to terminal 
 +<cli> 
 +lab46:~/src/comporg/pnc0/gcc$ ./primereg 8 2> /dev/null 
 +  0.0001 
 +lab46:~/src/comporg/pnc0/gcc$ 
 +</cli> 
 +Redirect your STDOUT to **/dev/null** to only output the STDERR to terminal 
 +<cli> 
 +lab46:~/src/comporg/pnc0/gcc$ ./primereg 8 > /dev/null 
 +2 3 5 7 11 13 17 19 
 +lab46:~/src/comporg/pnc0/gcc$ 
 +</cli> 
 + 
 +To test your output time tests you can do the following:\\ 
 +<cli> 
 +lab46:~/src/comporg/pnc0$ ./pncrun 
 +</cli> 
 + 
 +Also do not forget about error checking!\\ 
 +EXAMPLE:\\ 
 +<cli> 
 +lab46:~/src/comporg/pnc0/gcc$ ./primereg 
 +Incorrect Number of Arguments! 
 +./primereg QUANTITY 
 +lab46:~/src/comporg/pnc0/gcc$ 
 +</cli> 
 + 
 +=====Submission===== 
 +To submit, run:\\ 
 +<cli> 
 +lab46:~/src/comporg/pnc0$ make submit  
 +</cli> 
 + 
 + 
 +if you run into trouble edit the makefile and on line 47 where it says "save: clean" remove the word "clean" 
 + 
 +Also you can try  
 +<cli> 
 +lab46:~/src/comporg/pnc0$ make update 
 +</cli>
notes/comporg/projects/pnc0.1516287783.txt.gz · Last modified: 2018/01/18 15:03 by ktodd3