Using the Excel Spreadsheet column logic you need to write a script which calculates the column position based on any number input and vice versa, calculate a number based on any word input.
Example: 1237890619700 = EXCELLENT and LKWRNM = 148020041
I am able to solve Letters to Numbers but I am unsure how to solve Numbers to Letters.
I am also able to figure out the length of word but then struggle to figure out what those letters should be.
I am hoping someone can point me in the direction of a technique or algorithm I should be looking at to solve this type of problem.
To convert from numbers to letters, it is very similar to converting a base-10 number to a base-26 number, with the reminder that it is 1-based (without 0)
26=Z
27=AA
If base-26 is too odd to understand, try thinking how base-16 and base-10 are inter-convertible, e.g.
15=F
16=10
They are similar but the tricky part is to handle the 1-based condition.
When you have solved this Excel puzzle, reuse your source code to solve another one:
I am not familiar with base-x is this an formula?
I can pass this challenge by brute-forcing it however it’s much too slow.
What I have attempted is continuously dividing the number by 26 until I reach a value less than 26 and that tells me how many letters are in the number eg.
var x = 1237890619700;
var count = 0;
while (x >= 26) {
x /= 26;
count++;
}
Know I am trying to figure out what the letters are.
I’m failing the last testcase Big Numbers and Letters. I get this:
Found:
ADVBKCFT JOB YOUR PROGRAM K HAN... S K 6722172310625687000 FDSMVZLW O EKCCUIZY 660283592480108500
Expected:
EXCELLENT JOB YOUR PROGRAM APPR...AUXYQPNBIOUICV AMONXAOSYKNZYN ADDDNUVLXFAKRX 660283592480108544
I first thought it was because the numbers get too big to handle for int ?
For example this custom test case fails (it is the first number from inputs):
The default code shows you how to print to the error stream. You may follow that syntax to add some code to output the values of the variables at various points of code execution for debugging. This will help you identify where the variables are not calculated as per your expectation.