You just bought a brand new chair! Problem is, you have no idea how to control it so you'll need to write a program to do it for you.

Example of an adjustable chair

You can only sit in the unadjusted chair for so long. So your code will need to be as short as possible.



| _
| |


|  _
|  |


|      _

Am I the only one who thinks this look like an airplane?

Chair parts

The chair has various components:

|  <- Backrest
|  _  <- Armrest
|  |
|__|__ <- Seat
   |   <- Leg
  OOO  <- Wheels


You will be outputting a chair given various variables.

The input will be in the following order, all inputs will be positive integers (always greater than 0) and will always be provided.

  1. Backrest Height
  2. Seat Width always odd
  3. Armrest Height Always less than backrest height
  4. Leg Height
  5. Wheel count Always less than or equal to seat width and Always odd

Detailed part Descriptions

The parts of the chair are:

Backrest: This amount of | is the Backrest Height


Seat: The amount of _ is the Seat Width, insert a | in the middle for the armrest.


Armrest: The amount of | is the Armrest Height. This should be inserted in the middle of the seat.


Leg: The amount of | is determined by Leg Height


Wheels: The wheels are centered below the legs. If they are more than one, all but the center wheel should have _ in the line above them.

_ _


The output may have a trailing newline. Each line may have trailing spaces. Leading whitespace is not allowed

  • \$\begingroup\$ The third test case appears to be wrong. The seat width is far more than 2. \$\endgroup\$
    – Doorknob
    Dec 18, 2015 at 2:36
  • \$\begingroup\$ @Doorknob冰 whoops, that was a problem with the input order, I've fixed it. \$\endgroup\$
    – Downgoat
    Dec 18, 2015 at 2:38
  • \$\begingroup\$ The "airplane" one reminds me a lot of these tanks from Super Mario Bros 3. \$\endgroup\$ Dec 18, 2015 at 2:58

6 Answers 6


JavaScript (ES6), 197 bytes

(b,s,a,l,w)=>eval('o="";for(i=0;i<b+l+2;i++)o+=(i?i>b?x[r](s/2-w/2+1)+(i>b+l?"O"[r](w):(p=(i<b+l?x:"_")[r](w/2))+"|"+p):"|"+(p=(i-b?x=" ":"_")[r="repeat"](s/2))+(i>b-a?"|":i<b-a?x:"-")+p:"O")+`\n`')


