Brain smoker ...
|
12-12-2014, 02:20 PM
(This post was last modified: 12-13-2014 10:37 AM by DrD.)
Post: #1
|
|||
|
|||
Brain smoker ...
This was my challenge of the day:
Find the sum of the absolute values of the products, of all the pairs of numbers, where one is drawn from each of two lists: Example a:={2,-3} b:={4,-5} This is the goal: (Absolute values of the above): 2*4 + 2*5 +3*4 +3*5 = 45 I tried a few things and came up with this: sum(mat2list(map(a,(a)->ABS(a*b)))) which seems to be my best effort (so far!) If you feel so inclined, can you find other (hp prime) ways, perhaps more efficient in some way? -Dale- |
|||
12-12-2014, 04:25 PM
Post: #2
|
|||
|
|||
RE: Brain smoker ...
Nice challenge, it helped me to learn a few things about the Prime !!
Here's what I've found:
|
|||
12-12-2014, 09:18 PM
Post: #3
|
|||
|
|||
RE: Brain smoker ...
How about
Code: sum_list(|a|) * sum_list(|b|) Nigel (UK) |
|||
12-12-2014, 10:07 PM
(This post was last modified: 12-12-2014 10:08 PM by Han.)
Post: #4
|
|||
|
|||
RE: Brain smoker ...
(12-12-2014 09:18 PM)Nigel (UK) Wrote: How about sum(abs(a))*sum(abs(b)) will do what you proposed. The multiplication described seems like a simple distribution (unless I misread the original post) \[ (a_1 + a_2 + a_3 + \dotsm + a_n) ( b_1 + b_2 + b_3 + \dotsm + b_m ) =\] \[ a_1 \cdot ( b_1 + b_2 + b_3 + \dotsm + b_m ) + a_1 \cdot ( b_1 + b_2 + b_3 + \dotsm + b_m ) + \dotsm + a_n \cdot ( b_1 + b_2 + b_3 + \dotsm + b_m ) \] but with absolute values of each term. Graph 3D | QPI | SolveSys |
|||
12-12-2014, 11:10 PM
(This post was last modified: 12-12-2014 11:28 PM by Gilles.)
Post: #5
|
|||
|
|||
RE: Brain smoker ...
Nigel idea is excellent
Another way,less efficient : Code:
|
|||
12-13-2014, 12:53 AM
Post: #6
|
|||
|
|||
RE: Brain smoker ...
(12-12-2014 11:10 PM)Gilles Wrote: Nigel idea is excellent Are you sure this works for any arbitrary lists a and b? Graph 3D | QPI | SolveSys |
|||
12-13-2014, 08:58 AM
Post: #7
|
|||
|
|||
RE: Brain smoker ... | |||
12-13-2014, 10:37 AM
Post: #8
|
|||
|
|||
RE: Brain smoker ...
Several different methods, all accomplishing the objective. Han's breakdown, as a simple distribution, seems to be the easiest, human readable, and concise formula. Each of the other solutions provide very novel approaches, and provide a great way to explore some of the inner reaches of the prime.
This challenge was a spinoff of a problem posed for a Python procedure, using list comprehension. After finally getting a suitable Python solution, I couldn't resist the temptation to find a similar hp prime result. All told, this is a neat example of distributed processing, in both human and hardware! Thanks for all the great responses! -Dale- |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)