Help: Aliens Programmers only speak ASCII
Pyth, 17 13 bytes
Another one of those Pyth programmers. Sorry.
The new code requires each line to be wrapped in quotes and escaped (including newlines if you desire them to be printed), but puts an extra newline between the line and the ASCII.
jjLC9smCMBd.Q
Try it online!
Explanation:
.Q Evaluate all input lines
m For each of those lines:
Bd Return the line and
CM the line mapped to ASCII characters
s Sum all these together to begin alternating between line and mapped line
jLC9 Join all the characters and numbers in the lines and mapped lines on tabs
j And join all of those on newlines
I'm keeping the old code and its' explanation below.
#Jw
jKC9J
jK+CMJT
Try it online! or use an easier-to-read test case.
Explanation:
# Until we run into an error:
Jw Read in the next line of input and call it J.
(When there is no line of input, error is thrown that ends program.)
j Join:
J all characters in input line
KC9 and insert tab characters (C9), which we can refer to later as K.
(Setting it to a variable doesn't save or lose bytes.)
Implicit print that join with trailing newline.
j Join:
CMJ the mapping of ASCII numbers to characters in the input,
K inserting tab characters in between every number
+ T And with a trailing 10 for the newline at the end.
Vim, 86, 77 keystrokes
:g/^/norm A<C-v><C-v>10<C-v><esc>Yp:s/./\=char2nr(submatch(0))."\t"/g<C-v><cr>k:s/./&\t/g<C-v><cr>
:%s/<C-v><cr>0<cr>
This is way too long, but that's what you get when you use vim's eval
feature (\=
).
Python 2, 105 bytes
This uses a slightly different approach than the OP's answer. Note that SO messes up my literal tabs with spaces.
def f(s):
o=x=''
for c in s:
o+=c+" ";x+="%s "%ord(c)
if"\n"==c:print o[:-1],x;o=x=''
print o+"\n"+x
Try it online