ข้อความภาพสามมิติที่ซ่อนอยู่


29

คุณต้องสร้างภาพสามมิติของข้อความตามสตริงอินพุตที่มีย่อหน้าของข้อความบรรทัดว่างแล้วข้อความที่ซ่อนอยู่ ผลลัพธ์จะปรากฏเป็นคู่ย่อหน้าหนึ่งย่อหน้าที่มีระยะห่างต่างกันทำให้เกิดผลของการยกขึ้นเมื่อดูภาพสามมิติ (คำอธิบายสามารถพบได้ที่นี่ )

ตัวอย่าง

การป้อนข้อมูล:

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

vegetarianism. is awesome.

เอาท์พุท:

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. 

โบนัส

  • เพิ่มตัวเลือกเพื่อเลือกระหว่างแบบขนานและแบบเหลื่อมเป็นอินพุตผู้ใช้ (-20)
  • ความกว้างคอลัมน์ที่ปรับได้ตามที่ผู้ใช้ป้อน (-50)

นี่คือรหัสกอล์ฟดังนั้นรหัสที่สั้นที่สุดหลังจากโบนัสชนะ


3
นี่เป็นครั้งแรกที่ฉันเห็นภาพสามมิติพร้อมข้อความ นี่มันเจ๋งมาก.
Michael M.

พวกเขาใช้งานไม่ได้สำหรับฉัน: / (ฉันมีปัญหาสายตาที่ยับยั้งการมองเห็นภาพสามมิติ)
David Wilkins

อึศักดิ์สิทธิ์ฉันเพิ่งเห็นมัน ... มันน่าประทับใจ!
WallyWest

@Glenn Randers-Pehrson คุณจะอธิบายว่าทำไมคุณจึงเพิ่มแท็ก [sorting]
user12205

มันเป็นความผิดพลาด. ฉันคิดว่าฉันมีคำถามอื่นและไม่สามารถหาวิธีที่จะยกเลิก หากได้รับอนุมัติแล้วฉันจะย้อนกลับ
Glenn Randers-Pehrson

คำตอบ:


1

ทุบตี, 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}

หากสคริปต์อยู่ในไฟล์เรียกทำงาน "สเตอริโอ" ให้พิมพ์

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

column_width เป็นตัวเลข 25-45 จะใช้งานได้ค่าเริ่มต้นคือ 35

page_width เป็นตัวเลขควรเป็นสองเท่าของ column_width ค่าเริ่มต้นคือ 80

สำหรับการดูแบบสองตาใช้ "r l" เป็นอาร์กิวเมนต์ที่ 4 ค่าเริ่มต้นคือ "l r" ซึ่งตั้งค่าสำหรับการดูแบบขนาน

แก้ไข: เขียนซ้ำเพื่อแยกไฟล์เป็นหนึ่งคำต่อบรรทัดจากนั้นประกอบอีกครั้งในตอนท้าย หมายเหตุ: ขอสงวนสัญลักษณ์ "=" สำหรับการใช้งานของตัวเอง เครื่องหมาย "=" ใด ๆ ในไฟล์อินพุตจะกลายเป็นช่องว่าง

แก้ไข: หากข้อความของคุณมี "=" ลงชื่อเข้าใช้คุณสามารถเลือกสัญลักษณ์อื่นสำหรับสคริปต์ที่จะใช้โดยระบุเป็นพารามิเตอร์ที่ 5

ตัวอย่าง

อินพุต: vegetarianism.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.

ผล

./stereo vegetarianism.txt 32 72 "l r": | ขยาย (ใช้เครื่องหมายโคลอนสำหรับสัญลักษณ์การทำงานภายใน)

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.

./stereo washington.txt 35 75 "l r" | ขยาย

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!

ไม่จำเป็นต้องใช้ "| expand" แต่เมื่อเลื่อนการส่งออก 4 ตำแหน่งแท็บจะได้รับการจัดการอย่างไม่ถูกต้อง มันสามารถใส่ลงในสคริปต์ในราคา 7 ไบต์

รูปแบบ ImageMagick

