diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-02-16 12:14:50 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-02-16 12:14:50 +0000 |
| commit | cf6927881376ec265295b932b345c8e0c588352b (patch) | |
| tree | c52a3ac10d24edc4e294a4d4635d411126ac85c4 | |
| parent | fb3e826100dc7388e6d6cd04ac61555db881d02b (diff) | |
| download | perlweeklychallenge-club-cf6927881376ec265295b932b345c8e0c588352b.tar.gz perlweeklychallenge-club-cf6927881376ec265295b932b345c8e0c588352b.tar.bz2 perlweeklychallenge-club-cf6927881376ec265295b932b345c8e0c588352b.zip | |
a bit of golf
| -rw-r--r-- | challenge-100/james-smith/perl/ch-1.pl | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/challenge-100/james-smith/perl/ch-1.pl b/challenge-100/james-smith/perl/ch-1.pl index e241822661..0e1cb1d401 100644 --- a/challenge-100/james-smith/perl/ch-1.pl +++ b/challenge-100/james-smith/perl/ch-1.pl @@ -6,6 +6,18 @@ use warnings; use feature qw(say); use Test::More; +is( ft( '05:15pm' ), '17:15' ); +is( ft( '05:15 pm' ), '17:15' ); +is( ft( '17:15' ), '05:15pm' ); +is( ft( '05:15am' ), '05:15' ); +is( ft( '05:15 am' ), '05:15' ); +is( ft( '05:15' ), '05:15am' ); +is( ft( '00:00' ), '12:00am' ); +is( ft( '12:00' ), '12:00pm' ); +is( ft( '24:00' ), '12:00pm' ); +is( ft( '12:00 am' ), '00:00' ); +is( ft( '12:00 pm' ), '12:00' ); + is( fun_time( '05:15pm' ), '17:15' ); is( fun_time( '05:15 pm' ), '17:15' ); is( fun_time( '17:15' ), '05:15pm' ); @@ -18,28 +30,19 @@ is( fun_time( '24:00' ), '12:00pm' ); is( fun_time( '12:00 am' ), '00:00' ); is( fun_time( '12:00 pm' ), '12:00' ); -is( fun_time_readable( '05:15pm' ), '17:15' ); -is( fun_time_readable( '05:15 pm' ), '17:15' ); -is( fun_time_readable( '17:15' ), '05:15pm' ); -is( fun_time_readable( '05:15am' ), '05:15' ); -is( fun_time_readable( '05:15 am' ), '05:15' ); -is( fun_time_readable( '05:15' ), '05:15am' ); -is( fun_time_readable( '00:00' ), '12:00am' ); -is( fun_time_readable( '12:00' ), '12:00pm' ); -is( fun_time_readable( '24:00' ), '12:00pm' ); -is( fun_time_readable( '12:00 am' ), '00:00' ); -is( fun_time_readable( '12:00 pm' ), '12:00' ); - done_testing(); -## 72 chars ############################################################ -## Just split so slightly more readable and fits on 72 char lines +## 72 chars ############################################################# +#000000000111111111122222222223333333333444444444455555555556 +#123456789012345678901234567890123456789012345678901234567890 + +## Just split so slightly more readable and fits on 60 char lines -sub fun_time { $_[0]=~s{(\d+):(\d+)\s*(\wm|)}{sprintf'%02d:%02d%s', - ($1%12||(12*!$3))+12*('pm'eq$3),$2,$3?'':$1>11?'pm':'am'}re; } +sub ft{$_[0]=~s{(\d+):(\d+)\s*(\wm|)}{sprintf'%02d:%02d%s', +($1%12||(12*!$3))+12*('pm'eq$3),$2,$3?'':$1<12?'am':'pm'}re} ## This is more readable version with notes... -sub fun_time_readable { +sub fun_time { return $_[0] =~ s{ ## Split into 3 parts, $1 - hours, $2 - minutes & $3 - am/pm |
