Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!
tweet

# First 6 problems by Factis699

By: a guest on Aug 10th, 2011  |  syntax: Lua  |  size: 0.73 KB  |  views: 89  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. --1st problem
2. table_element(table, number)
3.         return table[number]
4. end
5.
6. --2nd problem
7. last_table_element(table)
8.         return table[#table]
9. end
10.
11. --3th problem
12. last_second_table_element(table)
13.         return table[#table - 1]
14. end
15.
16. --4th problem
17. lenght_of_array(table)
18.         return #table
19. end
20.
21. --5th problem - I think on this about 30 mins!
22. reverse_table(table)
23.         local l = {}
24.         for n = 1, #table do
25.                 l[#table + 1 - n] = t[n]
26.         end
27. return l
28. end
29.
30.
31. --6th problem - hardest one!
32. function table_in_palidrome(table)
33.         local n = math.floor(#table / 2)
34.         for p = 1, n do
35.                 if table[p] ~= table[#table - p + 1] then
36.                         return false
37.                 end
38.         end
39.         return true
40. end
clone this paste RAW Paste Data
Top