11
\$\begingroup\$

Challenge: Print the entire printable ASCII charset (not just a range!) in order.

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

Rules: read closely

  • No other characters allowed in the output.

  • Program/function does not accept input.

  • Try not to hardcode/embed the output.

  • This is code golf, shortest answer wins.

\$\endgroup\$
8
  • 7
    \$\begingroup\$ Well they are a couple main things about this challenge that are why it's getting downvoted. A) the community really doesn't like it when you ban golfing language (whether or not I agree with this is a different matter) B) it's rather simple but I wouldn't say it's exactly trivial (kinda on the edge). Also saying "Try not to ..." usually isn't a good sign because it's not actually enforcing it (because it's hard to enforce this objectively), and it might mean your challenge may not be found that interesting (therefore getting downvotes). \$\endgroup\$
    – Downgoat
    Commented Jul 11, 2016 at 0:38
  • 10
    \$\begingroup\$ I'm not sure how to interpret try not to hardcode the output here. For a constant output challenge, that's the only way... \$\endgroup\$
    – Dennis
    Commented Jul 11, 2016 at 0:50
  • 1
    \$\begingroup\$ Do we have to print the output from a function or is returning a string acceptable? \$\endgroup\$
    – Dennis
    Commented Jul 11, 2016 at 5:53
  • 2
    \$\begingroup\$ Does "no other characters" include embedded newlines? \$\endgroup\$
    – Neil
    Commented Jul 11, 2016 at 7:48
  • 2
    \$\begingroup\$ This is NOT a duplicate of that challenge! Programs there had to accept input and print only part of the table. This challenge is easier and different. \$\endgroup\$
    – anna328p
    Commented Jul 11, 2016 at 23:23

87 Answers 87

1 2
3
0
\$\begingroup\$

Scala, 25 bytes

()=>' 'to'~'foreach print

Anonymous function with no args which prints given range

See it online: https://ideone.com/fX2rwf

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

Lua - 41 bytes

for i=32,127 do io.write(("").char(i))end
\$\endgroup\$
1
  • \$\begingroup\$ You also have to print #127. Not collecting everything in a variable seems to be shorter: for i=32,127 do io.write(("").char(i))end \$\endgroup\$
    – manatwork
    Commented Jul 11, 2016 at 8:51
0
\$\begingroup\$

2sable, 8 bytes

95Ý32+çJ

Try it online!

Same as for 05AB1E

Explanation

95Ý       Push [0..95]
   32+    Add 32 (vectorizes)
      ç   chr (vectorizes)
       J  Join by empty string
\$\endgroup\$
0
\$\begingroup\$

3var, 20 bytes

iiss+<+<>+<+<kkF[Pi]

Try it online!

Explanation

iiss                 Increment A twice, square A twice (set a to 16)
    +                Add A to B (set R to 16)
     <               Set B to R
      +<>            Add A and B (16 + 16 = 32), store to A and B
         +<+<        Add 32 to B twice more (B = 96)
             kk      Decrement B twice (B = 94)
               F[  ] Do B times
                 Pi  Print A as character and increment A
\$\endgroup\$
0
\$\begingroup\$

Actually, 12 bytes

:95r:32+♂┌εj

Try it online!

Explanation

:95r          Push [0 .. 95]
    :32+      Add 32
        ♂┌    Map chr over TOS
          εj  Join by empty string
\$\endgroup\$
0
\$\begingroup\$

VBA (Excel), 28 bytes

using immediate window.

for i=32to 126:?chr(i);:next

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

Perl 5, 21 bytes

print map{chr}32..127

Try it online!

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

Swift 4, 57 bytes

for i in 32...126{print(UnicodeScalar(i)!,terminator:"")}

Try it online!

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

Stax, 2 bytes

Vp

Run and debug it

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

Jelly, 2 bytes

ØṖ

Try it online!

Yep, it's included, but here's an answer without the builtin:

Jelly, 7 bytes

95Ḷ+32Ọ

Try it online!

95Ḷ        create lowered range, from 0 to 94 inclusive
   +32     add 32 to every element in the range
      Ọ    cast the entire list to characters and implicitly print
\$\endgroup\$
0
\$\begingroup\$

Yabasic/VBA, 29 bytes

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

Note that the VBA answer could be 1 byte shorter by using Chr instead of Chr$.

For i=32To 126:?Chr$(i);:Next

Yabasic: Try it online!

