I've created a program that will take, a bunch of numbers from a
range of 1 - 255, and then put them into 3 different strings(servers) equally. It does this by having a count that starts at 1 and loops to 3, once the count has hit 3 it restarts until three servers have hit a max capacity of 100 numbers within it.
Once that max capacity has been hit, the numbers dump the remaining into a server called
I'm looking for better ways to write this, that are cleaner, and will make this, if possible, more readable.
#!/local/usr/bin/ruby users = (1..255) #<= Amount of users calculon = " " #<= Random servers to be append into darth = " " invader_zim = " " failsafe = " " #<= Failsafe count = 1 users.each do |i| target_string = case count when 1 then calculon #<= Append into server when 2 then darth #<= Append into server when 3 then invader_zim #<= Append into server end target_string = failsafe if target_string.length == 100 target_string << i #<= When amount is reached hits fail safe if count == 3 count = 1 else count += 1 end end puts calculon.length == 1 ? 'No users on server' : calculon.length puts darth.length == 1 ? 'No users on server' : darth.length puts invader_zim.length == 1 ? 'No users on server' : invader_zim.length puts failsafe.length == 1 ? 'No users on server' : failsafe.length
Example of usage:
86 86 86 No users on server
The main objective of this program is to have a script that will equally load three different servers, and if all servers have hit a max capacity, will load into a fail safe server.