Question

write the program with the language NODEJS need help Programming challenge, screenshot your work and output.  ...

write the program with the language NODEJS need help Programming challenge, screenshot your work and output.  

Description

A positive integer is a palindrome if its decimal representation (without leading zeros, is a palindromic string (a string that reads the same forwards and backwards). For example, the number 5, 77, 363, 4884, 11111, 12121 and 349943 are palindromes

A range of integers is interesting if it contains an even number of palindromes. The range [L, R], with L <= R, is defined as the sequence of integers from L to R (inclusive): (L, L+1, L+2,.., R-1, R). L and R are the range’s first and last numbers.

The range [L1,R1] is subrange of [L,R] if L <= L1 <= R1 <= R. Your job is to determine how many interesting subrane of [L,R] there are

Input

Your program should read lines of text from standard input. Each line will contain two positive integers, L and R (in that Order), separated by space.

Output

For each line of input, print out the number of interesting subranges of [L,R]

Code given:

process.stdin.resume();

process.stdin.setEncoding('utf8');

var stdin = ' ';

process.stdin.on('data', function (chunk) {

  stdin += chunk;

}).on('end', function() {

  var lines = stdin.trim().split('\n');

  for(var i=0; i

      process.stdout.write(lines[i]);

  }

});

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is one way to do it: (Copyable code is provided at the end)

Driver Function:

Main function: This Function counts the number of palindromes

Palindrome checker Function : This Function checks whether a number is palindrome or not.

Input: First line for the number of inputs and the second line for the values L and R.

Output:

Copyable code:


function main(chunk) {
var input = chunk.trim().split(' ');
   for (var i = 1; i < input.length; i++) {
       var splitchunk = input[i].split(" ");
       var begin = parseInt(splitchunk[0]);
       var end = parseInt(splitchunk[1]);
       var count = 0;
       for (var j = begin; j <= end; j++) {
           if (isPalindrome(j.toString())) {
               count++;
           }
       }
       console.log(count);
   }
}

function isPalindrome(chunk) {
   var midIndex = Math.floor(chunk.length / 2);
   var len = chunk.length;
   var isPalindrome = true;
for (var i=0 ; i <= midIndex ; i++) {
if (chunk[i] != chunk[len-(i+1)]) {
           isPalindrome = false;
           break;
       }
}
   return isPalindrome;
}


process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin = "";

process.stdin.on("data", function (chunk) {
stdin += chunk;
});

process.stdin.on("end", function () {
main(stdin);
});

Add a comment
Know the answer?
Add Answer to:
write the program with the language NODEJS need help Programming challenge, screenshot your work and output.  ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help programming this program in C. 1.) Write a program that reads a message,...

    I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...

  • C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality...

    C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality work. Lab 8 (this is to be turned in) Palindrome is a string that is the same as backwards or forwards “otto” “ababa” “noon” “ababbbbaba” In this lab we will work with strings (so we will be using character arrays). 1. Write a program that reads two strings strl and str2 from the keyboard 2. Print both strings 3. Write a function computeLength and...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list : You are given a sequence of n positive integers a1,a2,…,an, where n is even. Swap adjacent elements in the given sequence and print the resulting sequence: a2,a1,a4,a3,a6,a5,… Input The first line contains a positive even integer n (2≤n≤1000) — the length of the sequence. The second line contains n space-separated integers a1,a2,…,an (1≤ai≤1000) — the elements of the sequence. Output Print n...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list : You are given a non-decreasing sequence of n positive integers a1,a2,…,an. Print the number of distinct values in the sequence. For example, if the sequence is 1,2,2,2,3,4,4,5,7,10, the answer is 6 since distinct values are 1,2,3,4,5,7,10. Input The first line contains a positive integer n (1≤n≤1000) — the length of the sequence. The second line contains n space-separated positive integers a1,a2,…,an (1≤ai≤1000)...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : i have 15 min to submit the solution please help me   You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other in the sequence. Input The first line contains an integer n...

  • (C++ programming) Need help with homework. Write a program that can be used to gather statistical...

    (C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : Alex got a sequence of n integers a1,a2,…,an as a birthday present. Alex doesn't like negative numbers, so he decided to erase the minus signs from all negative numbers. As a result, he got a sequence of non-negative numbers. Print the resulting sequence. For example, if the sequence is  1, 5, -3, 4,...

  • Java 8 Braces You are designing a compiler for a C++ program and need to check...

    Java 8 Braces You are designing a compiler for a C++ program and need to check that braces in any given file are balanced Braces in a string are considered to be balanced if the following criteria are met: All braces must be closed. Braces come in pairs of the form 0.0andl1. The left brace opens the pair, and the right one closes it In any set of nested braces, the braces between any pair must be closed For example,...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT