Rotating Toy Display - A possible New Problem

Back to General discussions forum

CSFPython     2023-02-18 10:31:40

This was inspired by a shop-window display at Christmas.

Rodion, the relevant files are in your e-mail.

TestUser     2023-02-19 07:59:07
User avatar

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!

gardengnome     2023-02-19 16:05:24
User avatar

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.

CSFPython     2023-02-19 16:35:41

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!

CSFPython     2023-02-19 16:54:17

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?

gardengnome     2023-02-19 16:58:39
User avatar

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).

CSFPython     2023-02-19 18:08:10

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.

Please login and solve 5 problems to be able to post at forum