Clever Person Challenge!
Author
Discussion

darrent

Original Poster:

630 posts

283 months

Wednesday 21st July 2004
quotequote all
Ok – who is a clever clogs on here?!?!

I basically need some sort of excel/access formula or a VB script (anything!) that will convert a list of telephone numbers into letters i.e. alphanumeric telephone numbers. There are a few bits on the web that convert alphanumeric to numbers but I need it the other way round – anybody any bright ideas??

for the winner

plotloss

67,280 posts

294 months

Wednesday 21st July 2004
quotequote all
Dont see how you could do it really, because 2 can be either A, B or C

You could create a list of the all the possible permutations I suppose.

victormeldrew

8,293 posts

301 months

Wednesday 21st July 2004
quotequote all
A typical 11 digit phone number would generate at least 3 to the power of 11 results (more if it contains 7's or 9's, as they could be one of four letters). Thats a very big number. The conversion from alhpa to numeric is simple, as there is only one possible result.

darrent

Original Poster:

630 posts

283 months

Wednesday 21st July 2004
quotequote all
Yes there could be variations - are you both saying it can't be done? There is a tool called Alphaphone that does this very thing (shareware) but it only does 1 at a time - I need to do 1000 at a time!!

plotloss

67,280 posts

294 months

Wednesday 21st July 2004
quotequote all
Does this Alphaphone have a command line interface?

If so, can you call it iteratively for the 1000 numbers?

What it would require, depending on what you want to get out of it is to take a phone number, create an array of all the permutations (loads) then trundle through the array and look to see if any of the permutations are valid words by looking up against some sort of dictionary.

It can be done, but would take ages to write and quite a while to run as well...

joust

14,622 posts

283 months

Wednesday 21st July 2004
quotequote all
darrent said:
Yes there could be variations - are you both saying it can't be done? There is a tool called Alphaphone that does this very thing (shareware) but it only does 1 at a time - I need to do 1000 at a time!!
Why? Why would you want to find out what words are spelt by certain numbers? Surely what you want to know are what the number combinations are for the words that you want to spell, and then you check those against your list of 1000 numbers to see which one to use.

Even if it could be done, do you have the time to look through over 170,000 results to find the one you want?

If you think laterally you might find an easier way to do this...

J

dern

14,055 posts

303 months

Wednesday 21st July 2004
quotequote all

Here you go, pint of adnams please...

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

public class PhoneToAlpha {

private String number;

private static char alphas[][] = {
{ '0' },
{ '1' },
{ 'A', 'B', 'C' },
{ 'D', 'E', 'F' },
{ 'G', 'H', 'I' },
{ 'J', 'K', 'L' },
{ 'M', 'N', 'O' },
{ 'P', 'Q', 'R', 'S' },
{ 'T', 'U', 'V' },
{ 'W', 'X', 'Y', 'Z' },
{ ' ' }
};

public PhoneToAlpha(String number) {
this.number = number;
}

public void generate(PrintWriter out) {
char[][] results = new char[number.length()][4];
for(int i = 0; i < number.length(); i++) {
try {
results = alphas[Integer.parseInt(number.substring(i, i + 1))];
} catch(NumberFormatException e) {
results = alphas[10];
}
}

int counters[] = new int[results.length];
for(int i = 0; i < counters.length; i++) {
counters = 0;
}

int c;
do {
StringBuffer answer = new StringBuffer();
for(int i = 0; i < counters.length; i++) {
answer.append(results[counters]);
}
out.println(this.number + ":" + answer.toString());
for(c = 0; c < counters.length; c++) {
counters[c]++;
if(counters[c] >= results[c].length) {
counters[c] = 0;
} else {
break;
}
}
} while(c != counters.length);
}

public static void main(String[] args) {
try {
String inFile = args[0];
String outFile = args[1];
BufferedReader in = new BufferedReader(new FileReader(inFile));
PrintWriter out = new PrintWriter(new FileOutputStream(outFile, false));
String phoneNumber;
while((phoneNumber = in.readLine()) != null) {
System.out.println("processing " + phoneNumber);
new PhoneToAlpha(phoneNumber).generate(out);
}
System.out.println("finished");
in.close();
out.close();
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("usage: java PhoneToAlpha source-file results-file");
System.out.println(" where source-file is a text file contain one phone number per line");
} catch(IOException e) {
System.out.println("usage: java PhoneToAlpha source-file results-file");
System.out.println(" error reading or writing to files: " + e.getMessage());
e.printStackTrace();
}
}
}


>> Edited by dern on Wednesday 21st July 14:45

dern

14,055 posts

303 months

Wednesday 21st July 2004
quotequote all
If you can download java or have it installed I can compile this into a class file for you to run if you like a bit later.

It doesn't actually give you much in terms of interest though. For example for the number 01234 886323 it gives...

