Tin nhắn lập thể ẩn


29

Bạn phải tạo một bản mẫu văn bản theo một chuỗi đầu vào có chứa một đoạn văn bản, một dòng trống sau đó là thông điệp ẩn. Kết quả sẽ được hiển thị dưới dạng một cặp đoạn văn, một đoạn có khoảng cách khác nhau khiến hiệu ứng của nó được nâng lên khi được xem theo cách lập thể (Có thể tìm thấy lời giải thích ở đây ).

Thí dụ

Đầu vào:

I invented vegetarianism.  It is a diet involving no meat, just vegetables.  It is also common in cows - they are awesome.

vegetarianism. is awesome.

Đầu ra:

I      invented    I      invented
 vegetarianism.    vegetarianism. 
It   is a  diet    It  is  a  diet
involving    no    involving    no
meat,      just    meat,      just
vegetables.  It    vegetables.  It
is  also common    is  also common
in cows  - they    in cows  - they
are    awesome.    are   awesome. 

Tiền thưởng

  • Thêm tùy chọn để chọn giữa song song và lác mắt làm đầu vào của người dùng (-20)
  • Điều chỉnh độ rộng cột làm đầu vào của người dùng (-50)

Đây là mã golf, vì vậy mã ngắn nhất sau khi tiền thưởng thắng.


3
Đây là lần đầu tiên tôi thấy một bản lập thể với văn bản. Điều này thật tuyệt.
Michael M.

Họ không làm việc cho tôi: / (Tôi có vấn đề về mắt làm ức chế tầm nhìn lập thể)
David Wilkins

Chúa ơi tôi vừa thấy nó ... Thật ấn tượng!
WallyWest

@Glenn Randers-Pehrson bạn có phiền giải thích lý do tại sao bạn thêm thẻ [sắp xếp] không?
dùng12205

Đó là một sai lầm. Tôi nghĩ rằng tôi đang ở một câu hỏi khác, và không thể tìm cách hủy bỏ. Nếu nó được chấp thuận thì tôi sẽ quay lại.
Glenn Randers-Pehrson

Câu trả lời:


1

Bash, sed: 228 223 197 (242 - 70) = 172

c=${5:-=};R=$c;L=;for f in r l;do
e="sed -e ";$e"$ d;s/$\|  */ \n/g" $1>m
o=1;for w in `$e"$ p;d" $1`;do
$e"$o,/^$w /s/^$w /$L$w$R /" m>n;o="/$c/"
cp n m;done;tr -d \\n<n|fold -sw${2:-35}|$e"s/$c/ /g">$f
L=$c;R=;done;pr -tmw${3:-80} ${4:-l r}

Nếu tập lệnh nằm trong một tập tin thực thi có tên là "stereo", thì hãy gõ

stereo file.in [column_width [page_width ["r l"]]]

cột_ băng thông là một số; 25-45 sẽ hoạt động, mặc định là 35.

page_creen là một số, nên gấp khoảng hai lần cột_ thong, mặc định là 80

Để xem bằng mắt, sử dụng "r l" làm đối số thứ 4. Mặc định là "l r", thiết lập để xem song song.

EDIT: Viết lại để chia tệp thành một từ trên mỗi dòng, sau đó lắp lại ở cuối. Lưu ý: bảo lưu dấu "=" để sử dụng riêng. Bất kỳ dấu "=" nào trong tệp đầu vào sẽ trở thành khoảng trống.

EDIT: Nếu thông điệp của bạn có dấu "=" trong đó, bạn có thể chọn một biểu tượng khác cho tập lệnh để sử dụng, bằng cách cung cấp nó làm tham số thứ 5.

Thí dụ

Đầu vào: chayism.txt:

I invented vegetarianism.  It is a diet involving no meat, just
vegetables.  It is also common in cows - they are awesome.

vegetarianism. is awesome.

Kết quả

./st bd chayism.txt 32 72 "l r": | mở rộng (sử dụng dấu hai chấm cho biểu tượng làm việc bên trong của nó)

I invented  vegetarianism. It       I invented vegetarianism.  It
 is a diet involving no meat,       is  a diet involving no meat,
just vegetables. It is also         just vegetables. It is also
common in cows - they are           common in cows - they are
 awesome.                           awesome.

./st bd washington.txt 35 75 "l r" | mở rộng

In a little district west of          In a little district west of
 Washington Square the streets        Washington  Square the streets
have run crazy and broken             have run crazy and broken
themselves into small strips          themselves into small strips
called 'places'. These 'places'       called 'places'. These 'places'
make strange angles and curves.       make strange angles and curves.
One Street crosses itself a time      One Street crosses itself a time
or two. An artist once discovered     or two. An artist once discovered
a valuable possibility in this        a valuable possibility in this
street. Suppose a collector with a    street. Suppose a collector with a
bill for  paints, paper and canvas    bill for paints,  paper and canvas
should, in traversing this route,     should, in traversing this route,
suddenly meet  himself coming         suddenly meet himself  coming
back, without a cent having been      back, without a cent having been
paid on account!                      paid on account!

"| Mở rộng" là không cần thiết nhưng khi thay đổi đầu ra theo 4 vị trí thì TAB được xử lý không chính xác. Nó có thể được đưa vào tập lệnh với chi phí 7 byte.

Biến thể ImageMagick

Thay thế dòng cuối cùng bằng lệnh ImageMagick từ văn bản sang hình ảnh:

c=${6:-=};R=$c;L=;for f in r l;do
e="sed -e ";$e"$ d;s/$\|  */ \n/g" $1>m
o=1;for w in `$e"$ p;d" $1`;do
$e"$o,/^$w /s/^$w /$L$w$R /" m>n;o="/$c/"
cp n m;done;tr -d \\n<n|fold -sw${2:-35}|$e"s/$c/ /g">$f
L=$c;R=;done;
convert -border 10x30 label:@${4:-l} label:@${5:-r} +append show:

Trong trường hợp này, "r" và "l" để xem chéo và xem song song là các đối số riêng biệt:

./im_st bd chayism.txt 40 80 lr =


(nguồn: simplesystems.org )

EDIT 3: Đã thêm biến thể ImageMagick.


8

TeX 212

Tôi đang sử dụng một hệ thống sắp chữ, không phải ASCII. Độ rộng cột có thể được thay đổi bằng cách thay đổi 90pttrong dòng thứ tư, nhưng tôi không biết liệu điều đó có đủ để đủ điều kiện giảm giá 50 byte hay không. Khoảng cách giữa hai bản sao của văn bản có thể được thay đổi bằng cách thay đổi 9pt, cũng trong dòng thứ tư. Mã có thể được thực hiện ngắn hơn. Người ta có thể thay thế mỗi dòng mới bằng một không gian duy nhất, nhưng không thể loại bỏ chúng hoàn toàn.

