23
\$\begingroup\$

All the challenges on this site are focused on byte count, or the characters themselves. This one is different. Your challenge is to write a program that produces output which has a code point sum identical to the source's code point sum.

To produce a code point sum:

  1. Find the values of the characters in the program's character set.
    For example - FOO in ASCII: F = 70, O = 79, O = 79
  2. Add them all together.
    Code point sum of FOO in ASCII: F+O+O = 70+79+79 = 228.

An example of an ASCII sum quine would be if the source code was ABC and the output was !!!!!!. This is because the sum of the the ASCII values of the source (A = 65, B = 66, C = 67, sum = 198) is the same as the sum of the ASCII values in the output (! = 33, 33*6 = 198). BBB would also be valid output, as would cc.

Rules

  • Your program must not be a reverse, shuffled, error, or any other type of "true" quine. To elaborate: If the output contains all the same characters as the source, it is invalid.
  • Your program cannot use any errors/warnings from the compiler/interpreter as the output.
  • Your program's source must use the same codepage as the output.
  • Your program may use any codepage that was created before this challenge was.
  • Your program's output must not contain any unprintable characters (e.g. ASCII 0 through 31, or above 127) aside from linefeeds and tabs.
  • Standard loopholes apply.
  • If the source and/or output has a trailing linefeed, it must be included in the code point sum.
  • Compiler flags need to be included in the final byte count (score), but not the source's code point sum.
  • The output/source may not be empty.

Scoring

Shortest answer in byte count (not code point sum) wins. Please use this header format answers:

# Jelly, 12 bytes, sum 56 (SBCS)

You can use this tool to calculate ASCII sums.

Reference

Here are some useful codepage references.

/* Configuration */

