diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-07-06 01:19:21 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-07-06 01:19:21 +0100 |
| commit | fe32ae54b9a8097119b2d2063b43b663e3d0ad2b (patch) | |
| tree | fb468611ebbf5ea4825da1bf774c2a55c562f049 | |
| parent | 7e8ee000d1f104332905832b4324ecc00d9f6e82 (diff) | |
| parent | 9fc665f377d858e0304a703ddc9542cc0c325bd3 (diff) | |
| download | perlweeklychallenge-club-fe32ae54b9a8097119b2d2063b43b663e3d0ad2b.tar.gz perlweeklychallenge-club-fe32ae54b9a8097119b2d2063b43b663e3d0ad2b.tar.bz2 perlweeklychallenge-club-fe32ae54b9a8097119b2d2063b43b663e3d0ad2b.zip | |
Merge branch 'master' of github.com:drbaggy/perlweeklychallenge-club
| -rw-r--r-- | challenge-172/james-smith/README.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/challenge-172/james-smith/README.md b/challenge-172/james-smith/README.md index 6cd02905cc..7fe8ecdb67 100644 --- a/challenge-172/james-smith/README.md +++ b/challenge-172/james-smith/README.md @@ -42,6 +42,21 @@ sub partition { **Note** we add a `0` to `@_` so that if (in the first call) `@_` only has two numbers `$p` is set to zero. +### Only one partition + +If you only wish to get **a** partition then we simply tweak the code to have a return in the inner map - to return the entry if we find it! + +```perl +sub first_partition { + my ( $m, $n, $p ) = ( @_, 0 ); + $n > 1 + ? map { $p = $_; + map { return [ $p, @{$_} ] } first_partition( $m-$p, $n-1, $p ) + } @{ primes $p+1, int( ( $m - $n/2 + 1/2 ) / $n ) } + : $m > $p && is_prime $m ? [ $m ] : (); +} +``` + # Task 2 - Five number summary ***You are given an array of integers. Write a script to compute the five-number summary of the given set of integers. (min,lower-quartile,median,upper-quarile,max)*** |
