This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:discrete:fall2022:projects:cnv2 [2022/11/05 01:31] – [ARRAY-BASED PRIME FACTOR] hcordell | notes:discrete:fall2022:projects:cnv2 [2022/11/09 18:27] (current) – [SIEVE OF ERATOSTHENES] gsuber | ||
---|---|---|---|
Line 5: | Line 5: | ||
====ARRAY-BASED PRIME FACTOR==== | ====ARRAY-BASED PRIME FACTOR==== | ||
- | Focused only on prime numbers | + | For the array optimisation, |
- | Additional optimization level | + | |
- | + | ||
- | Make an array, | + | |
- | + | ||
- | \*\*I will fix these notes later - Ash | + | |
====SIEVE OF ERATOSTHENES==== | ====SIEVE OF ERATOSTHENES==== | ||
The sieve only works with prime numbers, you might find it easier just to create a separate file that contains the code for your sieve of eratosthenes. If you do, add your filename to the end of "BIN = $(PROJ)" | The sieve only works with prime numbers, you might find it easier just to create a separate file that contains the code for your sieve of eratosthenes. If you do, add your filename to the end of "BIN = $(PROJ)" | ||
Line 20: | Line 15: | ||
You have a populated array starting from your checking value to your upper bound. | You have a populated array starting from your checking value to your upper bound. | ||
- | You will cross out all other numbers that are divisible by the number you are checking. | + | You will cross out all other numbers that are divisible by the number you are checking |
This will reduce the numbers you will be checking. Afterwards, move to the your checking number to the next number that is not a crossed out number, and test if that is a prime. If it is, remove that number from the list of available numbers, until you reach the upper bound. Repeat this process until either your quantity or upper bound is reached. | This will reduce the numbers you will be checking. Afterwards, move to the your checking number to the next number that is not a crossed out number, and test if that is a prime. If it is, remove that number from the list of available numbers, until you reach the upper bound. Repeat this process until either your quantity or upper bound is reached. | ||
Line 35: | Line 30: | ||
*For anybody interested in editing the wiki page, here is the dokuwiki user guide: https:// | *For anybody interested in editing the wiki page, here is the dokuwiki user guide: https:// | ||
=====PROGRAM===== | =====PROGRAM===== | ||
+ | If you create a second source file for your sieve, you can include it in the makefile by adding the following line: | ||
+ | < | ||
+ | BIN = $(PROJ) <name of sieve file, without the .c> | ||
+ | </ | ||
+ | Add it below the line that says: | ||
+ | < | ||
+ | BIN = $(PROJ) | ||
+ | </ | ||
+ | |||
+ | For example, if your file is named sieve.c: | ||
+ | < | ||
+ | BIN = $(PROJ) | ||
+ | BIN = $(PROJ) sieve | ||
+ | </ | ||
=====OUTPUT SPECIFICATIONS===== | =====OUTPUT SPECIFICATIONS===== | ||
+ | New functions should output prime numbers, separated by newline characters. This will largely follow the format of the previous iterations of cnv (cnv0, cnv1). | ||
=====VERIFICATION===== | =====VERIFICATION===== | ||
+ | Similar to the other cnvX projects, there is no verification script, or unit test for you to test against. However, cnv2 only deals with prime numbers, so you can test the output against a list of prime numbers. Also, your new optimization, |