aboutsummaryrefslogtreecommitdiff
path: root/challenge-102/james-smith/php/ch-2.php
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-03-02 18:37:38 +0000
committerdrbaggy <js5@sanger.ac.uk>2021-03-02 18:37:38 +0000
commitbd220f937a3e68f7904f29856a15da7929ba6aab (patch)
tree55448fa3f9bbdce6bd5c7014b66f8d2c8e199afb /challenge-102/james-smith/php/ch-2.php
parentbeb85731c96259b8a964daa71e9ec5eb7e6a047d (diff)
downloadperlweeklychallenge-club-bd220f937a3e68f7904f29856a15da7929ba6aab.tar.gz
perlweeklychallenge-club-bd220f937a3e68f7904f29856a15da7929ba6aab.tar.bz2
perlweeklychallenge-club-bd220f937a3e68f7904f29856a15da7929ba6aab.zip
remove need for lots of len calls - and reduce loop to a single line
Diffstat (limited to 'challenge-102/james-smith/php/ch-2.php')
-rw-r--r--challenge-102/james-smith/php/ch-2.php6
1 files changed, 2 insertions, 4 deletions
diff --git a/challenge-102/james-smith/php/ch-2.php b/challenge-102/james-smith/php/ch-2.php
index 015733e992..8353e6c2c4 100644
--- a/challenge-102/james-smith/php/ch-2.php
+++ b/challenge-102/james-smith/php/ch-2.php
@@ -14,9 +14,7 @@ foreach( range(1,20) as $_ ) {
function hash_count_string($n) {
$s = '';
- do {
- if( $n == strlen($s) ) return $s;
- if( $n-1 == strlen($s) ) return "#$s";
- } while( $s = ($n-strlen($s)) ."#$s" );
+ while($n>1) list($s,$n) = ["$n#$s",$n-1-strlen($n)];
+ return ( $n? '#' : '' ).$s;
}