So I tried to make a program that is about Multiplication Consistency. However, that required me to use large numbers. I decided to implement my own structure for handling them, as I thought it would be better to use something customized for the program. But I managed to design two ways to handle big numbers, and I do not know which is better for this case.
The program does a lot of divisions and number generation, without too much printing.
Number generation is done by taking a number, that is the multiplication of powers of 2, 3, 5 and 7 (2^a * 3*b * 5^c * 7^d) and generates all numbers, where the multiplication of the digits equals that number, excluding numbers containing 1s, because such digits can be added infinitely. Generation here is handled recursively, so I do not generate new numbers from scratch.
Once a number is generated, it is tested by which powers of 2, 3, 5 and 7 it is divisible, which is where the program does the divisions. This is where most of the program's work is done.
So, I came up with two ways to handle numbers: a straightforward string of single digits and the structure n * INT + k
(n times the max integer value plus a smaller number; INT does not have to be explicitly int32
).
Which would be faster?
Digits array:
- Each digit is a number, so working with the string is working with numbers
- Printing is as simple as printing an array
- Division can be done with integers up to 9, or with other strings
- The more digits, the longer the division process
- Numbers are easy to build
- Practically no limit to the length of the number
- Testing if the number is divisible by some numbers (3, 9, 2^n and 5^n) can be sped up by looking at the digits, but that can become complex to implement
Division with this solution is done by scanning the array.
n * INT + k
- The structure is about values
- Printing requires to turn the values into a digit string
- Division can be done with integers up to the maximum value, and each division makes the number smaller for further divisions
- The larger the values, the slower the process
- Numbers require a special algorithm to build
- Maximum value is INT * INT + INT, so going around that limit would require further development
- No digits, so testing for divisibility is done by dividing
Division of this structure is recursive: The result of the division is (n / d) * INT + k / d
with a remain of (n % d) * INT + k % d
. The remain is a number on its own, so it is further divided and the new result is added to the first.
I must note that I have not implemented dividing big numbers by big numbers, so big numbers get divided only by integers.
While the array of digits requires a lot of scanning while dividing, the other option can be slow at first, but the number can be tested for division with much larger numbers, which can quickly lower the value, and such divisions are faster on their own.
How are the two solutions compared?