lootsack

lootsack is a small C suite that frames the classic 0/1 knapsack problem as a treasure-hauling dilemma: given a pile of randomly generated loot — coins, crowns, daggers, gems, necklaces, rings, swords — and a maximum weight an adventurer can carry, pick the subset that maximizes total gold-piece value.

Goals

Programs

How it works

Treasure types have per-type weight and value ranges (lootsack.c) and a sampling frequency that makes coins common and swords rare. The generator (generate.c) uses arc4random_uniform to draw a type and then random weight/value within that type's bounds. The selection routine in main.c sorts by a fixed-point value-per-weight ratio and greedily takes items that still fit — a fast approximation, not an optimal solver. A heap-based and a true dynamic-programming solver are tracked as future work in the README.

Source files