23
\$\begingroup\$

Inspired by this blog post.

Write a program that outputs 99 distinct programs (in the same language) that output the string I love you.

How the programs are separated from one another in the output will be defined by you. However, Each byte of output can only belong to at most 1 of the 99 programs.

Constraints for Output Programs

  1. If any string of characters is removed, then the program must not output I love you.
    e.g. console.log('I love you');;; is invalid because ;;; can be removed
  2. If any two strings of characters are both removed, then the program must not output I love you. This is to prevent inconsequential application of pairs of characters, that pass rule 1 because removing any single string will break the program.
    e.g. print((('I love you'))) is invalid, because (( and )) can be removed

There will be two categories of scoring to participate in.

  1. Standard code golf—smallest source code wins
  2. Combined code golf—smallest source code + output wins

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 198052; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/<a/.test(lang)) lang = jQuery(lang).text();
    
    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>
<div id="language-list">
  <h2>Winners by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>

\$\endgroup\$
  • 3
    \$\begingroup\$ Does the code have to be pristine (there is no way to produce the same result by removing any number of characters) or just following the constraints you mentioned? e.g. from Benji's program: would print(chr(207%134)) ... be allowed even if taking out 20, %1, and 4 would result in print(chr(73)) ... which yields the same result? \$\endgroup\$ – Zimonze Jan 16 at 2:44
  • 11
    \$\begingroup\$ There must not exist a string of characters that, when removed, does not lead to Could that be rephrased to remove the two negations? I find it very confusing \$\endgroup\$ – Luis Mendo Jan 16 at 7:33
  • 10
    \$\begingroup\$ These double negatives are killing my chance at understanding this question. Could this be reworded without the double negatives? \$\endgroup\$ – ouflak Jan 16 at 9:15
  • 7
    \$\begingroup\$ Perhaps try: "Your solution must fail to output I love you if you remove any one or two strings of characters. Removal of 3 or more strings of characters is not required to fail.". Then just copy the two examples. \$\endgroup\$ – Zizy Archer Jan 16 at 9:58
  • 3
    \$\begingroup\$ I don't understand the rule However, Each byte of output can only belong to at most 1 of the 99 programs.. Can you clarify what you mean by that? \$\endgroup\$ – AdmBorkBork Jan 16 at 13:48

19 Answers 19

18
\$\begingroup\$

JavaScript (JavaScript shell), 65 bytes

total: (64 + 3366 = 3450) bytes

for(i=99;i++<198;)print(`\\u0${i}="I love you";print(\\u{${i}})`)
\u0100="I love you";print(\u{100})
\u0101="I love you";print(\u{101})
\u0102="I love you";print(\u{102})
\u0103="I love you";print(\u{103})
\u0104="I love you";print(\u{104})
\u0105="I love you";print(\u{105})

It is trivial.

JavaScript allow escape sequence in variable name. console.lo\u0067('Hello world') is prefect valid. I don't think this feature is useful anyway. But...

No TIO link, since the TIO version is out-of-date. You may download JavaScript Shell from https://archive.mozilla.org/pub/firefox/releases/72.0.1/jsshell/ .


JavaScript (SpiderMonkey), 76 bytes

total: (76 + 2475 = 2551) bytes

for(i=99;i++<198;print(v+'="I love you";print('+v+')'))v=eval('"\\u0'+i+'"')

Try it online!

Output:

Ā="I love you";print(Ā)
ā="I love you";print(ā)
Ă="I love you";print(Ă)
ă="I love you";print(ă)
Ą="I love you";print(Ą)
ą="I love you";print(ą)

This one is shorter when counting total length. And it is much more trivial.


JavaScript (SpiderMonkey), 85 bytes

total: (86 + 36927 = 37013) bytes

for(n=99,p="(L='I love you')=>",q="print(L)";n--;p+='x=>')p='('+p,q+=')()',print(p+q)

Try it online!

Output:

((L='I love you')=>print(L))()
(((L='I love you')=>x=>print(L))())()
((((L='I love you')=>x=>x=>print(L))())())()
(((((L='I love you')=>x=>x=>x=>print(L))())())())()
((((((L='I love you')=>x=>x=>x=>x=>print(L))())())())())()

