Wednesday, 8 July 2009

Command line redirection

This is going to be of use in a little while when I've finished writing a program to work through all possible combinations of 2 words.

For instance, if I have a java program called from the command line and I want to collate the output of that program then I could do something like this:

C:\java someProg > someResult.txt

Then anything that gets thrown out by someProg will get sent to the text file someResult.

Another thing to take into account is that if two angle brackets (>>) are used then the output is appended to the file if it already exists... then again the single angle bracket (>) will overwrite the file.

Getting back to the program that I need to write it's a little like this in that I need to get all possible permutations of 2 different words... in both upper and lower case, the thing that makes it easy is that the letters must be in the correct order... they can however be either upper or lower case. For instance all combinations of the words "a" and "i" are: "a", "A", "i", "I". Whereas all possible combinations of the words "ab" and "cd" are: "ab", "aB", "ad", "aD", "Ab", "AB", "Ad", "AD", "ib", "iB", "id", "iD", "Ib", "IB", "Id", "ID". I guess you can see where this is going.

So there are 4 possible combinations for 2 one letter words, 16 possible combinations for 2 two letter words, 64 possible combinations for 2 three letter words, 256 possible combinations for 2 four letter words, 1024 for 2 five letter words, 4096 for 2 six letter words, 16384 for 2 seven letter words and 65536 for 2 eight letter words!

Think I'll need to use java arrays to output 'em all rather than messing about by hand using pen and paper.