Xmas Puzzle 2020 (1)

Also, once a/b are selected that narrows down the choice ...


For that matter if a<c then a<4, which can be proven pretty quickly for the left-hand double equality (a/b=c/d=...), and I am pretty sure with a bit more work also for the right-hand (a/b=c/de-...) as well.
 
I wrote Logix5000 code to test for solutions, but the number of iterations proved too much for the maxed out watchdog, so i gave up and deleted all the code. After deleting all the code I realized I could have done a fault routine and let it carry on regardless... DOH !

One question I have though, is to what precision are the fractions ? pi is nowhere equal to 22/7
 
One question I have though, is to what precision are the fractions ? pi is nowhere equal to 22/7
The fraction I use for pi is 355/113. I used this ratio all the time when programming 16 microprocessors in assembly code.
There are other ratios or series that are even more precise estimated of PI but 355/113 is the most practical one and it provides more precision that is necessary most of the time.
 
I wrote Logix5000 code to test for solutions, but the number of iterations proved too much for the maxed out watchdog, so i gave up and deleted all the code. After deleting all the code I realized I could have done a fault routine and let it carry on regardless... DOH !

One question I have though, is to what precision are the fractions ? pi is nowhere equal to 22/7




I was thinking one permutation per scan. 9! yields around 300k permutations, so at 1-2ms/scan, it would take 5-10minutes to complete.
 
I was thinking one permutation per scan. 9! yields around 300k permutations, so at 1-2ms/scan, it would take 5-10minutes to complete.

I might have another go at this tomorrow - I like the idea that a PLC can solve a problem posted on a PLC forum, even if it takes several minutes ! ....
 
It's a bit more than five minutes though: Heap's Algorithm has a significant fraction of the passes through the main loop that do not generate a permutation; those extra scans could probably be eliminated with a bit more logic.

It takes 986,409 passes through the main loop to get the 300k+ permutations.

RSLogixMicroStarterLite/MicroLogix 1000 example below; it ran about one ms/scan on average, so it was 16-17 minutes, I think; it did find the four basic solutions with a<b and a<c.
 
Last edited:
One of the contentious answers is as follows:



.2/1 = .6/3 = 97/485


This increases the number of combinations somewhat :)
 
I put my PLC code back in to test for solutions, and sort of got it working.

It found 4 solutions (pure solutions that is, nothing sneaky with decimal points and the like).

I wanted to see if it could be done in one scan of the code, so used a series of nested FOR loops, and basically blindly iterating every damn combination. But the I had to do checking in the innermost loop to ensure we had all different values for a-j. This obviously slowed the process considerably, so Heap's algorithm would dramatically reduce the time taken.

First thing the checking did was RETurn if A>=B, or C>=D, then I just matrix checked the others against each other, RET'ing at every conceivable opportunity. If the numbers got through all the checks, I calculated and compared the fractions.

Anyway - it found the 4 solutions as follows.....

1st : @08:10 minutes
2nd : @09:40 minutes
3rd : @15:15 minutes
4th : @17:27 minutes

At 33 minutes in, the task watchdog faulted the processor (I had set it to maximum = 2000 mS), but at the time of faulting the a, b, c, d values were 6, 9, 7, 2 respectively, and I cannot believe there would be any more solutions above that. It's something I could test for by starting a & B at, say 5, and see if any more solutions exist, but I doubt it.

Incidentally, I had written a Program Fault routine to reset the Type 6, Code 1 task watchdog fault, but this did NOT work - Then realised a Task fault should be in the Controller Fault Handler, so I moved my fault handling to there, and it didn't work there either.... I believe the controller won't let you reset a watchdog fault.

So my answer is there are only four possible non-contentious solutions. (We are talking about the left hand equation, haven't thought about the other, yet).
 
It's a bit more than five minutes though: Heap's Algorithm has a significant fraction of the passes through the main loop that do not generate a permutation; those extra scans could probably be eliminated with a bit more logic.
I like brute force but generating all the permutations is not required. You could just start with a list of numbers 1-9 and pass that to a function and then assign one of the numbers to a second list that represents the characters. As one makes recursive calls and the numbers from the list of numbers is used the number is removed from the list. When bad option is found then back up and try another number. The advantage is that you don't generate all the permutations because as soon as an invalid solution is found you back up and don't try the other combinations lower in the tree. This is somewhat how a chess program works but closer to how a lumber optimizer fills a volume with the optimal number and size of boards.

The problem is that PLCs don't have lists but you could get by with bit sets. The problem then is generating an encode or decode function like some of the old PLCs had.
 

Similar Topics

Two brothers were walking down the road. The first brother poses a question to the other: 'If I take the digits 1 through 9 and write them down...
Replies
4
Views
1,751
A mother and child walk down an escalator which is running at constant speed in the downward direction. Once on the escalator, the child walks...
Replies
5
Views
1,997
Find 3 palindromic numbers that, when added together, make 85709 (Numbers are in Base 10) Answers by pm please.
Replies
19
Views
6,465
It was too early for Easter, suppose I could have done Chinese New year, but that's too close to Valentines Day. Two parts : 1. A Logix5000...
Replies
1
Views
1,310
Another puzzle for you - answers by pm again. You have 30 coins which you want to deposit in a bank 10km away. A taxi takes you but can only...
Replies
9
Views
7,569
Back
Top Bottom