Even or odd
Built-in methods:
var n = 42;
say n.is_odd; # false
say n.is_even; # trueChecking the last significant digit:
func is_odd(n) { n&1 == 1 };
func is_even(n) { n&1 == 0 };Using modular congruences:
func is_odd(n) { n%2 == 1 };
func is_even(n) { n%2 == 0 };PreviousEven numbers which cannot be expressed as the sum of two twin primesNextEvolutionary algorithm
Last updated
Was this helpful?