Print the content of /etc/passwd with constant creation limit

-2

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

Kokizzu

Posted 2015-01-27T12:01:53.950

Reputation: 1 531

Question was closed 2015-01-27T16:54:36.483

What about languages like Bash, where everything is equivalent to a literal (ex. echo -n hello is the same as "echo" "-n" "hello")? – Doorknob – 2015-01-27T12:42:19.397

echo is function calling so it's not, but -n counted as 2 bytes, hello counted as 5 bytes – Kokizzu – 2015-01-27T12:51:34.703

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). – Peter Taylor – 2015-01-27T14:43:11.953

I'm confused. We're supposed to print the contents of a specific file without reading any files? – KSFT – 2015-01-27T14:46:50.750

I forgot to add except /etc/passwd – Kokizzu – 2015-01-27T15:04:15.020

Answers

2

CJam, 49 characters + 0 bytes constant = 49

W[JCJFJIJBEIDHDHDHJBKGIJDHKCIHKFKFKJJA]Y/f+Afb:cg

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

jimmy23013

Posted 2015-01-27T12:01:53.950

Reputation: 34 042

0

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);
});

Kokizzu

Posted 2015-01-27T12:01:53.950

Reputation: 1 531