This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:discrete:fall2021:projects:saf1 [2021/10/06 03:21] – Added submission requirement that tic file needs to be on lab46 smalik3 | notes:discrete:fall2021:projects:saf1 [2021/10/07 03:13] (current) – [Display] ccolocci | ||
---|---|---|---|
Line 7: | Line 7: | ||
=====Objective===== | =====Objective===== | ||
+ | |||
Using the TIC-80 fantasy console simulator on your pi, implement a program that performs a sorting of a randomized list of values, both displaying an animation of the sort, along with timing and keeping track of the approximate number of steps needed to accomplish the task for variable numbers of non-animated runtimes. | Using the TIC-80 fantasy console simulator on your pi, implement a program that performs a sorting of a randomized list of values, both displaying an animation of the sort, along with timing and keeping track of the approximate number of steps needed to accomplish the task for variable numbers of non-animated runtimes. | ||
Line 27: | Line 28: | ||
====Process==== | ====Process==== | ||
+ | |||
+ | ==Randomness in Lua== | ||
+ | |||
+ | As with the projects before, `math.random()` can be used to generate random values for the array. It may also have a different purpose depending on how you approach this project. While there are many ways to show the algorithms... rinse and repeat, or do a brand new array... one can use `math.random()` to randomize which algorithm is used to sort the array upon each new initialized array. | ||
+ | |||
==Bubble Sort== | ==Bubble Sort== | ||
Line 56: | Line 62: | ||
{2 3 5 7 9} -> {2 3 5 7 9} | {2 3 5 7 9} -> {2 3 5 7 9} | ||
</ | </ | ||
- | You will notice that, in this specific example, the algorithm had to sweep through 5 times in order to reach the final result. You will also notice that the complete sorting was finished after pass 4, but the algorithm did a 5th one as well. This is because the algorithm has to do one whole pass without doing a swap in order for it to be considered a successful sort. | + | You will notice that, in this specific example, the algorithm had to sweep through 5 times in order to reach the final result. You will also notice that the complete sorting was finished after pass 4, but the algorithm did a 5th one as well. This is because the algorithm has to do one whole pass without doing a swap in order for it to be considered a successful sort. You will soon read about an algorithm (next algorithm) that is very similar, except far more robust and faster. |
==Selection Sort== | ==Selection Sort== | ||
Line 101: | Line 107: | ||
Insertion sort somewhat combines the incremental nature of bubble sort with the position-seeking ideas of selection sort. In insertion sort, the list is searched for the first element which is out of order (in our case, the first element which is lower than its predecessor) and then it is moved downward until it reaches a point where the element below it has a value which is lower than its own. Once that point is reached, it will continue searching for the initial situation of a lesser ancestor from the point which was reached in the previous operation and repeat until the last element is reached. | Insertion sort somewhat combines the incremental nature of bubble sort with the position-seeking ideas of selection sort. In insertion sort, the list is searched for the first element which is out of order (in our case, the first element which is lower than its predecessor) and then it is moved downward until it reaches a point where the element below it has a value which is lower than its own. Once that point is reached, it will continue searching for the initial situation of a lesser ancestor from the point which was reached in the previous operation and repeat until the last element is reached. | ||
+ | |||
====Display==== | ====Display==== | ||
+ | |||
+ | In order to meet project specifications, | ||
+ | |||
==A Note on the Print Function== | ==A Note on the Print Function== | ||
print() is a very versatile tool; there are so many things to play around with and so many different arguments to take advantage of. For example, these are the arguments for print(): text [x=0 y=0] [color=12] [fixed=false] [scale=1] [smallfont=false]. The first three are pretty self-explanatory, | print() is a very versatile tool; there are so many things to play around with and so many different arguments to take advantage of. For example, these are the arguments for print(): text [x=0 y=0] [color=12] [fixed=false] [scale=1] [smallfont=false]. The first three are pretty self-explanatory, | ||
+ | |||
+ | Alternatively, | ||
=====References===== | =====References===== | ||
https:// | https:// | ||
+ | |||
+ | https:// | ||
https:// | https:// | ||
Line 114: | Line 128: | ||
https:// | https:// | ||
+ | https:// | ||
=====Submission===== | =====Submission===== | ||