Skip to main content
Commonmark migration
Source Link

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term:

 

25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1

 

The choice of 0 and 1 is... not very binary. We shall perform the true binary expansion by expanding with powers of 2, but with a coefficient of 1 or -1 instead:

 

25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1

 

Now this looks binary.

 

Given any positive number, it should be trivial to see that:

 
  • Every odd number has infinitely many true binary expansions
  • Every even number has no true binary expansions
 

Hence, for a true binary expansion to be well-defined, we require the expansion to be the least, i.e with the shortest length.


Given any positive, odd integer n, return its true binary expansion, from the most significant digit to the least significant digit (or in reversed order).

Rules:

  • As this is , you should aim to do this in the shortest byte count possible. Builtins are allowed.
  • Any output that can represent and list the coefficients is acceptable: an array, a string of coefficients with separators, etc...
  • Standard golfing loopholes apply.
  • Your program should work for values within your language's standard integer size.

Test Cases

25 -> [1,1,1,-1,-1]
47 -> [1,1,-1,1,1,1]
1 -> [1]
3 -> [1,1]
1234567 -> [1,1,-1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,1,1]

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term:

 

25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1

 

The choice of 0 and 1 is... not very binary. We shall perform the true binary expansion by expanding with powers of 2, but with a coefficient of 1 or -1 instead:

 

25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1

 

Now this looks binary.

 

Given any positive number, it should be trivial to see that:

 
  • Every odd number has infinitely many true binary expansions
  • Every even number has no true binary expansions
 

Hence, for a true binary expansion to be well-defined, we require the expansion to be the least, i.e with the shortest length.


Given any positive, odd integer n, return its true binary expansion, from the most significant digit to the least significant digit (or in reversed order).

Rules:

  • As this is , you should aim to do this in the shortest byte count possible. Builtins are allowed.
  • Any output that can represent and list the coefficients is acceptable: an array, a string of coefficients with separators, etc...
  • Standard golfing loopholes apply.
  • Your program should work for values within your language's standard integer size.

Test Cases

25 -> [1,1,1,-1,-1]
47 -> [1,1,-1,1,1,1]
1 -> [1]
3 -> [1,1]
1234567 -> [1,1,-1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,1,1]

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term:

25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1

The choice of 0 and 1 is... not very binary. We shall perform the true binary expansion by expanding with powers of 2, but with a coefficient of 1 or -1 instead:

25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1

Now this looks binary.

Given any positive number, it should be trivial to see that:

  • Every odd number has infinitely many true binary expansions
  • Every even number has no true binary expansions

Hence, for a true binary expansion to be well-defined, we require the expansion to be the least, i.e with the shortest length.


Given any positive, odd integer n, return its true binary expansion, from the most significant digit to the least significant digit (or in reversed order).

Rules:

  • As this is , you should aim to do this in the shortest byte count possible. Builtins are allowed.
  • Any output that can represent and list the coefficients is acceptable: an array, a string of coefficients with separators, etc...
  • Standard golfing loopholes apply.
  • Your program should work for values within your language's standard integer size.

Test Cases

25 -> [1,1,1,-1,-1]
47 -> [1,1,-1,1,1,1]
1 -> [1]
3 -> [1,1]
1234567 -> [1,1,-1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,1,1]
Tweeted twitter.com/StackCodeGolf/status/904194535974215680
edited tags
Link
Peter Taylor
  • 43.4k
  • 4
  • 72
  • 179
added 23 characters in body
Source Link
Voile
  • 406
  • 2
  • 13

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term:

25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1

The choice of 0 and 1 is... not very binary. We shall perform the true binary expansion by expanding with powers of 2, but with a coefficient of 1 or -1 instead:

25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1

Now this looks binary.

Given any positive number, it should be trivial to see that:

  • Every odd number has infinitely many true binary expansions
  • Every even number has no true binary expansions

Hence, for a true binary expansion to be well-defined, we require the expansion to be the least, i.e with the shortest length.


Given any positive, odd integer n, return its true binary expansion, from the most significant digit to the least significant digit (or in reversed order).

Rules:

  • As this is , you should aim to do this in the shortest byte count possible. Builtins are allowed.
  • Any output that can represent and list the coefficients is acceptable: an array, a string of coefficients with separators, etc...
  • Standard golfing loopholes apply.
  • Your program should work for values within your language's standard integer size.

Test Cases

25 -> [1,1,1,-1,-1]
47 -> [1,1,-1,1,1,1]
1 -> [1]
3 -> [1,1]
1234567 -> [1,1,-1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,1,1]

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term:

25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1

The choice of 0 and 1 is... not very binary. We shall perform the true binary expansion by expanding with powers of 2, but with a coefficient of 1 or -1 instead:

25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1

Now this looks binary.

Given any positive number, it should be trivial to see that:

  • Every odd number has infinitely many true binary expansions
  • Every even number has no true binary expansions

Hence, for a true binary expansion to be well-defined, we require the expansion to be the least, i.e with the shortest length.


Given any positive, odd integer n, return its true binary expansion, from the most significant digit to the least significant digit.

Rules:

  • As this is , you should aim to do this in the shortest byte count possible. Builtins are allowed.
  • Any output that can represent and list the coefficients is acceptable: an array, a string of coefficients with separators, etc...
  • Standard golfing loopholes apply.
  • Your program should work for values within your language's standard integer size.

Test Cases

25 -> [1,1,1,-1,-1]
47 -> [1,1,-1,1,1,1]
1 -> [1]
3 -> [1,1]
1234567 -> [1,1,-1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,1,1]

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term:

25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1

The choice of 0 and 1 is... not very binary. We shall perform the true binary expansion by expanding with powers of 2, but with a coefficient of 1 or -1 instead:

25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1

Now this looks binary.

Given any positive number, it should be trivial to see that:

  • Every odd number has infinitely many true binary expansions
  • Every even number has no true binary expansions

Hence, for a true binary expansion to be well-defined, we require the expansion to be the least, i.e with the shortest length.


Given any positive, odd integer n, return its true binary expansion, from the most significant digit to the least significant digit (or in reversed order).

Rules:

  • As this is , you should aim to do this in the shortest byte count possible. Builtins are allowed.
  • Any output that can represent and list the coefficients is acceptable: an array, a string of coefficients with separators, etc...
  • Standard golfing loopholes apply.
  • Your program should work for values within your language's standard integer size.

Test Cases

25 -> [1,1,1,-1,-1]
47 -> [1,1,-1,1,1,1]
1 -> [1]
3 -> [1,1]
1234567 -> [1,1,-1,-1,1,-1,1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,1,1]
Source Link
Voile
  • 406
  • 2
  • 13
Loading