<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://teherba.org/tehowiki/index.php?action=history&amp;feed=atom&amp;title=OEIS%2Fgen_meander.pl</id>
	<title>OEIS/gen meander.pl - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://teherba.org/tehowiki/index.php?action=history&amp;feed=atom&amp;title=OEIS%2Fgen_meander.pl"/>
	<link rel="alternate" type="text/html" href="http://teherba.org/tehowiki/index.php?title=OEIS/gen_meander.pl&amp;action=history"/>
	<updated>2026-05-05T00:50:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://teherba.org/tehowiki/index.php?title=OEIS/gen_meander.pl&amp;diff=253&amp;oldid=prev</id>
		<title>imported&gt;Gfis: new</title>
		<link rel="alternate" type="text/html" href="http://teherba.org/tehowiki/index.php?title=OEIS/gen_meander.pl&amp;diff=253&amp;oldid=prev"/>
		<updated>2017-09-10T17:27:21Z</updated>

		<summary type="html">&lt;p&gt;new&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; #!/usr/bin/perl&lt;br /&gt;
 &lt;br /&gt;
 # Generate a meander sequence&lt;br /&gt;
 # 2017-08-31, Georg Fischer&lt;br /&gt;
 # Program in the public domain&lt;br /&gt;
 # c.f. &amp;lt;http://www.teherba.org/index.php/OEIS/A220952&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 use strict;&lt;br /&gt;
 use integer; # avoid division problems with reals&lt;br /&gt;
 &lt;br /&gt;
 my $debug  = 0;&lt;br /&gt;
 my $ansi   = 0; # whether to use ANSI colors on console output&lt;br /&gt;
 my $bfile  = 0; # whether to print b-file&lt;br /&gt;
 my $graph  = 0; # whether to plot y,x behind the b-file entries&lt;br /&gt;
 my $fail   = 0;&lt;br /&gt;
 my $sep    = &amp;quot;/&amp;quot;;&lt;br /&gt;
 my $base   = 5; &lt;br /&gt;
 my $fbase  = 10;&lt;br /&gt;
 my $tbase  = $base;&lt;br /&gt;
 my $ident  = &amp;quot;xx&amp;quot;;&lt;br /&gt;
 my $limit  = 125;&lt;br /&gt;
 my @path   = (0,1,2,3,4,9,14,19,18,17,16,11,12,13,8,7,6,5,10,15,20,21,22,23,24);&lt;br /&gt;
 # $bpath =   &amp;quot;00/01/02/03/04/14/24/34/33/32/31/21/22/23/13/12/11/10/20/30/40/41/42/43/44/&amp;quot;; # defines the meander sequence&lt;br /&gt;
 # print &amp;quot;     0  3  6  9  12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72\n&amp;quot; if $debug &amp;gt;= 1;&lt;br /&gt;
 &lt;br /&gt;
 while (scalar(@ARGV) &amp;gt; 0 and ($ARGV[0] =~ m{\A\-})) { # start with hyphen&lt;br /&gt;
     my $opt = shift(@ARGV);&lt;br /&gt;
     if (0) {&lt;br /&gt;
     } elsif ($opt eq &amp;quot;\-a&amp;quot;) {&lt;br /&gt;
         $ansi   = 1;&lt;br /&gt;
     } elsif ($opt eq &amp;quot;\-b&amp;quot;) {&lt;br /&gt;
         $bfile  = 1;&lt;br /&gt;
     } elsif ($opt eq &amp;quot;\-d&amp;quot;) {&lt;br /&gt;
         $debug  = shift(@ARGV);&lt;br /&gt;
     } elsif ($opt eq &amp;quot;\-g&amp;quot;) {&lt;br /&gt;
         $graph  = 1;&lt;br /&gt;
     } elsif ($opt eq &amp;quot;\-i&amp;quot;) {&lt;br /&gt;
         $ident  = shift(@ARGV);&lt;br /&gt;
     } elsif ($opt eq &amp;quot;\-l&amp;quot;) {&lt;br /&gt;
         $limit  = shift(@ARGV);&lt;br /&gt;
     } elsif ($opt eq &amp;quot;\-p&amp;quot;) {&lt;br /&gt;
         @path   = split(/\,/, shift(@ARGV));&lt;br /&gt;
     }&lt;br /&gt;
 } # while opt&lt;br /&gt;
 &lt;br /&gt;
 print &amp;quot;&amp;lt;!-================================-_&amp;gt;\n&amp;quot;;&lt;br /&gt;
 my $bpath  = join(&amp;quot;&amp;quot;, map { my $bnum = &amp;amp;to_base($_); (length($bnum) &amp;lt; 2 ? &amp;quot;0$bnum&amp;quot; : $bnum) . $sep} @path);&lt;br /&gt;
 print &amp;quot;&amp;lt;meander id=\&amp;quot;$ident\&amp;quot; path=\&amp;quot;&amp;quot; . join(&amp;quot;,&amp;quot;, @path) . &amp;quot;\&amp;quot;\n&amp;quot;&lt;br /&gt;
     . &amp;quot;    bpath=\&amp;quot;$bpath\&amp;quot;\n&amp;quot;&lt;br /&gt;
     . &amp;quot;    &amp;gt;\n&amp;quot;;&lt;br /&gt;
 my $ind = 1;&lt;br /&gt;
 &lt;br /&gt;
 if (1) { # generate b-file&lt;br /&gt;
     print &amp;quot;&amp;lt;b$base-file&amp;gt;\n&amp;quot;;&lt;br /&gt;
     $ind = 1;&lt;br /&gt;
     my $ind_1 = $ind - 1;&lt;br /&gt;
     my $bprev = &amp;quot;9&amp;quot;;&lt;br /&gt;
     my $bcurr = &amp;quot;0&amp;quot;;&lt;br /&gt;
     print &amp;quot;0 0\n&amp;quot;;&lt;br /&gt;
     while ($fail == 0 and $ind &amp;lt;= $limit) {&lt;br /&gt;
         my $bnext = &amp;amp;get_successor($bprev, $bcurr);&lt;br /&gt;
         if (length($bnext) &amp;gt; 8) {&lt;br /&gt;
             $fail = 1;&lt;br /&gt;
         } else { # not yet_failed&lt;br /&gt;
             if ($bfile &amp;gt; 0) {&lt;br /&gt;
                 print &amp;quot;$ind $bnext\n&amp;quot;;&lt;br /&gt;
             } else {&lt;br /&gt;
                 if (length($bcurr) != length($bnext)) {&lt;br /&gt;
                     $ind_1 = $ind - 1;&lt;br /&gt;
                     print &amp;quot;$ind_1 $bcurr\n$ind $bnext\n&amp;quot;; &lt;br /&gt;
                 }&lt;br /&gt;
             }&lt;br /&gt;
         } # not yet failed&lt;br /&gt;
         $bprev = $bcurr;&lt;br /&gt;
         $bcurr = $bnext;&lt;br /&gt;
         $ind ++;&lt;br /&gt;
     } # while $ind&lt;br /&gt;
     print &amp;quot;&amp;lt;/b$base-file&amp;gt;\n&amp;quot;;&lt;br /&gt;
 } # b-file&lt;br /&gt;
 &lt;br /&gt;
 if ($fail == 0) { # success&lt;br /&gt;
     &amp;amp;draw_path(@path);&lt;br /&gt;
     if ($graph &amp;gt; 0) {&lt;br /&gt;
         &amp;amp;draw_graph();&lt;br /&gt;
     }&lt;br /&gt;
 } # success&lt;br /&gt;
 print &amp;quot;&amp;lt;/meander&amp;gt;\n&amp;quot;;&lt;br /&gt;
 #--------&lt;br /&gt;
 sub get_successor {&lt;br /&gt;
     # get the successor node $bnext of a pair ($bprev, $bcurr)&lt;br /&gt;
     our @cands  = (); # candidates&lt;br /&gt;
     #----&lt;br /&gt;
     sub add_candidate {&lt;br /&gt;
         # add a candidate&lt;br /&gt;
         #----&lt;br /&gt;
         sub adjust {&lt;br /&gt;
             # make sure that both arguments start with &amp;quot;0&amp;quot; and have the same length&lt;br /&gt;
             my ($bnum1, $bnum2) = @_;&lt;br /&gt;
             while (length($bnum1) &amp;lt; length($bnum2)) {&lt;br /&gt;
                 $bnum1 = &amp;quot;0$bnum1&amp;quot;;&lt;br /&gt;
             } &lt;br /&gt;
             while (length($bnum2) &amp;lt; length($bnum1)) {&lt;br /&gt;
                 $bnum2 = &amp;quot;0$bnum2&amp;quot;;&lt;br /&gt;
             } &lt;br /&gt;
             if (substr($bnum1, 0, 1) != &amp;quot;0&amp;quot;  or &lt;br /&gt;
                 substr($bnum2, 0, 1) != &amp;quot;0&amp;quot;) {&lt;br /&gt;
                 $bnum1 = &amp;quot;0$bnum1&amp;quot;;&lt;br /&gt;
                 $bnum2 = &amp;quot;0$bnum2&amp;quot;;&lt;br /&gt;
             }&lt;br /&gt;
             return ($bnum1, $bnum2);&lt;br /&gt;
         } # adjust&lt;br /&gt;
         #----&lt;br /&gt;
         sub is_adjacent {&lt;br /&gt;
             # check whether 2 nodes are adjacent&lt;br /&gt;
             my ($bprev, $bcurr) = @_;&lt;br /&gt;
             ($bprev, $bcurr) = &amp;amp;adjust($bprev, $bcurr);&lt;br /&gt;
             # print &amp;quot;#     is_adjacent(bprev=$bprev, bcurr=$bcurr) \n&amp;quot; if ($debug &amp;gt;= 2);&lt;br /&gt;
             my $adjacent = 1;&lt;br /&gt;
             my $width = length($bcurr);&lt;br /&gt;
             my $j = $width - 1;&lt;br /&gt;
             while ($adjacent == 1 and $j &amp;gt; 0) {&lt;br /&gt;
                 my $i = $j - 1;&lt;br /&gt;
                 while ($adjacent == 1 and $i &amp;gt;= 0) {&lt;br /&gt;
                     my $ppair = substr($bprev, $i, 1) . substr($bprev, $j, 1);&lt;br /&gt;
                     my $cpair = substr($bcurr, $i, 1) . substr($bcurr, $j, 1);&lt;br /&gt;
                     my $ppos  = index($bpath, $ppair);&lt;br /&gt;
                     my $cpos  = index($bpath, $cpair);&lt;br /&gt;
                     if ($ppair != $cpair and abs($cpos - $ppos) != 3) {&lt;br /&gt;
                         print &amp;quot;\n#   is_adjacent($bprev,$bcurr): ppair=$ppair, cpair=$cpair, ppos=$ppos, cpos=$cpos\n&amp;quot; if $debug &amp;gt;= 2;&lt;br /&gt;
                         $adjacent = 0;&lt;br /&gt;
                     }&lt;br /&gt;
                     $i --;&lt;br /&gt;
                 } # while $i&lt;br /&gt;
                 $j --;&lt;br /&gt;
             } # while $j&lt;br /&gt;
             return $adjacent;&lt;br /&gt;
         } # is_adjacent&lt;br /&gt;
         #----&lt;br /&gt;
         my ($npair, $bprev, $bcurr, $i, $j) = @_;&lt;br /&gt;
         my $width = length($bcurr);&lt;br /&gt;
         print &amp;quot;#   add_candidate(npair=$npair, i=$i, j=$j)&amp;quot; if ($debug &amp;gt;= 1);&lt;br /&gt;
         my $bcand = substr($bcurr, 0, $i)                   # before i&lt;br /&gt;
                   . substr($npair, 0, 1)                    # 1st digit -&amp;gt; [$i]&lt;br /&gt;
                   . substr($bcurr, $i + 1, $j - $i - 1)     # between i and j&lt;br /&gt;
                   . substr($npair, 1, 1)                    # 2nd digit -&amp;gt; [$j]&lt;br /&gt;
                   . substr($bcurr, $j + 1, $width - 1 - $j) # behind j&lt;br /&gt;
                   ;&lt;br /&gt;
         if (0) {&lt;br /&gt;
         } elsif (&amp;amp;is_adjacent($bcurr, $bcand) == 0) {&lt;br /&gt;
             print &amp;quot;#   $bcurr not adjacent to $bcand&amp;quot; if $debug &amp;gt;= 1;&lt;br /&gt;
         } elsif ($bcand eq $bprev) {&lt;br /&gt;
             print &amp;quot;    $bcand=bprev&amp;quot; if $debug &amp;gt;= 1;&lt;br /&gt;
         } else {&lt;br /&gt;
             my $cpos = substr($bcurr, $i, 1) ne substr($bcand, $i, 1) ? $i : $j; # else change must be at j&lt;br /&gt;
             my $icand = 0;&lt;br /&gt;
             my $busy = 1;&lt;br /&gt;
             while ($busy == 1 and $icand &amp;lt; scalar(@cands)) {&lt;br /&gt;
                 $busy = $cands[$icand] ne $bcand ? 1 : 0;&lt;br /&gt;
                 $icand ++;&lt;br /&gt;
             } # while icand&lt;br /&gt;
             if ($busy == 1) { # not yet stored&lt;br /&gt;
                 # $bcand =~ s{\A0}{};&lt;br /&gt;
                 push(@cands, $bcand); &lt;br /&gt;
             } # not yet stored&lt;br /&gt;
             print &amp;quot; -&amp;gt; bcand=$bcand&amp;quot; if $debug &amp;gt;= 1;&lt;br /&gt;
         }&lt;br /&gt;
         print &amp;quot;\n&amp;quot; if ($debug &amp;gt;= 1);&lt;br /&gt;
     } # add_candidate&lt;br /&gt;
     #----&lt;br /&gt;
     my ($bprev, $bcurr) = @_;&lt;br /&gt;
     ($bprev, $bcurr) = &amp;amp;adjust($bprev, $bcurr);&lt;br /&gt;
     print &amp;quot;# get_successor(bcurr=$bcurr)\n&amp;quot; if ($debug &amp;gt;= 1);&lt;br /&gt;
     @cands = ();&lt;br /&gt;
     my $width = length($bcurr);&lt;br /&gt;
     my $j = $width - 1;&lt;br /&gt;
     while ($j &amp;gt; 0) {&lt;br /&gt;
         my $i = $j - 1;&lt;br /&gt;
         while ($i &amp;gt;= 0) {&lt;br /&gt;
             my $cpair = substr($bcurr, $i, 1) . substr($bcurr, $j, 1);&lt;br /&gt;
             my $cpos  = index($bpath, $cpair);&lt;br /&gt;
             print &amp;quot;#   cpair=$cpair -&amp;gt; cpos=$cpos\n&amp;quot; if ($debug &amp;gt;= 1);&lt;br /&gt;
             if ($cpos &amp;gt;= 3) { # before&lt;br /&gt;
                 &amp;amp;add_candidate(substr($bpath, $cpos - 3, 2), $bprev, $bcurr, $i, $j);&lt;br /&gt;
             } # before&lt;br /&gt;
             if ($cpos &amp;lt; length($bpath) - 3) { # behind&lt;br /&gt;
                 &amp;amp;add_candidate(substr($bpath, $cpos + 3, 2), $bprev, $bcurr, $i, $j);&lt;br /&gt;
             } # behind&lt;br /&gt;
             $i --;&lt;br /&gt;
         } # while $i&lt;br /&gt;
         $j --;&lt;br /&gt;
     } # while $j&lt;br /&gt;
     my $cand = &amp;quot;&amp;quot;;&lt;br /&gt;
     print &amp;quot;# get_successor: &amp;quot; if ($debug &amp;gt;= 1);&lt;br /&gt;
     my $lcand = scalar(@cands);&lt;br /&gt;
     if (0) {&lt;br /&gt;
     } elsif ($lcand &amp;gt;  1) {&lt;br /&gt;
         print &amp;quot;# more than 1 candidate for $bcurr @ $ind&amp;quot; . &amp;quot;, cands=&amp;quot; . join(&amp;quot;,&amp;quot;, @cands) . &amp;quot;\n&amp;quot;; &lt;br /&gt;
         $fail = 1;&lt;br /&gt;
     } elsif ($lcand &amp;lt;  1) {&lt;br /&gt;
         print &amp;quot;# no candidate for $bcurr at $ind\n&amp;quot;;&lt;br /&gt;
         $fail = 1;&lt;br /&gt;
     } else { # $lcand == 1&lt;br /&gt;
         $cand = $cands[0];&lt;br /&gt;
         $cand =~ s{\A0+}{};&lt;br /&gt;
         if (length($cand) &amp;gt; 16) {&lt;br /&gt;
             print &amp;quot;# $cand exploding @ $ind\n&amp;quot;;&lt;br /&gt;
             $fail = 1;&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
     print &amp;quot;\n&amp;quot; if $debug &amp;gt;= 1;&lt;br /&gt;
     return $cand;&lt;br /&gt;
 } # get_successor&lt;br /&gt;
 #--------&lt;br /&gt;
 sub to_base {&lt;br /&gt;
     # return a normal integer as number in base $tbase&lt;br /&gt;
     my ($num)  = @_;&lt;br /&gt;
     my $result = &amp;quot;&amp;quot;;&lt;br /&gt;
     while ($num &amp;gt; 0) {&lt;br /&gt;
         my $digit = $num % $tbase;&lt;br /&gt;
         $result =  $digit . $result;&lt;br /&gt;
         $num /= $tbase;&lt;br /&gt;
     } # while &amp;gt; 0&lt;br /&gt;
     return $result eq &amp;quot;&amp;quot; ? &amp;quot;0&amp;quot; : $result; &lt;br /&gt;
 } # to_base&lt;br /&gt;
 #--------&lt;br /&gt;
 sub from_base {&lt;br /&gt;
     # return a number in base $fbase (string, maybe with letters) as normal integer&lt;br /&gt;
     my ($num)  = @_;&lt;br /&gt;
     my $bpow   = 1;&lt;br /&gt;
     my $result = 0;&lt;br /&gt;
     my $pos    = length($num) - 1;&lt;br /&gt;
     while ($pos &amp;gt;= 0) { # from backwards&lt;br /&gt;
         my $digit = substr($num, $pos, 1);&lt;br /&gt;
         if ($digit &amp;lt; 0) {&lt;br /&gt;
             print STDERR &amp;quot;invalid digit in number $num\n&amp;quot;;&lt;br /&gt;
         }&lt;br /&gt;
         $result += $digit * $bpow;&lt;br /&gt;
         $bpow   *= $fbase;&lt;br /&gt;
         $pos --;&lt;br /&gt;
     } # positive&lt;br /&gt;
     return $result; &lt;br /&gt;
 } # from_base&lt;br /&gt;
 #--------&lt;br /&gt;
 sub draw_graph {&lt;br /&gt;
     print &amp;quot;&amp;lt;draw-graph&amp;gt;\n&amp;quot;;&lt;br /&gt;
     $ind = 1;&lt;br /&gt;
     my $ind_1 = $ind - 1;&lt;br /&gt;
     my $bprev = &amp;quot;9&amp;quot;;&lt;br /&gt;
     my $bcurr = &amp;quot;0&amp;quot;;&lt;br /&gt;
     print &amp;quot;0 0\n&amp;quot;;&lt;br /&gt;
     while ($fail == 0 and $ind &amp;lt;= $limit) {&lt;br /&gt;
         my $bnext = &amp;amp;get_successor($bprev, $bcurr);&lt;br /&gt;
         print sprintf(&amp;quot;%-10s&amp;quot;, &amp;quot;$ind $bnext&amp;quot;) &lt;br /&gt;
                     . ($graph &amp;gt; 0 ? &amp;quot;|&amp;quot; . &amp;quot; &amp;quot; x (&amp;amp;from_base($bnext) + 1) . &amp;quot;@&amp;quot; : &amp;quot;&amp;quot;) &lt;br /&gt;
                     . &amp;quot;\n&amp;quot;; &lt;br /&gt;
         $bprev = $bcurr;&lt;br /&gt;
         $bcurr = $bnext;&lt;br /&gt;
         $ind ++;&lt;br /&gt;
     } # while $ind&lt;br /&gt;
     print &amp;quot;&amp;lt;/draw-graph&amp;gt;\n&amp;quot;;&lt;br /&gt;
 } # draw_graph  &lt;br /&gt;
 #--------&lt;br /&gt;
 sub draw_path {&lt;br /&gt;
     our $vert   = &amp;quot;||&amp;quot;; if ($ansi == 1) { $vert = &amp;quot;\x1b[103m$vert\x1b[0m&amp;quot;; }&lt;br /&gt;
     our $hori   = &amp;quot;==&amp;quot;; if ($ansi == 1) { $hori = &amp;quot;\x1b[103m$hori\x1b[0m&amp;quot;; }&lt;br /&gt;
     our @matrix = ();&lt;br /&gt;
     our $blan   = &amp;quot;  &amp;quot;;&lt;br /&gt;
     #----&lt;br /&gt;
     sub get_matrix_pos {&lt;br /&gt;
         my ($x, $y) = @_;&lt;br /&gt;
         my $base2_1 = $base * 2 - 1; # 9  for base=5&lt;br /&gt;
         return $x * 2 + ($base2_1 - 1) * $base2_1 - $y * 2 *$base2_1; &lt;br /&gt;
     } # get_matrix_pos&lt;br /&gt;
     #----&lt;br /&gt;
     sub get_digit {&lt;br /&gt;
         # return the value of a digit from a string in $base representation&lt;br /&gt;
         # $base &amp;lt;= 10 for the moment, but hex is prepared&lt;br /&gt;
         my ($num, $pos) = @_; # pos is 0 for last character&lt;br /&gt;
         my $bum = &amp;amp;based0($num);&lt;br /&gt;
         return substr($bum, length($bum) - 1 - $pos, 1);&lt;br /&gt;
     } # get_digit&lt;br /&gt;
     #----&lt;br /&gt;
     sub based0 {&lt;br /&gt;
         # return a number in base $base, &lt;br /&gt;
         # filled to $maxexp - 1 with leading zeroes&lt;br /&gt;
         my $maxexp = 2; # for drawing the start path only!&lt;br /&gt;
         my ($num) = @_;&lt;br /&gt;
         my $result = &amp;quot;&amp;quot;;&lt;br /&gt;
         my $ind = 0;&lt;br /&gt;
         while ($ind &amp;lt; $maxexp) {&lt;br /&gt;
            $result = ($num % $base) . $result;&lt;br /&gt;
            $num    /= $base;&lt;br /&gt;
            $ind ++;&lt;br /&gt;
         } # while $idig&lt;br /&gt;
         return $result; &lt;br /&gt;
     } # based0&lt;br /&gt;
     #----&lt;br /&gt;
     sub connect {&lt;br /&gt;
         my ($pa0, $pa1) = @_;&lt;br /&gt;
         if ($pa0 &amp;gt; $pa1) { # exchange, make p1 smaller&lt;br /&gt;
             my $temp = $pa0;&lt;br /&gt;
             $pa0 = $pa1;&lt;br /&gt;
             $pa1 = $temp;&lt;br /&gt;
         } # pa0 &amp;lt;= pa1&lt;br /&gt;
         my $ba0 = &amp;amp;based0($pa0);&lt;br /&gt;
         my $ba1 = &amp;amp;based0($pa1);&lt;br /&gt;
         print &amp;quot;ba0=$ba0, ba1=$ba1&amp;quot; if $debug &amp;gt;= 2;&lt;br /&gt;
         my $x0 = &amp;amp;get_digit($pa0, 1);&lt;br /&gt;
         my $y0 = &amp;amp;get_digit($pa0, 0);&lt;br /&gt;
         my $x1 = &amp;amp;get_digit($pa1, 1);&lt;br /&gt;
         my $y1 = &amp;amp;get_digit($pa1, 0);&lt;br /&gt;
         print &amp;quot;, x0=$x0, y0=$y0, x1=$x1, y1=$y1&amp;quot; if $debug &amp;gt;= 2;&lt;br /&gt;
         my $mp0 = &amp;amp;get_matrix_pos($x0, $y0);&lt;br /&gt;
         if ($x0 eq $x1) { # up&lt;br /&gt;
             $matrix[$mp0 - ($base * 2 - 1)] = $vert; # up&lt;br /&gt;
             print &amp;quot; $vert\n&amp;quot; if $debug &amp;gt;= 2;&lt;br /&gt;
         } else {&lt;br /&gt;
             $matrix[$mp0 + 1]               = $hori; # right&lt;br /&gt;
             print &amp;quot; $hori\n&amp;quot; if $debug &amp;gt;= 2;&lt;br /&gt;
         }&lt;br /&gt;
     } # connect&lt;br /&gt;
     #----&lt;br /&gt;
     # initialize the matrix&lt;br /&gt;
     my $x = 0;&lt;br /&gt;
     my $y = 0;&lt;br /&gt;
     while ($x &amp;lt; $base) {&lt;br /&gt;
         $y = 0;&lt;br /&gt;
         while ($y &amp;lt; $base) {&lt;br /&gt;
             my $mp = &amp;amp;get_matrix_pos($x, $y);&lt;br /&gt;
             $matrix[$mp] = $ansi == 1 ? &amp;quot;\x1b[102m$x$y\x1b[0m&amp;quot; : &amp;quot;$x$y&amp;quot;;&lt;br /&gt;
             if ($x &amp;lt; $base - 1) {&lt;br /&gt;
                 $matrix[$mp + 1] = $blan; # &amp;quot; &amp;quot;; # right&lt;br /&gt;
             }&lt;br /&gt;
             if ($y &amp;gt; 0) {&lt;br /&gt;
                 $matrix[$mp + $base * 2 - 1] = $blan; # &amp;quot;  &amp;quot;; # down&lt;br /&gt;
                 if ($x &amp;lt; $base - 1) {&lt;br /&gt;
                     $matrix[$mp + $base * 2 - 1 + 1] = $blan; # &amp;quot; &amp;quot;; # down&lt;br /&gt;
                 }                   &lt;br /&gt;
             }&lt;br /&gt;
             $y ++;&lt;br /&gt;
         } # while y&lt;br /&gt;
         $x ++;&lt;br /&gt;
     } # while $x&lt;br /&gt;
 &lt;br /&gt;
     my $ipa = 1;&lt;br /&gt;
     while ($ipa &amp;lt; scalar(@path)) {&lt;br /&gt;
         &amp;amp;connect($path[$ipa - 1], $path[$ipa]);&lt;br /&gt;
         $ipa ++;&lt;br /&gt;
     } # while $ipa &lt;br /&gt;
     print &amp;quot;&amp;lt;draw-path&amp;gt;\n\n&amp;quot;;&lt;br /&gt;
     my $imp = 0;&lt;br /&gt;
     while ($imp &amp;lt; scalar(@matrix)) { # print&lt;br /&gt;
         print &amp;quot;$matrix[$imp]&amp;quot;;&lt;br /&gt;
         $imp ++;&lt;br /&gt;
         if ($imp % ($base * 2 - 1) == 0) {&lt;br /&gt;
             print &amp;quot;\n&amp;quot;;&lt;br /&gt;
         }&lt;br /&gt;
     } # printing&lt;br /&gt;
     print &amp;quot;\n&amp;lt;/draw-path&amp;gt;\n&amp;quot;;&lt;br /&gt;
 } # draw_path&lt;br /&gt;
 #--------&lt;br /&gt;
 __DATA__&lt;/div&gt;</summary>
		<author><name>imported&gt;Gfis</name></author>
	</entry>
</feed>