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.
-
7\$\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– pxeger2022年06月29日 07:23:56 +00:00Commented Jun 29, 2022 at 7:23
-
5\$\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– mousetail2022年06月29日 07:27:07 +00:00Commented Jun 29, 2022 at 7:27
-
5\$\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– Luis Mendo2022年06月29日 12:24:02 +00:00Commented Jun 29, 2022 at 12:24
-
6\$\begingroup\$ Is a trailing space accepted, to make the last line the same length as the others? \$\endgroup\$Luis Mendo– Luis Mendo2022年06月29日 12:28:43 +00:00Commented Jun 29, 2022 at 12:28
-
2\$\begingroup\$ @LuisMendo Yes, it trivializes the question. A trailing space is OK but not necessary. \$\endgroup\$loggeek– loggeek2022年06月29日 14:24:16 +00:00Commented Jun 29, 2022 at 14:24
86 Answers 86
Python 3, 42 bytes
print(('%c'*16+'\n')*6%(*range(32,127),9))
Includes a trailing tab on the last line and a trailing newline.
-
1\$\begingroup\$
print
have another extra\n
. So it actually ends with\r\n\n
on Linux or\r\r\n\r\n
on Windows. If multiple line breaks are allowed at the ending, you may simply output triple line breaks at the end. \$\endgroup\$tsh– tsh2022年06月29日 13:41:28 +00:00Commented Jun 29, 2022 at 13:41 -
2\$\begingroup\$ Nice!
%c
is a proper game changer here. \$\endgroup\$loopy walt– loopy walt2022年06月29日 13:42:29 +00:00Commented Jun 29, 2022 at 13:42 -
1\$\begingroup\$
\n
alongside\r\n
definitely looks cheaty to me. But if I were OP which I am not I'd argue a space should be perfectly fine. If the gap weren't at the end but at the beginning or in the middle of a row one clearly would want a placeholder there. Why should the end be different? \$\endgroup\$loopy walt– loopy walt2022年06月29日 13:47:40 +00:00Commented Jun 29, 2022 at 13:47 -
1\$\begingroup\$ @loopywalt it's okay. \$\endgroup\$loggeek– loggeek2022年06月29日 14:25:33 +00:00Commented Jun 29, 2022 at 14:25
-
2\$\begingroup\$ Pretty sneaky putting a tab at the end instead of a space to save one character. \$\endgroup\$Mark Ransom– Mark Ransom2022年06月30日 03:13:38 +00:00Commented Jun 30, 2022 at 3:13
-
1\$\begingroup\$ Very clever use of slicing to vary the end-of-line character. I'd give this an upvote except somebody else has a shorter Python solution. \$\endgroup\$Mark Ransom– Mark Ransom2022年06月30日 03:19:17 +00:00Commented Jun 30, 2022 at 3:19
-
6\$\begingroup\$ @MarkRansom you can upvote any answers you find clever or interesting! \$\endgroup\$qwr– qwr2022年06月30日 17:15:35 +00:00Commented Jun 30, 2022 at 17:15
Prelude, (削除) 50 (削除ここまで) 42 bytes
88+
6(1-) v^^( 1-++!)^6-!)
1- v+(1-) v(1-
Explanation
88+
6(1-)
1- v+
Push \16ドル\$ to Voice 1 and \95ドル\$ to Voice 3.
v^^
(1-)
For each value from \95ドル\$ down to \1ドル\$, push that value and two copies of \16ドル\$ to Voice 2. When the loop ends, the stack in Voice 2 is [..., 0, 0, 0, 95, 16, 16, 94, 16, 16, ..., 1, 16, 16]
.
( 1-++! )
For each triplet of values in Voice 2, sum them and subtract \1ドル\$, then print the result as an ASCII character...
)
v(1-
in groups of 16...
^6-!
with a newline appended to each group.
Printing fails on the (non-existent) 96th character because the triplet of values summed is [0, 0, 0]
, with the result that the code attempts to convert \$-1\$ to ASCII and thus exits with an out-of-range error.
Fugue
Fugue is a musical encoding for Prelude. Fugascii*, a short trio for woodwinds, was generated from the Prelude code above using a script that I wrote for this purpose. Read all about it in this answer.
* The title is a pun on a previous Fugue composition of mine, Fugacity.
-
2\$\begingroup\$ Now I want to hear the music! \$\endgroup\$emanresu A– emanresu A2022年07月01日 07:34:40 +00:00Commented Jul 1, 2022 at 7:34
-
5\$\begingroup\$ @emanresuA I transcribed it here: t.pxeger.com/files/Fugascii.mscz. You can listen to it on YouTube (or see it on Musescore.com). It doesn't sound very good. \$\endgroup\$pxeger– pxeger2022年07月01日 07:59:43 +00:00Commented Jul 1, 2022 at 7:59
-
1\$\begingroup\$ @pxeger That's cool! I think the clarinet part needs to be transposed down a tone to sound as intended (it's not much improvement though). I wrote it at transposed rather than concert pitch, which admittedly would be more obvious if I'd put in key signatures. \$\endgroup\$Dingus– Dingus2022年07月01日 08:19:38 +00:00Commented Jul 1, 2022 at 8:19
-
\$\begingroup\$ Now I want to see a whole challenge around the idea of "best sounding solution", though popularity-contest seems to be out of fashion nowadays. \$\endgroup\$ojdo– ojdo2022年07月01日 10:07:40 +00:00Commented Jul 1, 2022 at 10:07
-
\$\begingroup\$ I was curious if this worked in bash as well: it doesn't. Bash supports range-expansions like
{A..z}
which include some non-alphanumeric characters in the expansion, but not a range starting or ending with a space or punctuation. \$\endgroup\$Peter Cordes– Peter Cordes2022年07月01日 02:01:17 +00:00Commented Jul 1, 2022 at 2:01
Piet + ascii-piet, (削除) 87 (削除ここまで) 82 bytes (×ばつ28=84 codels)
Thanks @Bubbler for -5 bytes by changing 4 dup * 2 *
to a more space efficient 8 4 *
eeeumtqcsqrrjlvuddtrjcqdjes_eeeu ?????rr?jujrnvmsjiqqc _eeuu kdvtrbbbbb???vv qq?
Might add a more detailed explanation later if I feel like to, but here's an explanation image generated by Bubbler's Piet interpreter for now. Can 100% be golfed, but I'm too lazy to do that right now lol.
Explanation image
The basic algorithm is to initially push 32
to the stack, then keep incrementing and outputting the character until 127
, after which the code stops. At each iteration, it checks if the number+1 is a multiple of 16, and prints a newline if it is.
Longer explanation
Here's the ascii piet version of the code, with newlines added for clarity:
eeeumtqcsqrrjlvuddtrjcqdjes_
eeeu ?????rr?jujrnvmsjiqqc _
eeuu kdvtrbbbbb???vv qq?
I'll be going over the code section by section.
Initialization:
eeeum
eeeu
eeuu
Push 8, Push 4, multiply. This puts 32
onto the stack (the codepoint for space)
Top half of the loop:
tqcsqrrjlvuddtrjcqdje
What it does:
Commands Stack DP, CC
dup [32,32] right left
out (char) [32] right left
1 + Dup [33,33] right left
4 dup * dup * 2 / 1 - [33,33,127] right left
- ! ! [33,1] right left
DP+ [33] down left
Basically, it adds 1
to the current codepoint and checks if it is equal to 127
. If it is, then DP+
will turn the pointer 0
times and terminate the code. Otherwise, DP+
will turn the pointer 1
time and continue the loop.
Bottom right portion of the loop:
?jujrnvmsjiqqc
???vv qq?
What it does:
Command Stack DP, CC
dup [33,33] down left
4 dup * [33,33,16] left right
% [33,1] left right
! 3 * [33,0] left right
1 CC+ [33,0] left left
DP+ [33] left right
This checks if the current codepoint is a multiple of 16 (remember that we added 1 to the codepoint in the top half of the loop). If it is a multiple of 16, then DP+
will turn the DP to face downwards. Otherwise, the DP stays facing left. This is based on the observation that all the characters before a newline all have codepoints that are 1 less than a multiple of 16.
For example, let's say that at the beginning of this portion, the stack is [48]
. This means that the ascii 47
, or /
, just got printed, and then that value was incremented by 1
from the top half of the loop. After taking this value modulo 16 and applied !
on the value, the stack becomes [48,1]
. The 1
on the stack is then multiplied by 3
which causes DP+
to turn the DP 3 times, resulting in the DP facing down.
Bottom branch of the loop:
t
?
kdvtrbbbbb
What it does:
Command Stack DP, CC
1 5 dup + [33,1,10] left right
out (char) pop [33] left right
Basically just prints out a newline.
Top branch of the loop:
t rr
?????rr?
Nothing actually happens here. The code just passes through and enters back into the loop. One thing to note is that the reason why we did CC+
earlier was to get through the r
block. Before the CC+
, the CC was facing right, but that poses a problem when we go through the r
block, because the code will continue execution through the top left of the block, which will break the entire code. Instead, we toggle the CC once to switch it to the left, which causes the code to exit out of the block from the bottom left.
Once the top half is entered again, dup out (char)
is ran, printing out another character, and the loop continues.
Loop exit:
s_
_
Once the loop reaches 127
, the loop is exited. s
is essentially a noop that does nothing, and the program terminates in the _
block.
-
\$\begingroup\$
8 4 *
(or4 8 *
) can certainly utilize the black area better. \$\endgroup\$Bubbler– Bubbler2022年07月01日 10:07:34 +00:00Commented Jul 1, 2022 at 10:07 -
\$\begingroup\$ @Bubbler Yep thanks for the suggestion, I was originally planning to do two rows so I wrote it like that, but I couldn't fit everything in. \$\endgroup\$Aiden Chow– Aiden Chow2022年07月01日 19:18:09 +00:00Commented Jul 1, 2022 at 19:18
Rust, 58 bytes
||for i in' '..''{print!("{:
<1$}",i,i as usize%16/15+1)}
Explanation
The answer is a closure expression implementing the
Fn()
trait.print!
can pad outputs to a given length:print!("{:x<5}", 'a')
→axxxx
The length can come from an argument:
print!("{:x<1$}", 'a', 5)
→axxxx
The padding char can be a raw newline in place of the
x
in this example.In my program, the length is either 1 (just the char) or 2 (char + newline).
-
\$\begingroup\$ If you remove
fn main(){
this would be shorter than mine \$\endgroup\$mousetail– mousetail2022年06月30日 12:25:21 +00:00Commented Jun 30, 2022 at 12:25 -
\$\begingroup\$ It would end up being a "snippet" I think. I can't dig up the relevant Meta link right now but we tend to expect answers to be either full programs or function definitions / lambda expressions (so
puts("Hello world!");
is not a valid C answer, butf(){puts("Hello world!");}
is). \$\endgroup\$lynn– lynn2022年06月30日 13:18:37 +00:00Commented Jun 30, 2022 at 13:18 -
\$\begingroup\$ oh, this is sort of relevant codegolf.meta.stackexchange.com/questions/2419/… \$\endgroup\$lynn– lynn2022年06月30日 13:18:50 +00:00Commented Jun 30, 2022 at 13:18
MS-DOS (.COM format), (削除) 33 (削除ここまで) (削除) 30 (削除ここまで) 26 bytes
- -3 thanks to Deadcode
- -4 by using
INT 29H
to output
Iterates through 20H and 7EH, printing each character and a line break between the 16th character of each line.
0000 B0 20 CD 29 40 3C 7F 74 10 A8 0F 75 F5 50 B0 0A
0010 CD 29 B0 0D CD 29 58 EB E9 C3
Assembly version (TASM):
IDEAL
P8086
MODEL TINY
CODESEG
ORG 100H
MAIN:
MOV AL,20H ; Start at ' '
PRINT:
INT 29H ; Print character
INC AX ; Increment character
CMP AL,7FH ; Done?
JZ DONE ; Yes, exit
TEST AL,0FH ; End of line?
JNZ PRINT ; No, next character
PUSH AX ; Save current character
MOV AL,0AH ; Print CR+LF
INT 29H
MOV AL,0DH
INT 29H
POP AX ; Restore current character
JMP PRINT ; Next character
DONE:
RET
END MAIN
ENDS
-
\$\begingroup\$ You can save 3 bytes by changing
INC DL
toINC DX
and replacing theXCHG
s withPUSH
andPOP
. \$\endgroup\$Deadcode– Deadcode2022年06月30日 06:47:09 +00:00Commented Jun 30, 2022 at 6:47 -
\$\begingroup\$ Filling a buffer and printing that is another approach; 27 bytes for that as a Linux 32-bit executable. (Perhaps less as a function). Might be possible with
xchg ax,dx
/stosw
to store a 2-byte newline. But without being sure you have some stack space above you can overwrite (which would break ret), it's less appealing. \$\endgroup\$Peter Cordes– Peter Cordes2022年07月01日 14:55:39 +00:00Commented Jul 1, 2022 at 14:55 -
\$\begingroup\$ Very cool optimization of using the undocumented INT 29h for output. It's worth noting that it prints directly to the screen and can't be redirected (unlike INT 21h.02h which uses stdout). And it really was undocumented; it's not present in my 1991 copy of The Programmer's PC Sourcebook. \$\endgroup\$Deadcode– Deadcode2022年07月02日 02:22:19 +00:00Commented Jul 2, 2022 at 2:22
-
\$\begingroup\$ @Deadcode I find that Ralf Brown's Interrupt List is pretty useful for stuff like this. \$\endgroup\$ErikF– ErikF2022年07月02日 04:50:22 +00:00Commented Jul 2, 2022 at 4:50
Python 3, 71 bytes
-2 bytes thanks to @pxeger
for i in range(6):print(''.join(chr(j+i*16+32)for j in range(16-i//5)))
Python 2, 66 bytes
for i in range(6):print bytearray(j+i*16+32for j in range(16-i/5))
Based on @mousetail's solution; submitted as my own answer by their suggestion.
Rust, (削除) 74 (削除ここまで) (削除) 72 (削除ここまで) (削除) 70 (削除ここまで) 64 bytes
(' '..'').any(|i|print!("{i}")>if i as u8%16>14{print!("
")});
Text contains non-printable characters so might not render correctly. @Antiip saved me some bytes.
-
2\$\begingroup\$ The Rust version on TIO is too old for using
char
s in ranges. You may use ATO instead, which also supports the new syntaxprint!("{i}")
. \$\endgroup\$alephalpha– alephalpha2022年06月29日 08:54:04 +00:00Commented Jun 29, 2022 at 8:54 -
1\$\begingroup\$ You can abuse
all
for -5 bytes:(' '..='~').all(|i|print!("{i}")==if(i as u8)%16>14{print!(" ")});
\$\endgroup\$AnttiP– AnttiP2022年06月29日 09:06:27 +00:00Commented Jun 29, 2022 at 9:06 -
\$\begingroup\$ You can use the official Rust Playground: bit.ly/3zzZUXZ \$\endgroup\$Eric Xue– Eric Xue2022年07月27日 23:10:38 +00:00Commented Jul 27, 2022 at 23:10
Whitespace, (削除) 110 (削除ここまで) 100 bytes
[S S S T T T T T N
_Push_31][N
S S N
_Create_Label_LOOP][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 S T N
_If_0_Jump_to_undefined_Label][S N
S _Duplicate][T N
S S _Print_as_character][S N
S _Duplicate][S S S T S S S S N
_Push_16][T S T T _Modulo][S S S T T T T N
_Push_15][T S S T _Subtract][N
T T N
_If_neg_Jump_to_Label_LOOP][S S S T S T S N
_Push_10_\n][T N
S S _Print_as_character][N
S N
N
_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 only).
Explanation in pseudo-code:
Integer n = 31
Start LOOP:
n = n + 1
If (n==127):
Stop program with error by jumping to undefined Label
Print n as character to STDOUT
If (n modulo 16 < 15):
Go to next iteration of LOOP
Print '\n'
Go to next iteration of LOOP
brainfuck, (削除) 64 (削除ここまで) 86 bytes
+++++[>++>++++++>+<<<-]>>++>+[-[>+<[->>+<<]]>>[-<<+>>]<+++++++++++++++[<<.+>>-]<<<.>>]
No longer prints 0x7f as the last character.
With many thanks to @Jiří for the fix.
-
2\$\begingroup\$ This includes 0x7F. It needs to stop at 0x7E. \$\endgroup\$Ray– Ray2022年06月29日 17:29:23 +00:00Commented Jun 29, 2022 at 17:29
-
\$\begingroup\$ Here is my way to fix it, but it comes at cost of 22 bytes:
+++++[>++>++++++>+<<<-]>>++>+[-[>+<[->>+<<]]>>[-<<+>>]<+++++++++++++++[<<.+>>-]<<<.>>]
\$\endgroup\$Jiří– Jiří2022年06月30日 00:57:56 +00:00Commented Jun 30, 2022 at 0:57 -
\$\begingroup\$ @Ray interesting point. The rules state that "The output should be exactly like shown above, but trailing whitespace is OK.". I interpret that as meaning that 0x7F being a non printable character (and therefore not affecting the display at least not on TIO) can be seen as a trailing whitespace. I'll leave it to OP to comment if I am wrong. \$\endgroup\$ElPedro– ElPedro2022年06月30日 07:37:13 +00:00Commented Jun 30, 2022 at 7:37
-
\$\begingroup\$ TIO was showing a (a character containing the hex values) for me (but stackexchange wouldn't let me include it in a comment). (And 0x00-0x19 are also (mostly) non-printable characters, but presumably nobody's printing those.) \$\endgroup\$Ray– Ray2022年06月30日 14:13:20 +00:00Commented Jun 30, 2022 at 14:13
-
2\$\begingroup\$ OP already said otherwise. See comment under question where someone is asking if the bottom corner can be DEL character (this is character 0x7F). Answer to this question was no. \$\endgroup\$Jiří– Jiří2022年06月30日 18:20:50 +00:00Commented Jun 30, 2022 at 18:20
x86-32 machine code (Linux executable) 27 bytes
cut-down NASM listing: Address | machine code | source
global _start
_start: ; Linux processes (and thus static executables) start with registers zeroed, except ESP
asciitable:
00 B020 mov al, ' '
02 B20A mov dl, 0xa
04 89E7 mov edi, esp ; space above ESP on the stack is argc, argv[] and env[] array elements, and the env strings. We overwrite that.
.loop:
06 AA stosb
07 40 inc eax ; there is no branch condition for AF, the half-carry flag :/
08 A88F test al, 0x8f ; detect mod16 and when we've gone past printable
0A 7503 jnz .nonewline
0C 92 xchg eax, edx
0D AA stosb
0E 92 xchg eax, edx
.nonewline:
; FLAGS still set from earlier TEST
0F 79F5 jns .loop ; stop at 0x80, beyond what the syscall uses
; mov [edi-1], 0xa ; no trailing newline
11 B004 mov al, 4 ; __NR_write
; ebx=0 from process startup; writing to stdin happens to work on a terminal
13 89E1 mov ecx, esp
15 8D5060 lea edx, [eax-4 + 0x7f-0x20 + 5] ; exclusive range, 5 newlines; final line does not end with newline as whitespace isn't required
18 CD80 int 0x80 ; write(0, ecx, 100)
; mov eax,1 ; exit(ebx)
; int 0x80
1A CC int3 ; abort program
Fill bytes into a buffer (overwriting stack memory above ESP, starting with argc, argv[], and into env[]). We go a bit beyond 0x7e because that makes the stop condition cheaper, but those bytes aren't printed: we have to generate an explicit length in EDX anyway, so we just omit it.
We make one write(0, buf, 100)
system call. 0
is STDIN_FD, but on a normal xterm/konsole/gnome_terminal, FD 0,1, and 2 are all read+write duplicates of the same file description. So we save 1 byte for inc ebx
. If you want to pipe the output into something to hexdump for example, ./asciitable 0>&1 | hexdump -C
Instead of existing cleanly, we use int3
to raise a debug exception, resulting in the OS delivering SIGTRAP, killing the process. A typical shell will then print Trace/breakpoint trap (core dumped)
, but that's the shell, not this program. This saves 3 bytes vs. mov al, 1
/ int 0x80
(the upper bytes of EAX are zeroed, unless write
returned an error).
I considered letting execution just fall off the end (to probably 00 00
padding added by the linker, which decodes as add [eax], al
and will segfault), but we're already stretching things a bit by only counting the .text
section of the executable, not the whole file size. (Unlike a DOS .com
, there is metadata)
Our output doesn't end with a newline; as the question says, no trailing whitespace is required after the 0x7e
~
character.
The mod16 detection via checking the low bits 4 of AL is fairly straightforward, but was borrowed from ErikF's the x86-16 MS-DOS answer which I read first before thinking about how I'd do it.
But to enable a jns
as the loop branch without a separate cmp
, we also set the MSB in our mask for test
. That's not a spot we wanted a newline anyway. I'd hoped to be able to branch on FLAGS from inc al
(2 bytes), but since we'd also need something for newlines, this is even better: we can now use inc eax
(1 byte) and still branch on the MSB of AL. Using mov dl, 0xa (2B) / xchg/stosb/xchg (1B each) instead of mov byte [edi], 0xa
(3 bytes) / inc edi
(1 byte but clobbers FLAGS) was the key to that, saving another test
or cmp
for a net saving of 1 byte.
Demo:
$ nasm -felf32 asciitable.asm
$ ld -melf_i386 -o asciitable asciitable.o
$ ./asciitable
!"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~Trace/breakpoint trap (core dumped)
$ ./asciitable 0>&1 | cat # suppresses signal diagnostic from shell
!"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~peter@volta:/tmp$
$ ./asciitable 0>&1 | hexdump -C
00000000 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'()*+,-./|
00000010 0a 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e |.0123456789:;<=>|
00000020 3f 0a 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d |?.@ABCDEFGHIJKLM|
00000030 4e 4f 0a 50 51 52 53 54 55 56 57 58 59 5a 5b 5c |NO.PQRSTUVWXYZ[\|
00000040 5d 5e 5f 0a 60 61 62 63 64 65 66 67 68 69 6a 6b |]^_.`abcdefghijk|
00000050 6c 6d 6e 6f 0a 70 71 72 73 74 75 76 77 78 79 7a |lmno.pqrstuvwxyz|
00000060 7b 7c 7d 7e |{|}~|
00000064
$ strace ./asciitable 0>/dev/null
execve("./asciitable", ["./asciitable"], 0x7ffc63d167c0 /* 55 vars */) = 0
[ Process PID=2670503 runs in 32 bit mode. ]
strace: WARNING: Proper structure decoding for this personality is not supported, please consider building strace with mpers support enabled.
write(0, " !\"#$%&'()*+,-./\n0123456789:;<=>"..., 100) = 100
--- SIGTRAP {si_signo=SIGTRAP, si_code=SI_KERNEL} ---
+++ killed by SIGTRAP (core dumped) +++
Trace/breakpoint trap (core dumped)
Try it online! with an inc ebx
added so it writes to stdout and thus shows up in the tio.run output pane. IDK why it didn't show in the debug pane. (32-bit code supported by having FASM make an executable directly, instead of NASM.)
TODO: a function instead of program, filling a buffer
We'd obviously save the syscall code, but could no longer write past the end of the actual stop point. So would need maybe 1 more byte in the loop to go back to cmp al, 0x7e
/ jne
as the loop condition.
-
\$\begingroup\$ I really wanted to do a
jns
for the loop condition as well, but with the codepoint ending at0x7E
not0x7F
that made it not really work out. \$\endgroup\$640KB– 640KB2022年07月01日 15:06:52 +00:00Commented Jul 1, 2022 at 15:06 -
\$\begingroup\$ @640KB: Yeah, that's part of why I went with filling a buffer, so I could go past the end but not print that part. Also that Linux doesn't have a putchar system call so the byte(s) have to be in memory. \$\endgroup\$Peter Cordes– Peter Cordes2022年07月01日 15:09:15 +00:00Commented Jul 1, 2022 at 15:09
-
\$\begingroup\$ I suppose I could have mine write to a buffer too and save 3 bytes by using
stosb
instead ofint 29h
. Great idea! \$\endgroup\$640KB– 640KB2022年07月01日 15:11:21 +00:00Commented Jul 1, 2022 at 15:11 -
\$\begingroup\$ @640KB: As I suggested for ErikF's DOS answer, you could
xchg
/stosw
/xchg
to store a 2-byte newline similar to how I'm doing it here. \$\endgroup\$Peter Cordes– Peter Cordes2022年07月01日 15:12:56 +00:00Commented Jul 1, 2022 at 15:12 -
\$\begingroup\$ Ha, I actually did that when I was editing my answer for the output to buffer! \$\endgroup\$640KB– 640KB2022年07月01日 15:28:00 +00:00Commented Jul 1, 2022 at 15:28
x86-16 machine code, PC DOS, (削除) 24 (削除ここまで) 19 bytes
00000000: b020 bb0a 0daa 40a8 0f75 0393 ab93 3c7e . [email protected]....<~
00000010: 7ef3 c3 ~..
Listing:
B0 20 MOV AL, 20H ; starting codepoint
BB 0D0A MOV BX, 0D0AH ; CR/LF chars
CP_LOOP:
AA STOSB ; write AL to buffer
40 INC AX ; increment to next char
A8 0F TEST AL, 0FH ; is end of line?
75 03 JNZ CP_NEXT ; jump if so
93 XCHG AX, BX ; save current codepoint
AB STOSW ; write CR/LF to buffer
93 XCHG AX, BX ; restore codepoint
CP_NEXT:
3C 7E CMP AL, 07EH ; <= 7EH?
7E F3 JLE CP_LOOP ; if so, keep looping
C3 RET ; return to caller
Using @PeterCordes's suggestion to write to an output buffer instead of direct to console.
Callable function, output to string buffer ES:[DI]
.
-
1\$\begingroup\$ You mean codepoint, not codepage, I think. (BTW, I posted a Linux x86-32 version just a few minutes after this.) \$\endgroup\$Peter Cordes– Peter Cordes2022年07月01日 14:59:15 +00:00Commented Jul 1, 2022 at 14:59
K (ngn/k), (削除) 21 (削除ここまで) 17 bytes
-4bytes thanks to Traws!
`0:`c6ドル 16#32+!95
It's my first answer in K! So there might be some optimizations ^^
`0:`c6ドル 16#32+!95
32+!95 / Creates an array from 32 to 126
6 16# / Reshapes it to 16 columns and 6 lines (16 can me replaced by 0N)
`c$ / For each elements of this array/matrix, convert the int to a char
`0: / Print the result whitout ( and "
-
1\$\begingroup\$ nice first answer. you don't need the lambda and each for the conversion, just `c$ is enough to convert the whole array. \$\endgroup\$Traws– Traws2022年07月10日 13:43:52 +00:00Commented Jul 10, 2022 at 13:43
-
\$\begingroup\$ @Traws Fixed! Thanks :D \$\endgroup\$touka– touka2022年07月10日 18:46:40 +00:00Commented Jul 10, 2022 at 18:46
05AB1E, 10 bytes
Without builtin:
3L31+çJ6ä»
With builtin (5 bytes):
žQ6ä»
Explanation:
3L # Push a list in the range [1,95]
31+ # Add 31 to each
ç # Convert the codepoint-integers to ASCII characters
J # Join the list together to a string
6ä # Split it into 6 parts
» # Join by newlines
# (after which the result is output implicitly)
žQ # Push a string of all ASCII characters
6ä» # Same as above
Burlesque, 18 bytes
@!~r@' +]16co)++un
@!~ # Push ! and ~ to stack
r@ # Range between them
' +] # Prepend " "
16co # Chunks of 16
)++ # Concat
un # Intercalate newlines between blocks and join
PowerShell Core, 35 bytes
-join(' '..'~')-split'(.{16})'-ne''
(' '..'~') # create a list of characters from <space> to ~
-join # join the list to a single string
-split'(.{16})' # split the string every 16 chars ...
-ne'' # ... and let only non-empty strings pass.
BQN, 12 bytes
6‿16⥊' '+↕95
Output has a trailing space character.
BQN's affine character space is quite neat here: adding a number to a character gives another character.
So: create a range from zero to 95 (↕95
), add it to the space character (' '+
), and reshape to 6-row, 16-column format (6‿16⥊
).
BQN, 26 bytes
@+100⥊⍉(32+⍉6‿16⥊↕95)∾6⥊10
Longer version with output string that is truly "exactly like shown above", written before the edit allowing trailing whitespace.
Creates a transposed array of character values (32+⍉6‿16⥊↕95
), appends a newline value 10 to each column (∾6⥊10
), re-transposes (⍉
) & extracts the first 100 values (100⥊
), and finally converts to characters (@+
).
V (vim), 10 bytes
¬ ~5ñ16|á
Explanation:
¬ # Insert characters between the code points...
~ # "space" and "~"
5ñ # 5 Times...
16| # Go to the 16th character on this line
á<cr> # Append a newline
Hexdump:
00000000: ac20 7e35 f131 367c e10d . ~5.16|..
sed -r
, 94 bytes
s/.*/ABCDEFGHIJKLMNO\nPQRSTUVWXYZ/
saa !"#$%\&'()*+,-./\n0123456789:;<=>?\n@&[\\]^_\n`\L&{|}~a
This is probably the best that can be done in sed, which has no functionality for ranges of characters. The main byte saving is in the fact we can generate ABCDEFGHIJKLMNOPQRSTUVWXYZ
and then use \L
to get the lowercase version.
PHP, (削除) 43 (削除ここまで) 40 bytes
<?=chunk_split(join(range(' ','~')),16);
Simply outputs the expected text, without any trailing newlines.
Just run php file.php
and it should produce the output.
Try it on: https://onlinephp.io/c/013ce
Thanks to Steffan for -3 bytes.
-
1\$\begingroup\$
join('',range(' ','~'))
can just bejoin(range(' ','~'))
for -3 bytes \$\endgroup\$naffetS– naffetS2022年08月07日 19:39:48 +00:00Commented Aug 7, 2022 at 19:39 -
\$\begingroup\$ @Steffan Totally forgot to check if the empty string was required. Thank you. \$\endgroup\$Ismael Miguel– Ismael Miguel2022年08月08日 00:02:30 +00:00Commented Aug 8, 2022 at 0:02
Vyxal 2.14.1, 9 bytes
kPð+s16ẇ⁋
So turns out kP
isn't actually all of printable ascii - it's missing the space character, and it isn't in the right order either, meaning that for the purposes of this challenge, it shouldn't be banned, as it doesn't print "the ascii table" and it isn't exactly "trivial" either.
(And if it isn't allowed, then that's grounds enough for VTCing this challenge as needs details or clarity, because "trivialising the challenge" isn't objectively defined - there's an argument to be made that kPð+s
isn't a trivial built-in).
Explained
kPð+s16ẇ⁋
kPð+ # a string of 0-9a-Z + python's string.punctuation + space
s # sorted to be in printable ascii order
16ẇ # split into parts of length 16
⁋ # joined on newlines
Vyxal, 5 bytes
kP6/⁋
Bug fixes make this 5 bytes in reality.
-
5\$\begingroup\$ It does not output the required text which has 6 lines of 16 characters each (except the final line which has 15). Changing
5
to6
does not do the trick either. \$\endgroup\$Jonathan Allan– Jonathan Allan2022年06月29日 16:35:41 +00:00Commented Jun 29, 2022 at 16:35 -
\$\begingroup\$
6/
should work, but it's so buggy.16ẇ
works, though. \$\endgroup\$naffetS– naffetS2022年06月29日 17:29:31 +00:00Commented Jun 29, 2022 at 17:29 -
\$\begingroup\$ Bugs are fixed, you can use
6/
now. \$\endgroup\$naffetS– naffetS2022年08月08日 00:14:05 +00:00Commented Aug 8, 2022 at 0:14
-
\$\begingroup\$ I think that this outputs an illegal final space. \$\endgroup\$Dominic van Essen– Dominic van Essen2022年06月29日 12:44:50 +00:00Commented Jun 29, 2022 at 12:44
-
\$\begingroup\$ @DominicvanEssen hmmm, seems so, indeed. Waiting for clarification. \$\endgroup\$pajonk– pajonk2022年06月29日 12:47:17 +00:00Commented Jun 29, 2022 at 12:47
-
\$\begingroup\$ Looks like it's Ok now... \$\endgroup\$Dominic van Essen– Dominic van Essen2022年06月29日 16:03:07 +00:00Commented Jun 29, 2022 at 16:03
APL (Dyalog Extended), 12 bytes
6 16⍴' '...'~'
' '...'~'
inclusive range from space to tilde
6 16⍴
cyclically reshape into the required number of rows and columns
-
\$\begingroup\$ I think that this outputs an illegal final space. \$\endgroup\$Dominic van Essen– Dominic van Essen2022年06月29日 12:44:01 +00:00Commented Jun 29, 2022 at 12:44
-
2\$\begingroup\$ @DominicvanEssen APL is an array language. The normal way to output multiple lines is to print an orthogonal (non-ragged) matrix, padding with spaces. Furthermore, OP has now explicitly clarified that any trailing whitespace is OK. \$\endgroup\$Adám– Adám2022年06月29日 14:35:03 +00:00Commented Jun 29, 2022 at 14:35
-
1\$\begingroup\$ looks like the OP has now allowed trailing spaces, so this is now Ok. But (as a newbie array programmer) surely it would otherwise be possible in APL to output multiple non-identically-long lines? It was do-able in BQN (see my answer), albeit with a substantially longer program... \$\endgroup\$Dominic van Essen– Dominic van Essen2022年06月29日 14:38:38 +00:00Commented Jun 29, 2022 at 14:38
-
1\$\begingroup\$ @DominicvanEssen Yes, it is possible to output multiple times, and also to output a flat character vector with line breaks in it. It just isn't the norm. \$\endgroup\$Adám– Adám2022年06月29日 14:39:47 +00:00Commented Jun 29, 2022 at 14:39
-
\$\begingroup\$ Not sure if APL has anything like J's alphabet
a.
, but perhaps this approach could be adapted:2}.8 16$a."_
? \$\endgroup\$Jonah– Jonah2022年06月29日 17:45:02 +00:00Commented Jun 29, 2022 at 17:45
MathGolf, 10 bytes
♣⌡╒T≥$y☻/n
Explanation:
♣ # Push 128
⌡ # Decrement it by 2 to 126
╒ # Pop and push a list in the range [1,126]
T # Push 31
≥ # Pop and remove the first 31 items from the list
$ # Convert each codepoint-integer to a character
y # Join the list to a string
☻ # Push 16
/ # Pop and split the string into parts of size 16
n # Join the list by newlines
# (after which the entire stack is output implicitly as result)
jq -nr
, 39 bytes
[range(32;127)]|implode|scan(".{1,16}")
The best I can do without regex is 40 bytes:
16*range(2;8)|[.+range(16-./99)]|implode
Charcoal, 12 bytes
UT⪪⪫...· ¦~ω16
Try it online! Link is to verbose version of code. Explanation:
UT
Disable automatic padding (would normally output a trailing space on the last line).
⪪⪫...· ¦~ω16
List the characters from to ~
inclusive, join them together, split into groups of 16, and implicitly print each group on its own line.
Save 6 bytes by using the builtin γ
in place of ⪫...· ¦~ω
.
Try it online! Link is to verbose version of code.
-
\$\begingroup\$ The question has since been edited to allow any trailing whitespace, in which case save 2 bytes from both programs by removing the
UT
. \$\endgroup\$Neil– Neil2022年06月29日 17:40:22 +00:00Commented Jun 29, 2022 at 17:40
Explore related questions
See similar questions with these tags.