Pump the Prime

Pump the Prime

(can be found in Google Play)

Author: Doug Campbell .... A.K.A Mister iCan

1) Video

Pump the Prime Demo

https://play.google.com/store/apps/details?id=appinventor.ai_docampbell.PumpThePrime

2) Program Purpose and Development

a. Provide a written response to identify the programming language, purpose of the program, and explanation of what the video demonstrates.

Language: App Inventor

Version: #2 (February 2, 2016)

Platform: Android

The Elevator Pitch:

I want to make an app called Pump the Prime. Basically, it will be an app where students can explore prime numbers and ask “what if” types of questions about prime numbers. The app will access basic information about primes to include some key history about prime numbers and their importance. Then students can play with prime numbers. Not only will they be able to tell if a single number is prime, but will be able to enter any number and then generate the sequence of prime numbers after that number one at a time. They will also be able to find and count the primes between a number and the next 1000 integers. Finally, they will be able to explore a random prime generator. I can generate questions about prime numbers, turn students loose with the app, and teach my lessons about prime numbers without inflicting students with another powerpoint adventure. I also plan to use this app when I cover abstraction and algorithms in my programming classes. It provides a range of challenges in case I have some students who quickly master the entry concepts while others struggle.

App Screen Shots:

App Description/Purpose:

This app introduces students to prime numbers. Each button connects a student to a prime number exploration. While there are an infinite number of prime numbers, this app limits students to those less than 1,000,000. The descriptions bellow correspond to the screenshots above. Each screenshot is a destination form one of the event buttons on the home screen. Abot Primes and Prime History open an external browser while all other screens are contained within the app.

  1. Is It Prime allows a student to enter a single number and then find if that number is prime or composite when the pump button is pressed.
  2. The Next Prime allows a student to enter a single number and then find the next prime number larger than that number. Each successive press of the pump yields the next prime in the sequence. You must press start over to start a new sequence. Otherwise, it continues the current sequence even after you enter a new starting number in the input box.
  3. Primes Between allows a student to enter a number and then count and find all of the primes in the next 1000 numbers when the pump button is pressed. Press the pump only once and wait for the app to generate your list. Pressing multiple times will result in the app repeating the same list once for each button press.
  4. Random Prime allows a student to enter an upper limit and find a new random prime number between 1 and the upper limit when the pump is pressed.
  5. About Primes provides links to websites with information about prime numbers.
  6. Prime History provides links to sites that explore the history of how humankind explored prime numbers.

Video Description:

The video shows how a user can navigate to two of the app options from the home screen. First, it demonstrates navigating to the nextPrime screen. The user then enters a number in the text box and then presses a pump to start get the next prime number. It continues the sequence with the next prime number with a reminder of what the previous prime value was. The user can start a new sequence by pressing the start over button and entering a new starting number. The video also shows how the user can access online material, such as the Khan Academy video for prime numbers by pressing the About Primes button and then selecting the Khan Academy option from the list.

b. Program Development:

I used an iterative development process to refine my algorithm for testing whether or not a number is prime. My original concept involved a for loop check whether or not a number could be divided without remainder by any number from 2 to the number - 1. From that point, I did several iterative refinements that included setting the limit on the loop to the square root of the number plus 1 since the largest divisor of any number would be its square root. I then converted my algorithm from a for construct to a while construct. I assumed that a number was prime until I could show, with no remainder, that it was composite. That would allow me to alter the boolean condition to prime is false so that the program would exit the loop and avoid the needless steps in the for loop.

In the Next Prime, Primes Between, and Random Prime features, I had to check a sequence of numbers to see if each of the sequence was prime. Even with my most efficient algorithm, this could take a long time for my mobile device processor, especially for large numbers. I addressed this incrementally by setting an upper limit of 1,000,000 for the app. I then made an iterative refinement. Since all even numbers are automatically composite, I adjusted my sequence to only check odd numbers, eliminating 50% of the needed checks. I did this by revising my starting number for the sequence so that if it was an even number, I added one to make it odd. I then set my for or while loop increment to plus 2. In effect, I could reduce my run time by 50%.


c. Algorithms Working Together (marked in blocks with ovals)

I circled the random prime algorithm contained in Button 1 for the randomPrimes screen. It starts with a number and then identifies the next random number larger than the number entered. Each time the pump is pushed, it continues to the next larger random number. It calls three other algorithms (also circled) that are needed to implement the main algorithm. First, it calls the checkUpperLimit procedure which is a simple algorithm to set an upper limit or cap for the prime number search. Second, it calls the startOdd procedure which is a simple odd-even algorithm designed to make sure the main algorithm only checks odd numbers. Third, it calls the checkPrime procedure to check and see if each of the odd numbers encountered is prime or composite. The three subroutines work independently to accomplish a task and each task is needed for the overall random prime algorithm. All of the smaller routines use mathematical/logical concepts such as if or if/else. The table below highlights the code referenced above.

d. One of My Abstractions Explained:

I have highlighted my checkPrime algorithm and procedure in the Is It Prime feature. The algorithm assumes that the next number to be checked is prime. It then starts by dividing the number by every sequential integer starting with 2 to see if that quotient produces a remainder of 0. If it does, the value of the variable isPrime changes from 1 to 0 to indicate that the assumption that a number is prime is false. It then exits the while loop and proceeds to the next number. If the limit of the square root of the number is reached for the counter in the while loop, it means that the algorithm made it all the way through and did not change isPrime. The conclusion would be that the number must be prime. The procedure made the logic in the button block must simpler. It now follows … get a number … assume it is prime … set the starting counter (the divisor) … check to see if the number is prime … and output the results. A copy of the procedure is included below as well as in the block code at the end of this report.

e. Pump the Prime Code Blocks (The Source Code can be found here.)

Screen 1 / Home Screen

IsItPrime Screen

NextPrime Screen

betweenPrimes Screen

randomPrimes Screen

App Info Screen