Subversion Repositories distributed

Compare Revisions

No changes between revisions

Regard whitespace Rev 31 → Rev 32

/ViaThinkSoft Distributed/src/test/fraktal3d/BouncingBall.java
1,7 → 1,6
package test.fraktal3d;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
 
public class BouncingBall extends SimpleGame {
 
/ViaThinkSoft Distributed/src/test/fraktal3d/Raumplan.java
13,7 → 13,7
private static final int Abbruch_Size = 5;
private static final float Size_Faktor = 0.5f;
private static final float Abstand_Initial = 0.5f;
private static final float Abstand_Faktor = 0.5f;
// private static final float Abstand_Faktor = 0.5f;
public Raumplan(Node rootNode, float size, float x, float y, float z, LockDirectoryEnum e) {
this.centerbox = new Box("Center-Box", new Vector3f(x, y, z), new Vector3f(size, size, size));
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/genX/ImmortableNumberSearch.java
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/genX/ImmortableException.java
File deleted
Property changes:
Deleted: svn:mime-type
-text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/genX/ImmortalException.java
0,0 → 1,23
package de.viathinksoft.immortal.genX;
 
public class ImmortalException extends Exception {
 
private static final long serialVersionUID = -2350754871091479027L;
public ImmortalException() {
super();
}
 
public ImmortalException(Throwable cause) {
super(cause);
}
 
public ImmortalException(String message) {
super(message);
}
 
public ImmortalException(String message, Throwable cause) {
super(message, cause);
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/genX/ImmortalNumberSearch.java
0,0 → 1,370
package de.viathinksoft.immortal.genX;
 
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
 
/**
* Immortable Iterator
*
* @author Daniel Marschall, Big thanks to the users of MatheBoard.de
* @see http://www.matheboard.de/archive/435725/thread.html
*/
public class ImmortalNumberSearch {
 
private static final String SIGNATURE = "Immortal Number Report File Version 2.02";
private static final String SIGNATURE_MINOR = "Iterator GenX Java (100k save-interval, load-integrity-check, int32-r, array-object) r29";
private static final String END_SIG = "END OF REPORT";
private static final int SOFTBREAK = 76;
 
private ByteArray a;
private String filename;
private int saveInterval = 100000;
private int u = -1;
private int r = -1; // FUTURE: r als BigInteger
private String creation_time;
private String backupDir = "backup";
 
private static final int INITIAL_SIZE = 1000000;
private static final int EXPANSION_SIZE = 1000000;
 
private boolean do_integrity_test = false;
private boolean verbose = false;
 
public boolean isDo_integrity_test() {
return do_integrity_test;
}
 
public void setDo_integrity_test(boolean doIntegrityTest) {
do_integrity_test = doIntegrityTest;
}
 
public boolean isVerbose() {
return verbose;
}
 
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
 
protected void log(String s) {
if (verbose) {
String timestamp = DateUtils.now("EEE, d MMM yyyy HH:mm:ss Z");
System.out.println(timestamp + " - " + s); // FURUE: In eine
// Log-Datei schreiben
}
}
 
public ImmortalNumberSearch(String filename) throws LoadException {
this.filename = filename;
load();
}
 
public String getBackupDir() {
return backupDir;
}
 
public void setBackupDir(String backupDir) {
this.backupDir = backupDir;
}
 
public int getSaveInterval() {
return this.saveInterval;
}
 
public ByteArray getA() {
return a;
}
 
public int getU() {
return u;
}
 
public int getR() {
return r;
}
 
public String getFilename() {
return filename;
}
 
public void setSaveInterval(int saveInterval) {
this.saveInterval = saveInterval;
}
 
private boolean savePointExists() {
return new File(filename).exists();
}
 
private void load() throws LoadException {
if (!savePointExists()) {
this.a = new ByteArray(INITIAL_SIZE, EXPANSION_SIZE);
return;
}
 
BufferedReader f;
try {
f = new BufferedReader(new FileReader(filename));
} catch (FileNotFoundException e) {
// Will not happen because of savePointExists().
return;
}
 
u = -1;
r = -1;
 
try {
try {
String s = f.readLine();
if (!s.equals(SIGNATURE)) {
throw new LoadException("Corrupt: Wrong signature");
}
 
f.readLine(); // Minor. signature
f.readLine(); // ""
 
f.readLine(); // "(Starting time)"
creation_time = f.readLine();
f.readLine(); // ""
 
f.readLine(); // "(Save timestamp)"
f.readLine(); // Timestamp
f.readLine(); // ""
 
f.readLine(); // "(Digits)"
s = f.readLine();
u = Integer.parseInt(s) - 1;
f.readLine(); // ""
 
f.readLine(); // "(r)"
s = f.readLine();
r = Integer.parseInt(s); // FUTURE: (1) Multi-Line-Support?
f.readLine(); // ""
 
this.a = new ByteArray(u + 1 + EXPANSION_SIZE, EXPANSION_SIZE);
 
f.readLine(); // "(M5 reversed)"
do {
s = f.readLine();
for (int i = 0; i < s.length(); i++) {
a.add(Byte.parseByte(s.substring(i, i + 1)));
}
} while (!s.equals(""));
 
if (u + 1 != a.count()) {
throw new LoadException(
"Corrupt: Formal and actual length mismatch!");
}
 
s = f.readLine();
if (!s.equals(END_SIG)) {
throw new LoadException("Corrupt: End-signature mismatch.");
}
} finally {
f.close();
}
} catch (IOException e) {
throw new LoadException(e);
}
}
 
private void save(boolean integrityTest) throws SaveException {
if ((integrityTest) && (do_integrity_test)) {
log("Beginne Selbsttest vor erster Speicherung...");
 
if (!integryTest()) {
throw new SaveException(
"Integrity test failed. (Loaded file broken?) Will not save.");
}
}
 
log("Speichere bei u=" + (u + 1));
 
String timestamp = DateUtils.now("EEE, d MMM yyyy HH:mm:ss Z");
String timestamp_filename = DateUtils.now("dd-MM-yyyy_HH-mm-ss");
 
try {
BufferedWriter f = new BufferedWriter(new FileWriter(filename));
 
try {
f.write(SIGNATURE + "\r\n");
 
f.write(SIGNATURE_MINOR + "\r\n");
f.write("\r\n");
 
f.write("(Starting time)\r\n");
f.write(creation_time + "\r\n");
f.write("\r\n");
 
f.write("(Save timestamp)\r\n");
f.write(timestamp + "\r\n");
f.write("\r\n");
 
f.write("(Digits)\r\n");
f.write((u + 1) + "\r\n");
f.write("\r\n");
 
f.write("(r)\r\n");
f.write(r + "\r\n"); // FUTURE: (1) Multi-Line-Support?
f.write("\r\n");
 
f.write("(M5 reversed)\r\n");
int i;
for (i = 0; i < a.count(); i++) {
byte xa = a.get(i);
f.write("" + xa);
if ((i + 1) % SOFTBREAK == 0) {
f.write("\r\n");
}
}
if ((i + 1) % SOFTBREAK != 0) {
f.write("\r\n");
}
f.write("\r\n");
 
f.write(END_SIG);
} finally {
f.close();
}
} catch (IOException e) {
throw new SaveException("Could not save master file.", e);
}
 
// Make backup
 
new File(backupDir).mkdir();
String bak_filename = backupDir + "/immortal_" + timestamp_filename
+ "_" + (u + 1) + ".txt";
try {
FileUtils.copyFile(new File(filename), new File(bak_filename));
} catch (IOException e) {
throw new SaveException("Could not make backup", e);
}
 
if ((integrityTest) && (do_integrity_test)) {
log("Erste Speicherung absolviert. Stabile Phase hat begonnen.");
}
}
 
public void calcIterate(int amount) throws SaveException {
log("Beginn der Rechenarbeit...");
 
int cnt = 0;
 
// Wir führen beim ersten Speichern einen weiteren
// integrity-Test durch. Grund: Wäre bei einer Fortsetzung einer
// Datei das "r" falsch (der Datenteil aber korrekt), dann würde
// diese Datei beim Speichern ungültige Daten enthalten (Zahl
// nicht immortabel).
boolean firstSave = true;
 
if (a.isEmpty()) {
creation_time = DateUtils.now("EEE, d MMM yyyy HH:mm:ss Z");
a.add((byte) 5);
a.add((byte) 2);
u = 1;
r = 2;
cnt += 2;
}
 
int s, m, k;
 
do {
r = (r /* - a.get(u) */) / 10 + a.get(u);
s = 0;
for (m = 1, k = u; m < k; m++, k--) {
s += a.get(m) * a.get(k);
}
r += 2 * s;
if (m == k) {
r += a.get(m) * a.get(m);
}
u++;
a.add((byte) (r % 10));
 
cnt++;
if (cnt % saveInterval == 0) {
save(firstSave);
firstSave = false;
}
} while (cnt != amount);
 
// Wir brauchen nicht zwei Mal zu speichern
if (cnt - 1 % saveInterval != 0) {
log("Letzte Speicherung vor Ende...");
save(firstSave);
// firstSave = false;
}
 
log("Ende der Rechenarbeit...");
}
 
public byte getDigitReverse(int u) {
return a.get(u);
}
 
public StringBuilder M5_StringBuilder(int u) {
StringBuilder s = new StringBuilder();
for (int i = 0; i < a.count(); i++) {
byte xa = a.get(i);
s.append("" + xa);
}
s.reverse();
return s;
}
 
public String M5_String(int u) {
return M5_StringBuilder(u).toString();
}
 
public BigInteger M5_BigInteger(int u) {
return new BigInteger(M5_String(u));
}
 
public StringBuilder M6_StringBuilder(int u) {
StringBuilder s = new StringBuilder();
for (int i = 0; i < a.count(); i++) {
byte xa = a.get(i);
if (i > 0) {
s.append("" + (9 - xa));
} else {
s.append("" + (11 - xa));
}
}
s.reverse();
return s;
}
 
public String M6_String(int u) {
return M6_StringBuilder(u).toString();
}
 
public BigInteger M6_BigInteger(int u) {
return new BigInteger(M6_String(u));
}
 
protected static boolean isImmortable(BigInteger num, int m) {
// Alternativ
// return num.pow(2).toString().endsWith(num.toString());
 
// n² === n (mod 10^m) <===> n²%10^m == n%10^m == n
 
BigInteger m_pow = BigInteger.TEN.pow(m);
return num.pow(2).mod(m_pow).equals(num);
}
 
protected static boolean isImmortable(BigInteger num) {
int m = num.toString().length();
return isImmortable(num, m);
}
 
public boolean integryTest() {
// return isImmortable(M5_BigInteger(u), a.count());
return isImmortable(M6_BigInteger(u), a.count());
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/genX/MainUnit.java
2,8 → 2,8
 
public class MainUnit {
 
public static void main(String[] args) throws ImmortableException {
ImmortableNumberSearch x = new ImmortableNumberSearch("data.txt");
public static void main(String[] args) throws ImmortalException {
ImmortalNumberSearch x = new ImmortalNumberSearch("data.txt");
x.calcIterate(-1);
// x.calcIterate(10);
}
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/genX/SaveException.java
1,6 → 1,6
package de.viathinksoft.immortal.genX;
 
public class SaveException extends ImmortableException {
public class SaveException extends ImmortalException {
 
private static final long serialVersionUID = 6676069625825930604L;
 
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/genX/LoadException.java
1,6 → 1,6
package de.viathinksoft.immortal.genX;
 
public class LoadException extends ImmortableException {
public class LoadException extends ImmortalException {
 
private static final long serialVersionUID = 5556229109549989469L;
 
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/gen2/ImmortalBase.java
0,0 → 1,7
package de.viathinksoft.immortal.gen2;
 
public enum ImmortalBase {
M5, M6
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/gen2/ImmortalWriter.java
0,0 → 1,36
package de.viathinksoft.immortal.gen2;
 
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
 
 
 
public class ImmortalWriter {
 
public static void writeImmortable(ImmortalBase b, BigInteger u,
String filename, boolean reverse) throws IOException {
BufferedWriter f = new BufferedWriter(new FileWriter(filename));
 
String s = null;
 
if (b == ImmortalBase.M5) {
s = Immortal.M5(u).toString();
} else if (b == ImmortalBase.M6) {
s = Immortal.M6(u).toString();
}
 
if (reverse) {
s = new StringBuffer(s).reverse().toString();
}
 
f.write(s);
 
f.close();
}
private ImmortalWriter() {
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/gen2/Immortal.java
0,0 → 1,140
package de.viathinksoft.immortal.gen2;
 
import java.math.BigInteger;
 
import de.viathinksoft.immortal.gen2.math.CoPrimeExpectedException;
import de.viathinksoft.immortal.gen2.math.MathUtils;
import de.viathinksoft.immortal.gen2.math.MathUtils2;
 
/**
* Immortable Number Generator (ING)
*
* @author Daniel Marschall
*/
 
public class Immortal {
 
/**
* Calculates M5 or M6
*
* @param base
* @param u
* @return
*/
public static BigInteger M(ImmortalBase base, BigInteger u) {
BigInteger p, q;
 
if (base == ImmortalBase.M5) {
p = BigInteger.ONE;
q = BigInteger.ZERO;
} else if (base == ImmortalBase.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(ImmortalBase.M5, u);
}
 
/**
* Gets M6(u)
*
* @param u
* Length of number
* @return
*/
public static BigInteger M6(BigInteger u) {
return M(ImmortalBase.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 Immortal() {
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/gen2/InvalidLengthException.java
0,0 → 1,7
package de.viathinksoft.immortal.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/immortal/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)
/ViaThinkSoft Distributed/src/de/viathinksoft/immortal/gen2/Gen2Test.java
0,0 → 1,16
package de.viathinksoft.immortal.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;
ImmortalWriter.writeImmortable(ImmortalBase.M5,
new BigInteger(val), "gen2_m5_" + val + ".txt", true);
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property