The challenge wasn't to create some reusable library code, or to demonstrate good programming practice, but to calculate the Standard Deviation in the shortest possible way in BBC BASIC. Like all similar 'minimum code' challenges anything goes unless explicitly ruled out.
If you don't want to destroy the contents of the array then simply make a copy of the original array first:
Code: Select all
copy() = array()
All of the whole-array operations in BBC BASIC make the same assumptions, it's a feature of the language; it's no more necessary to state that explicitly for this example than it is for the built-in operations like SUM, MOD and the dot-product operator, or for that matter the routines in the arraylib library.This solution assumes that the array is being used 0-based, and has no "empty" entries ,e.g. at the top
I expect your preferred programming language allows you to specify a subset of the array on which 'whole array' operations are performed. Clearly that is a valuable extension, and one which I wish Sophie had implemented when the whole-array operations were added in 1986. But it's not one which BBC BASIC supports, and the best you can do is to adopt the technique described in the Wiki here.
I will leave it as an exercise to extend the code in the Wiki to specify both the starting element and the length of the partial array, and to support MOD as well as SUM.