hello everyone
So i have a project to do a code about using these powers of three numbers: 1, 3, 9, 27, and 81 (we dont have to use all and a number of them can only be used up to one time per number being decomposed) and use them to decompose numbers from -121 to 121. I brainstormed everything and discovered some patterns, and there is intervals given for us as hints:
[-121,-41], [-40, -14], [-13, -5], [-4, -2], [-1, -1], [1, 1], [2, 4], [5, 13], [14, 40], and [41, 121].
So if we take 5 till 14 for instance, we notice that 5 decomposes to 9-3-1. 6=9-3. 7=9-3+1. 8=9-1. 9=9. 10=9+1. 11=9+3-1. 12=9+3. 13=9+3+1. and 14=27-9-3-1
notice that 14 starts with 27, the next power of 3 number, yet it just takes the characteristic of the numbers before it (9-3-1). also, if you notice, at 9, the decomposition is just 9. if you look before 9, so from 5-8, and after 9, 10-13, you find that the signs are opposite, but numbers are same. so this proves same for all other intervals (of course different numbers, but for the 14-40 interval, at 27=27, the numbers before 27 will be same as numbers after, except opposite signs.)
so, thats my thinking and breaking of the problem. i know i am on the right track. and i even started the following code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x;
int p3n[10] = { -81, -27, -9, -3, -1, 1, 3, 9, 27, 81 };
cin >> x;
int interval_1[2] = { 1, 1 };
int interval_2[3] = { 2, 3, 4 };
int interval_3[9] = { 5, 6, 7, 8, 9, 10, 11, 12, 13 };
int interval_4[27] = { 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
int interval_5[]
for (x = 0; x >= -121 || x <= 121; x++)
{
cout <<
}
system("pause");
return 0;
}
so the idea is to grab a number based on the user's input and somehow relate it to the powers of 3 array (p3n). i created arrays for all intervals to make some kind of coding sequence like the one i explained above, but in code. I am still weak at programming, so I hope I provided something that proves I am not here for code, rather, just some help on how to continue. showing me some code will help a lot, i never copy code, but showing me will better make me understand what you might propose as an answer.
also, I have a question: as you see, i am trying to write every single number for each interval in the array elements. the first 3 was easy, but the 2 others get sooooo long! is there a way to make it like for the array that has about 27 elements make it like 14, 15, then ...40 at the end in simple short way, or i have to define every single element?