aspose file tools*
The moose likes Programming Diversions and the fly likes Project Euler: Problem 36 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Project Euler: Problem 36" Watch "Project Euler: Problem 36" New topic
Author

Project Euler: Problem 36

dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
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

Joined: Mar 12, 2011
Posts: 808
Never mind. I was ignoring single-digit numbers.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4392
    
    8

Did you remember single digit numbers?

Edit: too slow!
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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


SCJP
Visit my download page
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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

Joined: Mar 12, 2011
Posts: 808
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

Joined: Mar 05, 2008
Posts: 3014
    
  10
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

Joined: Apr 06, 2010
Posts: 4392
    
    8

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

Joined: Mar 05, 2008
Posts: 3014
    
  10
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

Joined: Apr 06, 2010
Posts: 4392
    
    8

Sorry, you're right. My mistake. 1110.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

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

Joined: Mar 05, 2008
Posts: 3014
    
  10
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

Joined: Oct 02, 2003
Posts: 11314
    
  16

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

Joined: Mar 05, 2008
Posts: 3014
    
  10
That's OK, I've got it covered.
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
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

Joined: Aug 01, 2012
Posts: 4
I have tried to solve it. Is the final sum of all palindromes is xxxxxx?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4392
    
    8

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

Joined: Aug 01, 2012
Posts: 4
Thanks Matthew for letting me know the site. I am sorry that i posted answer here. Will check on site now on.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Project Euler: Problem 36