This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:discrete:fall2021:projects:pnf0 [2021/08/28 14:21] – additional usage section work aholmes9 | notes:discrete:fall2021:projects:pnf0 [2021/09/05 12:05] (current) – [Submission] wedge | ||
---|---|---|---|
Line 7: | Line 7: | ||
=====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 24: | Line 25: | ||
====TIC80==== | ====TIC80==== | ||
- | TIC80 works on a system of **carts**. The carts present on a system can be listed via a familiar call to `ls`, or, at a more involved level, the system folder which TIC80 uses to store its data can be accessed via the `folder` command in the TIC80 terminal. The code content of these cards after `load`ing them can be accessed by pressing [ESC] from the terminal, opening the included basic IDE equipped with a code, sprite, map, sfx, and music editor. | + | TIC80 works on a system of **carts**. The carts present on a system can be listed via a familiar call to `ls`, or, at a more involved level, the system folder which TIC80 uses to store its data can be accessed via the `folder` command in the TIC80 terminal. A new cart can be made with the `new` command, and the loaded cart can be saved via the `save` command. The code content of these cards after `load`ing them can be accessed by pressing [ESC] from the terminal, opening the included basic IDE equipped with a code, sprite, map, sfx, and music editor. |
The **code editor** is relatively simple: 64KB are allotted for a script written in any of: Lua, JavaScript, Moonscript, Wren, Fennel, and Squirrel. External packages may also be used to allow for the usage of more languages. The first step in writing a basic program in TIC80 is to supply a series of comments (formatted in the choice language) which allow TIC80 to ascertain four pieces of metadata, as in: | The **code editor** is relatively simple: 64KB are allotted for a script written in any of: Lua, JavaScript, Moonscript, Wren, Fennel, and Squirrel. External packages may also be used to allow for the usage of more languages. The first step in writing a basic program in TIC80 is to supply a series of comments (formatted in the choice language) which allow TIC80 to ascertain four pieces of metadata, as in: | ||
Line 41: | Line 42: | ||
for JavaScript, and so on. | for JavaScript, and so on. | ||
- | Once a language is selected, a developer will need to include a `TIC()` function. This is essentially the " | + | Once a language is selected, a developer will need to include a `TIC()` function. This is essentially the " |
data and resets to blank. | data and resets to blank. | ||
+ | |||
====Priminality==== | ====Priminality==== | ||
+ | |||
=====Specifications===== | =====Specifications===== | ||
Line 57: | Line 60: | ||
- If prime, positive output (e.g. rainbow/ | - If prime, positive output (e.g. rainbow/ | ||
- If composite, negative/ | - If composite, negative/ | ||
+ | |||
+ | ====Input==== | ||
+ | |||
====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 // | ||
+ | |||
+ | 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? | ||
====Display==== | ====Display==== | ||
+ | |||
+ | The `print` function can be used to print text on the screen, but it also returns the width of the text. For example, `local string=print(" | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | The `time` function returns the current run-time of the program in milliseconds. This is useful in a variety of circumstances; | ||
=====References===== | =====References===== | ||
+ | |||
+ | https:// | ||
+ | |||
+ | http:// | ||
+ | |||
+ | =====Submission===== | ||
+ | To submit, provide your tic file using the **submit** tool on lab46. | ||
+ | |||
+ | I'll be looking for the following: | ||
+ | |||
+ | < | ||
+ | 65: | ||
+ | *:pnf0:no errors, program runs in TIC-80 [13/13] | ||
+ | *:pnf0: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 |