आई सो दैट कमिंग


19

1 से कम या -1 से अधिक पूर्णांक में होने वाले प्रोग्राम या फ़ंक्शन को लिखें। यही है, इनपुट 0, 1, या -1 नहीं होगा।

यदि इनपुट है 2, तो आउटपुट होना चाहिए:

|\_/|
|___|

यदि इनपुट है 3, तो आउटपुट होना चाहिए:

|\_/\_/|
|______|

यदि इनपुट है 4, तो आउटपुट होना चाहिए:

|\_/\_/\_/|
|_________|

बड़े इनपुट के लिए पैटर्न उसी तरह से जारी रहता है। उदाहरण के लिए, यदि इनपुट है 10, तो आउटपुट होना चाहिए:

|\_/\_/\_/\_/\_/\_/\_/\_/\_/|
|___________________________|

यदि इनपुट है -2, तो आउटपुट होना चाहिए:

 ____
|    |
|_/\_|

यदि इनपुट है -3, तो आउटपुट होना चाहिए:

 _______
|       |
|_/\_/\_|

यदि इनपुट है -4, तो आउटपुट होना चाहिए:

 __________
|          |
|_/\_/\_/\_|

छोटे आदानों के लिए पैटर्न उसी तरीके से जारी है। उदाहरण के लिए, यदि इनपुट है -10, तो आउटपुट होना चाहिए:

 ____________________________
|                            |
|_/\_/\_/\_/\_/\_/\_/\_/\_/\_|

आउटपुट को प्रिंट किया जा सकता है या एक स्ट्रिंग के रूप में एक वैकल्पिक अनुगामी न्यूलाइन के साथ लौटाया जा सकता है। नकारात्मक इनपुट के लिए आउटपुट का शीर्ष दायां "खाली" स्थान एक स्थान हो सकता है या यह रिक्त रह सकता है।

बाइट्स में सबसे छोटा कोड जीतता है।


12
मैंने देखा कि आपने वहां क्या किया।
एलेक्स ए।

जवाबों:


1

पायथ, 45 बाइट्स

