Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

╥╥╥╥─╥╥╥╥
║║║╚═╝║║║
║║╚═══╝║║
║╚═════╝║
╚═══════╝
share|improve this question
3  
AFAIK those are not ASCII characters. unicode-art – flawr Jan 10 at 23:45
    
welp, @flawr you are right. What now... – JuanPotato Jan 10 at 23:48
    
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.) – flawr Jan 10 at 23:50
    
That looks like extended ASCII, though, so you're probably okay. – Mama Fun Roll Jan 10 at 23:51
2  
@ՊՓԼՃՐՊՃՈԲՍԼ 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. – Level River St Jan 11 at 0:13

12 Answers 12

up vote 1 down vote accepted

CJam, 59 bytes

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

Try it here!

share|improve this answer
    
You can now use +-| to build the arches, see op for examples. – JuanPotato Jan 11 at 2:08

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.

share|improve this answer
    
You can now use +-| to build the arches, see op for examples. – JuanPotato Jan 11 at 2:05
2  
@JuanPotato OP stands for original poster. Do you mean the question? – VTCAKAVSMoACE Jan 11 at 7:50
1  
@flagasspam yes, I've just seen uses where it means original post – JuanPotato Jan 11 at 20:11

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
share|improve this answer
    
I think this prints a single for n = 0, but it should print nothing. – Lynn Jan 11 at 1:41
    
@Mauris I just ran it and you are correct – JuanPotato Jan 11 at 2:08
1  
@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. – type_outcast Jan 11 at 5:59

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>

share|improve this answer

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;
share|improve this answer

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$*═.

share|improve this answer

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)
share|improve this answer

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 
share|improve this answer

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

share|improve this answer

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
share|improve this answer

𝔼𝕊𝕄𝕚𝕟, 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.

share|improve this answer

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//' <<< ''
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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