01234 886323 :01ADG TTMDAD
01234 886323 :01BDG TTMDAD
01234 886323 :01CDG TTMDAD
01234 886323 :01AEG TTMDAD
01234 886323 :01BEG TTMDAD
01234 886323 :01CEG TTMDAD
01234 886323 :01AFG TTMDAD
01234 886323 :01BFG TTMDAD
01234 886323 :01CFG TTMDAD
01234 886323 :01ADH TTMDAD
01234 886323 :01BDH TTMDAD
01234 886323 :01CDH TTMDAD
01234 886323 :01AEH TTMDAD
01234 886323 :01BEH TTMDAD
01234 886323 :01CEH TTMDAD
01234 886323 :01AFH TTMDAD
01234 886323 :01BFH TTMDAD
01234 886323 :01CFH TTMDAD
01234 886323 :01ADI TTMDAD
01234 886323 :01BDI TTMDAD
01234 886323 :01CDI TTMDAD
01234 886323 :01AEI TTMDAD
01234 886323 :01BEI TTMDAD
01234 886323 :01CEI TTMDAD
01234 886323 :01AFI TTMDAD
01234 886323 :01BFI TTMDAD
01234 886323 :01CFI TTMDAD
01234 886323 :01ADG UTMDAD
01234 886323 :01BDG UTMDAD
01234 886323 :01CDG UTMDAD
01234 886323 :01AEG UTMDAD

...and so on. Is that what you wanted? It takes two files as command line arguments, the first is a file of phone numbers (one per line) and the second contains all the output as above that you could probably import into excel.

Regards,

Mark

>> Edited by dern on Wednesday 21st July 14:58

darrent

Original Poster:

630 posts

283 months

Thursday 22nd July 2004
quotequote all
Mark,

Top man - only need to convert the last six digits though - no need to do the prefix. Not very up with Java - what's a class file and how would a run it??

dern

14,055 posts

303 months

Thursday 22nd July 2004
quotequote all
darrent said:
Top man - only need to convert the last six digits though - no need to do the prefix. Not very up with Java - what's a class file and how would a run it??



When you compile a normal program you get an exe file which you can simply run from the command line. The equivelent in java is the class file which is basically compiled java. However class files don't run under windows directly you have to use a java runtime program to run it for you. You basically do this from the command line...

java MyProgram

...and it gets run for you. This may sound stupid but the idea is that the java class file can run on any system you have the java run time for. So I've written that under windows you can run it under windows, macos, linux, etc.

You may be lucky and have java installed. To find out open a command window (start/run and type 'cmd') and the type 'java' at the command line. If you get told that java can't be found then it probably isn't installed. If it is let me know the version by typing 'java -version'.

If you don't have java then you can download and install sun's java runtime from <a href="http://java.sun.com/j2se/1.4.2/download.html"><a href="http://java.sun.com/j2se/1.4.2/download.html">http://java.sun.com/j2se/1.4.2/download.html</a></a> (do a search on that page for "J2SE v 1.4.2_05 JRE" and download whatever version you need). You must follow all the instructions including adding java to your path so that you can run java from the command line as described above.

If you can get to that point I can send you a class file to run by email.

Can I ask what you're going to use this code for by the way. You can email me this through my profile if you'd rather not say on here.

If you want to use this on a regular basis I can knock up a GUI front end for it for a 'small' fee As is though you can use the code for whatever you want for nowt.

If you only want the number and not the code converted can you simply put the number and not the code in the input file? If you do that the code as it stands will only give you the possibly encodings for the numbers you give. What format do you want the output in by the way. Is the format "<original-number>:<encoded-number>" ok?

Regards,

Mark

PS. Writing java is what I do as a job but this is just for fun (god that sounds sad) so no warrenty implied or given

PPS. The other alternative is to give my code to someone (or some kind soul on PH who is willing to volunteer) who can write C++ and has access to the tools and get them to write you an exe version and therefore you wouldn't need to download java.

PPPS. You could potentially make this an awful lot more useful by getting the program to use one of the many dictionary web services to look up and validate the resulting 'words' for you. You could then possibly throw away the non-genuine words and be left with the useful ones. Just a thought.

PPPPS. No, my current job isn't a challenge

PPPPPS. No, I'm really not that nerdy.


>> Edited by dern on Thursday 22 July 11:36

unity1

271 posts

276 months

Thursday 22nd July 2004
quotequote all
Am I missing the point here as I dont see the problem. Are you just trying to convert a numeric value to a numeric looking text value (Cstr) or a straight letter encoding with the same number of digits such as.
0 = a
1 = b
2 = c
..
9 = j

If thats the case it does not matter how big the number is the conversion is just the same.
1 = b
1000000 = baaaaaa

chrisjl

787 posts

306 months

Thursday 22nd July 2004
quotequote all
unity1 said:
Am I missing the point here..


Yes.

For a selection of phone numbers, he wants to pick out any that can be given out as words that can be dialed (e.g. see the 0800 R-E-V-E-R-S-E ad with Holly Valance)
2 = ABC
3 = DEF
..
..
9 = WXYZ

I'm assuming the set of available phone numbers is fixed, or it would make more sense to start with the word and convert it to numbers (as Joust already said).