#!/bin/bash

f() {
    t=0 ;# if this was a standalone program, t is auto initialised to 0

# The following lines may be put in a standalone script file and run as is:
b=10
for i;{((t+=$b#$i,b=i));}
echo $t

}

for testcase in \
  "4 12 34 20 14 6 25 13 33" \
  "5 14 2 11 30 18" \
  "12 11 10 9 8 7 6 5 4 3 12 2 11 3 10 2 10" \
  "36 36"
    do
    f $testcase
done