I know next to zilch about C# so I won't be much help with this review, but I can say that it looks well thought out and implements some cool features. And like retailcoder I'm still working on my version (hoping to minimize the brute-force portion) using Ruby.
If C# allows enums to implement methods, I would move CombineSolvedState
into SudokuProgress
. Forgive my Java syntax, but if this is allowed I expect it will be easy to translate.
public enum SudokuProgress {
public SudokuProgress CombineSolvedState(SudokuProgress solved) {
if (this == SudokuProgress.FAILED)
return this;
if (this == SudokuProgress.NO_PROGRESS)
return solved;
if (this == SudokuProgress.PROGRESS)
return solved == SudokuProgress.FAILED ? solved : this;
throw new InvalidOperationException("Invalid value for " + this);
}
FAILED, NO_PROGRESS, PROGRESS
}
I think this SO question addresses the issue, and one answer says it's not directly possible without using a class instead of an enum while another implies that it can be done using extensions.
Also, can't you use enums in a switch
statement instead of a series of if
s?
- 8.9k
- 1
- 27
- 44