Created
April 21, 2021 18:00
-
-
Save brenapp/d15ad34cd5e7558da37c0910a4fecefb to your computer and use it in GitHub Desktop.
Counterexample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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