6
Introduction
BitShift is an esolang, created by me, to output strings. Sounds boring, is boring. However, the only instructions available to BitShift are 0
and 1
. Therefore it can be challenging to golf in it. To make matters even more interesting, the language only supports 4 bitshifting instructions, a clear, a print and an input instruction.
How it works
BitShift is written by alternating 0
and 1
characters. Once the interpreter finds 2 of the same characters in a row, it will perform an instruction based on the amount of non-alternating characters preceding it.
010010110001010
will perform the operations 3 4 2 1 5
010 0101 10 0 01010
here, the non-alternating characters are seperated by a spacebar for readability.
The interpreter can be found here
Operations
All operations are performed on one single value. BitShift does not know of a stack.
BitShift programs initially start with a value of 0. This value can range from 0-255 and overflows at -1 and 256
1 Shift the value 1 bit to the left (0000 0001 > 0000 0010)
2 Shift the value 1 bit to the right (0000 0010 > 0000 0001)
3 XOR the value with 1 (0000 0000 > 0000 0001)
4 XOR the value with 128 (0000 0000 > 1000 0000)
5 Set the value to 0
6 Convert the value to a character and print it
7 Read a character from user input and set the value to it
Challenge
Your task is to create a program which can convert an input string to the shortest possible BitShift program which will output that string when run.
Rules
- You are not allowed to use the
7
operation - Your program takes only one input argument, which is the string to convert
- Your program will output the translated BitShift program to STDOUT
- You can use any kind of built-in function in your preffered language
- You can use any kind of language, as long as it's created before this date
Scoring
This is a metagolf.
The person who can create the shortest BitShift program will win this challenge. In case of a tie, the lowest byte count will win.
The input string (ISO 8859-1) you should base your answer on is:
This is a string, meant to test the effectiveness of your program. Here are some special characters to make matters interesting: Æ Ø ß. How meta! :D
The special characters used are Æ Ø ß
Please post the output of your program in your answer, so that it can be tested for validation.
The following is an example solution. Obviously, this is a terrible solution.
Javascript, 594 bytes, 4275 characters
var flag = true;
var input = prompt();
var output = ""
for (n in input) {
var c = input.charCodeAt(n).toString(2);
while (c.length < 8) {
c = "0" + c;
}
for (var i = 0; i < 8; i++) {
if (c[i] == "1") {
output += flag ? "010" : "101";
}
if (i < 7) output += flag ? "0" : "1";
}
for (var z = 0; z < 6; z++) {
output += flag ? "0" : "1";
flag = !flag;
}
flag = !flag;
for (var z = 0; z < 5; z++) {
output += flag ? "0": "1";
flag = !flag;
}
flag = !flag;
}
console.log(output);
1Pretty clear, but one problem: 1. This challenge is wide open to "volkswagening". As written, I understand the program is required to work with any input. Is it acceptable to hardcode for the specific input string in the Scoring section? If not, you should provide more examples, but that may complicate the scoring. – Level River St – 2015-11-20T09:34:16.833
1 start="2">
1
Re steve's first point, I recently posed a similar challenge. Feel free to take some inspiration from the scoring section there.
– Martin Ender – 2015-11-20T09:37:09.573It is allowed to hardcode the input string, but that will most likely just increase the byte count of your program. Because it indeed needs to work for any input. All input characters should be one byte long (0-255), i'm not a hero with encodings but i believe that's utf-8? – Bassdrop Cumberwubwubwub – 2015-11-20T09:40:19.600
@steveverrill What is volkswagening? Google turns up empty. – Mario Carneiro – 2015-11-20T09:44:36.927
6
@MarioCarneiro volkswagening is a term I have coined to describe programming to optimize performance in one specific test case, without any regard for normal use. Which is exactly what Volkswagen did with their engine management software. If you've missed all the news, here it is: https://en.wikipedia.org/wiki/Volkswagen_emissions_scandal
– Level River St – 2015-11-20T09:49:21.187@MarioCarneiro it seems I am not the only one who has though of this. The third hit I get on google is
Samsung-is-accused-of-volkswagening-its-tvs-to-oversell-their-energy-efficiency.
– Level River St – 2015-11-20T09:56:45.8631Non-ASCII characters such as the ones in your string are not one byte in UTF-8. – feersum – 2015-11-20T12:24:24.117
Maybe I'm just reading it wrong, but this part of the description sounds unclear to me: "based on the amount of non-alternating characters preceding it". The rest of the explanation makes it sound like non-alternating characters separate the tokens, and then the count of alternating characters determines which instruction is encoded by the token. – Reto Koradi – 2015-11-20T16:57:32.193
It's worth noting that all 3 of the non-ASCII characters in the example text are present in ISO-8859-1. I propose that this be used as the encoding for the output.
– Mego – 2015-11-21T15:53:09.2131Is the bitshift cyclic (e.g.
00000011>10000001
), or if not, will the border bits be filled with ones or zeros? – flawr – 2015-11-21T18:57:24.737@flawr It's not cyclic. Borders are filled with zeroes. – Bassdrop Cumberwubwubwub – 2015-11-23T08:56:10.640
@Mego (and others) I believed these were regular ASCII characters. Found them on this page.
– Bassdrop Cumberwubwubwub – 2015-11-23T08:56:21.050@RetoKoradi You are right, English isn't my mother tongue – Bassdrop Cumberwubwubwub – 2015-11-23T08:56:34.177
2
@Bas ASCII technically covers only 128 letters (it's actually a 7-bit encoding). Everything beyond the first 128 characters is called "extended ASCII". There are many different encodings for those, the simplest (when you're sticking to code points below 256) would be ISO 8859-1 (or Latin-1) which I think you've used here.
– Martin Ender – 2015-11-23T11:13:08.227@MartinBüttner You are right, this is Latin-1. Thanks for the explanation! – Bassdrop Cumberwubwubwub – 2015-11-23T11:37:02.733