having trouble with a mathmatical function

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2009
Posts: 50
Reputation: lukerobi is an unknown quantity at this point 
Solved Threads: 16
lukerobi lukerobi is offline Offline
Junior Poster in Training

having trouble with a mathmatical function

 
0
  #1
Oct 4th, 2009
lets say i have 2 lists:
lista = [1,2,3,5,6,7]
listb = [4,5,6,7,8,9,10]

The lists can be different lengths, and may not allways be unequal lengths.

The higher average will allways be in listb, so that is the 1 constant we can rely on.

This works for even teams:
  1. average = float(sum(lista) + sum(listb)) / \
  2. float(len(lista) + len(listb))
  3.  
  4. value = round(abs((average * len(lista)) - sum(lista)))

value would return the number i needed to move from listb to lista

i tried this,but it doesnt seem to work:
  1. Offset = float(len(listb) - len(lista))
  2.  
  3. value = round(((len(lista) * sum(lista)) + \
  4. (len(lista) * Offset) - \
  5. (average * len(lista) - \
  6. (average * Offset))) / \
  7. (len(lista) * Offset))

any ideas?
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,614
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 131
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso
 
0
  #2
Oct 6th, 2009
Huh? You've said what you've done, but not what you're trying to do...
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 7
Reputation: JohnboyUK is an unknown quantity at this point 
Solved Threads: 0
JohnboyUK JohnboyUK is offline Offline
Newbie Poster

2 Lists

 
0
  #3
Oct 6th, 2009
Is the function a fictitious theory or for a specific reason?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #4
Oct 7th, 2009
You are getting tangled up in a forest of parenthesis. There is one missing in the mess. It is best to break things into smaller parts ...
  1. list_a = [1,2,3,5,6,7]
  2. list_b = [4,5,6,7,8,9,10]
  3. # for convenience
  4. list_ab = list_a + list_b
  5.  
  6. average = float(sum(list_ab))/len(list_ab)
  7. offset = float(len(list_b) - len(list_a))
  8.  
  9. a = len(list_a) * sum(list_a)
  10. b = len(list_a) * offset
  11. c = average * len(list_a)
  12. d = average * offset
  13.  
  14. value = (a + b - c - d)/b
  15.  
  16. print value
  17. print round(value)
Last edited by vegaseat; Oct 7th, 2009 at 10:58 am.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC