1
\$\begingroup\$

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).
\$\endgroup\$
  • 1
    \$\begingroup\$ So much CJam hate :( \$\endgroup\$ – Optimizer Dec 17 '14 at 21:42
  • \$\begingroup\$ How could a "separating or grouping symbol" not be a token? \$\endgroup\$ – feersum Dec 17 '14 at 21:45
  • \$\begingroup\$ the quotes in a string count as 2 tokens ? \$\endgroup\$ – Optimizer Dec 17 '14 at 21:46
  • \$\begingroup\$ Also, many languages allow variable names to be accessed, so they can be abused like strings. \$\endgroup\$ – feersum Dec 17 '14 at 21:46
  • \$\begingroup\$ @Optimizer I don't hate CJam, I could have said Perl or Brainfuck ;-) \$\endgroup\$ – coredump Dec 17 '14 at 21:47
8
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ +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... \$\endgroup\$ – coredump Dec 17 '14 at 23:23
  • 2
    \$\begingroup\$ Its not a literal. It is the program. \$\endgroup\$ – Optimizer Dec 17 '14 at 23:24
  • \$\begingroup\$ 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? \$\endgroup\$ – coredump Dec 17 '14 at 23:34
  • \$\begingroup\$ You can say that, but at least here I am not abusing them, but actually using them how they are meant to be used. \$\endgroup\$ – Optimizer Dec 17 '14 at 23:36
  • 1
    \$\begingroup\$ I 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) \$\endgroup\$ – coredump Dec 18 '14 at 8:13
1
\$\begingroup\$

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

\$\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.