Stack Overflowing

47

7

(Inspired by this question)

Objective

Your task is to write a program or function to print an ASCII version of the Stack Overflow logo to STDOUT

 \|/
(-)
(-)
(-)
(-)

Your program should take two inputs, referred to here as H and N. The height of the stack "container" (the parentheses) is determined by H. The number of items in the stack is determined by N. If N>H, the stack will "overflow".

Input/Output

H will determine the height of the containers

For example:

H=1:

( )

H=2:

( )
( )

H=3:

( )
( )
( )

H will always be at least 1

N will determine how many items are in the stack. The following examples are all H = 2:

N=0

( )
( )

N=1

( )
(-)

N=2

(-)
(-)

N=3

 \
(-)
(-)

N=4

 \|
(-)
(-)

N=5

 \|/
(-)
(-)

N=6

 \|/
(-)-
(-)

N=7

 \|/
(-)-
(-)-

N will never be more than 2H+3 (In other words, the stack will never go through the ground).

Rules

  • No Standard Loopholes.
  • Your program must not produce any errors.
  • All test cases must pass.
  • You can input H and N any way you want.
  • I seriously doubt that your language has a built-in for this.
  • Each line may optionally have an extra space at the end. A blank line above a stack where N <= H is optional, as is a trailing newline.
  • This is , so shortest code in bytes wins!

Test Cases

In addition to all of the H=2 test cases from the Input/Output section, all of the following test cases must pass:

H=1, N=1

(-)

H=1, N=5

 \|/
(-)-

H=4, N=7

 \|/
(-)
(-)
(-)
(-)

H=5, N=0

( )
( )
( )
( )
( )

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=81167,OVERRIDE_USER=41505;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

Daniel M.

Posted 2016-06-03T02:42:29.210

Reputation: 3 737

4May I post a non-competing program that actually overflows the stack instead of printing the logo? – user8397947 – 2016-06-04T15:14:08.330

@dorukayhan If it only overflows when n>h :) – Daniel M. – 2016-06-04T15:20:05.637

I mean, may I make a program that crashes from a stack overflow? – user8397947 – 2016-06-04T15:33:37.683

@dorukayhan only if it crashes when there are more items than the stack can hold – Daniel M. – 2016-06-04T15:35:35.973

Answers

14

Pyth, 43 41 40 bytes

<" \|/"g#0hK-QJEVJs[\(?<N_Kd\-\)*<N-K3\-

Try it online. Test suite.

First pass, quick and dirty. Input to STDIN as N\nH.

