The path 1 > 7 > 8 > 9 > 11 doesn't exist in your input but does in the graph, is it on purpose, or an issue?

If it's on purpose, you can drop most of the input and only keep unique pairs, for example there's no need for 1 > 2 to appear twice and 8 > 9 thrice. In that case, by just keeping those unique pairs your graph is already defined. I don't know about ASCII graphs, but your input is really easy to turn into dot, and then into a graph (maybe there is a tool that turns dot data into ASCII graphs...)

If having 1 > 7 > 8 > 9 > 11 in your output graph is a mistake, what you have is a DFA which you want to minimize. There might be a module that does that on graphs in perl.

This is kind of OT but your input can be turned into a regular expression (using A and B for 10 and 11, to have only one char per transition): 1256789B|125678AB|1456789B|145678AB|1356789B|135678AB|178AB.
This can be optimized by a module like Regexp::Optimizer: (?:(?:1(?:[234]5678[9A]|78A)B)) (I cheated on that one, I manually turned the perl regexp into a javascript one)
And then plotted by one of the online tools that turn regexp into graphs: like this (notice the separate branch for 1 > 7 > 8 > 10 > 11 / 178AB).

This is just taking advantage of the fact regular expressions (in the first sense of the name, not the extended stuff allowed by perl) can be turned to a DFA and back. I don't know the implementation of Regexp::Optimizer but it might just do a DFA minization in some form or other.

Edit: oh and that's the result you get by adding 1789B as a possible path in the regex, which is the graph you asked for.

Edit2: How to convert dot graph to ASCII. So if you're in the first case (1 > 7 > 8 > 9 > 11 allowed), your problem becomes really easy to solve.


In reply to Re: Graph in a terminal (ASCII - art) by Eily
in thread Graph in a terminal (ASCII - art) by baxy77bax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.