Skip to main content
2 of 2
Fixed bug
user81655
  • 11.2k
  • 1
  • 25
  • 50

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>

user81655
  • 11.2k
  • 1
  • 25
  • 50