VBA:      There is no TIO for VBA :(

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

JavaScript (Node.js), 47 bytes

for(i=31;++i<127;)alert(String.fromCharCode(i))

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ I'm pretty sure Node.js doesn't have alert. \$\endgroup\$
    – Leaf
    Commented Jul 29, 2022 at 20:58
0
\$\begingroup\$

Prolog (SWI), 80 68 67 62 45 bytes

?-between(32,126,I),writef('%n',[I]),1=0;1=1.

Try it online!

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

Befunge-93, 18 bytes

 g:"~"`#@_:,1+00p#

You can try it here. The leading space is important!

                     The current character to be printed/checked, starts loop with a space
  g                  Push character from (0|0) onto stack(using the implicit 0s on the empty stack)
   :"~"`#@_          Check whether the char on (0|0) is over ~, if yes then end
           :,1+00p   Duplicate current char for output and incrementation
                  #  Since the code is a torus, it would continue at (0|0) so we skip it, since it could break the code.
\$\endgroup\$
0
\$\begingroup\$

Python - 41 bytes

for i in range(32, 127, 1):
 print(chr(i))

Python has a built-in ASCII function, so we can use that and print all 95 characters in a loop, one at a time.

No newlines - 50 bytes

for i in range(32, 127, 1):
 x = x + chr(i)
print(x)

This is just in case newlines aren't allowed, so this entry still gets in.

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

naz, 32 bytes

4a5m6m6a2x1v1x1f1a1o3x1v1l0x4d1f

Try it online!

Explanation (with 0x instructions removed)

4a5m6m6a2x1v   # Set variable 1 equal to 126
1x1f           # Function 1
    1a1o       # Add 1 to the register, then output
        3x1v1l # Goto the start of the function if the register is less than variable 1
4d             # Integer divide by 4, setting the register to a value of 31
1f             # Call function 1
\$\endgroup\$
0
\$\begingroup\$

Pxem, 17 bytes (filename) + 0 bytes (content) = 17 bytes.

  • Filename (some unprintables are escaped): ~.z.c\001.-.c\037.a.s.p
  • Content: empty.

Try it online!

With comments

XX.z
.a~.zXX.z # push 127; while size<2 || (pop!=pop); do
  .a.cXX.z # dup
  .a\001.-XX.z # push 1; push abs(pop-pop) iff size>=2
  .a.cXX.z # dup
.a\037.aXX.z # push 31; done
.a.s.pXX.z # pop (* to remove 31 *); while size>0; do printf "%c", pop; done
.a
\$\endgroup\$
0
\$\begingroup\$

Factor, 18 bytes

32 126 [a,b] write

Works in any modern version of Factor that supports printing non-string sequences directly. (i.e. not TIO.)

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

Kotlin, 27 bytes

(' '..'~').joinToString("")

Try it online!

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

Knight, 23 bytes

;=a 31W>127=a+1aO+Aa"\"

Try it online!

Unminified:

; = a 31
: WHILE (> 127 (= a (+ 1 a)))
    : OUTPUT (+ (ASCII a) "\")
\$\endgroup\$
0
\$\begingroup\$

Ly, 7 bytes

' '~R&o

Try it online!

' '~     - push first (" ") and last ("~") printable characters
    R    - generate a rage of codepoints
     &o  - print the stack as characters
\$\endgroup\$
0
\$\begingroup\$

Z80Golf, 9 bytes

00000000: 3e 20 06 5f ff 3c 10 fc 76                     > ._.<..v

Try it online!

Assembler source (z80asm):

start:
    ; start at space
    ld      a, ' '
    ; loop counter 
    ; I could also cp 0x7f; jr nz, .loop but this is faster to TOTALLY make up for below
    ld      b, 0x7F - ' '
.loop:
    ; Call 0x38, then nop slide to 0x8000 to print A to stdout
    ; only has a 130842 cycle overhead, which is worth the 2 bytes it saves
    rst     0x38
    ; set A to the next char
    inc     a
    ; Decrement b, then loop if non-zero
    djnz    .loop
    ; Exit
    halt

Pretty straightforward loop approach.

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

Knight (v2), 23 bytes

;;=s@W>95s=s+sA+32sO^sN

Try it online!

Another Alternative is

;=a@W>95=a+1aO+A+31a"\"
\$\endgroup\$
0
\$\begingroup\$

Pascal, 66 B

This program requires to be run on a processor using the ASCII character set (or a binary-compatible superset). The output will look quite different for instance on an IBM mainframe using EBCDIC.

program p(output);var c:char;begin for c:=' 'to'~'do write(c)end.

Note, in Pascal for-loop limits are inclusive. During the final iteration c assumes the specified value '~'.

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

Alice, 14 bytes

' w.oh.'~h-$K@

Try it online!

Explanation

' w.oh.'~h-$K@   Full program
'                Adds 32 (space) on the stack
  w        $K@   Repeat until...
      .'~h-      ...we reach 126 (~)
   .oh           Print and increase the current character
\$\endgroup\$
0
\$\begingroup\$

Go, 45 bytes

func(){for i:=32;i<127;i++{print(string(i))}}

Attempt This Online!

Prints to STDERR.

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

International Phonetic Esoteric Language, 21 bytes

{3j}{w}ɑeχue1søɒ

Ungolfed

{3j}{w}   ( loop bounds: 32 w <= e < 127 3j )
ɑ         ( loop )
 e        ( push index )
  χ       ( ord index )
   u      ( pop-output without newline )
    e1sø  ( increment index )
        ɒ ( end loop )
\$\endgroup\$
1 2
3

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.