My current program demonstrates this very well.

Could you show us that program, or at least a short version of it? (SSCCE) Also, this sounds like a case where you might benefit from a test-first approach: even if you don't have the body of your function yet, you can still write tests using Test::More to test this hypothetical function. Not only will it help you see how close you're getting while you're developing, it'll help us understand your problem description better :-)

use warnings; use strict; use Test::More; sub my_func { my $target = shift; my @weights = @_; my @output = (); # TODO! return \@output; } is_deeply my_func(30, 7,10,13), [10,10,10]; is_deeply my_func( 5, 3,7,11), [3,3]; # TODO: lots more test cases! done_testing;
If it were all in whole numbers it would be trivial.

In my experience integers are much easier to work with, and you don't suffer from floating-point imprecisions. I'd suggest switching to milligrams, micrograms, etc. - for example, my Perl (64 bit) can handle integers up to 9007199254740992 without loss of precision. (source)


In reply to Re: optimization problem by haukex
in thread optimization problem by spencoid

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.