Subversion Repositories distributed

Compare Revisions

No changes between revisions

Regard whitespace Rev 35 → Rev 34

/ViaThinkSoft Distributed/properties.cfg
File deleted
/ViaThinkSoft Distributed/src/de/viathinksoft/immortable/gen2/ImmortableBase.java
0,0 → 1,7
package de.viathinksoft.immortable.gen2;
 
public enum ImmortableBase {
M5, M6
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortable/gen2/ImmortableWriter.java
0,0 → 1,35
package de.viathinksoft.immortable.gen2;
 
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
 
 
public class ImmortableWriter {
 
public static void writeImmortable(ImmortableBase b, BigInteger u,
String filename, boolean reverse) throws IOException {
BufferedWriter f = new BufferedWriter(new FileWriter(filename));
 
String s = null;
 
if (b == ImmortableBase.M5) {
s = Immortable.M5(u).toString();
} else if (b == ImmortableBase.M6) {
s = Immortable.M6(u).toString();
}
 
if (reverse) {
s = new StringBuffer(s).reverse().toString();
}
 
f.write(s);
 
f.close();
}
private ImmortableWriter() {
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortable/gen2/Gen2Test.java
0,0 → 1,15
package de.viathinksoft.immortable.gen2;
 
import java.io.IOException;
import java.math.BigInteger;
 
 
public class Gen2Test {
 
public static void main(String[] args) throws IOException {
String val = "" + Integer.MAX_VALUE;
ImmortableWriter.writeImmortable(ImmortableBase.M5,
new BigInteger(val), "gen2_m5_" + val + ".txt", true);
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortable/gen2/Immortable.java
0,0 → 1,140
package de.viathinksoft.immortable.gen2;
 
import java.math.BigInteger;
 
import de.viathinksoft.immortable.gen2.math.CoPrimeExpectedException;
import de.viathinksoft.immortable.gen2.math.MathUtils;
import de.viathinksoft.immortable.gen2.math.MathUtils2;
 
/**
* Immortable Number Generator (ING)
*
* @author Daniel Marschall
*/
 
public class Immortable {
 
/**
* Calculates M5 or M6
*
* @param base
* @param u
* @return
*/
public static BigInteger M(ImmortableBase base, BigInteger u) {
BigInteger p, q;
 
if (base == ImmortableBase.M5) {
p = BigInteger.ONE;
q = BigInteger.ZERO;
} else if (base == ImmortableBase.M6) {
p = BigInteger.ZERO;
q = BigInteger.ONE;
} else {
p = null;
q = null;
}
 
BigInteger a = MathUtils2.pow(new BigInteger("2"), u);
BigInteger b = MathUtils2.pow(new BigInteger("5"), u);
 
// To calculate M5:
// x = 2^u = a mod 1
// x = 5^u = b mod 0
 
// To calculate M6:
// x = 2^u = a mod 0
// x = 5^u = b mod 1
 
try {
return MathUtils.chineseRemainder(p, a, q, b);
} catch (CoPrimeExpectedException e) {
// Can never happen since 2^u and 5^u are always coprimes.
return null;
}
}
 
/**
* Gets M5(u)
*
* @param u
* Length of number
* @return
*/
public static BigInteger M5(BigInteger u) {
return M(ImmortableBase.M5, u);
}
 
/**
* Gets M6(u)
*
* @param u
* Length of number
* @return
*/
public static BigInteger M6(BigInteger u) {
return M(ImmortableBase.M6, u);
}
 
/**
* Toggles between M5 and M6 base.
*
* @param cur
* Number
* @param u
* Length of number (because of possible leading zeros)
* @return Number in opposide base.
* @throws Exception
*/
public static BigInteger toggleBase(BigInteger cur, BigInteger u)
throws Exception {
// Converts M6(u) <-> M5(u)
// M6(u) = 1 + 10^u - M5(u)
// M5(u) = 1 + 10^u - M6(u)
if (u.compareTo(MathUtils2.length(cur)) < 0) {
throw new InvalidLengthException();
}
 
return BigInteger.ONE.add(MathUtils2.pow(BigInteger.TEN, u)).subtract(cur);
}
 
/**
* Toggles between M5 and M6 base. The length of the current number is
* assumed (and no leading zero).
*
* @param cur
* @return
* @throws Exception
*/
public static BigInteger toggleBase(BigInteger cur) throws Exception {
try {
return toggleBase(cur, MathUtils2.length(cur));
} catch (InvalidLengthException e) {
// Should never happen
return null;
}
}
public static boolean isImmortable(BigInteger num) {
// Alternativ: n²%10^m == n%10^m
return num.pow(2).toString().endsWith(num.toString());
}
public static String findNextImmortable(String num) {
if (!isImmortable(new BigInteger(num))) {
return null;
}
for (int i=1; i<=9; i++) {
String s = i+num;
if (isImmortable(new BigInteger(s))) {
return s;
}
}
return "0"+num;
}
 
private Immortable() {
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortable/gen2/InvalidLengthException.java
0,0 → 1,7
package de.viathinksoft.immortable.gen2;
 
public class InvalidLengthException extends Exception {
 
private static final long serialVersionUID = 559305281746485769L;
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortable/gen2/erkenntnisse
0,0 → 1,32
Erkenntnis #1 - Der Zusammenhang zwischen M5 und M6
 
M5(u) + M6(u) = 1 + 10^u
 
M5(u) = 1 + 10^u - M6(u)
M6(u) = 1 + 10^u - M5(u)
 
z.B.
 
M6 = 0081787109376
M5 = 9918212890625
^^^^^^^^^^^^
999999999999
 
Erkenntnis #2 - Speicherung
 
Aufgrund von Erkenntnis #1:
=> Man muss nur noch M5 oder M6 größtmöglich berechnen und
kann dann auf das jeweils Andere schließen.
=> Man benötigt kein BigInteger, um von M5 auf M6 zu wechseln.
Es reicht, wenn man alle Komplemente der Ziffern (mit
Ausnahme der letzten Ziffer "5" bzw "6"!) bildet und
aneinander reiht!
 
Desweiteren
- Man sollte die Zahlen umdrehen, sodass eine Datei mit
der aktuellen größtmöglichen Suche immer nur Appended
werden muss.
- Man sollte immer wieder Backups machen, um zu prüfen
ob der Algorithmus nicht an irgendeiner Stelle einen
Fehler gemacht hat (danach prüfen, ob alle Dateien den
selben Anfang haben)