Added options, --copy to auto copy the number to clipboard, and --verbose to enable the verbose

This commit is contained in:
obvWolf
2023-11-02 17:25:34 -05:00
parent 078baefbf6
commit 83aa263d01
3 changed files with 84 additions and 18 deletions

View File

@@ -1,2 +1,32 @@
# Countroll
A java program to make counting bots a bit more interesting # Countroll - Description
Countroll is designed to make using counting bots a bit more interesting. It turns integers into complex, unreadable
mathematical expressions, perfect for showing off your mathematical knowledge to you friends!
Countroll uses the following operators to make your integer as complex as possible
- Addition | +
- Subtraction | +
- Multiplication | *
- Division | /
- Square Root | sqrt()
- Exponentiation | ^
## Compatibility
Countroll is currently only compatible with [Numselli's counting bot](https://counting.numselli.xyz/), although I hope to be able to support more counting bots soon!
## Usage
1. Compile the Java program from the source, or download a Precompiled Jar
2. Execute it through the command-line `java -jar Countroll-<version>.jar`
3. Enter a target integer. (Whole number ie: 1, 16, 4096)
4. Copy the outputed expression and use it wherever you'd like!
# Compiling
Make sure you have Java 17 or higher installed on your system!
1. Clone the repo `$ git clone https://github.com/thetrouper/Countroll/`
2. Change directory to the repo `$ cd Countroll`
3. Build with gradle `$ ./gradlew build`
4. Build will be output to `/Countroll/build/libs`

View File

@@ -0,0 +1,18 @@
package me.trouper.Functions;
import me.trouper.Main;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
public class Utils {
public static void copyToClip(String text) {
StringSelection parsed = new StringSelection(text);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(parsed,null);
}
public static void verbose(String text) {
if (Main.verbose) System.out.println(text);
}
}

View File

@@ -1,27 +1,41 @@
package me.trouper; package me.trouper;
import me.trouper.Functions.Complexers; import me.trouper.Functions.Complexers;
import me.trouper.Functions.Utils;
import java.util.Random; import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
import static me.trouper.Functions.Eval.*; import static me.trouper.Functions.Eval.*;
import static me.trouper.Functions.Utils.verbose;
public class Main { public class Main {
public static boolean verbose;
public static boolean deep;
public static void main(String[] args) { public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
boolean doCopy = false;
for (String arg : args) {
switch (arg) {
case "--copy" -> doCopy = true;
case "--verbose" -> verbose = true;
case "--deep" -> deep = true;
}
}
while (true) { while (true) {
System.out.print("Enter Target Integer: "); System.out.print("Enter Target Integer: ");
if (scanner.hasNextInt()) { if (scanner.hasNextInt()) {
int target = scanner.nextInt(); int target = scanner.nextInt();
String expression = obfInt(target); String expression = obfInt(target,deep);
double output = eval(expression); double output = eval(expression);
System.out.println("\nTarget Integer: " + target); System.out.println("\nTarget Integer: " + target);
if (output == target) { if (output == target) {
System.out.println("Expression Verified Correct: \n" + expression); System.out.println("Expression Verified Correct: \n" + expression);
if (doCopy) Utils.copyToClip(expression);
} else { } else {
System.out.println("!!!! INCORRECT !!!! \n" + expression); System.out.println("!!!! INCORRECT !!!! \n" + expression);
} }
@@ -34,12 +48,13 @@ public class Main {
scanner.close(); scanner.close();
} }
public static String obfInt(int target) { public static String obfInt(int target, boolean deep) {
if (deep) System.out.println("Deep Obfuscation is still in development!");
StringBuilder expression = new StringBuilder(); StringBuilder expression = new StringBuilder();
Random random = new Random(); Random random = new Random();
int initializer = random.nextInt(9)+1; int initializer = random.nextInt(9)+1;
System.out.println("Initializing Expression: " + initializer); verbose("Initializing Expression: " + initializer);
expression.append(initializer); expression.append(initializer);
int cubeCount = 0; int cubeCount = 0;
@@ -56,6 +71,7 @@ public class Main {
int eval = (int) eval(expression.toString()); int eval = (int) eval(expression.toString());
int ri = random.nextInt(9)+1; int ri = random.nextInt(9)+1;
int op = random.nextInt(2); int op = random.nextInt(2);
boolean mult = false;
if (!isInt(eval(expression.toString()))) { if (!isInt(eval(expression.toString()))) {
System.out.println("Something went horribly wrong, Here is the relevant info." + System.out.println("Something went horribly wrong, Here is the relevant info." +
@@ -66,24 +82,26 @@ public class Main {
break; break;
} }
System.out.println("Random: " + ri); verbose("Random: " + ri);
System.out.println("Current: " + eval(expression.toString())); verbose("Current: " + eval(expression.toString()));
if (isPerfectSquare(eval)) { if (isPerfectSquare(eval)) {
perfectCount++; perfectCount++;
System.out.println("PERFECT SQUARE TIME! (" + perfectCount+ ")"); verbose("PERFECT SQUARE TIME! (" + perfectCount+ ")");
expression.insert(0,"sqrt(").append(")"); expression.insert(0,"sqrt(").append(")");
eval = (int) eval(expression.toString()); eval = (int) eval(expression.toString());
} }
if (target - eval > 1000) { if (target - eval > 1000) {
mult = true;
cubeCount++; cubeCount++;
System.out.println("Enormous than (" + cubeCount + ")"); verbose("Enormous than (" + cubeCount + ")");
expression.append("+").append(Complexers.power(ri,3)); expression.append("+").append(Complexers.power(ri,3));
} else if (target - eval > 100) { } else if (target - eval > 100) {
factorCount++; factorCount++;
System.out.println("Large than (" + factorCount + ")"); verbose("Large than (" + factorCount + ")");
expression.append("+").append(Complexers.multiply(ri,10)); expression.append("+").append(Complexers.multiply(ri,10));
continue;
} }
if (eval < target) { if (eval < target) {
@@ -93,8 +111,8 @@ public class Main {
} else { } else {
rootCount++; rootCount++;
} }
expression.append("+").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri)); expression.append((mult) ? "*" : "+").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri));
System.out.println("Less than (" + addCount + ")"); verbose("Less than (" + addCount + ")");
} }
if (eval > target) { if (eval > target) {
@@ -107,19 +125,19 @@ public class Main {
expression.insert(0,"(").append(")"); expression.insert(0,"(").append(")");
expression.append("-").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri)); expression.append("-").append((op == 0) ? Complexers.divide(ri) : Complexers.root(ri));
System.out.println("Greater than (" + subCount + ")"); verbose("Greater than (" + subCount + ")");
} }
} }
System.out.println("Broke out of loop. Value: " + eval(expression.toString())); verbose("Broke out of loop. Value: " + eval(expression.toString()));
System.out.println("Expression: " + expression.toString()); verbose("Expression: " + expression);
System.out.println("Statistics: " + System.out.println("\n\n\n\nStatistics: " +
"\nCubes: " + cubeCount + "\nCubes: " + cubeCount +
"\nFactors: " + factorCount + "\nFactors: " + factorCount +
"\nAdditions: " + addCount + "\nAdditions: " + addCount +
"\nSubtractions: " + subCount + "\nSubtractions: " + subCount +
"\nRoots Taken: " + rootCount + "\nRoots Taken: " + rootCount +
"\nDivisors " + divideCount + "\nDivisors: " + divideCount +
"\nPerfect Squares Found: " + perfectCount + "\nPerfect Squares Found: " + perfectCount +
"\nTotal steps taken: " + total); "\nTotal steps taken: " + total);
return expression.toString(); return expression.toString();