You must write a program or function that, when given a nonempty string S of N printable ASCII characters†, outputs a program that will exit with exit code C, where C is the ASCII codepoint at position 0 in S. This program you write will additionally output a program P, such that, when run, it exits with exit code C′, where C′ is the ASCII codepoint at position 1 in S. Program P will output another program P′. This process repeats until there are no characters left in S. After this is done, you must output nothing, followed by an optional newline; and should exit with exit code 0.
†The characters between 0x20
and 0x7e
inclusive.
Some more rules:
- Self-modifying programs are not allowed: you must output the source to STDOUT (or, return value initially)
- You may not read your own source code.
The shortest such program in bytes will win.
For some rudimentary testing, this ruby script can be used. (The first argument is the way you invoke the script, the second is the program, and the third is the input string.)
Hypothetical Example
Say the program is FOO
. When given the string "ABC", it outputs BARA
. This program exits with code 65
and outputs BARB
. This in turn exits with code 66
and ouputs BARC
. This program exits with code 67
and outputs BAR!
. This outputs nothing, and exits with code 0
.
0
is Success. tio.run/nexus/… \$\endgroup\$33 throw
to throw an arbitrary number. You use negatives for OS-level, and the offset is -512. Idk much either, but I'm looking here: complang.tuwien.ac.at/forth/gforth/Docs-html/… \$\endgroup\$