17
\$\begingroup\$

Given a nonnegative integer n, your solution must output a program in your chosen language whose output has n times as many bytes as the outputted program.

Rules

  • You must specify the language and encoding of the programs your solution outputs, and you may not choose different languages or encodings for different inputs to your solution. The language of your output program may or may not be the same as the language of your solution.
  • Your submission only needs to handle integers in your language's range, but please do not abuse this rule.

This is so the shortest submission in bytes wins.

Example

Suppose n is 4. My solution then outputs f_8, a program which, in my (imaginary) language outputs j3 1s+/2]!mz. The program output has length 3 and its output has length 3 * 4 = 12, so the solution is correct for input 4.

Suppose instead that n is 1 and my program outputs ffffpfpffp (10 bytes). The program ffffpfpffp in my chosen language would have to produce an output of 10 * 1 = 10 bytes.

\$\endgroup\$
8
  • \$\begingroup\$ At the moment, this is pretty underspecified. Could you provide some examples? \$\endgroup\$
    – DJMcMayhem
    Commented Aug 22, 2017 at 1:32
  • 3
    \$\begingroup\$ I think I know what we're supposed to do, but every time I read the spec, I become less certain. output some text that has n times as many bytes as the outputted program seems to imply that we have to output a text and a program. The character set and the language must be consistent for all integers. Which "character set" is this referring to? \$\endgroup\$
    – Dennis
    Commented Aug 22, 2017 at 1:49
  • \$\begingroup\$ Nevermind, I actually did misunderstand, and so did all but one of the answers. \$\endgroup\$
    – Dennis
    Commented Aug 22, 2017 at 1:53
  • 1
    \$\begingroup\$ @Dennis It doesn't help that the title seems to contradict the body. Perhaps Output a program that outputs n times its length would be a better title, if I understand the challenge correctly (I'm not sure I do) \$\endgroup\$
    – Sisyphus
    Commented Aug 22, 2017 at 1:55
  • 1
    \$\begingroup\$ Can we take n as a string? \$\endgroup\$
    – Shaggy
    Commented Aug 22, 2017 at 11:19

19 Answers 19

7
\$\begingroup\$

JavaScript (ES6), 38 bytes

n=>`(x="${n}")=>(x+1/7+1e9).repeat(x)`

Demo

let f =

n=>`(x="${n}")=>(x+1/7+1e9).repeat(x)`

function update() {
  let n = I.value,
      func = f(n),
      res = eval(func)();
  O.innerText =
    'n = ' + n + '\n\n' +
    'Function (' + func.length + ' bytes):\n' + func + '\n\n' +
    'Function output (' + res.length + ' bytes):\n' + res;
}
update()
<input type=range id=I min=0 max=100 oninput="update()">
<pre id=O>

\$\endgroup\$
0
3
\$\begingroup\$

Cheddar, 10 9 bytes

(*)&" "*9

An awkward Proton polyglot >_<

\$\endgroup\$
1
  • 1
    \$\begingroup\$ +1 for Proton polyglot with Cheddar to show the inspiration :D \$\endgroup\$
    – hyperneutrino
    Commented Sep 18, 2017 at 16:23
3
\$\begingroup\$

Jelly, 10 bytes

;“DL+8×x@⁶

Try it online!

For input 12, it outputs 12DL+8×x@⁶, which outputs 120 spaces. Try it online!

\$\endgroup\$
3
\$\begingroup\$

brainfuck, 348 bytes

--[>+<++++++]>>--[>+<++++++]>++[-<+>]----[>+<----]>---[-<+>]----[>+<----]>-[-<+>]-[>+<---]>++++++[-<+>]-[>+<---]>++++++++[-<+>]--[>+<++++++]>+++[-<+>]<[<],[->.<]>>>>>.<<<.>>.<<<.>>>.<<<.>>>.<<<.>>...>>>.<<....<<.>>>.<<..<<.>>>..<<.......>>>>.<<<..<<.>.....>>>.<<.>>.>>.<<<<<.>>>>.<<.<<.>>.>.<<<.>>.<<<.>>...<<.>>>..>>.<<.>.<<<.>.<<.>>>.>>.<<<..>>>.

Try it online! Or see the Ungolfed version (i.e. what I had to work with)


Disclaimer

I spent more time making this than I thought was humanly possible. I'd like to thank my girlfriend for allowing me to ditch her to work on this; as well as my savior.

How does it even work?

No clue.

How does it work?

All outputs have a trailing snippet of code that are all the same:

[->+>+>+<<<]>>>>-[<<+>>-------]<<+-----[<[.-]>->[->+<<<+>>]>[-<+>]<<]

Let's split it into three parts called a,b,c

a : [->+>+>+<<<]>>>>               THE DUPLICATOR
b : -[<<+>>-------]<<+-----        THE ADJUSTER
c : [<[.-]>->[->+<<<+>>]>[-<+>]<<] THE PRINTER

The input i is simply tacked on to the front in unary:

iabc

(e.g; if the input was 10, then i = '++++++++++')

The Duplicator - Splits the input into two identical numbers m, n, equivalent to the input

The Adjuster - Adjusts n such that it equals the length of the program

The Printer - Prints m*n ASCII characters


Note that the input in the example is a newline, which as an ASCII value of 10, therefore the input is 10. If you want to test other small numbers, replace the , with however many +'s you desire.

\$\endgroup\$
2
\$\begingroup\$

Haskell, 55 bytes

f n=(++)<*>show$"main=putStr$[1.."++show n++"*2]>>'#':"

Try it online! Example usage: f 1 yields the following 54 bytes program:

main=putStr$[1..1*2]>>'#':"main=putStr$[1..1*2]>>'#':"

Try it online! which produces the following 54 byte output:

#main=putStr$[1..1*2]>>'#':#main=putStr$[1..1*2]>>'#':
\$\endgroup\$
1
\$\begingroup\$

Python 3 -> HQ9+, 11 bytes

'Q'.__mul__

It had to be done

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ Where can I test HQ? \$\endgroup\$
    – Titus
    Commented Aug 22, 2017 at 8:49
  • 1
    \$\begingroup\$ Well, Q just prints its own source code. You can test that here: hq9plus.alwaysdata.net. This was never supposed to be a serious entry \$\endgroup\$
    – michi7x7
    Commented Aug 22, 2017 at 8:52
  • \$\begingroup\$ This doesn't work. If I input 1, then you output Q, which in turn outputs Q. Q has length 1, but your code has length 11. \$\endgroup\$ Commented Sep 18, 2017 at 15:06
  • \$\begingroup\$ @NoOneIsHere 'whose output has n times as many bytes as the outputted program.' (not the submitted program) \$\endgroup\$
    – michi7x7
    Commented Sep 19, 2017 at 16:33
  • 1
    \$\begingroup\$ @NoOneIsHere this does not: almnet.de/esolang/hq9plus.php (The language specification only states "Prints the entire text of the source code file") \$\endgroup\$
    – michi7x7
    Commented Sep 19, 2017 at 16:49
1
\$\begingroup\$

Java 8, 175 174 bytes

interface M{static void main(String[]a){System.out.printf("interface M{static void main(String[]a){int i=(88+%s)*%s;for(;i-->0;System.out.print(0));}}",a[0].length(),a[0]);}}

Examples:

n=1 outputs:

interface M{static void main(String[]a){int i=(88+1)*1;for(;i-->0;System.out.print(0));}}

(length=89) which outputs 89 zeroes:

00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

n=10 outputs:

interface M{static void main(String[]a){int i=(88+2)*10;for(;i-->0;System.out.print(0));}}

(length=90) which outputs 900 zeroes:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

n=100 outputs:

interface M{static void main(String[]a){int i=(88+3)*100;for(;i-->0;System.out.print(0));}}

(length=91) which outputs 9100 zeroes:

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Explanation:

interface M{                                // Class:
  static void main(String[]a){              //  Mandatory main method
    System.out.printf("interface M{static void main(String[]a){
                                            //   Print a new program with:
      int i=(88+%s)*%s;                     //    Integer containing (88*A)+B
      for(;i-->0;System.out.print(0));}}",  //    And print that many zeroes
        a[0].length(),                      //     Where A is the length of the number
                                            //     (0-9 = 1; 10-99 = 2; 100-999 = 3; etc.)
        a[0]);}}                            //     and B is the number itself
\$\endgroup\$
0
\$\begingroup\$

RProgN 2, 7 5 bytes

«•.* 

With a trailing space

Explained

«•.* 
«    # Yield a function from the remaining string.
 •.  # Append a space and stringify, which builds the original program (Because stringifying a function removes noops, which spaces are)
   * # Repeat the implicit input times.

Try it online!

\$\endgroup\$
0
0
\$\begingroup\$

CJam, 8 13 bytes

q_,S\" 8+*S*"

Try it Online

The generated program outputs spaces so it's kind of hard to tell.

