I know how many boards I need and their dimensions. Is there some sort of calculator that can tell me how many long boards to buy so that I lower the cost? For example, I need 2 60" 2x4's and I also need 2 20" 2x4's. You might just buy 2 96" boards and get your cut out of that but it might be cheaper to buy 1 16' 2x4 and get it all out of that. I'm looking for a calculator that has that kind of algorithm.
The question is inherently too subjective for any single calculator. There are whole industries dedicated to this, and even then the software must be constantly amended, and customized to each company's specific use and needs.
Longer material may be cheaper, but that depends heavily on the choice of material, and ability to source the species in those lengths.
Beyond that you must make transportation and tooling constraints. You may not be able to transport a 16' board at all, even if it would be cheaper.
The woodworking software industry is about as fragmented as any, and as a result there are a lot of optimization programs out there that vary across a very wide spectrum, and very rarely are the cheap or free ones very useful.
Even with this, a very high percentage still does things the old fashioned way, cut-listing by hand, or using Excel or some other generic program.
You might be able to do this for dimensional lumber (i.e., your standard 1x and 2x material), since there are several "standard" lengths - 6', 8', and 10' being the most common*, with 12' and 16' being fairly widely available, in the US at least. My local hardwood dealer carries some 7' and 9' pre-milled boards, though, so maybe there aren't any standards... It will also work for plywood since those sheets are standard sizes (4'x8', 5'x5' typically). It is not likely to be available for rough cut lumber because the only standard dimension there is thickness (4/4, 6/4, 8/4, etc).
Looking at this question and this one, though, a lot of people tend to make their own cut lists / layouts because the products that do exist aren't very good, or don't produce layouts which minimize waste. Throw cost into the equation, too, and that adds a whole layer of complexity that most programs don't even try to tackle.
Your best bet is to get Sketchup (available for free) or a similar piece of software, or break out the good 'ol graph paper, and try several different layouts yourself. You know what sizes your local store carries and so you can come up with a couple different layouts for the typical lengths available in your area.
*Given that you said 2x4, I assume you're buying from the big box stores and not buying from a specialized (hard)wood shop. Those are the typical sizes at my local big box stores; YMMV of course.