1
In this meta-challenge, you will score your own atomic-code-golf 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 atomic-code-golf 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).
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
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.
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).
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.440What 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.227What 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