\let\e\expandafter\read5to\t\read5to\.\def\a#1
{\def\~##1#1##2\a{\def\t{##1\hbox{\
#1\~{}}##2}\a}\e\~\t\a}\e\a\.{}\shipout\hbox
spread9pt{\hsize90pt\fontdimen3\font\hsize\vbox{\t}\
\let\~\ \def\ {}\vbox{\t}}\end.

Sau khi gọi tex filename.textrong thiết bị đầu cuối, người dùng được nhắc đưa ra văn bản chính, sau đó nhắc lại danh sách các từ cần thay đổi. Không có dòng trống ở giữa. Danh sách các từ được phân tách bằng dấu cách trong dòng thứ hai sẽ xuất hiện chính xác như trong văn bản chính (dấu câu được xử lý giống như một chữ cái, chỉ các khoảng trắng phân cách các từ).


7
Tôi không có trình biên dịch TeX. Tôi có thể xem một bức tranh không?
aebabis

1
Tôi có nghĩa là điều chỉnh theo đầu vào của người dùng thay vì chỉnh sửa mã, nếu không phần thưởng này sẽ áp dụng cho hầu hết mọi mã.
kitcar2000

4

Javascript 391 (441 - 50)

(Golf mã đầu tiên của tôi)

k=' ';Q='length';A=prompt().split(k);S=prompt().split(k);i=-1;M=25;L=[[]];j=0;R='';while(i++<A[Q]-1){if((j+A[i][Q])<M){if(S.indexOf(A[i])>-1){A[i]=(j?k+k:k)+A[i]}L[L[Q]-1].push(A[i]);j+=A[i][Q]+1}else{j=0;i--;L.push([])}}for(i=0;i<L[Q]-1;P(L[i++].join(C))){C=k;while(L[i].join(C+k)[Q]<M){C+=k}}P(L[i].join(k)+k);function P(a){while(a[Q]<M){a=a.replace(k,k+k)}R+=a;for(c in S){a=a.split(k+k+S[c]).join(k+S[c]+k)}R+=k+k+a+'\n'}console.log(R);

Kết quả

In    a  little  district   In    a  little  district
west    of     Washington   west    of    Washington 
Square   the streets have   Square   the streets have
run    crazy  and  broken   run    crazy  and  broken
themselves    into  small   themselves    into  small
strips   called 'places'.   strips   called 'places'.
These     'places'   make   These     'places'   make
strange     angles    and   strange     angles    and
curves.     One    Street   curves.     One    Street
crosses  itself a time or   crosses  itself a time or
two.     An  artist  once   two.     An  artist  once
discovered    a  valuable   discovered    a  valuable
possibility     in   this   possibility     in   this
street.      Suppose    a   street.      Suppose    a
collector   with  a  bill   collector   with  a  bill
for   paints,  paper  and   for  paints ,  paper  and
canvas      should,    in   canvas      should,    in
traversing   this  route,   traversing   this  route,
suddenly   meet   himself   suddenly   meet  himself 
coming    back, without a   coming    back, without a
cent  having been paid on   cent  having been paid on
account!                    account! 

Mã dài:

var arr = "In a little district west of Washington Square the streets have run crazy and broken themselves into small strips called 'places'. These 'places' make strange angles and curves. One Street crosses itself a time or two. An artist once discovered a valuable possibility in this street. Suppose a collector with a bill for paints, paper and canvas should, in traversing this route, suddenly meet himself coming back, without a cent having been paid on account!".split(' ');
var secret = "Washington paints himself".split(' ');
var i = -1;
var MAX_WIDTH = 25;
var lines = [[]];
var _l = 0;

var result = '';

while (i++ < arr.length - 1) {
    if ((_l + arr[i].length) < MAX_WIDTH) {
        if (secret.indexOf(arr[i]) > -1) {arr[i] = (_l?'  ':' ') + arr[i]}
        lines[lines.length - 1].push(arr[i]);
        _l += arr[i].length + 1;

    } else {
        _l = 0;
        i--;
        lines.push([]);
    }
}

for (var i = 0; i < lines.length - 1; putText(lines[i++].join(chars))) {
  // Align text
  var chars = ' ';
  while (lines[i].join(chars + ' ').length < MAX_WIDTH) {
    chars += ' ';
  }
}
putText(lines[i].join(' ') + ' ');
function putText(line) {
  while (line.length < MAX_WIDTH) {
    line = line.replace(' ', '  ');
  }
  // Make the illusion
  result += line;
  for (var val in secret) {
    line = line.split('  '+secret[val]).join(' ' + secret[val] + ' ');
  }
  result += ('   ' + line) + '\n';
}
console.log(result);

1
Hoàn thành tốt Bạn có thể lưu một bó (~ 17) nếu bạn thêm Q='length'và sau đó thay thế những thứ như A.lengthbằng A[Q].
DocMax

@DocMax cảm ơn, đó là một mẹo hay. Tôi là người mới trong codegolf, cảm ơn lời đề nghị của bạn :)
TrungDQ

1
"Washington tự vẽ"?
Joe Z.

3

Javascript 493 (kỳ vọng tối thiểu)

g=" ";l=prompt().split(g);r=l.slice();m=prompt().split(g);f=[];s=f.slice();w=0;n=0;a="";for(i=0;i<l.length;i++){if(l[i]==m[0]){m.shift();l[i]=g+r[i];r[i]+=g;}if(l[i].length+1>w)w=l[i].length+1;}while(l.length){f[f.length]="";s[s.length]="";while(l.length&&f[f.length-1].length+l[0].length<w){f[f.length-1]+=l[0]+g;s[s.length-1]+=r[0]+g;l.shift();r.shift();}f[f.length-1]+=g.repeat(w-f[f.length-1].length);}console.log(f,s);while(f.length){a+=f[0]+s[0]+"\n";f.shift();s.shift();}console.log(a);

Mã này thiết lập hai mảng dòng (trái và phải), sắp xếp chúng thành một chuỗi và in ra f12bàn điều khiển.

Đây chỉ là một câu trả lời tối thiểu, không có ý định giành chiến thắng.


