AlphaBot 26 sourcecode
Main Entry: AlphaBot System
Function: public class xorart_alphabotx (java)
Description: The xorart_alphabotx class implements executable software code
which converts words (base 27) to their base-10 numerical equivalents and back.
Author: Baker, Baker & Baker ©2000 H.MM 2K, Baker Baker Omnia Baker
Date: OCT 2K8
/*
the xorart bignumber alphabot class
©2K Baker Baker Omnia Baker
(alpha) versie notes (dutch)
Alphabot bewerkt alleen alphabetische input.
de xorart_alphabotx class zoekt door spaties " " gemarkeerde strings
woorden kunnen behalve uit letters, ook uit cijfers en leestekens bestaan.
alle gevonden woorden worden char voor char bekeken en
die delen die onafgebroken uit letters bestaan ('wordReals')
worden naar 27-tallige alphabotwoorden omgezet.
Alphabot is extreem 'greedy', cijfers en leestekens worden
onveranderd meegegeven in de outputstream.
"b89" = "b" + "89" = 2 + 89 = 289 //greedy
wordReals bestaan volledig uit letters en zijn dus altijd omkeerbaar:
"az" -> 53 -> "az"
"ba" -> 55 -> "ba"
Nb. 54 in alphabot komt niet voor. //gap
de verwerking van mixed words is niet omkeerbaar in deze versie van alphabot:
"b3" = "b" + 3 = 2 3
"b3" wordt 23, maar 23 terug wordt "w", niet "b3" // ....
SOLUTION/FEATURE...tag de chunks in 'mixWords'
... aangeven waar chunks *numeric of ^alphabot zijn:
"de25b" = ^113*25^2 // omkeerbaar mixWord
below: de java code.
*/
import java.math.*;
import java.io.*;
public class xorart_alphabotx {
//--- mainfunctie, 2 methods:
public static void main(String[] args) throws IOException {
String ourIntext = readSfile( "ascii.txt" ); // INPUT FILE: ASCII.TXT
String mysTapout = ""; // deze string collects alles voor de output
mysTapout += "\n The xorart_alphabotx class implements the executable program";
mysTapout += "\n in order to convert words to their base-10 numerical equivalents.";
mysTapout += "\n Baker Baker, Omnia Baker (2000)";
mysTapout += "\n ---------------------------------------------------------------------\n";
int ourIntextLen = ourIntext.length() -1; //fix last substr 4 use
BigInteger bimine = new BigInteger("0");
LookupWord myOOLookupWord = new LookupWord(bimine); // objectcode see below
String mywoord = "";
String mynonwoord = "";
String zonderboldzeroes = "";
String metboldzeroes = "";
int i = 0;
int b = 0;
String d = ourIntext.substring(0,1); // eerste substr
int u = myOOLookupWord.getLutidx(d); // returns -1 als geen letter
while ( i < ourIntextLen ) { // mainloop
mywoord = "";
metboldzeroes = "";
mynonwoord = mywoord; // i like this
// ===== OPT 1: NONWOORD
while ( u == -1 && i < ourIntextLen) {
mynonwoord += d;
i++;
d = ourIntext.substring(i, i+1); // 1 letter tegelijk
u = myOOLookupWord.getLutidx(d); // returns LUT-idx, of -1 als geen letter
}
mysTapout += mynonwoord;
// ===== OPT 2: WOORD
while ( u != -1 && i < ourIntextLen) {
mywoord += d;
i++;
d = ourIntext.substring(i, i+1); // 1 letter tegelijk
u = myOOLookupWord.getLutidx(d); // returns LUT-idx of -1 als geen letter
}
//
bimine = myOOLookupWord.getBigNumWord(mywoord); // convert 27dig to 10dig
zonderboldzeroes = bimine.toString();
//
for (b=0; b < zonderboldzeroes.length(); b++) {
if ( zonderboldzeroes.substring(b, b+1).equals("0") ){
metboldzeroes += "<B>" + zonderboldzeroes.substring(b, b+1) + "</B>";
} else {
metboldzeroes += zonderboldzeroes.substring(b, b+1); //default
}
}
//
mysTapout += metboldzeroes;
}
mysTapout += "\n\n...einde.\n";
String ourOuttext = writeSfile( "writtenout.txt" , mysTapout ); // OUTPUT FILE: WRITTENOUT.TXT
System.out.println(ourOuttext);
} // einde mainfunctie...
//--- METHOD readSfile:
public static String readSfile(String f) {
String lineSep = System.getProperty("line.separator");
String allLinesstrg = "";
try {
String aLine = "";
BufferedReader br = new BufferedReader(new FileReader(f));
while(null != (aLine = br.readLine()))
allLinesstrg += aLine + lineSep;
br.close();
}
catch(Exception e) {
e.printStackTrace();
} finally {
return allLinesstrg;
}
}
//--- METHOD writeSfile
public static String writeSfile(String g, String mySdat) {
String tip="";
try {
BufferedWriter out = new BufferedWriter(new FileWriter(g));
out.write(mySdat);
out.close();
tip="\n\t no (io)exceptions \n";
}
catch(IOException e) {
tip="\n\t ohoh io exception! \n";
e.printStackTrace();
} finally {
return tip;
}
}
} // -------- eind class xorart_alphabotx --------
// LookupWord code:
class LookupWord extends xorart_alphabotx {
public BigInteger hj = new BigInteger("0");
// fill lookuptables:
public String[] radixLo =
{"leeg","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 String[] radixUp =
{"LEEG","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"};
//--- CONSTRUCTOR
public LookupWord(BigInteger inzt) {
this.hj = inzt; // just any (BigInteger) to init obj ?
}
//--- METHOD
public int getLutidx(String singlekarakt) {
// returns the [id] of one single char, as an int, eg z -> 26.
int li = 0;
int re = -1; // geen match
for (li=0; li < this.radixLo.length; li++) {
if ( singlekarakt.equals(this.radixUp[li]) || singlekarakt.equals(this.radixLo[li]) ){
re=li;
break;
}
}
return re; // 1-26 (A-Z); ...of -1, als geen match
}
//--- METHOD
public BigInteger getBigNumWord(String abcwoord) {
// returns Alphabot word as BI eg "ae"->32 , calls getLutidx() inside
String tletter = "";
int m = abcwoord.length();
int i = 0;
int j = m-1-i;
int u = 0;
long v = 0L;
BigInteger grondtal = new BigInteger("27"); // what radix u want
BigInteger bp = new BigInteger("0");
BigInteger bk = new BigInteger("0");
for (i=0; i<m; i++) {
tletter=abcwoord.substring(i, i+1);
u=this.getLutidx(tletter); // returns int ...
v=u; // ... int u need it long: v
bk = BigInteger.valueOf(v); // ... long v ... BigInteger bk ...
//bp = bp.add(bk.multiply(grondtal.pow(i))); // letters vlnr: i als exponent.
j = m-1-i;
bp = bp.add(bk.multiply(grondtal.pow(j))); // vrnl zoals NUMMERS; j=m-1-i; j als exponent
}
return bp; // returns a BigInteger
}
} // -------- eind class LookupWord --------