How to resolve the algorithm Knapsack problem/Unbounded step by step in the Ursala programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Knapsack problem/Unbounded step by step in the Ursala programming language

Table of Contents

Problem Statement

A traveler gets diverted and has to make an unscheduled stop in what turns out to be Shangri La.   Opting to leave, he is allowed to take as much as he likes of the following items, so long as it will fit in his knapsack, and he can carry it. He knows that he can carry no more than   25   'weights' in total;   and that the capacity of his knapsack is   0.25   'cubic lengths'. Looking just above the bar codes on the items he finds their weights and volumes.   He digs out his recent copy of a financial paper and gets the value of each item.

He can only take whole units of any item, but there is much more of any item than he could ever carry

Show how many of each item does he take to maximize the value of items he is carrying away with him.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Knapsack problem/Unbounded step by step in the Ursala programming language

Source code in the ursala programming language

#import nat
#import flo

vol = iprod/<0.025,0.015,0.002>+ float*
val = iprod/<3000.,1800.,2500.>+ float*
wgt = iprod/<0.3,0.2,2.0>+ float*

packings = ~&lrlrNCCPCS ~&K0=> iota* <11,17,13>

solutions = fleq$^rS&hl |=&l ^(val,~&)* (fleq\25.+ wgt)*~ (fleq\0.25+ vol)*~ packings

#cast %nmL

human_readable = ~&p/*<'panacea','ichor','gold'> solutions

  

You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Draco programming language
You may also check:How to resolve the algorithm Function frequency step by step in the C programming language
You may also check:How to resolve the algorithm Conjugate transpose step by step in the Perl programming language
You may also check:How to resolve the algorithm Harshad or Niven series step by step in the D programming language
You may also check:How to resolve the algorithm Atomic updates step by step in the Raku programming language