Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Quines that print what their index is

We all know what a quine is. A quine is a program which prints its own source code. And we also know about the printable ASCII characters. Well... this challenge mixes both.

Your mission, should you accept it, is to create an index quine. An index quine is a non-empty program, composed only of the printable ASCII characters, which prints its own index.

The index of a string is its position within an infinite dictionary where all strings composed of exactly the printable ASCII characters appear, sorted by size then ASCII code.

The index is a non-negative whole number, assigning 0 to the empty string then continuing with the space, !, " onward.

For example, *! precedes ** as the ending ! in the first string has lower ASCII code than the ending * in the second, but both are preceded by {, which has a higher ASCII code than the characters of the last two examples, but is shorter.

The printed index should be in base 10, outputted through STDOUT or closest equivalent, with no other output unless your language requires trailing newlines/other characters. Also, a bit like actual quines, do not access your source code directly (as a file, etc.)

Your program should be non-empty, as a reminder to those reading these rules.

If there are multiple programs of shortest length, the tiebreaker is the program with the lower index.

The shortest program following these very rules wins. Have fun.

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ -3 bytes by using a for loop instead of the reduce \$\endgroup\$ Commented Jun 1, 2020 at 6:21
  • \$\begingroup\$ @Mukundan That’s great, thanks! \$\endgroup\$ Commented Jun 1, 2020 at 6:30

AltStyle によって変換されたページ (->オリジナル) /