मैं तौलिया दिन भूल गया


15

मैं तौलिया दिन भूल गया

सैंडबॉक्स लिंक

दोनों उदाहरणों के लिए PHP स्क्रिप्ट (त्रुटि, स्ट्रिंग को स्वरूपित करना)

सही php स्क्रिप्ट, इनपुट स्व व्याख्यात्मक है

$argvविभिन्न परिणाम देखने के लिए अधिक इनपुट टिप्पणी / असहजता के साथ PHP स्क्रिप्ट

जैसा कि आप जानते हैं, 25 मई को तौलिया दिवस के रूप में जाना जाता है , क्योंकि बहुत से उपयोगों में एक तौलिया हो सकता है।

"द हिचहाइकर गाइड टू द गैलेक्सी" पुस्तक का एक सरल उद्धरण (व्यक्तिगत रूप से मैंने इस पुस्तक को "रोजमर्रा की मार्गदर्शिका" के रूप में लिया है ):

"एक तौलिया सबसे बड़े पैमाने पर उपयोगी चीज के बारे में है जो एक इंटरस्टेलर सहयात्री के पास हो सकता है। आंशिक रूप से इसका बहुत अच्छा मूल्य है।"

यदि आपको तौलिए के बारे में अधिक जानकारी की आवश्यकता है, तो इस 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"

  • स्ट्रिंग प्रारूप आपके ऊपर है, यदि आप उदाहरण के लिए सबस्ट्रिंग को केंद्र में रखना चाहते हैं।

  • शब्द-विराम विच्छेदित हैं।

संपादित करता

मुझे वास्तव में किसी भी उलझन के बारे में खेद है, क्योंकि ansii तौलिए मैं आकर्षित मापदंडों से मेल नहीं खाता था, आपके लिए अपेक्षित आउटपुट की जांच करने के लिए दोनों उदाहरणों के लिए एक PHP स्क्रिप्ट जोड़ा ।

साथ ही उन सभी लोगों को धन्यवाद, जिन्होंने मतदान किया और मेरी पहली चुनौती मानी: डी।


मुझे इसे ठीक करने के लिए कुछ मिनट दें (बस यह देखा)। क्या हुआ कि मैंने तौलिया खींचने के लिए php पर एक कार्यक्रम बनाया, लेकिन यह मेरे द्वारा प्रस्तुत किए जाने की तुलना में बहुत सरल था, मेरे पास उदाहरणों के लिए एक कार्यक्रम था और मैं इसे संशोधित करना भूल गया।
फ्रांसिस्को हैन

@ लियन ने दोनों परीक्षण मामलों के साथ एक php ungolfed समाधान जोड़ा, किसी भी भ्रम के बारे में क्षमा करें।
फ्रांसिस्को हैन

क्या हम चुन सकते हैं कि लाइन ब्रेक कहां जाए?
जकोब

लाइन ब्रेक को जोड़ा जाना चाहिए जब current line + next wordआपके तौलिया @Jakob के लिए अनुमत सीमा से अधिक हो जाएगी क्योंकि php स्क्रिप्ट मैंने इसे तय किया था।
फ्रांसिस्को हैन

क्या हम कंप्यूटिंग के बजाय तर्क के रूप में उचित पाठ चौड़ाई और / या ऊँचाई ले सकते हैं?
जोश

जवाबों:



2

जावास्क्रिप्ट (Node.js) , 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

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