Step by Step guide for start coding at CodeChef using javascript

RANJITH KUMAR KOMMURI
2 min readNov 20, 2020

--

I have been searching for this over the internet for a long time but couldn’t find it. So, to help some of the fellow students I’m going to do my best to explain it clearly. Firstly! don’t go deep into the boilerplate code which I will be provided in the blog use it as a tool to make your work done.

Boilerplate definition according to google search.

function runProgram(input){
input = input.split(‘\n’);
for(var i=0; i<input.length; i++){
if(Number(input[i]) == 42){
return
}
else{
console.log(Number(input[i]))
}
}
}
if(process.env.USERNAME === “ranji”){
runProgram(``); //This is for input to be given in your system use any ide //like VS Code
}
else{
process.stdin.resume();
process.stdin.setEncoding(“ascii”);
let read = “”;
process.stdin.on(“data”, function (input) {
read += input;
});
process.stdin.on(“end”, function () {
read = read.replace(/\n$/,””)
runProgram(read);
});

process.on(“SIGINT”, function () {
read = read.replace(/\n$/,””)
runProgram(read);
process.exit(0);
});
}

You can download the VS Code software from here. This is the code for Universe Problem in CodeChef you can find the link to the question over here.

process.env.USERNAME === “Name”. You need to replace your system user name over here to get this program to execute in your system so that there is no need to provide input for every run. console.log(process.env.USERNAME) I’m providing this assuming that you are using a terminal or Git Bash in windows to run your program.

Try to copy this program and execute the problem in CodeChef and get a better understanding of how you can change an input as per the problem statement.

It’s done for now let’s execute more codes All the best! If you have any doubts do let me know. I will try my best to resolve that.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response