কার্ড হাউস (সংস্করণ 1)


25

সংস্করণ 2 এখানে ।

সাধারণ চ্যালেঞ্জ: একটি পূর্ণসংখ্যার দেওয়া, প্রদত্ত সংখ্যক গল্পের সাথে কার্ডের একটি ঘর আঁকুন। সংখ্যাটি যদি নেতিবাচক হয় তবে বাড়িটাকে উপরের দিকে টানুন। উদাহরণ:

Input: 2
Output:

 /\
 --
/\/\

Input: 5
Output:

    /\
    --
   /\/\
   ----
  /\/\/\
  ------
 /\/\/\/\
 --------
/\/\/\/\/\

Input: 0
Output: <empty, whitespace or newline>

Input: -3
Output:

\/\/\/
 ----
 \/\/
  --
  \/

ইনপুট সংখ্যা বা একটি স্ট্রিং হতে পারে। আউটপুট অবশ্যই দেখাতে হবে ঠিক যেমন, নেতৃস্থানীয় এবং / অথবা পিছনে স্থান এবং নতুন লাইনের অনুমতি সহ be

এই , তাই প্রতিটি ভাষার পক্ষে সংক্ষিপ্ততম প্রোগ্রাম / ফাংশন জিতে যেতে পারে!


এটি স্যান্ডবক্স থেকে আসে ।
— চার্লি

শীর্ষস্থানীয় নিউলাইনগুলি অনুমোদিত?
— শেগি

@ শেগি হ্যাঁ, আপনি যতক্ষণ না কার্ডের ঘর আঁকছেন ঠিক ততক্ষণ আপনি নেতৃস্থানীয় হোয়াইটস্পেস এবং নিউলাইনগুলিও রাখতে পারেন। এটি যদি স্ক্রিনের বাম দিকে সংযুক্ত না হয় তবে আমার আপত্তি নেই।
— চার্লি

আমরা কি নিক্ষেপ করতে পারি এবং ত্রুটি করতে পারি input=0?
— রড

@ রড যদি খালি আউটপুট উত্পন্ন করে তবে এটি ডিফল্টরূপে অনুমোদিত
— লুইস মেন্ডো

উত্তর:


14

পাইথন 2 , 97 95 94 92 বাইট

-২ বাইট ধন্যবাদ লুকা-কে
এই সংস্করণটি ব্যতিক্রম প্রকাশ করে n=0তবে কিছুই ছাপানো ছাড়াই

n=input()*2
m=abs(n)
for i in range(2,m+1)[::n/m]:print(i/2*'/-\-'[i%2::2][::n/m]).center(m)

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

অ-ত্রুটি সংস্করণ, পাইথন 2, 94 বাইট

n=input()*2
x=n>0 or-1
for i in range(2,x*n+1)[::x]:print(i/2*'/-\-'[i%2::2][::x]).center(n*x)

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


x=n>0 or-1=>x=n>0or-1
— জাকারি

@ জাকারি কাজ করে না, অষ্টা 0orনম্বর হিসাবে ব্যাখ্যা করা হবে
— রড

Cut 2 আরও বেশি বাইট: m=abs(n)। তারপর, পরিবর্তে xকরা n/m, পরিবর্তে x*nকরাm
— Luka থেকে

9

05 এ বি 1 ই , 30 29 24 বাইট

ÄF„--Nׄ/\N>×}).C∊2ä¹0‹è

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

ব্যাখ্যা

ÄF                         # for N in [0 ... abs(input-1)] do:
  „--N×                    # push the string "--" repeated N times
       „/\N>×              # push the string "/\" repeated N+1 times
             }             # end loop
              )            # wrap stack in a list
               .C          # pad strings on both sides to equal length
                 ∊         # vertically mirror the resulting string
                  2ä       # split in 2 parts
                    ¹0‹    # push input < 0
                       è   # index into the the list with the result of the comparison

7

পিএইচপি , 125 বাইট

ইনপুট নেতিবাচক নেতৃস্থানীয় নিউলাইন

ইনপুট পজিটিভ ট্রেলিং নিউলাইন

for($s=str_pad;++$i<$b=2*abs($argn);)$t.=$s($s("",2*ceil($i/2),["-","/\\"][1&$i]),$b," ",2)."
";echo$argn>0?$t:$t=strrev($t);

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

পিএইচপি , 130 বাইট

for(;++$i<$b=2*abs($a=$argn);)echo($s=str_pad)($s("",2*abs(($a<0?$a:$i&1)+($i/2^0)),["-",["/\\","\/"][0>$a]][1&$i]),$b," ",2)."
";

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


5

এমএটিএল , 39 বাইট

|:"G|@-:~'/\'G0<?P]@E:)htg45*c]xXhG0<?P

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

ব্যাখ্যা

|         % Implicitly input, N. Absolute value
:"        % For k from 1 to that
  G|      %   Push absolute value of N again
  @-      %   Subtract k
  :       %   Range [1 2 ... N-k]
  ~       %   Convert to vector of N-k zeros
  '/\'    %   Push this string
  G0<     %   Is input negative?
  ?       %   If so
    P     %     Reverse that string (gives '\/')
  ]       %   End
  @E      %   Push 2*k
  :       %   Range [1 2 ... 2*k]
  )       %   Index (modularly) into the string: gives '/\/\...' or '\/\/...'
  h       %   Horizontally concatenate the vector of zeros and the string. Zeros
          %   are implicitly converted to char, and will be shown as spaces
  t       %   Duplicate
  g       %   Convert to logical: zeros remain as 0, nonzeros become 1
  45*c    %   Multiply by 45 (ASCII for '=') and convert to char
]         % End
x         % Delete (unwanted last string containing '=')
Xh        % Concatenate into a cell array
G0<       % Is input negative?
?         % If so
  P       %   Reverse that cell array
          % Implicit end. Implicit display

