Try RUDRA
Playground
Browse real RUDRA programs and the output they actually produce. Each sample below was compiled and run with the RUDRA 1.1.0 toolchain.
How this works
RUDRA compiles to native machine code, so there is no in-browser
compiler. This page shows verified sample programs and their recorded
output. To run your own code, install the toolchain and use
rudra file.rux program and then run ./program. Nothing here is simulated: the
output shown is the real output of each sample.
hello.rux
fn main() -> int {
print("Hello, RUDRA!\n");
return 0;
}
return main();Output (verified)
Hello, RUDRA!
factorial.rux
fn factorial(n: int) -> int {
if n <= 1 {
return 1;
}
return n * factorial(n - 1);
}
fn main() -> int {
print(to_str(factorial(5)) + "\n");
return 0;
}
return main();Output (verified)
120
struct.rux
struct Point { x: int, y: int }
fn manhattan(p: Point) -> int {
return p.x + p.y;
}
fn main() -> int {
let p: Point = Point { x: 3, y: 4 };
print(to_str(manhattan(p)) + "\n");
return 0;
}
return main();Output (verified)
7
enum_and_match.rux
enum Shape { Circle(int), Square(int), Empty }
fn area(s: Shape) -> int {
let mut a: int = 0;
match s {
Shape.Circle(r) => { a = 3 * r * r; }
Shape.Square(w) => { a = w * w; }
Shape.Empty => { a = 0; }
}
return a;
}
fn main() -> int {
print(to_str(area(Shape.Circle(5))) + "\n");
print(to_str(area(Shape.Square(4))) + "\n");
print(to_str(area(Shape.Empty)) + "\n");
return 0;
}
return main();Output (verified)
75 16 0
loop.rux
fn main() -> int {
let mut i: int = 0;
let mut total: int = 0;
while i < 5 {
total = total + i;
i = i + 1;
}
print(to_str(total) + "\n");
return 0;
}
return main();Output (verified)
10
list.rux
fn main() -> int {
let xs: list[int] = list_new();
for i in 0..5 {
push(xs, i * i);
}
let mut sum: int = 0;
for v in xs {
sum = sum + v;
}
print("squares sum: " + to_str(sum) + "\n");
print("length: " + to_str(list_len(xs)) + "\n");
return 0;
}
return main();Output (verified)
squares sum: 30 length: 5