Exemplo n.º 1
0
        /// <summary>
        /// Parse the given instructions to Turing instructions
        /// </summary>
        /// <param name="instructions">Instructions to parse</param>
        /// <returns>Parsed instructions</returns>
        private static Dictionary <char, TuringInstruction> ParseInstructions(ICollection <string> instructions)
        {
            var stateMap = new Dictionary <char, TuringInstruction>();

            for (int i = 3; i < instructions.Count; i += 10)
            {
                var t = TuringInstruction.Parse(instructions.Skip(i).Take(9).ToArray());
                stateMap[t.State] = t;
            }

            return(stateMap);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse an instruction from the given lines
        /// </summary>
        /// <param name="lines">Lines to parse</param>
        /// <returns>Parsed instruction</returns>
        public static TuringInstruction Parse(string[] lines)
        {
            var turing = new TuringInstruction
            {
                State          = lines[0][lines[0].Length - 2],
                FalseOutput    = lines[2][lines[2].Length - 2] == '1',
                FalseDirection = lines[3][lines[3].Length - 3] == 'f' ? Direction.Left : Direction.Right,
                FalseNextState = lines[4][lines[4].Length - 2],
                TrueOutput     = lines[6][lines[6].Length - 2] == '1',
                TrueDirection  = lines[7][lines[7].Length - 3] == 'f' ? Direction.Left : Direction.Right,
                TrueNextState  = lines[8][lines[8].Length - 2]
            };

            return(turing);
        }