diff options
| -rw-r--r-- | challenge-102/james-smith/perl/ch-2.pl | 8 | ||||
| -rw-r--r-- | challenge-102/james-smith/php/ch-2.php | 6 |
2 files changed, 6 insertions, 8 deletions
diff --git a/challenge-102/james-smith/perl/ch-2.pl b/challenge-102/james-smith/perl/ch-2.pl index 015e40dc98..a3a89a7184 100644 --- a/challenge-102/james-smith/perl/ch-2.pl +++ b/challenge-102/james-smith/perl/ch-2.pl @@ -45,9 +45,9 @@ done_testing(); sub hash_count_string { my ( $s, $n ) = ( '', @_ ); - do { - return $s if $n == length $s; - return "#$s" if $n-1 == length $s; - } while $s = ($n-length $s) ."#$s"; + + ( $s, $n ) = ( $n.'#'.$s, $n-1-length $n ) while $n > 1; + + return ( $n? '#' : '' ).$s; } 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; } |
