24
\$\begingroup\$

Goal

You have to print the ASCII printable characters' code page (0x20-0x7E). The output should look like this:

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

Rules

  • The output should be exactly like shown above, but trailing whitespace is OK.
  • No builtins that trivialize the question (e.g. the ones that print the ASCII table) ! They can be posted for documentation purposes, but will not be in the leaderboards.
  • Standard rules for I/O and loopholes apply.
  • Lowest bytecount wins.

Good Luck!

P.S. This challenge is well-known, but a straight "print every single printable ASCII character" has somehow never been done here.

\$\endgroup\$
17
  • 6
    \$\begingroup\$ Could you clarify exactly what you mean by "No builtins"? No builtins if they return exactly that output? No builtins that return any kind of ASCII table? No builtins at all (which would make this impossible in most languages)? \$\endgroup\$
    – pxeger
    Jun 29 at 7:23
  • 4
    \$\begingroup\$ Many built-ins for the ascii table seem to include characters like the line break and tab so I think they wouldn't work anyways. \$\endgroup\$
    – mousetail
    Jun 29 at 7:27
  • 4
    \$\begingroup\$ trivialize the question is not objectively defined. If a builtin outputs the string of ASCII codes (not formatted as a table), does that trivialize the question? If it outputs an ASCII table with a different format? \$\endgroup\$
    – Luis Mendo
    Jun 29 at 12:24
  • 5
    \$\begingroup\$ Is a trailing space accepted, to make the last line the same length as the others? \$\endgroup\$
    – Luis Mendo
    Jun 29 at 12:28
  • 2
    \$\begingroup\$ @LuisMendo Yes, it trivializes the question. A trailing space is OK but not necessary. \$\endgroup\$
    – loggeek
    Jun 29 at 14:24

67 Answers 67

1 2
3
0
\$\begingroup\$

The Waterfall Model (with output extension), 166 bytes

[[30000,7,7,7,7,7,7,7],[3,2,2,0,0,0,7,0],[2,2,2,0,0,0,3,0],[1,0,2,300,0,0,0,0],[66,2,0,0,302,0,9,0],[4822,2,0,0,300,5100,9,0],[9,0,0,0,0,0,1,0],[29998,0,0,0,0,0,0,0]]

Try it online!

$$ \begin{array}{c|c|ccccccc} &start&A&B&α&β&γ&out&halt\\\hline A&3&2&2&&&&7&\\ B&2&2&2&&&&3&\\ α&1&&2&300&&&&\\ β&66&2&&&302&&9&\\ γ&4822&&&&300&5100&9&\\ out&9&&&&&&1&\\ halt&29998&&&&&&& \end{array} $$

  • A and B each (upon zeroing) add 2 to both of them, and stay 1 apart. This means one of them will be zeroing every 2 steps, and externally adding 2 to that one will switch it to the other one.
  • α and β cause switches to A and to B, respectively. β has a period 2 longer than α, so the time between α and β increases by 2 each cycle, and thus the number of times A zeroes increases by 1 each cycle.
  • A increments the output counter and β causes it to be output as a character and reset to 0, thus outputting an increasing sequence of characters. B increases the output waterclock by a non-output-affecting value of 3 to keep it away from zero.
  • γ first zeroes after the 17th zeroing of α and 10 following zeroings of A. It causes output as a character, for a line feed (ASCII 10), and increases β by 302 – equal to α's period rather than 2 greater – so that the difference between α and β does not change for this cycle.
    γ has a period 17 times that of α, to add a line feed after every 16 other characters.
  • The halt waterclock is never incremented, and simply counts down and ends the program after 100 characters (95 printable characters and 5 line feeds).
\$\endgroup\$
0
\$\begingroup\$

GolfScript, 21 bytes

96,{[32+]}[/]''*16/n*

Try it online!

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

Dyalog APL, 16 bytes

⎕UCS 6 16⍴31+⍳95
\$\endgroup\$
0
\$\begingroup\$

Befunge-93, 36 bytes

" ">:,1+:"~"1+\`v
   ^            _@

Try it online!

I don't know if i can optimize this code even further than i did.

An explanation

This code is comprised of 5 main parts:

  • " ": Push 0x20 onto the stack.
  • :,: Output the current character.
  • -1: Increment the current character.
  • :"~"1+`: Compare the current character with 0x7e.
  • _@: If current character is greater than 0x7e, end the program; else loop back to the start with ^.
\$\endgroup\$
0
\$\begingroup\$

Kotlin, 89 73 bytes

print((' '..'~').chunked(16).map{it.joinToString("")}.joinToString("\n"))

Kotlin Playground

Edits

  • -16, inlined conversion to Char
\$\endgroup\$
0
\$\begingroup\$

Knight, 31 bytes

;=a 32W>127aO+AaI%=a+1a 16"\"""

Try it online!

Unminified:

; = a 32
: WHILE (> 127 a)
    : OUTPUT (+ (ASCII a) (IF (% (= a (+ 1 a)) 16) "\" ""))
\$\endgroup\$
0
\$\begingroup\$

Japt -R, 9 bytes

#_odH ¬òG

Test it

\$\endgroup\$
1 2
3

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.