Meta-atomic code golf

1

In this meta-challenge, you will score your own submissions. More precisely, you will need to write a program P in language L such that the atomic-score of P is produced by P.

Score

The idea behind is to count language tokens instead of bytes. However, in practice, it is hard to define a general set of rules for all questions (see Count big-ints/symbols/variables as N tokens in atomic-code-golf). That's why it is recommended to clarify rules for each challenge.

Intuitively, tokens are nodes in the abstract syntax tree of your language, except for strings, where each character count (due to potential abuse).

  1. Things that count as single tokens:

    • variable/function/type identifiers
    • literals, except strings, where each byte counts
    • built-in keywords and operators
    • (edit) Empty lists, empty vectors, empty strings
  2. Things that are ignored from counting:

    • preprocessor/reader macros
    • include/import statements
    • separating and grouping symbols used to build tuples, lists, arrays, statements, function parameters, structs are ignored (,;:(){}[]<>|). However, if those symbols are tokens, they count (I am looking at you, CJam (or Brainfuck)). Also, quotes enclosing strings are not counted.
  3. Corner cases

    • Using identifiers to hold data is a nice hack (see feersum's comment), but it might be considered abusive. So, there should be a penaly of +25 if your answer exploits identifiers' names for computations. This penalty needs not be correctly scored by your program. If you manage to add a penalty to programs which abuse identifiers' names for computation (for a reasonable subset of programs in your language), you deserve -100 points of bonus (this bonus needs not be correctly scored by your program).

Challenge

You should write a program in the language of your choice that scores programs in that language according to the above atomic-score rules. Your own answer will be scored according to that program.

  • Input may be read from STDIN or given as a function parameter
  • Output is a number, as a return value or printed to STDOUT
  • Answer with lowest atomic-score wins
  • I'll provide an example answer (if it has the lowest score, the next one wins).

coredump

Posted 2014-12-17T21:39:58.153

Reputation: 6 292

1So much CJam hate :( – Optimizer – 2014-12-17T21:42:06.590

How could a "separating or grouping symbol" not be a token? – feersum – 2014-12-17T21:45:24.180

the quotes in a string count as 2 tokens ? – Optimizer – 2014-12-17T21:46:30.633

Also, many languages allow variable names to be accessed, so they can be abused like strings. – feersum – 2014-12-17T21:46:33.040

@Optimizer I don't hate CJam, I could have said Perl or Brainfuck ;-) – coredump – 2014-12-17T21:47:30.837

@feersum They are not token if they are not concretely present in the AST. – coredump – 2014-12-17T21:49:43.853

@Optimizer no: quotes do not count as 2 tokens – coredump – 2014-12-17T21:50:12.403

@feersum About variable names: maybe that kind of abuse could be valid. Do you have an example? – coredump – 2014-12-17T21:52:02.790

@coredump Maybe something like this in Python: def f(s): soaosuOSNTEUHSONETUHTSon50392858209358092386092 = 3; exec locals().keys()[0].decode('base64') – feersum – 2014-12-17T21:58:24.440

What happens when some characters are no-op in one language ? i.e. their presence does not have any effect to the AST or the code ? – Optimizer – 2014-12-17T22:04:12.883

@Optimizer Like whitespace, comments? they are ignored. What do you have in mind? – coredump – 2014-12-17T22:09:43.247

@feersum maybe I can restrict this usage a little: "user-defined identifiers of length > 5 are counted as strings"? – coredump – 2014-12-17T22:12:35.900

What about built-in lexers? Are they allowed? – Martin Ender – 2014-12-17T22:35:14.183

@MartinBüttner Sure – coredump – 2014-12-17T23:26:28.417

What if () supports IO? It has only grouping symbols.

– jimmy23013 – 2014-12-18T04:36:39.547

@user23013 How would you name a function that does the same thing as ()?: "empty-list", "read-from-stdin"? Depending on the meaning of symbols in a particular language, symbols are counted differently. – coredump – 2014-12-18T08:02:24.103

@coredump the winning condition should be to win in as much (non-eso)languages as possible – Def – 2014-12-18T18:22:05.347

For scoring strings, is it number of bytes as typed or as parsed? E.g. do you score "\n" as 1 or 2 points? – algorithmshark – 2014-12-19T16:01:58.227

What does If you manage to add a penalty to programs which abuse identifiers' names for computation (for a reasonable subset of programs in your language), you deserve -100 points of bonus (this bonus needs not be correctly scored by your program). mean – l4m2 – 2018-01-05T11:33:33.253

Answers

8

Unary, 1

The program is a string of 47297560408284 zeroes

i.e.

000000000000000000000000000000000000000000.... 47297560408284 times

A brainfuck quivalent code would be

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

which just prints 1

as in unary, the whole program is made up of just 0 which are all a single token.

Optimizer

Posted 2014-12-17T21:39:58.153

Reputation: 25 836

+1 It works for any program written in Unary, not just itself. That being said, something tells me I should have a rule about very long litterals... – coredump – 2014-12-17T23:23:07.863

2Its not a literal. It is the program. – Optimizer – 2014-12-17T23:24:49.937

The whole chain of zero is one (big) integer expressed in base 1, which, converted back to Brainfuck can be decoded as commands. So it is both the program and a big literal, isn't it? – coredump – 2014-12-17T23:34:22.277

You can say that, but at least here I am not abusing them, but actually using them how they are meant to be used. – Optimizer – 2014-12-17T23:36:28.423

1I don't think you are abusing them, just that the language is designed to interpret a big unary literal. Even though is doesn't seem fair w.r.t. other languages, I can't prevent it. Let's Unary wins, for a change (atomic-code-golf rules were supposed to level languages, and ironically, they tend to favor this one) – coredump – 2014-12-18T08:13:02.977

I may be wrong, but I think you only need 47297560408284 zeroes. – r3mainer – 2014-12-18T09:56:29.153

The first BF character is +. According to this page, it should be represented by 010 in the binary stream. With a 1 added at the beginning, that means your number should start with 0b1010.... But 3424997280936108 in binary starts with 0b1100... (Or maybe i just read it wrong.)

– r3mainer – 2014-12-18T10:07:47.267

Ah, you are right. I messed up in binary conversion. – Optimizer – 2014-12-18T10:11:06.280

1

Common Lisp - 23 26

Here is the example answer:

(labels ((sum (s form)
           (if (typep form 'sequence)
               (max (1+ s) (reduce #'sum form :initial-value s))
               (1+ s))))
  (defmacro atomic-count (form) (sum 0 form)))

And here we can see the macro scoring itself:

(atomic-count
 (labels ((sum (s form)
            (if (typep form 'sequence)
                (max (1+ s) (reduce #'sum form :initial-value s))
                (1+ s))))
   (defmacro atomic-count (form) (sum 0 form))))
=> 26

NB. This never terminates (or, badly) with cyclic expressions built with #1= and #1# reader macros.

(edit) Empty sequences should count as 1 token

coredump

Posted 2014-12-17T21:39:58.153

Reputation: 6 292