I posted this on the Puzzle Lab chat, but it didn't get much response (except for Gareth...thanks Gareth!). Thus, I'm posting it here. Please feel free to chat on the Puzzle Lab if you have input that doesn't fit well here.
Hello Puzzle Lab Meta-People, in order to level the code-golf playing field for verbose languages, I've been thinking of introducing a new branch of code-golf called atomic-code-golf. Here, atomic means "Of or forming a single irreducible unit or component of code." Thus, the "atomic-code-golf" score of a piece of code is the sum of its atomic pieces. In such cases where the atomic-code-golf score is a tie, then we fall back to the code-golf score to determine the winner.
For a simple example, take a line of the Java Hello World code:
System.out.println("Hello World!");//35 points
In this code System
, out
, println
, and each character in the string "Hello World!"
would all be atomic components of the code, and would thus count as 1 point. In contrast, .
and ;
serve as separaters of atomic components, and would thus not count. Thus, the code might be counted as:
Sop("Hello World!")//19 points
Now, some may argue that "
, (
, and )
are groupers of atomic components, and so they should not count either. Thus, here are my broad level questions:
- Would people like this kind of contest?
- What should an atomic component be defined as?
- These are components that will be counted as 1 point even if it takes more than that to write them.
- Example: Object, keyword, and variable names such as
System
,class
, andmyInt
in Java code.
- What should a non non-atomic component be defined as?
- These are components that will be counted as 0 points even though you need them to make the program compile.
- Example: Separators such as
;
,.
, spaces, tabs, and newlines in Java code
What are the language-agnostic regular expressions we will need to atomic-code-golf score a language? Initially, I'm thinking we'll need the following:
- What is the regular expression that will match any component that should be counted at full length (such as a String)? For example, in the example of a String in Java, this should handle the string
"\""
where\"
is escaped. Any segment of code matching this regular expression will be counted at its full normal code-golf score. - Without considering matches from the first case, what is the regular expression of an atomic component (such as a variable name, Object name, keyword, number, etc.)? Each match on this regular expression will count as 1 point no matter how many characters are used.
- Again without considering matches from the first case, what is the regular expression for a non-atomic character (such as
;
,,
, etc.)? These will be counted as 0 when scoring a piece of code. - All remaining code-segments that do not match the above regular expressions will be counted at their full normal code-golf scores.
- What is the regular expression that will match any component that should be counted at full length (such as a String)? For example, in the example of a String in Java, this should handle the string
What are the above regular expressions in your favorite language? I, or anyone else who wishes, will strive to keep an updated alphabetical list of the regular expressions to be used for each language in the Regular Expressions section of this question. These will be revised as necessary to make the counts fair across all languages.
Once we've answered the above questions, I think the first question needs to be to write an atomic-code-golfed piece of code that figures out the atomic-code-golf score of a program in any language. The input for this program will be the code in question and the regular expressions needed to compute that code's atomic-code-golf score. The output will be the code's atomic-code-golf and code-golf scores (for the tie-breaker). An additional requirement will be that this needs to be accessible online so that future atomic-code-golf scores can be computed using this program.
Please let me know what you think, and any input is greatly appreciated!!!
Online scorer
Here is a tool to generate your atomic code-golf score. This will be updated/revised as more regular expressions are implemented and revised:
Currently Supports: GolfScript, JavaScript
Regular Expressions:
GolfScript:
- Full Length Code:
- RegExp:
/("((\\")|([^"]))*")/
- Matches on Strings:
"test"
or"\"test\""
- RegExp:
- Atomic Component:
- RegExp:
/and|or|xor|print|puts|rand|do|while|until|if|abs|zip|base/
- Matches on reserved words:
and
or
xor
print
puts
rand
do
while
until
if
abs
zip
base
- RegExp:
- Non-Atomic Component:
- none
JavaScript:
- Full Length Code:
- RegExp:
/("((\\")|([^"]))*")|('((\\')|([^']))*')/
- Matches on Strings:
"test"
,"\"test\""
,'test'
,'\'test\''
- RegExp:
- Atomic Component:
- RegExp:
/[a-zA-Z_$][0-9a-zA-Z_$]*/
- Matches on variable/object names:
var
,myVarName
,Math
,Array
- RegExp:
- Non-Atomic:
- RegExp:
/;|\.|\s|,/
- Matches on separators: period, comma, semicolon, space, newline, tab
- RegExp: