public override string FirstStar() { var states = TheHaltingProblem.BuildStates(); var result = TheHaltingProblem.DiagnosticChecksum("A", 12317297, states); return(result.ToString()); }
public static void FirstStarExample() { var states = new Dictionary <string, Func <StateContext, StateContext> >(); StateContext StateA(StateContext stateContext) { int nextPosition; string nextState; if (stateContext.Tape[stateContext.Position]) { stateContext.Tape[stateContext.Position] = false; nextPosition = stateContext.Position - 1; nextState = "B"; } else { stateContext.Tape[stateContext.Position] = true; nextPosition = stateContext.Position + 1; nextState = "B"; } return(new StateContext(nextPosition, stateContext.Tape, nextState)); } StateContext StateB(StateContext stateContext) { int nextPosition; string nextState; if (stateContext.Tape[stateContext.Position]) { stateContext.Tape[stateContext.Position] = true; nextPosition = stateContext.Position + 1; nextState = "A"; } else { stateContext.Tape[stateContext.Position] = true; nextPosition = stateContext.Position - 1; nextState = "A"; } return(new StateContext(nextPosition, stateContext.Tape, nextState)); } states.Add("A", StateA); states.Add("B", StateB); var result = TheHaltingProblem.DiagnosticChecksum("A", 6, states); Assert.Equal(3, result); }