Skip to content

Completed Homework for Stacks and Queues #2

Open
jadevance wants to merge 2 commits intoAda-C5:masterfrom
jadevance:master
Open

Completed Homework for Stacks and Queues #2
jadevance wants to merge 2 commits intoAda-C5:masterfrom
jadevance:master

Conversation

@jadevance
Copy link
Copy Markdown

No description provided.

workers.push(waiting_workers.dequeue)
end

evil_boss_roulette = 1 + rand(6)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! You're not even nice and let them get away with rolling a 0 and all being saved (You did it the way I intended, but not everyone will notice this nuance, I suspect.

@sudocrystal
Copy link
Copy Markdown

Looks good -- Only comment I would make is that it would have been nice to have this code in methods so that we could cycle however we want and have the process repeat however we want.

@jadevance
Copy link
Copy Markdown
Author

After I wrote that solution I did think about how to move it into methods, but ran out of time to actually re-write it. Here's a quick pass:

require_relative './Stack.rb'
require_relative './Queue.rb'

require_relative './Stack.rb'
require_relative './Queue.rb'

class EvilCorp

    def initialize 
        @waiting_workers = Queue.new
        @workers = Stack.new
    end 


    def queue_workers(number)
        number.times do |worker|
            @waiting_workers.enqueue(worker + 1)
        end
    end

    def get_workers
        6.times do 
            @workers.push(@waiting_workers.dequeue)
        end 
    end

    def fire_workers
        evil_boss_roulette = 1 + rand(6)

        evil_boss_roulette.times do 
            @waiting_workers.enqueue(@workers.pop)
        end 

        evil_boss_roulette.times do 
            @workers.push(@waiting_workers.dequeue)
        end
    end
end

### TESTING CODE ### 
# employees = EvilCorp.new
# employees.queue_workers(50)
# p employees
# employees.get_workers
# p employees
# employees.fire_workers
# p employees


@sudocrystal
Copy link
Copy Markdown

sudocrystal commented Apr 13, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants