Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

converter's scratchpad

by converter (Priest)
on Jun 02, 2004 at 03:29 UTC ( #359104=scratchpad: print w/replies, xml ) Need Help??

#!/usr/bin/perl use warnings; use strict; # given skew factor and sectors/track, # return a list of skewed sector numbers. # skew: skew factor # sectors: number of sectors (per track) sub skewlist { my ($skew, $sectors) = @_; my @a = 1; my %seen = (1 => 1); for (2..$sectors) { my $s = $a[-1] + $skew; $s = $skew - ($sectors - $a[-1]) if $s > $sectors; $s++ while $seen{$s}; $seen{$s}++; push @a, $s; } return @a; } sub main { unless (2 == @ARGV) { die "usage: skewgen <skew factor> <number of sectors>"; } my @a = skewlist(@ARGV); print "skewlist: @a\n"; } exit(main()); __END__ $ ./skewgen 4 15 skewlist: 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 $ ./skewgen 6 26 skewlist: 1 7 13 19 25 5 11 17 23 3 9 15 21 2 8 14 20 26 6 12 18 24 4 +10 16 22
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2016-12-06 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (108 votes). Check out past polls.