การแทนที่บรรทัดสุดท้ายด้วยคำสั่ง ImageMagick แบบข้อความต่อภาพ:

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:

ในส่วนนี้ "r" และ "l" สำหรับการดูแบบ cross-eyed และการดูแบบขนานเป็นอาร์กิวเมนต์ที่แยกกัน:

./im_stereo vegetarianism.txt 40 80 lr =


(ที่มา: simplesystems.org )

แก้ไข 3: เพิ่มรูปแบบ ImageMagick


8

TeX 212

ฉันใช้ระบบเรียงพิมพ์ไม่ใช่ ASCII ความกว้างของคอลัมน์สามารถเปลี่ยนแปลงได้โดยการเปลี่ยน90ptในบรรทัดที่สี่ แต่ฉันไม่รู้ว่าเพียงพอที่จะรับส่วนลด 50 ไบต์หรือไม่ ระยะห่างระหว่างข้อความสองสำเนาสามารถเปลี่ยนแปลงได้โดยการเปลี่ยน9pt, และในบรรทัดที่สี่ รหัสอาจสั้นลงได้ หนึ่งสามารถแทนที่แต่ละบรรทัดใหม่ด้วยพื้นที่เดียว แต่ไม่สามารถลบออกได้อย่างสมบูรณ์

\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.

หลังจากโทรtex filename.texเข้าเครื่องเทอร์มินัลผู้ใช้จะได้รับแจ้งให้ป้อนข้อความหลักจากนั้นจะถามอีกครั้งเพื่อให้รายการคำศัพท์เปลี่ยน ไม่มีบรรทัดว่างในระหว่าง รายการ (คั่นด้วยช่องว่าง) ของคำที่ให้ไว้ในบรรทัดที่สองควรปรากฏอย่างแน่นอนเหมือนกับที่อยู่ในข้อความหลัก (เครื่องหมายวรรคตอนจะถือว่าเหมือนตัวอักษร


7
ฉันไม่มีคอมไพเลอร์ TeX ฉันขอดูรูปได้ไหม
aebabis

1
ฉันหมายถึงการปรับโดยการป้อนข้อมูลของผู้ใช้แทนที่จะแก้ไขรหัสมิฉะนั้นโบนัสนี้จะใช้กับเกือบทุกรหัส
kitcar2000

4

Javascript 391 (441 - 50)

(กอล์ฟรหัสแรกของฉัน)

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);

ผล

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! 

รหัสยาว:

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
ทำได้ดีมาก คุณสามารถบันทึกพวง (~ 17) ถ้าคุณเพิ่มQ='length'แล้วแทนที่สิ่งที่ต้องการด้วยA.length A[Q]
DocMax

@DocMax ขอบคุณนั่นเป็นเคล็ดลับที่ดี ฉันใหม่ใน codegolf ขอบคุณสำหรับข้อเสนอแนะของคุณ :)
TrungDQ

1
"วอชิงตันวาดภาพตัวเอง"?
Joe Z.

3

Javascript 493 (ความคาดหวังขั้นต่ำ)

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);

รหัสนี้ตั้งค่าสองแถวของบรรทัด (ซ้ายและขวา) จัดเรียงไว้ในสตริงและพิมพ์ไปยังf12คอนโซล

นี่เป็นเพียงคำตอบขั้นต่ำไม่ได้ตั้งใจจะชนะ


1
418 กับ 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)

นี่เป็นโปรแกรม GolfScript ตัวแรกของฉัน ฉันจะไม่แปลกใจถ้ามีการปรับให้เหมาะสม สนับสนุนโบนัสทั้งสองอย่าง คาดว่าจะพบได้หลังจากอินพุตข้อความเช่น:

"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 (?)

หากคุณบันทึกไฟล์นั้นไปที่input(และดาวน์โหลดGolfScript ) คุณสามารถเรียกใช้สคริปต์ด้วย:

> cat input | ruby golfscript.rb

แข็งแรงเล่นกอล์ฟ

~{{\}}{{}}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

Ungolfed

~
#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(_)
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.