feat: add initial plot.py module with beast visualization logic

This commit introduces the core plotting module for the beast project, including
the initial implementation of data visualization functions and chart generation
utilities. The module provides the foundational structure for rendering beast-related
metrics and graphical outputs.
This commit is contained in:
2025-12-02 05:54:32 +00:00
commit f9c7a0fa78
58 changed files with 9092 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
public class Fibonacci {
public static int fib(int n) {
if (n <= 1) {
return n;
}
return fib(n - 1) + fib(n - 2);
}
public static int main() {
System.out.println(fib(0));
System.out.println(fib(1));
System.out.println(fib(2));
System.out.println(fib(3));
System.out.println(fib(4));
System.out.println(fib(5));
System.out.println(fib(6));
System.out.println(fib(7));
System.out.println(fib(8));
System.out.println(fib(9));
System.out.println(fib(10));
return 0;
}
}
+31
View File
@@ -0,0 +1,31 @@
public class PrimeNumbers {
public static int isPrime(int n) {
if (n <= 1) {
return 0;
}
if (n <= 3) {
return 1;
}
int i = 2;
while (i * i <= n) {
if (n - (n / i) * i == 0) {
return 0;
}
i = i + 1;
}
return 1;
}
public static int main() {
int count = 0;
int num = 2;
while (count < 20) {
if (isPrime(num) == 1) {
System.out.println(num);
count = count + 1;
}
num = num + 1;
}
return 0;
}
}
+28
View File
@@ -0,0 +1,28 @@
public class FactorialVariations {
public static int factorialRecursive(int n) {
if (n <= 1) {
return 1;
}
return n * factorialRecursive(n - 1);
}
public static int factorialIterative(int n) {
int result = 1;
int i = 1;
while (i <= n) {
result = result * i;
i = i + 1;
}
return result;
}
public static int main() {
System.out.println(factorialRecursive(5));
System.out.println(factorialIterative(5));
System.out.println(factorialRecursive(7));
System.out.println(factorialIterative(7));
System.out.println(factorialRecursive(10));
System.out.println(factorialIterative(10));
return 0;
}
}
+25
View File
@@ -0,0 +1,25 @@
public class GCD_LCM {
public static int gcd(int a, int b) {
while (b != 0) {
int temp = b;
b = a - (a / b) * b;
a = temp;
}
return a;
}
public static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static int main() {
System.out.println(gcd(48, 18));
System.out.println(gcd(100, 75));
System.out.println(gcd(17, 19));
System.out.println(lcm(12, 18));
System.out.println(lcm(15, 25));
System.out.println(lcm(7, 13));
return 0;
}
}
+26
View File
@@ -0,0 +1,26 @@
public class PowerFunction {
public static int power(int base, int exp) {
if (exp == 0) {
return 1;
}
if (exp == 1) {
return base;
}
int half = power(base, exp / 2);
if (exp - (exp / 2) * 2 == 0) {
return half * half;
}
return base * half * half;
}
public static int main() {
System.out.println(power(2, 0));
System.out.println(power(2, 1));
System.out.println(power(2, 3));
System.out.println(power(2, 5));
System.out.println(power(2, 10));
System.out.println(power(3, 4));
System.out.println(power(5, 3));
return 0;
}
}
+55
View File
@@ -0,0 +1,55 @@
public class ArrayOperations {
public static int sumArray(int[] arr) {
int sum = 0;
int i = 0;
while (i < arr.length) {
sum = sum + arr[i];
i = i + 1;
}
return sum;
}
public static int findMax(int[] arr) {
if (arr.length == 0) {
return 0;
}
int max = arr[0];
int i = 1;
while (i < arr.length) {
if (arr[i] > max) {
max = arr[i];
}
i = i + 1;
}
return max;
}
public static int main() {
int[] numbers = new int[5];
numbers[0] = 10;
numbers[1] = 25;
numbers[2] = 15;
numbers[3] = 30;
numbers[4] = 20;
System.out.println(sumArray(numbers));
System.out.println(findMax(numbers));
int[] fibonacci = new int[10];
fibonacci[0] = 0;
fibonacci[1] = 1;
int i = 2;
while (i < 10) {
fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];
i = i + 1;
}
i = 0;
while (i < 10) {
System.out.println(fibonacci[i]);
i = i + 1;
}
return 0;
}
}
+64
View File
@@ -0,0 +1,64 @@
public class BubbleSort {
public static int main() {
int n0 = 64;
int n1 = 34;
int n2 = 25;
int n3 = 12;
int n4 = 22;
int n5 = 11;
int n6 = 90;
int swapped = 1;
int temp = 0;
while (swapped == 1) {
swapped = 0;
if (n0 > n1) {
temp = n0;
n0 = n1;
n1 = temp;
swapped = 1;
}
if (n1 > n2) {
temp = n1;
n1 = n2;
n2 = temp;
swapped = 1;
}
if (n2 > n3) {
temp = n2;
n2 = n3;
n3 = temp;
swapped = 1;
}
if (n3 > n4) {
temp = n3;
n3 = n4;
n4 = temp;
swapped = 1;
}
if (n4 > n5) {
temp = n4;
n4 = n5;
n5 = temp;
swapped = 1;
}
if (n5 > n6) {
temp = n5;
n5 = n6;
n6 = temp;
swapped = 1;
}
}
System.out.println(n0);
System.out.println(n1);
System.out.println(n2);
System.out.println(n3);
System.out.println(n4);
System.out.println(n5);
System.out.println(n6);
return 0;
}
}
+25
View File
@@ -0,0 +1,25 @@
public class CollatzConjecture {
public static int collatzSteps(int n) {
int steps = 0;
while (n != 1) {
if (n - (n / 2) * 2 == 0) {
n = n / 2;
} else {
n = 3 * n + 1;
}
steps = steps + 1;
}
return steps;
}
public static int main() {
System.out.println(collatzSteps(1));
System.out.println(collatzSteps(2));
System.out.println(collatzSteps(3));
System.out.println(collatzSteps(10));
System.out.println(collatzSteps(15));
System.out.println(collatzSteps(27));
System.out.println(collatzSteps(100));
return 0;
}
}
+41
View File
@@ -0,0 +1,41 @@
public class PascalTriangle {
public static int binomialCoeff(int n, int k) {
if (k > n) {
return 0;
}
if (k == 0) {
return 1;
}
if (k == n) {
return 1;
}
if (k > n - k) {
k = n - k;
}
int result = 1;
int i = 0;
while (i < k) {
result = result * (n - i);
result = result / (i + 1);
i = i + 1;
}
return result;
}
public static int main() {
System.out.println(binomialCoeff(0, 0));
System.out.println(binomialCoeff(1, 0));
System.out.println(binomialCoeff(1, 1));
System.out.println(binomialCoeff(2, 0));
System.out.println(binomialCoeff(2, 1));
System.out.println(binomialCoeff(2, 2));
System.out.println(binomialCoeff(3, 0));
System.out.println(binomialCoeff(3, 1));
System.out.println(binomialCoeff(3, 2));
System.out.println(binomialCoeff(3, 3));
System.out.println(binomialCoeff(4, 2));
System.out.println(binomialCoeff(5, 2));
return 0;
}
}
+19
View File
@@ -0,0 +1,19 @@
public class TowerOfHanoi {
public static int hanoi(int n, int from, int to, int aux, int moveCount) {
if (n == 1) {
return moveCount + 1;
}
moveCount = hanoi(n - 1, from, aux, to, moveCount);
moveCount = moveCount + 1;
moveCount = hanoi(n - 1, aux, to, from, moveCount);
return moveCount;
}
public static int main() {
System.out.println(hanoi(1, 1, 3, 2, 0));
System.out.println(hanoi(2, 1, 3, 2, 0));
System.out.println(hanoi(3, 1, 3, 2, 0));
System.out.println(hanoi(4, 1, 3, 2, 0));
return 0;
}
}
+22
View File
@@ -0,0 +1,22 @@
public class AckermannFunction {
public static int ackermann(int m, int n) {
if (m == 0) {
return n + 1;
}
if (n == 0) {
return ackermann(m - 1, 1);
}
return ackermann(m - 1, ackermann(m, n - 1));
}
public static int main() {
System.out.println(ackermann(0, 0));
System.out.println(ackermann(0, 5));
System.out.println(ackermann(1, 0));
System.out.println(ackermann(1, 5));
System.out.println(ackermann(2, 0));
System.out.println(ackermann(2, 5));
System.out.println(ackermann(3, 0));
return 0;
}
}
+68
View File
@@ -0,0 +1,68 @@
public class ArrayOperations {
public static int sumArray(int[] arr, int length) {
int sum = 0;
int i = 0;
while (i < length) {
sum = sum + arr[i];
i = i + 1;
}
return sum;
}
public static int findMax(int[] arr, int length) {
int max = arr[0];
int i = 1;
while (i < length) {
if (arr[i] > max) {
max = arr[i];
}
i = i + 1;
}
return max;
}
public static int findMin(int[] arr, int length) {
int min = arr[0];
int i = 1;
while (i < length) {
if (arr[i] < min) {
min = arr[i];
}
i = i + 1;
}
return min;
}
public static int main() {
int[] numbers = new int[5];
numbers[0] = 10;
numbers[1] = 25;
numbers[2] = 5;
numbers[3] = 30;
numbers[4] = 15;
int sum = sumArray(numbers, 5);
System.out.println(sum);
int max = findMax(numbers, 5);
System.out.println(max);
int min = findMin(numbers, 5);
System.out.println(min);
int[] squares = new int[5];
int i = 0;
while (i < 5) {
squares[i] = (i + 1) * (i + 1);
i = i + 1;
}
System.out.println(squares[0]);
System.out.println(squares[1]);
System.out.println(squares[2]);
System.out.println(squares[3]);
System.out.println(squares[4]);
return 0;
}
}
+14
View File
@@ -0,0 +1,14 @@
public class SimpleArray {
public static int main() {
int[] arr = new int[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
int sum = arr[0] + arr[1] + arr[2];
System.out.println(sum);
return 0;
}
}
+30
View File
@@ -0,0 +1,30 @@
public class TowerOfHanoiStatic {
public static int moveCount = 0;
public static int hanoi(int n, int from, int to, int aux) {
if (n == 1) {
moveCount = moveCount + 1;
return moveCount;
}
hanoi(n - 1, from, aux, to);
moveCount = moveCount + 1;
hanoi(n - 1, aux, to, from);
return moveCount;
}
public static int main() {
moveCount = 0;
System.out.println(hanoi(1, 1, 3, 2));
moveCount = 0;
System.out.println(hanoi(2, 1, 3, 2));
moveCount = 0;
System.out.println(hanoi(3, 1, 3, 2));
moveCount = 0;
System.out.println(hanoi(4, 1, 3, 2));
return 0;
}
}
+44
View File
@@ -0,0 +1,44 @@
public class StringBasics {
public static int main() {
System.out.println("Hello, World!");
System.out.println("String support in Rava!");
String greeting = "Hello";
String name = "Rava";
String message = greeting + ", " + name + "!";
System.out.println(message);
int x = 42;
System.out.println("The answer is: " + x);
String result = "Sum: " + 10 + 20;
System.out.println(result);
String test = "Hello";
int len = test.length();
System.out.println(len);
String longer = "Hello World";
System.out.println(longer.length());
String s1 = "test";
String s2 = "test";
String s3 = "other";
if (s1.equals(s2)) {
System.out.println(1);
} else {
System.out.println(0);
}
if (s1.equals(s3)) {
System.out.println(1);
} else {
System.out.println(0);
}
System.out.println("String tests completed!");
return 0;
}
}
+22
View File
@@ -0,0 +1,22 @@
public class SimpleObject {
public static int main() {
Point p = new Point();
p.x = 10;
p.y = 20;
System.out.println(p.x);
System.out.println(p.y);
int sum = p.x + p.y;
System.out.println(sum);
Point p2 = new Point();
p2.x = 5;
p2.y = 15;
int total = p.x + p2.x;
System.out.println(total);
return 0;
}
}
+23
View File
@@ -0,0 +1,23 @@
public class InstanceMethods {
int value;
InstanceMethods(int v) {
this.value = v;
}
int getValue() {
return this.value;
}
void setValue(int v) {
this.value = v;
}
public static int main() {
InstanceMethods obj = new InstanceMethods(42);
System.out.println(obj.getValue());
obj.setValue(100);
System.out.println(obj.getValue());
return 0;
}
}
+32
View File
@@ -0,0 +1,32 @@
public class FileIO {
public static int main() {
String content = "Hello from Rava!";
boolean written = Files.write("/tmp/rava_test.txt", content);
if (written) {
System.out.println("File written successfully");
}
boolean exists = Files.exists("/tmp/rava_test.txt");
if (exists) {
System.out.println("File exists");
}
String readContent = Files.read("/tmp/rava_test.txt");
System.out.println(readContent);
boolean deleted = Files.delete("/tmp/rava_test.txt");
if (deleted) {
System.out.println("File deleted");
}
exists = Files.exists("/tmp/rava_test.txt");
if (exists) {
System.out.println("File still exists");
} else {
System.out.println("File is gone");
}
return 0;
}
}
+21
View File
@@ -0,0 +1,21 @@
public class ForLoop {
public static int main() {
int sum = 0;
for (int i = 1; i <= 5; i++) {
sum = sum + i;
}
System.out.println(sum);
int product = 1;
for (int j = 1; j <= 4; j++) {
product = product * j;
}
System.out.println(product);
for (int k = 0; k < 3; k++) {
System.out.println(k);
}
return 0;
}
}
+29
View File
@@ -0,0 +1,29 @@
public class Inheritance {
public static int main() {
Dog dog = new Dog();
dog.age = 5;
dog.speak();
dog.showAge();
return 0;
}
}
class Animal {
int age;
void speak() {
System.out.println("Animal speaks");
}
void showAge() {
System.out.println(this.age);
}
}
class Dog extends Animal {
void speak() {
System.out.println("Woof!");
}
}
+28
View File
@@ -0,0 +1,28 @@
public class ElseIf {
public static int main() {
int x = 75;
if (x >= 90) {
System.out.println("A");
} else if (x >= 80) {
System.out.println("B");
} else if (x >= 70) {
System.out.println("C");
} else if (x >= 60) {
System.out.println("D");
} else {
System.out.println("F");
}
int y = 50;
if (y > 100) {
System.out.println("Over 100");
} else if (y > 50) {
System.out.println("Over 50");
} else {
System.out.println("50 or less");
}
return 0;
}
}
+42
View File
@@ -0,0 +1,42 @@
public class BreakContinue {
public static int main() {
int sum = 0;
for (int i = 1; i <= 10; i++) {
if (i == 6) {
break;
}
sum += i;
}
System.out.println(sum);
int count = 0;
for (int j = 1; j <= 10; j++) {
if (j % 2 == 0) {
continue;
}
count++;
}
System.out.println(count);
int x = 10;
x += 5;
System.out.println(x);
x -= 3;
System.out.println(x);
x *= 2;
System.out.println(x);
int k = 0;
while (k < 100) {
k++;
if (k == 5) {
break;
}
}
System.out.println(k);
return 0;
}
}
+94
View File
@@ -0,0 +1,94 @@
public class Benchmark {
public static int fibonacci(int n) {
if (n <= 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
public static int fibonacciIterative(int n) {
if (n <= 1) {
return n;
}
int a = 0;
int b = 1;
for (int i = 2; i <= n; i++) {
int temp = a + b;
a = b;
b = temp;
}
return b;
}
public static int countPrimes(int limit) {
int count = 0;
for (int n = 2; n <= limit; n++) {
boolean isPrime = true;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
count++;
}
}
return count;
}
public static long sumLoop(int iterations) {
long sum = 0L;
for (int i = 0; i < iterations; i++) {
sum = sum + i;
}
return sum;
}
public static int main() {
System.out.println("=== Rava Benchmark Suite ===");
long start = System.nanoTime();
int fib30 = fibonacci(30);
long end = System.nanoTime();
long fibTime = (end - start) / 1000000;
System.out.print("Fibonacci(30) recursive = ");
System.out.println(fib30);
System.out.print("Time: ");
System.out.print(fibTime);
System.out.println(" ms");
start = System.nanoTime();
int fib40iter = fibonacciIterative(40);
end = System.nanoTime();
long fibIterTime = (end - start) / 1000000;
System.out.print("Fibonacci(40) iterative = ");
System.out.println(fib40iter);
System.out.print("Time: ");
System.out.print(fibIterTime);
System.out.println(" ms");
start = System.nanoTime();
int primes = countPrimes(100000);
end = System.nanoTime();
long primeTime = (end - start) / 1000000;
System.out.print("Primes up to 100000 = ");
System.out.println(primes);
System.out.print("Time: ");
System.out.print(primeTime);
System.out.println(" ms");
start = System.nanoTime();
long sumResult = sumLoop(10000000);
end = System.nanoTime();
long sumTime = (end - start) / 1000000;
System.out.print("Sum 0..10000000 = ");
System.out.println(sumResult);
System.out.print("Time: ");
System.out.print(sumTime);
System.out.println(" ms");
System.out.println("=== Benchmark Complete ===");
return 0;
}
}
+10
View File
@@ -0,0 +1,10 @@
public class HelloWorld {
public static int main() {
System.out.println(42);
System.out.println(100);
int x = 10;
int y = 20;
System.out.println(x + y);
return 0;
}
}
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
import time
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
def fibonacci_iterative(n):
if n <= 1:
return n
a, b = 0, 1
for i in range(2, n + 1):
a, b = b, a + b
return b
def count_primes(limit):
count = 0
for n in range(2, limit + 1):
is_prime = True
i = 2
while i * i <= n:
if n % i == 0:
is_prime = False
break
i += 1
if is_prime:
count += 1
return count
def sum_loop(iterations):
total = 0
for i in range(iterations):
total += i
return total
def main():
print("=== Python Benchmark Suite ===")
start = time.perf_counter_ns()
fib30 = fibonacci(30)
end = time.perf_counter_ns()
fib_time = (end - start) // 1000000
print(f"Fibonacci(30) recursive = {fib30}")
print(f"Time: {fib_time} ms")
start = time.perf_counter_ns()
fib40_iter = fibonacci_iterative(40)
end = time.perf_counter_ns()
fib_iter_time = (end - start) // 1000000
print(f"Fibonacci(40) iterative = {fib40_iter}")
print(f"Time: {fib_iter_time} ms")
start = time.perf_counter_ns()
primes = count_primes(100000)
end = time.perf_counter_ns()
prime_time = (end - start) // 1000000
print(f"Primes up to 100000 = {primes}")
print(f"Time: {prime_time} ms")
start = time.perf_counter_ns()
sum_result = sum_loop(10000000)
end = time.perf_counter_ns()
sum_time = (end - start) // 1000000
print(f"Sum 0..10000000 = {sum_result}")
print(f"Time: {sum_time} ms")
print("=== Benchmark Complete ===")
if __name__ == "__main__":
main()