Click here to Skip to main content
15,894,410 members
Home / Discussions / Algorithms
   

Algorithms

 
Questiondetect recursion during compilation Pin
invader8215-Jul-10 22:46
invader8215-Jul-10 22:46 
AnswerRe: detect recursion during compilation Pin
Alan Balkany16-Jul-10 4:04
Alan Balkany16-Jul-10 4:04 
AnswerRe: detect recursion during compilation Pin
Peter_in_278016-Jul-10 14:41
professionalPeter_in_278016-Jul-10 14:41 
AnswerRe: detect recursion during compilation Pin
T M Gray23-Jul-10 6:27
T M Gray23-Jul-10 6:27 
AnswerRe: detect recursion during compilation [OpenCL] Pin
ProtoBytes25-Jul-10 8:50
ProtoBytes25-Jul-10 8:50 
QuestionDistributing (different sized) objects Pin
Wjousts15-Jul-10 4:30
Wjousts15-Jul-10 4:30 
AnswerRe: Distributing (different sized) objects Pin
Alan Balkany16-Jul-10 4:01
Alan Balkany16-Jul-10 4:01 
GeneralRe: Distributing (different sized) objects Pin
Wjousts16-Jul-10 4:29
Wjousts16-Jul-10 4:29 
Okay, here's what I have. It seems to produce reasonable results, but I'm open to suggestions for making it more efficient (also, there might be flaws in my logic that I just haven't found yet). For distributing objects horizontally:

- Give an set of objects
- Iterate through the set and find the object with the left-most edge (leftObj) and the value for its left edge (left), and the object with the right-most edge (rightObj) and the value for its right edge (right). Left and right define the limits of my space and leftObj and rightObj don't need to be moved.
- The range in which to distribute the remaining objects is the (left-most edge of rightObj) - (right-most edge of leftObj).
- Now, from my set of objects, I must remove leftObj and rightObj (since they don't move) and sort the remaining objects by their left-most edge (maybe center would be better here?)
- Iterate through my new set of objects and subtract the widths of each object from the range. What's left at the end is the space I need to distribute between the remaining objects.
- Define step as the remaining range divided by the number of object remaining plus 1.
- Define position (where to put the first object) as the right-most edge of leftObj + step.
- Iterate through the remaining objects - for each object set the left-most edge to position. Then increase position by step + the width of this object.

So there you have it. I have to iterate through my list of objects at least 3 times, and I need to sort them once. The number of objects is never likely to be very large, and execution speed on my development laptop is essentially instant, but that doesn't mean I'm not interested in how to make it more efficient purely from an academic point-of-view.
GeneralRe: Distributing (different sized) objects Pin
Alan Balkany16-Jul-10 4:37
Alan Balkany16-Jul-10 4:37 
GeneralRe: Distributing (different sized) objects Pin
Wjousts16-Jul-10 5:40
Wjousts16-Jul-10 5:40 
GeneralRe: Distributing (different sized) objects Pin
Alan Balkany16-Jul-10 5:50
Alan Balkany16-Jul-10 5:50 
GeneralRe: Distributing (different sized) objects Pin
Wjousts20-Jul-10 3:31
Wjousts20-Jul-10 3:31 
GeneralRe: Distributing (different sized) objects Pin
Wjousts20-Jul-10 7:56
Wjousts20-Jul-10 7:56 
GeneralRe: Distributing (different sized) objects Pin
Alan Balkany20-Jul-10 8:01
Alan Balkany20-Jul-10 8:01 
AnswerRe: Distributing (different sized) objects Pin
Luc Pattyn16-Jul-10 5:54
sitebuilderLuc Pattyn16-Jul-10 5:54 
GeneralRe: Distributing (different sized) objects Pin
Alan Balkany16-Jul-10 6:06
Alan Balkany16-Jul-10 6:06 
GeneralRe: Distributing (different sized) objects Pin
Wjousts20-Jul-10 3:30
Wjousts20-Jul-10 3:30 
GeneralRe: Distributing (different sized) objects Pin
Luc Pattyn20-Jul-10 8:11
sitebuilderLuc Pattyn20-Jul-10 8:11 
GeneralRe: Distributing (different sized) objects Pin
Wjousts20-Jul-10 9:14
Wjousts20-Jul-10 9:14 
GeneralRe: Distributing (different sized) objects Pin
Luc Pattyn20-Jul-10 9:38
sitebuilderLuc Pattyn20-Jul-10 9:38 
QuestionGetting all combinations of N sets of objects iteratively Pin
gantww11-Jul-10 15:58
gantww11-Jul-10 15:58 
AnswerRe: Getting all combinations of N sets of objects iteratively Pin
Alan Balkany15-Jul-10 3:55
Alan Balkany15-Jul-10 3:55 
QuestionMy sorting algorithm Pin
AksharRoop6-Jul-10 4:53
AksharRoop6-Jul-10 4:53 
AnswerRe: My sorting algorithm Pin
Luc Pattyn6-Jul-10 5:20
sitebuilderLuc Pattyn6-Jul-10 5:20 
GeneralRe: My sorting algorithm Pin
AksharRoop6-Jul-10 5:24
AksharRoop6-Jul-10 5:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.