12
\$\begingroup\$

Given two inputs -- one of them a non-empty printable ASCII string (including space, excluding newline), the other being one of two distinct, consistent values of your choice (1 / 0, l / r, left / right, etc.) -- output an ASCII art airplane banner of the string, pointing either left or right. For consistency, I'll be using left and right throughout this challenge description.

The plane is either |-DI>-/ (left) or \-<ID-| (right). Since the banner is clear, it consists of the input string's characters separated by spaces, either left-to-right (left) or right-to-left (right), and surrounded by a box of the shape

    /--/
---<  <
    \--\

or

\--\
 >  >---
/--/

Note there must be one space between the beginning/end of the message and the >,< characters.

For example, here is the message HAPPY BIRTHDAY! and the direction left:

           /-------------------------------/
|-DI>-/---< H A P P Y   B I R T H D A Y ! <
           \-------------------------------\

Here is the message PPCG and the direction right. Note that the letters appear "backwards" when viewed from this side of the banner:

\---------\
 > G C P P >---\-<ID-|
/---------/

Rules

  • Leading or trailing newlines or whitespace are all optional, so long as the characters themselves line up correctly.
  • Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
  • If possible, please include a link to an online testing environment so other people can try out your code!
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Slightly related. \$\endgroup\$ Aug 29, 2017 at 14:58
  • 3
    \$\begingroup\$ JavaScript, 4 bytes: eval - Input a program that generates a left-facing plane for left, and a program that generates a right-facing plane for right. \$\endgroup\$
    – darrylyeo
    Aug 30, 2017 at 4:17

14 Answers 14

6
\$\begingroup\$

JavaScript (ES6), 141 138 bytes

String and direction are input via currying syntax.
'/\n|-DI>-/---< ' for left, '/\n|-DI<-\\---> ' for right.

t=>p=>(r=`${s='           '}/${_='-'.repeat(t.length*2+1)}${p}${[...t].join` `} ${d=p[12]} 
${s}\\${_}\\`,d>'<'?[...r].reverse().join``:r)

f=

t=>p=>(r=`${s='           '}/${_='-'.repeat(t.length*2+1)}${p}${[...t].join` `} ${d=p[12]} 
${s}\\${_}\\`,d>'<'?[...r].reverse().join``:r)

console.log(f('HAPPY BIRTHDAY!')('/\n|-DI>-/---< '))
console.log(f('HAPPY BIRTHDAY!')('/\n|-DI<-\\---> '))

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Ha, hard coding a section of the output seems like an exploitation of a loophole, but it seems fine based on the challenge as written. Clever! \$\endgroup\$ Aug 30, 2017 at 9:14
  • 4
    \$\begingroup\$ @RickHitchcock The ultimate loophole is eval... just provide left and right function sources as your two values of your choice. (I thought there was a meta on this but I can't find it.) \$\endgroup\$
    – Neil
    Aug 30, 2017 at 12:18
  • 2
    \$\begingroup\$ @Neil The eval "trick" would be this loophole in spirit, even if not explicitly stated. This answer here is kinda clever, though. \$\endgroup\$ Aug 30, 2017 at 12:36
  • \$\begingroup\$ Yeah, I was debating whether to post eval as a serious answer. A workaround for future challenges like this might be to include inputs as part of the byte count. \$\endgroup\$
    – darrylyeo
    Aug 30, 2017 at 22:17
6
\$\begingroup\$

Perl 5, 149 102 + 4 (-plF ) = 150 106 bytes

Shortened using tricks I've learned since the original answer. Still scored using the rules in effect at the time of the question.

s/./--/g;$_=$"x11 ."/-$_/";$_.="
|-DI>-/---< @F < 
".y|\\/|/\\|r;if(<>){y|<>|><|;$_=reverse;s|-/|-\\|}

Try it online!

Two line input. First is the message. Second is 0 for left, 1 for right.

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

V, 73, 65 bytes

Ó./& 
É ÄÒ-ys$/YGpr\$.11>Hj|R|-DI>-/³-<A< ÀñkæG|æ}-r>$BR>³-\-<

Try it online!

Not the greatest score, but that's because almost half of this comes from reversing the output.

Hexdump:

00000000: d32e 2f26 200a c920 c4d2 2d79 7324 2f59  ../& .. ..-ys$/Y
00000010: 4770 725c 242e 3131 3e48 6a7c 527c 2d44  Gpr\$.11>Hj|R|-D
00000020: 493e 2d2f b32d 3c1b 413c 201b c0f1 6be6  I>-/.-<.A< ...k.
00000030: 477c e616 7d2d 723e 2442 523e b32d 5c2d  G|..}-r>$BR>.-\-
00000040: 3c                                       <

