All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Mileage (Posted on 2004-06-16) Difficulty: 3 of 5
My car has a 5-digit odometer, which measures the miles since the car was built, and a 3-digit trip meter, which measures the miles since I last set it. Every so often, one or both of the readings is a palindrome. The meters reset to 000 after 999 and to 00000 after 99999.

The current readings are 123 and 12345. Assuming that I do not reset the trip meter, when is the next time both readings will be palindromes?

When was the most recent time both readings were palindromes?

Prove no matter what the mileage and trip meters read, they can eventually be made to both be palindromes without resetting the trip meter.

Note: A palindrome reads the same forwards and backwards, like 262 or 37173.

See The Solution Submitted by Brian Smith    
Rating: 3.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re: Code used for finding palindromic numbers - no spoiler | Comment 4 of 5 |
(In reply to Code used for finding palindromic numbers - no spoiler by Erik O.)

Visual Basic has the same LTRIM function that QuickBasic has (without the $'s though) and I use in the following program, to avoid the necessity of looping to remove leading blanks:

DEFLNG A-Z
trip = 123
main = 12345
DO
 trip = (trip + 1) MOD 1000: main = (main + 1) MOD 100000
 
 IF trip MOD 10 = trip \ 100 THEN
    m$ = LTRIM$(STR$(main))
    IF LEFT$(m$, 1) = RIGHT$(m$, 1) THEN
      IF MID$(m$, 2, 1) = MID$(m$, 4, 1) THEN
        PRINT trip, main, "next"
        EXIT DO
      END IF
    END IF
 END IF
LOOP UNTIL main = 12345

trip = 123
main = 12345
DO
 trip = trip - 1: main = main - 1
 IF trip < 0 THEN trip = trip + 1000
 IF main < 0 THEN main = main + 100000
 IF trip MOD 10 = trip \ 100 THEN
    m$ = LTRIM$(STR$(main))
    IF LEFT$(m$, 1) = RIGHT$(m$, 1) THEN
      IF MID$(m$, 2, 1) = MID$(m$, 4, 1) THEN
        PRINT trip, main, "prev"
        EXIT DO
      END IF
    END IF
 END IF
LOOP UNTIL main = 12345

which found

 909           13131        next
 999           12221        prev

  Posted by Charlie on 2004-06-16 10:03:20
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (7)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information