Code golf for the lazy

Java, 70 bytes

String A(String[]b){return"## "+b[0]+", "+b[1]+" bytes\n\n    "+b[2];}

Assumes b[0] is the language name, b[1] is the byte count, and b[2] is the code.

Making it compilable costs 9 bytes, resulting in a 79-byte non-standalone program:

class a{String A(String[]b){return"## "+b[0]+", "+b[1]+" bytes\n\n    "+b[2];}}

The equivalent monolithic program is 103 bytes long:

interface a{static void main(String[]A){System.out.print("## "+A[0]+", "+A[1]+" bytes\n\n    "+A[2]);}}

The monolithic one works with command line arguments, assuming these just like the non-standalone program:

  • First argument is the language name
  • Second argument is the byte count
  • Third argument is the code

Java (lambda expression), 56 48 bytes

(b)->"## "+b[0]+", "+b[1]+" bytes\n\n    "+b[2];

This is a java.util.function.Function<String[], String>.


None of these programs/functions handle multiline strings. To do so, simply replace b[2] and A[2] with b[2].replace("\n","\n ") and A[2].replace("\n","\n ") - doing so adds 23 bytes.


V, 24 bytes

Note that there is a trailing space at the end.

This program makes the assumption that {code} will not be on multiple lines.

Op has clarified, "code" may be a multiline string. This 24 byte version works:

2é#á $á,JA bytes
vGî4é 

Since this contains an unprintable character, here is the readable version:

2é#á $á,JA bytes
<esc>vGî4é<space>

Where <esc> is the literal escape character, e.g. 0x1B.


JavaScript (ES6), 56 bytes

(l,b,c)=>`## ${l}, ${b} bytes

`+c.replace(/^/gm,`    `)

Also, for laughs, here is an answer that formats itself for me:

JavaScript (ES6), 68 bytes

f=_=>`## JavaScript (ES6), ${`${f}`.length+3} bytes\n\n    f=${f};`;

Print the result of f().