From fa32da963e308b7fa2b8ddef03f840f81411f7fd Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Thu, 1 Apr 2021 20:00:28 +0100 Subject: - Added bash solution by Pete Houston. --- challenge-106/pete-houston/bash/ch-1.sh | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 challenge-106/pete-houston/bash/ch-1.sh (limited to 'challenge-106') 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 -- cgit