compute the change in led and keep on adding the change
$ sum = $ Led [ $ n [ 0 ] - '0' ] ; for ( $ i = 1 ; $ i < $ len ; $ i ++ ) { $ sum = $ sum + abs ( $ Led [ $ n [ $ i ] - '0' ] - $ Led [ $ n [ $ i - 1 ] - '0' ] ) ; } return $ sum ; }