aboutsummaryrefslogtreecommitdiff
path: root/challenge-100/james-smith
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-02-16 12:28:37 +0000
committerdrbaggy <js5@sanger.ac.uk>2021-02-16 12:28:37 +0000
commitfcb709b3c5c138a2c135f0c0c06133f87bb08225 (patch)
tree7a1a681891b8817301b832e10287314e9538b91a /challenge-100/james-smith
parente8c486430d342251c294715ce63eef0aff4f6944 (diff)
downloadperlweeklychallenge-club-fcb709b3c5c138a2c135f0c0c06133f87bb08225.tar.gz
perlweeklychallenge-club-fcb709b3c5c138a2c135f0c0c06133f87bb08225.tar.bz2
perlweeklychallenge-club-fcb709b3c5c138a2c135f0c0c06133f87bb08225.zip
one-liner down to 117 characters! 109 bytes of usefulness! by switching to "pop" rather than "shift"
Diffstat (limited to 'challenge-100/james-smith')
-rw-r--r--challenge-100/james-smith/perl/ch-1.pl8
1 files 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 | )