sample code from Wednesday evening
Tkil
tkil-sdpm at scrye.com
Fri Feb 22 00:50:40 CST 2002
~sdpm~
Sorry that it took me so long to post this.
First, the sample data, in file "ppe.log":
-------------------------------------------------------------------------------
ETN=s04619 Step_name=Drill_Chart Elapsed_time=1456 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04619 Step_name=Stackup Elapsed_time=2586 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04619 Step_name=Data_review Elapsed_time=8422 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04619 Step_name=CAM_inst Elapsed_time=1118 Finished=Yes Clock=No Epoch=0 ip=
booga booga!
ETN=s04619 Step_name=Drill_and_Inners Elapsed_time=27918 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04619 Step_name=Traveler_BOM Elapsed_time=7098 Finished=No Clock=No Epoch=0 ip=
ETN=s04621 Step_name=Drill_Chart Elapsed_time=9525 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04621 Step_name=Stackup Elapsed_time=2665 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04621 Step_name=Data_review Elapsed_time=10117 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04621 Step_name=CAM_inst Elapsed_time=2032 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04621 Step_name=Drill_and_Inners Elapsed_time=1032 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04621 Step_name=Traveler_BOM Elapsed_time=4021 Finished=No Clock=No Epoch=0 ip=
ETN=s04621 Step_name=CAM_inst Elapsed_time=10322 Finished=Yes Clock=No Epoch=0 ip=
ETN=s04621 Step_name=Fake_Step_1 Elapsed_time=13402 Finished=No Clock=No Epoch=0 ip=
ETN=s04619 Step_name=Data_review Elapsed_time=10032 Finished=Yes Clock=No Epoch=0 ip=
-------------------------------------------------------------------------------
Then the code we came up with:
-------------------------------------------------------------------------------
#!/usr/local/bin/perl -w
use strict;
use Data::Dumper qw(Dumper);
my %hash;
open IN, "ppe.log" or die "opening: $!";
while (<IN>)
{
if (/ETN=(\w+) .*?
Step_name=(\w+) .*?
Elapsed_time=(\d+)/x)
{
my ($etn, $step, $time) = ($1, $2, $3);
$hash{$etn}{$step} += $time;
}
else
{
print STDERR "couldn't parse line $.: $_";
}
}
close IN or die "closing: $!";
print STDERR Dumper(\%hash);
while (my ($etn, $info) = each %hash)
{
local *OUT;
open OUT, ">$etn.out" or die "opening $etn.out: $!";
while (my ($step, $total) = each %$info)
{
printf OUT "%-30s %6d\n", $step.":", $total;
}
close OUT or warn "closing $etn.out: $!";
}
-------------------------------------------------------------------------------
My perl examples are at this URL, although I've had difficulty getting
to the box lately (it's still up, but there's some sort of routing
nastiness going on at the moment):
http://slinky.scrye.com/~tkil/perl/
Finally, here's the C version of the "mystery m function" problem from:
http://www.itasoftware.com/careers/programmers.php
-------------------------------------------------------------------------------
#include <stdio.h>
int m(int i, int j, int k)
{
static int count = 0;
int rv;
if (i == 0) { rv = k+1; }
else if (i == 1 && k == 0) { rv = j; }
else if (i == 2 && k == 0) { rv = 0; }
else if (k == 0) { rv = 1; }
else { rv = m(i-1, j, m(i, j, k-1)); }
++count;
if ((count & 0xffff) == 0x0)
{
fprintf(stderr, "%08x: m(%d,%d,%d)=%d\n",
count, i, j, k, rv);
}
return rv;
}
int main (int argc, char * argv [] )
{
printf("m(4,4,4)=%d\n", m(4,4,4));
return 0;
}
-------------------------------------------------------------------------------
I ran it on my friend's box (1GHz Athlon) up to this iteration:
11dc0000: m(1,4,23243)=23247
Since it's still not ending, I basically gave up on actually running
it. If I get some more free time, maybe it's solvable "by hand".
t.
~sdpm~
The posting address is: san-diego-pm-list at hfb.pm.org
List requests should be sent to: majordomo at hfb.pm.org
If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:
unsubscribe san-diego-pm-list
If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.
More information about the San-Diego-pm
mailing list