2

first off I'm going to say I don't know a whole lot about theory and such. But I was wondering if this was an NP or NP-complete problem. It specifically sounds like a special case of the subset sum problem.

Anyway, there's this game I've been playing recently called Alchemy which prompted this thought. Basically you start off with 4 basic elements and combine them to make other elements.

So, for instance, this is a short "recipe" if you will for making elements

fire=basic element
water=basic element
air=basic element
earth=basic element
sand=earth+earth
glass=sand+fire
energy=fire+air
lightbulb=energy+glass

So let's say a computer could create only the 4 basic elements, but it could create multiple sets of the elements. So you write a program to make any element by combining other elements. How would this program process the list the create a lightbulb?

It's clearly fire+air=energy, earth+earth=sand, sand+fire=glass, energy+glass=lightbulb.

But I can't think of any way to write a program to process a list and figure that out without doing a brute force type method and going over every element and checking its recipe.

Is this an NP problem? Or am I just not able to figure this out?

duffymo
  • 305,152
  • 44
  • 369
  • 561
Earlz
  • 62,085
  • 98
  • 303
  • 499

2 Answers2

4

How would this program process the list the create a lightbulb?

Surely you just run the definitions backwards; e.g.

  1. Creating a lightbulb requires 1 energy + 1 glass
  2. Creating an energy requires 1 fire + 1 air

and so on. This is effectively a simple tree walk.

OTOH, if you want the computer to figure out that energy + glass means lightbulb (rather than "blob of molten glass"), you've got no chance of solving the problem. You probably couldn't get 2 gamers to agree that energy + glass = lightbulb!

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • yea, this actually makes sense. for your last comment, in the game it was actually electricity+glass but electricity had a long definition so I shortened it. I think I was seeing the problem in a different way that wasn't reversible like this but didn't phrase it correctly. Anyway this is the correct answer for how I phrased it though – Earlz Nov 29 '10 at 03:06
3

You can easily model your problem as a graph and look for a solution with any complete search algorithm. If you don't have any experience, it might also help to look into automated planning. I'm linking to that text because it also features an introduction on complexity and search algorithms.

Jim Brissom
  • 31,821
  • 4
  • 39
  • 33