1
418 với JavaScript:L=b=>b.length;c=console.log;p=prompt;r=(l=p().split(g=" ")).slice(),m=p().split(g),s=(f=[]).slice(),n=w=a="";for(i=0;i<L(l);i++)l[i]==m[0]&&(m.shift(),l[i]=g+r[i],r[i]+=g),L(l[i])+1>w&&(w=L(l[i])+1);for(;L(l);){f[L(f)]="";for(s[L(s)]="";L(l)&&L(f[L(f)-1])+L(l[0])<w;)f[L(f)-1]+=l[0]+g,s[L(s)-1]+=r[0]+g,l.shift(),r.shift();f[L(f)-1]+=g.repeat(w-L(f[L(f)-1]))}for(c(f,s);L(f);)a+=f[0]+s[0]+"\n",f.shift(),s.shift();c(a)
WallyWest

3

GolfScript 209 (279 -50 -20)

Đây là chương trình GolfScript lớn đầu tiên của tôi. Tôi sẽ không ngạc nhiên nếu có tối ưu hóa để có được. Cả hai phần thưởng đều được hỗ trợ; chúng dự kiến ​​sẽ được tìm thấy sau các thông báo đầu vào, như:

"I invented vegetarianism.  It is a diet involving no meat, just vegetables.  It is also common in cows - they are awesome."

"vegetarianism. is awesome."

16  # column width
0   # view type, 1 for cross eyed (?)

Nếu bạn đã lưu tệp đó vào input(và đã tải xuống GolfScript ), bạn có thể gọi tập lệnh bằng:

> cat input | ruby golfscript.rb

Chơi gôn

~{{\}}{{}}if:v;:w;n%~' '%\' '%[.]zip 0:c;{' '*}:s;{[.;]}:r;\{:x;{.c=0=x=}{1c+:c;}until.c<\1c+>[[x' 'v+' 'x v+]]\++}/zip{0:c;[[]]\{.,.c+w<{1c++:c;\)@r+r+}{:c;[r]+}if}/{.{,}%{+}*w\- 1$,1-.{1$1$/@@%@0:g;{3$3$g>+s\++1g+:g;}*\;\;}{[;.2/\2%1$s@@+s@)\;\]{+}*}if}%}%zip{{4s\++}*}%n*puts

Bị đánh cắp

~
#The program:

# Parameters, in reverse natural order

{{\}}{{}}if:v;   # view - truthy for parallel, falsey for cross-eyed
:w;         # col width

n%~         # split input on newlines

' '%\       # split secret message tokens
' '%        # split public message

[.]zip      # left and right

0:c;        # word count

{' '*}:s;   # spaces
{[.;]}:r;   # array of top

# for each secret word
\{

  :x;       # word

  {.c=0=x=}
  {1c+:c;} until
  # next public word is this private word

  # splice edits
  .c< \1c+> [[x' 'v+  ' 'x v+]]\ ++

}/
zip

# layout both messages
{

  0:c;    # char count

  [[]]\   # line accumulator

  # split lines
  {

    .,.c+w<
    # if enough room on line

    #append to current line
    {1c++:c;
    \)@r+r+
    }

    #append as new line
    {:c;
    [r]+
    }if

  }/

  # set lines
  {

    .{,}%{+}* # line chars
    w\-       # space chars
    1$,1-     # gaps between words

    # if multi word
    .{

      1$1$      # duplicate params

      /@@       # chars per space
      %         # extra space gaps

      @         # load line
      0:g;      # current gap

      # join row
      {
        3$3$    # params

        g>+     # extra space
        s       # space chars

        \++     # append

        1g+:g;  # update gap
      }*

      \;\;      # drop params

    }
    # else one word
    {
      [
        ;         # drop gap count
        .         # num spaces needed

        2/\       # spaces per side
        2%        # extra space

        1$s       # left space
        @@+s      # right space

        @)\;\     # word

      ]{+}*     # join

    }if

  }% # end line layout

}% # end message layout

zip

{{4s\++}*}%

n*

puts

1

JavaScript 391

_='L=b=>b.length;c=console.log;p=prompt;r=(l*=" ")3m*),s=(f=[]3n=w=a52i=0;i<67i++)l/==m@&&(m!,l/=g+r/,r/8g),?>w&&(w=?72;67){9$]5‌​2:]56)&&%#)+64)<w;)#8l4+g,:-1]8r@+g,l!,r!;#8g.repeat(w-%#))}2c(f,s7%f7)a8$f4+s4+"‌​\\n",f!,s!;c(a)!.shift()#9-1]$??%L(*=p().split(g/[i]2for(3).slice(),4[0]5="";6%l7)‌​;8+=9f[%f):s[%s)?6/)+1@[$0]';for(Y in $='@?:98765432/*%$#!')with(_.split($[Y]))_=join(pop());eval(_)
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.