• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# PEE PEE POO POO

a guest Sep 15th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. local function uglytest(arr)
2.     local function nondecreasing(arr)
3.         for i = 1, #arr - 1 do
4.             if arr[i] > arr[i + 1] then
5.                 return false
6.             end
7.         end
8.
9.         return true
10.     end
11.
12.     for j = 1, #arr do
13.         local val = table.remove(arr, j)
14.         if not nondecreasing(arr) then
15.             table.insert(arr, j, val)
16.         else
17.             return true
18.         end
19.     end
20.
21.     return false
22. end
23.
24. assert(test({ }) == true)
25.
26. assert(test({ 0 }) == true)
27.
28. assert(test({ 0, 0 }) == true)
29. assert(test({ 0, 1 }) == true)
30. assert(test({ 1, 0 }) == true)
31.
32. for a = 0, 2 do for b = 0, 2 do for c = 0, 2 do
33.     print(a, b, c, test({ a, b, c }))
34.     assert(test({ a, b, c }) == uglytest({ a, b, c }))
35. end end end
36. for a = 0, 3 do for b = 0, 3 do for c = 0, 3 do for d = 0, 3 do
37.     print(a, b, c, d, test({ a, b, c, d }))
38.     assert(test({ a, b, c, d }) == uglytest({ a, b, c, d }))
39. end end end end
40.
41. for a = 0, 4 do for b = 0, 4 do for c = 0, 4 do for d = 0, 4 do for e = 0, 4 do
42.     print(a, b, c, d, e, test({ a, b, c, d, e }))
43.     assert(test({ a, b, c, d, e }) == uglytest({ a, b, c, d, e }))
44. end end end end end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top