CAPL1.5+ ; 6 without input; 10 - 10 = 0 with input
Sidenote
I have read somewhere [link?] that custom languages aren't allowed in golfing questions, as they could make built-in functions that do exactly what the question is asking, however I made CAPL to make golfing easier in general. If you think this is not allowed here, let me know!
I got some ideas from ><> and Befunge (You can move between lines and use hexadecimal characters to push numbers), some from Ruby and some from my own to make golfing easier.
CAPL reads from left to right, and goes one line down at the end of the line. If it is as the last line, the program will quit.
As no-one knows this language yet, I'll try to explain as much as possible.
Outputting y. 6 bytes
bb*.n<
bb*
b
is hexadecimal for 11
, so bb*
is 11*11
=121
, which is the UTF-8 equivalent of y
. This value is pushed to the stack.
.
Pops the top value from the stack, and outputs as UTF-8. As 121
is on top of the stack, the index is ignored here.
n
Outputs a newline
<
Sends the pointer back to the beginning of the line, thus repeating that line. As we don't expect input, we can do this safely without re-asking for the input.
Outputting from input. 10 bytes, 0 after bonus
i~a&{X:.)}
i
Takes input from the user, pushes as UTF-8 on the top of the stack, and pushes the length after that. I.e. [72,101,108,108,111,5]
~
Pops a number from the stack, then reverses that amount of bytes. I.e. [111,108,108,101,72]
a
Hexadecimal for 10
, the newline character
&{...}
Makes an infinite loop. We have input, so we can't send the pointer back to the line. I could place the function on the line below, which would safe me a byte, but newlines aren't allowed in this challenge.
X
Removes the top value from the stack (The index from the loop)
:.
Duplicates the top value, then outputs as UTF-8
)
Turns stack right. ([1,2,3,4,5]
-> [5,1,2,3,4]
)
Howver, this means we start with a newline, then start outputting the input, then a newline, then the input, etc. If we're not allowed to start with a newline, use the following code with 12 bytes, or 2 after subtracting the bonus.
iXa#~&{X:.)}
The only new command here is #
, which pushes the amount of items on the stack to the stack.
I removed the length from i
, because adding 1, then swapping with the newline is longer than removing and getting the length again.
Just for fun, here is a "Hello World" program
"Hello World"#~
#?!;.<
The ?!
operation is the same as ><>'s
y
or\n
inside of a string literal"? \$\endgroup\$true.c
is 80 lines long. \$\endgroup\$yes
takes an optional argument on the command line, notstdin
. \$\endgroup\$y
s yourself. \$\endgroup\$