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

Sorting Problems

Started by Evil_Bengt, 03 October 2014 - 05:35 AM
Evil_Bengt #1
Posted 03 October 2014 - 07:35 AM
I'm having real problems with sorting numbers and stuff with lua… Is there any way to like sort 4 numbers that is in the same variable from highest to lowest… Like 9826 to 9862 and vice versa? :D/>
theoriginalbit #2
Posted 03 October 2014 - 07:44 AM
Can we see the code that you've tried so far, and what these 'real problems' are that you've been having with them? that way we can give you better advice for your specific problem.
Evil_Bengt #3
Posted 03 October 2014 - 02:49 PM
I haven't really started on anything with that yet… It's just a fun idea I got from this vid:

https://www.youtube.com/watch?v=d8TRcZklX_Q

I thought that I could make some fun generator with this to test numbers…
To do that one have to sort the numbers in falling order and subtract the opposite, like this example:

input: 6548
computation: 8654 - 4568
theoriginalbit #4
Posted 03 October 2014 - 02:52 PM
okay, well you'll want to take a look into tables. you can then make use of the table.sort function which will sort the values within the table
Evil_Bengt #5
Posted 03 October 2014 - 11:06 PM
Nice, I've been reading the online lua book thingy and when you say it, I remember that I've read about that sort function! Thanks alot!