Skip to main content
Commonmark migration
Source Link

#Pyth,  12  11 bytes

Pyth,  12  11 bytes

|R_1.>jQ2 1

Try it here!


#How?

How?

|R_1.>jQ2 1   Full program.

      jQ2      Convert input to a binary list.
     .>   1    Cyclically rotate the list above by 1 place to the right.
|R_1           Substitute 0 with -1.
               Implicitly output.

First off, we notice that the task is just "substitute the 0s in the binary writing with -1s and shift to the right by 1 place." — That's exactly what we should do! The binary conversion gives us a list of 0s and 1s. All we should do here is to find a golfy way to convert 0 to -1. The bitwise operator | (bitwise OR) is our friend. The map over the binary representation shifted with | and -1. If the current number is 0, it gets converted to -1.

#Pyth,  12  11 bytes

|R_1.>jQ2 1

Try it here!


#How?

|R_1.>jQ2 1   Full program.

      jQ2      Convert input to a binary list.
     .>   1    Cyclically rotate the list above by 1 place to the right.
|R_1           Substitute 0 with -1.
               Implicitly output.

First off, we notice that the task is just "substitute the 0s in the binary writing with -1s and shift to the right by 1 place." — That's exactly what we should do! The binary conversion gives us a list of 0s and 1s. All we should do here is to find a golfy way to convert 0 to -1. The bitwise operator | (bitwise OR) is our friend. The map over the binary representation shifted with | and -1. If the current number is 0, it gets converted to -1.

Pyth,  12  11 bytes

|R_1.>jQ2 1

Try it here!


How?

|R_1.>jQ2 1   Full program.

      jQ2      Convert input to a binary list.
     .>   1    Cyclically rotate the list above by 1 place to the right.
|R_1           Substitute 0 with -1.
               Implicitly output.

First off, we notice that the task is just "substitute the 0s in the binary writing with -1s and shift to the right by 1 place." — That's exactly what we should do! The binary conversion gives us a list of 0s and 1s. All we should do here is to find a golfy way to convert 0 to -1. The bitwise operator | (bitwise OR) is our friend. The map over the binary representation shifted with | and -1. If the current number is 0, it gets converted to -1.

added 131 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214

#Pyth,  12  11 bytes

|R_1.>jQ2 1

Try it here!


#How?

|R_1.>jQ2 1   Full program.

      jQ2      Convert input to a binary list.
     .>   1    Cyclically rotate the list above by 1 place to the right.
|R_1           Substitute 0 with -1.
               Implicitly output.

First off, we notice that the task is just "substitute the 0s in the binary writing with -1s and shift to the right by 1 place." — That's exactly what we should do! The binary conversion gives us a list of 0s and 1s. All we should do here is to find a golfy way to convert 0 to -1. The bitwise operator | (bitwise OR) is our friend. The map over the binary representation shifted with | and -1. If the current number is 0, it gets converted to -1.

#Pyth,  12  11 bytes

|R_1.>jQ2 1

Try it here!


#How?

|R_1.>jQ2 1   Full program.

      jQ2      Convert input to a binary list.
     .>   1    Cyclically rotate the list above by 1 place to the right.
|R_1           Substitute 0 with -1.
               Implicitly output.

#Pyth,  12  11 bytes

|R_1.>jQ2 1

Try it here!


#How?

|R_1.>jQ2 1   Full program.

      jQ2      Convert input to a binary list.
     .>   1    Cyclically rotate the list above by 1 place to the right.
|R_1           Substitute 0 with -1.
               Implicitly output.

First off, we notice that the task is just "substitute the 0s in the binary writing with -1s and shift to the right by 1 place." — That's exactly what we should do! The binary conversion gives us a list of 0s and 1s. All we should do here is to find a golfy way to convert 0 to -1. The bitwise operator | (bitwise OR) is our friend. The map over the binary representation shifted with | and -1. If the current number is 0, it gets converted to -1.

added 131 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214

#Pyth, 12 bytes

There should definitely be a better way.

:.>.BQ1\0"-1

Try it here!

#Pyth, 12 12  11 bytes

m|td1|R_1.>jQ2 1

Try it here!

#Pyth, 12 bytes

m|tsd1.>.BQ1

Try it here!Try it here!


#How?

:.>|R_1.BQ1\0"->jQ2 1   Full program.

   .BQ   jQ2      Convert input to a binary Stringlist.
 .>   1 .>   1    Cyclically rotate the Stringlist above by 1 place to the right.
:|R_1      \0      Substitute 0 with.
         -1    -1.
               Implicitly output.

#Pyth, 12 bytes

There should definitely be a better way.

:.>.BQ1\0"-1

Try it here!

#Pyth, 12 bytes

m|td1.>jQ2 1

Try it here!

#Pyth, 12 bytes

m|tsd1.>.BQ1

Try it here!


#How?

:.>.BQ1\0"-1   Full program.

   .BQ         Convert input to a binary String.
 .>   1        Cyclically rotate the String above by 1 place to the right.
:      \0      Substitute 0 with.
         -1    -1.
               Implicitly output.

#Pyth,  12  11 bytes

|R_1.>jQ2 1

Try it here!


#How?

|R_1.>jQ2 1   Full program.

      jQ2      Convert input to a binary list.
     .>   1    Cyclically rotate the list above by 1 place to the right.
|R_1           Substitute 0 with -1.
               Implicitly output.
added 131 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214
Loading
added 284 characters in body
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214
Loading
Source Link
Mr. Xcoder
  • 42.5k
  • 9
  • 81
  • 214
Loading