24
\$\begingroup\$

Cross posted from my anagolf post (note: may contain spoilers, post mortem).

Output the following text exactly.

  • You may have additional trailing whitespace on each line, and trailing newlines as well.
  • Shortest code, in bytes, wins.
                                                
                                              !"!
                                             "#$#"
                                            #$%&%$#
                                           $%&'('&%$
                                          %&'()*)('&%
                                         &'()*+,+*)('&
                                        '()*+,-.-,+*)('
                                       ()*+,-./0/.-,+*)(
                                      )*+,-./01210/.-,+*)
                                     *+,-./012343210/.-,+*
                                    +,-./0123456543210/.-,+
                                   ,-./01234567876543210/.-,
                                  -./0123456789:9876543210/.-
                                 ./0123456789:;<;:9876543210/.
                                /0123456789:;<=>=<;:9876543210/
                               0123456789:;<=>?@?>=<;:9876543210
                              123456789:;<=>?@ABA@?>=<;:987654321
                             23456789:;<=>?@ABCDCBA@?>=<;:98765432
                            3456789:;<=>?@ABCDEFEDCBA@?>=<;:9876543
                           456789:;<=>?@ABCDEFGHGFEDCBA@?>=<;:987654
                          56789:;<=>?@ABCDEFGHIJIHGFEDCBA@?>=<;:98765
                         6789:;<=>?@ABCDEFGHIJKLKJIHGFEDCBA@?>=<;:9876
                        789:;<=>?@ABCDEFGHIJKLMNMLKJIHGFEDCBA@?>=<;:987
                       89:;<=>?@ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA@?>=<;:98
                      9:;<=>?@ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA@?>=<;:9
                     :;<=>?@ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA@?>=<;:
                    ;<=>?@ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA@?>=<;
                   <=>?@ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA@?>=<
                  =>?@ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA@?>=
                 >?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>
                ?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?
               @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@
              ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`aba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA
             BCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCB
            CDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDC
           DEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFED
          EFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFE
         FGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGF
        GHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHG
       HIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnoponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIH
      IJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJI
     JKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJ
    KLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLK
   LMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONML
  MNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONM
 NOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPON
OPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO
\$\endgroup\$
  • 3
    \$\begingroup\$ Is there an intentional first whitespace-only line? \$\endgroup\$ – AdmBorkBork Apr 26 '18 at 13:42
  • 9
    \$\begingroup\$ @AdmBorkBork that's a space because that's the first ASCII char lol \$\endgroup\$ – HyperNeutrino Apr 26 '18 at 13:43
  • 2
    \$\begingroup\$ @the4kman and the <=>=< fish. \$\endgroup\$ – pizzapants184 Apr 26 '18 at 14:53
  • 4
    \$\begingroup\$ Is there a reason this isn't titled "You Must Construct ASCII Pylons!"? \$\endgroup\$ – mattdm Apr 27 '18 at 16:20
  • 3
    \$\begingroup\$ @mattdm I only came here from the HNQ list to upvote this because of its title. Nicely done. \$\endgroup\$ – Todd Wilcox Apr 27 '18 at 19:43

33 Answers 33

4
\$\begingroup\$

Canvas, 15 14 bytes

0c[C²[j}¹m]/││

Try it here!

Note that while making this I added a couple built-ins ( & ) as Canvas somehow didn't have any built-ins for ASCII/unicode before...

Explanation (some characters have been replaced to look monospace):

0c              push the charcode of "0" - 48
  {       ]     map over 1..48
   C              push the ASCII characters
    ²[ ]          repeat by the counter (0-indexed)
      j             remove the last character
        ¹m        mold to the length of the counter
           /    pad each line with spaces so it looks like a diagonal
            ││  palindromize the whole thing horizontally
\$\endgroup\$
16
\$\begingroup\$

PowerShell, 73 bytes

' '*48;46..0|%{" "*$_+-join[char[]](($x=79-$_)..($y=$x+$j++)+(++$y)..$x)}

Try it online!

Outputs the first whitespace-only line, then loops from 46 to 0. Each iteration, outputs the corresponding number of spaces and then a -joined together char-array of the appropriate symbols, via some calculations.

\$\endgroup\$
  • 1
    \$\begingroup\$ Can you save some calculations by treating the first line as 47 spaces followed by a space character? \$\endgroup\$ – Riking Apr 27 '18 at 23:35
  • \$\begingroup\$ @Riking To do so, you'd need to special case how the char-array is created to only create one item instead of 3 or more. As a result, it's shorter to special case the spaces-only line completely separately. \$\endgroup\$ – AdmBorkBork Apr 30 '18 at 12:49
11
\$\begingroup\$

Charcoal, 13 bytes

E⁴⁸⮌✂γι⊕⊗ι‖O←

Try it online! Link is to verbose version of code. Explanation:

 ⁴⁸             Literal 48
E               Map over implicit range
      ι  ι      Current index
        ⊗       Doubled
       ⊕        Incremented
     γ          Printable ASCII
    ✂           Slice
   ⮌            Reverse
                Implicitly print each slice on separate lines
          ‖O←   Reflect with overlap
\$\endgroup\$
  • 5
    \$\begingroup\$ The output seems wrong to me. \$\endgroup\$ – Mr. Xcoder Apr 26 '18 at 14:01
  • 1
    \$\begingroup\$ @Mr.Xcoder Ugh, classic off-by-1 error... \$\endgroup\$ – Neil Apr 26 '18 at 14:40
8
\$\begingroup\$

Python 2, 73 bytes

i=48
while i:i-=1;r=range(79-i,127-i*2);print' '*i+bytearray(r+r[-2::-1])

Try it online! Crossposted from anarchy golf (see my submission).

Quick post-mortem analysis: xnor and dianne discovered the exact same solution. ebicochneal submitted a 71 byte solution which mitchs improved to 70 bytes. They avoid dealing with bytearray (which is long) or ''.join(map(chr,…)) (which is even longer) entirely, by keeping a "current line" variable and cleverly updating it.

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

Jelly, 17 bytes

48ḶḤr$z0ZUŒB+32ỌY

Try it online!

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

05AB1E, 16 bytes

48FžQNÝûN+èJ}).C

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Ahhh... žQ was way better than žw79ŸvyžwN2*+ŸûçJ}).C \$\endgroup\$ – Magic Octopus Urn Apr 27 '18 at 20:31
4
\$\begingroup\$

SOGL V0.12, 16 15 bytes

'½{ ~Δf⌡kFm}⁰¼╥

Try it Here!

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

Common Lisp, 110 bytes

(dotimes(i 48)(dotimes(j 96)(princ(if(>(abs(- j 48))i)" "(code-char(+(-(* i 2)(abs(- j 48)))32)))))(princ"
"))

Try it online!

Explanation

(dotimes(i 48)                   ;; for i from 0 up to 47
    (dotimes(j 96)               ;; for j from 0 up to 95
        (princ                   ;; print
            (if(>(abs(- j 48))i) ;; if abs(j - 48) > i
                " "              ;; print " "
                (code-char(+(-(* i 2)(abs(- j 48)))32)) ;; else print appropriate character
            )
        )
    )(princ"
") ;; print newline
)
\$\endgroup\$
3
\$\begingroup\$

VBA, 71 bytes

An anonymous VBE immediate window function that takes no input and outputs to the console.

For i=0To 47:?Spc(47-i);:For j=-i To i:?Chr(32-Abs(j)+2*i);:Next:?:Next
\$\endgroup\$
3
\$\begingroup\$

Ruby, 70 bytes

s=[*?\s..?~]*'';48.times{|i|puts s[i,i+1].rjust(48)+s.reverse[-2*i,i]}

Try it online!

Constructs the full printable ASCII string and then prints the required number of forward (padded with spaces) + backward slices of it.

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

Jelly, 24 bytes

48RrḤ’$$ịØṖŒBṭ"48RU⁶ẋ$¤Y

Try it online!

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

C (gcc), 117 bytes

c;i;main(){for(i=0;i<48;++i){for(c=2*i-15;c<32+2*i;++c)putchar(c>31+i?c:32);for(;c>31+i;--c)putchar(c);putchar(10);}}

Try it online!

Ungolfed:

int ch;
int row;
int main(void) {
    for (row = 0; row < 48; ++row) {
        for (ch = 2*row-15; ch < 32 + 2*row; ++ch) {
            // The first character in the row is 2*row - 15 (row is zero-indexed)
            if (ch > 31+row)
                putchar(ch);
            else
                // If the current character is not in the pyramid, mask it with a space
                putchar(' ');
        }
        for (; ch > 31+row; --ch) {
            // Finish the other side of the pyramid
            putchar(ch);
        }
        putchar('\n');
    }
}
\$\endgroup\$
2
\$\begingroup\$

C (gcc), 114 113 107 bytes

#define _(_)for(k=32;k<j;)putchar(j+_++);
f(j,k){for(j=31;++j<80;){printf("\n%*c",80-j,j);_(-31+k)_(j+~k)}}

Try it online!

101 bytes are possible using a compiler flag.

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

Perl 6, 55 53 bytes

say ' 'x 47-$_,chrs 32+2*$_ X-(-$_..$_)>>.abs for ^48

Try it online!

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

T-SQL, 153 bytes

DECLARE @ INT=33,@t CHAR(95)=''a:PRINT @t;
SET @t=LEFT(STUFF(STUFF(@t,63-@/2,2,''),46,0,CHAR(@-1)+CHAR(@)+CHAR(@+1)+CHAR(@)),33+@/2)
SET @+=2IF @<128GOTO a

Returns are for display only.

I tried several ideas, including a loop to preconstruct the full string (163 characters), and a nested loop to build it on the fly (168 characters), but this ended up being the shortest.

Basically, each loop I'm cramming 4 new characters into the center of the string, then trimming off the extras from both ends, using the SQL STUFF() function.

Formatted and explained:

DECLARE @ INT=33,                      --Using a single counter for both rows and CHAR
        @t CHAR(95)=''                 --a non-null CHAR field will pre-fill with spaces
a:                                     --GOTO loop, shorter than a WHILE
    PRINT @t                           --duh
    SET @t = LEFT(                     --lops off the character at the end
            STUFF(                     --crams 4 new characters in the middle
            STUFF(@t, 63-@/2, 2, '')   --snips out a space and the leading character
                 ,46, 0, CHAR(@-1) + CHAR(@) + CHAR(@+1) + CHAR(@))
                 ,33 + @/2)            --rest of the LEFT()
    SET @+=2
IF @<128 GOTO a
\$\endgroup\$
2
\$\begingroup\$

J, 47 44 bytes

(,.~}:@|."1)(1+i.48)([|.@{.}.)"0 1 u:31+i.96

Try it online!

Thanks to Conor O'Brien for the template! Thanks to FrownyFrog for indicating the invalid solution.

\$\endgroup\$
  • 1
    \$\begingroup\$ Perhaps this is more easily modifiable: Try it online! \$\endgroup\$ – Conor O'Brien Apr 26 '18 at 19:10
  • \$\begingroup\$ @Conor O'Brien - Thank you for the template, I've updated the link. \$\endgroup\$ – Galen Ivanov Apr 27 '18 at 6:13
  • \$\begingroup\$ Prints an extra line at the top. \$\endgroup\$ – FrownyFrog Apr 27 '18 at 6:48
  • \$\begingroup\$ @FrownyFrog Oh, it's only now that I see that only trailing newlines are permitted, not leading. I'll try to fix it. \$\endgroup\$ – Galen Ivanov Apr 27 '18 at 6:57
  • \$\begingroup\$ @FrownyFrog - Fixed and slightly golfed. \$\endgroup\$ – Galen Ivanov Apr 27 '18 at 7:17
2
\$\begingroup\$

Ruby, 59 bytes

48.times{|i|-47.upto(i){|c|putc~c<i ?32-c.abs+2*i:32};puts}

Cross-posted from my answer on anagol.

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

Japt -R, 18 15 bytes

14 bytes if an additional leading newline is allowed.

#0õ_odH+ZÉ ¬êÃû

Test it


Explanation

#0                  :48
  õ                 :Range [1,48]
   _         Ã      :Pass each Z through a function
    o               :  Range [0,Z)
      H+ZÉ          :    To each add 32+Z-1
     d              :    Get the character at that codepoint
           ¬        :  Join to a string
            ê       :  Palinrdomise
              û     :Centre pad each element to the length of the longest element
                    :Implicitly join with newlines and output
\$\endgroup\$
2
\$\begingroup\$

J,  40 37 32 bytes

40 expression u:30+2>.(+:@i.@(2&+)(-*(>+:))"0 _|@i:)47 thanks to +Galen Ivanov & +Conor O'Brien for the ideas in their solutions

37 included echo echo u:32+|.(~.(>:*+:@[-])"0 _])|i:47

echo u:32+|.(~.(>:*[+-)"{])|i:47

incorporating @FrownyFrog tips from comments

TIO

\$\endgroup\$
  • \$\begingroup\$ I don't think expressions are valid submissions. \$\endgroup\$ – LyricLy Apr 26 '18 at 23:59
  • \$\begingroup\$ @LyricLy , opinion seems to vary as I do see another J answer in this form .. anyway thanks for prodding me to shave another 8 bytes .. now I have room to add "echo " : hope you're happy : ) \$\endgroup\$ – jayprich Apr 27 '18 at 13:46
  • \$\begingroup\$ "0 _"{ \$\endgroup\$ – FrownyFrog Apr 27 '18 at 22:22
  • \$\begingroup\$ +:@[-][+- \$\endgroup\$ – FrownyFrog Apr 27 '18 at 22:38
  • \$\begingroup\$ beautiful .. thanks for these tips @FrownyFrog \$\endgroup\$ – jayprich Apr 28 '18 at 15:12
2
\$\begingroup\$

Perl 5, 77 75 69 bytes

map{say$"x(47-$_),(@a=map chr$_+32,$_..$_*2),reverse@a[0..@a-2]}0..47

Try it online!

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

Python 2, 98 88 bytes

-1 byte thanks to @Mr.Xcoder

i=32
exec"print''.join(chr(i+i-32-abs(j))for j in range(32-i,i-31)).center(95);i+=1;"*48

Try it online!

\$\endgroup\$
  • \$\begingroup\$ -i+32 => 32-i and you might use ' '*(79-i) instead of .center(95) to save bytes. \$\endgroup\$ – Mr. Xcoder Apr 26 '18 at 14:19
  • \$\begingroup\$ @Mr.Xcoder thanks! ' '*(79-i)+ doesn't really save bytes :D \$\endgroup\$ – Dead Possum Apr 26 '18 at 14:28
1
\$\begingroup\$

Ruby, 78 bytes

s=*32;48.times{puts (s.map(&:chr)*'').center 95;c=*s[0]+1;s=c+s.map{|x|x+2}+c}

Try it online!

Full program. Ungolfed:

s=*32;                              # s is an array of integers
48.times{                           # Repeat 48 times:
  puts (s.map(&:chr)*'').center 95; # Turn each int to a char, join, center, and print
  c = *s[0] + 1;                    # c is a singleton array. It will bookend the next line
  s = c + s.map{|x|x+2} + c         # Add 2 to each element of s before adding the bookends
}
\$\endgroup\$
1
\$\begingroup\$

Yabasic, 80 bytes

An anonymous function that takes no input and outputs to the console

For i=0To 47
For j=i To 47?" ";Next
For j=-i To i?Chr$(32-Abs(j)+2*i);Next
?Next

Try it online!

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

uBASIC, 95 bytes

0ForI=0To47
1ForJ=ITo47:?" ";:NextJ
2ForK=-1*IToI:?Left$(Chr$(32-Abs(K)+2*I),1);:NextK
3?:NextI

Try it online!

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

MY-BASIC, 97 bytes

An anonymous MY-BASIC response that takes no input and outputs to the Console

For i=0 To 47
For j=i To 47
Print" "
Next
For j=-i To i
Print Chr(32-Abs(j)+2*i)
Next
Print;
Next

Try it online!

-1 byte thanks to Jonathan Frech

\$\endgroup\$
  • 1
    \$\begingroup\$ Print " " -> Print" ". \$\endgroup\$ – Jonathan Frech Apr 26 '18 at 19:53
  • \$\begingroup\$ @JonathanFrech - whoops sorry I mispelled your name \$\endgroup\$ – Taylor Scott Apr 30 '18 at 22:37
1
\$\begingroup\$

MATL, 18 bytes

48:"@@Zv30++Xhc3Zu

Try it online!

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

Gol><>, 29 bytes

`0FaLssLF:P|LF:M|`/L-R` lRo|;

Try it online!

How it works

`0FaLssLF:P|LF:M|`/L-R` lRo|;

`0F                        |;  Repeat the following 48 times and halt...
   a                           Push 10 (\n)
    Lss                        Push L(loop counter) + 32
       LF:P|                   Repeat "Clone the top and increment" L times
            LF:M|              Repeat "Clone the top and decrement" L times
                 `/L-R`        Push 32 (space) 47-L times (space is significant)
                        lRo    Print everything as char, from the top,
                               until the stack is empty
\$\endgroup\$
1
\$\begingroup\$

Tcl, 129 122 118 117 bytes

time {incr i;set j -48;set a {};time {set a $a[format %c [expr abs([incr j])>=$i?32:$i*2-abs($j)+30]]} 96;puts $a} 48

Try it online!

Explanation

time { # for i from 0 up to 47
    incr i
    set j -48
    set a {}
    time { # for j from -48 up to 47
        # add next character to a
        set a $a[format %c [expr abs([incr j])>$i?32:$i*2-abs($j)+32]]
    } 96
    puts $a # print a
} 48
\$\endgroup\$
1
\$\begingroup\$

C (gcc) 199 bytes

#include<stdio.h>
int i,j=32,k=32,l=49;int main(){while(k<127){for(i=0;i<l;++i)printf(" ");for(i=j;i<k;++i)printf("%c",i);printf("%c",k);for(i=k-1;i>=j;--i)printf("%c",i);printf("\n");j++;k+=2;l--;}}

