#! /usr/local/bin/perl -w

use strict;

my $splitRE = "[ ,\t\/|]+";
my $line;

sub getline {
  while(<>) {
    s/^\s*//;
    s/\s*$//;
    next unless length;
    my @data = split /$splitRE/;
#    print "-", join('-', @data), "-\n";
    return @data;
  }
}

$| = 0;
print "cash: "; 
my @cash = getline();
if ($cash[$#cash] eq '-') {
  pop @cash;
  print "cost: ";
  my @cost = getline();
  for(0..$#cash) {
    $cash[$_] -= $cost[$_];
  }
}

print "prod: "; 
my @prod = getline();

print "goal: "; 
my @goal = getline();

my @names = ("wood", "clay", "iron", "crop");
my @time;
foreach(0..$#cash) {
  $time[$_] = ($goal[$_] - $cash[$_]) / $prod[$_];
  $time[$_] = 0 if ($time[$_] < 0);
}
print "time: ", join(' ', @time), "\n";
