aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-208/james-smith/README.md17
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