aboutsummaryrefslogtreecommitdiff
path: root/challenge-197/deadmarshal/lua/ch-2.lua
blob: 252eb43d07a1c0067134390e9a70ffe8327e8cf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
local function wiggle_sort(t)
  for i=1, #t-1 do
    if (i % 2 ~= 0) == (t[i] > t[i+1]) then
      t[i],t[i+1] = t[i+1],t[i]
    end
  end
end

local t1,t2 = {1,5,1,1,6,4},{1,3,2,2,3,1}
wiggle_sort(t1)
wiggle_sort(t2)
print(table.concat(t1,' '))
print(table.concat(t2,' '))