Win a copy of Rust Web Development this week in the Other Languages forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Junilu Lacar
• Rob Spoor
• Paul Clapham
Saloon Keepers:
• Tim Holloway
• Tim Moores
• Jesse Silverman
• Stephan van Hulst
• Carey Brown
Bartenders:
• Al Hobbs
• Piet Souris
• Frits Walraven

Project Euler: Problem 36

Ranch Hand
Posts: 808
• Number of slices to send:
Optional 'thank-you' note:

The decimal number, 585 = 1001001001 (binary), is palindromic in both bases.
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

I expected this to be fairly easy, yet my answer was rejected. I must have missed out some palindromes somewhere. I found 14. How many should I have found?

dennis deems
Ranch Hand
Posts: 808
• Number of slices to send:
Optional 'thank-you' note:
Never mind. I was ignoring single-digit numbers.

Bartender
Posts: 4568
9
• 1
• Number of slices to send:
Optional 'thank-you' note:
Did you remember single digit numbers?

Edit: too slow!

Ranch Hand
Posts: 4716
9
• Number of slices to send:
Optional 'thank-you' note:
i skipped that one thinking it was too geeky
maybe i should try it...
it must be easier than some i have been working on

lowercase baba
Posts: 13018
66
• 1
• Number of slices to send:
Optional 'thank-you' note:
it's not hard.

write a method that parses a string to see if it is a palindrome.

write a method to convert an int to a string.

write a method to convert an int to a string containing its binary representation.

loop from 1 to 1,000,000.

test each number.

Randall Twede
Ranch Hand
Posts: 4716
9
• Number of slices to send:
Optional 'thank-you' note:
i think i will try it next. i have it half solved already from the other palindrome problems i have solved.

dennis deems
Ranch Hand
Posts: 808
• Number of slices to send:
Optional 'thank-you' note:

fred rosenberger wrote:
loop from 1 to 1,000,000.

test each number.

Mwahaha! I only had to examine 1998 Integers and their binary representations.

Rancher
Posts: 4064
56
• Number of slices to send:
Optional 'thank-you' note:
I would think you could skip about half of those as well, Dennis. Aren't all binary palindromes odd?

Hmm, my quick back-of-the-envelope count is that I'd need to check 1110 different numbers. Haven't actually done it though, so maybe I'm missing something.

Matthew Brown
Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
Just had a look at mine, and I think I checked 610 values (500 + 50 + 50 + 5 + 5, in case that's a clue).

Mike Simmons
Rancher
Posts: 4064
56
• Number of slices to send:
Optional 'thank-you' note:
Looks very similar to my count - I just think the 500 needs to be in there twice. 500 + 500 + 50 + 50 + 5 + 5 = 1110

Matthew Brown
Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
Sorry, you're right. My mistake. 1110.

fred rosenberger
lowercase baba
Posts: 13018
66
• Number of slices to send:
Optional 'thank-you' note:

Dennis Deems wrote:I only had to examine 1998 Integers and their binary representations.

I wasn't going for the most efficient...just the simplest.

Mike Simmons
Rancher
Posts: 4064
56
• Number of slices to send:
Optional 'thank-you' note:

fred rosenberger wrote:

Dennis Deems wrote:

fred rosenberger wrote:I only had to examine 1998 Integers and their binary representations.

I wasn't going for the most efficient...just the simplest.

I think your attributions are off there, Fred. I almost replied to say "but Fred has already posted the simplest".

fred rosenberger
lowercase baba
Posts: 13018
66
• Number of slices to send:
Optional 'thank-you' note:

Mike Simmons wrote:I think your attributions are off there, Fred. I almost replied to say "but Fred has already posted the simplest".

I don't know what you are talking about...

Mike Simmons
Rancher
Posts: 4064
56
• Number of slices to send:
Optional 'thank-you' note:
That's OK, I've got it covered.

dennis deems
Ranch Hand
Posts: 808
• Number of slices to send:
Optional 'thank-you' note:

Mike Simmons wrote:I would think you could skip about half of those as well, Dennis. Aren't all binary palindromes odd?

D'OH!

Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
I have tried to solve it. Is the final sum of all palindromes is xxxxxx?

Matthew Brown
Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:

Aashu Aggarwal wrote:I have tried to solve it. Is the final sum of all palindromes is xxxxxx?

Hi Aashu. Welcome to the Ranch!

If you want to check any answers, you can register and enter them at Project Euler. I think it's better if you don't publish your answers here, though - they prefer answers not to be published so that the challange remains. Hope you don't mind that I've deleted it from your post.

Aashu Aggarwal
Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
Thanks Matthew for letting me know the site. I am sorry that i posted answer here. Will check on site now on.

reply
Similar Threads