Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!bin/perl -w
- sub identifyTax($)
- {
- my ($transactions) = @_;
- my $fee = 5;
- my $maximumTocalculateTax = 100;
- my $minimumTransactionsPerMonth = 3;
- my $numberOfMonthsToChargeFee = 0;
- foreach my $date (keys %{$transactions})
- {
- $_ = $date;
- my $currentMonth = $1 if m/\-(\d{2})\-/;
- my $numberOfTransactionsForCurrentMonth = 0;
- my $numberOfTransactionsWithinTheSameMonthAbove100 = 0;
- my $chargeFeeInThisMonth = 0;
- foreach my $date (keys %{$transactions})
- {
- $_ = $date;
- my $monthToCheck = $1 if m/\-(\d{2})\-/;
- $numberOfTransactionsForCurrentMonth++
- if $monthToCheck eq $currentMonth;
- $numberOfTransactionsWithinTheSameMonthAbove100++
- if $transactions->{$date} >= 100;
- }
- if ($numberOfTransactionsForCurrentMonth >= 1 && $numberOfTransactionsWithinTheSameMonthAbove100 >= 3)
- {
- $chargeFeeInThisMonth = 1;
- }
- $numberOfMonthsToChargeFee++ if $chargeFeeInThisMonth == 1;
- }
- return $numberOfMonthsToChargeFee * $fee;
- }
- sub sumTransactions($)
- {
- my ($transactions) = @_;
- my $totalBalance = 0;
- foreach my $date (keys %{$transactions})
- {
- $totalBalance += $transactions->{$date};
- }
- return $totalBalance;
- }
- my $transactionsArrayRef = [100, 100, 100, -10];
- my $transactionDatesArrayRef = ['2020-12-31', '2020-12-22', '2020-12-03', '2020-12-29'];
- my %transactions;
- @transactions{@{$transactionDatesArrayRef}} = @{$transactionsArrayRef};
- my $tax = identifyTax(\%transactions);
- my $totalBalance = sumTransactions(\%transactions);
- $totalBalance -= $tax;
- print "total balance " . $totalBalance;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement