forked from AdaGold/stacks-queues
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
final commit. #19
Open
jlikesplants
wants to merge
1
commit into
Ada-C5:master
Choose a base branch
from
jlikesplants:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
final commit. #19
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
class Queue | ||
# First In First Out | ||
attr_accessor :store | ||
def initialize | ||
@store = Array.new | ||
end | ||
|
||
def dequeue | ||
grab = @store[0] | ||
@store = @store.drop(1) | ||
grab | ||
end | ||
|
||
def enqueue(element) | ||
@store << element | ||
end | ||
|
||
def size | ||
@store.length | ||
end | ||
|
||
def empty? | ||
size == 0 | ||
end | ||
|
||
def to_s | ||
@store.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
class Stack | ||
# Last In First Out | ||
attr_reader :store | ||
def initialize | ||
@store = Array.new | ||
end | ||
|
||
def pop | ||
end | ||
|
||
|
||
def push(element) | ||
@store << element | ||
end | ||
|
||
def pop | ||
@store.pop | ||
end | ||
|
||
def size | ||
@store.length | ||
end | ||
|
||
def empty? | ||
size == 0 | ||
end | ||
|
||
def to_s | ||
@store.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,57 @@ | ||
require './Stack.rb' | ||
require './Queue.rb' | ||
|
||
# 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. | ||
|
||
module Employment | ||
class Employees | ||
def self.get_employees(n) | ||
employees = Stack.new | ||
empl_id = 1 | ||
n.times do |employee| | ||
employees.push("empl" + "#{empl_id}") | ||
empl_id += 1 | ||
end | ||
employees | ||
end | ||
end | ||
|
||
class Sad_Job_Cycle | ||
def initialize(employees, job_count) | ||
@hired = Stack.new | ||
@waitlist = Queue.new | ||
print "\nemployees: #{employees}\n" | ||
employees.size.times do | ||
employee = employees.pop | ||
print "\nemployee: #{employee}" | ||
@waitlist.enqueue(employee) | ||
end | ||
hire(job_count) | ||
end | ||
|
||
def fire(number) | ||
number.times do | ||
fired_person = @hired.pop | ||
@waitlist.enqueue(fired_person) | ||
end | ||
end | ||
|
||
def hire(number) | ||
number.times do | ||
hired_person = @waitlist.dequeue | ||
@hired.push(hired_person) | ||
end | ||
end | ||
|
||
def roll_die | ||
([email protected]).to_a.sample | ||
end | ||
|
||
def rotate | ||
number = roll_die | ||
fire(number) | ||
hire(number) | ||
print number | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use
employee
in place ofempl_id
here and then remove that counter.