\$\endgroup\$
2
  • \$\begingroup\$ I think this is the only answer that interprets the part about outputting a program that outputs a text correctly, but the ratio is off if the input has more than one digit. \$\endgroup\$
    – Dennis
    Commented Aug 22, 2017 at 1:59
  • \$\begingroup\$ Oh yeah, duh.,, \$\endgroup\$
    – geokavel
    Commented Aug 22, 2017 at 3:32
0
\$\begingroup\$

Ly, 29 bytes

"\"9>("&onu")[<&s&ol>1-]<;"&o

Try it online! (does not work currently due to a pre-processing bug) All good!

\$\endgroup\$
0
\$\begingroup\$

Python → TECO, 20 bytes

The answer is in Python while the generated code is in TECO. The Python is a function returning VV12345\VV repeated n times. See here for an explanation of the TECO.

'VV12345\VV'.__mul__
\$\endgroup\$
0
\$\begingroup\$

PHP, 47+1 bytes

<?="<?=str_pad(_,",strlen($argn)+18,"*$argn);";

prints one underscore followed by spaces.
Run as pipe with -F; run outputted program with -f or -F.

This would fail for input with more than 64 digits,
which is far higher than PHP_INT_MAX (at this time).

However, it fails for input larger than PHP_INT_MAX-18 ... does it still qualify?

\$\endgroup\$
2
  • \$\begingroup\$ @HyperNeutrino: This will fail for input larger than PHP_INT_MAX-18. Does that disqualify? \$\endgroup\$
    – Titus
    Commented Aug 22, 2017 at 8:31
  • \$\begingroup\$ Nah, I'll say that's fine :) \$\endgroup\$
    – hyperneutrino
    Commented Aug 23, 2017 at 0:38
0
\$\begingroup\$

PHP → Python 2, 40+1 bytes

print "A"*<?=13+strlen($argn),"*",$argn;

prints a Python program that prints repeated As. Run as pipe with -F.

\$\endgroup\$
0
\$\begingroup\$

Batch → Charcoal, 22 bytes

I'm not sure which encoding I should be using, since these are bytes. Here are the bytes interpreted as Windows-1252:

@set/p=Á%1ñªÉñ«Ìñ¹<nul

The same bytes as PC-850:

@set/p=┴%1±¬╔±½╠±╣<nul

The same bytes in Charcoal's code page:

@set/p=A%1θ×Iθ⁺Lθ⁹<nul

The resulting Charcoal program is Plus(Length(Cast(n)), 9) bytes long:

A       Assign
 %1      (String representation of n)
   θ      To variable q
        Implicitly print a number of `-`s equal to:
×        Product of:
 Iθ       Cast of q to integer
 ⁺        Sum of:
  Lθ       Length of q
  ⁹        Integer constant 9
\$\endgroup\$
0
\$\begingroup\$

Recursiva, 16 15 bytes

++"*"V*15a'"*"'

Try it online!

This for input of n=2 prints:

*30"*"  

which outputs 30 *. Try it online!

\$\endgroup\$
0
\$\begingroup\$

JavaScript (ES8), 43 41 39 bytes

n=>`f=_=>"".padEnd(${n}*(88+f).length)`

Test it

The output of the generated function is a string of spaces which are replaced with *s in this Snippet.

g=
n=>`f=_=>"".padEnd(${n}*(88+f).length)`

o.innerText=(h=n=>`Function: ${x=g(n)}\nLength:   ${x.length}\nOutput:   "${x=eval(x)().replace(/./g,"*")}"\nLength:   `+x.length)(i.value=10);oninput=_=>o.innerText=h(+i.value)
<input id=i type=number><pre id=o>

\$\endgroup\$
0
\$\begingroup\$

R, 46 bytes

function(n)sprintf("cat(rep('a',%d*23),'')",n)

Try it online!

Anonymous function that returns the string

cat(rep('a',n*23),'')

Which prints a (that's a followed by a space) 23 times n times. I needed the '' because otherwise cat wouldn't print the last space character.

\$\endgroup\$
0
\$\begingroup\$

C, 94 bytes

main(int c,char**a){if(c>1){c=atoi(a[1]);if(c>0&&c<0xFFFFFF){c*=94;while(c--)printf("r");}}}

this would be 94 bytes include the last \n that stadard C says it should be written. return as 'r' characters as the (lenght of the program) * (argument of the program) if the program argument not exist or it is <=0 or it is >0xFFFFF print nothing example

C:\>nameProg.exe 1
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
\$\endgroup\$
0
\$\begingroup\$

MATLAB (63 bytes)

a=@(n)['repmat(''a'',1,',num2str(n*(15+numel(num2str(n)))),')']

For example:

>> a(5)

ans =

repmat('a',1,80)

and:

>> repmat('a',1,80)

ans =

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.