How do I reduce/shorten this one line of code?


#1

I feel like I should know this, but I am drawing a blank at the moment…

I added a new line of code to an old piston, and now the piston is too large to save.
To create space, I am trying to streamline the following code:

Set variable x = max(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9])

Can anyone please help?

My numbers actually go up to a[69], but if I can reduce the above, I can apply what I learn to the larger issue.

Thanks in advance.


#2

Can you sort the array and take either the first or last element (depending on how its sorted).


#3

Thanks for the input. Unfortunately, I cannot sort this array because I need them to retain the precise order they are in to draw my graph accurately.


#4

I don’t have time to try this now, but what if you did something like:

define variable maxSoFar
Set variable maxSoFar = a[0]
For x between 1 and 69
Set variable maxSoFar = max (maxSoFar,a[x])
x == x+1

I don’t know if that’ll actually save you code space or not but it’s all my foggy brain can come up with at the moment.


#5

You could alternatively do…

define variable maxSoFar = a[0]
define x = 1
repeat
  if  a[x] > maxSoFar then maxSoFar = a[x]
  x = x+1
until x=69

Both should work.