MacTech Network: MacTech Forums | MacForge.net | Computer Memory | Register Domains | Cables | iPod Deals | Mac Deals | Mac Book Shelf |
|
|
|
|
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This machine scans right in state 0 looking for a right parenthesis. When it finds one, it moves to state o This machine scans right in state 0 looking for a right parenthesis. When it finds one, it moves to state one, replaces the right parenthesis with an 'X', and moves to state 1 to scan for a left parenthesis., which it also replaces with an 'X'. If it encounters the 'A' delimiter when looking for a balancing parenthesis, it halts after writing a '0', indicating that the parentheses are not well-formed. If all parentheses are paired off, it writes a '1' indicating the input is well-formed. Your Challenge this month is to implement a Turing Machine. The prototype for the code you should write is: typedef unsigned long ulong; typedef enum {kMoveLeft=-1,kHalt=0, kMoveRight=1} MoveDir; typedef struct TMRule { /* rule in program for TM */ typedef void (*TMMoveProc) ( Boolean /* success */ TuringMachine( On input, your TuringMachine will be provided with numRules rules governing the behavior of the Turing Machine. The rules are pointed to by theRules. You will also be provided with a input tape pointed to by theTape, with a finite number of contiguous squares preinitialized to the Turing Machine input. The read-write head will be positioned on the input tape at theTape[rwHeadPos]. All other squares of the input tape will be empty, indicated by a binary zero. Your TuringMachine should begin in state 0, read the first input symbol, and find the appropriate rule. It should invoke the callback ReportMove to inform my test code of what your machine is doing, providing the outputSymbol that you will write to the tape, the newState of your finite state machine, and the moveDirection for the new position of the read-write head. You should then update theTape, move your read-write head, and update the Turing Machine state. When your TuringMachine encounters a rule with a moveDirection of kHalt, you should make a final callback to ReportMove and then return TRUE. If your TuringMachine exceeds the tapeLen of theTape, or if you are unable to find a rule that applies to your current machine state and the input symbol, you should return FALSE. It is my intent to provide all necessary input rules and a sufficient length of tape, but your machine should fail gracefully if an input bug or an implementation bug results in running out of tape or encountering a bad input symbol. Your code will be timed with a sequence of rule/tape pairs, and the solution that completes execution of the inputs correctly in the shortest total time will be the winner. Half of the tests will use a "universal" Turing Machine, where the rules describe a general Turing Machine interpreter, and the input tape contains another Turing Machine program. The time executed by the ReportMove callback will be included in your solution time. The callback will look something like the following: static void ReportMove(long outputSymbol, long newState, MoveDir
moveDirection) You may not modify the input rules pointed to by theRules, but you may allocate reasonable additional storage if you would like to preprocess the rules in some way, provided you deallocate the storage before returning. For those of you that would like additional information on Turing Machines, you can refer to almost any textbook on automata theory or the theory of computation. My personal favorite is Computation, Finite and Infinite Machines, by Marvin Minsky, (c) 1976 by Prentice-Hall. This will be a native PowerPC Challenge, using the latest CodeWarrior environment. Solutions may be coded in C, C++, or Pascal.
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
All contents are Copyright 1984-2008 by Xplain Corporation. All rights reserved.
MacTech is a registered trademark of Xplain Corporation. Xplain, Video Depot, Movie Depot, Palm OS Depot, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, NetProLive, JavaTech, WebTech, BeTech, LinuxTech, Apple Expo, MacTech Central and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.