Skip to content

Instantly share code, notes, and snippets.

@brenapp
Created April 21, 2021 18:00
Show Gist options
  • Save brenapp/d15ad34cd5e7558da37c0910a4fecefb to your computer and use it in GitHub Desktop.
Save brenapp/d15ad34cd5e7558da37c0910a4fecefb to your computer and use it in GitHub Desktop.
Counterexample
use std::process::exit;
fn main() {
// The minimum values of m to search though
let m_min = 2;
let m_max = 16;
for m in m_min..m_max {
print!("For {}:", m);
let m2 = m * m;
// Consider a in [0, m]
for a in 0..m {
// Create b from a + multiples of m^2, to only generate values of b that are congruent
// with b mod m
for i in 0..100 {
let b = a + i * m2;
println!(" {} ≡ {} (mod {}^2)", a, b, m);
if a % m == b % m {
println!(" {} ≡ {} (mod {})", a, b, m)
} else {
// We've found a counterexample, end early!
println!(" {} ≡ {} (mod {}) == FALSE!", a, b, m);
exit(0);
}
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment