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

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.