Back to General discussions forum
This was inspired by a shop-window display at Christmas.
Rodion, the relevant files are in your e-mail.
Dear Clive, Hi!
Thanks for this nice problem - and also for notification as it served as a kind reminder about some forgotten things to do!
It would be curious to see that shop-window but I guess it was not left working too long after Christmas?
Oh, hm, wrong account again - just switched to see if the problem works properly.
Unless I'm much wrong I understand how to solve it! Hopefully shall try bit later today!
Nice problem! A word of caution though: if you are really unlucky, the result could be so large that it won't fit into a typical 64-bit integer - not a problem for Python but important for many other languages.
Mathias,
Thanks for spotting this. I thought that I had written the code to keep answers below 2^64. After re-reading it I can see a small possibility for a greater number to creep in, but it seemed very unlikely.
I ran the routine for 1000 times in order to count the number of times the answer was too big. I never got one hit! You have been unfortunate to come across one. I could rewrite the setter code but with such a small probability there seems little point.
Thanks for the two interesting problems that you submitted. I wonder where the bunnies will crop up next!
Mathias,
I have looked again at my code and am now confused. The answer should never be as large as 2^63 so should fit into a signed integer. I have carried out several thousand more test runs and the answer is always less than 2^63. I cannot understand why one of your runs produced something larger. Did you keep the test data by any chance?
Hi, this is very very unlikely to happen with random positions, and it didn't happen to me. I don't think anything needs to be changed here. On other sites / platforms though, this would be a good candidate for "hacking". I had an issue with 32-bit integers being too small, and then I wondered what the max value might be (which is a whole puzzle in itself).
For anyone intending to solve the problem using C++ or similar, I can confirm that the problem does not create answers which are too big for int 64 data types. In fact the maximum possible answer is guaranteed to be less than one tenth the size of int 63.