diff options
| author | James Smith <js5@sanger.ac.uk> | 2023-03-27 22:13:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-27 22:13:45 +0100 |
| commit | 236529b48e11f0d4bc8f912db5d21482eafa7a78 (patch) | |
| tree | c910355a843021dd124ead316b9f882753564f56 /challenge-210 | |
| parent | 45a2931a966fbde04251e2e183a7b70336fbb792 (diff) | |
| download | perlweeklychallenge-club-236529b48e11f0d4bc8f912db5d21482eafa7a78.tar.gz perlweeklychallenge-club-236529b48e11f0d4bc8f912db5d21482eafa7a78.tar.bz2 perlweeklychallenge-club-236529b48e11f0d4bc8f912db5d21482eafa7a78.zip | |
Update README.md
Diffstat (limited to 'challenge-210')
| -rw-r--r-- | challenge-210/james-smith/README.md | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/challenge-210/james-smith/README.md b/challenge-210/james-smith/README.md index f1b4be3c65..2888dd9d66 100644 --- a/challenge-210/james-smith/README.md +++ b/challenge-210/james-smith/README.md @@ -61,17 +61,19 @@ We can use a stack to achieve this. We start with an empty stack and follow thes 2) **IF** the absolute value for the top of the stack and the next value **THEN** we remove the value from the stack and throw away the current value; - 3) **IF** the absolute value for the top of the stack is greater than the absolute value of the next value **THEN** we remove the value from we throw the current value away; + 3) **IF** the absolute value for the top of the stack is less than the absolute value of the next value **THEN** we remove the value from the top of the stack; - 4) **Otherwise (IF)** the absolute value for the top of the stack is less than the absolute value of the next value **THEN** we remove the value from the top of the stack. + 4) **Otherwise (IF)** the absolute value for the top of the stack is greater than the absolute value of the next value **THEN** we just throw the current value away. ```perl sub collision { my @s; - $_[0]>0 || !@s || $s[-1] < 0 ? push @s, shift - : $s[-1] == -$_[0] ? pop @s && shift - : $s[-1] >= -$_[0] ? shift - : pop @s + !@s || + $_[0] > 0 || + 0 > $s[-1] ? push @s, shift + : -$_[0] == $s[-1] ? pop @s && shift + : -$_[0] >= $s[-1] ? pop @s + : shift while @_; @s } |
