Making a factoring calculator

275 views
Skip to first unread message

DaVe

unread,
Jul 29, 2018, 10:20:37 PM7/29/18
to MIT App Inventor Forum
Hey I am working on a making a program that can find the factors of numbers. I really need help if anyone know how to do this please let me know or share a picture of the code.

TimAI2

unread,
Jul 30, 2018, 3:35:43 AM7/30/18
to MIT App Inventor Forum
This approach seems most programmable:

"

How to Factor Numbers: Factorization

This factors calculator factors numbers by trial division. Follow these steps to use trial division to find the factors of a number.

  1. Find the square root of the integer number n and round down to the closest whole number. Let's call this number s.
  2. Start with the number 1 and find the corresponding factor pair: n ÷ 1 = n. So 1 and n are a factor pair because division results in a whole number with zero remainder.
  3. Do the same with the number 2 and proceed testing all integers (n ÷ 2, n ÷ 3, n ÷ 4... n ÷ s) up through the square root rounded to s. Record the factor pairs where division results in whole integer numbers with zero remainders.
  4. When you reach n ÷ s and you have recorded all factor pairs you have successfully factored the number n.
"

Use the remainder block to identify factors, the maths blocks and a looping procedure should do the rest.

TimAI2

unread,
Jul 30, 2018, 4:10:38 AM7/30/18
to MIT App Inventor Forum
Here are the basics, a bit more work to do to order the list and remove duplicates.


TimAI2

unread,
Jul 30, 2018, 4:36:15 AM7/30/18
to mitappinv...@googlegroups.com
Hopefully the full requirement, using Imaginity's bubble sort method (more blocks than the rest of the aia!)


aia attached


note: you could avoid using the sort method by inserting the factors to the middle of the list, instead of adding to the end


factors.aia

TimAI2

unread,
Jul 30, 2018, 4:54:22 AM7/30/18
to MIT App Inventor Forum
Without the sort method, but inserting to centre of list


Abraham Getzler

unread,
Jul 30, 2018, 9:50:53 AM7/30/18
to MIT App Inventor Forum
How big a number do you want to factor?

For tremendous numbers, to avoid having your   app go
unresponsive, you would have to break up the work into chunks
dribbled out under control of a Clock Timer.

The attached app solves a different problem, finding all the primes up to a limit,
but it shows the Clock Timer technique.

ABG

2016-10-10 11_26_33-5554__build_.png
2016-10-10 11_28_04-5554__build_.png
2016-10-10 11_30_17-5554__build_.png
blocks.png
Designer.png
SieveV2.aia

SteveJG

unread,
Jul 30, 2018, 10:16:06 AM7/30/18
to MIT App Inventor Forum
This probably would work using the  mXparser library


Use the Math Expression Parser of               http://mathparser.org/ 

that Taifun has created an extension for       https://puravidaapps.com/math.php  

be used.  You will have to experiment.

Regards,
Steve

Juan Antonio

unread,
Jul 30, 2018, 10:28:07 AM7/30/18
to MIT App Inventor Forum
Other code:


p49b_divisoresi.aia

TimAI2

unread,
Jul 30, 2018, 10:57:27 AM7/30/18
to MIT App Inventor Forum
^^^ nice :)

Juan Antonio

unread,
Jul 30, 2018, 12:21:36 PM7/30/18
to mitappinv...@googlegroups.com
Thank you Tim.

Only curiosity, find primes by JavaScript, very fast:
Reply all
Reply to author
Forward
0 new messages