X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=blobdiff_plain;f=quacks-ingredients-counts;h=5377cbcb1d53e18e982b95d4bddbbe898d3e5ed5;hp=0affe2efe4eee8892bd45228c0fbaa23c969cd29;hb=HEAD;hpb=43b7e9e700151cda673bad9642640eb444517306 diff --git a/quacks-ingredients-counts b/quacks-ingredients-counts index 0affe2e..5377cbc 100755 --- a/quacks-ingredients-counts +++ b/quacks-ingredients-counts @@ -1,25 +1,111 @@ #!/usr/bin/perl -w +use strict; + use Data::Dumper; +use POSIX; + +our $which = shift @ARGV; + +sub xdata ($) { + my ($cb) = @_; + return unless $which eq 'Base'; + foreach my $count (qw(1 2 3)) { + foreach my $nspots (qw(0 1 2 3 4)) { + $_ = $cb->($count,$nspots)."\t".$_; + } + } +} $_=; chomp or die; +xdata sub { + my ($xcount,$xnspots) = @_; + "${xcount}x". (qw(Zero One Two Three Four)[$xnspots]); +}; our @names = split /\t/, $_; our %count; -foreach my $nspots (qw(1 2 3 4)) { +foreach my $nspots (qw(1 2 3 4 0)) { $_=; chomp or die; + xdata sub { + my ($xcount,$xnspots) = @_; + $xnspots == $nspots and "$xcount+0"; + }; my @l = split /\t/, $_; - foreach my $i (0..$#names) { $count{$names[$i]}{$nspots} = $l[$i] // 0; } + foreach my $i (0..$#names) { + $_ = $l[$i] || '0+0'; + $_ ||= 0; + m/\+/ or die "$which $nspots ?"; + + $count{$names[$i]}{$nspots} = + $which eq 'All' ? $` + $' : + $which eq 'Base' ? $` : + $which eq 'Witches' ? $' : + die "$which ?"; + } } $_ = Dumper(\%count); s{^}{// }mg; -print or die $!; +#print STDERR; + +our $name; +our $total_count; +our $total_real_count; +our $max_nrows=0; +our $max_rowsz=0; + +sub wrtoplevel () { + my $cs = $count{$name}; + my $total = 0; $total += $_ foreach values %$cs; + return unless $total; + print "module ${which}_$name(){ ////toplevel\n"; + my $rowsz = ceil(sqrt($total)); + my $nrows = ceil($total / $rowsz); + $total_count += $total; + $total_real_count += $total if $name =~ m/^[A-Z][a-z]+$/; + $max_nrows = $nrows if $nrows > $max_nrows; + $max_rowsz = $rowsz if $rowsz > $max_rowsz; + my $ix = 0; + printf "// %s %-10s total=%2d rowsz=$rowsz nrows=$nrows\n", + $which, "$name", $total; + foreach my $nspots (sort keys %$cs) { + my $c = $cs->{$nspots}; + print <error and die $!; __DATA__ -White Green Blue Red Yellow Purple Black Orange -20 15 14 12 13 15 18 20 -8 10 10 8 6 -4 - 13 10 10 10 +White Green Blue Red Yellow Purple Black Orange Orange6 Loco WhiteSpare +21+6 15+10 14+8 12+6 13+6 15+8 18+8 20+12 1+0 +9+3 10+5 10+5 8+5 6+5 1+0 +5+2 1+0 + 13+5 10+5 10+5 10+5 + 0+20 0+25