From fcb709b3c5c138a2c135f0c0c06133f87bb08225 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Tue, 16 Feb 2021 12:28:37 +0000 Subject: one-liner down to 117 characters! 109 bytes of usefulness! by switching to "pop" rather than "shift" --- challenge-100/james-smith/perl/ch-1.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/challenge-100/james-smith/perl/ch-1.pl b/challenge-100/james-smith/perl/ch-1.pl index 818f9781e2..4d83710a33 100644 --- a/challenge-100/james-smith/perl/ch-1.pl +++ b/challenge-100/james-smith/perl/ch-1.pl @@ -37,13 +37,15 @@ done_testing(); #23456789012345678901234567890123456789012345678901234567890 ## Just split so slightly more readable and fits on 60 char lines - -sub ft{$_[0]=~s{(\d+):(\d+)\s*(\wm|)}{sprintf'%02d:%02d%s', +## Not nasty hack - we pop rather than shift as it saves 2 bytes! +sub ft{pop=~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 { - return $_[0] =~ + return pop =~ + ## Note the nasty hack we pop rather than shift - that saves 2 bytes + ## in our golfdom.... s{ ## Split into 3 parts, $1 - hours, $2 - minutes & $3 - am/pm (\d+) : (\d+) \s* ( \wm | ) -- cgit