बॉक्स में ASCII बॉक्स ड्रा करें


23

संकट

इनपुट दिया गया a,b,c

जहां a,b,cसकारात्मक भी पूर्णांक हैं

तथा a > b > c

आयामों के साथ किसी भी अनुमत चरित्र का एक बॉक्स बनाएं a x a

b x bपिछले के भीतर आयामों के साथ एक अलग अनुमति वाले चरित्र के एक बॉक्स को केंद्र में रखें

c x cपिछले के भीतर आयामों के साथ एक और अलग अनुमत चरित्र के एक बॉक्स को केंद्र में रखें

स्वीकृत वर्ण ASCII वर्ण हैं [a-zA-z0-9!@#$%^&*()+,./<>?:";=_-+]

इनपुट a=6, b=4, c=2

######
#****#
#*@@*#
#*@@*#
#****#
######

इनपुट a=8, b=6, c=2

########
#******#
#******#
#**@@**#
#**@@**#
#******#
#******#
########

इनपुट a=12, b=6, c=2

############
############
############
###******###
###******###
###**@@**###
###**@@**###
###******###
###******###
############
############
############

नियम

  • सबसे छोटा कोड जीतता है
  • याद रखें कि आप चुन सकते हैं कि दी गई सीमा के भीतर कौन सा चार्ट प्रिंट करना है
  • अनुगामी newlines स्वीकार किए जाते हैं
  • अनुगामी व्हॉट्सएप ने स्वीकार कर लिया
  • फ़ंक्शंस नए सिरे, स्ट्रिंग ऐरे के साथ स्ट्रिंग लौटा सकते हैं या प्रिंट कर सकते हैं

5
क्या इनपुट हमेशा मान्य होगा (अर्थात प्रत्येक संख्या पिछले से कम से कम 2 कम है)? और संख्या हमेशा सममित ड्राइंग सुनिश्चित करने के लिए (सभी सम) या (सभी विषम) होगी?
— बिखराव


1
@ पहली 3 पंक्तियाँ उन आवश्यकताओं को परिभाषित करती हैं, कृपया मुझे बताएं कि क्या वे पर्याप्त हैं।
— LiefdeWen

@StefanDelport आप सही हैं, मुझे याद है। धन्यवाद।
— तितर बितर करना

जवाबों:



7

जेली ,  20  19 बाइट्स

`एक लिंक से बचने के लिए क्विक का उपयोग करके -1 बाइट , जैसा कि एरिक द आउटगॉल्फ द्वारा सुझाया गया है।

H»þ`€Ḣ>ЀHSUṚm€0m0Y

एक पूर्ण प्रोग्राम [a,b,c]जो बक्से का उपयोग करके छपाई करता है a:2 b:1 c:0
... वास्तव में, यह 10 बक्से तक काम करेगा , जहां अंतरतम बॉक्स 0( उदाहरण के लिए ) है।

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

कैसे?

H»þ`€Ḣ>ЀHSUṚm€0m0Y - Main link: list of boxes, B = [a, b, c]
H                   - halve B = [a/2, b/2, c/2]
    €               - for €ach:
   `                -   repeat left argument as the right argument of the dyadic operation:
  þ                 -     outer product with the dyadic operation:
 »                  -       maximum
                    - ... Note: implicit range building causes this to yield
                    -       [[max(1,1),max(1,2),...,max(1,n)],
                    -        [max(2,1),max(2,2),...,max(2,n)],
                    -        ...
                    -        [max(n,1),max(n,2),...,max(n,n)]]
                    -       for n in [a/2,b/2,c/2]
     Ḣ              - head (we only really want n=a/2 - an enumeration of a quadrant)
         H          - halve B = [a/2, b/2, c/2]
       Ѐ           - map across right with dyadic operation:
      >             -   is greater than?
                    - ...this yields three copies of the lower-right quadrant
                    -    with 0 if the location is within each box and 1 if not
          S         - sum ...yielding one with 0 for the innermost box, 1 for the next, ...
           U        - upend (reverse each) ...making it the lower-left
            Ṛ       - reverse ...making it the upper-right
             m€0    - reflect €ach row (mod-index, m, with right argument 0 reflects)
                m0  - reflect the rows ...now we have the whole thing with integers
                  Y - join with newlines ...making a mixed list of integers and characters
                    - implicit print - the representation of a mixed list is "smashed"

7

पायथन 2, 107 103 बाइट्स

a,b,c=input()
r=range(1-a,a,2)
for y in r:
 s=''
 for x in r:m=max(x,y,-x,-y);s+=`(m>c)+(m>b)`
 print s

पूरा कार्यक्रम, साथ बक्से प्रिंट a=2, b=1,c=0

थोड़ा बुरा जवाब, सूची समझ (104 बाइट्स) के साथ:

a,b,c=input()
r=range(1-a,a,2)
for y in r:print''.join(`(m>c)+(m>b)`for x in r for m in[max(x,y,-x,-y)])

5

सी #, 274 232 बाइट्स

using System.Linq;(a,b,c)=>{var r=new string[a].Select(l=>new string('#',a)).ToArray();for(int i=0,j,m=(a-b)/2,n=(a-c)/2;i<b;++i)for(j=0;j<b;)r[i+m]=r[i+m].Remove(j+m,1).Insert(j+++m,i+m>=n&i+m<n+c&j+m>n&j+m<=n+c?"@":"*");return r;}

यहां तक ​​कि सी # के लिए भयानक तो निश्चित रूप से गोल्फ हो सकता है लेकिन मेरा दिमाग खाली हो गया है।

पूर्ण / प्रारूपित संस्करण:

using System;
using System.Linq;

class P
{
    static void Main()
    {
        Func<int, int, int, string[]> f = (a,b,c) =>
        {
            var r = new string[a].Select(l => new string('#', a)).ToArray();

            for (int i = 0, j, m = (a - b) / 2, n = (a - c) / 2; i < b; ++i)
                for (j = 0; j < b;)
                    r[i + m] = r[i + m].Remove(j + m, 1).Insert(j++ + m,
                        i + m >= n & i + m < n + c &
                        j + m > n & j + m <= n + c ? "@" : "*");

            return r;
        };

        Console.WriteLine(string.Join("\n", f(6,4,2)) + "\n");
        Console.WriteLine(string.Join("\n", f(8,6,2)) + "\n");
        Console.WriteLine(string.Join("\n", f(12,6,2)) + "\n");

        Console.ReadLine();
    }
}

आपको लगता है कि आपके दिमाग को फिर से पा लिया गया है, j + m <= n + cबन सकता है n + c > j + m
— LiefdeWen

अच्छी तरह से तो के रूप में के रूप में i + m >= nकरने के लिएn < i + m
— LiefdeWen

आप i+m4 बार उपयोग करते हैं , इसलिए आप इसे forकुछ को बचाने के लिए एक चर में जोड़ सकते हैं
— LiefdeWen

इन की ठीक से जाँच नहीं की गई है, लेकिन आप कभी भी iअलगाव में उपयोग नहीं करते हैं , बस आरंभ i=mऔर तुलना करें i<b+m; या ... बस का उपयोग करें i, init i=0लेकिन पाश पर i<a, फिर जोड़ने के r[i]=new string('#',a),लिए j=0और एक शर्त जोड़ने के लिए जाँच करने के iलिए सीमा के भीतर है j(यह भुगतान करना चाहिए, क्योंकि आप सभी Linq खो देते हैं)।
— विजुअलमेल


3

जावास्क्रिप्ट (ईएस 6), 174 170 147 बाइट्स

a=>b=>c=>(d=("#"[r="repeat"](a)+`
`)[r](f=a/2-b/2))+(e=((g="#"[r](f))+"*"[r](b)+g+`
`)[r](h=b/2-c/2))+(g+(i="*"[r](h))+"@"[r](c)+i+g+`
`)[r](c)+e+d

कोशिश करो

fn=
a=>b=>c=>(d=("#"[r="repeat"](a)+`
`)[r](f=a/2-b/2))+(e=((g="#"[r](f))+"*"[r](b)+g+`
`)[r](h=b/2-c/2))+(g+(i="*"[r](h))+"@"[r](c)+i+g+`
`)[r](c)+e+d
oninput=_=>+x.value>+y.value&&+y.value>+z.value&&(o.innerText=fn(+x.value)(+y.value)(+z.value))
o.innerText=fn(x.value=12)(y.value=6)(z.value=2)
label,input{font-family:sans-serif;}
input{margin:0 5px 0 0;width:50px;}
<label for=x>a: </label><input id=x min=6 type=number step=2><label for=y>b: </label><input id=y min=4 type=number step=2><label for=z>c: </label><input id=z min=2 type=number step=2><pre id=o>


व्याख्या

a=>b=>c=>            :Anonymous function taking the 3 integers as input via parameters a, b & c
(d=...)              :Assign to variable d...
("#"[r="repeat"](a)  :  # repeated a times, with the repeat method aliased to variable r in the process.
+`\n`)               :  Append a literal newline.
[r](f=a/2-b/2)       :  Repeat the resulting string a/2-b/2 times, assigning the result of that calculation to variable f.
+                    :Append.
(e=...)              :Assign to variable e...
(g=...)              :  Assign to variable g...
"#"[r](f)            :    # repeated f times.
+"*"[r](b)           :  Append * repeated b times.
+g+`\n`)             :  Append g and a literal newline.
[r](h=b/2-c/2)       :  Repeat the resulting string b/2-c/2 times, assigning the result of that calculation to variable h.
+(...)               :Append ...
g+                   :  g
(i=...)              :  Assign to variable i...
"*"[r](h)            :    * repeated h times.
+"@"[r](c)           :  @ repeated c times
+i+g+`\n`)           :  Append i, g and a literal newline.
[r](c)               :...repeated c times.
+e+d                 :Append e and d.