jtW!J<Q0.b+.[YN+h*3t.aQJY.>[d.<"\_/"J\_)J" ||

इसे ऑनलाइन आज़माएँ: प्रदर्शन या टेस्ट सूट

स्पष्टीकरण:

jtW!J<Q0.b+.[YN+h*3t.aQJY.>[d.<"\_/"J\_)J" ||  implicit: Q = input number
    J<Q0                                       assign Q < 0 to J
                           [           )       create a list with
                            d                    * the string " "
                             .<"\_/"J            * the string "\_/" rotated to 
                                                   the left by J
                                     \_          * the string "_"
                         .>             J      rotate to the right by J
                                         " ||  the string " ||"
        .b                                     binary mapping, N iterates
                                               over list, Y over string:
           .[YN+h*3t.aQJ                         pad Y with N to reach a string
                                                 of length 3*(abs(Q)-1)+1-J
          +             Y                        and append Y
 tW!J                                           remove the first line if Q > 0
j                                               print each on separate line

4

CJam, 56 50 49 बाइट्स

ri_(z"\_/"*'_@0>{\4>W<_,@*SooNoS}|1$,*]${'|\'|N}/

CJam दुभाषिया में इसे ऑनलाइन आज़माएं

यह काम किस प्रकार करता है

ri     e# Read an integer from STDIN and push it on the stack.
_(z    e# Push a copy, decrement it and apply absolute value.
       e# For positive n, (n -> n-1) and (-n -> n+1).
"\_/"* e# Repeat the string that many times.
'_     e# Push an underscore.
@0>    e# Check if the original integer is positive.
{      e# If it isn't:
  \    e#   Swap the generated string with the underscore.
  4>W< e#   Discard the string's first 4 and last character.
       e#   This makes the pattern of the bottom row start and end with an
       e#   underscore, truncating it to the correct length in the process.
  _,   e#   Push the length of a copy.
  @*   e#   Repeat the underscore that many times.
  So   e#   Print a space.
  oNo  e#   Print the underscores, then a linefeed.
  S    e#   Push a space.
}|     e#
1$,    e# Retrieve the strings length.
*      e# Repeat the underscore or space that many times.
]$     e# Wrap the two generated strings in an array and sort it.
{      e# For each string:
  '|\  e#   Push a vertical bar and swap the string on top of it.
  '|N  e#   Push a vertical bar and a linefeed.
}/     e#

3

पायथ, 56 54 बाइट्स

मैं ऑनलाइन दुभाषिया के साथ एक फोन पर पायथन गोल्फ कर रहा हूं। यह पूरी तरह से एक महान विचार है।

अद्यतन २०१५-१०-१५: मैंने इस बात को फिर से लिखा (अभी भी अपने फोन पर, लोल) और २ बाइट्स बचाए हैं, जिनमें से एक मूल के साथ भी किया जा सकता था।

J<Q0Ljb"||"jPW!J_WJ[y<>*K+J*3t.aQ"\_/"JKy*K?Jd\_+d*K\_

इसे ऑनलाइन आज़माएं।


2

मिंकोलंग 0.8 , 100 बाइट्स

"|"nd0`u!vbd3*["_"]"|"25*"|"1g["\_/"]"|"(O).
"[d~g1"_"<.)O(" "D*3R~1"_"*52"|"D*3R1dg2"| "*52"|"]"\/_

बस स्टैक को बनाता है और फिर सभी को एक ही बार में प्रिंट करता है। मुझे यकीन है कि यह गोल्फ हो सकता है लेकिन मैंने पहले ही इस पर बहुत समय बिताया है ...


1

जावास्क्रिप्ट (ईएस 6), 111 98 बाइट्स

इष्टतम तकनीक की खोज! टेम्पलेट तार से उन सभी interpolators को हटाने पता चला है एक बचत होती है बहुत कुछ बाइट्स की। शायद इसे अभी भी कम किया जा सकता है, शायद नहीं। किसी भी स्थिति में, ES6 टेम्पलेट स्ट्रिंग्स (और एरो फ़ंक्शंस) भयानक हैं। :)

x=>(x>0?`|\\_/A|
|___A|`:` ___A_
|   A |
|_/\\A_|`).replace(/(...)A/g,(_,y)=>y.repeat(x>0?x-1:~x))

0

पायथन 2.7, 144 बाइट्स

इसमें उम्मीद से ज्यादा बाइट्स लगीं। यहाँ कोड है।

c=int(input())
p,w,n,u=list('| \n_')
a=abs(c)-1
d=3*a
if c>0:
 s=p+"\\_/"*a+p+n+p+u*d+p
else:
 d=d+1
 s=w+u*d+n+p+w*d+p+n+p+"_/\\"*a+u+p
print s

0

जावा, 272 बाइट्स

String f(int i) {
String p = i>0?"\\_/":"_/\\_",x = "|"+new String(new char[(i<0?-i:i)-1]).replace("\0",p)+"|",
l=new String(new char[x.length()-2]).replace("\0","_");
return i>0?x+"\n|"+l+"|":" "+l+" \n|"+new String(new char[x.length()-2]).replace("\0"," ")+"|\n"+x;
}

0

SpecBAS - 167 बाइट्स

1 INPUT n: DIM s$="\_/","_/\": LET t$=s$(2-(n>0))*(ABS n-1)+("_"*(n<0)),u$="_"*LEN t$
2 TEXT IIF$(n>0,"|"+t$+"|"#13"|"+u$+"|"," "+u$+#13"|"+" "*LEN t$+"|"#13"|"+t$+"|")

IIF$एक इनलाइन IFस्टेटमेंट है, #13एक नई स्ट्रिंग को एक स्ट्रिंग में एम्बेड करने का एक तरीका है (और अगर इसे हार्डकोड स्ट्रिंग्स के बीच हमेशा "+" की आवश्यकता नहीं है)।

चूँकि कुछ समय पहले, SpecBAS आपको एक LETकथन के लिए कई कार्य देता है , जो कुछ वर्णों को सहेजने में मदद करता है।


0

पायथन 2.7, 118 बाइट्स

n=input()*3-3
a=-n-6
s=' %s_\n| %s|\n|%s_|'%(a*'_',a*' ',a/3*'_/\\')
if n>0:s='|%s|\n|%s|'%(n/3*'\\_/',n*'_')
print s

120 से 118 पर उतरना मजेदार था!


0

रूबी - 113 बाइट्स

बहुत लंबा लगता है। मैं इसे थोड़ा और नीचे गोल्फ करने की कोशिश करूँगा।

n=gets.to_i;p,h=n.abs-1,?|;n>0 ? (puts h+'\\_/'*p+h,h+'___'*p+h):(k=p*3+1;puts' '+?_*k,h+' '*k+h,'|_'+'/\\_'*p+h)

0

सी #, 185 बाइट्स

सी # गोल्फ के साथ संघर्ष को दोहराता है।

पूरी तरह से गोल्फ:

string S(int n){int m=n>0?n:-n;return string.Format(n>0?"|{0}\n|{1}|":" {1}\n|{2}|\n|_{0}","|".PadLeft(m).Replace(" ",n>0?@"\_/":@"/\_"),"".PadLeft(m=m*3-(n>0?3:2),'_'),"".PadLeft(m));}

स्पष्टता के लिए जोड़ा गया इंडेंटेशन और नई लाइनें:

string S(int n){
    int m=n>0?n:-n;
    return string.Format(n>0?"|{0}\n|{1}|":" {1}\n|{2}|\n|_{0}",
        "|".PadLeft(m).Replace(" ",n>0?@"\_/":@"/\_"),
        "".PadLeft(m=m*3-(n>0?3:2),'_'),
        "".PadLeft(m)
    );
}

0

पॉवर्सशेल - 200 190 186 168 154

समीकरण (4 - (($ n-2) 3))) से (3 $ n-6) के साथ-साथ कुछ बाहरी सामान और अर्धविराम।

पाया कि `एन के बराबर है [Environment]::NewLineऔर वह $s -f [args]बराबर है [String]::Format:

$n=$args;if($n-gt0){$s="|{1}|{0}|{2}|";$a=$n;$b=$n*3}else{$n*=-1;$s=" {2}{0}|{3}|{0}|_/{1}\_|";$a=$n-2;$b=$c=3*$n-2};$s-f"`n",("\_/"*$a),("_"*$b),(" "*$c)

स्पष्टीकरण कोष्ठक स्पष्ट करता रहता है:

$n=$args;

// Basically a way of coming up with a string to format and the 
// necessary counts of repeated characters
if($n-gt0){
  // Placeholder format
  $s="|{1}|{0}|{2}|{3}";
  // Number of repeated "\_/" instances
  $a=$n;
  // Number of repeated "_" instances
  $b=$n*3
} else { 
  $n*=-1;
  $s=" {2}{0}|{3}|{0}|_/{1}\_|";
  $a=($n-2);
  $b=(4+(($n-2)*3));
  // Number of repeated " " instances .. not needed for "positive" saw
  $c=$b;
};
[String]::Format($s,[Environment]::NewLine,"\_/"*$a,"_"*$b," "*$c)
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.