Сообщение Аресибо - это межзвездное радиосообщение 1974 года, несущее основную информацию о человечестве и Земле, отправленное в шаровое звездное скопление M13 в надежде, что внеземной разум сможет его получить и расшифровать ... Сообщение состояло из 1679 двоичных цифр, приблизительно 210 байтов ...
Число 1679 было выбрано потому, что оно является полупростым (произведение двух простых чисел) и должно быть расположено в виде прямоугольника 73 рядами по 23 столбцами. Альтернативное расположение, 23 строки на 73 столбца, создает непонятный набор символов (как и все другие форматы X / Y).
Это сообщение с добавленным цветом, чтобы выделить его отдельные части. Фактическая двоичная передача не несла информацию о цвете.
Ваша задача - вывести сообщение Аресибо в точном формате 23х73, как показано на рисунке. Любой из этих форматов вывода приемлем:
- Текст, используя один символ для единиц, а другой для нулей (используя обычные правила для разделения строк)
- 2D массив двух разных значений
- Изображение 23x73 с двумя разными цветами
- Непрерывный поток из 1679 элементов двух разных значений (т. Е. Любого из вышеперечисленных форматов, но плоский).
- 1679-битное целое число. Укажите порядок следования битов и байтов (порядковый номер) в вашем решении.
Для вашего удобства вот копируемая версия (также пример вывода в текстовом формате):
00000010101010000000000
00101000001010000000100
10001000100010010110010
10101010101010100100100
00000000000000000000000
00000000000011000000000
00000000001101000000000
00000000001101000000000
00000000010101000000000
00000000011111000000000
00000000000000000000000
11000011100011000011000
10000000000000110010000
11010001100011000011010
11111011111011111011111
00000000000000000000000
00010000000000000000010
00000000000000000000000
00001000000000000000001
11111000000000000011111
00000000000000000000000
11000011000011100011000
10000000100000000010000
11010000110001110011010
11111011111011111011111
00000000000000000000000
00010000001100000000010
00000000001100000000000
00001000001100000000001
11111000001100000011111
00000000001100000000000
00100000000100000000100
00010000001100000001000
00001100001100000010000
00000011000100001100000
00000000001100110000000
00000011000100001100000
00001100001100000010000
00010000001000000001000
00100000001100000000100
01000000001100000000100
01000000000100000001000
00100000001000000010000
00010000000000001100000
00001100000000110000000
00100011101011000000000
00100000001000000000000
00100000111110000000000
00100001011101001011011
00000010011100100111111
10111000011100000110111
00000000010100000111011
00100000010100000111111
00100000010100000110000
00100000110110000000000
00000000000000000000000
00111000001000000000000
00111010100010101010101
00111000000000101010100
00000000000000101000000
00000000111110000000000
00000011111111100000000
00001110000000111000000
00011000000000001100000
00110100000000010110000
01100110000000110011000
01000101000001010001000
01000100100010010001000
00000100010100010000000
00000100001000010000000
00000100000000010000000
00000001001010000000000
01111001111101001111000
Если по какой-то причине ваш язык имеет встроенную функцию для сообщения Аресибо, вы не можете использовать эту встроенную функцию.
Удачи!
ОБНОВЛЕНИЕ: Я принял ответ 05AB1E, так как он был первым, который был короче исходного сообщения. Не позволяйте этому отговорить вас от новых решений.
ОБНОВЛЕНИЕ 2019-09-09: Принятый ответ перемещен в новый ответ 05AB1E, так как он отменяет предыдущий ответ 05AB1E. То же самое относится и к предыдущему обновлению; новые решения по-прежнему приветствуются.
источник
Ответы:
05AB1E, 182 bytes
Try it online! (uses
1
for 0 and0
for 1, as allowed by the question).Try it online! (5 bytes longer,
0
for 0 and1
for 1, added newlines for readability).Most of the code is a base-255 integer constant N, the rest is an Asymmetric Numeral System decoder, using hardcoded probabilities of 75% / 25% (the actual frequency of 0 is 76.35%, which is so close to 75% that it would only save 1.2 bits in the payload, while the nice and round 75% lets us save several bytes in the decoder).
Here's the ANS encoder that generated the constant: Try it online!
источник
05AB1E,
215210200 bytesSaved 15 bytes thanks to Magic Octopus Urn
Try it online! or with Additional formatting
Base-255 encoded trinary string with occurrences of
0000
replaced by2
.источник
0000
with2
by 9 more bytes. - pastebin.com/aZ6tHxjx for 201Java,
688 678 590 379361 bytesReturns a string.
-10 bytes by returning the raw stream (old answer)
-88 bytes by using base 10 numerics (thanks @ceilingcat!)
-211 bytes (I knew it could be golfed!) by using a base-36 encoded BigInteger (thanks @JollyJoker!)
-18 bytes by using a different encoded integer (thanks again @JollyJoker)
Try it online!
Explanation:
источник
Jelly, 213 bytes
Try it online!
I played around with Huffman coding, but the improvements in data size were outweighed by the extra code. As such, this is simply a base-250 encoded version of the desired output. Output consists of an integer that when decoded as bijective base 2 will yield the 1D list of 1s and 2s. Thanks @Emigna for pointing out the change in rules.
Try it online - with further decoding to demonstrate output!
If a more conventional binary encoding is preferred, here is one that encodes an integer representation of the inverted binary message. The most significant bit of the integer represents the beginning of the message.
источник
Brainfuck,
236020081938 bytesTry it online!
I will probably golf this even further soon.
источник
Deadfish~,
111510881084 bytesTry it online!
If someone has the patience to golf this further, I salute you ahead of time. :P
-27 bytes by printing 10s and 100s in places where applicable.
-4 bytes by printing three 1000s and one 1001 on line 3
источник
Piet, 1763 codels
Outputs a stream of 0s and 1s (no line breaks).
Codel size 1:
Codel size 4, for easier viewing:
Explanation
Notes
The program follows a spiral path, clockwise from top left into the centre. The scattered black blocks that roughly follow the diagonals are the flow control. Here's the trace from NPiet.
I've been working on this since the day this challenge went up, but it took a little bit of time to get the message "written" into the picture! I wrote the final loops and the sentinel value first, and then built up the message from the centre outwards. (Since Piet always starts execution from the top left, I expected to have to shuffle and rotate the image around to avoid excess whitespace, but it fit perfectly!)
Fun fact: Run-length encoding in Piet doesn't (by itself) save any space. It takes n codels of one colour to push the value n onto the stack, or n codels of different colours to push that many 1s onto the stack. So it's the same number of codels either way. But the bigger numbers that RLE gives you mean you can use arithmetic tricks (e.g. instead of pushing 9, you can push 3, duplicate, and multiply) to reduce the number of codels, and funny-shaped blocks to fill in available whitespace.
I wasn't sure about how to count score for Piet entries. I found some that seem to count all codels, and others that explicitly only count those actively used. I just counted them all; ignoring white codels (even those that the program never moves through) seems akin to ignoring whitespace in a more typical programming language.
Oh, and I've just now (two hours after posting) realised that I wasted the last bit of time working on this. I wanted to trim off the almost-completely-white last row and column, so I shuffled things around... including the black flow-control blocks. But the edges of the image work the same as black! If I'd just remembered that, I wouldn't have needed to spend so much time puzzling over the intricacies of DPs and CCs...
источник
C# (Visual C# Interactive Compiler),
366332329319 bytesReplace all instances of
␀
with\0
to test.Try it online!
C# (Visual C# Interactive Compiler), 305 bytes, 210 chars
Same with above, replace with
␀
with\0
to test. Output asIEnumerable<string>
.Try it online!(Courtesy of Jo King)
источник
++
in12-i++%2
is a nop (at least, it worked for me when I removed it)Perl 6, 368 bytes
Try it online!
The long string is the message as a single base-36 number (with a single prefixed 1 bit to preserve the leading zeroes) which is then converted back to binary and printed 23 bits at a time.
источник
>>.say
and&{S/.//}
to save bytes. Have you thought about using a different base instead?Wolfram Language (Mathematica), 383 bytes
Try it online!
источник
Node.js, 333 bytes
Returns a binary string of 1,679 characters.
Try it online! (with formatted output)
JavaScript (ES8), 413 bytes
Returns a binary string of 1,679 characters.
Try it online! (with formatted output)
источник
Bubblegum,
275236 bytesTry it online!
источник
bash + GNU tools, 351 bytes
TIO
источник
MathGolf,
223220 bytesTry it online!
Explanation
источник
L/n
to the footer, so it's actually 220 bytes. Can more bytes be saved by porting the 05AB1E / Java answers (using this compressed integer, convert it to base-3, and replace all2
s with0000
s)?2
to♫░╞
? EDIT: Never mind. I see you don't have a Base Conversion builtin (except for binary/hexadecimal) to convert to base-3?+
to the footer as wellPerl 5, 460 bytes
Try it online!
источник
Python 2, 336 bytes
Try it online!
Prints a string of bytes
источник
Java (OpenJDK 8), 364 bytes
Try it online!
Explanation: First had
n->new java.math.BigInteger(str,36).toString(2)
, just converting a radix 36 number to binary, but that needed nine extra chars for leading zeroes. Then, I got the idea of run-length encoding some zeroes as twos. A length of four zeroes seems to minimize the radix 36 length, son->new java.math.BigInteger(str,36).toString(3).replaceAll("2","0000")
See the discussion under this answer for the leading zeroes bug fix by @KevinCruijssen
источник
[Python 2], 345 bytes
I encoded the length of strings of 0s as a byte starting at chr(31). Then I encoded the remaining 10101 as binary numbers starting at chr(70) up to chr(126). Binary strings that didn't fit were split up into smaller chunks.
Edit: Reduced to 326 bytes. Thanks Jo King
Edit: Fixed a bug in the code generator program
Edit: Final Edit
источник
o
to a variable.Zsh, 577 bytes
try it online!!
Used custom encoding logic. The string
S
is 421 characters, could possibly be compressed a bit more. Lettersa-w
represent repeated0
s. Numbers1-9
represent repeated1
s. Lettersx y z
represent10 100 1000
respectively.Maybe I should have tried byte-pair encoding or Ascii85.
источник
Bash,
702697 bytesTry it online!
источник
Ruby, 362 bytes
Integer written in base 36. There's surely a more efficient way to compress the integer, e.g. with
zlib
orbase64
.Try it online!
источник
[C++ (VC++)(but tested with gcc as well)], 585 bytes
Try it online!
ungolfed Version (lacks the break after the 1679th element though and goes until the 1680th):
as an Explanation: i concatenated the 73 lines of sample output given to one long line. i encoded them in hexadecimal where the bit order is msbfirst (using this program https://github.com/Marc-Bender/longBinaryStreamToHex/releases/download/addedErrorCode-4/longBinaryStreamToHex.exe) i shortened the Output of that by about 70 hexadecimal Digits by using the letters 'G'-'Z' as a sign to repeat the last Digit for a certain amount of times (Z = 2more times, Y = 3more times …) the rest should be relatively self explainatory for Code-Golfers. abusing the preprocessor to shorten loops, abusing the
,
Operator and the like.Output Format is uninterrupted stream of 1679 0/1-values.
источник
Perl 6, 348 bytes
Based on Benjamin Urquhart's Java solution.
Uses a straight stream of 0 and 1 characters. The link below has some code to prettify the output.
Try it online!
источник
Tcl, 366 bytes
Try it online!
источник
C++ (with Gnu multi-precision library), 359 bytes
This outputs the string as one line. It uses '1' for 0, and '0' for 1 :/
It simply reads the embedded string as base 62, and prints it as base 2.
Use
g++ -g arecibo.cpp -lgmp -lgmpxx
to compile and linkисточник
class_mpz
withmpz_class
Perl 6, 276 bytes
Try it online!
Outputs as a series of 1679 0s and 1s. You can have it on different lines by adding
.comb(23)>>
before thesay
.Explanation:
I can probably save bytes by using the output as a 1679 bit integer instead, or reversing the bit representation.
источник
C++ (gcc), 748 bytes
Try it online!
By replacing the most used substring with a new character until it's not worth it anymore
источник
Python 3, 331 bytes
Try it online!
источник