छिपा हुआ स्टिरोग्राम संदेश


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
यह पहली बार है जब मैंने पाठ के साथ एक स्टिरियोग्राम देखा है। यह कमाल का है।
माइकल एम।

वे मेरे लिए काम नहीं करते: / (मुझे आंख की समस्याएं हैं जो रूढ़िवादी दृष्टि को बाधित करती हैं)
डेविड विल्किंस

पवित्र बकवास मैंने अभी देखा ... यह प्रभावशाली है!
वैलेवेस्ट

@Glenn Randers-Pehrson क्या आप यह बताना चाहेंगे कि आपने [सॉर्टिंग] टैग क्यों जोड़ा?
user12205

वो एक गलती थी। मुझे लगा कि मैं एक और सवाल पर हूं, और रद्द करने का कोई तरीका नहीं खोज सकता। अगर यह मंजूर हो जाता है तो मैं इसे वापस ले लूंगा।
ग्लेन रैंडर्स-पीरसन

जवाबों:


1

बैश, सेड: 228 223 197 (२४२ - 24०) = १ .२

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 एक संख्या है, जिसे कॉलम_ बैंडविड्थ के बारे में दो बार होना चाहिए, डिफ़ॉल्ट 80 है

क्रॉस-आइडेड देखने के लिए, "r l" को 4 वें तर्क के रूप में उपयोग करें। डिफ़ॉल्ट "एल आर" है जो समानांतर देखने के लिए सेट है।

संपादित करें: फ़ाइल को प्रति पंक्ति एक शब्द में विभाजित करने के लिए फिर से लिखना, फिर अंत में फिर से इकट्ठा करें। नोट: अपने स्वयं के उपयोग के लिए "=" संकेत रखता है। इनपुट फ़ाइल में कोई भी "=" संकेत रिक्त हो जाएंगे।

EDIT: यदि आपके संदेश में "=" संकेत हैं, तो आप स्क्रिप्ट का उपयोग करने के लिए 5 वें पैरामीटर के रूप में आपूर्ति करके एक और प्रतीक चुन सकते हैं।

उदाहरण

इनपुट: शाकाहार

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 शाकाहार .xt 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 washton.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!

"विस्तार करना" आवश्यक नहीं है लेकिन जब आउटपुट को 4 स्थानों पर शिफ्ट किया जाता है तो TAB गलत तरीके से नियंत्रित हो जाते हैं। इसे 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:

इस एक में, "आर" और "एल" क्रॉस-आइडेड बनाम समानांतर देखने के लिए अलग-अलग तर्क हैं:

./im_stereo शाकाहार .xt 40 80 lr =


(स्रोत: simplesystems.org )

संपादित 3: जोड़ा गया ImageMagick भिन्नता।


8

TeX 212

मैं टाइपिंग सिस्टम का उपयोग कर रहा हूं, एएससीआईआई का नहीं। कॉलम की चौड़ाई 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 कंपाइलर नहीं है। क्या मैं एक तस्वीर देख सकता हूं?
ऐनाबिस

1
मेरा मतलब था कि कोड को संपादित करने के बजाय उपयोगकर्ता इनपुट द्वारा समायोज्य है, अन्यथा यह बोनस लगभग किसी भी कोड पर लागू होगा।
किटकार्सन

4

जावास्क्रिप्ट 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 धन्यवाद, यह एक अच्छी चाल है। मैं कोडगुल्फ़ में नया हूँ, आपके सुझाव के लिए धन्यवाद :)
TrungDQ

1
"वाशिंगटन खुद पेंट करता है"?
जो जेड

3

जावास्क्रिप्ट 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 जावास्क्रिप्ट के साथ: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)
वैल्लीवेस्ट

3

गोल्फस्क्रिप्ट 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(और गोल्फस्क्रिप्ट डाउनलोड कर ली है ) तो आप इस स्क्रिप्ट को इनवॉइस से देख सकते हैं:

> cat input | ruby golfscript.rb

golfed

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

जावास्क्रिप्ट 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(_)
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.