var QUESTION_ID = 135571; // 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 = 8478; // 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 = (function(){
  var headerTag     = String.raw `h\d`
  var score         = String.raw `\-?\d+\.?\d*` // with negative/floating-point support
  var normalText    = String.raw `[^\n<>]*` // no HTML tag, no newline
  var strikethrough = String.raw `<s>${normalText}</s>|<strike>${normalText}</strike>|<del>${normalText}</del>`
  var noDigitText   = String.raw `[^\n\d<>]*`
  var htmlTag       = String.raw `<[^\n<>]+>`

  return new RegExp(
  String.raw  `<${headerTag}>`+
  String.raw    `\s*([^\n,]*[^\s,]),.*?`+
  String.raw    `(${score})`+
  String.raw    `(?=`+
  String.raw      `${noDigitText}`+
  String.raw      `(?:(?:${strikethrough}|${htmlTag})${noDigitText})*`+
  String.raw      `</${headerTag}>`+
  String.raw    `)`
  );
})();

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;
    lang = jQuery('<i>' + a.language + '</i>').text().toLowerCase();
    
    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link, uniq: lang};
  });

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

  langs.sort(function (a, b) {
    if (a.uniq > b.uniq) return 1;
    if (a.uniq < b.uniq) 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;
  float: left;
}

#language-list {
  padding: 10px;
  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="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654">
<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>
<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>

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

\$\endgroup\$
12
  • \$\begingroup\$ Are comments allowed? \$\endgroup\$ Commented Jul 25, 2017 at 5:02
  • \$\begingroup\$ @musicman523 yes, I guess so. \$\endgroup\$
    – MD XF
    Commented Jul 25, 2017 at 5:04
  • \$\begingroup\$ Why disallow warnings? I feel that's unnecessary. \$\endgroup\$ Commented Jul 25, 2017 at 16:55
  • 1
    \$\begingroup\$ @ConorO'Brien Warnings are not allowed to be the output of the program, e.g. no error quines. I guess that's unclear, one minute. \$\endgroup\$
    – MD XF
    Commented Jul 25, 2017 at 16:56
  • 2
    \$\begingroup\$ Does our output need to be deterministic? That is: Is it ok if my program randomly outputs one of several output but always outputs something with the proper sum? \$\endgroup\$
    – Wheat Wizard
    Commented Oct 11, 2019 at 4:30

53 Answers 53

1
2
1
\$\begingroup\$

Gaia, 4 bytes, sum 176 (SBCS)

6 5%

Explanation

In Gaia's codepage, linefeed has a code point of x7F (127 in decimal). Printable ASCII characters have the same code point as in ASCII.

This computes 6 modulo 5, which is 1, and prints 1 with a trailing linefeed.

Byte values of the characters in the codepage (in decimal):

6 5%: 54 + 32 + 53 + 37 = 176

1: 49 + 127 (linefeed) = 176

\$\endgroup\$
1
\$\begingroup\$

Trumpscript, 131 bytes, sum 10600 (ASCII)

They wants to make war 110000000;make dark 10000000;as long as,dark less war;:make dark,dark plus 1000000;say "00"!america is great

Is this real life?

Check with this.

Thanks @MagicOctopusUrn for telling me that exists.

\$\endgroup\$
1
\$\begingroup\$

Help, WarDoq!, 5 bytes, sum 1052 (Latin1)

l³ÿÿÿ

Prints

Hello World

Try it online!

Help, WarDoq! can add two numbers and test for primes, so it is considered as a valid programming language per this meta post.

\$\endgroup\$
1
\$\begingroup\$

Ly, 10 5 bytes, byte sum 679 381 (ASCII)

97^u:

Outputs:

4782969

Try it online!

\$\endgroup\$
1
\$\begingroup\$

PHP, 12 9 bytes, sum 481

<?=10**9;

prints 1000000000

Try it online.

other solutions:

PRINT 5**19;    # 12 bytes, sum 731, output 19073486328125
Print 4/31;     # 11 bytes, sum 815, output 0.12903225806452
Print 8/7;      # 10 bytes, sum 774, output 1.1428571428571
<?=5<<29;       #  9 bytes, sum 523, output 2684354560
\$\endgroup\$
1
\$\begingroup\$

Whitespace, 105 bytes, sum 2232 (ASCII)

   	

   	    		
 
 	
 	   	 	 
	
     	
	    
    		  	
	  	
	  	   	 	

 
 	    		

   	   	 	
 




		

Well you can't see the code but it's here ._.

I did put two <tab>s at the end (that doesn't affect the program) to match sum.

Explanation

The program counts from 1 to 24. I used the example you can find in this tutorial at the Annotated Example section.
For those who don't want to check this tutorial:
It puts your number onto the stack, then loop until <line10>'s number is reached by the number on the stack. The loop prints your number on the stack to stdout, increments it by 1, and puts a space and a linefeed.

Try it online!

Counted with this.

\$\endgroup\$
1
\$\begingroup\$

Cubically (6 bytes, sum 309)

I thought I'd do this in your language just for fun. Turns out the solution is pretty simple since % can print out up to two characters for every one character.

F1%441

Output:

363621
\$\endgroup\$
2
  • \$\begingroup\$ You seem to like Cubically :D +1 \$\endgroup\$
    – MD XF
    Commented Jul 26, 2017 at 15:50
  • \$\begingroup\$ @MDXF It's a fun language! Plus, aside from BF, it's the only esoteric language I'm familiar with. \$\endgroup\$
    – TehPers
    Commented Jul 26, 2017 at 15:56
1
\$\begingroup\$

ArnoldC, 185 bytes, sum 14508

IT'S SHOWTIME
HEY CHRISTMAS TREE i
YOU SET US UP 6
STICK AROUND i
TALK TO THE HAND "२"
GET TO THE CHOPPER i
HERE IS MY INVITATION i
GET DOWN 1
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

Try it online!

Code sum

Output sum

Special thanks to V. Courtois and their answer, in particular for providing the sum count scripts.

Pseudocode:

start
var i
i = 6
while i
    print "२\n"
    i
    = i
        - 1
    (end assignment)
(end loop)
(end program)

At this point, I don't see a way to further golf it, as the rest is boilerplate for ArnoldC... ArnoldC surprisingly supports unicode output, so it was just finding a unicode character which, when repeated 5 times, summed to the same as the code.


If printable unicode is off-limits:

ArnoldC, 187 bytes, sum 12300

IT'S SHOWTIME
HEY CHRISTMAS TREE q
YOU SET US UP 150
STICK AROUND q
TALK TO THE HAND "H"
GET TO THE CHOPPER q
HERE IS MY INVITATION q
GET DOWN 1
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

Try it online!

Verification

\$\endgroup\$
6
  • \$\begingroup\$ unicode~~ good work! \$\endgroup\$ Commented Jul 26, 2017 at 22:43
  • \$\begingroup\$ @V.Courtois I think unicode is technically against the rules, and it certainly fails the ascii codepoint checker... I now want to make one that passes his ascii verifier with unicode xD \$\endgroup\$ Commented Jul 26, 2017 at 22:47
  • \$\begingroup\$ wait... pass ascii with unicode? but how? maybe in a language with implicit conversion to int (scala) but not arnold c lel, even if arnoldc is scala \$\endgroup\$ Commented Jul 26, 2017 at 22:51
  • 1
    \$\begingroup\$ @V.Courtois २ == -213 according to his ascii codesum... I think I could swing a mix of ascii/unicode that gives a codesum of near zero >:D. Not sure it's worth the effort though. Also, that unicode is 3 bytes, so TIO is wrong. \$\endgroup\$ Commented Jul 26, 2017 at 22:53
  • \$\begingroup\$ good luck with this, though I don't think having negative codes is quite legit >:D \$\endgroup\$ Commented Jul 26, 2017 at 23:07
1
\$\begingroup\$

Perl 5, 8 bytes, sum = 688 (ASCII)

Input:

say"q"x6

Output:

qqqqqq

x is the repetition operator in perl. So "q"x6 is the same as qqqqqq. say prints the string with a following line feed.

\$\endgroup\$
1
\$\begingroup\$

Z80Golf, 4 bytes, sum 354 (ASCII)

00000000: 3676 7e38                                6v~8

Try it online!

The output is vvv.

Slightly modified from my 3-byte Output same length as code.

Disassembly

start:
  ld (hl), $76  ; 36 76
  ld a, (hl)    ; 7e
  db $38        ; 38 ; jr c, 0

As always, (hl) allows to use the memory address 0 similar to a register with pre-loaded value. In this case, the program overwrites its first opcode to halt, and then loads the same value to a. Usual stack underflow causes v to be printed three times and return to the start of program.

The last instruction is a no-op added to match the sum. The alternative 3-byte vvv program (in the link above) is unusable here because the difference $7a translates to ld a, d, which interferes with the preceding ld a, $76 (and it can't be moved in order to halt correctly).

\$\endgroup\$
1
\$\begingroup\$

Python 3, 13 bytes, sum 950 (ASCII)

print('_'*10)

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Keg, 4 bytes, sum=272

Note: This is kept as 4 general pure ASCII one-byte encoding bytes. Keg has multiple code pages, and the user can alternate between them. The pure ASCII+EASCII code page is one of them.

\*

There are control characters in between the characters \ and *. The bytecode of 136 is counted as 2 bytes.

Try It Online!

How did I get this program?

First of all, the challenge wants us to solve an equation, and the sum of all of the numbers in the source code equals a mystery number passed through a mystery function. I chose the multiply-two function because it is powerful enough to allow the solving of the equation. This is what I get as a draft (replace 2 with its control-character form mentally):

\?2*

(I prepended an escaping instruction before the mystery character because I want the character to be pushed no matter what the character is. My previous attempt of the mystery character without escaping had failed. The character was ,, which is a Keg instruction.) Obviously the ord codes of \, 2, and * are 92, 2, and 42 respectively, so we've complete half of the equation:

x+92+2+42

The other half is simply multiplying x by 2.

2x=x+2+92+42
 x=136

Therefore I escaped the 136 character, which is unprintable. So I need to verify the solution in case the result is wrong:

2*136=136+2+92+42
  272=272

The solution is valid, therefore the program is a valid code point sum quine solution.

\$\endgroup\$
6
  • \$\begingroup\$ Isn't this 5 bytes, since the 136 character counts for 2 bytes? (As it says on TIO) \$\endgroup\$
    – EdgyNerd
    Commented Oct 6, 2019 at 12:29
  • \$\begingroup\$ Pretend that I'm using pure ASCII. \$\endgroup\$
    – user85052
    Commented Oct 6, 2019 at 12:30
  • \$\begingroup\$ If I'm not mistaken any code points above 128 would be extended ascii, meaning it'd be two bytes still \$\endgroup\$
    – EdgyNerd
    Commented Oct 6, 2019 at 12:34
  • \$\begingroup\$ It is two bytes in Unicode, but it is one byte in the code page. \$\endgroup\$
    – user85052
    Commented Oct 6, 2019 at 12:35
  • \$\begingroup\$ Yeah I guess, though since the code page doesn't really exist yet I'd say keep it as 5 bytes until it's implemented and on TIO \$\endgroup\$
    – EdgyNerd
    Commented Oct 6, 2019 at 12:40
1
\$\begingroup\$

Lost, 31 30 bytes, sum 1598

///x///<<<///
>!?<@]]1111<%
//

Try it online!

Output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

\$\endgroup\$
1
\$\begingroup\$

Klein, 3 bytes, sum 138

$@&

Try it online!

This outputs 0 0 with a trailing newline (48 32 48 10). The executing parts are $, which swaps the top two values of the stack (taking implicit zeroes from the bottom) and @, which terminates the program and prints the stack. & is just there to balance out the codepoint sum, and isn't a valid instruction in Klein, nor is it actually parsed. Since the pointer doesn't wrap around any edge, this works in any topology of Klein.

\$\endgroup\$
1
\$\begingroup\$

Deadfish~, 5 bytes, sum = 574 (ASCII)

{ion}

Try it online!

Prints from 1 to 10, no spaces. n is a no-op (like most characters in deadfish~) which puts the code point sum where it needs to be.

\$\endgroup\$
1
\$\begingroup\$

Runic Enchantments, 6 bytes, sum=380

"Dz":@

Try it online!

D has a code-point-sum double that of " while z has the code-point-sum equal to : plus @. Duplicating the string (resulting in DzDz) then provides one copy to count for its own characters in the source and one copy to count for the remainder of the program. Getting a lower sum will be difficult, but I don't preclude it.

For comparison, the 6 byte quines are "'<~@> and variants of '<~@|" (any IP redirection command that turns a left-pointing IP into a right-pointing IP all work).

\$\endgroup\$
2
  • 1
    \$\begingroup\$ How about a7p@9? There's probably a 4 byte solution floating about somewhere \$\endgroup\$
    – Jo King
    Commented Oct 12, 2019 at 7:35
  • \$\begingroup\$ @JoKing Nice! I figure there was probably one of that form, but I didn't have the mental energy to hash it out (work's been a real nightmare lately; client recently OK'd an extension that would allow us to write a better framework with the understanding that we were going to miss the deadline anyway, then two days later asked for something extra). \$\endgroup\$ Commented Oct 12, 2019 at 15:37
1
\$\begingroup\$

Zsh, 11 bytes

<<< $[1e12]

Try it online!

Outputs 1000000000000. followed by a newline.

\$\endgroup\$
1
\$\begingroup\$

ARBLE, 4 bytes, Sum 186

''+A

Outputs

""+A

Each " is 5 codepoints smaller than their respective ', -5*2 and the output includes a newline, +10, which equals the source.

+A has to to be included as an implicit argument is needed to stringify as it does.

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Vyxal, 1 byte, sum 58

:

Try it Online!

Outputs 0\n, which has codepoint sum 48+10=58, which is the codepoint of :.

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

Triangular, 6 bytes, sum 306 (ASCII)

FA%%%<

Prints 151515. Check it here and Try it online!

Formats into this triangle:

  F
 A %
% % <

The IP starts reading southwest from the topmost character. < directs it east, so the code is read like this:

F%%%

F pushes 15 to the stack, % prints it. A was the necessary character to get the byte sums even.

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

Bitwise, 117 bytes, sum 5796 (ASCII)

MOV 1 &46 &1
LABEL &1
MOV 2 &1 &1
LABEL &2
NOT 1 *1
AND *1 2 *2
XOR 1 2 1
SL *2 &1 2
JMP @2 2
OUT &126 &1
JMP @1 1
;$

Outputs 46 tildes (~). Try it online!

This will be alot shorter once I add functions to Bitwise...

MOV 1 &46 &1     move l46 into r1 when l1 is truthy
LABEL &1         create label 1
MOV 2 &1 &1      move l1 into r2 when l1 is truthy
LABEL &2         \
NOT 1 *1          \
AND *1 2 *2        \_ all this code performs r1 = r1 - r2
XOR 1 2 1          /
SL *2 &1 2        /
JMP @2 2         /
OUT &126 &1      print l126 (~) when l1 is true
JMP @1 1         jump to jp1 when r1 is truthy
;$               byte fill :P

l is short for literal, r is short for register, jp is short for jump point. I'll update with a better explanation later.

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

Bash + coreutils, 13 bytes, sum = 1090 (ASCII)

yes c|   head

Note the three spaces after the pipe.

Output:

c
c
c
c
c
c
c
c
c
c

Output is 10 c's and 10 line feeds, ascii 99 and 10 respectively, for a total of 1090. Input is 121+101+115+32+99+124+32+32+32+104+101+97+100=1090.

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

Actually, 6 4 bytes

Simply outputs 512. Adds 2 NOPs in order to get to that number.

9╙Ω☼

Try it online!

Explanation

9╙   512 is 2**9
  Ω  Unfortunately opcode 250 is an implemented instruction; 
     opcode 234 has to be used instead.
   ☼ Opcode 16 just for the bytecount; this is also not an instruction.
\$\endgroup\$
1
2

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.