Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/lua
- io.write('How many people? ')
- p = tonumber(io.read())
- io.write('How many teams? ')
- t = tonumber(io.read())
- if t > p then
- print('Error. You can\'t have more teams than players!')
- os.exit(0)
- end
- -- input
- names = {}
- for i=1,p do
- io.write(i .. ' > ')
- --table.insert(names, io.read())
- table.insert(names, string.char(64 + i))
- end
- -- shuffle
- for i=1,p do
- a = math.random(1,p)
- tmp = names[a]
- names[a] = names[i]
- names[i] = tmp
- end
- -- output
- print('')
- nt = p / t -- base number of people per team
- rem = p % t -- number of extra people
- cpi = 1 -- current player index
- for ti=0,t-1 do
- nt2 = nt
- if ti < rem then nt2 = nt + 1 end
- print('')
- for pi=0,nt2-1 do
- print(names[cpi] .. ' on team ' .. ti)
- cpi = cpi + 1
- end
- end
- os.exit(0)
- for i=1,p do
- print(names[i])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement