The problem I have is trivial. But then I start an algorithm to solve it, and it gets so convoluted and uggly that I just can't bare it. There must be a much more elegant solution that I'm missing.
The problem, as stated, doesn't sound like much. I have 3 variables that can have 3 valid states, and an invalid one (showing that the variable has not yet been assigned a valid value).
Any of the variables can have any valid state, but they must all have a different one (i.e. every valid value must be assigned to a variable).
Initially, it is possible for all three variables to be invalid, or for one or two of them to already have a valid value. The algorithm must do nothing more than find out which values are still available and assign them to the available variables. It doesn't matter which one goes to which one.
Sounds simple, and probably is, but I'm getting into a nasty spaghetti pot. Can anyone tell me how to solve the problem with as simple an algorithm as possible (pseudo-code or real code, doesn't really matter).
The problem, as stated, doesn't sound like much. I have 3 variables that can have 3 valid states, and an invalid one (showing that the variable has not yet been assigned a valid value).
Any of the variables can have any valid state, but they must all have a different one (i.e. every valid value must be assigned to a variable).
Initially, it is possible for all three variables to be invalid, or for one or two of them to already have a valid value. The algorithm must do nothing more than find out which values are still available and assign them to the available variables. It doesn't matter which one goes to which one.
Sounds simple, and probably is, but I'm getting into a nasty spaghetti pot. Can anyone tell me how to solve the problem with as simple an algorithm as possible (pseudo-code or real code, doesn't really matter).