Skip to content

Instantly share code, notes, and snippets.

View rogeliorv's full-sized avatar

Red Valenzuela rogeliorv

  • Mexico
View GitHub Profile
@rogeliorv
rogeliorv / brackets_equilibrium.py
Created February 22, 2017 20:57
Given a string containing opening braces '(' and closing braces ')' find the index where you have the same number of opening and closing braces
# 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
#
@rogeliorv
rogeliorv / base-2.py
Last active November 24, 2022 03:16
Codility challenge get a base -2 number with the least significative bit at the left.
# 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