2

वी , 70, 44 , 42 बाइट्स

Àé#@aÄÀG@b|{r*ÀG@c|{r@òjdòÍ.“.
ç./æ$pYHP

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

यह गूढ़ है। Eww। काफी बेहतर। अभी भी कम से कम नहीं, लेकिन कम से कम कुछ गोल्फ।

@ Nmjmcman101 को धन्यवाद दो बाइट्स बचाए!

Hexdump:

00000000: c0e9 2340 61c4 c047 4062 7c16 7b72 2ac0  ..#@a..G@b|.{r*.
00000010: 4740 637c 167b 7240 f26a 64f2 cd2e 932e  G@c|.{r@.jd.....
00000020: 0ae7 2e2f e624 7059 4850                 .../.$pYHP

आप अपनी अंतिम दो पंक्तियों को दो बाइट की बचत के लिए जोड़ सकते हैं इसे ऑनलाइन आज़माएं!
— nmjcman101

@ nmjcman101 आह, अच्छी बात है। धन्यवाद!
— DJMcMayhem

1

MATL , 26 23 22 20 18 बाइट्स

2/t:<sPtPh!Vt!2$X>

इनपुट एक कॉलम वेक्टर है [a; b; c]। आउटपुट का उपयोग करता है वर्ण 2, 1, 0।

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

एक तरफ के रूप में, यह दस बक्सों के लिए काम करता है, न कि केवल तीन यहां पांच बक्सों के साथ एक उदाहरण है ।


1

गणितज्ञ, 49 बाइट्स

Print@@@Fold[#~CenterArray~{#2,#2}+1&,{{}},{##}]&

इनपुट लेता है [c, b, a]। आउटपुट है a=1, b=2, c=3।

कैसे?

Print@@@Fold[#~CenterArray~{#2,#2}+1&,{{}},{##}]&
                                                &  (* Function *)
        Fold[                        ,{{}},{##}]   (* Begin with an empty 2D array.
                                                      iterate through the input: *)
                                    &              (* Function *)
             #~CenterArray~{#2,#2}                 (* Create a 0-filled array, size
                                                      (input)x(input), with the array
                                                      from the previous iteration
                                                      in the center *)
                                  +1               (* Add one *)
Print@@@                                           (* Print the result *)

@ जेनी_मैथी इस सवाल में: * फंक्शंस में स्ट्रिंग को नईलाइन, स्ट्रिंग ऐरे से प्रिंट कर सकते हैं, या प्रिंट कर सकते हैं। " Gridन तो बनाता है Stringऔर न ही करता Printहै।
— जंगवान मिन

0

PHP> = 7.1, 180 बाइट्स

इस मामले में मुझे नफरत है कि चर $PHP में एक के साथ शुरू होते हैं

for([,$x,$y,$z]=$argv;$i<$x*$x;$p=$r%$x)echo XYZ[($o<($l=$x-$a=($x-$y)/2)&$o>($k=$a-1)&$p>$k&$p<$l)+($o>($m=$k+$b=($y-$z)/2)&$o<($n=$l-$b)&$p>$m&$p<$n)],($o=++$i%$x)?"":"\n".!++$r;

PHP सैंडबॉक्स ऑनलाइन


इस मामले में, प्रिंट से पहले पेंट बहुत छोटा है। : D या यह है क्योंकि मैं $argvएक सरणी के रूप में उपयोग करते हैं ? क्या आपने कोशिश की है? क्या आपने अलग-अलग टर्नरीज़ की कोशिश की है?
— टाइटस

@ मुझे पता नहीं है, लेकिन मेरे दृष्टिकोण में अमान्य विषम संख्याओं के इनपुट को सही किया गया है
— Jörg Hülsermann

0

गणितज्ञ, 173 बाइट्स

(d=((a=#1)-(b=#2))/2;e=(b-(c=#3))/2;z=1+d;x=a-d;h=Table["*",a,a];h[[z;;x,z;;x]]=h[[z;;x,z;;x]]/.{"*"->"#"};h[[z+e;;x-e,z+e;;x-e]]=h[[z+e;;x-e,z+e;;x-e]]/.{"#"->"@"};Grid@h)&

इनपुट

[12,6,2]


0

पायथन 2 , 87 बाइट्स

a,_,_=t=input();r=~a
exec"r+=2;print sum(10**x/9*10**((a-x)/2)*(r*r<x*x)for x in t);"*a

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

फॉर्म की संख्याओं को जोड़कर प्रिंट करने के लिए अंकगणित की गणना करता है 111100। बहुत कुरूपता है, शायद सुधार की गुंजाइश है।


0

जावा 8, 265 252 बाइट्स

 a->b->c->{int r[][]=new int[a][a],x=0,y,t;for(;x<a;x++)for(y=0;y<a;r[x][y++]=0);for(t=(a-b)/2,x=t;x<b+t;x++)for(y=t;y<b+t;r[x][y++]=1);for(t=(a-c)/2,x=t;x<c+t;x++)for(y=t;y<c+t;r[x][y++]=8);String s="";for(int[]q:r){for(int Q:q)s+=Q;s+="\n";}return s;}

-13 बाइट्स अंकों के साथ वर्णों को प्रतिस्थापित करके।

एक अलग दृष्टिकोण का उपयोग करके निश्चित रूप से गोल्फ हो सकता है।

स्पष्टीकरण:

इसे यहाँ आज़माएँ।

a->b->c->{                         // Method with three integer parameters and String return-type
  int r[][]=new int[a][a],         //  Create a grid the size of `a` by `a`
      x=0,y,t;                     //  Some temp integers
  for(;x<a;x++)for(y=0;y<a;r[x][y++]=0);
                                   //  Fill the entire grid with zeros
  for(t=(a-b)/2,x=t;               //  Start at position `(a-b)/2` (inclusive)
      x<b+t;x++)                   //  to position `b+((a-b)/2)` (exclusive)
    for(y=t;y<b+t;r[x][y++]=1);    //   And replace the zeros with ones
  for(t=(a-c)/2,x=t;               //  Start at position `(a-c)/2` (inclusive)
      x<c+t;x++)                   //  to position `c+((a-b)/2)` (exclusive)
    for(y=t;y<c+t;r[x][y++]=8);    //   And replace the ones with eights
  String s="";                     //  Create a return-String
  for(int[]q:r){                   //  Loop over the rows
    for(int Q:q)                   //   Inner loop over the columns
      s+=Q;                        //    and append the result-String with the current digit
                                   //   End of columns-loop (implicit / single-line body)
    s+="\n";                       //   End add a new-line after every row
  }                                //  End of rows-loop
  return s;                        //  Return the result-String
}                                  // End of method

0

जावास्क्रिप्ट (ईएस 6), 112

एक मल्टी लाइन स्ट्रिंग लौटाने वाला अनाम फ़ंक्शन। अक्षर 0,1,2

(a,b,c)=>eval("for(o='',i=-a;i<a;o+=`\n`,i+=2)for(j=-a;j<a;j+=2)o+=(i>=c|i<-c|j>=c|j<-c)+(i>=b|i<-b|j>=b|j<-b)")

कम गोल्फ वाला

(a,b,c)=>{
  for(o='',i=-a;i<a;o+=`\n`,i+=2)
    for(j=-a;j<a;j+=2)
      o+=(i>=c|i<-c|j>=c|j<-c)+(i>=b|i<-b|j>=b|j<-b)
  return o
}  

var F=
(a,b,c)=>eval("for(o='',i=-a;i<a;o+=`\n`,i+=2)for(j=-a;j<a;j+=2)o+=(i>=c|i<-c|j>=c|j<-c)+(i>=b|i<-b|j>=b|j<-b)")

function update()
{
  var [a,b,c]=I.value.match(/\d+/g)
  O.textContent=F(a,b,c)
}

update()
  
a,b,c <input id=I value='10 6 2' oninput='update()'>
<pre id=O></pre>


0

PHP> = 5.6, 121 बाइट्स

for($r=A;$p?:$p=($z=$argv[++$i])**2;)$r[((--$p/$z|0)+$o=($w=$w?:$z)-$z>>1)*$w+$p%$z+$o]=_BCD[$i];echo chunk_split($r,$w);

इसे ऑनलाइन चलाएं -nrया परीक्षण करें ।

संयुक्त छोरों फिर से ... मैं उन्हें प्यार करता हूँ!

टूट - फूट

for($r=A;                           # initialize $r (result) to string
    $p?:$p=($z=$argv[++$i])**2;)    # loop $z through arguments, loop $p from $z**2-1 to 0
    $r[((--$p/$z|0)+$o=
        ($w=$w?:$z)                     # set $w (total width) to first argument
        -$z>>1)*$w+$p%$z+$o]            # calculate position: (y+offset)*$w+x+offset
        =_BCD[$i];                      # paint allowed character (depending on $i)
echo chunk_split($r,$w);            # insert newline every $w characters and print
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.