Created
June 20, 2025 06:15
-
-
Save olegwtf/6beeab83d5ce139e822313eabfda71e3 to your computer and use it in GitHub Desktop.
credit calc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use v5.10; | |
| use strict; | |
| use warnings; | |
| use Time::Piece; | |
| use Time::Seconds; | |
| use constant { | |
| LOAN => 500000, | |
| PERCENT => 25, | |
| START_DATE => '2025-03-26', | |
| DATE_FORMAT => '%Y-%m-%d"', | |
| }; | |
| my $start_date = Time::Piece->strptime(START_DATE, DATE_FORMAT); | |
| open my $fh, '<payments' or die $!; | |
| my $remaining = LOAN; | |
| for my $str (<$fh>, Time::Piece->new->strftime(DATE_FORMAT) . ' ' . 0) { | |
| my ($date, $sum) = split /\s+/, $str; | |
| $date = Time::Piece->strptime($date, DATE_FORMAT) if !ref $date; | |
| my $days_diff = int Time::Seconds->new($date - $start_date)->days; | |
| $remaining -= $sum - $remaining * PERCENT / 100 / 365 * $days_diff; | |
| $start_date = $date; | |
| } | |
| say $remaining; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment