Brain smoker ... - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Brain smoker ... (/thread-2612.html) |
Brain smoker ... - DrD - 12-12-2014 02:20 PM 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- RE: Brain smoker ... - Didier Lachieze - 12-12-2014 04:25 PM Nice challenge, it helped me to learn a few things about the Prime !! Here's what I've found:
RE: Brain smoker ... - Nigel (UK) - 12-12-2014 09:18 PM How about Code: sum_list(|a|) * sum_list(|b|) Nigel (UK) RE: Brain smoker ... - Han - 12-12-2014 10:07 PM (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. RE: Brain smoker ... - Gilles - 12-12-2014 11:10 PM Nigel idea is excellent Another way,less efficient : Code:
RE: Brain smoker ... - Han - 12-13-2014 12:53 AM (12-12-2014 11:10 PM)Gilles Wrote: Nigel idea is excellent Are you sure this works for any arbitrary lists a and b? RE: Brain smoker ... - Gilles - 12-13-2014 08:58 AM (12-13-2014 12:53 AM)Han Wrote:(12-12-2014 11:10 PM)Gilles Wrote: Nigel idea is excellent Any arbitrary list...of 2 elements. RE: Brain smoker ... - DrD - 12-13-2014 10:37 AM 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- |