|
Post by 128Gigabytes on Apr 28, 2017 4:29:49 GMT
Create a sorting function (That sorts in alphabetical order, or reverse alphabetical order.)
Obviously you can not use default library functions like table.sort in lua.
Input can be whatever you want as long as you can add more arguments Examples of acceptable input An array A tuple A string with a pattern in in like "Dog; Cat; Bird;"
|
|
|
Post by 128Gigabytes on May 7, 2017 0:42:24 GMT
Here I'll get us started 121 characters, lua
function a(b)c=0 for x=1,#b-1 do if b[x]>b[x+1] then b[x],b[x+1]=b[x+1],b[x]c=1 end end if c==1 then a(b)end return b end
Example of use
for _, v in next, a({}) do
print(v)
end
|
|
|
Post by AxonMega on May 7, 2017 12:15:00 GMT
Mine is 95 characters, Lua.
function s(a)i=1 while i<#a do if a>a[i+1] then a,a[i+1]=a[i+1],ai=0 end i=i+1 end end
example of use:
a = {"Q", "J", "S", "J", "X", "A"} s(a) print(unpack(a))
|
|
|
Post by Josh on May 7, 2017 12:17:49 GMT
Mine is 95 characters, Lua. function s(a)i=1 while i<#a do if a>a[i+1] then a,a[i+1]=a[i+1],ai=0 end i=i+1 end end
example of use:
a = {"Q", "J", "S", "J", "X", "A"}
s(a)
print(unpack(a))
Nice!
|
|
|
Post by AxonMega on May 7, 2017 12:20:38 GMT
thnx
|
|
|
Post by 128Gigabytes on May 7, 2017 20:34:59 GMT
AxonMega Sorry but it looks like you made a mistake somewhere, your code errors, feel free to edit your answer and fix it though!
|
|
|
Post by AxonMega on May 7, 2017 20:49:51 GMT
It looks like some of my code got removed; what appears now is only 86 characters.
|
|
|
Post by 128Gigabytes on May 7, 2017 21:42:42 GMT
Huh, well I did edit your reply and Joshs so your code was inside code blocks but I don't think I removed anything (Or if I did, I accidentally did it twice, if so sorry!) could you please message me the fixed one so I can edit your reply, again very sorry if it was something I did.
|
|
|
Post by AxonMega on May 8, 2017 13:42:08 GMT
Here's the original:
function s(a)i=1 while i<#a do if a>a[i+1] then a,a[i+1]=a[i+1],ai=0 end i=i+1 end end
--example: a = {"Q", "J", "S", "J", "X", "A"} s(a) print(unpack(a))
|
|
|
Post by Josh on May 8, 2017 14:39:40 GMT
Here's the original: function s(a)i=1 while i<#a do if a >a[i+1] then a,a[i+1]=a[i+1],ai=0 end i=i+1 end end
--example: a = {"Q", "J", "S", "J", "X", "A"} s(a) print(unpack(a))This is also 86 characters AxonMega.
|
|
|
Post by AxonMega on May 8, 2017 14:51:30 GMT
function s(a)i=1 while i<#a do if a>a[i+1] then a,a[i+1]=a[i+1],ai=0 end i=i+1 end end
|
|
|
Post by AxonMega on May 8, 2017 14:52:14 GMT
function s(a)i=1 while i<#a do if a>a[i+1] then a,a[i+1]=a[i+1],ai=0 end i=i+1 end end
|
|
|
Post by AxonMega on May 8, 2017 14:52:26 GMT
What in tarnation is going on here?
|
|
|
Post by Bit on May 8, 2017 19:47:17 GMT
Axon, just put it in code blocks to avoid formatting killing it.
|
|
|
Post by AxonMega on May 8, 2017 23:59:18 GMT
function s(a)i=1 while i<#a do if a[i]>a[i+1] then a[i],a[i+1]=a[i+1],a[i]i=0 end i=i+1 end end
Example:
a = {"Q", "J", "S", "J", "X", "A"} s(a) print(unpack(a))
|
|