তোয়ালে দিন ভুলে গেছি


15

তোয়ালে দিন ভুলে গেছি

স্যান্ডবক্স লিঙ্ক

উভয় উদাহরণের জন্য পিএইচপি স্ক্রিপ্ট (ত্রুটি, স্ট্রিংটির বিন্যাসকরণ)

পিএইচপি স্ক্রিপ্ট সংশোধন করা হয়েছে, ইনপুটটি স্বতঃস্পষ্ট

পিএইচপি স্ক্রিপ্ট আরও ফলাফল ইনপুট মন্তব্য / uncomment $argvসঙ্গে

আপনি জানেন যে, 25 মে টাওয়েল দিবস হিসাবে সুপরিচিত , কারণ একটি তোয়ালে থাকতে পারে এমন অনেকগুলি ব্যবহার।

"দ্য হিচিকার্স গাইড টু দ্য গ্যালাক্সি" বইটির একটি সহজ সূত্র (ব্যক্তিগতভাবে আমি এই বইটিকে "দৈনন্দিন গাইড" হিসাবে নিয়েছি ) বলে:

"একটি তোয়ালে হ'ল আন্তঃবিষ্টার হিচিকারের কাছে সবচেয়ে কার্যকর যে জিনিসটি হতে পারে সে সম্পর্কে এটি রয়েছে Part আংশিকভাবে এর দুর্দান্ত ব্যবহারিক মূল্য রয়েছে" "

তোয়ালে সম্পর্কে আপনার যদি আরও তথ্যের প্রয়োজন হয় তবে এই SE.scifi উত্তরটি দেখুন


চ্যালেঞ্জ

আশা করি আপনি আপনার পায়ের কম্বল হিসাবে ব্যবহৃত তোয়ালে দিয়ে এটি করবেন।

কোনও বৈধ প্রোগ্রামিং ভাষায় একটি সম্পূর্ণ প্রোগ্রাম বা ফাংশন লিখুন যা দুটি ইনপুট নেয়

size        Integer  : #The size
message     string   : #A sentence

এই মানগুলি দিয়ে তোয়ালে কীভাবে আঁকবেন?

প্রথমে ব্যবহারsize :

আমাদের তোয়ালের জন্য আকারের ইনপুট, উপর নির্ভর করে একটি তোয়ালে আঁকুন

  width = 12*size

  #the line that has the "bar" its always present with different sizes

  Width is defined as:
  from the first | to the second | has to be equal to size*12 including both ||

      <-   width-> 
  [===|          |====]  
      | 12 chars ||   1  height starts here, just after the "bar"
      | SIZE = 1 ||   2
      |          ||   3   height = 5*size
      |          ||   4
      |          ||   5  height ends here just before the first line |=======|
      |==========||   # the lines with the # 
      |==========||   # are always fixed
      """"""""""""|   # it means, every towel
       |          |   # always has this 5 rows
       """"""""""""   # no matter the size

দ্বিতীয়ত, এটি দিন message

আপনাকে এটিকে একটি বার্তা দিতে হবে, সোনার সুতোয় সেলাই করা কোনও সুন্দর বার্তা ছাড়া তোয়ালে কী?

উদাহরণ 1

  input: size=1, message="a simple message can stay with size"

  width = 12*size

  #the line that has the "bar" it's always present with different sizes
  #no words allowed at the bar level


  [===|          |====]  
      | a simple ||   1  height starts here, just after the "bar"
      | message  ||   2
      | can stay ||   3   height = 5*size
      | with size||   4
      |          ||   5  height ends here just before the first line |=======|
      |==========||   # the lines with the # 
      |==========||   # are always fixed
      """"""""""""|   # it means, every towel
       |          |   # always has this 5 rows
       """"""""""""   # no matter the size

উদাহরণ 2

input size=2 
message="Don't Panic and bring a towel to SE Programming Puzzles and CodeGolf"

The size is 2
That means 24 width and 10 heigth

    <-    24 chars width  ->
[===|                      |====]
    | Don't Panic and bring||   1
    | a towel to SE        ||   2
    | Programming Puzzles  ||   3
    | and CodeGolf         ||   4
    |                      ||   5
    |                      ||   6
    |                      ||   7
    |                      ||   8
    |                      ||   9
    |                      ||   10
    |======================||   #  The lines with the "#"
    |======================||   #  always present and
    """"""""""""""""""""""""|   #  adapted to 
     |                      |   #  the towel width
     """"""""""""""""""""""""   #  

