logo       

Re: Solution to QOTW #23 in language of QOTW #24: msg#00215

Subject: Re: Solution to QOTW #23 in language of QOTW #24

On Sep 21, 2004, at 1:51 PM, Mark Jason Dominus wrote:
I think it has fewer
states and fewer total instructions,

I realize now that I could have gotten rid of at least one state and five instructions:

C_scan_R [ C_scan_R [ R
C_scan_R ] C_scan_R ] R
C_scan_R ( C_close [ R
C_scan_R ) C_close [ R
C_scan_R _ D_fix _ L

C_close ( C_open ] R
C_close ) C_open ] R

C_open ( C_close [ R
C_open ) C_close [ R
C_open _ D_fix _ L

C_open is superfluous here; I could re-use C_scan_R instead, like this:

C_close ( C_scan_R ] R
C_close ) C_scan_R ] R

and then get rid of C_open and its three instructions entirely.

By the time control reaches section D, there are no remaining ( or )
marks; they have all been replaced with [ and ].  So these instructions
can be eliminated:

D_fix ( D_fix ( L
D_fix ) D_fix ) L


None of this affects the performance of the algorithm, however.
Total run time to generate strings of 2n parentheses is about
19n-27 steps per string.

          init: <(>) ( ) ( )
          init:  (<)>( ) ( )
          init:  ( )<(>) ( )
          init:  ( ) (<)>( )
          init:  ( ) ( )<(>)
          init:  ( ) ( ) (<)
          init:  ( ) ( ) ( )<_
()()()
      A_scan_1:  ( ) ( ) (<)>_
      A_scan_1:  ( ) ( )<(>) _
      A_scan_2:  ( ) (<)>( ) _
      A_change:  ( ) ( [<(>) _
      B_scan_L:  ( ) (<[>] ) _
      B_scan_L:  ( )<(>[ ] ) _
      B_scan_R:  ( ) [<[>] ) _
      B_scan_R:  ( ) [ [<]>) _
      B_scan_R:  ( ) [ [ ]<)>_
      B_scan_L:  ( ) [ [<]>] _
      B_scan_L:  ( ) [<[>] ] _
      B_scan_L:  ( )<[>[ ] ] _
      B_scan_L:  (<)>[ [ ] ] _
      B_scan_L: <(>) [ [ ] ] _
      B_scan_R:  [<)>[ [ ] ] _
      B_scan_L: <[>] [ [ ] ] _
      B_scan_L: <_>[ ] [ [ ] ] _
      C_scan_R:  _<[>] [ [ ] ] _
      C_scan_R:  _ [<]>[ [ ] ] _
      C_scan_R:  _ [ ]<[>[ ] ] _
      C_scan_R:  _ [ ] [<[>] ] _
      C_scan_R:  _ [ ] [ [<]>] _
      C_scan_R:  _ [ ] [ [ ]<]>_
      C_scan_R:  _ [ ] [ [ ] ]<_
         D_fix:  _ [ ] [ [ ]<]>_
         D_fix:  _ [ ] [ [<]>) _
         D_fix:  _ [ ] [<[>) ) _
         D_fix:  _ [ ]<[>( ) ) _
         D_fix:  _ [<]>( ( ) ) _
         D_fix:  _<[>) ( ( ) ) _
         D_fix: <_>( ) ( ( ) ) _
          init:  _<(>) ( ( ) ) _
          init:  _ (<)>( ( ) ) _
          init:  _ ( )<(>( ) ) _
          init:  _ ( ) (<(>) ) _
          init:  _ ( ) ( (<)>) _
          init:  _ ( ) ( ( )<)>_
          init:  _ ( ) ( ( ) )<_
()(())
      A_scan_1:  _ ( ) ( ( )<)>_
      A_scan_1:  _ ( ) ( (<)>) _
      A_scan_1:  _ ( ) (<(>) ) _
      A_scan_2:  _ ( )<(>( ) ) _
      A_scan_2:  _ (<)>( ( ) ) _
      A_change:  _ ( [<(>( ) ) _
      B_scan_L:  _ (<[>] ( ) ) _
      B_scan_L:  _<(>[ ] ( ) ) _
      B_scan_R:  _ [<[>] ( ) ) _
      B_scan_R:  _ [ [<]>( ) ) _
      B_scan_R:  _ [ [ ]<(>) ) _
      B_scan_L:  _ [ [<]>] ) ) _
      B_scan_L:  _ [<[>] ] ) ) _
      B_scan_L:  _<[>[ ] ] ) ) _
      B_scan_L: <_>[ [ ] ] ) ) _
      C_scan_R:  _<[>[ ] ] ) ) _
      C_scan_R:  _ [<[>] ] ) ) _
      C_scan_R:  _ [ [<]>] ) ) _
      C_scan_R:  _ [ [ ]<]>) ) _
      C_scan_R:  _ [ [ ] ]<)>) _
       C_close:  _ [ [ ] ] [<)>_
        C_open:  _ [ [ ] ] [ ]<_
         D_fix:  _ [ [ ] ] [<]>_
         D_fix:  _ [ [ ] ]<[>) _
         D_fix:  _ [ [ ]<]>( ) _
         D_fix:  _ [ [<]>) ( ) _
         D_fix:  _ [<[>) ) ( ) _
         D_fix:  _<[>( ) ) ( ) _
         D_fix: <_>( ( ) ) ( ) _
          init:  _<(>( ) ) ( ) _
          init:  _ (<(>) ) ( ) _
          init:  _ ( (<)>) ( ) _
          init:  _ ( ( )<)>( ) _
          init:  _ ( ( ) )<(>) _
          init:  _ ( ( ) ) (<)>_
          init:  _ ( ( ) ) ( )<_
