Added more verbose + statistics
This commit is contained in:
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@@ -5,7 +5,7 @@
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="#JAVA_HOME" />
|
||||
<option name="gradleJvm" value="18" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
||||
4
.idea/misc.xml
generated
4
.idea/misc.xml
generated
@@ -1,5 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ASMSmaliIdeaPluginConfiguration">
|
||||
<asm skipDebug="true" skipFrames="true" skipCode="false" expandFrames="false" />
|
||||
<groovy codeStyle="LEGACY" />
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
|
||||
@@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'me.trouper'
|
||||
version '1.0-SNAPSHOT'
|
||||
version '0.0.1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -23,4 +23,9 @@ jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'me.trouper.Main'
|
||||
}
|
||||
from {
|
||||
configurations.runtimeClasspath.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,21 @@ public class Complexers {
|
||||
return "(" + i + ")";
|
||||
}
|
||||
|
||||
public static String multiply(int i, int factor) {
|
||||
String result = "(" + i + "*" + factor + ")";
|
||||
if (eval(result) == i * factor) {
|
||||
return result;
|
||||
}
|
||||
return "(" + i + ")";
|
||||
}
|
||||
public static String power(int i, int exp) {
|
||||
String result = "(" + i + "^" + exp + ")";
|
||||
if (eval(result) == Math.pow(i,exp)) {
|
||||
return result;
|
||||
}
|
||||
return "(" + i + ")";
|
||||
}
|
||||
|
||||
public static String root(int i) {
|
||||
int squared = (int) Math.pow(i,2);
|
||||
String result = "sqrt(" + squared + ")";
|
||||
@@ -25,9 +40,4 @@ public class Complexers {
|
||||
}
|
||||
return "(" + i + ")";
|
||||
}
|
||||
|
||||
/*public static String power(int i) {
|
||||
int
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -8,4 +8,14 @@ public class Eval {
|
||||
Expression exp = new ExpressionBuilder(expression).build();
|
||||
return exp.evaluate();
|
||||
}
|
||||
public static boolean isPerfectSquare(int num) {
|
||||
if (num < 0) {
|
||||
return false;
|
||||
}
|
||||
int sqrt = (int) Math.sqrt(num);
|
||||
return sqrt * sqrt == num;
|
||||
}
|
||||
public static boolean isInt(double number) {
|
||||
return (number == Math.floor(number)) && !Double.isInfinite(number);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import me.trouper.Functions.Complexers;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
import static me.trouper.Functions.Eval.eval;
|
||||
import static me.trouper.Functions.Eval.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
@@ -13,10 +13,10 @@ public class Main {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
while (true) {
|
||||
System.out.print("Enter Target Integer (or a non-integer to exit): ");
|
||||
System.out.print("Enter Target Integer: ");
|
||||
if (scanner.hasNextInt()) {
|
||||
int target = scanner.nextInt();
|
||||
String expression = generateObfuscatedExpression(target);
|
||||
String expression = obfInt(target);
|
||||
double output = eval(expression);
|
||||
|
||||
System.out.println("\nTarget Integer: " + target);
|
||||
@@ -34,7 +34,7 @@ public class Main {
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
public static String generateObfuscatedExpression(int target) {
|
||||
public static String obfInt(int target) {
|
||||
StringBuilder expression = new StringBuilder();
|
||||
Random random = new Random();
|
||||
|
||||
@@ -42,27 +42,86 @@ public class Main {
|
||||
System.out.println("Initializing Expression: " + initializer);
|
||||
expression.append(initializer);
|
||||
|
||||
int cubeCount = 0;
|
||||
int factorCount = 0;
|
||||
int addCount = 0;
|
||||
int subCount = 0;
|
||||
int rootCount = 0;
|
||||
int divideCount = 0;
|
||||
int perfectCount = 0;
|
||||
int total = 0;
|
||||
|
||||
while (eval(expression.toString()) != target) {
|
||||
System.out.println("Current: " + eval(expression.toString()));
|
||||
total++;
|
||||
int eval = (int) eval(expression.toString());
|
||||
int ri = random.nextInt(9)+1;
|
||||
int op = random.nextInt(2);
|
||||
System.out.println("Random: " + ri);
|
||||
if (eval(expression.toString()) < target) {
|
||||
expression.append("+").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri));
|
||||
System.out.println("Less than");
|
||||
|
||||
if (!isInt(eval(expression.toString()))) {
|
||||
System.out.println("Something went horribly wrong, Here is the relevant info." +
|
||||
"\nEvaluation: " + eval(expression.toString()) +
|
||||
"\nRandom Pick: " + ri +
|
||||
"\nOperation: " + op +
|
||||
"\nCaught at: \n" + expression);
|
||||
break;
|
||||
}
|
||||
if (eval(expression.toString()) > target) {
|
||||
|
||||
System.out.println("Random: " + ri);
|
||||
System.out.println("Current: " + eval(expression.toString()));
|
||||
|
||||
if (isPerfectSquare(eval)) {
|
||||
perfectCount++;
|
||||
System.out.println("PERFECT SQUARE TIME! (" + perfectCount+ ")");
|
||||
expression.insert(0,"sqrt(").append(")");
|
||||
eval = (int) eval(expression.toString());
|
||||
}
|
||||
|
||||
if (target - eval > 1000) {
|
||||
cubeCount++;
|
||||
System.out.println("Enormous than (" + cubeCount + ")");
|
||||
expression.append("+").append(Complexers.power(ri,3));
|
||||
} else if (target - eval > 100) {
|
||||
factorCount++;
|
||||
System.out.println("Large than (" + factorCount + ")");
|
||||
expression.append("+").append(Complexers.multiply(ri,10));
|
||||
}
|
||||
|
||||
if (eval < target) {
|
||||
addCount++;
|
||||
if (op == 0) {
|
||||
divideCount++;
|
||||
} else {
|
||||
rootCount++;
|
||||
}
|
||||
expression.append("+").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri));
|
||||
System.out.println("Less than (" + addCount + ")");
|
||||
}
|
||||
|
||||
if (eval > target) {
|
||||
subCount++;
|
||||
if (op == 0) {
|
||||
divideCount++;
|
||||
} else {
|
||||
rootCount++;
|
||||
}
|
||||
expression.insert(0,"(").append(")");
|
||||
|
||||
expression.append("-").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri));
|
||||
System.out.println("Greater than");
|
||||
System.out.println("Greater than (" + subCount + ")");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Broke out of loop. Value: " + eval(expression.toString()));
|
||||
System.out.println("Expression: " + expression.toString());
|
||||
|
||||
System.out.println("Statistics: " +
|
||||
"\nCubes: " + cubeCount +
|
||||
"\nFactors: " + factorCount +
|
||||
"\nAdditions: " + addCount +
|
||||
"\nSubtractions: " + subCount +
|
||||
"\nRoots Taken: " + rootCount +
|
||||
"\nDivisors " + divideCount +
|
||||
"\nPerfect Squares Found: " + perfectCount +
|
||||
"\nTotal steps taken: " + total);
|
||||
return expression.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user