July 2018 little math problem
|
07-25-2018, 08:52 PM
(This post was last modified: 07-25-2018 08:53 PM by pier4r.)
Post: #1
|
|||
|
|||
July 2018 little math problem
I should really collect all those little problems in one place :/
The problem should be solved ideally with pen and paper. Of course computing devices are allowed as last resort. One has the numbers 1,2,3,4,5,6,7,8,9 and should arrange them in the following position without repetition. Code:
What are the arrangements? How many are there? Of course would be nice to know the way you picked to solve the problem. Code:
Wikis are great, Contribute :) |
|||
07-25-2018, 09:33 PM
(This post was last modified: 07-25-2018 09:35 PM by Voldemar.)
Post: #2
|
|||
|
|||
RE: July 2018 little math problem
Code:
|
|||
07-25-2018, 10:27 PM
(This post was last modified: 07-25-2018 10:40 PM by Thomas Klemm.)
Post: #3
|
|||
|
|||
RE: July 2018 little math problem
I just used brute force.
Code: Spoiler alert! |
|||
07-26-2018, 12:16 AM
(This post was last modified: 07-26-2018 04:53 PM by Albert Chan.)
Post: #4
|
|||
|
|||
RE: July 2018 little math problem
(07-25-2018 10:27 PM)Thomas Klemm Wrote: I just used brute force. I did solved Thomas third solution by hand. If using computer is allowed, I would use Picat Programming Language It is great for puzzle solving, and very fast (below code take 0.12 second to run) Code: import cp. % zigzag4.pi, 4 sums added to same number S |
|||
07-26-2018, 12:57 AM
(This post was last modified: 07-28-2018 04:36 PM by John Keith.)
Post: #5
|
|||
|
|||
RE: July 2018 little math problem
(07-25-2018 10:27 PM)Thomas Klemm Wrote: I just used brute force. So did I! Emulated HP 50g with the ListExt Library took 3437 seconds on an ancient WinXP laptop. Same results. Edit: my original code was atrociously bad. New "brute force" code is shorter and trims execution time down to 1272 seconds. Code:
|
|||
07-26-2018, 02:39 AM
Post: #6
|
|||
|
|||
RE: July 2018 little math problem
Code: I noticed the middle number e cannot be 5, below is the prove. |
|||
07-26-2018, 03:42 AM
Post: #7
|
|||
|
|||
RE: July 2018 little math problem
(07-26-2018 12:16 AM)Albert Chan Wrote: If using computer is allowed, I would use Picat Programming LanguageInteresting. Never heard of that language. I just used Python: Code: from itertools import permutations |
|||
07-26-2018, 04:03 AM
Post: #8
|
|||
|
|||
RE: July 2018 little math problem
(07-26-2018 12:57 AM)John Keith Wrote: So did I! ...and yet another "brute force" method using ListExt with a slight twist on the check. Code:
|
|||
07-26-2018, 12:36 PM
(This post was last modified: 07-26-2018 02:56 PM by pier4r.)
Post: #9
|
|||
|
|||
RE: July 2018 little math problem
(07-26-2018 12:57 AM)John Keith Wrote: Emulated HP 50g with the ListExt Library took 3437 seconds on an ancient WinXP laptop. Same results. one hour on an emulated system that will be at least a pentium 3 and more likely a pentium 4 or the like? Woah. I was expecting the 50g to be wicked fast, of course not entirely by brute force. When I solved it by hand (a couple of solutions) I noticed a weak pattern (n1), if I find the time I will put it on the 50g to see how much it takes to find every solution. (n1) I do believe there is a strong pattern. Mine is pretty weak but I didn't discover the strong one yet in the post, maybe because I did not stricly check the posted code. Wikis are great, Contribute :) |
|||
07-26-2018, 01:03 PM
Post: #10
|
|||
|
|||
RE: July 2018 little math problem | |||
07-26-2018, 03:38 PM
(This post was last modified: 07-26-2018 04:14 PM by DavidM.)
Post: #11
|
|||
|
|||
RE: July 2018 little math problem
(07-26-2018 01:03 PM)John Keith Wrote: Actually not brute force as it uses analysis of the problem. Well, I was thinking that any method based on visiting every permutation would be considered "brute force", though I see your point. Here's another method that doesn't visit every permutation. It only permutes the remaining variables if the currently selected branches qualify. You might say that it's a wee bit faster. This one I would definitely not call "brute force". edit: I just ran this on a real 50g, and it found the same 96 solutions in about 27 minutes. I'm sure this isn't the fastest possible approach on this platform, but it's certainly much better than my first attempt! The Prime (or a newRPL 50g) should be able to do something like this much faster. Code: Spoiler alert... |
|||
07-26-2018, 03:43 PM
Post: #12
|
|||
|
|||
RE: July 2018 little math problem
(07-26-2018 12:36 PM)pier4r Wrote: I do believe there is a strong pattern. Mine is pretty weak but I didn't yet see it, maybe because I did not strictly check the posted code. We can start with \(e\in\{1\ldots9\}\). And then let \(c\) and \(g\) be different digits with \(c<g\). This gives us \(9\times\binom{8}{2}=252\) possibilities. But since \(s=a+b+c=c+d+e=e+f+g=g+h+i\) and \(a+b+c+d+e+f+g+h+i=\sum_{k=1}^{9}k=45\) we know that their sum is \(4s=45+c+e+g\) which must be divisible by 4. This reduces the possibilities further down to 60. We can now calculate \(d=s-c-e\) and \(f=s-e-g\) and check that both are digits. And of course each element of \(\{c,d,e,f,g\}\) must be unique. With this we're down at 12 possibilities: Code: Spoiler alert! Now it's easy to find \(a\) and \(b\) so that \(a+b+c=s\) and similarly find \(h\) and \(i\) so that \(g+h+i=s\). Code: Spoiler alert! Checking only 252 instead of 9! = 362,880 possibilities speeds us up by the factor 1,440. Even checking that 45+c+e+g is divisible by 4 is rather simple. Thus here's a program for the HP-42S that lists possible tuples "c:d:e:f:g". You have to weed some of them out though. But that's still easier than doing the whole calculation manually. Code: Spoiler alert! Make sure to have the display mode set to ALL. This will lead to a list like this: 6:2:9:0:8 → discard since f=0 is not valid 5:3:9:-1:9 → discard since f=-1 is not valid 4:3:9:1:6 → this is a valid solution ... Cheers Thomas |
|||
07-26-2018, 06:16 PM
(This post was last modified: 07-26-2018 07:21 PM by Albert Chan.)
Post: #13
|
|||
|
|||
RE: July 2018 little math problem
(07-26-2018 03:42 AM)Thomas Klemm Wrote:(07-26-2018 12:16 AM)Albert Chan Wrote: If using computer is allowed, I would use Picat Programming LanguageInteresting. Never heard of that language. Picat is a declarative language, based on B-Prolog. All you need is to describe the problem, and it take care of the rest. Using symmetry, sum constraint, the program now run much faster. Picat solved a 9-sided zigzag under 2 minutes: 33452 * 8 = 267616 solutions. If result saved to file, Picat only take 51 seconds. My computer pre-dated Win-XP, so is not fast (I later upgraded Win-XP on it) My guess is Picat does not go brute force by visiting all permutations ... Code: import cp. % zigzag9.pi, all 9 sides sum to same S Edit: Re-reading Thomas last post. My code had exactly the same idea. Symmetry reduce the problem to one eighth its size ... |
|||
07-26-2018, 10:45 PM
Post: #14
|
|||
|
|||
RE: July 2018 little math problem
I have solved the puzzle by hand (no calculator)
Code: To reduce the permutations, I force c < g, and ignore the edges a, b, h, i (for now) |
|||
07-27-2018, 01:30 AM
Post: #15
|
|||
|
|||
RE: July 2018 little math problem
.
Hi, Albert Chan: I'm on the very verge of going on a trip to start my summer vacations so I haven't had much time, if any, to devote to this nice problem by pier4r. From the top of my head I just had the time to concoct a quik'n'dirty 6-lines of HP-71B code (main program) which calls another simple 6-line subprogram to perform an essentially brute-force search with a few refinements, which finds all solutions very quickly but I have no time to post it here right now, I must go. Nevertheless, a cursory read of the already existing posts made me realize that yet another symmetry is lacking from all solutions so far (if I read the posts correctly, read them really fast). Albert Chan Wrote:Add back missing digits to confirm above 12 cases. All confirmed ! Each solution actually represent 8 solutions, by head swap, tail swap and reverse the digits. Close but no cigar. Actually there are only 6 primary solutions, not 12, each one of them representing 16 derived solutions, not 8. You mention head swap, tail swap and reverse the digits but you missed 10's-complementing the digits:
Albert Chan Wrote:SUM SOLUTIONS Your first 6, say, can be considered the 6 primary solutions. But the remaining 6 are actually derived from them and so aren't primary. For instance, your first solution is: 13 391847256 and your last (12th) solution can be derived from it by simply 10-complementing it (and in your case, reversing the digits), like this: [13, 391847256 ] -> [30-13, (10-3)(10-9)(10-1)...(10-2)(10-5)(10-6)] -> [17, 719263854] and after reversing the digits we get: 17 458362917, which is your 12th solution indeed. In the same fashion you can derive your 11th solution from the 2nd primary, the 10th solution from the 3rd primary, and so on until deriving your 7th solution from the 6th primary. Sorry but absolutely no time for more, will be back next September, have a nice summer. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
07-27-2018, 03:06 AM
(This post was last modified: 07-27-2018 12:23 PM by Albert Chan.)
Post: #16
|
|||
|
|||
RE: July 2018 little math problem
(07-27-2018 01:30 AM)Valentin Albillo Wrote: your last (12th) solution can be derived from it by simply 10-complementing it (and in your case, reversing the digits), like this: Hi, Valentin, Nice catch. That shorten my hand calculations by half. :-) For this puzzle, center (sum = 15) has no solution, so N-complement symmetry has a clean cut. But, if center has solution, and other symmetries are involved, it is hard. A sure way is to build all the center solutions first, go through the list, and remove its N-complement. Unfortunately, it may be hard to spot, possibly mask by other symmetry. Each center solution has to check if it's N-complement equivalent had already shown. That may be more trouble than it is worth ... Note: zigzag side must have the same length, otherwise N-complement symmetry is gone. |
|||
07-27-2018, 08:20 AM
Post: #17
|
|||
|
|||
RE: July 2018 little math problem
Hello,
Prime version: Brute force, executes in ~7s on my prime. Code:
Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
07-27-2018, 10:03 AM
Post: #18
|
|||
|
|||
RE: July 2018 little math problem
(07-26-2018 03:43 PM)Thomas Klemm Wrote: But since \(s=a+b+c=c+d+e=e+f+g=g+h+i\) and \(a+b+c+d+e+f+g+h+i=\sum_{k=1}^{9}k=45\) we know that their sum is \(4s=45+c+e+g\) which must be divisible by 4. This was the same point I reached, then I worked on the multiples of 4. I was not expecting such an healthy thread (n1) for a problem apparently simple. n1: thanks to this thread I also realize that even if someone posted already a super efficient solution, having other point of views - even with less efficient solutions - gives other perspective and increase the possibility to confront/compose ideas. Thus making the thread more enjoyable. Wikis are great, Contribute :) |
|||
07-27-2018, 03:37 PM
(This post was last modified: 07-27-2018 03:41 PM by Albert Chan.)
Post: #19
|
|||
|
|||
RE: July 2018 little math problem
Discover a way to add Complement Symmetry to solve zigzag puzzles.
Removing center solutions complement equivalent is hard, so the trick is ... not remove it ! This Picat program solve all zigzag puzzles, with sides > 2: Each solution actually represent 8, by head swap, tail swap, or reversing digits. Code: import cp. % Usage: picat zigzag.pi [Sides = 4] For a 4-sided zigzag: I still got 12, but Picat really solved only 6: Complement Symmetry is internalized for a nice speedup. [1,9,4,8,2,7,5,3,6] [9,1,6,2,8,3,5,7,4] [2,8,4,9,1,7,6,3,5] [8,2,6,1,9,3,4,7,5] [3,9,1,8,4,7,2,5,6] [7,1,9,2,6,3,8,5,4] [4,8,2,9,3,5,6,1,7] [6,2,8,1,7,5,4,9,3] [5,8,1,6,7,4,3,2,9] [5,2,9,4,3,6,7,8,1] [6,7,1,5,8,4,2,3,9] [4,3,9,5,2,6,8,7,1] I tried zigzag program with other sides: Code: Sides Time(s) solns x 8 |
|||
07-27-2018, 09:50 PM
(This post was last modified: 07-27-2018 10:40 PM by Albert Chan.)
Post: #20
|
|||
|
|||
RE: July 2018 little math problem
Turns out, my not trying to untangle the complement symmetry was dead on.
If there are any solutions at the center, it is unlikely to reduce primary solutions in half. While playing around with my zigzag.pi, I wanted to see if there is a simple way to "cut" primary solution in half, as suggested by Valentin ... it cannot be done. Code: side primary solutions at the center (sum = 3 * (side + 1)), all solutions is 8X 3-sided zigzag is impossible to cut solutions in half. (3 is odd) 4-sided zigzag can apply complement symmetry because there is nothing in the center. It is actually the exception case. 5-sided zigzag 20 center solutions can be reduced to 16, but not enough to cut in half. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 7 Guest(s)