#!/usr/bin/perl print "Content-type: text/html\n\n"; open(FIL,"people.txt"); #open a list of people that should be on the chores list @FIL = ; close(FIL); open(FIL,"noomit.txt"); #open a list of chores that may NOT be omitted on any given day @noomit = ; close(FIL); open(FIL,"samechores.txt"); #open a list of people/chores that remain the same all week @samechores = ; close(FIL); #left1-5 are chores that may not be omitted for mon-fri $left1 = "-"; $left2; $left3; $left4; $left5; #first, we add chores that we cannot omit to the $left1 variable foreach $l (@noomit) { $l =~ s/(\n|\r)//g; #eliminate newlines $left1 .= int($l) . "-"; } #then we copy that across to the other variables $staticleft = $left2 = $left3 = $left4 = $left5 = $left1; open(FIL,"nchores.txt"); #find out how many total chores we need $nchores = int(); close(FIL); %people; @chores; foreach $l (@FIL) { $l =~ s/(\n|\r)//g; #eliminate newlines $people{$l} = "-"; #this variable will be used to make sure nobody has the same chore twice in a week } #first we print the header for the chores table print < Chores List

Do Your Chores



EOHTML $day1 = "-"; $day2; $day3; $day4; $day5; for ($i = 0; $i<$nchores; $i++) { $day1 .= ($i+1) . "-"; } $day2 = $day3 = $day4 = $day5 = $day1; @chores; $z = 0; foreach $n (sort keys %people) { $chores[$z][0] = $n; $z++; } @days = ($day1, $day2, $day3, $day4, $day5); @left = ($left1, $left2, $left3, $left4, $left5); #produce random list of chores for ($i=0;$i<6;$i++) { for ($j=0;$j<$z-1;$j++) { $day = $days[$i]; $lef = $left[$i]; @dchore = split("\-",$day); $m = $dchore[int(rand($#dchore))+1]; $chores[$j][$i+1] = $m; $m = "-" . $m . "-"; $day =~ s/($m)/\-/g; $lef =~ s/($m)/\-/g; $days[$i] = $day; $left[$i] = $lef; } } #insert the required chores for ($i=0;$i<6;$i++) { $lef = $left[$i]; while ($lef =~ /[0-9]/){ @nums = split("\-",$lef); do { $n = int(rand($z)); $m = "-" . $chores[$n][$i+1] . "-"; } while ($staticleft =~ $m); $chores[$n][$i+1] = $nums[1]; $m = "-" . $nums[1] . "-"; $lef =~ s/$m/\-/g; } } @left; $count = 0; #shuffle the chores until we get as unique of values as possible while (! $sorted && $count < 45) { #shuffle the list a maximum of 45 times (so we don't get stuck in an infinite loop) $sorted = 1; for ($j=0;$j<$z-1;$j++) { $left[$j] = "-"; for ($i=0;$i<6;$i++) { $q = ''; $p = "-" . $chores[$j][$i+1] . "-"; if ($left[$j] =~ $p) { $sorted = 0; $q = 'z'; for ($n=$0;$n<$z-1;$n++) { $m = "-" . $chores[$n][$i+1] . "-"; if ($left[$j] !~ $m && $left[$n] !~ $p) { $q = $chores[$j][$i+1]; $chores[$j][$i+1] = $chores[$n][$i+1]; $chores[$n][$i+1] = $q; break; } } if ($q eq 'z') { @nums = split("\-",$days[$i]); for ($n=0;$n<$#nums;$n++) { $m = "-" . $nums[$n] . "-"; if ($nums[$n] ne '' && $left[$j] !~ $m && $staticleft !~ $p) { $q = $chores[$j][$i+1]; $chores[$j][$i+1] = $nums[$n]; $nums[$n] = $q; $days[$i] = join("\-",@nums); break; } } } } $left[$j] .= $chores[$j][$i+1] . "-"; } } $count++; } #print the results for ($i = 0; $i<$#chores; $i++) { print ""; for ($j = 0; $j<6;$j++) { print "\n"; } print ""; } # if anybody must have a designated chore or set of chores separate from the rest of the list, insert table codes here for ($i=0; $i<$#samechores; $i++) { my ($p,$c) = split(',',$samechores[$i]); print "\n" . "\n" x 5 . ""; } #print "\n" . "\n" x 5; print "
 
Monday
Tuesday
Wednesday
Thursday
Friday
" . $chores[$i][$j] . "
$p$c
Mike Hansen14






Shuffled list $count times
"; if (! $sorted) { print "UNSUCCESSFUL RANDOMIZATION. SHUFFLE EXCEEDED MAXIMUM COUNT
"; } print "
";