Try it online!

Thanks to Picard and PunPun1000 for all of the help

\$\endgroup\$
  • \$\begingroup\$ @Picard I removed the spaces. I could further minify with a global iterator variable. \$\endgroup\$ – Jonathan Landrum Apr 27 '18 at 0:59
  • \$\begingroup\$ @Picard I edited it on my phone; didn't realize I'd left a blank line. \$\endgroup\$ – Jonathan Landrum Apr 27 '18 at 16:59
  • 1
    \$\begingroup\$ There's unnecessary spaces in the printf calls after the commas, and the variable names can be shortened down to one letter. Also it would be nice if you could include a TIO link and the actual byte count. Here's the link for your current code TIO \$\endgroup\$ – PunPun1000 Apr 27 '18 at 19:55
  • \$\begingroup\$ ok, i've squeezed it a bit more, i think i'd have to change the algorithm to shrink it further \$\endgroup\$ – Jonathan Landrum Apr 27 '18 at 20:05
1
\$\begingroup\$

Haskell, 102 bytes

main=putStr$do
i<-[48,47..0]
let l=replicate i 32++[79-i..126-i*2]
map toEnum$l++tail(reverse l)++[10]

Things I have tried that were not shorter:

  • Expressing everything in terms of character literals and succ or pred to save the map toEnum.
  • Writing a downward range instead of using reverse.
\$\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.