18
5
Code Golf
Totally real backstory: I'm a contractor working on a website www.Sky.Net and one of our tasks it to create some self-aware program or something, I don't know I wasn't really listening to the boss. Anyways in an effort to make our code more self-aware we need IT to be able to know what code is on each line-number.
Challenge
Create a program or function that takes an input n
and returns the code of said program or function on line n
.
Rules
➊ Your program or function must be at least 4 lines long. Each line must be unique.
➋ You may assume the input will always be a positive integer greater than or equal to 1 and less than or equal to the number of lines in your program/function.
➌ The first line in your program/function is line 1, not line 0.
➍ You can not access the file that your program is on. (If someone has to ask "Isn't this technically breaking rule #4"; it probably is)
➎ Lines can-not be empty (this includes a space if spaces don't do anything in your language)
➏ Lines can-not be //comments (/* of any <!--style)
This is a quine-like challenge
This is code-golf, so the submission with the fewest bytes wins!
Let us continue this discussion in chat.
– Conor O'Brien – 2017-02-27T00:17:08.1931
I'd like to see this done in 99 :)
– Jonathan Allan – 2017-02-27T01:14:16.3372@JonathanAllan You might run into the issue where not every line is unique – MildlyMilquetoast – 2017-02-27T01:15:19.157
"Lines cannot be comments, but I guess effective no-ops are OK" (but honestly, sometimes it's hard to say whether a line should count as a no-op or not; for example my Ruby answer has the last line be only a curly bracket to end the lambda) – Value Ink – 2017-02-27T01:26:18.030
The title might be better "Input number; Output line with that line number"? Or even "Output line by number". – Paŭlo Ebermann – 2017-02-27T21:50:18.483
@PaŭloEbermann That's more accurate but I'm a minimalist – Albert Renshaw – 2017-02-27T23:16:56.430
@AlbertRenshaw the point is that the title sounds more like searching for the input number in some text and returning the line number where it is found. – Paŭlo Ebermann – 2017-02-27T23:34:17.270