Divide sequence of numbers from 1 to n into 2 groups with minimum difference
It turns out that the strategy depends on $n$ mod $4$.

To see why, one computes the total sum of all these numbers, which is $n(n+1)/2$. The parity of this sum depends on $n$ mod $4$: if $n$ is congruent to $0$ or $3$ mod $4$, the total sum is even; otherwise the total sum is odd.

When the total sum is odd, it is not possible to divide the set into two parts with equal sums. The minimum difference you can expect is therefore $1$.



If $n = 0$ mod $4$: you already figured out how to do that.

If $n = 1$ mod $4$: divide $2, \cdots, n$ using your strategy, and add the extra $1$ to any side. This achieves the minimum difference $1$.

If $n = 2$ mod $4$: divide $3, \cdots, n$ using your strategy, and add the extra $1$ and $2$ to each side to get the minimum difference $1$.

If $n = 3$ mod $4$: divide $4, \cdots, n$ using your strategy, and add $1$ and $2$ to one side, and $3$ to the other side to get the minimum difference $0$.