This is my original solution.

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ TIL SpiderMonkey has a print function \$\endgroup\$ – Mason Jan 16 at 8:26
  • \$\begingroup\$ What's wrong with this 56 byter \$\endgroup\$ – Expired Data Jan 16 at 14:12
  • 1
    \$\begingroup\$ @ExpiredData _XY="I love you";print(_XY) can be reduced to _X="I love you";print(_X). \$\endgroup\$ – Arnauld Jan 16 at 14:49
  • 2
    \$\begingroup\$ What I meant is that the output programs are not pristine because the \ can be removed (e.g. u0100="I love you";print(u0100)). \$\endgroup\$ – Arnauld Jan 17 at 1:37
  • 1
    \$\begingroup\$ @Arnauld Ah, nice catch. Fixed by +1 byte (and switching to newer version. \$\endgroup\$ – tsh Jan 17 at 1:58
9
\$\begingroup\$

Whitespace, 718 bytes, score: 34180 (33462+718)

[S S S T    N
_Push_1][S S S N
_Push_n=0][T    T   S _Store_1:n][N
S S S N
_Create_Label_LOOP][S S S T N
_Push_1][S N
S _Dupe_1][T    T   T   _Retrieve_1:n][T    S S S _Add][S N
S _Dupe_n+1][S S S T    T   S S T   S S N
_Push_100][T    S S T   _Subtract][N
T   S T T   N
_If_0_Jump_to_Label_EXIT_WITH_PRINT][S S S T    N
_Push_1][S N
T   _Swap][T    T   S _Store_1:n+1][S S S T N
_Push_1_newline][S N
S _Dupe_1_newline][S S S T  S T T   T   N
_Push_23_space][S S S T N
_Push_1_newline][S T    S S T   N
_Copy_0-based_1st_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S S S N
_Push_0_tab][S T    S S T   S N
_Copy_0-based_2nd_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][S S S N
_Push_0_tab][S T    S S T   N
_Copy_0-based_1st_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][S S S N
_Push_0_tab][N
S T N
_Call_Subroutine_PUSH_INTEGER][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S N
S _Dupe_0_tab][N
S T N
_Call_Subroutine_PUSH_INTEGER][S S S T  N
_Push_1_newline][S S S T    S T T   T   N
_Push_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S N
S _Dupe_1_newline][S T  S S T   S N
_Copy_0-based_2nd_23_space][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S T  S S T   S N
_Copy_0-based_2nd_23_space][S N
S _Dupe_23_space][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S T  S S T   S N
_Copy_0-based_2nd_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S T    S S T   N
_Copy_0-based_1st_23_space][S N
S _Dupe_23_space][S S S N
_Push_0_tab][S T    S S T   N
_Copy_0-based_1st_23_space][S N
S _Dupe_23_space][S S S N
_Push_0_tab][S T    S S T   N
_Copy_0-based_1st_23_space][S S S T N
_Push_1_newline][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S N
S _Dupe_0_tab][S T  S S T   S S N
_Copy_0-based_4th_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S T    S S T   N
_Copy_0-based_1st_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S N
S _Dupe_0_tab][S T  S S T   S S N
_Copy_0-based_4th_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S T    S S T   N
_Copy_0-based_1st_23_space][S S S N
_Push_0_tab][S T    S S T   N
_Copy_0-based_1st_23_space][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S T  S S T   S N
_Copy_0-based_2nd_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S N
S _Dupe_0_tab][S N
S _Dupe_0_tab][S T  S S T   S T N
_Copy_0-based_5th_23_space][S N
S _Dupe_23_space][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S T  S S T   S N
_Copy_0-based_2nd_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S T    S S T   N
_Copy_0-based_1st_23_space][S S S N
_Push_0_tab][S T    S S T   N
_Copy_0-based_1st_23_space][S S S N
_Push_0_tab][S T    S S T   N
_Copy_0-based_1st_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S T    S S T   N
_Copy_0-based_1st_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][S S S T   N
_Push_1_newline][S T    S S T   N
_Copy_0-based_1st_23_space][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S T  S S T   S N
_Copy_0-based_2nd_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S N
S _Dupe_0_tab][S T  S S T   T   N
_Copy_0-based_3rd_23_space][S N
S _Dupe_23_space][S S S N
_Push_0_tab][N
S T N
_Call_Subroutine_PUSH_INTEGER][S S S T  N
_Push_1_newline][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S N
S _Dupe_0_tab][S N
S _Dupe_0_tab][S S S T  S T T   T   N
_Push_23_space][S S S N
_Push_0_tab][S N
S _Dupe_0_tab][S T  S S T   S N
_Copy_0-based_2nd_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][N
S T N
_Call_Subroutine_PUSH_INTEGER][N
S N
S N
_Jump_to_Label_LOOP][N
S S T   T   N
_Create_Label_EXIT_WITH_PRINT][S N
N
_Discard_n][N
S S T   N
_Create_Label_PRINT_LOOP][S S S T   S S T   N
_Push_9][T  S S S _Add][T   N
S S _Print_as_character][N
S N
T   N
_Jump_to_Label_PRINT_LOOP][N
S S N
_Create_Subroutine_PUSH_INTEGER][S S S T    N
_Push_1_newline][S S S N
_Push_0][S S S T    N
_Push_1][T  T   T   _Retrieve_1:n][T    T   S _Store_0:m][N
S S S S N
_Create_Label_TAB_LOOP][S S S N
_Push_0_tab][S N
S _Dupe_0][S N
S _Dupe_0][T    T   T   _Retrieve_0:m][S S S T  N
_Push_1][T  S S T   _Subtract][S N
S _Dupe_m-1][N
T   S S T   N
_If_0_Jump_to_Label_DONE_WITH_TAB_LOOP][T   T   S _Store_0:m-1][N
S N
S S N
_Jump_to_Label_TAB_LOOP][N
S S S T N
_Create_Label_DONE_WITH_TAB_LOOP][S S S T   S T T   T   N
_Push_23_space][S N
S _Dupe_23_space][S N
S _Dupe_23_space][N
T   N
_Return_from_Subroutine_PUSH_INTEGER]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

The output Whitespace programs are output without delimiter. Each program will be as follows, where the x is variable in the range [3,102].

[S S S (x_amount_of_T   )N
_Push_n][S S S T    T   S T T   T   T   N
_Push_constant_111][S S S (x_amount_of_T    )N
_Push_n][T  S S T   ][T T   S _store][S S S T   T   S N
_Push_6_u][S S S N
_Push_0_o][S S S T  S T S N
_Push_10_y][S S T   T   S S T   T   T   T   N
_Push_-79_space][S S T  T   S T S N
_Push_-10_e][S S S T    T   T   N
_Push_7_v][S S S N
_Push_0_o][S S T    T   T   N
_Push_-3_l][S T S S T   S S N
_Copy_0-based_4th_-79_space][S S T  T   S S T   T   S N
_Push_-38_I][N
S S N
_Create_Label_LOOP][S S S (x_amount_of_T    )N
_Push_n][T  T   T   _Retrieve][S S S (x_amount_of_T )N
_Push_n][T  S S S _Add][T   S S S _Add][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

In the 1st program, x will be 3, so the four Push n parts will push the integer 7 (binary 111; three 1-bits); in the 15th program, x will be 18, so the four Push n parts will push the integer 262143 (binary 111111111111111111; eighteen 1-bits); etc. up to 5070602400912917605986812821503 (binary with 102 1-bits).

Try it online for the 15th program (with raw spaces, tabs and new-lines only).

I've used this Whitespace tip of mine to print the output I love you. The optimal constant 111 is generated by this Java program. In addition, I use one copy for the space to save bytes.

I've also used this same tip with a constant 9 in the generator program to output the Whitespace sub-programs. After that I've used loads of duplicates, as well as copies for the spaces where possible.

Explanation in pseudo-code:

Generator program:

Store n=0 at heap-address 1
Start LOOP:
  Retrieve n from heap-address 1
  n = n + 1
  If(n == 100):
    Call function EXIT_WITH_PRINT
  Store the updated n+1 at heap-address 1
  Push the codepoints of "NNSNSSNTSSSTSSST" minus 9 for the output program
  Call subroutine PUSH_INTEGER
  Push the codepoints of "TTT" minus 9 for the output program
  Call subroutine PUSH_INTEGER
  Push the codepoints of "NSSNNSTTSSTTSSNSSTSSTSNTTTSSNSSSNTTTSSSNSTSTTSSNTTTTSSTTSSNSTSTSSSNSSSNSTTSSSSTTTSST" minus 9 for the output program
  Call subroutine PUSH_INTEGER
  Push the codepoints of "NTTTTSTTSSS" minus 9 for the output program
  Call subroutine PUSH_INTEGER
  Go to the next iteration of LOOP

Function EXIT_WITH_PRINT:
  Discard n that was still on the top of the stack
  Start PRINT_LOOP:
    Add 9 to the value at the top of the stack
    Pop and print it as character
    (this will fail with an error since there is nothing more to pop, when we're done with
     the final character to stop the program)
    Go to the next iteration of PRINT_LOOP

Subroutine PUSH_INTEGER:
  Push the codepoint of "N" minus 9 for the output program
  Retrieve n from heap-address 1
  Integer m = n
  Store m at heap-address 0
  Start TAB_LOOP:
    Push the codepoint of "T" minus 9 for the output program
    Retrieve m from heap-address 0
    m = m - 1
    If(m == 0):
      Call function DONE_WITH_TAB_LOOP
    Store m-1 at heap-address 0
    Go to next iteration of TAB_LOOP

  Function DONE_WITH_TAB_LOOP:
    Push the codepoints of "SSS" minus 9 for the output program
    Return to the caller of the PUSH_INTEGER subroutine, and continue from there

Sub-program:

Variable as explained before is integer n (which has x amount of binary 1-bits).

Integer t = 111 - n
Store t at heap-address n
Push the codepoints of "uoy evol I" minus 111
Start LOOP:
  Retrieve t from heap-address n
  t = t + n
  Add t (which is 111 again) to the value at the top of the stack
    Pop and print it as character
    (this will fail with an error since there is nothing more to pop, when we're done with
     the final character to stop the program)
    Go to the next iteration of LOOP

Since we use the variable n four times (t = 111-n; store t at heap-address n; retrieve t from heap-address n; t = t+n) with other pieces of relevant code in between the pushes, we need to remove four string-sequences in order to still have a valid I love you output, complying to the rule stating you can't remove one or two string-sequences.

|improve this answer|||||
\$\endgroup\$
7
\$\begingroup\$

JavaScript (Node.js), 81 bytes

Output: 4275 bytes

for(n=100;--n;)console.log(`console.log('I lo'+Buffer([${n}^${118^n}])+'e you')`)

Try it online!

|improve this answer|||||
\$\endgroup\$
6
\$\begingroup\$

Batch, 131 + 3564 bytes

@for %%a in (a b c d e f g h i j k)do @for %%b in (. / \ "," ";" [ ] + "=")do @echo @for %%%%%%a in (love)do @echo%%~bI %%%%%%a you

This produces 99 variants of the same code:

@for %%k in (love)do @echo=I %%k you

The for variable (here k) loops over the 11 values a to k, while the other character that changes is the separator after echo, which can usually (as here) be any of 11 characters, but five of them need quoting to use in a for command, so I've omitted space and (. The programs are all irreducible because they need to get the word love to appear in the output.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ ? @for /L %k in (1 1 99) do @echo @set a%k=I love you^&^&echo %a%k% \$\endgroup\$ – mazzy Jan 18 at 20:03
  • \$\begingroup\$ @mazzy That doesn't produce irreducible programs. \$\endgroup\$ – Neil Jan 18 at 21:22
  • 1
    \$\begingroup\$ @mazzy Additionally, the programs don't even work since variable expansion happens at parse time by default. \$\endgroup\$ – Neil Jan 18 at 21:23
5
\$\begingroup\$

C (clang), 87 \$\cdots\$ 160 120 bytes

Output: 3822 bytes (Total: 3942 bytes)

i;main(j){for(;i<99;printf("main(){printf(\"%%c Love You\",%d^%d);}\n",j,j^73))j=3+i++*4,j=strchr("$,2MOPW]_",i)?6*j:j;}

Try it online!

Fixed pristine-errors kindly pointed out by Expired Data.
Fixed pristine-errors kindly pointed out by Kaddath.
Saved 50 bytes thanks to gastropner!!!

Prints 99 unique lines like:

main(){printf("%c Love You",3^74);}
|improve this answer|||||
\$\endgroup\$
5
\$\begingroup\$

Python 3, 86 bytes

86 code + 10289 output = 10375 total

x=0
while x<99:print(f"print(chr(len('{(bin(x)[2:8]).zfill(73)}'))+' love you')");x+=1

sample segment of output: print(chr(len('0000000000000000000000000000000000000000000000000000000000000000000110000'))+' Love you')

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ @Arnauld It does... I'll see if I can fix that \$\endgroup\$ – Benji Jan 16 at 2:32
  • \$\begingroup\$ You might want to look carefully at the first line of your sample segment of output... There are two strings which can be removed to leave 73 in the char(). \$\endgroup\$ – Zimonze Jan 16 at 3:34
  • 2
    \$\begingroup\$ There is also 100-90 which can be simply 10. \$\endgroup\$ – Bubbler Jan 16 at 3:42
  • \$\begingroup\$ I think I have finally made it so that if any character(s) are removed, it will break.(I'm new to code-golf, so thanks for the help) \$\endgroup\$ – Benji Jan 16 at 14:04
  • 1
    \$\begingroup\$ This currently outputs only 98 programs. Suggested 77-byte version, with a shorter output. \$\endgroup\$ – Arnauld Jan 16 at 14:58
4
\$\begingroup\$

PHP, 96 bytes

Output: 2516 bytes (total 2612)

<?php for(;($i+=2)<773;)if($i<99||--$i%100>67&&$i>299)echo"I<?=chr(".(33+$i++)."-$i)?>love you";

Try it online!

Example program:

I<?=chr(35-3)?>love you

Still quite new at code golf, hope I get this right. Wanted to encode the space as 32 is the lowest number and wanted to do something else than port an existing answer. Got me into troubles with the 2 strings removing part, but I think this time it passes

(Edit: one line was missing, programs count was 98) (Edit2: separator is now :, as - was in the code, and total count was wrong)

Edit3: This time I think it's OK (got much more complicated than planned):

  • I had to remove all the intervals of the form x99-x67 that can be reduced by removing the x's
  • Had also to remove all the interval of the form 3xx-2xx that can be reduced by removing the xx- and xx
  • Tried to keep only --$i%100>67&&$i>299 as a condition but unfortunately it goes to 1003-971 and a bit beyond that all can be reduced to the form 103-71
  • new code is manupulating $i with -- and ++ to avoid to add prenthesis and do ($i-1)%100>67 in test and "-".($i-1).") in display
  • no separator anymore, as per a question's comment
  • removed the space after echo (thanks to @Ismael Miguel answer)
|improve this answer|||||
\$\endgroup\$
4
\$\begingroup\$

05AB1E, 23 bytes (combined score 1688 bytes)

тGN"•«À¢ÒÙΓʒγ•"тN-…O₃BJ

Try it online! or try one of the output programs.

тG                       # for N from 1 to 99:
  N                      #  N
   "•«À¢ÒÙΓʒγ•"          #  string "•«À¢ÒÙΓʒγ•"
               тN-       #  100 - N
                  …O₃B   #  "O₃B"
                      J  #  join the entire stack

Each subprogram looks like:

1                       # 1 (N)
 •«À¢ÒÙΓʒγ•             # compressed integer 11971423964735158206
           99           # 99 (100 - N)
             O          # sum the entire stack
              ₃B        # convert to base 95
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ @downvoter care to explain what's wrong with this answer? \$\endgroup\$ – Grimmy Jan 20 at 17:05
3
\$\begingroup\$

05AB1E, 34 31 30 28 25 bytes

Combined Score: very very big (25 + no. permutations of "I love you"*20)

-3 bytes thanks to @KevinCruijssen

…I„΀v'"y'""œ{•B‹<•è"J

Try it online!


Optimised for Combined Score

05AB1E, 32 30 27 bytes

Combined Score: 27 + 1980 = 2007

…I„΀îœт£¦v'"y'""œ{•B‹<•è"J

Try it online!

This may take a while to run...


Explanation

…I„Î€î                       # Compressed string "I love you" 
      œ                      # Get the permutations of this string 
       ¦                     # Remove the first one ("I love you")
        v                    # loop over these and do...
         '"y'"               # the string with the value in (e.g. "I love yuo"
              "œ{•B‹<•è"     # string literal with œ{•B‹<•è value
                        J    # join these and print e.g. "I love yuo"œ{•B‹<•è

Explanation of the output programs:

"I love yuo"                   # a string which is a permutation of "I love you"
            œ{                 # get the sorted permutations of this string 
              •B‹<•è           # get the value at index 750832 which is "I love you"
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ One of the output can be reduced. \$\endgroup\$ – tsh Jan 16 at 10:27
  • \$\begingroup\$ Doesn't the second one produce much more than 99 programs? \$\endgroup\$ – Kaddath Jan 16 at 12:48
  • \$\begingroup\$ I trust you, knowing nothing about 05AB1E, but I get a huge list and "The output exceeded 128 KiB and was truncated" with the TIO link \$\endgroup\$ – Kaddath Jan 16 at 13:16
  • 1
    \$\begingroup\$ @kaddath added an explanation hope that is useful \$\endgroup\$ – Expired Data Jan 16 at 14:05
  • 2
    \$\begingroup\$ “€í„Î€î“ can be …I„΀î (also fixes the lowercase i to uppercase I in the sentence) \$\endgroup\$ – Kevin Cruijssen Jan 16 at 14:44
3
\$\begingroup\$

Keg, 33 bytes

Programs separated by :

Output is 1385 bytes

в&(c|&:&I+,&:&,`- love you:`,⑹

Try it online!

Programs:

ѻв- love you:Ѽг- love you:ѽд- love you:Ѿе- love you:ѿж- love you:Ҁз- love you:ҁи- love you:҂й- love you:҃к- love you:҄л- love you:҅м- love you:҆н- love you:҇о- love you:҈п- love you:҉р- love you:Ҋс- love you:ҋт- love you:Ҍу- love you:ҍф- love you:Ҏх- love you:ҏц- love you:Ґч- love you:ґш- love you:Ғщ- love you:ғъ- love you:Ҕы- love you:ҕь- love you:Җэ- love you:җю- love you:Ҙя- love you:ҙѐ- love you:Қё- love you:қђ- love you:Ҝѓ- love you:ҝє- love you:Ҟѕ- love you:ҟі- love you:Ҡї- love you:ҡј- love you:Ңљ- love you:ңњ- love you:Ҥћ- love you:ҥќ- love you:Ҧѝ- love you:ҧў- love you:Ҩџ- love you:ҩѠ- love you:Ҫѡ- love you:ҫѢ- love you:Ҭѣ- love you:ҭѤ- love you:Үѥ- love you:үѦ- love you:Ұѧ- love you:ұѨ- love you:Ҳѩ- love you:ҳѪ- love you:Ҵѫ- love you:ҵѬ- love you:Ҷѭ- love you:ҷѮ- love you:Ҹѯ- love you:ҹѰ- love you:Һѱ- love you:һѲ- love you:Ҽѳ- love you:ҽѴ- love you:Ҿѵ- love you:ҿѶ- love you:Ӏѷ- love you:ӁѸ- love you:ӂѹ- love you:ӃѺ- love you:ӄѻ- love you:ӅѼ- love you:ӆѽ- love you:ӇѾ- love you:ӈѿ- love you:ӉҀ- love you:ӊҁ- love you:Ӌ҂- love you:ӌ҃- love you:Ӎ҄- love you:ӎ҅- love you:ӏ҆- love you:Ӑ҇- love you:ӑ҈- love you:Ӓ҉- love you:ӓҊ- love you:Ӕҋ- love you:ӕҌ- love you:Ӗҍ- love you:ӗҎ- love you:Әҏ- love you:әҐ- love you:Ӛґ- love you:ӛҒ- love you:Ӝғ- love you:ӝҔ- love you:
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ To my understanding, separator : isn't count into the byte count. So, output should be count as 1385 bytes. \$\endgroup\$ – tsh Jan 16 at 10:23
3
\$\begingroup\$

Ruby, 200 181 172 165 + 3992 3828 3540 bytes

m="I love you";q=?",?';%w[print $><< puts].map{|e|q.product(q){|c,d|8.times{|i|puts e+c+"#{m.chars.rotate(~i)*""}#{c}.chars.rotate(#{i+1})*#{d*2}"}};puts e+"'#{m}'"}

This combines different ways of printing (print, $stdout <<, puts), different ways of quoting the string ('', ""), and different rotations of the string "I love you" to make (((8 * 4) + 1) * 3) = 99 irreducible programs.

Golfy Tricks

  • Uses %w[] as a whitespace-separated string array
  • Use *"" and *'' instead of .join
  • Use different combinations of quotation marks ("", '') instead of different combination of splitting a string (chars, split(//)), and just use the shorter (chars)
  • Use puts instead of $stdout<< as the third way of printing (I didn't think it would be allowed because it also appends a newline where the others don't, but maybe this is fine?)

Try it online! for the initial generator code.

Try it online! for the generated code.

This now has some "I love you"s appended with a newline, and some not. I hope this is okay.

EDIT: Saved lots of even more bytes thanks to Value Ink!


Ruby, 53 + 2375 bytes

This is the cheap way of using a unicode range as variable names.

(?ÿ..?š).each{|v|puts"#{v}='I love you';puts #{v}"}

Try it online! for the generator code.

Try it online! for the generated code.

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ 1) Replace the $stdout<< version of printing with puts for some byte saves; I'm pretty sure the trailing newline isn't a problem for the challenge. Also .join to *"". 2) Use %w notation for your arrays, for example %w(print $><< puts) saves lots of bytes over ['print','$><<','puts']. 3) Use 8.times and modify i as necessary instead of doing if i>0: -i becomes ~i, and #{i} becomes #{i+1}. \$\endgroup\$ – Value Ink Jan 21 at 22:23
  • 1
    \$\begingroup\$ I also meant you should change .join to *"" in your array... %w[.join *''] becomes %w[*"" *''] which you can golf further to %w["" ''] if you do *#{d}. Also, map is better than each in 99% of cases \$\endgroup\$ – Value Ink Jan 22 at 9:59
  • \$\begingroup\$ Oh yeah, I didn't think of mixing up the quotation marks! \$\endgroup\$ – IMP1 Jan 22 at 10:15
  • \$\begingroup\$ I can also swap out the %w[chars split(//)] with different quotation marks around the string. \$\endgroup\$ – IMP1 Jan 22 at 10:21
  • \$\begingroup\$ Since it's come to you using the quotation marks for both parts: q=?",?';q.product(q) then *"+d*2 works. Also, you can do puts e+c+"#{m.... instead of interpolating, since they're just basic strings! \$\endgroup\$ – Value Ink Jan 22 at 12:42
2
\$\begingroup\$

Perl 6, 75 bytes, 2178 + 75 = 2253

unique("'I love you'.tclc.say",{S:x(8)[\w]~^=' 'x 2.rand}...*)[^99+1]>>.say

Try it online!

Outputs variants of:

'I love you'.tclc.say

string part has a randomised unique case. tclc is short for "title case, lowercase", which capitalises the first letter and lowercases the rest.

"..."         # Starting from the base program
     ,{                        }...*  # Generate an infinite series of
       S:x(8)[\w]~^=             # String xor the first 8 letters
                    ' 'x 2.rand  # Randomly space or nothing, 
                                 # Essentially flipping the case

unique( ... )                 # From the unique elements
             [^99+1]          # Take 99, skipping the first
                    >>.say    # And print each

The reason I don't include the first unique element is so that a variant with correct casing isn't produced, since that would be reducible.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

PowerShell, 63 + 3167 = 3230

1..99|%{$z=$_%10;"''+(echo you $($_-$z)/10) love $z I)[4,2,0]"}

Try it online!

Sample output:

''+(echo you 0 love 1 I)[4,2,0]
''+(echo you 0 love 2 I)[4,2,0]
...
''+(echo you 1 love 0 I)[4,2,0]
''+(echo you 1 love 1 I)[4,2,0]
''+(echo you 1 love 2 I)[4,2,0]
...
''+(echo you 9 love 8 I)[4,2,0]
''+(echo you 9 love 9 I)[4,2,0]

PowerShell, 2575 = 101 + 2474

Inspired by Jo King's answer for Perl.

Minimal total output for Powershell (84+2153) was written by Andrei Odegov

So make sure to upvote them both as well!

1..99|%{$n=$_
'"I "+("'+-join(0..6|%{[char](($n-shr$_)%2*32+'LOVEYOU'[$_])
' '*!($_-3)})+'"|% *wer)'}

Try it online!

Sample output:

"I "+("lOVE YOU"|% *wer)
"I "+("LoVE YOU"|% *wer)
"I "+("loVE YOU"|% *wer)
"I "+("LOvE YOU"|% *wer)
...
"I "+("loVE You"|% *wer)

PowerShell, 2672 = 99 + 2573, bonus track

1..99|%{$p,$d="0$_"[-2,-1]
$e,$l,$c,$r='I love you'-split"^(.{$p})(.)"
"'$l$d$r'-replace$d,`"$c`""}

Try it online!

It generates 10 distinct programs for each char of the input string. The length of string I love you is 10 chars. This is enough for 99 iterations

Sample output:

'1 love you'-replace1,"I"
'2 love you'-replace2,"I"
'3 love you'-replace3,"I"
...
'8 love you'-replace8,"I"
'9 love you'-replace9,"I"
'I0love you'-replace0," "
'I1love you'-replace1," "
...
'I love yo8'-replace8,"u"
'I love yo9'-replace9,"u"

PowerShell, 94 + 2890, bonus track 2

1..99|%{$n=$_;$i=0
'"=I='+-join(' love you'|% t*y|%{$_+'='[1-($n-shr$i++)%2]})+'"-replace"="'}

Try it online!

Sample output:

"=I= =love you"-replace"="
"=I= l=ove you"-replace"="
"=I= =l=ove you"-replace"="
"=I= lo=ve you"-replace"="
"=I= =lo=ve you"-replace"="
...

PowerShell, 96 + 3094

Specially for those who love to turn 99 into 9. ٩(^‿^)۶

2..100|%{"-join('"+-join(('I love you '*$_)[($_+10)..$_])+"'*$(2+($_-$_%10)/10))[$($_+10)..$_]"}

Try it online!

Sample output:

-join(' I uoy evol'*2)[12..2]
-join('l I uoy evo'*2)[13..3]
-join('ol I uoy ev'*2)[14..4]
-join('vol I uoy e'*2)[15..5]
-join('evol I uoy '*2)[16..6]
-join(' evol I uoy'*2)[17..7]
-join('y evol I uo'*2)[18..8]
-join('oy evol I u'*2)[19..9]
-join('uoy evol I '*3)[20..10]
-join(' uoy evol I'*3)[21..11]
-join('I uoy evol '*3)[22..12]
-join(' I uoy evol'*3)[23..13]
...
-join(' uoy evol I'*10)[98..88]
-join('I uoy evol '*10)[99..89]
-join(' I uoy evol'*11)[100..90]
-join('l I uoy evo'*11)[101..91]
-join('ol I uoy ev'*11)[102..92]
-join('vol I uoy e'*11)[103..93]
-join('evol I uoy '*11)[104..94]
-join(' evol I uoy'*11)[105..95]
-join('y evol I uo'*11)[106..96]
-join('oy evol I u'*11)[107..97]
-join('uoy evol I '*11)[108..98]
-join(' uoy evol I'*11)[109..99]
-join('I uoy evol '*12)[110..100]

PowerShell, 123 + 3141

...and in a normal order. https://coub.com/view/27d6eh

$s='I love you';(2..122|%{"-join('"+-join(("$s "*$_)[-($_+10)..-$_])+"'*$(2+($_-$_%10)/10))[$($_-1)..$($_+9)]"})-notmatch$s

Try it online!

Sample output:

-join('u I love yo'*2)[2..12]
-join('ou I love y'*2)[3..13]
-join('you I love '*2)[4..14]
-join(' you I love'*2)[5..15]
-join('e you I lov'*2)[6..16]
-join('ve you I lo'*2)[7..17]
-join('ove you I l'*2)[8..18]
-join('love you I '*3)[9..19]
-join(' love you I'*3)[10..20]
-join('u I love yo'*3)[13..23]
-join('ou I love y'*3)[14..24]
-join('you I love '*3)[15..25]
...
|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ For your first answer, what's to stop me turning the 99 into 9? \$\endgroup\$ – Neil Jan 21 at 13:43
  • \$\begingroup\$ Nothing. Thanks. \$\endgroup\$ – mazzy Jan 21 at 13:59
1
\$\begingroup\$

R, 84 Bytes

for(x in 1:99){cat("assign(intToUtf8(",x,"),'I love you');get(intToUtf8(",x,"))\n")}
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I think this doesn't satisfy condition 2. For any values of x > 9 (i.e more than one digit), then you can remove two strings (one digit from both numbers) and it will still print 'I love you'. \$\endgroup\$ – IMP1 Jan 20 at 10:48
1
\$\begingroup\$

C# (Visual C# Interactive Compiler), 70 bytes

for(char i='ÿ';i++<355;Write($"var {i}=\"I love you\";Write({i});"));

Try it online!

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 85 + 2647 = 2732 83 + 2251 = 2334 79 + 1818 = 1897

0..226|?{[char]::isletterordigit($_)}|%{"`$$([char]$_)"}|%{"($_='I love you')"}

-398 thanks to mazzy

Try it online!

Sample output:

($0='I love you')
...
($â='I love you')

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ nice. you can remove { and }. Try it online! \$\endgroup\$ – mazzy Jan 18 at 19:14
  • \$\begingroup\$ You can reduce programs by removing the $0= and ;$0 parts \$\endgroup\$ – Jo King Jan 20 at 0:39
  • \$\begingroup\$ I'm agree in this case. The constraint 1 violated: If $0= is removed, then the program outputs `I love you' \$\endgroup\$ – mazzy Jan 20 at 4:49
  • \$\begingroup\$ I thinks this 84+2153 was the best \$\endgroup\$ – mazzy Jan 20 at 6:35
1
\$\begingroup\$

Ruby, 123 + 4247 94 90 + 2124 bytes

Heredoc abuse. Takes 49 different alphanumerics (A-Z, _, a-v) and constructs 2 programs that print the text using the appropriate heredoc. That's only 98 programs, though, so it adds one more print at the end. Each program is 3 lines long, except the last one.

This beats IMP1's Ruby solution in the combined code golf score, but falls behind in standard scoring.

l="I love you"
(?A..?v).grep(/\w/){|i|puts"$><<<<"+i,l,i,"puts <<"+i,l,i}
puts"puts'#{l}'"

Try it online!

Generated code

Old solution, 123 + 4247 bytes

Beats out IMP1's (non-Unicode) Ruby solution in the standard code golf department, but falls behind in combined code golf scoring. Unlike their use of multiple output solutions and rotation, I chose to shuffle the string after setting a seed with srand.

99.times{|i|srand i;puts"srand #{i};puts'#{[*0..9].shuffle.zip('I love you'.chars).sort.map(&:last)*''}'.chars.shuffle*''"}

Try it online!

Generated code

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

W n d, 34 bytes

Different programs are separated as different list items. The n flag joins the input with newlines.

•u≡`â!=Ç¡l╪G⌠±×èe↔/.╫ù{¶c×█)←╢k0ôF

Uncompressed

99''a146+C"C'"a73+C"C-C@ love you@+"++++M

Explanation

99                                      M % Map in the range from 1 to 99
  ''                                      % A single quote '
    a146+                                 % Add the current item by 146
         C                                % Convert the current item to a character
          "C'"                            % Add a string C'
              a73+C                       % Add the current item by 73 (creating a difference of 73)
                   "C-C@ love you@+"++++  % Prepend the string and join the whole stack

Program explanation

'ⁿC'JC-              # Create the number 73
       C" love you"+ # Convert to character and append "love you"
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Aha! 'I4"#Mpu~!:O&` COPY \$\endgroup\$ – user85052 Jan 19 at 1:15
0
\$\begingroup\$

Zsh, 74 bytes

Output: 2178 (after removing newline delimiters) for a category 2 score of 2252 bytes

for p (echo print '<<<');for v ({1..7} {a..z})<<<"$v='I love you';$p \$$v"

Try it online!

Uses method from this Ruby answer, setting a unique variable before printing. In zsh, variables must be alphanumeric, so we limit to 33 names and then print out programs using echo, print, and <<< to get our 99.

There is optimization to be done for category 2, this tweak scores 77 + 2145 = 2222 bytes, and more can probably be found.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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