6
\$\begingroup\$

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

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

(Of course, replace space with the actual space character.)

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\$
  • 5
    \$\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 Jul 11 '16 at 0:38
  • 8
    \$\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 Jul 11 '16 at 0:50
  • 1
    \$\begingroup\$ Do we have to print the output from a function or is returning a string acceptable? \$\endgroup\$ – Dennis Jul 11 '16 at 5:53
  • 2
    \$\begingroup\$ Does "no other characters" include embedded newlines? \$\endgroup\$ – Neil Jul 11 '16 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\$ – dkudriavtsev Jul 11 '16 at 23:23

62 Answers 62

1
\$\begingroup\$

Retina, 12 bytes

The  is the Unit Separator character \x1F (31)



+;T`p`p_

Try it online!


Retina 0.8.2, 18 bytes

Same method as above, but requires some extra bytes for printing and not having a trailing newline.



+*\T`p`p_
\`.

Try it online!


If, like in Martin's answer, a trailing newline is acceptable, then this is possible, beating him by 5 bytes:

Retina 0.8.2, 13 bytes



+*\T`p`p_

Try it online!

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

Gol><>, 9 bytes

`_FLss|rH

Try it online!

How it works

`_FLss|rH

`_F...|    Run the following 95 times:
   Lss       Push the loop counter + 32
       rH  Print all the chars in the pushed order and halt
\$\endgroup\$
1
\$\begingroup\$

F# (.NET Core), 30 bytes

Seq.iter(printf"%c")[' '..'~']

Try it online!

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

Common Lisp, 41 bytes

(dotimes(i 95)(princ(code-char(+ i 32))))

Try it online!

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

Charcoal, 1 byte

γ

Try it online!

No builtin, 7 bytes:

⪫…· ¦~ω

Try it online!

Explanation

⪫     ω  Join by empty string
 …· ¦~    Inclusive range from " " to "~"
\$\endgroup\$
1
\$\begingroup\$

Tcl, 55 bytes

set i 31
time {puts -nonewline [format %c [incr i]]} 95

Try it online!

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

Add++, 12 bytes

L^,126 32rBF

Try it online!

Explanation

L^,          Lambda returning stack cast to string (takes character code of numbers)
   126 32r   Inclusive range from 32 to 126
          BF Flatten stack
\$\endgroup\$
1
\$\begingroup\$

><>, 21 19 bytes

48*v
)?;>:o1+:763**

Try it online!

Explanation

48*v               Push 32 and move down
                   Print character, increment, stop if greater than 126
)?;>:o1+:763**
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 2 bytes

žQ

Try it online!

No builtin, 8 bytes:

95Ý32+çJ

Try it online!

Explanation

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

Ruby, 14 bytes

print *?\s..?~

Try it online!

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

Chip -w -gii -c127, 19 bytes

aABbcC,~S
dDEefF^Gg

Try it online!

Flags:

  • -w Don't attempt to read stdin
  • -gii Generate incrementing bytes for input
  • -c127 Cut off execution at 127 cycles

Code:

This is a cat program suitable for ASCII (only handles 7 bits):

aABbcC
dDEefF Gg

And this suppresses output for values outside the range 0x20-0x7f. (More accurately, it requires that at least one of the bits 0x20 or 0x40 to be true):

      ,~S
     F^G
\$\endgroup\$
1
\$\begingroup\$

Whitespace, 52 bytes

[S S S T    S S S S S N
_Push_32][N
S S N
_Create_Label_LOOP][S N
S _Duplicate][T N
S S _Print_as_character][S S S T    N
_Push_1][T  S S S _Add][S N
S _Duplicate][S S S T   T   T   T   T   T   T   N
_Push_127][T    S S T   _Subtract][N
T   T   N
_If_negative_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs, and new-lines).
Program stops with error: No exit defined.

Pseudo-code:

Integer c = 32
Start LOOP:
  Print c as character
  c = c + 1
  If c - 127 is negative:
    Go to next iteration of LOOP
\$\endgroup\$
1
\$\begingroup\$

Forth (gforth), 27 bytes

: f 127 32 do i emit loop ;

Try it online!

Explanation

127 32 do  \ loop from 32 to 126 (127 is not printable)
  i emit   \ get the index of the loop, then print it as its ascii representation
loop       \ end the loop       
\$\endgroup\$
1
\$\begingroup\$

Mathematica, 22 bytes

32~CharacterRange~126&

Pretty simple. & creates an anonymous function and 32~CharacterRange~126 outputs a list of characters from 32 () to 126 (~). Actually, I'm pretty sure this is optimal this time.

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

Japt -P, 5 bytes

#_odH

Test it


Explanation

#_        :95
  o       :Range [0,95)
    H     :Add 32 to each
   d      :Get the characters at those codepoints
\$\endgroup\$
1
\$\begingroup\$

PowerShell 5.1, 22 Bytes

-join[char[]](32..126)

Or 17 bytes if newlines are allowed and we can ditch the join.

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

Elixir, 24 bytes

IO.puts Enum.uniq 32..?~

Try it online!

Prints a trailing newline. If that's not acceptable, it's +1 byte for write instead of puts.

uniq is the cheapest operation I managed to find for converting range to list. As a bonus, here are 4 different programs that all accomplish the task in 27 bytes:

IO.puts Enum.to_list 32..?~
IO.puts Enum.into 32..?~,[]
IO.puts Enum.take 32..?~,95
IO.puts for n<-32..?~,do: n
\$\endgroup\$
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\$
  • \$\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 Jul 11 '16 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
\$\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\$
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\$

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.