Wise is a simple bitwise language I designed a while back. It is based around Python's bitwise operations. It has several operations most of these are the same or very similar to the equivalent symbol in Python.
:Duplicate the top of the stack
?Rotate the top of the stack to the bottom
!Rotate the bottom of the stack to the top
]loop while the top of the stack is not zero
~not the top of the stack (
-negate the top of the stack (
>bitshift the top of the stack once to the right (
<bitshift the top of the stack once to the left (
^xor the top two items of the stack (Same as Python)
|or the top two items of the stack (Same as Python)
&and the top two items of the stack (Same as Python)
Making an integer in Wise is pretty simple you can make zero with
::^ and increment it with
~- so you make zero and increment it a bunch of times. However if we remove the
- things become a little more interesting.
We can still make every number using the remaining operations. For example here is 3
This works because
~ turns zero, an infinite string of
0 bits, into negative one, an infinite string of
1 bits, each
< appends a
0 bit to the end, when we are done we do
~ which turns each it into a string of
0s followed by a two
1s, or as most people call it 3.
Write a program that when given a positive integer will output a Wise program that will create the number
n without any
- in its source (the source of the output, you may use
- in your own source). You may assume that there is already a zero on the top of the stack.
This list is not exhaustive they are simply possible outputs
1 -> ~<~ 2 -> ~<~< 3 -> ~<<~ 4 -> ~<~<< 5 -> ~<~:<<| 6 -> ~<<~< 7 -> ~<<<~ 8 -> ~<~<<< 9 -> ~<~:<<<| 10 -> ~<~:<<|< 11 -> ~<<~:><<<| 12 -> ~<<~<< 13 -> ~<<~:<<<|> 14 -> ~<<<~< 15 -> ~<<<<~ 16 -> ~<~<<<<