diff options
| author | James Smith <js5@sanger.ac.uk> | 2023-03-17 14:21:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-17 14:21:55 +0000 |
| commit | 0502d0ee7e7c8cab6bc91b96bd1961ae342f64f4 (patch) | |
| tree | 1198ad07fe01401b48d1a98a9e28269e91f33259 | |
| parent | 6d72a63df03a00f3c2f8d992cd7903ccc38faada (diff) | |
| download | perlweeklychallenge-club-0502d0ee7e7c8cab6bc91b96bd1961ae342f64f4.tar.gz perlweeklychallenge-club-0502d0ee7e7c8cab6bc91b96bd1961ae342f64f4.tar.bz2 perlweeklychallenge-club-0502d0ee7e7c8cab6bc91b96bd1961ae342f64f4.zip | |
Update README.md
| -rw-r--r-- | challenge-208/james-smith/README.md | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/challenge-208/james-smith/README.md b/challenge-208/james-smith/README.md index 78914ce0c0..60038de5c3 100644 --- a/challenge-208/james-smith/README.md +++ b/challenge-208/james-smith/README.md @@ -24,13 +24,14 @@ https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-208/ja We proceed to do a pass of each array. ```perl sub min_index_sum { - my( $b, %x, $t, $s, @best ) = ( 1e99, - map { $_[0][$_] => $_ } reverse ( 0 .. $#{$_[0]} ) ); #1 - exists $x{$t = $_[1][$_]} && #3 - ( $b > ($s=$x{$t}+$_) ? ($b,@best) = ( $s,$t ) #4 - : $b == $s && push @best, $t ) #5 - for 0 .. $#{$_[1]}; #2 - return \@best; #6 + my( $b, %x, $t, $s, @best ) = ( 1e99, #0 + map { $_[0][$_] => $_ } reverse ( 0 .. $#{$_[0]} ) #1 + ); + exists $x{$t = $_[1][$_]} && #3 + ( $b > ($s=$x{$t}+$_) ? ($b,@best) = ( $s,$t ) #4 + : $b == $s && push @best, $t ) #5 + for 0 .. $#{$_[1]}; #2 + \@best #6 } ``` @@ -40,6 +41,8 @@ We then loop through the second list of strings (`#2`) looking for words which a At the end we just return the current list of words (which could be empty if there are no duplicates). (`#6`) +Note we set the initial best index sum (`#0`) as `10^99` as the index sum will be no where near this and so we can treat this as effectively infinity... + # Task 2: Duplicate and Missing Try all combinations and |
