Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 24, 2026 18:26
Show Gist options
  • Select an option

  • Save rust-play/c40fb09781dde561832a0b2a124e0466 to your computer and use it in GitHub Desktop.

Select an option

Save rust-play/c40fb09781dde561832a0b2a124e0466 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
/// Represents a point in 4D space
#[derive(Debug, Clone, Copy)]
struct Point4D {
x: i32,
y: i32,
z: i32,
w: i32,
}
impl Point4D {
/// Calculates the squared Euclidean distance from the origin (0,0,0,0)
fn distance_squared(&self) -> i32 {
self.x.pow(2) + self.y.pow(2) + self.z.pow(2) + self.w.pow(2)
}
/// Returns the Euclidean distance as a f64
fn distance(&self) -> f64 {
(self.distance_squared() as f64).sqrt()
}
}
fn main() {
let target_sq = 7;
let search_range = 0..3; // Searching within 3 units in each dimension
println!("--- Tesseract Coordinate Explorer ---");
println!("Searching for vertices that satisfy x² + y² + z² + w² = {}\n", target_sq);
let mut found_any = false;
for x in search_range.clone() {
for y in search_range.clone() {
for z in search_range.clone() {
for w in search_range.clone() {
let point = Point4D { x, y, z, w };
let dist_sq = point.distance_squared();
if dist_sq == target_sq {
found_any = true;
println!(
"FOUND: Vertex ({}, {}, {}, {}) -> distance: √{} (≈ {:.4})",
x, y, z, w, dist_sq, point.distance()
);
if w == 0 {
println!(" [!] Warning: This vertex exists in 3D space.");
} else {
println!(" [+] This vertex requires the 4th dimension (w-axis).");
}
}
}
}
}
}
if !found_any {
println!("No integer vertices found for √{} in this range.", target_sq);
} else {
println!("\nMathematical Note:");
println!("Legendre's three-square theorem proves that 7 cannot be the sum");
println!("of 3 integer squares. By adding the 4th dimension (w), we can");
println!("reach √7 using coordinates like (2, 1, 1, 1).");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment