changeset 1:8f77e48d3704

Add the power of two exercise
author Louis Opter <kalessin@kalessin.fr>
date Sun, 30 Jun 2013 23:43:41 -0700
parents 20fea762903e
children 6bebf4b42ebc
files misc/poweroftwo/question.rst misc/poweroftwo/solution.py
diffstat 2 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/poweroftwo/question.rst	Sun Jun 30 23:43:41 2013 -0700
@@ -0,0 +1,4 @@
+Is a Power of 2?
+================
+
+Write a function that returns true if the given number is a power of two.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/poweroftwo/solution.py	Sun Jun 30 23:43:41 2013 -0700
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+
+def is_power_of_two(n):
+    return n > 0 and not n & (n - 1)