## Palindrometer Program

Palindrometer Program
# 1
07-20-2011
Palindrometer Program

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
\While driving the other day, John looked down at his odometer, and it read 100000. John
was pretty excited about that. But, just one mile further, the odometer read 100001, and
John was REALLY excited! You see, John loves palindromes (things that read the same
way forwards and backwards. So, given any odometer reading, what is the least number
of miles John must drive before the odometer reading is a palindrome? For John, every
odometer digit counts. If the odometer reading was 000121, he wouldn't consider that a
palindrome."
Write a script that solves this problem. The script is invoked with the current odometer
reading on the command line, and it should echo back the total number of miles to drive
to get the next reading that is a palindrome. For example when invoked as
should echo back
1
and
palindrometer 100000
palindrometer 000121
should echo back
979.

2. Relevant commands, code, scripts, algorithms:
I couldn't understand how to make this program, I tried my best to understand the program but I couldn't it.

3. The attempts at a solution (include all code and scripts):
Tried with 6 digit input and in next palindrome subtracted it

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Narasaraopeta Engineering College, Guntur (Andhra Pradesh) INDIA.
Professor: Sudeepthi, Code No: Q0501/R05 (Unix and Shell Programming)

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 sujithcrazy View Public Profile for sujithcrazy Find all posts by sujithcrazy
# 2
07-20-2011
Quote:
Originally Posted by sujithcrazy
2. Relevant commands, code, scripts, algorithms:
I couldn't understand how to make this program, I tried my best to understand the program but I couldn't it.
Still, what did you try? It'd also be good to know what shell we're supposed to use!
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688
# 3
07-20-2011
I used Borne Shell
 sujithcrazy View Public Profile for sujithcrazy Find all posts by sujithcrazy
# 4
07-20-2011
"What variety is your shell?" "Bourne"
"What model is your car?" "Blue"

Both very vague answers. If I wrote an answer for you in my shell odds are good it wouldn't work in your shell.

If you don't know what your shell is, do you know what your system is?

Last edited by Corona688; 07-20-2011 at 03:50 PM..
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688
# 5
07-20-2011
While Corona is absolutely correct in stating that you should document your environment and what you tried so far (btw: it is good style in IT to document thoroughly! You can't start too soon to develop good habits!) i'd like to tackle a different part of your problem meanwhile:

How would you solve the problem of finding the next palindrome number manually? Which mathematical algorithm would you use?

I hope this helps.

bakunin
 bakunin View Public Profile for bakunin Find all posts by bakunin
# 6
07-30-2011
I agree with the above posters. We need to know precisely what Operating System you have and exactly what Shell you have. Nowadays it is quite rare to encounter a raw Bourne Shell.
The palindrone question is an advanced text manipulation exercise which usually requires you to first determine the length of the string, then reverse the order of the characters in the string, and then compare the before and after string. If they are the same then it is a palindrome.
There are some extraordinarily complex methods for doing this involving arrays however it may be worth checking out the unix "rev" command if this command is allowed by your tutor.

This example script should work with any true Bourne Shell.

Ps. The straightforward answer to the original question is "zero". I do hope that this isn't an interview question.
However if you continue from 100001 and attempt to find the next palindrone (which I guess is 101101) by incremental methods then this is much more interesting.

Conforming to old Bourne Shell syntax we arrive at something like this:

If your course context suggests that the string reversal bit should be done with string arrays, then it is up to you to how you reverse the string.

Last edited by methyl; 07-30-2011 at 09:24 PM.. Reason: Wrong guess.
 methyl View Public Profile for methyl Find all posts by methyl

## Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( \$response =~ m/^/ ) { \$user_wants_to_quit...

## Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text...

## Calling c program from another c program

Hi All, Probably this is a repeated question. My knowledge in this is limited and i got confused on all those materials i got in google search. We use #include <> to include a predefined library like stdio.h i saw somewhere that #include "" includes a man made module(another C program). IS...

## Python program faster than C++ program.

I wrote a simple program that generates a random word 10,000,000 times. I wrote it in python, then in C++ and compared the two completion times. The python script was faster! Is that normal? Why would the python script be faster? I was under the impression that C++ was faster. What are some of...

## Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"...

## C program

Can anyone tell me how to..... program to create multiple threads (one master thread and rest worker threads) and using the threads write into and read from shared memory Restrictions: Only one thread should be able to read at any instant of time into shared memory region. Only one...

## A program to trace execution of another program

Hi, I wanted to know if i can write a program using switches and signals, etc to trace execution of other unix program which calls c program internally. If yes how? If not with signals and switches then are there any other methods apart from debugging with gdb/dbx.

## How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------...

## How to write to stdin of another program (program A -> [stdin]program B)

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question: ---------...

## executing a program within a program

Read the title: how do i do it?