# HG changeset patch # User Louis Opter # Date 1372661021 25200 # Node ID 8f77e48d3704b08b4be9d2657325751b4c64ff01 # Parent 20fea762903ea17b2f0ddd2cb7423e8e1e1777c9 Add the power of two exercise diff -r 20fea762903e -r 8f77e48d3704 misc/poweroftwo/question.rst --- /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. diff -r 20fea762903e -r 8f77e48d3704 misc/poweroftwo/solution.py --- /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)