Cookbook: Difference between revisions

Jump to navigation Jump to search
1 byte added ,  11 April 2017
(→‎Find if a package is installed: use pkg list instead of pkg describe, because describe has an odd behaviour)
Line 337: Line 337:
You have a number, or an array or matrix of them, and want to know if any of them is an odd or even number, i.e., their parity.
You have a number, or an array or matrix of them, and want to know if any of them is an odd or even number, i.e., their parity.
==== Solution ====
==== Solution ====
Check the remainder of a division by two. If the remainder is zero, the number is odd.
Check the remainder of a division by two. If the remainder is zero, the number is even.


   mod (value, 2) ## 1 if odd, zero if even
   mod (value, 2) ## 1 if odd, zero if even
Anonymous user

Navigation menu