Knapsack problem/Continuous: Difference between revisions
→{{header|Haskell}}: Then again, if we're going to use exact arithmetic, we might as well give exact answers.
Underscore (talk | contribs) (Added Haskell.) |
Underscore (talk | contribs) (→{{header|Haskell}}: Then again, if we're going to use exact arithmetic, we might as well give exact answers.) |
||
Line 42:
import Data.List (sortBy)
import Data.Ord (comparing)
import Data.Ratio (numerator, denominator)
import Text.Printf
Line 70 ⟶ 71:
main = do
forM_ solution $ \(w, b) ->
where f (w, Bounty _ v wtot) = v * (w / wtot)
then show a
else printf "%d %d/%d" a (numerator b) (denominator b)
where a = floor q
b = q - toEnum a</lang>
=={{header|Java}}==
|