I have "n" buckets. For this example, let's say I have 3.

Each of these buckets holds an integer value (at no time can they hold a non-integer), so for this example... 10, 5, and 1

I have a total value "x"... so... 16 in this case. It can also only be an integer value.

I decide I want to change "x" to a new number, and have it update the buckets to new values in proportion to what they currently are. So, if I change it to "26", I need to distribute those "10" I added on to my buckets in a 10:5:1 ratio, as evenly as possible... In the end, the sum in my "n" buckets will equal what I changed "x" to, and will be roughly (though not necessarily exactly) in the same ratio of 10:5:1.

Conventional math using rounding can end up with SUM(buckets(n)) <> x due to rounding errors compounding.

As I said, I was wondering if there was am algorithm out there that handles this already.

Essentially, this is to split a forecasted yearly part-count across 12 months, weighted based on last-years monthly sales

Any response would be greatly appreciated... either a code/pseudocode example or just the name of the algorithm is it already exists. As I said, I'm pretty confident I can come up with something myself, but if this is something more elegantly done before, I don't like reinventing the wheel.

Thanks! ]]>

There are 2 questions that I have (I had help with something related to this previously, but these are newer questions).

1. If you click anywhere in the PictureBox, you will notice the heading in degrees in the Title. I would like to set this up, so if the target is in front of myship, it is always noted as 0/360. If it's to the right, then 90, behind 180, and to the left, 270. How can I set this up so I don't interfere with any calculations in the long run.

2. I added a button, which is empty. I would like to add code, that if I click on the button, myship jumps half way the distance between my ship and the target ship. Also, I would like to add another button, that does the same (it jumps a distance), except I would like that to be an increment of a fixed distance. I am working on figuring out how to close in on the target.

Please bear with me, I have a lot of help from vbforums so far, but I am only now learning to correctly understand the math behind this. I would like to better understand Radians, Degrees, the Trig functions, Pythagorean and etc. So if you could please explain your help, I would appreciate it, for example if you fix the angle notation in question 1, then can you please explain how you made the adjustments in case I want to change the coordinate system, so I actually know what I'm doing.

:sick:

Thank you.

:confused:

Code:

`Public Class frmMain`

Dim myShips As New List(Of Ship)

Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Me.Location = Screen.AllScreens(1).Bounds.Location

CreateShips()

HeadToTarget()

End Sub

Private Sub CreateShips()

myShips.Add(New Ship("MyShip", New Point(500, 750)))

myShips.Add(New Ship("EnemyShip", New Point(500, 350)))

End Sub

Private Sub pbMap_MouseDown(sender As Object, e As MouseEventArgs) Handles pbMap.MouseDown

myShips(0).m_pos = New Point(e.X, e.Y)

pbMap.Invalidate()

HeadToTarget()

End Sub

Private Sub pbMap_Paint(sender As Object, e As PaintEventArgs) Handles pbMap.Paint

For Each s As Ship In myShips

e.Graphics.FillRectangle(Brushes.LemonChiffon, s.m_pos.X - 5, s.m_pos.Y - 5, 10, 10)

e.Graphics.DrawRectangle(Pens.Black, s.m_pos.X - 5, s.m_pos.Y - 5, 10, 10)

e.Graphics.DrawString(s.m_name, New Font("Arial", 12), Brushes.Black, s.m_pos.X + 15, s.m_pos.Y)

Next

End Sub

Private Sub HeadToTarget()

Me.Text = ((180 / Math.PI) * Math.Atan2(myShips(0).m_pos.X - myShips(1).m_pos.X, myShips(0).m_pos.Y - myShips(1).m_pos.Y)).ToString

End Sub

Private Sub btnMove_Click(sender As Object, e As EventArgs) Handles btnMove.Click

End Sub

Private Sub btnMove2_Click(sender As Object, e As EventArgs) Handles btnMove2.Click

End Sub

End Class