Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codechef javascript submission [closed]

Tags:

javascript

how can I submit solutions in Javascript for Codechef questions?

can you give me an example to handle js input at codechef?

www.codechef.com

like image 968
user753661 Avatar asked Dec 20 '11 15:12

user753661


Video Answer


2 Answers

Yes this is for each language a huge hazzle. The best javascript implementation in Codechef is via node.js. This is for the first Exercise "Life, the Universe, and Everything":

process.stdin.resume();
process.stdin.setEncoding('utf8');


process.stdin.on('data', function (chunk) {
  var lines = chunk.toString().split('\n');

  lines.forEach(function(line) {
  if (line === '42') {
     process.exit();
  }
     process.stdout.write(line+'\n');

  });
});

For me this worked.

like image 166
Flex Elektro Deimling Avatar answered Oct 28 '22 16:10

Flex Elektro Deimling


Codechef uses Rhino Javascript engine to judge solutions. This is how it can be done for JavaScript (rhino-1.7R4).

importPackage(java.io);
importPackage(java.lang);

var reader = new BufferedReader( new InputStreamReader(System['in']) );

while(true) {
    var line = reader.readLine();
    if(line == null || line == "42") {
        break;
    } else {
        System.out.println(line);
    }
}

here you can find a basic implementation in most of the languages

like image 43
avichalp Avatar answered Oct 28 '22 16:10

avichalp