def problem_8_5(n):
    """ Implement an algorithm to print all valid (e.g., properly opened and
    closed) combinations of n-pairs of parentheses.

    EXAMPLE:
    input: 3 (e.g., 3 pairs of parentheses)
    output: ['()()()', '()(())', '(())()', '((()))']
    """
    def parantheses(n):
        """ Composes n pairs of parantheses correctly.
        Returns:
            list, of strings
        """
        if n == 1:
            return ['()']

        subs = parantheses(n-1)
        out = []
        for s in subs:
            out.append('()'+s)
            out.append('('+s+')')
            if '()'+s != s+'()':
                out.append(s+'()')
        return out

    return parantheses(n)