-
Notifications
You must be signed in to change notification settings - Fork 15
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
Panda level submission #12
Open
jperezish
wants to merge
11
commits into
RubyoffRails:master
Choose a base branch
from
jperezish: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
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5c3b2f4
update stubs to doubles
jperezish 6f8b133
add a starting point
jperezish fb29c0c
add benchmarking
jperezish a5db5fc
add initial version of miles traveled
jperezish ba1cebc
update salesperson and route to calculate total miles traveled
jperezish 3050a74
add ability to calculate travel time
jperezish 1d5dbc0
update salesperson
jperezish fd90517
rename calculates_route to route
jperezish b92f36c
update time_traveled from 60 to 55 mph
jperezish 4124db5
update sales_person class to inject the route collaborator in the con…
jperezish d5bcb35
update text in salesperson to say 55 instead of 60, update route #cal…
jperezish 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 |
---|---|---|
@@ -0,0 +1,220 @@ | ||
CITIES = ["Acton, CA", | ||
"Adelanto, CA", | ||
"Agoura Hills, CA", | ||
"Agua Dulce, CA", | ||
"Alameda, CA", | ||
"Alamo, CA", | ||
"Albany, CA", | ||
"Alhambra, CA", | ||
"Aliso Viejo, CA", | ||
"Alpine, CA", | ||
"Alta Loma, CA", | ||
"Altadena, CA", | ||
"Alturas, CA", | ||
"Amador City, CA", | ||
"Anaheim, CA", | ||
"Anaheim Hills, CA", | ||
"Anderson, CA", | ||
"Angels Camp, CA", | ||
"Angelus Oaks, CA", | ||
"Antelope, CA", | ||
"Antioch, CA", | ||
"Anza, CA", | ||
"Apple Valley, CA", | ||
"Applegate, CA", | ||
"Aptos, CA", | ||
"Arcadia, CA", | ||
"Arcata, CA", | ||
"Arleta, CA", | ||
"Armona, CA", | ||
"Arnold, CA", | ||
"Aroura Hills, CA", | ||
"Arroyo Grande, CA", | ||
"Atascadero, CA", | ||
"Atwater, CA", | ||
"Atwood, CA", | ||
"Auberry, CA", | ||
"Auburn, CA", | ||
"Avalon, CA", | ||
"Avery, CA", | ||
"Avila Beach, CA", | ||
"Azusa, CA", | ||
"Bakersfield, CA", | ||
"Baldwin Park, CA", | ||
"Bangor, CA", | ||
"Banning, CA", | ||
"Barstow, CA", | ||
"Bay Point, CA", | ||
"Bayside, CA", | ||
"Bel Air, CA", | ||
"Bell, CA", | ||
"Bellflower, CA", | ||
"Belmont, CA", | ||
"Belmont Shores, CA", | ||
"Belvedere, CA", | ||
"Ben Lomond, CA", | ||
"Benicia, CA", | ||
"Berkeley, CA", | ||
"Berry Creek, CA", | ||
"Beverly Hills, CA", | ||
"Big Bear City, CA", | ||
"Big Bear Lake, CA", | ||
"Big Sur, CA", | ||
"Bishop, CA", | ||
"Blue Jay, CA", | ||
"Blue Lake, CA", | ||
"Blythe, CA", | ||
"Bolinas, CA", | ||
"Bonita, CA", | ||
"Borrego Springs, CA", | ||
"Bothell, CA", | ||
"Boulder Creek, CA", | ||
"Brea, CA", | ||
"Breenbrae, CA", | ||
"Brentwood, CA", | ||
"Brisbane, CA", | ||
"Buellton, CA", | ||
"Buena Park, CA", | ||
"Burbank, CA", | ||
"Burlingame, CA", | ||
"Burlington, CA", | ||
"Calabasas, CA", | ||
"California City, CA", | ||
"Calimesa, CA", | ||
"Calistoga, CA", | ||
"Camarillo, CA", | ||
"Cambria, CA", | ||
"Cameron Park, CA", | ||
"Campbell, CA", | ||
"Campo, CA", | ||
"Canoga Park, CA", | ||
"Canyon Country, CA", | ||
"Canyon Lake, CA", | ||
"Capistrano Beach, CA", | ||
"Capitola, CA", | ||
"Cardiff, CA", | ||
"Cardiff-by-the-Sea, CA", | ||
"Carlsbad, CA", | ||
"Carmel, CA", | ||
"Carmel Valley, CA", | ||
"Carmichael, CA", | ||
"Carpinteria, CA", | ||
"Carson, CA", | ||
"Castaic, CA", | ||
"Castro Valley, CA", | ||
"Catalina Island, CA", | ||
"Cathedral City, CA", | ||
"Cayucos, CA", | ||
"Cedar Glen, CA", | ||
"Cedar Ridge, CA", | ||
"Ceres, CA", | ||
"Cerritos, CA", | ||
"Chatsworth, CA", | ||
"Cherry Valley, CA", | ||
"Chester, CA", | ||
"Chico, CA", | ||
"China Lake, CA", | ||
"Chino, CA", | ||
"Chino Hills, CA", | ||
"Chula Vista, CA", | ||
"Citrus Heights, CA", | ||
"City of Industry, CA", | ||
"Claremont, CA", | ||
"Clayton, CA", | ||
"Clearlake Oaks, CA", | ||
"Clearlake, CA", | ||
"Cloverdale, CA", | ||
"Clovis, CA", | ||
"Coarsegold, CA", | ||
"Colfax, CA", | ||
"Coloma, CA", | ||
"Colton, CA", | ||
"Columbia, CA", | ||
"Colusa, CA", | ||
"Commerce, CA", | ||
"Compton, CA", | ||
"Concord, CA", | ||
"Cordelia, CA", | ||
"Corning, CA", | ||
"Corona, CA", | ||
"Corona del Mar, CA", | ||
"Coronado, CA", | ||
"Corralitos, CA", | ||
"Corte Madera, CA", | ||
"Costa Mesa, CA", | ||
"Cotati, CA", | ||
"Coto de Caza, CA", | ||
"Covina, CA", | ||
"CresceCutten, CA", | ||
"Cypress, CA", | ||
"Daly City, CA", | ||
"Dana Point, CA", | ||
"Danville, CA", | ||
"Davis, CA", | ||
"Del Mar, CA", | ||
"Desert Hot Springs, CA", | ||
"Diamond Bar, CA", | ||
"Diamond Springs, CA", | ||
"Dobbins, CA", | ||
"Dominguez Hills, CA", | ||
"Dove Canyon, CA", | ||
"Downey, CA", | ||
"Duarte, CA", | ||
"Dublin, CA", | ||
"Hemet, CA", | ||
"Hercules, CA", | ||
"Hermosa Beach, CA", | ||
"Hesperia, CA", | ||
"Highland, CA", | ||
"Hinkley, CA", | ||
"Hollister, CA", | ||
"Hollywood, CA", | ||
"Homeland, CA", | ||
"Honcut, CA", | ||
"Humboldt, CA", | ||
"Huntington Beach, CA", | ||
"Huntington Park, CA", | ||
"Idyllwild, CA", | ||
"Imperial, CA", | ||
"Imperial Beach, CA", | ||
"Independence, CA", | ||
"Indian Wells, CA", | ||
"Indio, CA", | ||
"Inglewood, CA", | ||
"Inverness, CA", | ||
"Ione, CA", | ||
"Irvine, CA", | ||
"Irwindale, CA", | ||
"Isla Vista, CA", | ||
"Isleton, CA", | ||
"Jackson, CA", | ||
"Jacumba, CA", | ||
"Jamestown, CA", | ||
"Jamul, CA", | ||
"Jenner, CA", | ||
"Joshua Tree, CA", | ||
"Julian, CA", | ||
"Kelseyville, CA", | ||
"Kensington, CA", | ||
"Kentfield, CA", | ||
"Kenwood, CA", | ||
"King City, CA", | ||
"Klamath, CA", | ||
"Klamath River, CA", | ||
"La Canada, CA", | ||
"La Canada Flintridge, CA", | ||
"La Crescenta, CA", | ||
"La Habra, CA", | ||
"La Honda, CA", | ||
"Lake Elsinore, CA", | ||
"Lake Forest, CA", | ||
"Lake Isabella, CA", | ||
"Lakeport, CA", | ||
"Lakeside, CA", | ||
"Vineburg, CA", | ||
"Visalia, CA", | ||
"Vista, CA", | ||
"Walnut, CA", | ||
"Walnut Creek, CA", | ||
"Warm Springs, CA", | ||
"Watsoncca Valley, CA"] |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Dir["./lib/*.rb"].each {|file| require file } | ||
|
||
require 'benchmark' | ||
require_relative "benchmark_helper" | ||
|
||
phil = SalesPerson.new | ||
|
||
Benchmark.bm do |x| | ||
x.report("2 cities") do | ||
phil.schedule_city(Place.build("Chino Hills, CA"), starting_city: true) | ||
1.upto(2) do |city| | ||
phil.schedule_city(Place.build(CITIES[city])) | ||
end | ||
end | ||
|
||
x.report("10 cities") do | ||
phil.schedule_city(Place.build("Chino Hills, CA"), starting_city: true) | ||
1.upto(10) do |city| | ||
phil.schedule_city(Place.build(CITIES[city])) | ||
end | ||
end | ||
|
||
x.report("50 cities") do | ||
phil.schedule_city(Place.build("Chino Hills, CA"), starting_city: true) | ||
1.upto(50) do |city| | ||
phil.schedule_city(Place.build(CITIES[city])) | ||
end | ||
end | ||
|
||
x.report("200 cities") do | ||
phil.schedule_city(Place.build("Chino Hills, CA"), starting_city: true) | ||
1.upto(200) do |city| | ||
phil.schedule_city(Place.build(CITIES[city])) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class Route | ||
attr_reader :miles_traveled | ||
|
||
def initialize | ||
@miles_traveled = 0 | ||
end | ||
|
||
def calculate(points) | ||
remaining_points = points | ||
route = [] | ||
route << remaining_points.slice!(0) | ||
until remaining_points == [] do | ||
next_point = shortest_distance(route.last, remaining_points) | ||
route << remaining_points.slice!(remaining_points.index(next_point)) | ||
end | ||
route | ||
end | ||
|
||
def shortest_distance(from, possible) | ||
distances = possible.map do |point| | ||
{point: point, distance: Map.distance_between(from, point)} | ||
end | ||
get_the_shortest_distance_from(distances) | ||
end | ||
|
||
def get_the_shortest_distance_from(distances) | ||
shortest_distance = distances.sort{|a,b| a.fetch(:distance) <=> b.fetch(:distance)} | ||
add_to_miles_traveled(shortest_distance.first.fetch(:distance)) | ||
shortest_distance.first.fetch(:point) | ||
end | ||
|
||
def add_to_miles_traveled(miles) | ||
@miles_traveled += miles | ||
end | ||
|
||
def time_traveled | ||
@miles_traveled / 55 | ||
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,15 +1,28 @@ | ||
class SalesPerson | ||
|
||
attr_reader :cities | ||
attr_reader :cities, :starting_city | ||
def initialize | ||
@cities = [] | ||
@route = Route.new | ||
end | ||
|
||
def schedule_city(city) | ||
def schedule_city(city, options={}) | ||
if options[:starting_city] == true | ||
@starting_city ||= city | ||
@cities.unshift(@starting_city) | ||
end | ||
@cities << city unless @cities.include?(city) | ||
end | ||
|
||
def route | ||
CalculatesRoute.calculate(cities) | ||
@route.calculate(cities) | ||
end | ||
|
||
def miles_traveled | ||
@route.miles_traveled | ||
end | ||
|
||
def time_traveled | ||
@route.time_traveled | ||
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,10 +1,15 @@ | ||
Dir["./lib/*.rb"].each {|file| require file } | ||
|
||
|
||
phil = SalesPerson.new | ||
phil.schedule_city(Place.build("Dallas, TX")) | ||
phil.schedule_city(Place.build("El Paso, TX")) | ||
phil.schedule_city(Place.build("Austin, TX")) | ||
phil.schedule_city(Place.build("Lubbock, TX")) | ||
jason = SalesPerson.new | ||
jason.schedule_city(Place.build("Whittier, CA")) | ||
jason.schedule_city(Place.build("Chino Hills, CA"), starting_city: true) | ||
jason.schedule_city(Place.build("Brea, CA")) | ||
jason.schedule_city(Place.build("Irvine, CA")) | ||
|
||
puts phil.route | ||
puts "-----------------------------" | ||
puts "Here's my route:" | ||
puts jason.route | ||
puts "-----------------------------" | ||
puts "This route will cover #{jason.miles_traveled.round(1)} miles, as the crow flies." | ||
puts "If that crow flew 60 mph it'd take #{jason.time_traveled.round(2)} hours." | ||
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. I do believe you calculate at 55 mph though :) |
Oops, something went wrong.
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.
Totally a prefence, but I like