Well this got rather convoluted quite quickly. I'll just comment on what each line does at a high level. Hopefully with this formatting it's not too hard to follow all the ternary operators.

    for(i=0;i<b+l+2;i++)                        // for each line
      o+=(i?                                    // add to output

        // Leg lines
          x[r](s/2-w/2+1)                       // spaces before wheels
              "O"[r](w)                         // wheels
              (p=(i<b+l?x:"_")[r](w/2))         // spaces or wheel cover before leg
              +"|"                              // leg
              +p                                // spaces or wheel cover after leg

        // Backrest lines
          "|"                                   // backrest
          +(p=(i-b?x=" ":"_")[r="repeat"](s/2)) // spaces or seat before armrest
          +(i>b-a?"|":i<b-a?x:"-")              // armrest
          +p                                    // spaces or seat after armrest

      // Headrest line


var solution = (b,s,a,l,w)=>eval('o="";for(i=0;i<b+l+2;i++)o+=(i?i>b?x[r](s/2-w/2+1)+(i>b+l?"O"[r](w):(p=(i<b+l?x:"_")[r](w/2))+"|"+p):"|"+(p=(i-b?x=" ":"_")[r="repeat"](s/2))+(i>b-a?"|":i<b-a?x:"-")+p:"O")+`\n`')
Input separated by commas (,) = <input type="text" id="input" value="5,3,2,3,5" />
<button onclick="result.textContent=solution(...input.value.split(',').map(x=>+x))">Go</button>
<pre id="result"></pre>


Python 2, 157 bytes

y,z,n,A='|_\n '



|   _

JavaScript (ES6), 182

An anonymous function. Using template strings, there are 3 newlines that are significant an included in the byte count.

(b,s,a,l,w,R=(x=s/2,c=' ')=>c.repeat(x),f=`

No loops, using repeat for the same purpose.

Less golfed

(b, s, a, l, w, // parameters
 // local variables as parameters with default values
 R = (x=s/2,c=' ')=>c.repeat(x), // shortcut for repeat 
 f = `\n`+R(s/2+1-w/2), // filler before the wheels (used twice)
 h = R(s/2,'_'), // half seat (used twice)
 g = R(w/2,'_'), // last wheel support (used twice)
 v = '|', // vertical bar (used many times)
 u = `\n`+v // newline + bar (define below in the golfed version)
  'O'+R(b+~a, u)+  // backrest 
  u+R()+'_'+       // backrest + armrest top
  R(a-1, u+R()+v)+ // backrest + armrest
  u+h+v+h+         // seat
  R(l-1, `\n`+R()+v)+ // leg
  f+g+v+g+         // wheels support
  f+R(w, 'O')      // wheels

Test Snippet

f=(b,s,a,l,w,R=(x=s/2,c=' ')=>c.repeat(x),f=`

function test()
Input <input type="text" id="I" value="5,5,3,2,3" />
<button onclick="test()">Go</button>
<pre id="O"></pre>

  • 1
    \$\begingroup\$ +1 for more of your bytes being in the function parameters than the body of the function. \$\endgroup\$
    – user81655
    Dec 18, 2015 at 14:37

LabVIEW, 146 LabVIEW Primitives

This got a lot bigger than I imagined...

There won't be a GIF this time, on the one Hand because of the size on the other hand because there's no way anyone can follow all the data flowing.

It does work, unless you get LabVIEW and suggest a file hoster there will be no way to check though.


SpecBAS - 185 168 bytes

1 INPUT b's'a'l'w: sx=(s/2)+1,wx=sx-(w/2)
2  ?"o"'("|"#13)*b
3  ?AT b,1;"_"*s;AT b+l,wx;"_"*w;AT b-a,sx;"-"
4 FOR i=b+1-a TO b+l: ?AT i,sx;"|": NEXT i
5  ?AT b+l+1,wx;"0"*w

Now that SpecBAS allows ? to be used instead of PRINT and doesn't need LET before variable assignment, it starts being a bit better at golfing.

Also helps that you can specify y,x print positions to avoid having to work out lots of spacing. This prints back, seat, arms and legs then wheels.


to print the back, replace a FOR...NEXT loop with pipe + return multiplied by the height (("|"#13)*b)

enter image description here


Perl, 181 bytes

includes +1 for -n. Put in a file and echo 5,3,2,2,1 | perl -n file.pl

($b,$s,$a,$l,$w)=/\d+/g;$,=$/;print'O',('|')x($b-$a-1),($D='|'.$"x($s/=2)).'_',("$D|")x--$a,($q='|'.'_'x$s).$q,($"x$s.' |')x--$l,($x=$"x(1+$s-($W=$w/2))).'_'x$W.'|'.'_'x$W,$x.O x$w

With comments:

#!/usr/bin/perl -n              # -n: iterate stdin, put in $_

($b,$s,$a,$l,$w)=/\d+/g;        # get the parameters

$,=$/;                          # set $OUTPUT_FIELD_SEPARATOR to \n;
                                # this is printed between each of print's args

print                           # shorter than `-p` and @_=(...); $"=$/; $_="@_";
    'O',                        # the headrest

    ('|')x($b-$a-1),            # space between headrest and armrest.
                                # (...) x $n: produces $n lists.

    ($D='|' . $"x($s/=2))       # backrest and padding ($"=' ') up to armrest
    . '_',                      # armrest.

    ("$D|")x--$a,               # backrest, padding, armrest

    ($q='|' . '_'x$s) . $q,     # backrest bottom and 1/2 seat, armrest bottom and 1/2 seat

    ($" x $s . ' |' ) x --$l,   # padding before leg and leg, repeated leg-1 times

    ( $x =                     
      $" x (1+$s - ($W=$w/2) )  # padding before wheel top
    . '_'x$W . '|'              # left side of wheel top, wheel top,
    . '_'x$W,                   # right side of wheel top

    $x . O x$w                  # padding before wheels, wheels

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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