[Tutor] Help with silly algorhythm

kevin parks kp87@lycos.com
Fri, 15 Feb 2002 01:01:13 +0900

I have been wanting to ask this one for a while, but it is a bit tricky to articulate so I will try my best.

What I want to do is generate a new list of items based on another list and a some 
criteria (list of accepable values, for example). So, i might have:

* list of input values =[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
* a list of acceptable new 'partner values' = [1, 3, 7, 10]

and I want a new list made up of the closest member of a list (modulo the
number of list members: here 12 (0-11) of acceptable values 
in 4 different ways [upper, lower, or alternating (starting higher, starting lower)]

All with the further stipulation that values from the input list do not team with values
in the "buddy" list if they are the same, so input 1 would not go with 1 from list 2, but
with 3 (the next value up),  or 10 (next value down).

vague i know, i am trying my best...

so we might get (in mode 1: all closest higher value)

 [ [0, 1], [1, 3], [2, 3], [3, 7], [4, 7], [5, 7], [6, 7], [7, 11]....


[1,   3,  3, 7, 7, 7, 7, 11.....]

mode 2 (all closest value down) might be:

[[0,10], [1, 10], [2, 1], [3, 1], [4, 3], [5,3], [6,3], [7,3], [8, 7]....

mode 3

[ [0, 1], [1, 10], [2, 3], [3, 1].....


So problem number one for me is how do i figure out which value is
'closest' (up or down), do i have to test it against each value of the list
or is there a smarter way.

I realize that this is very odd and convoluted. If it is too stupid a question
please feel free to snub it.

I know i have asked a lot of this list lately and have recieved some
very helpful responses. I am trying to get as much Python in as possible
before the holiday is over.


meanwhile i am pouring over the last few tutor digests...

Love is in the Air!

Check out Cupid School where you will learn from Matchmaker's
best and brightest.

At Cupid School you'll learn how to pair up hopeful romantics
with one another, based on their personal preferences.
If you do well- you'll be rewarded with your own
set of love bow and arrows!

Good Luck!