From 0cca848031edf23406749e4f5f3a04191da1602e Mon Sep 17 00:00:00 2001 From: Elle Vargas Date: Thu, 25 Aug 2016 10:35:06 -0700 Subject: [PATCH 1/6] completed stack class implementation --- Stack.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Stack.rb b/Stack.rb index 25da8b60..251e5be3 100644 --- a/Stack.rb +++ b/Stack.rb @@ -2,19 +2,27 @@ class Stack def initialize @store = Array.new end - + def push(element) + @store << (element) + # @store.push(element) end - + def pop + return @store.pop end def top + return @store.last end - + def size + return @store.length end def empty? + return size == 0 + # return @store.empty + # size here calls the size method end end From 275e0f8c49b28fa3317b5d72b1f40220ccf83ee8 Mon Sep 17 00:00:00 2001 From: Elle Vargas Date: Thu, 25 Aug 2016 10:43:27 -0700 Subject: [PATCH 2/6] both Queue and Stack are complete --- Queue.rb | 14 ++++++++++---- Stack.rb | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Queue.rb b/Queue.rb index 57ef609b..58c66817 100644 --- a/Queue.rb +++ b/Queue.rb @@ -1,19 +1,25 @@ -class Queue +class Queue #FIFO def initialize + @store = Array.new end - + def enqueue(element) + @store << (element) end - + def dequeue + return @store.shift end def front + return @store.first end - + def size + return @store.length end def empty? + return size == 0 end end diff --git a/Stack.rb b/Stack.rb index 251e5be3..ee8c2118 100644 --- a/Stack.rb +++ b/Stack.rb @@ -1,4 +1,4 @@ -class Stack +class Stack #LIFO def initialize @store = Array.new end From 8907f1bbfebcc39cd924ecb7329b3e4fc71d4a8f Mon Sep 17 00:00:00 2001 From: Elle Vargas Date: Mon, 29 Aug 2016 21:59:48 -0700 Subject: [PATCH 3/6] I am going to bed. This is what I've got. --- job-simulation.rb | 63 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/job-simulation.rb b/job-simulation.rb index 2c9c46d5..a89c6c27 100644 --- a/job-simulation.rb +++ b/job-simulation.rb @@ -1,15 +1,48 @@ -# A company has six hiring positions with more people wanting jobs than the -# number of available positions. The company managers decide in order to give -# more people an opportunity to make money; they will allow people to work in -# three-month intervals. The first five people on the waiting list will be hired -# in the order that they are on the waiting list. The first six people will -# keep these positions for three months. At the end of three months, the -# manager will roll a dice to determine the number of people who will lose their -# jobs. The company will use the policy of last-hired-first-fired. For example, -# if the dice roll is 3, the last 3 people hired will lose their jobs to the -# first 3 people on the waiting list. People losing their jobs will be placed on -# the back of the waiting list in the order that they are fired. This process -# will continue for every three-month interval. - -require './Stack.rb' -require './Queue.rb' +require_relative './Stack.rb' +require_relative './Queue.rb' +require 'awesome_print' + +class ProbablyComcast + + attr_reader :working, :waitlisted + + def initialize(ppl_working = 6, ppl_waitlisted = 12) + @working = Stack.new + @waitlisted = Queue.new + + ppl_working.size do |index| + @working << (index + 1) + end + + ppl_waitlisted.size do |index| + @waitlisted.enqueue(index + 1) + end + + end + + def next_quarter + die = Random.rand(1..6) + + die.times do + + fired = @working.pop + ap "Workers fired: #{fired}" + @waitlisted.enqueue(fired) + + hired = @waitlisted.dequeue + ap "Waitlisted hired: #{hired}" + @working.push(hired) + end + + # hired = @waitlisted.enqueue(@working.top(die)) + #fired = @working << (@waitlisted.dequeue(die)) + # ^ didn't work + + end + +end + +recession = ProbablyComcast.new(6,12) +recession.next_quarter + +# I don't know why this isn't working. From be9aeea8d9a7f2923af2c6777582a15f43e41cfa Mon Sep 17 00:00:00 2001 From: Elle Vargas Date: Wed, 31 Aug 2016 17:31:32 -0700 Subject: [PATCH 4/6] worked with Susan to figure out job-simulation --- job-simulation.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/job-simulation.rb b/job-simulation.rb index a89c6c27..76cd36de 100644 --- a/job-simulation.rb +++ b/job-simulation.rb @@ -10,39 +10,41 @@ def initialize(ppl_working = 6, ppl_waitlisted = 12) @working = Stack.new @waitlisted = Queue.new - ppl_working.size do |index| - @working << (index + 1) + ppl_working.times do |index| + @working.push(index + 1) end - - ppl_waitlisted.size do |index| - @waitlisted.enqueue(index + 1) + # + ppl_waitlisted.times do |index| + @waitlisted.enqueue(index + 7) end end def next_quarter die = Random.rand(1..6) - die.times do fired = @working.pop ap "Workers fired: #{fired}" @waitlisted.enqueue(fired) + end + + die.times do hired = @waitlisted.dequeue ap "Waitlisted hired: #{hired}" @working.push(hired) end - - # hired = @waitlisted.enqueue(@working.top(die)) - #fired = @working << (@waitlisted.dequeue(die)) - # ^ didn't work - end end recession = ProbablyComcast.new(6,12) recession.next_quarter - -# I don't know why this isn't working. +# puts recession.working.inspect +# puts recession.waitlisted.inspect +# +# puts recession.next_quarter +# +# puts recession.working.inspect +# puts recession.waitlisted.inspect From f134a7197a583e251c66cb8a7425784122ed9665 Mon Sep 17 00:00:00 2001 From: Elle Vargas Date: Sat, 24 Sep 2016 21:37:48 -0700 Subject: [PATCH 5/6] Update job-simulation.rb --- job-simulation.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/job-simulation.rb b/job-simulation.rb index 76cd36de..4e8ee016 100644 --- a/job-simulation.rb +++ b/job-simulation.rb @@ -1,3 +1,17 @@ +# A company has six hiring positions with more people wanting jobs than the +# number of available positions. The company managers decide in order to give +# more people an opportunity to make money; they will allow people to work in +# three-month intervals. The first five people on the waiting list will be hired +# in the order that they are on the waiting list. The first six people will +# keep these positions for three months. At the end of three months, the +# manager will roll a dice to determine the number of people who will lose their +# jobs. The company will use the policy of last-hired-first-fired. For example, +# if the dice roll is 3, the last 3 people hired will lose their jobs to the +# first 3 people on the waiting list. People losing their jobs will be placed on +# the back of the waiting list in the order that they are fired. This process +# will continue for every three-month interval. + + require_relative './Stack.rb' require_relative './Queue.rb' require 'awesome_print' From af7dedc66f3b78908525c04b51b69f64a89ff277 Mon Sep 17 00:00:00 2001 From: Elle Vargas Date: Sat, 24 Sep 2016 21:38:13 -0700 Subject: [PATCH 6/6] Update job-simulation.rb --- job-simulation.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/job-simulation.rb b/job-simulation.rb index 4e8ee016..2e071791 100644 --- a/job-simulation.rb +++ b/job-simulation.rb @@ -55,6 +55,7 @@ def next_quarter recession = ProbablyComcast.new(6,12) recession.next_quarter + # puts recession.working.inspect # puts recession.waitlisted.inspect #