"সিঁড়ি- ify" একটি স্ট্রিং


12

আপনাকে অবশ্যই এমন একটি প্রোগ্রাম বা ফাংশন লিখতে হবে যা "সিঁড়ি-আইয়েড" স্ট্রিং তৈরি করে। আপনি এখানে একটি স্ট্রিং "সিঁড়ি-ইফী" দিচ্ছেন:

স্ট্রিংয়ের প্রতিটি চরিত্রের জন্য:

  • চরিত্র একটি ঊর্ধ্ব বা ছোট হাতের স্বরবর্ণ, 'Y' সহ না, আউটপুট হয়, তাহলে তখন স্ট্রিং বাকি সরাতে আপ একটি কলাম।

  • অক্ষরটি যদি কোনও স্থান বা কোনও ট্যাব হয় তবে আউটপুট করুন তারপরে বাকী স্ট্রিংটি একটি কলমের নীচে সরান ।

  • চরিত্রটি যদি না হয় তবে এটিকে আউটপুট করুন।

আইও যে কোনও যুক্তিসঙ্গত বিন্যাসে থাকতে পারে। ইনপুটটিতে কোনও নতুন লাইন থাকবে না। আপনি যদি চান তবে আপনি যে কোনও পেছনের সাদা স্থান সরিয়ে ফেলতে পারেন।

আপনি যদি স্ট্রিংটি মুদ্রণের পরিবর্তে ফিরিয়ে দেওয়া পছন্দ করেন তবে দয়া করে একটি ছোট প্রোগ্রাম অন্তর্ভুক্ত করুন যা আপনার স্ট্রিংটি মুদ্রণ করবে যাতে এটি দৃশ্যমান হতে পারে। এটি বাধ্যতামূলক নয়, এটি আপনার বাইট-কাউন্টের দিকেও যাবে না। কোডটি দিয়ে আউটপুট বা টিঙ্কার যাচাই করতে সক্ষম হবেন এমন গল্ফ বা এসওল্যাংগুলি (আমার মতো) বোঝে না এমন ব্যবহারকারীদের জন্য এটি কেবল একটি সুবিধা।

নমুনা আইও:

"বিসিডিএফ গিজকিল" এর আউটপুট:

    f    jkl
bcde  ghi

"প্রোগ্রামিং ধাঁধা এবং কোড-গল্ফ" এর আউটপুট:

                               lf
                            -Go
                  s  nd   de   
         ng   zzle  A   Co       
      mmi   Pu                 
   gra        
Pro

"Abcdefghijklmnopqrstuvwxyz" এর আউটপুট:

                     vwxyz
               pqrstu
         jklmno
     fghi          
 bcde             
A        

যথারীতি, এটি কোড-গল্ফ, তাই বাইট জেতে সংক্ষিপ্ত উত্তর।



আমরা কি কোনও শীর্ষস্থানীয় / চলমান শ্বেত স্থান ছিনিয়ে নিতে পারি?
orlp

@orlp যেহেতু এটি চাক্ষুষ উপস্থাপনাটি একেবারেই বদলাবে না, কেন তা আমি দেখছি না।
জেমস

যদি আমরা স্ট্রিংটি ফেরত দেওয়া বেছে নিই, তবে মুদ্রণের জন্য প্রোগ্রামটি কি বাইট গণনায় অন্তর্ভুক্ত?

@ পিটারপিটার আমার শেষ সম্পাদনা দেখুন।
জেমস 0

উত্তর:


2

এমএটিএল , 38 37 বাইট

Oj33<G13Y2m-IL)hYstX<-"@Z"GX@)h]Xh!c!

এটি অনলাইন চেষ্টা করুন!

ব্যাখ্যা

প্রতিটি চরের জন্য, কোডটি তার উল্লম্ব অবস্থানটি গণনা করে, উপরে থেকে পরিমাপ করা হয় (0 সর্বোচ্চ)। এরপরে এটি আবর্তিত আউটপুট স্ট্রিংগুলি তৈরি করে: প্রতিটি চরটি উল্লম্ব অবস্থানটি নির্দেশ করে যতগুলি নেতৃস্থানীয় স্পেস সহ একটি লাইনে থাকে। তারপরে সমস্ত লাইনগুলি 2D চর অ্যারেতে সংযুক্ত করা হয়, যা শেষ পর্যন্ত স্থানান্তরিত হয় এবং প্রদর্শিত হয়।

O       % push a 0
j       % input a string
33<     % array of the same length as the input that contains true for spaces or tabs
G       % push input again
11Y2    % string 'aeiouAEIOU'
m       % array of the same length as the input that contains true for vowels
-       % subtract
IL)     % remove last element
h       % prepend the 0 that is at the bottom of the stack
Ys      % cumulative sum. This gives the vertical position of each char
tX<     % duplicate. Compute minimum
-       % subtract. This sets minimum vertical position to 0
"       % for each vertical position
  @     %   push vertical position of current character
  Z"    %   string with that many spaces
  G     %   push input again
  X@)   %   get the character corresponding to the current iteration index
  h     %   concatenate horizontally
]       % end for each
Xh      % concatenate all lines into a row cell array
!       % transpose into a column cell array
c       % convert into 2D array, padding with spaces if needed
!       % transpose. Implicitly display

7

পাইথ, 63 বাইট

V_Q aY?}rN0"aeiou"=hZ?}N"     "=tZZ;Jh.mbYKh.MZYjC.b++*d+JNY*dK_YQ
                         ^^^^^
                         |||||
                         |tabs
                        space

মাঝের স্পেসগুলি আসলে একটি একক ট্যাব চরিত্র, তবে স্ট্যাক এক্সচেঞ্জ এটিকে চারটি স্পেস হিসাবে রেন্ডার করে।

এটি অনলাইন চেষ্টা করুন!


আমি 64 বাইট গণনা।
কনর ও'ব্রায়ান

কারণ এখানে ট্যাবটি চারটি স্থান হিসাবে দেখানো হচ্ছে।
ফাঁস নুন

অবশ্যই 64 বাইট। mothereff.in/…

না, @ কেনেলাউ মানে চারটি জায়গার পরিবর্তে ট্যাব চরিত্রটি স্থাপন করা উচিত। এটি দেখুন অনলাইন লিঙ্কে দেখুন।
মামা ফান রোল

@ মামাফুনরোল স্ট্যাকএক্সচেঞ্জটি স্বয়ংক্রিয়ভাবে 4 টি স্পেস দ্বারা ট্যাবগুলিকে প্রতিস্থাপন করে।
orp

4

পাইথন 2, 141 137 বাইট

def S(s,l=[0]):
 for c in s:l+=[l[-1]-(c in"aeiouAEIOU")+(c<"!")]
 for h in sorted(set(l)):print"".join([" ",c][i==h]for i,c in zip(l,s))

মনে হচ্ছে এটি কোনও
ফাঁকে

@ স্কোর_উন্ডার এটি আমার মেশিনে দুর্দান্ত কাজ করে। আপনি পাইথন 2 পরীক্ষা করছেন?
orlp

ইহা কাজ করছে. আমি কীভাবে পুরোপুরি জানি না তবে এটি প্রথমবারের সাথে পেস্ট করার সময় আমার অবশ্যই ভুল হয়েছে।
স্কোর_উন্ডার

3

জাভাস্ক্রিপ্ট (ফায়ারফক্স 30-57), 151 বাইট

s=>[...s].map((c,i)=>r[c<'!'?n++:/[AEIOU]/i.test(c)?n--:n][i]=c,n=s.length,r=[for(_ of s+s)[]])&&[for(a of r)if(s=[for(c of a)c||' '].join``)s].join`\n`

যেখানে \nআক্ষরিক নিউলাইন চরিত্রের প্রতিনিধিত্ব করে।


2
টেম্পলেট স্ট্রিংগুলির সাহায্যে আপনি একটি স্ট্রিংয়ে একটি নতুন লাইন রাখতে পারেন, যাতে আপনি /n``
জেনেরিক ব্যবহারকারী

1
@ জেনেরিকউজার বাইট গণনাটি সামঞ্জস্য করে ধরেই নেওয়া হয়েছে যে আপনি ইতিমধ্যে এটি সম্পন্ন করেছেন; আমি কেবল আমার পোস্টে একটি আক্ষরিক নিউলাইন ব্যবহার করতে চাইনি।
নীল

1

সি, 180 বাইট

char s[99];i,j,p[99],m,M;main(c){for(gets(s);c=s[i];j+=strchr("aeiou",c|32)!=0,j-=c<33,m>j?m=j:M<j?M=j:0)p[i++]=j;for(;m<=M;putchar(10),M--)for(i=0;c=s[i];)putchar(M^p[i++]?32:c);}

Ungolfed:

char s[99];i,j,p[99],m,M;
main(c){for(gets(s);c=s[i];
j+=strchr("aeiou",c|32)!=0,j-=c<33,m>j?m=j:M<j?M=j:0)
  //move current height up or down, adjust minimum and maximum height
p[i++]=j;  //record height of character
for(;m<=M;putchar(10),M--)  //from maximum to minimum height
for(i=0;c=s[i];)putchar(M^p[i++]?32:c);}  //print only characters on this height

1

পার্ল, ১১০ বাইট (108 বাইট স্ক্রিপ্ট + 2 বাইট পতাকা)

$h=0;map{$h{$h}.=' 'x($p-$p{$h}).$_;$p{$h}=++$p;$h+=/[aeiou]/i-/\s/}split//;print for@h{sort{$b<=>$a}keys%h}

এর সাথে চালান perl -nl script.pl, ইনপুট স্টিডিনে থাকে, আউটপুট স্টাডআউট হয় on

Deobfuscated

আমি ভেরিয়েবলগুলিকে আরও সংবেদনশীলরূপে নামকরণ করেছি, কোড use strictএবং আনুগত্য তৈরি করেছি use warningsএবং অনেকগুলি যাদু পার্ল স্বয়ংক্রিয়ভাবে করে ফেলেছি।

এটি কেবল এটি হিসাবে চালানো হয় perl script.pl, কারণ এটি -nlস্ক্রিপ্টের অভ্যন্তরে পতাকাগুলির প্রতিলিপি তৈরি করে ।

use strict;
use warnings;
use English;

# The effect of -l in perl's flags
$INPUT_RECORD_SEPARATOR = "\n";
$OUTPUT_RECORD_SEPARATOR = "\n";

# These variables are magicked into existence
our $column = 0;
our %line_col = ();
our %lines = ();

# The implicit while-loop is the effect of -n in perl's flags
while (defined(my $line = <>)) {
    # The "chomp" is part of perl's -l flag too
    chomp $line;

    # Here starts the actual script. "$h=0" turns into...
    our $height = 0;
    for my $char (split '', $line) {
        if (!exists $line_col{$height}) {
            # Setting it to 0 is a bit of a white lie, but it might as well be 0.
            # Perl would otherwise have called the value "undef", which is
            # similar to 0 in numeric contexts.
            $line_col{$height} = 0;
        }

        $lines{$height} .= ' ' x ($column - $line_col{$height});
        $lines{$height} .= $char;

        $column++;
        $line_col{$height} = $column;

        $height++ if $char =~ /[aeiou]/i;
        $height-- if $char =~ /\s/;
    }

    # Sort line heights numerically descending (so the greatest is printed first)
    my @heights = sort { $b<=>$a } keys %lines;

    for my $line (@lines{ @heights }) {
        print $line;
    }
}

1

জাভাস্ক্রিপ্ট (ES6), 133

s=>s.replace(/[^aeiou ]*(.?)/gi,(z,x,c)=>(q=o[r]||'',o[r]=q+=' '.repeat(c-q.length)+z,x<'!'?++r:r?--r:o=[,...o]),o=[],r=0)&&o.join`
`

কম গল্ফড

s=>(
  s.replace(/[^aeiou ]*(.?)/gi,(z,x,c)=>(
    q = o[r] || '',
    o[r] = q += ' '.repeat(c - q.length) + z,
    x == ' ' ? ++r : r ? --r : o = [,...o]
  ), o = [], r = 0),
  o.join`\n`
)

পরীক্ষা

f=s=>s.replace(/[^aeiou ]*(.?)/gi,(z,x,c)=>(q=o[r]||'',o[r]=q+=' '.repeat(c-q.length)+z,x<'!'?++r:r?--r:o=[,...o]),o=[],r=0)&&o.join`
`

function test() {
  i=I.value
  O.textContent=f(i)
}

test()
#I { width:90%}
<input id=I oninput='test()' value='Programming Puzzles And Code-Golf'>
<pre id=O>


0

হাস্কেল (এএনএসআই টার্মিনালের মধ্যে), 75 বাইট

("\27[2J"++).(h=<<)
h ' '="\27[B "
h c|elem c"aeiouAEIOU"=c:"\27[A"
h c=[c]

ব্যবহারের উদাহরণ: putStr $ ("\27[2J"++).(h=<<) $ "bcdef ghijkl"

এটি কার্সারটিকে উপরে এবং নীচে সরানোর জন্য এএনএসআই এস্কেপ কোডগুলি ব্যবহার করে।


0

সি, 173 160 156 155 বাইট

সম্পাদনা করুন: 13 বাইটটি শেভ করতে @ এমিলিবিট থেকে স্ট্র্যাচআরআর ব্যবহার করার ধার নেওয়া ধারণা

সম্পাদনা 2: ন্যূনতম / সর্বোচ্চ তুলনা, -4 বাইট স্ট্রিমলাইড

সম্পাদনা 3: সি এর পরিবর্তে মূল (সি), -1 বাইট দিয়ে শুরু করতে কোনও মান থাকতে পারে

সম্পাদনা 4: যুক্তগোষ্ঠী / ব্যাখ্যা যুক্ত করা হয়েছে

p,l,j,m;main(c){char b[99],*s=gets(b);for(;j<m+2;p?putchar(c?l?32:c:10):l<j?j=l:l>m?m=l:0,l-=c?(c&=223)&&c-9?!!strchr("AEIOU",c):-1:(p=s=b,l+j++))c=*s++;}

অবহেলিত এবং ব্যাখ্যা:

/* declare and initialize these variables to int and 0 */
p,l,j,m;

/* declares main, but also int c */
main(c)
{

  /* we can handle strings of length 98 (+1 for string-terminating 0) */
  /* we declare and initialize s to point to the beginning of the input
     string for the first pass through the for loop */
  char b[99],*s=gets(b);

  /* the for-loop actually contains nested loops, where the inner loops
     behave differently depending on the outer loop parameter p as follows:
     p attains the values false (0) and true (non-null pointer), in this order.

     p == false:
      the inner loop has the parameter s and passes through all the characters
      in the string until the string is exhausted (*s == 0). l is the vertical
      position of the current character relative to the first character
      (l = 0), smaller number = higher up. The purpose here is simply to find
      the range of vertical positions [j, m] present in the string. The
      commands in execution order are:

      -- loop over s --

      // test does not do anything since j <= m by design
      1. j < m+2

      // puts current char in c and increments string counter
      2. c = *s++          

      // ensures that j (m) equals the min (max) of the vertical positions (l)
         encountered so far. At first step j = l = m = 0.
      3. l<j?j=l:l>m?m=l:0 

      // c != 0, this updates the vertical position for the next character
      // c = SPC or C = TAB -> lower (l increases by 1)
      // c = "aeiouAEIOU" -> higher (l decreases by 1)
      4a. l-=(c&=223)&&c-9?!!strchr("AEIOU",c):-1

      -- loop over s ends --

      // c == 0, this resets the string pointer s and puts p = true, and 
      //         thereby initiates the next phase of the algorithm
      //         see rest of the explanation at p == true)
      4b. p=s=b

    p == true:
     now there are two inner loops. The outer of these has the parameter j,
     which ranges from the smallest vertical position+1 (the value of j after
     the p == false pass) to the largest vertical position+1 (m+2 after the
     p == true pass). The innermost loop has the parameter s and passes through
     all characters in the string until the string is exhausted (*s == 0) just
     as in the p == false inner loop. Here l is now the vertical position
     relative to the current position j-1, so that l == 0 when a character is
     at the current level. Such characters are printed as is, whereas
     characters at other levels are replaced by space. The end-of-string
     marker 0 outputs a newline. The commands in execution order are:

      -- loop over j --

      // at first step increments j to point to be one more than the
      // current vertical position. At other steps moves the current position
      // (j-1) one vertical position downwards. Also, at all steps, this
      // biases the vertical position counter l to be zero at the current
      // vertical position (j-1)
      1. l=-j++

      // compare j to stopping criteria, exit if j > m+1
      2. j < m+2

       -- loop over s --

       // puts current char in c and increments string counter
       3. c = *s++          

       // outputs character as follows:
       // c == 0 (end of string), output newline
       // c != 0 (middle of string)
       //  l == 0 (character at current vertcial position), output c
       //  l != 0 (character not at current vertical position), output space
       4. putchar(c?l?32:c:10)

       // c != 0, this updates the vertical position for the next character
       // c = SPC or C = TAB -> lower (l increases by 1)
       // c = "aeiouAEIOU" -> higher (l decreases by 1)
       5a. l-=(c&=223)&&c-9?!!strchr("AEIOU",c):-1

       -- loop over s ends --

      // c == 0, this resets the string pointer s for next loop over s
      //         algorithm (see rest of the explanation at p == true)
      5b. p=s=b

     -- loop over j ends --
  */

  for(;
      j<m+2;
      p?putchar(c?l?32:c:10):
    l<j?j=l:l>m?m=l:0,
      l-=c?(c&=223)&&c-9?!!strchr("AEIOU",c):-1:
       (p=s=b,l+j++))
    c=*s++;
}
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.