-2
\$\begingroup\$

Rules/Objectives:

  1. The program must be executed using ./program-name without shell parameter/arguments.

  2. the program-name may not contain any of characters in /etc/passwd, that is acdepstw

  3. You may not open any other file, including own's source code, only /etc/passwd that should be read.

  4. The program must print the content the /etc/passwd file.

  5. Total score of the code equal to number of characters in the code added with constant literal declaration point. Each byte of constant declaration literal equal to +100 to the score, after 3 declaration, each byte adds +200 to the score. So the program should not contain too many constant declaration, but you may use predeclared constants (M_PI for example) or exploit the reflection of the function/variable/class name (function, variable or class names in this case are not considered as constant). Counting example:

    int x = 12;       // counted as 1 byte (12 can fit to 8-bit)
    x += 345;         // counted as 2 bytes (345 can fit to 16-bit)
    #define Y 'e'     // counted as 1 byte ('e')
    #define X Y       // counted as 0 (not considered as constant)
    string s = "abc"; // counted as 3 bytes ("abc")
    :foo              // counted as 3 bytes (:foo) 
                      //  ^ EACH characters in atom (Elixir, etc) 
                      //    or characters in symbol (Ruby, etc) 
                      //    are counted as 1 byte constant
    ''                // counted as 0 (not considered as constant)
    [0xAC, 12, 114]   // counted as 3 bytes (0xAC, 12, 114)
    

Clarification:

things that counted as constant literal:

  • numbers, each byte, depends on size
  • strings/symbols, each character = 1 byte
  • chars, one byte

things that not counted as constant literal:

  • class declaration
  • function declaration
  • variable declaration
  • operators, brackets
  • predefined symbols
  • predefined constants
\$\endgroup\$

closed as unclear what you're asking by Peter Taylor, feersum, KSFT, A.L, Hannes Karppila Jan 27 '15 at 16:54

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ What about languages like Bash, where everything is equivalent to a literal (ex. echo -n hello is the same as "echo" "-n" "hello")? \$\endgroup\$ – Doorknob Jan 27 '15 at 12:42
  • \$\begingroup\$ echo is function calling so it's not, but -n counted as 2 bytes, hello counted as 5 bytes \$\endgroup\$ – Kokizzu Jan 27 '15 at 12:51
  • \$\begingroup\$ The scoring rules currently just do not make sense. I think I can figure out the grammatical errors, but they require an unsupplied map between the terms you use and the tokens in a program. E.g. if I were following my best guess at the meaning of the rules, I would give your JS answer a much higher score because of all the symbols it contains (e.g. function names used other than in declarations). \$\endgroup\$ – Peter Taylor Jan 27 '15 at 14:43
  • \$\begingroup\$ I'm confused. We're supposed to print the contents of a specific file without reading any files? \$\endgroup\$ – KSFT Jan 27 '15 at 14:46
  • \$\begingroup\$ I forgot to add except /etc/passwd \$\endgroup\$ – Kokizzu Jan 27 '15 at 15:04
2
\$\begingroup\$

CJam, 49 characters + 0 bytes constant = 49

W[JCJFJIJBEIDHDHDHJBKGIJDHKCIHKFKFKJJA]Y/f+Afb:cg

It doesn't work in the online interpreter for obvious reasons.

\$\endgroup\$
0
\$\begingroup\$

NodeJS - 179 characters + 1 byte constant declaration = 279

#!/usr/bin/env node
fs=function fs(){};fs=require(fs.name);x=function etc(){};y=function passwd(){};z='/';fs.readFile(z+x.name+z+y.name,function(err,data){console.log(''+data);});

Readable version:

#!/usr/bin/env node    
fs = function fs(){};
fs = require(fs.name);
x = function etc(){};
y = function passwd(){};
z = '/'; // 1 declaration
fs.readFile(z+x.name+z+y.name,function(err,data){
  console.log(''+data);
});
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.