Explanation

  1. Save the second input (height) to J (JE), and subtract it from the first input (the number of items). (-QJE)
  2. Save the difference (number of overflowing items) to K. (K-QJE)
  3. Add 1 to the number. (hK-QJE)
  4. Take max(0, previous). This is required as negative numbers would break the next step. (g#0hK-QJE)
  5. Take at most that many letters from the string " \|/" to get the first line and print. (<" \|/"g#0hK-QJE)
  6. Loop N over range(0, J). (VJ) For each N print the concatenation of the following: (s[)
    • "(" (\()
    • " " if there are at least N+1 free spaces in the stack (<N_K), "-" otherwise. (?<N_Kd\-)
    • ")" (\))
    • "-" if there are at least N+4 overflowing pieces in the stack (<N-K3), "" otherwise. (*<N-K3\-)

PurkkaKoodari

Posted 2016-06-03T02:42:29.210

Reputation: 16 699

13

JavaScript (ES6), 105 102 bytes

@Edit: Saved 3 bytes thanks to @PatrickRoberts.

f=
(n,h)=>` \\|/`.substr(0,n+1-h)+[...Array(h)].map((_,i)=>`
(${i+n<h?` `:`-`})${i+h+3<n?`-`:``}`).join``
;
<div oninput=o.textContent=f(+n.value,+h.value)>n<input id=n type=number min=0 value=0>h<input id=h type=number min=0 value=0><pre id=o>

Neil

Posted 2016-06-03T02:42:29.210

Reputation: 95 035

You can replace substring with substr to save 3 bytes, and replace i+n<h?' ':'-' with '- '[i+n<h] to save 2 bytes and replace i+h+3<n?'-':'' with ' -'[i+h+3<n] to save 1 byte. That'll get you under 100 – Patrick Roberts – 2016-06-03T13:27:39.883

@PatrickRoberts I couldn't remember whether substr ignored negative subscripts or not, but I can't use your other tips because string subscripts are strings, so booleans aren't good enough. – Neil – 2016-06-03T18:42:24.933

crap I forgot about that, good point – Patrick Roberts – 2016-06-04T02:35:13.317

Really clever use of tagged template in order to save those two characters! – Benjamin Gruenbaum – 2016-06-05T11:27:42.797

@BenjaminGruenbaum what is a "tagged template"? – Patrick Roberts – 2016-06-06T11:52:17.323

@PatrickRoberts ECMASCript 2015 brings template strings with backticks ()s - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals - the fun part is that you can pass a _function_ before them which will allow you to do nifty things with them (escape SQL automatically, write parsers, lots of fun things). This answer uses this using.join_as if_ it was a template tag, thethis` value remains and the empty string is passed as the template - tagged template take the template parts as the first argument so this just happens to work. Pretty clever trick. – Benjamin Gruenbaum – 2016-06-06T12:22:01.683

@BenjaminGruenbaum thank you for that resource. I always just assumed that if the function took a single string argument that you could omit the parentheses. Now I understand why. – Patrick Roberts – 2016-06-06T13:27:57.933

12

JavaScript (ES6), 126 122 112 bytes

h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )`[r='repeat'](0>-o?0:-o)+`
(-)-`[r](o=0>o-3?0:o-3)+`
(-)`[r](n<h-o?n:h-o)

Test

f=h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )`[r='repeat'](0>-o?0:-o)+`
(-)-`[r](o=0>o-3?0:o-3)+`
(-)`[r](n<h-o?n:h-o)
document.write(`<pre>${[[2,0],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[1,1],[1,5],[4,7],[5,0]].map(a=>f(a.shift())(a.shift())).join`

`}</pre>`)

Alternate Test (if your browser does not support ES6)

See the test on Babeljs.io and check "evaluate".

Interesting alternate approach at 136 bytes

h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )${0>-o?0:-o}
(-)-${o=0>o-3?0:o-3}
(-)${n<h-o?n:h-o}`.replace(/(\n.*)(\d+)/g,(_,s,r)=>s.repeat(r))

This moves the repeat amounts into the template string and uses a regexp and replace to inject the repeating groups. Unfortunately the signature for .replace() is just too long.

Patrick Roberts

Posted 2016-06-03T02:42:29.210

Reputation: 2 475

I get an error...? – Addison Crump – 2016-06-03T13:46:31.960

1

@VTCAKAVSMoACE your browser must support ES6 syntax. It works fine for me. Feel free to paste the test into Babel.

– Patrick Roberts – 2016-06-03T14:11:07.557

@VTCAKAVSMoACE Chrome 52 (in beta as of June 2016) supports all of ES6 and ES7 except tail call optimisation and module loading. – gcampbell – 2016-06-03T18:28:56.860

10

C++14 (lambda function), 196

Saved 1 byte thanks to Quentin.

Saved 2 bytes thanks to Adam Martin.

#include<iostream>
using namespace std;[](int h,int n){auto s=" \\|/( ) (-) (-)-"s;int t=max(min(n-h,3),0);n-=t;cout<<s.substr(0,t+1)+'\n';for(;h;h--)n-=t=n>h?2:h<=n,cout<<s.substr(4+4*t,4)+'\n';}

The function itself takes 157 bytes.

See it in action here.

Ungolfed version:

[](int h, int n) {
    auto s = " \\|/( ) (-) (-)-"s;
    int t = max(min(n - h, 3), 0);
    n -= t;
    cout << s.substr(0, t + 1) + '\n';
    for(; h; h--) {
        if (n > h) t = 2;
        else if (h > n) t = 0;
        else t = 1;
        n -= t;
        cout << s.substr(4 + 4 * t, 4) + '\n';
    }
};

vaultah

Posted 2016-06-03T02:42:29.210

Reputation: 1 254

2I see no point in including includes and using namespace std; in byte count, unless your answer is a complete program (which it isn't). – Alexander Revo – 2016-06-04T21:00:10.783

9

CJam, 57 bytes

Sri:X'(*+X),W%X)X')*+X),X))f+]zN*X5*,X'-*_"\|/"\++ri<S+er

Test it here.

Could definitely use some improvement. The idea is to build a grid where the -\|/- cells are replaced with consecutive integers, e.g.

 345
(2)6
(1)7
(0)8

And then to replace them with the correct characters (potentially spaces) at the end.

Martin Ender

Posted 2016-06-03T02:42:29.210

Reputation: 184 808

6

Python 2, 101 100 98 bytes

def f(h,n):
 print" \|/"[:max(0,n-h+1)]
 for i in range(h):print("(-)","( )")[h-i>n]+"-"*(n>i+h+3)

Chuck Morris

Posted 2016-06-03T02:42:29.210

Reputation: 456

Spaces after print are unnecessary – Cyoce – 2016-06-03T20:17:50.003

@Cyoce Thanks, that saves 2 chars. – Chuck Morris – 2016-06-03T20:43:40.377

4

JavaScript (ES6), 87 80 bytes

F=(h,n)=>h?F(h-1,n-1)+`
(${n>0?'-':' '})${n>2*h+2?'-':''}`:' \\|/'.substr(0,n+1)

Uses recursion to create the output string from the bottom up.

EDIT: Thanks to @Neil for shaving 7 bytes off from 87 bytes

Original

(h,n)=>(E=s=>h--?E(`
(${n>0?'-':' '})${--n>2*h+3?'-':''}`+s):` \\|/`.substr(0,n+1)+s)``

Test snippet:

F=(h,n)=>h?F(h-1,n-1)+`
(${n>0?'-':' '})${n>2*h+2?'-':''}`:' \\|/'.substr(0,n+1)


h.oninput = n.oninput = () => output.innerHTML = F(+h.value, +n.value);
<label>h <input type="number" min="0" value="0" id="h" /></label>
<label>n <input type="number" min="0" value="0" id="n" /></label>
<hr />
<pre id="output"></pre>

George Reith

Posted 2016-06-03T02:42:29.210

Reputation: 2 424

thanks for the nice snippet! Should give an extra point :P – Kimmax – 2016-06-04T23:18:20.893

1@Kimmax Thanks mate, no one wants to be messing about with the console – George Reith – 2016-06-04T23:29:18.030

At least when I tried, the stack was pretty large, and it would only be 78 bytes with ordinary recursion. – Neil – 2016-06-06T09:45:02.513

The snippet console is showing a SyntaxError for me. – ArtOfCode – 2016-06-06T10:25:44.343

1@ArtOfCode Need to use an ES6 compliant browser – George Reith – 2016-06-06T10:58:47.197

@GeorgeReith I think I am... Chrome 53 – ArtOfCode – 2016-06-06T11:00:37.833

@ArtOfCode Strange works fine for me. What's the full error? That is a preview browser though. I am on Chrome 51 FYI – George Reith – 2016-06-06T11:17:10.980

@Neil None of the major browsers implement TCO yet. It's just a note. How would it be 78 bytes? This is normal recursion. – George Reith – 2016-06-06T11:26:14.403

I miscounted and it was 80: f=(h,n)=>h?f(h-1,n-1)+\\n)${n>0?'-':' '})${n>2*h+2?'-':''}`:' \|/'.substr(0,n+1)` – Neil – 2016-06-06T12:49:52.900

@Neil That's really cool thanks! Not sure why that didn't occur to me to not pass the string down. – George Reith – 2016-06-06T13:06:05.440

@PatrickRoberts Thanks good spot, was used to just pasting the definition from my other answers – George Reith – 2016-06-06T13:46:11.703

3

Excel, 131 bytes

Input taken as a tuple, Height H in A1, N in B1. Cell containing formula needs to have Text Wrapping turned on. Suggest using a Mono-spaced font.

=LEFT(" \|/",MAX(0,B1-A1+1))&"
"&REPT("(-)-
",MAX(0,B1-A1-3))&REPT("( )
",MAX(0,A1-B1))&REPT("(-)
",A1-MAX(0,B1-A1-3)-MAX(0,A1-B1))

Wernisch

Posted 2016-06-03T02:42:29.210

Reputation: 2 534

Wonderful solution! You should add that this take input as the 2-tuple from A1 and B1 and add the simple note that this does require the calling cell to have the wrap text option to be true. Also maybe that to get the proper alignment it should have a mono-spaced font such as Courier New or Lucidia Console – Taylor Scott – 2017-11-29T20:00:54.180

1Thanks @TaylorScott. Updated answer with your suggestions. – Wernisch – 2017-11-30T15:43:21.987

3

JavaScript (ES6), 149 139 137 bytes

h=>n=>` ${[(g=(j,m=1)=>` -\\|/`[(j<n)*m])(h,2),g(h+1,3),g(h+2,4)].join``}${[...Array(h)].map((_,i)=>`
(${g(h-i-1)})${g(h+i+3)}`).join``}`

I liked @MartinEnder's idea about indexing the -\|/ characters and I wanted to see how it would fare in ES6. Apparently I didn't do so well. Trying to figure out if this could be improved using for...of.

Edits

  • I managed to remove regexp and the call to .replace, moving the indexing directly into g() instead.
  • I accidentally counted f= in the second byte count

Test

f=h=>n=>` ${[(g=(j,m=1)=>` -\\|/`[(j<n)*m])(h,2),g(h+1,3),g(h+2,4)].join``}${[...Array(h)].map((_,i)=>`
(${g(h-i-1)})${g(h+i+3)}`).join``}`
document.write(`<pre>${[[2,0],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[1,1],[1,5],[4,7],[5,0]].map(a=>f(a.shift())(a.shift())).join`

`}</pre>`)

Patrick Roberts

Posted 2016-06-03T02:42:29.210

Reputation: 2 475

3

Java, 186 177 bytes

void f(int h,int n){for(int i=0;i<h+1;i++)System.out.print((i>0?"(":" ")+(i>0?n>h-i-2?"-":" ":n>h+0?"\\":" ")+(i>0?")":n>h+1?"|":" ")+(i>0?n>h+2+i?"-":" ":n>h+2?"/":" ")+"\n");}

Ungolfed try online

String f(int h, int n)
{
    String s=" ";
    s+=n>h+0?"\\":" ";
    s+=n>h+1? "|":" ";
    s+=n>h+2? "/":" ";
    s+="\n";

    for(int i=0; i<h; i++)
    {
        s+="(";
        s+=n>h-i-1?"-":" ";
        s+=")";
        s+=n>h+3+i?"-":" ";
        s+="\n";
    }

    return s;
}

Khaled.K

Posted 2016-06-03T02:42:29.210

Reputation: 1 435

You can save bytes by using a lambda- you can probably even leave out the lambda body – Daniel M. – 2016-06-03T21:48:01.770

2Do I need some custom IDE to compile Ungoled Java code? :D – Kimmax – 2016-06-04T23:43:10.277

@Kimmax .. D'oh! – Khaled.K – 2016-06-05T07:51:50.673

2

C++11, 155 148 145 bytes

void f(int h,int n){cout<<string{" \\|/",max(min(3,n-h),0)+1}<<'\n';for(int i=0;i<h;++i)cout<<(h-i<=n?"(-)":"( )")<<(i<max(n-h-3,0)?"-\n":"\n");}

Ungolfed:

void f(int h,int n)
{
  cout << string{" \\|/", max(min(3, n-h), 0) + 1} << '\n';
  for(int i=0; i<h; ++i)
    cout << (h-i <= n ? "(-)" : "( )") << (i < max(n-h-3,0) ? "-\n" : "\n");
}

Usage:

#include <iostream>
#include <string>
using namespace std;

void f(int h,int n){cout<<string{" \\|/",max(min(3,n-h),0)+1}<<'\n';for(int i=0;i<h;++i)cout<<(h-i<=n?"(-)":"( )")<<(i<max(n-h-3,0)?"-\n":"\n");}

int main()
{
  int h,n;
  cin >> h >> n;
  f(h, n);
}

Alexander Revo

Posted 2016-06-03T02:42:29.210

Reputation: 270

137 bytes – ceilingcat – 2019-05-03T01:03:41.550

1

Perl 5, 91 bytes

say((' \|/'=~/./g)[0..-($a=<>)+($b=<>)]);say$b<=$a-$_?'( )':'(-)'.'-'x($b-2>$a+$_)for 1..$a

Try it online!

Xcali

Posted 2016-06-03T02:42:29.210

Reputation: 7 671

1

Pip, 50 bytes

Ps.(0Xa."\|/")@<bDC0Fi,aP"()"WV"- "@[b<a-ib<a+4+i]

Try it online!

Ugh, this is too long... don't know how to shorten it any more, though. Cyclical indexing, which is usually helpful, cost extra bytes this time.

DLosc

Posted 2016-06-03T02:42:29.210

Reputation: 21 213

1

PowerShell, 109 108 104 bytes

param($n,$h)-join" \|/"[0..(($d=$n-$h),0)[$d-lt0]]
1..$h|%{("( )","(-)")[$h-$_-lt$n]+"-"*($h+$_+2-lt$n)}

Try it online!

Lost a lot on expensive indexing but still decent-ish. I'm not sure my index math is optimal however. Stole some logic from the other answers to save a byte. Also remembered precedence to pop some parens for -4 bytes.

Veskah

Posted 2016-06-03T02:42:29.210

Reputation: 3 580

1

Python 3, 134 121 118 111 bytes

def f(h,n):print('\|/'[:max(0,n-h)]+'\n'+'\n'.join('(-)-'if h<n-x-3else('(-)','( )')[x+n<h] for x in range(h)))

Test it here: https://repl.it/CYL1/0

Un-golfed:

def f(h,n):
  top=['\|/'[:max(0,n-h)]]
  stack=['( )'if x+n<h else'(-)'for x in range(h)]
  overflow=top+stack
  v=n-3
  while v>h:
      overflow[h-v]+='-' #add side overflow
      v-=1

  print('\n'.join(overflow))

I'd like to have added the side overflow to the list comprehension, but I couldn't squeeze it in, so I had to go with the while loop. Saved 13 bytes!

atlasologist

Posted 2016-06-03T02:42:29.210

Reputation: 2 945

The output is off, you probably need to change the '\|/'[:max(0,n-h)] to be like the Python 2 solution. – busfault – 2016-06-28T19:18:00.880

0

05AB1E, 45 bytes

-U…( )¸¹иε²N›ið'-:]RεX4-N@i'-«]" \|/"XdX*>£š»

Can definitely be golfed.. Not too happy about it in its current form tbh.

Try it online or verify all test cases.

Explanation:

-                # Subtract the 2nd (implicit) input `n` from the 1st (implicit) input `h`
                 #  i.e. `h`=3, `n`=8 → 5
 U               # Pop and store it in variable `X`
…( )             # Push string "( )"
    ¸            # Wrap it into a list: ["( )"]
     ¹и          # Repeat it the first input (`h`) amount of times
                 #  i.e. 3 → ["( )","( )","( )"]
ε                # Map each to:
 ²N›i            #  If the second input `n` is larger than the map-index N:
                 #    i.e. `n`=8 >= N=0 → 1 (truthy)
     ð'-:       '#   Replace the space with a "-"
                 #    i.e. "( )" → "(-)"
]                # Close both the if and map
 R               # Reverse the list
ε                # Map each to:
 X4-N@i          #  If `X` minus 4 is larger than or equal to the map-index N:
                 #     i.e. `X`=5 and N=0 → 5-4 >= 0 → 1 (truthy)
                 #     i.e. `X`=5 and N=2 → 5-4 >= 2 → 0 (falsey)
       '-«      '#   Append a "-"
]                # Close both the if and map
 " \|/"          # Push String " \|/"
       Xd        # Check if `X` is 0 or positive (0 if negative, 1 if 0 or positive)
                 #  i.e. `X`=5 → 1 (truthy)
         X*      # Multiply it by `X`
                 #  i.e. 1 * 5 → 5
           >     # Increase it by 1
                 #  i.e. 5 → 6
            £    # Take that many character of the string " \|/"
                 #  i.e. 6 → " \|/"
             š   # Prepend it to the list
                 #  i.e. ["(-)-","(-)-","(-)"] and " \|/" → [" \|/","(-)-","(-)-","(-)"]
              »  # Join the list by newlines (and output implicitly)
                 #  i.e. [" \|/","(-)-","(-)-","(-)"] → " \|/\n(-)-\n(-)-\n(-)"

Kevin Cruijssen

Posted 2016-06-03T02:42:29.210

Reputation: 67 575

If it makes you feel better here's what I had: LR'(ì')«¹x‚3+¬UŸ¦ζJ¹XŸJ¦1úr)˜» and that's only half done. – Magic Octopus Urn – 2018-10-31T15:39:45.100