17
\$\begingroup\$

I like ascii art and I get bored a lot, so I found some ascii characters and started to make random things, 8-bit mario castle, mazes, and arches. I found that the arches could easily be stacked in a neat way.

╔═══════╗
║╔═════╗║
║║╔═══╗║║
║║║╔═╗║║║
╨╨╨╨─╨╨╨╨

Challenge

Create a program, function, or any other standard format that accepts an integer that is greater than or equal to 0 (unless you are doing the bonus) and outputs ascii art with the amount of arches specified.

Test Cases

Input:

7

Output:

╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨

Alt:

+-------------+
|+-----------+|
||+---------+||
|||+-------+|||
||||+-----+||||
|||||+---+|||||
||||||+-+||||||
||||||| |||||||
---------------

Input:

1

Output:

╔═╗
╨─╨

Alt:

+-+
| |
---
  • If the integer is 0 then don't output anything
  • This question will be in utf-8, each character will count as a "byte"
  • This is so the shortest answer wins.
  • You have the option of using +-+ instead of ╔═╗, --- instead of ╨─╨, and | instead of

Bonus (not decided whether to allow this on the alternate version because it wouldn't be as hard)

-10% if the program supports negative numbers and flips the arches like so

╥╥╥╥─╥╥╥╥
║║║╚═╝║║║
║║╚═══╝║║
║╚═════╝║
╚═══════╝
\$\endgroup\$
  • 3
    \$\begingroup\$ AFAIK those are not ASCII characters. unicode-art \$\endgroup\$ – flawr Jan 10 '16 at 23:45
  • \$\begingroup\$ welp, @flawr you are right. What now... \$\endgroup\$ – JuanPotato Jan 10 '16 at 23:48
  • \$\begingroup\$ The world is going to collapse! Don't worry, perhaps just mention that they are not part of standard ASCII, but the ascii-art tag still applies (the unicode-tag was a joke.) \$\endgroup\$ – flawr Jan 10 '16 at 23:50
  • \$\begingroup\$ That looks like extended ASCII, though, so you're probably okay. \$\endgroup\$ – Mama Fun Roll Jan 10 '16 at 23:51
  • 2
    \$\begingroup\$ @ՊՓԼՃՐՊՃՈԲՍԼ There's no standard version of extended ASCII en.wikipedia.org/wiki/Extended_ASCII The closest thing there is is codepage 437 en.wikipedia.org/wiki/Code_page_437 which was standard in the USA and many other countries but I find when I copy and paste this into a codepage 437 editor and back into windows it "interprets" as arches with +---+ at the top, sides of | and a bottom of ----- which looks fine to me. Juanpotato, if you want to use non-ascii characters, please indicate the encoding in the question. As it stands I'm voting to close as unclear. \$\endgroup\$ – Level River St Jan 11 '16 at 0:13

14 Answers 14

1
\$\begingroup\$

CJam, 59 bytes

qi:Lg"^Za"a{_0=1'Z3*tsa\{'[2*\*}%+}L(*'rL*a2*N*a+9462ff+N**

Try it here!

\$\endgroup\$
  • \$\begingroup\$ You can now use +-| to build the arches, see op for examples. \$\endgroup\$ – JuanPotato Jan 11 '16 at 2:08
2
\$\begingroup\$

Python 2, 106 bytes (94 chars)

n=input();j=1
exec"s=j/2*'║';print s+'╔'+'═'*(2*n-j)+'╗'+s;j+=2;"*n
if n:t='╨'*n;print t+'─'+t

Pretty straightforward. Prints line by line with a changing number of horizontal and vertical bars. The last line is printed separately.

I feel like I'm missing some optimizations. The fact that the chars are multiple bytes means you can't do something like '║╨'[n>0], so I didn't find a good way to print the last line in the loop. It's ugly that there's so much manipulation going on with the counter. I'd like update strings directly, like s+='║', but the index is also used for horizontal bars.

\$\endgroup\$
  • \$\begingroup\$ You can now use +-| to build the arches, see op for examples. \$\endgroup\$ – JuanPotato Jan 11 '16 at 2:05
  • 2
    \$\begingroup\$ @JuanPotato OP stands for original poster. Do you mean the question? \$\endgroup\$ – Addison Crump Jan 11 '16 at 7:50
  • 1
    \$\begingroup\$ @flagasspam yes, I've just seen uses where it means original post \$\endgroup\$ – JuanPotato Jan 11 '16 at 20:11
2
\$\begingroup\$

Perl, 78 82 chars

$n='─';$_='══'x pop;while(s/══//){print"$s╔═$_╗$s\n";$s.="║";$n="╨$n╨"}$s&&print$n

Sadly, I couldn't figure out a way to take advantage of the bonus without increasing the size by more than 10%. I may yet prevail.

Ungolfed

Pretty straightforward, really. Builds up bottom line (╨$n╨) incrementally, while shortening top line (══) by two characters, ending when it can no longer be shortened, so I don't have to mess with counters.

 $n = '─'; # Bottom line
 $_ = '══'x pop; # "Top" line, length from commandline argument
 while (s/══//) { # Shorten top line by two characters
     print "$s╔═$_╗$s\n"; # Print current line with $s (sides)
     $s .= "║";           # Append vertical bar to sides
     $n  = "╨$n╨";        # Widen bottom line
 }
 $s && print $n; # Print bottom line if input is not 0
\$\endgroup\$
  • \$\begingroup\$ I think this prints a single for n = 0, but it should print nothing. \$\endgroup\$ – Lynn Jan 11 '16 at 1:41
  • \$\begingroup\$ @Mauris I just ran it and you are correct \$\endgroup\$ – JuanPotato Jan 11 '16 at 2:08
  • 1
    \$\begingroup\$ @Mauris Dang! You're absolutely right. My original version was fine, but somewhere along the line I lost the check. Fixed, at the cost of 4 chars. Thanks for spotting that. \$\endgroup\$ – type_outcast Jan 11 '16 at 5:59
  • \$\begingroup\$ I know this is old, but to add to @Abigail's comment, you can save bytes using -n too: Try it online! \$\endgroup\$ – Dom Hastings Jul 11 '18 at 15:38
1
\$\begingroup\$

Bash, 124 bytes (112 characters)

printf -vh %$1s
b=${h// /╨}
h=${h// /═}
for((n=$1;n--;)){
echo $v╔$h${h:1}╗$v
h=${h#?}
v+=║
}
(($1))&&echo $b─$b

Sample run:

bash-4.3$ bash ascii-arch.sh 7
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨

bash-4.3$ bash ascii-arch.sh 1
╔═╗
╨─╨

bash-4.3$ bash ascii-arch.sh 0
\$\endgroup\$
1
\$\begingroup\$

Japt -R, 29 bytes

Uses + & -. Sacrificed 4 bytes to handle the bloody input validation!

©Æ'+²¬q-p´UÑÄÃpS û| p-pNÑÄ)ªP

Try it


Explanation

                                  :Implicit input of integer U
©                                 :Logical AND with U
 Æ                                :Map the range [0,U)
  '+                              :  Literal "+"
    ²                             :  Repeat twice
     ¬                            :  Split
      q                           :  Join with
       -                          :   Literal "-"
        p                         :   Repeat
         ´U                       :    Decrement U
           Ñ                      :    Multiply by 2
            Ä                     :    Add 1
             Ã                    :End mapping
              pS                  :Push a space
                 û|               :Centre pad each element with "|" to the length of the longest element
                    p     )       :Push
                     -            : Literal "-"
                      p           : Repeat
                       N          :  The array of inputs (which will be cast to an integer if we perform a mathematical operation on it)
                        ÑÄ        :  Multiply by 2 and add 1
                           ª      :Logical OR
                            P     :The empty string
                                  :Implicitly join with newlines and output
\$\endgroup\$
  • \$\begingroup\$ fails on the input 0 \$\endgroup\$ – dzaima Jul 11 '18 at 10:06
  • \$\begingroup\$ @dzaima, what do you mean? How can you have an arch of size 0? \$\endgroup\$ – Shaggy Jul 11 '18 at 10:15
  • \$\begingroup\$ If the integer is 0 then don't output anything from the challenge :/ \$\endgroup\$ – dzaima Jul 11 '18 at 10:16
  • \$\begingroup\$ @dzaima, Oh, I missed that. Thanks. First of all: Boo-urns to input validation! Secondly, Japt can't output nothing - I could output 0, false or an empty string at a cost of some bytes but I don't know if any of those would be acceptable except, maybe, the empty string, which would cost me 5 bytes (0 would only cost me 1). \$\endgroup\$ – Shaggy Jul 11 '18 at 10:19
0
\$\begingroup\$

JavaScript (ES6), 101 characters

f=(n,i=0)=>n?i-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g:""

Explanation

Recursive function that prints each line

f=(n,i=0)=>              // f = recursive function, i = current line (default = 0)
  n?                     // if n != 0
    i-n?                 // if we are not in the last line, print the line
      (b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1)               // add the output of the next line
    :(g="╨"[r](n))+"─"+g // if we ARE in the last line, print the last line
  :""                    // print nothing if n = 0

Test

Test does not use default parameter for browser compatibility.

var solution = f=(n,i)=>n?(i|=0)-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g:""
<input type="number" oninput="result.textContent=solution(+this.value)" />
<pre id="result"></pre>

\$\endgroup\$
0
\$\begingroup\$

PHP (109 chars)

$s='';for($b=($n=$argv[1])?'─':'';$n--;){echo$s.'╔═'.str_repeat('══',$n)."╗$s\n";$s.='║';$b="╨{$b}╨";}echo$b;

Still need to get rid of that str_repeat but most alternatives won't handle mulyibyte chars.

$s = '';
// Initialise $b (bottom) to '─' or '' for n==0
for ($b = ($n = $argv[1]) ? '─' : ''; $n--;) {
    // Echo sides + arch + sides
    echo $s . '╔═' . str_repeat('══', $n) . "╗$s\n";
    // Growing sides
    $s .= '║';
    // Growing bottom
    $b = "╨{$b}╨";
}
// Show bottom
echo $b;
\$\endgroup\$
0
\$\begingroup\$

Retina, 79 chars

.+
$0$*═$0$*═╗
^═
╔
+`(║*)╔═(═+)═╗║*$
$0¶$1║╔$2╗║$1
(\S+)$
$0¶$1
T`═╔╗║`─╨`\S+$

Try it online.

This uses a new feature in Retina that replaces a decimal number \d+ with a list of that many characters $0$*═.

\$\endgroup\$
0
\$\begingroup\$

Swift (209 bytes)

Probably Swift is not the best language for this, this is my first time trying to do a code golf challenge:

func *(l:String,r: Int)->String{return r>0 ?l+(l*(r-1)):""}
let n=Int(readLine()!)!
for i in 0...(n-1){let a=("║"*i)+"╔═";let b=a+("══"*(n-1-i))+"╗"+("║"*i);print(b)};print("╨"*n+"─"+"╨"*n)
\$\endgroup\$
0
\$\begingroup\$

Ruby, 90 bytes (74 characters)

->n{n.times{|i|puts ?║*i+?╔+?═*((n-i)*2-1)+?╗+?║*i}>0&&puts(?╨*n+?─+?╨*n)}

Sample run:

2.1.5 :001 > ->n{n.times{|i|puts ?║*i+?╔+?═*((n-i)*2-1)+?╗+?║*i}>0&&puts(?╨*n+?─+?╨*n)}[7]
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨
 => nil 

2.1.5 :002 > ->n{n.times{|i|puts ?║*i+?╔+?═*((n-i)*2-1)+?╗+?║*i}>0&&puts(?╨*n+?─+?╨*n)}[1]
╔═╗
╨─╨
 => nil 

2.1.5 :003 > ->n{n.times{|i|puts ?║*i+?╔+?═*((n-i)*2-1)+?╗+?║*i}>0&&puts(?╨*n+?─+?╨*n)}[0]
 => false 
\$\endgroup\$
0
\$\begingroup\$

Haskell, 151 162 bytes

r=replicate
c=concat
f n=putStr$unlines[c[r i '║',"╔",r(2*(n-i)-1)'═',"╗",r i '║']|i<-[0..n-1]]++c[r n '╨',r(signum n)'─',r n '╨']
main=readLn>>=f

Edit: I forgot to deal with 0 as input

\$\endgroup\$
0
\$\begingroup\$

𝔼𝕊𝕄𝕚𝕟, 54 chars / 95 bytes

⩥ïⓜᵖ⟮ ⍘|ď⟯$+`+⦃⟮⍘-ď (ï⟯-$)*2-1)}+`+Ⅰ$;ï⅋ᵖⅠï+⬭+Ⅰï,Ⅱ*2+1

Try it here (Firefox only).

Explanation

⩥ïⓜᵖ⟮ ⍘|ď⟯$+`+⦃⟮⍘-ď (ï⟯-$)*2-1)}+`+Ⅰ$;ï⅋ᵖⅠï+⬭+Ⅰï,Ⅱ*2+1 // implicit: ï=input, $=mapped item
                                                       // PHASE 1
⩥ïⓜ                                                   // create a range to map over
    ᵖ                                                  // push to stack:
     ⟮ ⍘|ď⟯$                                            // | repeated $ times
           +`+⦃⟮⍘-ď (ï⟯-$)*2-1)}+`                      // & +[- repeated 2$-1 times]+
                                 +Ⅰ$;                  // & | repeated $ times
                                                       // PHASE 2
                                     ï⅋                // if ï>0
                                       ᵖ               // push to stack 2 items:
                                        Ⅰï+⬭+Ⅰï,      // | repeated $ times & [space] & | repeated $ times
                                                 Ⅱ*2+1 // and - repeated 2ï+1
                                                       // implicit stack output, newline-separated

NOTE: this makes use of good ol' copy blocks to get at the spots where ordinary variable declaring could not reach.

\$\endgroup\$
0
\$\begingroup\$

Sed, 97 bytes (81 characters)

(96 bytes (80 characters) code + 1 character command line option)

s/.(.*)/2&\13/
t
:
H
s/(.+)11(.+)/4\1\24/
t
y/1234/─╨╨╨/
H
g
s/\n//
y/1234/═╔╗║/

Input expected as unary integer.

Sample run:

bash-4.3$ sed -r 's/.(.*)/2&\13/;t;:;H;s/(.+)11(.+)/4\1\24/;t;y/1234/─╨╨╨/;H;g;s/\n//;y/1234/═╔╗║/' <<< '1111111'
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨

bash-4.3$ sed -r 's/.(.*)/2&\13/;t;:;H;s/(.+)11(.+)/4\1\24/;t;y/1234/─╨╨╨/;H;g;s/\n//;y/1234/═╔╗║/' <<< '1'
╔═╗
╨─╨

bash-4.3$ sed -r 's/.(.*)/2&\13/;t;:;H;s/(.+)11(.+)/4\1\24/;t;y/1234/─╨╨╨/;H;g;s/\n//;y/1234/═╔╗║/' <<< ''

Sed, 105 bytes (75 characters)

(104 bytes (74 characters) code + 1 character command line option)

y/1/═/
s/.(.*)/╔&\1╗/
t
:
H
s/(.+)══(.+)/║\1\2║/
t
y/╔║╗═/╨╨╨─/
H
g
s/\n//

Input expected as unary integer.

Sample run:

bash-4.3$ sed -r 'y/1/═/;s/.(.*)/╔&\1╗/;t;:;H;s/(.+)══(.+)/║\1\2║/;t;y/╔║╗═/╨╨╨─/;H;g;s/\n//' <<< '1111111'
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨

bash-4.3$ sed -r 'y/1/═/;s/.(.*)/╔&\1╗/;t;:;H;s/(.+)══(.+)/║\1\2║/;t;y/╔║╗═/╨╨╨─/;H;g;s/\n//' <<< '1'
╔═╗
╨─╨

bash-4.3$ sed -r 'y/1/═/;s/.(.*)/╔&\1╗/;t;:;H;s/(.+)══(.+)/║\1\2║/;t;y/╔║╗═/╨╨╨─/;H;g;s/\n//' <<< ''
\$\endgroup\$
0
\$\begingroup\$

Canvas, 15 bytes

-*+∔]⤢:↷±n│L-×∔

Try it here!

Explanation:

{    ]            map over 1..input
 -*                 repeat "-" counter times
   +∔               append "+" to that
      ⤢           transpose
       :          create a duplicate of that
        ↷±        rotated 90°, then reversed horizontally
          n       overlap the 2
           |      and palindromize horizontally with 1 overlap
            L     get the with of that
             -×   repear "-" that many times
               ∔  and add vertically to the rest of the output
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.