diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-04-01 20:00:28 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-04-01 20:00:28 +0100 |
| commit | fa32da963e308b7fa2b8ddef03f840f81411f7fd (patch) | |
| tree | 521e610ec743a4410d811b56505dc2f63ddf91ba | |
| parent | dabb35cfbd48996b9fa92ca70b819a67ea27e374 (diff) | |
| download | perlweeklychallenge-club-fa32da963e308b7fa2b8ddef03f840f81411f7fd.tar.gz perlweeklychallenge-club-fa32da963e308b7fa2b8ddef03f840f81411f7fd.tar.bz2 perlweeklychallenge-club-fa32da963e308b7fa2b8ddef03f840f81411f7fd.zip | |
- Added bash solution by Pete Houston.
| -rw-r--r-- | challenge-106/pete-houston/bash/ch-1.sh | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-106/pete-houston/bash/ch-1.sh b/challenge-106/pete-houston/bash/ch-1.sh new file mode 100644 index 0000000000..b309bb3c29 --- /dev/null +++ b/challenge-106/pete-houston/bash/ch-1.sh @@ -0,0 +1,37 @@ +#!/bin/bash +#=============================================================================== +# +# FILE: 10601.sh +# +# USAGE: ./10601.sh < infile +# +# DESCRIPTION: Output maximum difference between adjacent integers. +# Input should be a set of integers separated by +# whitespace (incl. newlines) +# +# REQUIREMENTS: Inputs must all be integers otherwise they will be +# skipped +# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk +# ORGANIZATION: Openstrike +# VERSION: 1.0 +# CREATED: 30/03/21 +#=============================================================================== + +prev='z' +max=0 + +adjdiff () { + if [ $prev != 'z' ]; then + mydiff=$(($1 - $prev)) + if [ $mydiff -gt $max ]; then + max=$mydiff + fi + fi + prev=$1 +} + +sed -e 's/[ \t]/\n/g' | grep -E '^-?[0-9]+$' | sort -un | while read line +do + adjdiff $line + echo $max +done | tail -1 |
