Hello,

Thanks for the suggestion, however, there is a bug in the above code. While the code correctly extracts non-repeated characters, it can use any of these characters randomly which may result in repeated characters in the line:

$r .= $chars[rand @chars] for 1 .. shift;
Here is the correct version of the program:
#!/usr/bin/perl -nw # generate ascii 3-d for an input height field # input contains tabs(ts=8), spaces(h=0) or numbers 0..9 # 0 is the furthest and 9 is the closest. # Copyright 2001 -- Abdulaziz Ghuloum chomp; s/\t/' 'x8/eg; # replace tabs $_|=' 'x72; # normalize width s/ /0/g; # default depth s/(\d)/$1$1/g; # double each letter s/.//; # remove first chop; # and last $p=rs('',16); # pick a random string print $p; $p=reverse$p; s[(\d)(\d)][ # for each step if($2>$1){chop($p) for 1..$2-$1} # remove chars if going up elsif($2<$1){$p=rs($p,$1-$2)}; # add chars if going down $p =~ s/(.*)(.)/$2$1/; # rotate chars $2 # and substitute ]eg; print "$_\n"; sub rs{ my ($p,$n) = @_; return $p unless $n; my @chars = map chr, 33..126; # all printable chars @chars = grep index($p,$_)==-1, @chars if defined $p; $p .= $chars[rand@chars]; rs($p,$n-1); }

In reply to Re: Re: ASCII Stereograms (SIRTS) by abstracts
in thread ASCII Stereograms (SIRTS) by abstracts

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.