This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
augustas656's profile picture

math.max from a table

Started by augustas656, 31 December 2013 - 10:06 PM
augustas656 #1
Posted 31 December 2013 - 11:06 PM
Does anyone know a very efficient and compact way of finding the highest number in a table that consists of number variables only? Especially this:

example = {}
example.A = 5
example.B = 15
example.C = 10
example.max = Formula that works out the highest number of all
the variables in the example table apart from this variable itself.

Thank you
Edited on 31 December 2013 - 10:07 PM
Lyqyd #2
Posted 31 December 2013 - 11:08 PM
math.max(unpack(example))
augustas656 #3
Posted 31 December 2013 - 11:16 PM
Thank you, also, specifically I want to findout the most compact way of finding the highest text length from a table of strings only.
Edited on 31 December 2013 - 10:20 PM
OReezy #4
Posted 01 January 2014 - 12:21 AM
You can use # to get the length of strings and tables.

Ex: Length of strings
#stringVar
#table[1]

Ex: Length of table
#table
Edited on 31 December 2013 - 11:23 PM