Takes the string as input to the buffer, and the direction as 0 for left and 1 for right as command line arguments.

\$\endgroup\$
4
\$\begingroup\$

05AB1E, 63 bytes

„\\S'-¹g·>×ýD∞2äθ‚11ú"|-DI>-/---<"¸¹ε²i∞θ}J'<«S«ð«J¸«Àε²i∞2äθ}»

Try it online!

Based off bugs that may get fixed in the future.

\$\endgroup\$
4
  • \$\begingroup\$ @MagicOctopusUrn possibly \$\endgroup\$ Aug 30, 2017 at 8:37
  • \$\begingroup\$ @MagicOctopusUrn actually no it won't work like that... \$\endgroup\$ Aug 30, 2017 at 8:46
  • \$\begingroup\$ @MagicOctopusUrn Try to change the 0 on the second line to a 1. \$\endgroup\$ Aug 31, 2017 at 14:25
  • \$\begingroup\$ Ah, the leading space... \$\endgroup\$ Aug 31, 2017 at 14:27
4
\$\begingroup\$

Charcoal, 44 40 39 35 bytes

|-DI>-/³↗<→/-LηLη↙¹←< ¿N↷⁴‖T⮌⪫η ‖B↓

Try it online! Link is to verbose version of code. First input is 1 for right and 0 for left, second is banner string. Edit: Saved 1 byte by using ReflectButterfly(:Up) as ReflectButterfly(:Down) currently has a cursor positioning bug, but I saved a further 4 bytes by reversing the print direction, and now it doesn't matter which I use. 38 34 32 byte version if mirroring the banner was allowed:

|-DI>-/³P⪫⪫<<η ↘→\-LηLη↖¹‖B↑¿N‖T

Try it online! Link is to verbose version of code. First input is 0 for right and 1 for left. Explanation:

|-DI>-/

Print the plane.

³↗<→/-LηLη↙¹←< 

Print the top half of the box (note trailing space).

¿N↷⁴‖T

If the second input is nonzero, reverse the print direction, otherwise reflect the plane and box.

⮌⪫η 

Print the message with extra spacing (note trailing space). The cursor is at the far end of the box from the plane so the message needs to be reversed.

‖B↓

Reflect to get the bottom half of the box.

\$\endgroup\$
2
  • \$\begingroup\$ Verbose version seems to have issues. \$\endgroup\$ Aug 30, 2017 at 11:16
  • \$\begingroup\$ @EriktheOutgolfer Deverbosifier was broken recently; TIO doesn't seem to have the fix yet. \$\endgroup\$
    – Neil
    Aug 30, 2017 at 12:10
2
\$\begingroup\$

Jelly, 68 65 bytes

“/\<“\/>”y
³K“|-DI>-/---< “ < ”j
LḤ‘”-x⁾//jṭ⁶x11¤Fµ,Ñj¢œs3U⁴¡YÑ⁴¡

Try it online!

Takes 1 for right, 0 for left.

-3 bytes thanks to @JonathanAllan (grr I always forget AB+ does the same as B+@A)

\$\endgroup\$
1
  • \$\begingroup\$ ³K“|-DI>-/---< “ < ”j saves a byte; LḤ‘”-x⁾//jṭ⁶x11¤Fµ,Ñj¢œs3U⁴¡YÑ⁴¡ saves another 2 in the same fashion. \$\endgroup\$ Aug 30, 2017 at 1:25
1
\$\begingroup\$

Charcoal, 56 bytes

-8 bytes thanks to totallyhuman and Erik the Outgolfer!

≔⪫S θ≔⁺Lθ²η× ¹¹/η/⸿|-DI>-/³<× η<‖B↓FN«‖TM⁺η³→≔⮌θθ»↑↑Mη←θ

Try it online!

Fixing the cases dzaima mentioned took quite a toll on the byte count. 36 bytes if we are allowed to reverse characters like < and /.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ In python, ' '.join(s) works. Surely that can be used in Charcoal? \$\endgroup\$ Aug 29, 2017 at 15:29
  • 1
    \$\begingroup\$ @totallyhuman Join works on strings too. \$\endgroup\$ Aug 29, 2017 at 15:46
  • \$\begingroup\$ Umm, I think it was totallyhuman who actually suggested that. \$\endgroup\$ Aug 29, 2017 at 18:01
  • \$\begingroup\$ @EriktheOutgolfer Oh, I misinterpreted @totallyhuman's suggestion as making a call to Python's ' '.join in Charcoal. I'll credit both of you. \$\endgroup\$
    – notjagan
    Aug 29, 2017 at 18:02
  • \$\begingroup\$ You've broken the ast processor... \$\endgroup\$
    – Neil
    Aug 29, 2017 at 18:53
1
\$\begingroup\$

SOGL V0.12, 55 47 43 bytes

└"┐ξA∫`Ν┌r4≥‘┘¹§,{e⌡↔@¹"╝′‰‘┼}"-<-/ \”┼e?±↔

Try it Here!

0 for left and 1 for right

\$\endgroup\$
1
\$\begingroup\$

Python 2, 137 136 133 bytes

lambda s,d:'{0}/{1}-/\n|-DI{3}-{4}---{5} {2} {5} \n{0}\\-{1}\\'.format(' '*11,'--'*len(s),' '.join(s),*list('></\\<>')[d::2])[::-d|1]

Try it online!

1 for right and 0 for left

\$\endgroup\$
3
  • \$\begingroup\$ 135 bytes (-1 byte) by replacing 1-2*d with -d|1 (negate d xor 1). \$\endgroup\$
    – Mr. Xcoder
    Aug 29, 2017 at 16:02
  • \$\begingroup\$ Typo, it's not xor, it's bitwise or, in fact. \$\endgroup\$
    – Mr. Xcoder
    Aug 29, 2017 at 16:09
  • 1
    \$\begingroup\$ 134 bytes with a little trick: *list('></\\<>')[d::2] \$\endgroup\$
    – jferard
    Aug 29, 2017 at 19:55
1
\$\begingroup\$

PHP, 175 bytes

[,$d,$s]=$argv;$f=str_repeat("--",strlen($s));$r="\-$f\           
 ".join(" ",str_split("><"[$d].$s)).($d?" <---/->":" >---\-<")."ID-|
/-$f/           ";echo$d?strrev($r):$r;

Run with -nr, first argument = 0 for facing right or 1 for left and second argument=text
or try it online.

\$\endgroup\$
1
\$\begingroup\$

Perl 5, 126 bytes

124 bytes code + 2 for -pl.

s/./$& /g;$_=($q=$"x11 .'/-'.s/./-/gr."/
")."|-DI>-/---< $_<
".$q=~y|\\/|/\\|r;<>&&(y|<>|><|,$_=reverse,s/>/ >/,s|-/-|-\\-|)

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Corea, 51 bytes

"u *:>ip.j:l)X-'/S:>"
|-DI>-/---< V< 
"h}>>`tHL`idF

Try it online!

Explanation

The program is composed of a few parts:

1: Initialization

"u *:>ip.j:l)X-'/S:>"
"..................."   execute the inside as code
 u                      repeat
   *                    a space, 11 times
    :                   duplicate this string
     >                  write this string to the content field
      i                 take a line of input
       p                push a space
        .j              insert that space after every character
          :l)           get (length(str) + 1)
             X-         repeat a hyphen that many times
               '/       push the "/" character
                 S      surround that string with the above character
                  :>    duplicate and write that string to the content field

2: raw text

The following text is outputted to the content field:


|-DI>-/---< V<

3: postamble

"h}>>`tHL`idF
"               execute until the end of the file
 h              mirror the previous string horizontally
  }             move the modified input string to the front of the stack
   >>           write the top two strings to the content field
     `   `id    do the inside `i`nput times
      tH        reflect the content field horizontally and vertically
        L       reverse the input string
            F   save the input string in a field (default: V)
                this replaces all Vs in the code with the input string
\$\endgroup\$
1
\$\begingroup\$

Google Sheets, 210 Bytes

Anonymous worksheet function that takes input input as string from [A1] and int from range [B1] where 1 indicates that the plane is on the left and 0 indicates that the plane is on the right.

=If(B1,"           /","\")&Rept("-",2*Len(A1)+1)&If(B1,"/
","\
")&If(B1,"|-DI>-/---< "," > ")&RegexReplace(A1,"(.)","$1 ")&If(B1,"<
",">---\-<ID-|
")&If(B1,"           \","/")&Rept("-",2*Len(A1)+1)&If(B1,"\","/
\$\endgroup\$
0
\$\begingroup\$

Excel VBA, 198 Bytes

Anonymous VBE immediate window function that takes input as string from [A1] and int from range [B1] where 1 indicates that the plane is on the left and 0 indicates that the plane is on the right.

b=[B1]:a=StrConv(IIf(b,[A1],StrReverse([A1])),64):j=[Rept("-",2*Len(A1)+1)]:k="/"&j &"/":l="\"&j &"\":s=Space(11):?IIf(b,s &k,l):?IIf(b,"|-DI>-/---< "," > ")a;IIf(b,"<",">---\-<ID-|"):?IIf(b,s &l,k)
\$\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.