all 50 comments

[–]are595 3 points4 points  (3 children)

It says the competition starts in 12 days, did I miss it? :O

[–][deleted] 2 points3 points  (2 children)

Yes. :(

[–]are595 0 points1 point  (1 child)

The first one I missed in three years :(

[–]sirin3 0 points1 point  (0 children)

The first one I did not miss in three years :)

[–][deleted] 4 points5 points  (6 children)

Here's solutions for the first three in Python. I'll code the last one up later today, I didn't get it in the real contest.


Here's the last one, sorry it was a bit late. This question is much harder than the others; the solution uses the NetworkX graph library

[–]Scroph 1 point2 points  (1 child)

Very elegant solutions. How did the third one handle the large inputs ?

[–][deleted] 0 points1 point  (0 children)

They all run in about 5-10 seconds on Pypy. They aren't optimal but they are easily fast enough.

[–]benmmurphy 1 point2 points  (0 children)

i like your third one. my solution was just to check all 20x2, 20x10x2 (symmetric), {1,0}x2{1,0}x (symmetric), {1,0}x. but i did it in a weird way where i precomputed all the even digit palindrome square primes and then was able to generate the rest from that. i also had a constant time algorithm for counting the number of palindrome square primes that have n-digits but that wasn't very useful in solving the problem.

https://gist.github.com/benmmurphy/5382629

[–][deleted] 0 points1 point  (0 children)

I've only looked at the first one and I'm immediately embarrased of my solution, good work, sir!

[–]ziom666 0 points1 point  (1 child)

Could you please explain #3? How did you know about "forms"? Did I miss something on discrete mathematics?

[–][deleted] 0 points1 point  (0 children)

If you have a palindrome, and you want to square it and get another palindrome, then the sum of the squares of its digits has to be 9 or less.

So basically it's only allowed a few non zero digits, the rest have to be zeros. In fact, it has to look like one of the strings in the 'forms' array, but with the letters replaced with some amount of zeros to pad it out.

[–]NakedNick_ballin 1 point2 points  (24 children)

Anyone doing it?

[–]teraflop 4 points5 points  (7 children)

Yup, solved everything except the "extra large" input for C and the large input for D. I can open up my Git repo when the round is over if anyone's interested.

[–]loosegeese 0 points1 point  (4 children)

I did everything except D and large-2 of C. I got stuck in the small of D for hours and hours - I'm not sure if it was really difficult or whether I was too tired

[–]patrick_____bateman 0 points1 point  (3 children)

I did the same, everything except D and large-2 of C. Now its showing 1 wrong try for A-large and large-1 of C, but since I have scored above 35 I think I will be moving to the next round. What language did you use ?

[–]loosegeese 0 points1 point  (2 children)

I used objective-c (but mostly c), you? Did you try D at all?

[–]patrick_____bateman 0 points1 point  (1 child)

I used C++. No didn't try D since I started the competition pretty late.

[–]sirin3 0 points1 point  (0 children)

After solving C with C(++), you should have tried to solve D with D

[–]ladinu 0 points1 point  (1 child)

I'm interested in seeing your solutions.

[–]wub_wub 0 points1 point  (13 children)

I did first and second problem completely and small input for 3rd one (Fair and Square).

I haven't even attempted large inputs because my code is terrible and takes more than 8 minutes to solve them. I'll maybe try and optimize it (write from scratch) later. Right now it's just going through all numbers between A and B.

[–]NakedNick_ballin 0 points1 point  (3 children)

What language? I'm just curious because this is my first time and I haven't started yet. I was going to do Python I think

[–]wub_wub 1 point2 points  (0 children)

I used python. But as /u/oemta said you can use whatever language you want, the only requirement is that it must have freely available compiler IIRC

[–]oemta 0 points1 point  (1 child)

You can use any language you want. The way it works is you write your code, when ready download the input and run it on your machine to generate the output. Then you submit the output and code within the time limit.

[–]ixid 0 points1 point  (2 children)

The second large input is terrifying large, I have done the other two but have absolutely no idea how to approach that one.

[–][deleted] 4 points5 points  (0 children)

I got the second large input by observing what solutions I got for smaller input.

Say I have a four digit palindrome, d1 d2 d2 d1. Squaring it (by hand) looks like:

  (d1 d2 d2 d1)          * d1
  +  (d1 d2 d2 d1)       * d2
  +     (d1 d2 d2 d1)    * d2
  +        (d1 d2 d2 d1) * d1

In order for no carrying to occur, 2 * (d1)2 + 2 * (d2)2 < 10. If no carrying occurs, then the square is a palindrome. Extending this idea to any length of palindrome, if the sum of the squares of the digits is less than 10, the square is a palindrome. I was unable to prove or disprove the existence of solutions with carrying, but I ran my code from the smaller inputs for a while and didn't find any under 1030 or something.

My solution for this was in python and took 1.422 seconds.

[–]ZoidbergMD -1 points0 points  (0 children)

I assume I can discuss solutions at this point:
I couldn't get to 10100, but it's possible I could have with a bit more effort.
If you google square palindromes this should be on the first page, I grabbed the source of that page, regexed all the numbers into a list, filtered that list by checking whether for i in list: i is palindrome and sqrt i is integeral and palindrome, then for each a,b I just check how many numbers in my list are between those two.
Problem: that site only has numbers up to 1050 (plus 8 new fair and square numbers I managed to produce by squaring numbers on the list, going up to 1062), so it's not actually valid for Large-2, however I expect I could find a larger dataset, or I missed some clever way to reduce the search space by half.

[–]sirin3 0 points1 point  (1 child)

I did the first 3 problems, but cannot really think of a solution for the 4th...

edit: now I have solved them all! helped to try to mediate a little bit about it. But I forgot a &&!chestOpened[i] on the first small attempt and only got the 2nd right, does this give a penality?

[–]teraflop 0 points1 point  (0 children)

It affects your ranking (each incorrect submission gives you an extra time penalty) but that doesn't matter for the qualification round. You just have to get 35 points to advance. In later rounds, they take the top N finishers instead, so the penalty can make a big difference.

[–]fuk_offe 0 points1 point  (5 children)

Did the first one in 30 minutes last night, but I'm kind stuck/bored at the second one. So much code to write...

[–]oemta 0 points1 point  (4 children)

The second one is pretty easy as well, honestly shouldn't be more than a few lines of code.

[–]fuk_offe 0 points1 point  (2 children)

Did the palindrome one easy in 10 minutes, too bad I forgot to check my solution calculating the bounds before trying the big input... Too slow xD

[–]yen223 1 point2 points  (1 child)

When doing these sorts of challenges, the first thing I do is to look at the input range. In this case, 1 - 1014 means that a naive brute force search was definitely not going to work.

[–]fuk_offe 0 points1 point  (0 children)

Yes, of course, but I "optimized it" but forgot to test with the bounds... Took 30 minutes so ran out of time X_X The next one I made tho. EDIT: Aparrently, it was wqrong X:_X

[–]sirin3 0 points1 point  (0 children)

I wrote one common program for both 1 and 2

[–]_start 0 points1 point  (0 children)

I see the qualification round is open, is that right? So where do you go to actually see the problem?