(())()
      A_scan_1:  _ ( ( ) ) (<)>_
      A_scan_1:  _ ( ( ) )<(>) _
      A_scan_2:  _ ( ( )<)>( ) _
      A_change:  _ ( ( ) [<(>) _
      B_scan_L:  _ ( ( )<[>] ) _
      B_scan_L:  _ ( (<)>[ ] ) _
      B_scan_L:  _ (<(>) [ ] ) _
      B_scan_R:  _ ( [<)>[ ] ) _
      B_scan_L:  _ (<[>] [ ] ) _
      B_scan_L:  _<(>[ ] [ ] ) _
      B_scan_R:  _ [<[>] [ ] ) _
      B_scan_R:  _ [ [<]>[ ] ) _
      B_scan_R:  _ [ [ ]<[>] ) _
      B_scan_R:  _ [ [ ] [<]>) _
      B_scan_R:  _ [ [ ] [ ]<)>_
      B_scan_L:  _ [ [ ] [<]>] _
      B_scan_L:  _ [ [ ]<[>] ] _
      B_scan_L:  _ [ [<]>[ ] ] _
      B_scan_L:  _ [<[>] [ ] ] _
      B_scan_L:  _<[>[ ] [ ] ] _
      B_scan_L: <_>[ [ ] [ ] ] _
      C_scan_R:  _<[>[ ] [ ] ] _
      C_scan_R:  _ [<[>] [ ] ] _
      C_scan_R:  _ [ [<]>[ ] ] _
      C_scan_R:  _ [ [ ]<[>] ] _
      C_scan_R:  _ [ [ ] [<]>] _
      C_scan_R:  _ [ [ ] [ ]<]>_
      C_scan_R:  _ [ [ ] [ ] ]<_
         D_fix:  _ [ [ ] [ ]<]>_
         D_fix:  _ [ [ ] [<]>) _
         D_fix:  _ [ [ ]<[>) ) _
         D_fix:  _ [ [<]>( ) ) _
         D_fix:  _ [<[>) ( ) ) _
         D_fix:  _<[>( ) ( ) ) _
         D_fix: <_>( ( ) ( ) ) _
          init:  _<(>( ) ( ) ) _
          init:  _ (<(>) ( ) ) _
          init:  _ ( (<)>( ) ) _
          init:  _ ( ( )<(>) ) _
          init:  _ ( ( ) (<)>) _
          init:  _ ( ( ) ( )<)>_
          init:  _ ( ( ) ( ) )<_
(()())
      A_scan_1:  _ ( ( ) ( )<)>_
      A_scan_1:  _ ( ( ) (<)>) _
      A_scan_1:  _ ( ( )<(>) ) _
      A_scan_2:  _ ( (<)>( ) ) _
      A_change:  _ ( ( [<(>) ) _
      B_scan_L:  _ ( (<[>] ) ) _
      B_scan_L:  _ (<(>[ ] ) ) _
      B_scan_R:  _ ( [<[>] ) ) _
      B_scan_R:  _ ( [ [<]>) ) _
      B_scan_R:  _ ( [ [ ]<)>) _
      B_scan_L:  _ ( [ [<]>] ) _
      B_scan_L:  _ ( [<[>] ] ) _
      B_scan_L:  _ (<[>[ ] ] ) _
      B_scan_L:  _<(>[ [ ] ] ) _
      B_scan_R:  _ [<[>[ ] ] ) _
      B_scan_R:  _ [ [<[>] ] ) _
      B_scan_R:  _ [ [ [<]>] ) _
      B_scan_R:  _ [ [ [ ]<]>) _
      B_scan_R:  _ [ [ [ ] ]<)>_
      B_scan_L:  _ [ [ [ ]<]>] _
      B_scan_L:  _ [ [ [<]>] ] _
      B_scan_L:  _ [ [<[>] ] ] _
      B_scan_L:  _ [<[>[ ] ] ] _
      B_scan_L:  _<[>[ [ ] ] ] _
      B_scan_L: <_>[ [ [ ] ] ] _
      C_scan_R:  _<[>[ [ ] ] ] _
      C_scan_R:  _ [<[>[ ] ] ] _
      C_scan_R:  _ [ [<[>] ] ] _
      C_scan_R:  _ [ [ [<]>] ] _
      C_scan_R:  _ [ [ [ ]<]>] _
      C_scan_R:  _ [ [ [ ] ]<]>_
      C_scan_R:  _ [ [ [ ] ] ]<_
         D_fix:  _ [ [ [ ] ]<]>_
         D_fix:  _ [ [ [ ]<]>) _
         D_fix:  _ [ [ [<]>) ) _
         D_fix:  _ [ [<[>) ) ) _
         D_fix:  _ [<[>( ) ) ) _
         D_fix:  _<[>( ( ) ) ) _
         D_fix: <_>( ( ( ) ) ) _
          init:  _<(>( ( ) ) ) _
          init:  _ (<(>( ) ) ) _
          init:  _ ( (<(>) ) ) _
          init:  _ ( ( (<)>) ) _
          init:  _ ( ( ( )<)>) _
          init:  _ ( ( ( ) )<)>_
          init:  _ ( ( ( ) ) )<_
((()))
      A_scan_1:  _ ( ( ( ) )<)>_
      A_scan_1:  _ ( ( ( )<)>) _
      A_scan_1:  _ ( ( (<)>) ) _
      A_scan_1:  _ ( (<(>) ) ) _
      A_scan_2:  _ (<(>( ) ) ) _
      A_scan_2:  _<(>( ( ) ) ) _
      A_scan_2: <_>( ( ( ) ) ) _
Time: 176




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe