Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-15-2007, 03:41 PM
Member
 
Join Date: Aug 2007
Posts: 1
bladeb2k is on a distinguished road
Turing machine Help please!!
Can anyone help me with this problem or point me in the direction of somewhere that can, i wuld be extreamly grateful.

Q) The range of data to be accepted by the program has been extended to allow numbers to be grouped within parenthesis eg. 01,{01,0,{10,1,{0,1},{1}}},1

Design a Turing machine which will check for correctly formatted data. In this version the restriction of 0 being only represented by a single symbol need not be adhered to. The TM should check for correctly matched {and} but need not detect misplaced commas (as in, eg. {0,}).

You should assume:

i) the data is initially positioned on an otherwise blank tape (i.e. all spaces) with the TM's reading head above the first character.

ii) All commas are legally placed but {and} may not be

iii) the TM will end in one of the following states:

VALID DATA

TOO MANY '}'

TOO MANY '{'

with the obvious interpretation.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-15-2007, 10:47 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,124
hardwired is on a distinguished road
Code:
public class BraceCheck { public static void main(String[] args) { String[] tapes = { "01,{01,0,{10,1,{0,1},{1}}},1", "1,0,0{0}},{{{1,0}},1,0}", "0,1,{{0,0},{1},{{{0}},1" }; for(int j = 0; j < tapes.length; j++) { System.out.printf("checkBraces(tapes[%d]): = %s%n", j, checkBraces(tapes[j])); } } private static String checkBraces(String tape) { int len = tape.length(); //System.out.println("len = " + len); int headPos = 0; // Find first left brace. while(tape.charAt(headPos) != '{' && headPos < len) headPos++; int leftBraceIndex = headPos; //System.out.printf("leftBraceIndex = %d%n", leftBraceIndex); // Find index of a matching right brace. int match = 0; do { headPos++; if(tape.charAt(headPos) == '{') match--; if(tape.charAt(headPos) == '}') match++; } while(headPos < len-1); String result = "ILLEGAL STATE"; if(match < 1) result = "TOO MANY '{'"; if(match == 1) result = "VALID DATA"; if(match > 1) result = "TOO MANY '}'"; return result; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get URL from network machine Mir Networking 1 04-02-2008 01:08 AM
Getting name/ip of a machine Java Tip Java Tips 0 03-02-2008 08:11 PM
Too many virtual Machine davantmay Java Applets 1 07-06-2007 11:53 PM
Virtual Machine To Pda Heather Advanced Java 2 06-30-2007 04:11 PM
Visual Turing Machine 2.0 levent Java Announcements 0 05-31-2007 10:24 AM


All times are GMT +3. The time now is 07:13 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org