This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:discrete:fall2021:projects:pnf1 [2021/08/31 21:25] – stepping-suggestion aholmes9 | notes:discrete:fall2021:projects:pnf1 [2021/09/09 03:59] (current) – [Prime Detection Algorithm] mbrill1 | ||
---|---|---|---|
Line 4: | Line 4: | ||
</ | </ | ||
- | ======PROJECT: | + | ======PROJECT: |
=====Objective===== | =====Objective===== | ||
+ | |||
Using the TIC-80 fantasy console simulator on your pi, implement a program that visually displays a range of values (lower and upper bounds adjustable by the user) that colorfully displays whether each value is a **prime** or **composite** value. | Using the TIC-80 fantasy console simulator on your pi, implement a program that visually displays a range of values (lower and upper bounds adjustable by the user) that colorfully displays whether each value is a **prime** or **composite** value. | ||
Line 37: | Line 38: | ||
* ask copious, clarifying questions (so you can better add content) | * ask copious, clarifying questions (so you can better add content) | ||
* craft a coherent and organized document, with information located under pertinent headings | * craft a coherent and organized document, with information located under pertinent headings | ||
- | * explain the fundamentals of the process, conceptual background, algorithmic approach, and you can even suggest particulars related to TIC-80 (certain functions that might prove useful- individual, unrelated snippets to do things like capturing time, or displaying text, etc.) | + | * explain the fundamentals of the process, conceptual background, algorithmic approach, and you can even suggest particulars related to TIC-80 (certain functions that might prove useful- individual, unrelated snippets to do things like capturing time or displaying text, etc.) |
* to get full credit, each individual that submits must perform no fewer than 4 changes to this document (as viewable from the wiki revision system). Failure to do so will result in documentation penalties being applied. | * to get full credit, each individual that submits must perform no fewer than 4 changes to this document (as viewable from the wiki revision system). Failure to do so will result in documentation penalties being applied. | ||
Line 69: | Line 70: | ||
An effective way of going about this project is to allow the prime detection algorithm to " | An effective way of going about this project is to allow the prime detection algorithm to " | ||
+ | |||
====Prime Detection Algorithm==== | ====Prime Detection Algorithm==== | ||
+ | |||
+ | Before we can jump into how to //program// our prime number detection algorithm, we must understand the basic rules of prime numbers. | ||
+ | |||
+ | Prime Numbers Must Be: | ||
+ | * In the set of natural/ | ||
+ | * Greater than the number 1. | ||
+ | * Factorable by only two natural/ | ||
+ | |||
+ | With your knowledge of programming and the rules of prime numbers, you should be able to make a detection algorithm now! There are different computational methods for figuring out the primality of a number, we will take a look at one of the simplest ones first (more may be added in the future to this page). | ||
+ | |||
+ | ===Trial-By-Division Algorithm=== | ||
+ | |||
+ | One of the most basic methods of checking the primality of a number, this method relies on dividing a given number by the numbers in a set range. This is to see if any numbers in that range divide the given number cleanly; //no remainders exist in the mathematical output//. Clean division is a sign of a **composite** number. | ||
+ | |||
+ | Let's assume we have an integer, //n//, in order to see if //n// is a prime number we should first determine our lower and upper bounds for the division test(s): | ||
+ | * Lower bound: 2 | ||
+ | * Upper bound: < | ||
+ | * If taking unoptimized route, upper bound can just be //n - 1//. | ||
+ | |||
+ | Both of these bounds may be confusing, let me explain... | ||
+ | |||
+ | For our lower bound, we most definitely want to start on the lowest number possible. Since we know that the potential factors for our integer, //n//, must be natural/ | ||
+ | |||
+ | Hopefully, you understand why starting at 0 for **division tests** would not be such a good idea. Starting at 1 would be superfluous; | ||
+ | |||
+ | For our upper bound, we want to prioritize testing to what we // | ||
+ | |||
+ | We must consider other options, optimizations, | ||
+ | |||
+ | Now that you understand the general process of this algorithm, and what its lower and upper bounds should be, you can finally get into writing this algorithm. Here are a few concluding questions: | ||
+ | * How can we test if a number divides cleanly by //n//? | ||
+ | * Hint: remainder " | ||
+ | * How can we implement a square root in our code for the upper bound? | ||
+ | * How do we deal with testing the numbers 0 and 1? | ||
==Optional Functionality== | ==Optional Functionality== | ||
+ | |||
This can be relatively simply and familiarly implemented (at a high level) in the way that the **chmod** accepts permission codes. By assigning each optional optimization to a number (in binary terms, starting with 1, 2, 4, 8, 16, ...) and passing the set of selected optimizations as the sum of those selected numbers, the algorithm can handle, in a way of limited individual variables, optional functions. At runtime, these can be checked from greatest to least: if the options argument is a number greater than the number corresponding to the biggest number, perform that operation, and subtract that value from the argument, then move on to the next-biggest, | This can be relatively simply and familiarly implemented (at a high level) in the way that the **chmod** accepts permission codes. By assigning each optional optimization to a number (in binary terms, starting with 1, 2, 4, 8, 16, ...) and passing the set of selected optimizations as the sum of those selected numbers, the algorithm can handle, in a way of limited individual variables, optional functions. At runtime, these can be checked from greatest to least: if the options argument is a number greater than the number corresponding to the biggest number, perform that operation, and subtract that value from the argument, then move on to the next-biggest, | ||
In the case of Break, Odds, and Square Root methodology, | In the case of Break, Odds, and Square Root methodology, | ||
+ | |||
+ | ==If Statements== | ||
+ | |||
+ | An if statement can be used to accept two conditions instead of just one. In Lua, this is accomplished with `and.` As an example, `if a==2 and b==3 then` only performs an action if a=2 and b=3. This is useful for having multiple menus and deciding which sub-menu to display. It can also be used in conjunction with Optional Functionality. | ||
+ | |||
+ | |||
+ | ====Break On Composite Algorithm==== | ||
+ | |||
+ | The idea of the "break on composite algorithm", | ||
====Display==== | ====Display==== | ||
=====References===== | =====References===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | =====Submission===== | ||
+ | |||
+ | I'll be looking for the following: | ||
+ | |||
+ | < | ||
+ | 78: | ||
+ | *:pnf1:no errors, program runs in TIC-80 [13/13] | ||
+ | *:pnf1:user can specify lower and upper bounds at runtime [13/13] | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | </ | ||
+ | |||
+ | Additionally: | ||
+ | * Solutions not abiding by **SPIRIT** of project will be subject to a 25% overall deduction | ||
+ | * Solutions not utilizing descriptive why and how **COMMENTS** will be subject to a 25% overall deduction | ||
+ | * Solutions not utilizing **INDENTATION** to promote scope and clarity will be subject to a 25% overall deduction | ||
+ | * Solutions lacking **ORGANIZATION** and are not easy to read (within 90 char width) are subject to a 25% overall deduction |