Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- function add_arrays(arr1,arr2)
- len1= #arr1
- len2= #arr2
- arr3= arr1
- for i=len1,len1+len2 do
- arr3[#arr3+1]= arr2[i]
- end
- return arr3
- end
- function cut_array(array,ot,dos)
- res= {}
- for i=ot,dos do
- res[#res+1]= array[i]
- end
- return res
- end
- function gen_num()
- matrix= {}
- status= true
- while status do
- number= math.random(0,36)
- stat= false
- for i=1,#matrix do
- if number == matrix[i]
- then
- stat= true
- break
- end
- end
- if stat == false
- then
- matrix[#matrix+1]= number
- end
- if #matrix == 36
- then
- break
- end
- end
- return matrix
- end
- function add_to_base(array,base)
- stat= false
- for i=1,#base do
- if base[i][1] == array[2]
- then
- return base
- end
- end
- for i=1,#base do
- if base[i][1] == array[1]
- then
- stat= true
- end
- end
- if stat == false
- then
- base[#base+1]= {}
- c= 1
- for i=2,8 do
- base[#base][c]= array[i]
- c= c+1
- end
- return base
- else
- return base
- end
- end
- function winers(base,random_numbers)
- winers= {}
- for i=1,#base do
- c= 1
- count= 0
- for q=2,7 do
- if base[i][q] == random_numbers[c]
- then
- count= count+1
- else
- break
- end
- c= c+1
- end
- winers[#winers+1]= {}
- winers[#winers][1]= base[i][1]
- winers[#winers][2]= count
- end
- return winers
- end
- function sorts(array)
- for i=1,#array do
- for q=1,#array do
- if array[q+1] == nil
- then
- break
- end
- if array[q]>array[q+1]
- then
- temp= 0
- temp= array[q]
- array[q]= array[q+1]
- array[q+1]= temp
- end
- end
- end
- for i=1,#matrix do
- write(array[i].." ")
- end
- end
- base= {}
- winer= {}
- warnings= {}
- time= 0
- max_time= 120
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print(time)
- os.startTimer(1)
- event,id,message,distance= os.pullEvent()
- --print(event," ",id," ",message)
- if event == "rednet_message"
- then
- data= {}
- data= textutils.unserialize(message)
- if data[1] == "start"
- then
- n= gen_num()
- data= {}
- data[1]= "numbers"
- data= add_arrays(data,n)
- message= textutils.serialize(data)
- rednet.send(id,message)
- end
- if data[1] == "finish"
- then
- base= add_to_base(data,base,warnings)
- end
- end
- if event == "timer"
- then
- time= time+1
- if time == max_time
- then
- n= gen_num()
- winer= winers(base,n)
- for i=1,#winer do
- for q=1,#winer[i] do
- write(winer[i][q].." ")
- end
- print()
- end
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement