Hard to find a better title.

In a game you can have many progress bars: health, mana, spells, etc that use attribute points. I want to create a script that helps you determine the easiest way to level off each of them to purchase another object.

For example

HP: 60, 12 per hour Mana: 80, 17 per hour Spells: 31, 7 per hour NEW SPELL: requires 51 HP, 107 mana, 38 spells
We have three things to note: the identifier, the total on hand (first number) and the amount they earn per hour. Using the above sample, to buy our new spell we'd..
HP: 60 OH, 51 needed, 0 change Mana: 80 OH, 107 needed, +27 change Spells: 31 OH, 38 needed, +7 change
We'd need to add to both mana and spells from any surplus we have (which we have 9 extra from HP we don't need). Unfortunately we don't have enough extra to bring all of them to the min. required to buy the new spell so I want the script to then be smart and determine how to shuffle all of our points where we can meet the requirement FASTEST by taking the total we have now and taking how many we earn per hour into consideration.

In short, I'm trying to shuffle everything to determine 1) Do we already meet the requirement 2) Can we shuffle them where they'll all meet it, and how 3) If we don't have enough, determine how to shuffle the points in such a way where we'd earn the rest fasted (by the amount earned per hour).

I know I won't get a full solution here but if people can help get me started I'd be very grateful.


In reply to Calculate easiest way to 'level results' by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.