Consider binary representation of current i to decide which elements to pick .
j = 0 NEW_LINE while j < n : NEW_LINE INDENT if ( i & ( 1 << j ) ) : NEW_LINE INDENT sum += arr [ j ] NEW_LINE DEDENT j += 1 NEW_LINE DEDENT