• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Project Euler: Problem 36

 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I was ignoring single-digit numbers.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you remember single digit numbers?

Edit: too slow!
 
Randall Twede
Ranch Hand
Posts: 4439
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 4439
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, you're right. My mistake. 1110.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's OK, I've got it covered.
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:I would think you could skip about half of those as well, Dennis. Aren't all binary palindromes odd?


D'OH!
 
Aashu Aggarwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried to solve it. Is the final sum of all palindromes is xxxxxx?
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Matthew for letting me know the site. I am sorry that i posted answer here. Will check on site now on.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic