Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

One of my hobbies is quilting, and recently I've been preparing fabric scraps for a scrap quilt. When I am finished collecting and cutting, I will have 168 six-inch squares of distinct fabrics. My plan is to sew them togther in a 12 by 14 block grid.

Out of curiosity, I want this quilt to be as random as possible, and I was puzzling over a way to eliminate my human bias for color coordination (or lack thereof) when selecting block positions. Suddenly, it hit me: Perl.

I bolted into #perlmonks and with the help of the excellent monks there, this perl quilt generator was created.

A few words about logistics - each fabric swatch will be labeled, from 1 to 168. To keep this as random as possible I think I'll probably put all the swatches in the dryer and let them be tossed around for a few minutes, then pull them out one at a time to assign their number. The perl script below will produce a grid of numbers, and the numbers represent the swatch with that number.

A round of perl golf also ensued, but I'll let the participants in that post their own code. Here's what I ended up with (with a lot of help from my friends.)

#!/usr/bin/perl -w use strict; ### # the perl quilt generator # concept by ailie, perl created with the great help of jlp, jcwren, # japh, neshura, mikfire, and all of #perlmonks ### my @swatch; my @quilt; @swatch=(1 .. 168); while (@swatch) { my $x = rand(@swatch); my $v = $swatch[$x]; push(@quilt, $v) && splice(@swatch, $x, 1); } print join(" ", splice(@quilt, 0, 12)) ."\n" for (1..14);

In reply to a perl quilt by ailie

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2023-11-28 22:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found