Though I guess I'll be a bit more pedantic with this one: for i in 0..32 smuggles in some integer addition. So here's the set theoretic implementation, which has—less reliance on plus signs:
#[derive(Debug)]
enum Num {
S(Box<Num>),
Z,
}
fn s(n: Num) -> Num {
Num::S(Box::new(n))
}
fn z() -> Num {
Num::Z
}
fn set_add(a: Num, b: Num) -> Num {
let mut result = a;
let mut work = b;
loop {
match work {
Num::S(next) => {
result = s(result);
work = *next;
},
Num::Z => return result,
}
}
}
fn main() {
let a = s(s(s(z()))); // i.e., 3
let b = s(s(s(s(s(z()))))); // i.e., 5
println!("3 + 5 = {:?}", set_add(a, b));
}
Output:
3 + 5 = S(S(S(S(S(S(S(S(Z))))))))
Z means zero, and S means increment. So this is zero incremented eight times.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Though I guess I'll be a bit more pedantic with this one:
for i in 0..32
smuggles in some integer addition. So here's the set theoretic implementation, which has—less reliance on plus signs:Output:
Z means zero, and S means increment. So this is zero incremented eight times.