16
\$\begingroup\$

To celebrate the 2497th anniversary of the Greek victory at Salamis in 480 BC. Draw the lambda blazon.

The lambda blazon was the lambda painted on greek shields like so:

images of red capital lambda on circular white and gold shield backgrounds

Puzzle: Given a positive odd integer n, produce an ascii art image of the above shield.

Specifications:

n=1:

( /\ )

n=3:

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

n=5

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

Graph: n=3

          2|   (   /\   )
y-axis    1|   |  /  \  | 
          0|   ( /    \ )
               ___________  
               0123456789

                 x-axis

Description:

There should be exactly n \ characters and n / characters. The /s and \s should not touch the edge of the shield. The bottom and top corners of the shield will be denoted with a ( or ) unless n=1 where there will be one ) and one (. There will always be one space between the bottom corners and the lambda, increasing by 1 with the y axis until y + 1 == n. Non corners of the shield side will be denoted with |. There is no shield top.

\$\endgroup\$
  • 7
    \$\begingroup\$ Why downvote? (2 more to go) \$\endgroup\$ – user202729 Oct 20 '17 at 15:19
  • 3
    \$\begingroup\$ @user202729 what do you mean 2 more to go? \$\endgroup\$ – jacksonecac Oct 20 '17 at 15:28
  • 4
    \$\begingroup\$ SE has comment character restriction, which force comments to be at least 15 characters. \$\endgroup\$ – user202729 Oct 20 '17 at 15:29
  • 7
    \$\begingroup\$ Why couldn't you have waited 3 years to post it for the 2.5k'th anniversary ;-; \$\endgroup\$ – HyperNeutrino Oct 20 '17 at 16:38
  • 5
    \$\begingroup\$ Why only odd integers? :o \$\endgroup\$ – Felix Palmen Oct 20 '17 at 17:37

17 Answers 17

8
\$\begingroup\$

Charcoal,  17  13 bytes

Thanks to @Neil for saving 4 bytes!

(↙↓⊖θM↑(→↗N‖M

Try it online!

Explanation:

(↙                // Print '(' and move one step down and to the left.
  ↓⊖θ             // Print n-1 '|'s downwards.
     M↑          // Move one step up.
        (→        // Print '(' and move one step to the right.
          ↗N      // Print n '/'s towards the upper right corner.
            ‖M    // Mirror the left half to produce the right half.
\$\endgroup\$
  • 1
    \$\begingroup\$ saves you a byte, and half of your s are unnecessary. \$\endgroup\$ – Neil Oct 20 '17 at 16:06
  • 1
    \$\begingroup\$ Also, your Iθ can be to save another byte. \$\endgroup\$ – Neil Oct 20 '17 at 16:12
  • \$\begingroup\$ Summing up Neil's suggestions, 13 bytes \$\endgroup\$ – Mr. Xcoder Oct 20 '17 at 16:21
  • \$\begingroup\$ @Mr.Xcoder Thanks, but I got around to doing those already. \$\endgroup\$ – Steadybox Oct 20 '17 at 16:24
  • \$\begingroup\$ It's small, but I believe in your explanation (→ should mean "... and move one step to the right" \$\endgroup\$ – Kamil Drakari Oct 20 '17 at 18:35
6
\$\begingroup\$

SOGL V0.12, 17 14 bytes

┐*ƨ(Κm«@.╚┼┼╬³

Try it Here!

Explanation:

example input: 3
┐*              push a string of input amount of "|"                      "|||"
  ƨ(            push "("                                                  "|||", "(("
    Κ           prepend that to the vertical bar string                   "((|||"
     m          mold that string as the input (remove excess characters)  "((|"
      «         put the first character at the end                        "(|("
       @        push a space                                              "(|(", " "
        .╚      create a diagonal of input length                         "(|(", " ", ["  /", " / ", "/  "]
          ┼┼    append those three horizontally together                  ["(   /", "|  / ", "( /  "]
            ╬³  palindromize that all                                     
\$\endgroup\$
4
\$\begingroup\$

C (gcc), 103 96 bytes

f(n,j,b){for(j=n;j--;printf("%c%*c%*c%*c\n","|("[b],j+2,47,n+n-j+~j,92,j+2,"|)"[b=j<1|n-2<j]));}

Try it online!

\$\endgroup\$
  • \$\begingroup\$ We excuse the main and includes now? This community has changed. \$\endgroup\$ – Alec Teal Oct 21 '17 at 14:34
  • 2
    \$\begingroup\$ @AlecTeal It is acceptable to write a function that performs the specified task rather than a full program. Includes in general do count towards the byte count, some C compilers, however, attempt to guess a function definition if no matching includes are present. \$\endgroup\$ – Jonathan Frech Oct 21 '17 at 14:45
  • \$\begingroup\$ Think you crossed out the wrong number, chief \$\endgroup\$ – Veskah Jan 18 at 0:45
  • \$\begingroup\$ @Veskah True. ._. \$\endgroup\$ – Jonathan Frech Jan 18 at 18:37
3
\$\begingroup\$

Retina, 41 bytes

.+
$* 
 
( $'/$`$`\$' )¶
G`.
sT`()`|`¶.*¶

Try it online! Explanation:

.+
$* 

Convert to unary, but using spaces.

 
( $'/$`$`\$' )¶

Use the match prefix and suffix operators to generate a series of lines with increasing amounts of centre space on each line.

G`.

However, there's an extra blank line, which throws off the final transliteration, so delete it here.

sT`()`|`¶.*¶

On all lines except the first and last, change the ()s to |s.

\$\endgroup\$
2
\$\begingroup\$

Perl 5, 91 + 1 (-p) = 92 bytes

$_='('.($s=$"x($q=$_))."/\\$s)";while(--$q){say;y/()/|/;s| /|/ |;s|\\ | \\|}s/\|/(/;s/\|/)/

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Java (OpenJDK 8), 200 190 170 bytes

n->{for(char i=0,s[];i<n;s[-~n-i]=47,s[2+n+i]=92,s[0]=i<1|i>n-2?40:'|',s[3+n+n]=i<1|i++>n-2?41:'|',System.out.println("".valueOf(s).replace('\0',' ')))s=new char[4+n+n];}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Pyth, 43 bytes

This is quite gigantic given that it's been done on mobile :-/

j_m++++++@"(|"J!/,1QdK*;d\/*;y-Qd\\K@")|"JS

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Python 2, 85 bytes

n=a=input()
while a:print'(|'[1<a<n]+a*' '+'/'+(n-a)*'  '+'\\'+a*' '+')|'[1<a<n];a-=1

Try it online!

\$\endgroup\$
2
\$\begingroup\$

R, 153 bytes

function(n){s=2*n+4
m=matrix('|',s,n)
m[3:s-1,]=' '
m[cbind(5:s-2,c(n:1,1:n))]=1
m[1,c(1,n)]='('
m[s,c(1,n)]=')'
m[m>0]=rep(c('/','\\'),n)
rbind(m,'\n')}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Batch, 218 bytes

@echo off
set s=
for /l %%i in (1,1,%1)do call set s= %%s%%
set s=%s%/\%s%
echo (%s%)
for /l %%i in (2,1,%1)do call:l %1 %%i
exit/b
:l
set s=%s: /=/ %
set s=%s:\ = \%
if %1==%2 (echo ^(%s%^))else echo ^|%s%^|

As if |s weren't bad enough, ()s don't work well with if...else.

\$\endgroup\$
2
\$\begingroup\$

05ab1e (27 bytes)

F"|("0NQ¹<NQ~èð¹N-×'/ðN×J∞,

try it online

explanation

F                                                #Loop n times        
 |("0NQ¹<NQ~è                                    #Use ( or |        
             ð¹N-×                               #put spaces (1)        
                  '/                             #put /                
                    ðN×                          #put more space                
                       J∞,                       #reverse image        
\$\endgroup\$
  • \$\begingroup\$ I think '/¹N-ú is a byte shorter than ð¹N-×'/. \$\endgroup\$ – Neil Oct 23 '17 at 9:43
  • \$\begingroup\$ Nice approach, but there are a few things to golf. One is what @Neil suggested above. In addition: "|(" can be „|( (there are builtins for 1, 2, and 3-char strings being ', and respectively); and 0NQ¹<NQ~ can be ΂Nåè (Î seems to be bugged in the legacy version of TIO, but it does work in the latest version of 05AB1E, in which case you'll also have to replace with º). So in total (21 bytes): F„|(΂Nåè'/¹N-úðN×Jº, Try it online. \$\endgroup\$ – Kevin Cruijssen Jan 18 at 12:18
2
\$\begingroup\$

Funky, 101 bytes

n=>for(i=0;i<n;i++)print(((c=(i==n-1)or!i)?"(":"|")..(s=" "*n-i).."/"..(" "*i*2).."\\"..s..c?")":"|")

Try it online!

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

Python 2, 90 bytes

n=input()
for i in range(n):m=-~i%n<2;s=' '*(n-i);print'|('[m]+s+'/'+'  '*i+'\\'+s+'|)'[m]

Try it online!

-1 thanks to ovs.

\$\endgroup\$
  • \$\begingroup\$ fails for n=1, but can be fixed by replacing i%~-n<1 with -~i%n<2 \$\endgroup\$ – Rod Oct 20 '17 at 15:27
  • \$\begingroup\$ @Rod thanks, fixed \$\endgroup\$ – Erik the Outgolfer Oct 20 '17 at 15:28
  • \$\begingroup\$ 90 bytes: '<space>'*i*2 -> '<space><space>'*i \$\endgroup\$ – ovs Oct 20 '17 at 15:55
  • \$\begingroup\$ @ovs @_@ why didn't I think of that \$\endgroup\$ – Erik the Outgolfer Oct 20 '17 at 15:59
1
\$\begingroup\$

C# (.NET Core), 188 bytes

n=>{int y=0,i=-1;var s="";while(y<n){var r=new char[n*2+4];r[n+1-y]='/';r[n+2+y]='\\';if(y<2|y++>n-2)i++;r[0]="(|("[i];r[n*2+3]=")|)"[i];s+=new string(r)+"\n";}return s.Replace("\0"," ");}

Try it online!

Degolfed

n=>{
    int y=0,i=-1;
    var s="";

    while(y<n){
        var r=new char[n*2+4];
        r[n+1-y]='/';
        r[n+2+y]='\\';

        if(y<2 | y++>n-2)
            i++;

        r[0] = "(|("[i];
        r[n*2+3] = ")|)"[i];

        s += new string(r)+"\n";
    }

    return s.Replace("\0"," ");
}
\$\endgroup\$
1
\$\begingroup\$

Python 3, 110 bytes 93 bytes

b=c=int(input())*2
d,e='/\\'
while b:print('(|%%ss)|'[2<b<c::2]%f' {d+e:^{c}} ');d+='  ';b-=2
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 93 91 90 89 bytes

-2 Thanks to ASCII-only for pointing out extra parens
-1 Thanks to Mazzy for tweaking swap logic

param($n)0..--$n|%{"|("[!($x=($n-$_)*$_)]+($y=" "*($n-$_+1))+"/"+"  "*$_+"\$y"+"|)"[!$x]}

Try it online!

Trying to tweak that $x= bit. There's probably a smarter way to get the 1st and last line out in a few less bytes. There is a better $x= but it isn't much cheaper.

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

Canvas, 12 bytes

┤|×(e⟳ +╴/+║

Try it here!

Explanation:

┤             decrease the input by 2
 |×           repeat "|" vertically - if the amount is -1 (for input of 1), ir just removes the item currently
   (          push "("
    e        encase in that parentheis - if that first string isn't there, currently it just fails doing anything and leaves the parenthesis on the stack
     ⟳       rotate clockwise
       +     append horizontally a space
        ╴/   get a diagonal the length of the input
          +  append it horizontally to the current result
           ║  and palindromize horizontally with 0 overlap
\$\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.