Knapsack problem/Continuous: Difference between revisions
Content added Content deleted
(Omissions of several language solutions.) |
|||
Line 47: | Line 47: | ||
* [[Knapsack problem/0-1]] |
* [[Knapsack problem/0-1]] |
||
<br><br> |
<br><br> |
||
;See also: |
;See also: |
||
Line 54: | Line 53: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{output?|Ada|reason}} |
|||
<lang Ada>with Ada.Text_IO; |
<lang Ada>with Ada.Text_IO; |
||
with Ada.Strings.Unbounded; |
with Ada.Strings.Unbounded; |
||
Line 159: | Line 158: | ||
=={{header|GNU APL}}== |
=={{header|GNU APL}}== |
||
{{output?|GNU APL|reason}} |
|||
<lang APL> |
<lang APL>⍝ Data |
||
⍝ Data |
|||
Items←'beef' 'pork' 'ham' 'greaves' 'flitch' 'brawn' 'welt' 'salami' 'sausage' |
Items←'beef' 'pork' 'ham' 'greaves' 'flitch' 'brawn' 'welt' 'salami' 'sausage' |
||
Weights←3.8 5.4 3.6 2.4 4 2.5 3.7 3 5.9 |
Weights←3.8 5.4 3.6 2.4 4 2.5 3.7 3 5.9 |
||
Line 175: | Line 173: | ||
</lang> |
</lang> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
⚫ | |||
⚫ | |||
⚫ | |||
BEGIN { |
BEGIN { |
||
# arr["item,weight,price"] |
# arr["item,weight,price"] |
||
Line 272: | Line 269: | ||
END</lang> |
END</lang> |
||
Output: |
Output: |
||
<pre> |
<pre>Take all the salami |
||
Take all the salami |
|||
Take all the ham |
Take all the ham |
||
Take all the brawn |
Take all the brawn |
||
Line 361: | Line 357: | ||
) |
) |
||
);</lang> |
);</lang> |
||
Output:<pre>3.5 kg of welt |
|||
<pre>3.5 kg of welt |
|||
2.4 kg of greaves |
2.4 kg of greaves |
||
2.5 kg of brawn |
2.5 kg of brawn |
||
Line 503: | Line 498: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{output?|C++|reason}} |
|||
⚫ | |||
#include<iostream> |
<lang cpp>#include<iostream> |
||
#include<algorithm> |
#include<algorithm> |
||
#include<string.h> |
#include<string.h> |
||
Line 598: | Line 593: | ||
return 0; |
return 0; |
||
⚫ | |||
} |
|||
</lang> |
|||
===Alternate Version=== |
===Alternate Version=== |
||
<lang cpp> |
<lang cpp>// C++11 version |
||
// C++11 version |
|||
#include <iostream> |
#include <iostream> |
||
#include <vector> |
#include <vector> |
||
Line 656: | Line 648: | ||
space -= item.weight; |
space -= item.weight; |
||
} |
} |
||
⚫ | |||
} |
|||
</lang> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Line 1,974: | Line 1,965: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
{{output?|OCaml|reason}} |
|||
<lang ocaml>let items = |
<lang ocaml>let items = |
||
[ "beef", 3.8, 36; |
[ "beef", 3.8, 36; |
||
Line 3,038: | Line 3,029: | ||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
{{incorrect|Run BASIC}} |
|||
<lang runbasic>dim name$(9) |
<lang runbasic>dim name$(9) |
||
dim wgt(9) |
dim wgt(9) |