I know that we are allowed to ask questions about math and science but are we allowed to ask computer science. I am having trouble with bases and this question i cant understand the basic idea of what to program around:
Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic when expressed in base B; also print the value of that palindromic square. Use the letters 'A', 'B', and so on to represent the digits 10, 11, and so on.
what does this mean. I cant figure out where to start because this context of the question is confusing me. Can someone explain?
Don’t know where this is from, but their phrasing is annoying. Ok, here goes.
When it’s talking about the square being palindromic, it means it is the same forwards and backwards, e.g. 1794683864971. As for the number base stuff, I have no clue. Speaking of which, what language are you using? It seems like base code, which is only really useful to my brethren, the Hackers.
Sorry I couldn’t be much help! If you reply w/ more info, I’ll try to follow up.
I'm using Java for it i know im suppose to check if the square is a palindrome and by that i should have an array with the values and a loop to reverse the order. If they match before and after then it is a palindromic square. But i am confused about the base is the base 1-20? and then what does the integers mean? what are they?
Here’s a basic outline for your assignment. The actual coding depends on the language used.
Define and Create arrays: Numeric N(300,2), String BC(300,20). The first is a 2-dimeintional numeric array (named N) with two columns of 300 elements. The second is a string array (named BC) of 20 columns of 300 elements.
Generate numbers from 1 to 300 (base 10). Store these numbers sequentially in column (1) of array N(i,1) “N” is the name of the array and (i) is the location in the array, and the (1) means the first column.
Using a sequential loop process, square the number stored in array N(i,1) and store it in array N(i,2).
Call subroutine Base Number Conversion.
This will be the most complex part of your program. Here, your code will convert and populate the string array with the base_b equivalent of the number (N2) storing it in the location determined by (i).
BC(i,1) is the index and the number N. BC(i,10) will be the base 10 location. This will not require a base conversion but may (depending on the language used) need to be explicitly converted to a string format to store it here.
The other columns will have the square of this Number in the corresponding bases. BC(i,2) is the location for N2 in base 2 (binary). BC(i,3) is the location for N2 in base 3. BC(i,4) is the location for N2 in base 4, etc.
There are several algorithms for converting a decimal number to base (b).
Some languages have built-in subroutines for the common Hex and Binary base conversions, and some will do any base up to base 64. Your teacher/professor will probably want you to write your own code for these conversions.
The easiest method that’s conveniently suitable is the divide, subtract and multiply method.
Create a 20 element array to store the remainders. (The largest string will be 17 characters for the conversion of N=300; 3002 = 9000010 = 101011111100100002)
For any given base, the elements of the array will store the decimal value of each digit of base (b). The values are stored ascending in base 10, but the implied value for each element is
[D1 * b0] [D2 * b1], [D3 * b2], [D4 * b3], [D5 * b4], ..., ect where b is the base
Here’s an example converting 71298 (the square of 267) to base 17.
You can code separate subroutines for each base, or increment an index variable for the base divisor. The process is the same for each base. .
This is gives a sequential overview of how the variable data in the loop would present if they were examined at each step of the loop. These are the same lines of code repeated until a zero integer is returned. It is four times for this example.
Divide: 71298/17 = 4193.470588235 | separate the integer and fractional portions.
Subtract: 4193.470588235 -4193 = 0.470588235 | giving fractional portion
Multiply: 0.470588235 * 17 = 8 | Store in D1 (8 * 170) <-- implied base 17
Divide: 4193/17 = 246.6470588235
Subtract: 246.6470588235-246 = 0.6470588235
Multiply: 0.6470588235 * 17 = 11 | Store in D2 (11 * 171)
Divide: 246/17 = 14.47058823529
Subtract: 14.47058823529 - 14 = 0.47058823529
Multiply: 0.47058823529 * 17 = 8 | Store in D3 (8 * 172)
Divide: 14/17 = 0.82352941176
Subtract: 0.82352941176- 0 = 0.82352941176
Multiply: 0.82352941176 * 17 = 14 |store this in D2 (14 * 173)
End subroutine here if integer is (0). Then Convert and concatenate the numeric characters, then store in string array BC(N,B).
When a value exceeds (910) A, B, C will be used in its stead.
Read values in array D(p) |where p is the index position and p=1 is the least significant digit.
If D(p) < 10 then move D(p) to C(p) array. |IF a number less than 10 then move the number.
V=D(p) -10 on V move “A” , “B”, “C”, ect to C(p) | If a number greater than 9 then move the corresponding letter to concatenation array.
The “8” is copied as is, and 14 corresponds to “E” and 11 corresponds to “B”
After the loop completes, reverse the string so the lesser significant digits are to the right of the more significant digits, then store in string array BC(276,17). The language you use may have a library function to do this. The alpha-numeric number stored is E8B8.
Remember to clear the temporary concatenation array after each call to the subroutine; else you will have rubbish in some of your conversions.
Go to next loop for next base, do the same bloody thing until the base is greater than 20.
Then Loop until N > 300
After the main array is populated with the data, then it is a simple matter to look for numerical palindromes. The language you use may have a library function to reverse the string, or use the same code used in the convert and concatenate subroutine. Compare these two strings, if they match then move the relevant data to the screen or print array
This basic explanation of the algorithms involved may give the impression this is complicated, but this is simple to code.
Can you please explain bases are. In your example you have written "71298 (the square of 267) to base 17" What does this mean and how did you know to divide it by 17 as the base? In the question they provide a base.
Like an example input would be 10 and the output would be:
Like my ideas right now in java would be
BufferedReader br = new BufferedReader(new FileReader("palindromic.in"));
String reader = br.readLine();
int A = Integer.parseInt(reader);
int  N; = new int ;
String  BC = new String ;
Right now this is all i have as i dont understand what to do in terms of bases and dont understand bases in general.
How any methods should i make besided the MATCHING one that checks if the number is actually palindromic and prints it.
Can you please explain bases are.
You will defiantly need an understanding of numeric bases to complete your assignment.
This link https://www.mathsisfun.com/base-conversion-method.html presents an overview of base conversions, giving examples using the same method I used in the outline.
Google “base conversion” for other examples and methods of conversion.
First, a rudimentary explanation of what base 10 means. There are only 10 unique numbers (0,1,2,3,4,5,6,7,8,9) –notice that zero (0) is one of these numbers. If a value greater than 9 is needed, then two digits are required. When the 9 is incremented it returns to zero (0), and the digit to its left is incremented to show this happened. It then looks like this 10. Where this “rollover” takes place is the base number. Each value to the left is 10 times greater than its position on the right.
Most of the numbers we use are in base 10 –the decimal system. A clock however is in base 60 (Sexagesimal). Note that one (1) second after a clock reads 11:59:59 the displays reads 12:00:00. The minutes and seconds roll-over after 59, not 99. Most do not realize that it is base 60 because most clocks are encoded to display in base 10. This encoding is called “Decimal Encoded Sexagesimal”
Most people are so use to this that it’s not given a second thought. Considering this ease of understanding of a very large base (60), it is just a matter of extending this understanding to other (much smaller) bases.
In the program outline, the base conversion process uses decimal encoding and then converts that decimal to a symbol, in this case a letter, when value is greater than 9. So a “10” becomes an “A”, and an “11” becomes “B”, ect. If the display is set for decimal encoded base 17 then it might look like this: [14 | 8 |11 |8]17. After it’s conversion it will look like this: E8B817
Remember that any decimal value greater than 9 requires two characters. For bases greater than base 10, additional, unique single characters are needed to represent the values. It’s standard practice to use letters of the alphabet for this purpose.
In your example you have written "71298 (the square of 267) to base 17" What does this mean
The full text reads: “Here’s an example converting 71298 (the square of 267) to base 17.”
This means the example following will demonstrate how to convert the base 10 number (71298) to base 17. This was chosen at random from the numbers you will be required to examine.
In the question they provide a base.
Your assignment requires you to convert to 18 different bases. (I’m not seeing any ambiguity in the wording for your assignment.)
To clarify: Your assignment is to generate squares of (base 10) numbers from 1 to 300, then convert the squares to 18 other bases, starting with base 2 through base 20. One such number will be 2672=71298. I chose base 17 arbitrarily, as an example from one of the bases you will be converting to.
and how did you know to divide it by 17 as the base?
I knew to divide by 17 because to convert from one base to another requires division by that base.
Like an example input would be 10 and the output would be:
Your program will square 10, that is 100, then the 100 will be converted to bases 2,3,4,5, ... 17,18,19,20. Then each base conversion will be tested for a palindrome condition, if that is a true condition then the original base 10 number and its square will be printed along with the palindrome in base (b).
For now, work on understanding what a base is and how to convert to them. This should only require a few hours of study and practice.