-
Couldn't load subscription status.
- Fork 21
Completed #19
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
base: master
Are you sure you want to change the base?
Completed #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| source 'https://rubygems.org' | ||
|
|
||
| gem 'rubocop', require: false | ||
| gem 'rspec' | ||
| gem 'rspec' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # This class represents the town of GemCity | ||
| # This is a town riddled with crime but we can find out how happy the town is | ||
| class GemCity | ||
| attr_reader :population | ||
|
|
||
| def initialize | ||
| @people = { thieves: 5, officers: 1 } | ||
| @population = 50 | ||
| end | ||
|
|
||
| def thieves(thieves_number = @people[:thieves]) | ||
| @people[:thieves] = thieves_number | ||
| end | ||
|
|
||
| def officers | ||
| @people[:officers] | ||
| end | ||
|
|
||
| def officers=(officers) | ||
| @people[:officers] = officers | ||
| end | ||
|
|
||
| def happiness_of_town | ||
| # happiness is random... people don't know what they want! | ||
| happiness_vals = [] | ||
| happiness = 0 | ||
| (1..@population).each do | ||
| happiness_vals.push(rand((100 - successful_crime_rate)..100)) | ||
| end | ||
| happiness_vals.each do |value| | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to use something called a |
||
| happiness += value | ||
| end | ||
| happiness / 100 | ||
| end | ||
|
|
||
| def successful_crime_rate | ||
| thieves = @people[:thieves] | ||
| officers = @people[:officers] | ||
| if thieves <= 0 | ||
| 0 | ||
| elsif officers > thieves | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about combining two assertions in the same line here using the |
||
| 0 | ||
| else | ||
| odds = 1 / (-officers.to_f / thieves.to_f) | ||
| odds * 100 | ||
| end | ||
| end | ||
| end | ||
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.
Maybe move out the logic in this loop to another function, cause it's a little hairy in here with the rands and the constant values