The basic idea is to make jumps until you equal or exceed the absolute value of the target, then continue making jumps until the parity of the target and the parity of the counter t are equal, since you can only subtract an even number.

The function that computes the jumps themselves is similar. Once you have passed the target, d is the number you have to subtract.

Assume the destiny number is k, the step is n
we are looking for a minimal value of n that n(n+1) = 2k + 4x where x is the sum of a sub set of [1…n] so x can be any positive integer(no larger than n(n+1)/2)

# The algorithm works in two steps:
# – In the first step, we create the shortest array of the form [1, 2, 3, 4, 5, …] so that
# the sum s of the contained numbers satisfies ‘s – number % 2 == 0’. If ‘s – number == 0’
# we are done. In any case, the resulting array has exactly the length we are looking for.
# – In the second step, we adjust the signs of the numbers from the first array so that their
# sum equals the given number.
#
def JumpingJack.jump_to_positive_number(number)
n = 0
sum = 0
ret = []
loop do
diff = sum – number
return ret if diff == 0
break if diff > 0 && diff % 2 == 0