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

a perl quilt

by ailie (Friar)
on Jan 31, 2001 at 03:53 UTC ( #55398=perlmeditation: 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);

Comment on a perl quilt
Download Code
Re: a perl quilt
by jlp (Friar) on Jan 31, 2001 at 04:03 UTC
    This is what I eventually ended up with:
    my @s = (1..168); my @q; { $a=rand(@s);push(@q, $s[$a]); splice(@s, $a, 1); @s && redo } print join(" ", splice(@q, 0, 12)) . "\n" for (1..14);

    kudos to mikfire for reminding me about the return value of splice.

    Update: my splice was off by 1. whoops
Re: a perl quilt
by chipmunk (Parson) on Jan 31, 2001 at 09:44 UTC
    Well, I can't resist a bit of golf. @s=1..168;print+splice(@s,rand@s,1),@s%12?$":$/while@s

    Although I would sacrifice a few strokes to get formatted output: @s=1..168;printf'%3d%s',splice(@s,rand@s,1),@s%12?$":$/while@s
Re: a perl quilt
by Lexicon (Chaplain) on Jan 31, 2001 at 10:20 UTC
    Perhaps this would make a nice addition to the quilt?

    ##Perl Quilt #14x12 Patch # Randomizer use strict; my(@s,@q,$x) ;@s=(1..168) ;for(1..168) {$x=int rand @s; push(@q, splice@s,$x, 1);} print " ".join "\t", splice @q,0, 12for(1..14)
    -Lexicon
Re: a perl quilt
by a (Friar) on Feb 01, 2001 at 11:22 UTC
    This may be going in the wrong direction but ... the boys in the Work column of Server Workstation Expert had a column on random tiling (as in ceramic tiles) Escher, Penrose, Foyer in PostScript. It was, er, tough sledding, but one challenge they issued was to try and make their dart'n'kite tiling more random w/ something like perl. Not this little black duck, but you golfers may have an idea.

    a

Re: a perl quilt
by ChOas (Curate) on Feb 02, 2001 at 14:58 UTC
    Hey! ;)

    Just in case someone is interested, the Programmer Of The Month (POTM)
    Had a competition involving creating non repetitive (sp. ?) quilts a (long) while
    ago, you can find it here


    GreetZ!,
      ChOas

    p.s. It would be cool if a few monks would team up to enter the next competition (when ever), Idea ?

    print "profeth still\n" if /bird|devil/;
the perl quilt layout
by ailie (Friar) on Feb 05, 2001 at 07:13 UTC

    I ended up with the desired 168 squares of fabric needed for the 12 by 14 grid layout, and so once the swatches were ready I ran my script and got this layout:

    33 83 1 85 108 145 122 27 101 68 74 47
    18 9 137 6 142 134 162 136 43 8 19 80
    154 42 88 129 112 7 151 144 89 152 59 29
    124 14 55 60 81 125 104 97 133 70 102 107
    36 95 72 75 103 91 159 82 130 66 44 67
    76 25 46 166 10 111 22 138 119 71 23 30
    34 128 127 165 31 57 106 62 157 5 143 90
    99 126 3 54 32 50 135 113 77 12 109 86
    117 131 48 58 28 69 94 56 24 45 61 53
    116 161 123 96 167 93 4 105 40 13 156 78
    52 121 15 147 139 120 41 64 73 110 146 100
    164 37 158 17 92 38 79 20 26 16 140 35
    132 148 149 160 118 98 51 2 49 84 155 168
    11 21 65 114 141 39 163 115 87 153 150 63
    

    I've got a picture of the quilt top online, here, for your enjoyment.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://55398]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-12-28 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls