in reply to ASCII Stereograms (SIRTS)

One other thing I noticed:
Because of the way random letters are used to make these SIRTS (some are made with fixed sets of letters) you'll occasionaly see SIRTS generated that don't "step down" properly (ie: go from a high number to a lower number).

This can happen becuase the rs method has (unfortunately) just happened to pick some random characters that are allready part of the pattern for the current line. (In fact, I think the camel SIRTS that was posted has this problem with the legs).

You can prevent ths from happening by making two minor changes:

Replies are listed 'Best First'.
Re: Re: ASCII Stereograms (SIRTS)
by abstracts (Hermit) on Dec 25, 2001 at 15:18 UTC
    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); }