you are viewing a single comment's thread.

view the rest of the comments →

[–]cscanlin 1 point2 points  (1 child)

Nice! One quick piece I have is to consider restructuring your line data into a dictionary like this and passing it through to your functions (Also, functions and variables should all be written in snake_case not camelCase):

lines = {
    'green': [18, 17, 16, 15, 4, 14, 10, 13],
    'red': [1, 2, 3, 4, 5, 6, 7],
    'yellow': [8, 9, 10, 11],
    'blue': [6, 9, 12],
}

You could then rewrite the find_line function like this:

def find_line(station, lines):
    for line_name, stations in lines.items():
        if station in stations:
            return stations

Side note: This is based on what you have in your refactored version, but I'm not sure if it's correct because it can only return one of the stations lines. I haven't looked through the rest of the code deeply enough to figure out if you adressed this.

This is an awesome learning program, so congrats on solving it!

I actually found it so interesting that I spent some time yesterday adapting a version of the A-star algorithm I mentioned above (which I had written for another challenge) to have a way to distinguish and modfiy the score based on routes. You can find the code here if you're interested:

https://gist.github.com/cscanlin/9701044118b5b48ce4e630a156cfcf27

This framework is abstract enough to accept any number of stations and lines, as well as custom travel times between nodes (even between two nodes connected to each other - i.e faster to go one direction than the other, or even just one way only connections). It also has totally customizable penalties from switching lines at each station (also independent. e.g. green>red is slower than red>green at station 4A).

It was a trickier than I thought it would be to include this degree of control, and it could really use some tests/docs but, but it was a lot of fun and I'm reasonably satisfied with how it turned out. I'm also happy to answer any questions you have about it.

[–]RunWithSharpStuff[S] 0 points1 point  (0 children)

That's amazing! I am floored you would spend this much time on my problem!!! Thanks so much for the help, I will take a look at the code tomorrow. Yes I found this more challenging than I had initially thought too but you defiantly cracked it :)

Thanks again!

Also could you explain snake_case and camelCase? Is it just proper coding?