Earlier this week, we learned about how to format esoteric languages for commenting. Today, we're going to do the inverse of that. I need you to write a program or function that parses some well-commented esoteric code and parses the comments out, returning just the code. Using some examples from the previous challenge, here is what well-commented code looks like:
a #Explanation of what 'a' does bc #Bc d #d e #Explanation of e fgh #foobar ij #hello world k #etc. l #so on mn #and op #so forth
Here is what you need to do to extract the code out. First, remove the comment character (
#), the space before it, and everything after the comment character.
a bc d e fgh ij k l mn op
Then, collapse each line upwards into a single line. For example, since
b is in the second column on line two, once we collapse it up, it will be in the second column on line one. Similarly,
c will be put in the third column of line one, and
d will be put on the fourth. Repeat this for every character, and you get this:
Important note: It seems like the trivial solution is to just remove the comments, remove every space, and join every line. This is not a valid approach! Because the original code might have spaces in it, these will get stripped out with this approach. For example, this is a perfectly valid input:
hello #Line one #Line two world! #Line three
And the corresponding output should be:
Write a program or function that takes commented code as input, and outputs or returns the code with all the comments parsed out of it. You should output the code without any trailing spaces, although one trailing newline is permissible. The comment character will always be
#, and there will always be one extra space before the comments start.
# will not appear in the comment section of the input. In order to keep the challenge simpler, here are some inputs you do not have to handle:
You can assume that the code will not have two characters in the same column. For example, this is an input that violates this rule:
a #A character in column one bc #Characters in columns one and two
You can also assume that all comment characters appear in the same column. For example, this input:
short #this is a short line long #This is a long line
violates this rule. This also means that
#will not be in the code section.
And lastly, you do not have to handle code sections with leading or trailing spaces. For example,
Hello, # World! #
You may also assume that the input only contains printable ASCII characters.
Input: hello #Line one #Line two world! #Line three Output: hello world! Input: E #This comment intentionally left blank ac # h s # ecti # on is # one c # haracte # r longer # than the # last! # Output: Each section is one character longer than the last! Input: 4 #This number is 7 8 # 15 #That last comment is wrong. 16 # 23 # 42 # Output: 4815162342 Input: Hello #Comment 1 world #Comment 2 , #Comment 3 how #Comment 4 are #Comment 5 you? #Comment 6 Output: Hello world, how are you? Input: Prepare # for... # extra spaces! # Output: Prepare for... extra spaces!
You may take input in whatever reasonable format you like, for example, a list of strings, a single string with newlines, a 2d list of characters, etc. The shortest answer in bytes wins!