স্বীকৃত উত্তরের মানদণ্ড

  • এটি কোডগল্ফ তাই সাধারণ নিয়ম প্রয়োগ হয়।

বিধি

  • আপনি গ্যারান্টিযুক্ত যে সমস্ত ইনপুট স্ট্রিং আকার মাপসই করা হবে, তাই কোনও ইনপুট পছন্দ করে না size=1; message="This string is just tooooooooooooooooooooo long to fit the width and height of your towel"

  • স্ট্রিং ফর্ম্যাটটি আপনার উপর নির্ভর করে যদি আপনি উদাহরণস্বরূপ সাবস্ট্রিংগুলি কেন্দ্র করতে চান।

  • শব্দ বিরতি নিষিদ্ধ করা হয়।

সম্পাদনাগুলি

আমি যে কোনও বিভ্রান্তির জন্য সত্যই দুঃখিত, কারণ আমি যে আঁসি তোয়ালে আঁকলাম তা প্যারামিটারগুলির সাথে মেলে না, আপনার প্রত্যাশিত ফলাফলগুলি পরীক্ষা করার জন্য উভয় উদাহরণের জন্য একটি পিএইচপি স্ক্রিপ্ট যুক্ত করেছে

ভোট দেওয়া এবং আমার প্রথম চ্যালেঞ্জ বিবেচনা করে এমন সমস্ত লোককেও ধন্যবাদ: ডি।


আমাকে ঠিক করার জন্য কয়েক মিনিট সময় দিন (কেবল এটি দেখুন)। যা ঘটেছিল তা হ'ল আমি তোয়ালে আঁকার জন্য পিএইচপি তে একটি প্রোগ্রাম তৈরি করেছি তবে আমি যে উপস্থাপন করেছি তার থেকে এটি অনেক সহজ ছিল, উদাহরণগুলির জন্য আমার একটি প্রোগ্রাম ছিল এবং আমি এটি পরিবর্তন করতে ভুলে গিয়েছিলাম।
ফ্রান্সিসকো হহন

@ লিন উভয় পরীক্ষার ক্ষেত্রে একটি পিএইচপি অসম্পূর্ণ সমাধান যুক্ত করেছেন, কোনও বিভ্রান্তির জন্য দুঃখিত।
ফ্রান্সিসকো হহন

লাইন বিরতি কোথায় যেতে পারে তা আমরা বেছে নিতে পারি?
জাকোব

লাইন current line + next wordব্রেকটি যুক্ত করা উচিত যখন যখন আপনার পোস্ট করা পিএইচপি স্ক্রিপ্টটি সিদ্ধান্ত নেয় ঠিক তেমন আপনার তোয়ালে @ জ্যাকবকে অনুমতি দেওয়া সীমা ছাড়িয়ে যাবে।
ফ্রান্সিসকো হহন

আমরা কি সঠিক পাঠ্য প্রস্থ এবং / অথবা উচ্চতাগুলিকে গণনা করার পরিবর্তে আর্গুমেন্ট হিসাবে নিতে পারি?
জোশম

উত্তর:



2

জাভাস্ক্রিপ্ট (নোড.জেএস) , 375 বাইট

এটি আপনি পাবেন সবচেয়ে খারাপ জমা, তবে কমপক্ষে আমি চেষ্টা করেছি এক্সডি অর্ধেক বাইট যদিও ফাঁকা আছে

(s,_,w=12*s-2,h=5*s)=>`
[===|${j=' '.repeat(w)}|====]
${[...Array(h)].map((g,i)=>_.split` `.reduce((a,b)=>((l=a.split`,`)[l.length-1]+b).length>w-1?a+','+b:a+' '+b,'').split`,`[i]).map(a=>`    |${a?(r=a.length)<w?a+' '.repeat(w-r):a:j}||    `).join`\n`+
`
    |${'='.repeat(w)}||    `.repeat(2)}
    ${y='"'.repeat(w+2)}|    
     |${j}|    
     ${y}
`

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


2

জাভাস্ক্রিপ্ট (নোড.জেএস) , 347 345 343 337 334 328 326 বাইট

b=>d=>`
[===|${M=" "[X="repeat"](c=12*b-2)}|====]
${[...Array(5*b)].map((a,b)=>d[Y="split"]` `.reduce((a,b)=>((l=a[Y]`,`)[l[Z="length"]-1]+b)[Z]>c-1?a+","+b:a+" "+b)[Y]`,`[b]).map(a=>`    |${a?(r=a[Z])<c?a+" "[X](c-r):a:" "[X](c)}||    `).join`
`+`
    |${"="[X](c)}||    `[X](2)}
    ${y='"'[X](c+2)}|
     |${M}|
     ${y}
`

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


ব্যাখ্যা:

b =>                                   // lambda function taking arg 1 : size
    d =>                               // arg 2 : message
        `                              // begin string template for drawing
[===|${                                // draw first part and now open literal 
        M = ' '[X='repeat'(c=12*b-2)]  // set 3 variables, M, X , c to be used again
    }|====]                            // close and draw the next part ====]
${[...Array(5*b)]                      // open and create an array of length 5 * b =width
.map(a,b=>                             // begin map function two args : a,b
        d[Y='split']` `                // use d(message), split at whitespace, set to Y
.reduce((a,b) =>                       // reduce to single value, arg 1 : a, arg 2 : b
        ((l = a[Y]`,`)                 // declare l and then find in l
        [l[Z='length']-1]              // set Z as length
        + b)                           // add value of b
        [Z]                            // find the length 
        > c-1 ?                        // check if it's less than c - 1
        a+','+b                        // then add `${a},${b}`
        : a + ' ' + b                  // otherwise `${a} ${b}`
        )[Y]`,`                        // close and split at comma
        [b]                            // use b again
        )                              // close
        .map(a =>                      // map over that arg 1 : a
                `    |${               // four space + | and open 
        a ?                            // if a is true or a truthy value
            (r=a[Z])                   // set value of r as a's length
            < c ?                      // check if it's less than c
                a+' '[X](c-r)          // then draw a + space repeated c-r times
                : a + ' '[X](c)        // else draw a + space repeated c times
            }                          // close
            ||    `                    // add || and 4 spaces and close
        )                              // end
        .join`
`                                      // and turn to string with new line as separator 
    +                                  // add to that
    `
    |{                                 // new line , 4 spaces and | 
        '='[X](c)}                     // repeat = c times
        ||    `[X](2)}                 // and repeat that 2 times
    ${                                 // new line + 4 space
    y = '"'[X](c+2)                    // repeat " c + 2 times and set to y
    }|                                 // close and add |
    |{                                 // add | and open
        M}|                            // put M and close and add |
    {y}                                // new line , 4 spaces and variable y
`                                      // end with new line.

2

কাঠকয়লা , 79 বাইট

Nθ≔×⁵θε≔×¹²θδ←P←====[↓⁺³ε×"δ↖P↑⁺³ε←G↑²←⁻δ²↓²=↓↓↓¹×"δ↖↑⁺⁴ε====]F⪪S «×⸿›⁺ⅈLι⁻δ² ι

এটি অনলাইন চেষ্টা করুন! লিঙ্কটি কোডটির ভার্জোজ সংস্করণ। ব্যাখ্যা:

Nθ≔×⁵θε≔×¹²θδ

তোয়ালের আকার গণনা করুন।

←P←====[↓⁺³ε×"δ↖P↑⁺³ε←G↑²←⁻δ²↓²=↓↓↓¹×"δ↖↑⁺⁴ε====]

তোয়ালে আঁকুন।

F⪪S «

বার্তার প্রতিটি শব্দের উপর লুপ করুন।

×⸿›⁺ⅈLι⁻δ² ι

প্রস্থকে উপচে না ফেলে প্রতিটি শব্দ মুদ্রণ করুন।


দুর্দান্ত, এবং চ্যালেঞ্জের জন্য সময় দেওয়ার জন্য আপনাকে ধন্যবাদ।
ফ্রান্সিসকো হহন

1

ভি , 142 , 128 , 121 , 119 বাইট

:let @h=5*@a
:let @w=12*@a-2
O[===|@wá 4á=á]
:set tw=w
Vgq@hï{+@hjI    |kf|@hjjyt=pjp+@hjkl@wr=Ùjlr|Ù@w««r"YkP0xÁ|

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


1
এই ধরণের কোডটি আমি বলতে চাই "হেই, আপনি যদি করেন তবে আপনি thisসংরক্ষণ করতে পারেন n Bytes" .... তবে আমি এখনও পারি না: ডি।
ফ্রান্সিসকো হহন
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.