Factoring of numbers

Arrojeria, Eustakio

Elhuyar Zientziaren Komunikazioa

Lizaso, Pili

Informatika Saila

Elhuyar Fundazioa

Factoring numbers is not a complicated task, so writing a computer program that does it can be relatively simple.

However, although in many cases it is interesting that the computer itself makes some estimates and returns the results obtained, in other cases the user can also assume the role of simple observer and in order to avoid it, we try to demand the results to the user itself in our programs.

It is known that such programs make things difficult or at least make writing longer programs. Why?

The user normally does not have the answers correctly, with a single space, sorted, etc. there will be custom to enter, but you cannot be told that the answer you have entered is wrong.

For example:

228 factorization 2 2 . 3. It is 19 but the user 228 = 3 . 19. You can enter 2 2 and the answer would be correct.

At this point, the decision is usually made to clearly indicate to the user the rules that must be met when entering the answers or to leave the freedom to enter the way in which he wishes to do so (even if it is not complete).

When making this decision it is necessary to take into account, of course, that you must interpret the second way in order to check whether or not it fits your result.

The reason for this is that most of the program we are dealing with is aimed at interpreting the user's response.

The program is as follows:

Parts of the program:

  • 70-210: Create a random number from 1 to 9999 and break it down into factors.
    Factors are saved in table Z. Each of the components in this table consists of three elements:
    • Z (I,1) Own coefficient
    • Z (I,2) Letter of factor I (exponent)
    • Z (I,3) It will indicate whether this factor is invented or not.
  • 220-460: It takes control of the keys pressed by the user until the user press RETURN. The available keys, Ø, are the delete key and the numbers.
  • 470-670: The user-entered string is divided and stored as a factor in table S, i.e. exponent S (I,1) and exponent S (I,2), pairs.
  • 680-980: The program result (Z) is compared to the user result (S) and the corresponding message (680-790) is delivered. In
    any case the correct result will be shown (800-980).

Note:


In this case, the numbers are taken randomly and the resulting number can be very large, very small or be the number first. This is easy to solve if we calculate the number by multiplying by three random. Try it!

Babesleak
Eusko Jaurlaritzako Industria, Merkataritza eta Turismo Saila