Advertisement
ZNZNCOOP

lotoserver

Oct 31st, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. rednet.open("top")
  2.  
  3. function add_arrays(arr1,arr2)
  4.    len1= #arr1
  5.    len2= #arr2
  6.    arr3= arr1
  7.    for i=len1,len1+len2 do
  8.    
  9.        arr3[#arr3+1]= arr2[i]
  10.    
  11.    end
  12.    return arr3
  13. end
  14.  
  15. function cut_array(array,ot,dos)
  16.    res= {}
  17.    for i=ot,dos do
  18.       res[#res+1]= array[i]
  19.    end
  20.    return res
  21. end
  22.  
  23. function gen_num()
  24.  
  25.    matrix= {}
  26.    status= true
  27.    while status do
  28.       number= math.random(0,36)
  29.       stat= false
  30.       for i=1,#matrix do
  31.      
  32.          if number == matrix[i]
  33.          then
  34.             stat= true
  35.             break
  36.          end
  37.      
  38.       end
  39.       if stat == false
  40.       then
  41.          matrix[#matrix+1]= number
  42.       end
  43.       if #matrix == 36
  44.       then
  45.          break
  46.       end
  47.    end
  48.    return matrix
  49. end
  50.  
  51. function add_to_base(array,base)
  52.    stat= false
  53.    for i=1,#base do
  54.       if base[i][1] == array[2]
  55.       then
  56.          return base
  57.       end
  58.    end
  59.    for i=1,#base do
  60.          if base[i][1] == array[1]
  61.          then
  62.             stat= true
  63.          end
  64.    end
  65.    if stat == false
  66.    then
  67.       base[#base+1]= {}
  68.       c= 1
  69.       for i=2,8 do
  70.          base[#base][c]= array[i]
  71.          c= c+1
  72.       end
  73.       return base
  74.    else
  75.       return base
  76.    end
  77. end
  78.  
  79. function winers(base,random_numbers)
  80.    winers= {}
  81.    for i=1,#base do
  82.       c= 1
  83.       count= 0
  84.       for q=2,7 do
  85.          if base[i][q] == random_numbers[c]
  86.          then
  87.             count= count+1
  88.          else
  89.             break
  90.          end
  91.          c= c+1
  92.       end
  93.       winers[#winers+1]= {}
  94.       winers[#winers][1]= base[i][1]
  95.       winers[#winers][2]= count
  96.    end
  97.    return winers
  98. end
  99.  
  100. function sorts(array)
  101.    for i=1,#array do
  102.    
  103.       for q=1,#array do
  104.          if array[q+1] == nil
  105.          then
  106.             break
  107.          end
  108.          if array[q]>array[q+1]
  109.          then
  110.             temp= 0
  111.             temp= array[q]
  112.             array[q]= array[q+1]
  113.             array[q+1]= temp
  114.          end
  115.       end
  116.    end
  117.       for i=1,#matrix do
  118.    
  119.       write(array[i].." ")
  120.    
  121.    end
  122. end
  123.  
  124. base= {}
  125. winer= {}
  126. warnings= {}
  127. time= 0
  128. max_time= 120
  129. while true do
  130.    term.clear()
  131.    term.setCursorPos(1,1)
  132.    print(time)
  133.    os.startTimer(1)
  134.    event,id,message,distance= os.pullEvent()
  135.    --print(event," ",id," ",message)
  136.    if event == "rednet_message"
  137.    then
  138.       data= {}
  139.       data= textutils.unserialize(message)
  140.       if data[1] == "start"
  141.       then
  142.          n= gen_num()
  143.          data= {}
  144.          data[1]= "numbers"
  145.          data= add_arrays(data,n)
  146.          message= textutils.serialize(data)
  147.          rednet.send(id,message)
  148.       end
  149.       if data[1] == "finish"
  150.       then
  151.          base= add_to_base(data,base,warnings)
  152.       end
  153.    end
  154.    if event == "timer"
  155.    then
  156.       time= time+1
  157.       if time == max_time
  158.       then
  159.          n= gen_num()
  160.          winer= winers(base,n)
  161.          for i=1,#winer do
  162.             for q=1,#winer[i] do
  163.                write(winer[i][q].." ")
  164.             end
  165.             print()
  166.          end
  167.          break
  168.       end
  169.    end
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement