10
1
Your goal in this code golf is to take two strings, language
and code
(if the golfed code you wrote for this is multiline, then this variable would be multiline.), and one integer, bytes
. They represent the variables for a programming language, number of bytes it takes, and the code itself.
After that, you are going to format it like a code golfer does it.
The output variable is a multiline string called answer
.
You can use multiline strings on:
If you search Stack Overflow, you should be able to find more programming languages that support it.
Here is a template of the output markdown. The code
variable is in a code block, and there is a second-level header.
## {language}, {bytes} bytes
{code}
Here is what the output would look like when pasted into a Markdown parser.
{language}, {bytes} bytes
{code}
Variables are assumed to be filled out already as the language you coded your code golf entry in, the number of bytes it takes, and the actual code for it.
Here is another example of the output as code, this time with variables filled out:
## JavaScript, 1337 bytes
document.getElementById("foo").innerHTML = bar;
Here is the version as a blockquote:
JavaScript, 1337 bytes
document.getElementById("foo").innerHTML = bar;
Bytes can be taken off from your code if you use a way to set the text of a <p>
element in HTML by the id result
, like the following JavaScript code:
document.getElementById("result").innerHTML = answer;
Make sure to also include the <p id="result"></p>
in the HTML section of JSFiddle for this to work.
Scoring
Like all code-golf questions, the code that uses the least amount of bytes is the best.
1Can the header look like
# Language Name, Byte Count
instead of## Language Name, Byte Count
? – user8397947 – 2016-07-09T23:32:06.210@dorukayhan No. – haykam – 2016-07-09T23:42:50.137
3Will
{code}
ever be a multiline code? – Adnan – 2016-07-09T23:54:09.673Does our output have to exactly match yours, or does it just have to be valid mark down? – James – 2016-07-09T23:55:48.433
@DrGreenEggsandIronMan, it needs to be an exact match except the variables have to be replaced. – haykam – 2016-07-10T00:11:27.697
1Can't you use the builtin js snippet instead of JSFiddle? – None – 2016-07-10T01:29:17.583
8"Variables will be filled out as the language you coded your code golf entry in, the number of bytes it takes, and the actual code for it." Am I the only one interpreting this as a quine variation? – primo – 2016-07-10T07:34:54.717
@primo yeah, I'm actually very confused by all the current answers. E.g. the top-rated Java one seems to be assuming the existence of a variable
– Quuxplusone – 2016-07-10T08:17:25.137b
such thatb[0]=="Java" && b[1]=="70" && b[2]=="String A(String[]b){return\"## \"+b[0]+\", \"+b[1]+\" bytes\\n\\n \"+b[2];}"
, which really feels like cheating. I would have expected that the program would have to generate those outputs itself, not read them in from a magic variable.2Since the answers are solving two completely different problems, I'm putting this on hold this as unclear. Please clarify whether
language
,bytes
andcode
are input or whether this is a [tag:quine] variant where those things should match the solving code itself. (And if so, whether directly or indirectly reading that source code is allowed, and whether quine built-ins are allowed.) – Martin Ender – 2016-07-10T10:36:35.7201@MartinEnder They are inputs.
code
andlanguage
are strings, andbytes
are integers. – haykam – 2016-07-10T13:11:14.2602Could you also clarify Adnan's question whether the input
code
can itself contain linefeeds? – Martin Ender – 2016-07-10T13:13:35.0501@Adnan, yes, you can do that just like you do with the
answer
. – haykam – 2016-07-10T13:14:30.383@MartinEnder Okay, I've clarified that to them. I'm also editing the question to make sure people understand that we're assuming all the variables except
answer
will already be filled out. – haykam – 2016-07-10T13:15:55.447If {code} contains linefeeds, do we need to indent each line with four spaces, or only the first? – msh210 – 2016-07-11T15:47:45.960
@msh210 Do whatever you want. – haykam – 2016-07-11T15:49:44.367
1@Peanut You realize that in an actual PPCG answer, you'd have to indent each line for it to be formatted correctly? – mbomb007 – 2016-07-11T16:07:46.670
2@Peanut I'm confused. Can we assume
code
will not be multiline, or can't we? Please indicate that in the challenge text – Luis Mendo – 2016-07-11T16:40:22.947