using System.Collections;
using System.Collections.Generic;
public static readonly Item Battery = new Item() { Name = "Battery", Value = 2.4, Weight = 7 };
public static readonly Item Lamp = new Item() { Name = "Lamp", Value = 6.0, Weight = 30 };
public static readonly Item Shoe = new Item() { Name = "Shoe", Value = 2.76, Weight = 13};
public static readonly Item Pencil = new Item() { Name = "Pencil", Value = .14, Weight = 1 };
public static readonly Item Clipboard = new Item() { Name = "Clipboard", Value = .6, Weight = 3 };
public static readonly List<Item> AvailableItems = new List<Item>() {Battery, Lamp, Shoe, Pencil, Clipboard };
public interface IBackpack
int BagWeightLimit { get; }
List<Item> Contents { get; }
public class LootOptimizer
public static void Main()
var backpack = new Backpack();
new LootOptimizer().YOUR_NEW_FUCNTION(backpack);
public class Backpack : IBackpack
public int BagWeightLimit { get; private set; }
public List<Item> Contents { get; private set; }
Contents = new List<Item>();
public int GetRemainingSpace()
var consumed = Contents.Sum(i => i.Weight);
return BagWeightLimit - consumed;
public void PrintSummary()
foreach(var item in Item.AvailableItems)
var count = Contents.Count(i => i == item);
var weight = count * item.Weight;
var val = count * item.Value;
Console.WriteLine(String.Format("{0} - Count: {1} Weight: {2} Value: ${3}", item.Name, count, weight, val));
Console.WriteLine(String.Format("TOTAL - Weight: {0} Value: ${1} Remaining space: {2}", totalWeight, totalValue, BagWeightLimit - totalWeight));