1
মানুষ, তাড়াতাড়ি ছিল !! আমি আশা করি সংস্করণ 2 এত সহজ হবে না ... :-)
— চার্লি

4

সি (জিসিসি) , 169171 173 160 164 বাইট

#define F(A,B,C)for(i=A;B--;)printf(C);
#define P puts("");F(y,i," ")F(abs(n)-y
s,i,x,y;f(n){x=n<0;for(s=x?1-n:n;s--;){y=x?-n-s:s;P,i,x?"\\/":"/\\")y+=x;P,s>x&&i,"--")}}

নেতিবাচক কেস বাগের জন্য +13 বাইট।

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

অগল্ফোড (সমস্ত স্পেস এবং নিউলাইন সরানোর পরে 207 বাইট):

s, i, x, y;
f(n) {
  x = n < 0;
  for (s = x ? 1 - n : n; s--;) {
    y = x ? - n - s : s;
    puts("");
    for (i = y; i--;) printf(" ");
    for (i = abs(n) - y; i--;) printf(x ? "\\/" : "/\\");;
    y += x;
    puts("");
    for (i = y; i--;) printf(" ");
    for (i = abs(n) - y; s > x && i--;) printf("--");;
  }
}

1
@ অফিসিয়ালাইম স্থির! ধন্যবাদ
— কিউ গান

4

কাঠকয়লা, 31 28 27 বাইট

FI⊟⪪θ-«←ι↓→/…\/ι↙»‖M¿‹N⁰‖T↓

এটি অনলাইন চেষ্টা করুন! লিঙ্কটি কোডটির ভার্জোজ সংস্করণ। আমার কাছে প্রায় 4 টি বিভিন্ন 32 বাইট উত্তর ছিল তখন এটি পাওয়া গেল। সম্পাদনা করুন: স্ট্রিং ম্যানিপুলেশন ব্যবহার করে 3 4 বাইট সংরক্ষিত abs। ব্যাখ্যা:

   ⪪θ-                          Split the input (θ = first input) on -
  ⊟                             Take the (last) element
 I                              Convert it to a number i.e. abs(θ)
F     «                         Repeat that many times
       ←ι                       Print half of the -s
         ↓                      Position for the /\s
          →/                    Print the first /
            …\/ι                Print half of any remaining \/s
                ↙               Position for the next row of -s
                 »              End of the loop
                  ‖M            Mirror everything horizontally
                    ¿‹N⁰        If the input was negative
                        ‖T↓     Reflect everything vertically

আমি জানতাম যে চারকোলের উত্তরটি শেষ হবে ¿‹θ⁰‖T↓। :-)
— চার্লি

যখন চারকোলকে ASCII- আর্ট চ্যালেঞ্জ O_o তে 05AB1E দ্বারা পরাজিত করা হয়
— গ্রিফন - মনিকা

@ গ্রিফোন আমার কাছে একটি বাইট নেই abs...
— নিল

সত্য, এটি দেখার জন্য এটি কেবল অদ্ভুত। আপনাকে কী চমকে দেয় বিশ্বের কী আগমন ঘটে।
— গ্রিফন - মনিকা

হ্যাঁ, এটি একটি অ্যাবস বিল্টিন সহ 23 বাইট হবে। (48 কে,
— বিটিডব্লিউকে

2

জাপট , 40 38 বাইট

-২ বাইট @ শ্যাগি ধন্যবাদ

o½½@aXc)ç +"--/\\\\/"ò gYv *Ug)pXc a÷

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

ব্যাখ্যা

o½½@aXc)ç +"--/\\\\/"ò gYv *Ug)pXc a÷              // implicit: U = input integer
o.5,.5,XYZ{UaXc)ç +"--/\\\\/"ò gYv *Ug)pXc a} qR    // ungolfed
o.5,.5,                                             // array [.5,U] with step size .5
       XYZ{                                 }       // mapped by the function: (X = value, Y = index)
           UaXc)                                    //   absolute diff between U and ceil(X)
                ç                                   //   " " times that value
                  +"--/\\\\/"ò g      )             //   plus ["--","/\","\/"].get(...
                                Yv                  //     if Y is even, 1, else 0
                                   *Ug              //     times sign(U)
                                       pXc a        //   repeated abs(ceil(X)) times
                                              qR    // all that joined with newlines


2

গাইয়া , 21 বাইট

:┅“/\\“--”צ¦_€|ḣ¤ọ×ṣ

ব্যাখ্যা

:                      Push 2 copies of the input
 ┅                     Get the range to the input. If positive: [1 .. n]. If negative: 
                       [-1 .. n]. If zero: [0].
  “/\\“--”             Push ["/\", "--"]
          צ¦          Repeat both of those strings by each number in the range. Strings go
                       in reverse order when repeated a negative number of times.
             _         Flatten the list
              €|       Centre-align the rows of the list
                ḣ      Remove the last row (the "--"s on the bottom)
                 ¤     Swap (bring input back to the top)
                  ọ    Sign: -1 for negative, 0 for 0, 1 for positive
                   ×   Repeat the list that many times; (-1 × list) reverses it
                    ṣ  Join with newlines and implicitly output

1

গণিত, 140 বাইট

(T=Table;z=Column;B[a_]:=""<>"/\\"~T~a;If[#>0,m=0,m=Pi];z[Join[z/@T[{B@i,""<>"--"~T~i},{i,Abs@#-1}],{B@Abs@#}],Alignment->Center]~Rotate~m)&


আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.