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
# Codility challenge for base -2 with the least significative bit at the left. | |
# | |
# In base -2 integers are represented by sequences of bits in the following way. | |
# Bits are ordered from the least to the most significant. Sequence B of N bits | |
# represents the number: sum(B[i] * (-2)^i for i = 0..N-1). The empty sequence represents 0. | |
# Note that such representation is suitable for both positive and negative numbers. | |
# NOTE: Remember negative division returns the floor. http://python-history.blogspot.mx/2010/08/why-pythons-integer-division-floors.html | |
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
# Codility challenge | |
# Given a string containing opening braces '(' and closing braces ')' | |
# Return the index where you have the same number of opening and closing braces | |
# Example: | |
# Given '(())' the equilibrium index is two because there are the same number | |
# of opening brackets to the left as there are closing brackets to the right | |
# | |
# Given '(((' the equilibrium index is 0 because there are no opening brackets | |
# before index 0 and there are 0 closing brackets at that position | |
# |