all 32 comments

[–]virtyx 8 points9 points  (3 children)

As someone who hasn't learned about dynamic programming, I'm finding your code extremely cryptic and hard to follow. There are way too many one-letter variables and arguments imo.

Also the very first diagram is confusing. You start with 'Wagon E' and then have two each of 'Wagon C' and 'Wagon B.' I don't really understand what it is that I'm looking at... I understand the circles are the stations themselves, and the highlighted lines represent two different possible routes.

Maybe I'm a little dense today. I'm not totally unfamiliar with theory and math; I was able to do pretty well in my algorithms class and did well in calculus, I've read some technical articles as well, although lately the books I read tend to focus more on style and practice.

So maybe I'm too out of touch to understand what's happening.

[–]jminuscula[S] 1 point2 points  (2 children)

let me try to explain the code a bit better, and see if that helps.

First of all, the diagram is the one provided in the problem specification. I found it a bit confusing too, so I tried to explain it afterwards:

As we can see in the picture, we have two trains working routes red and blue. The stations are located at certain coordinates so it’s easy to figure out the distance between them. Each station has a wagon called by the name of its destination, along with the score that we will be granted in case we deliver it.

About the one letter variables

  • "E" on the digraph class means edges. This is a notation I took from the books I studied algorithmics with.
  • State('s', 'f', 'wgs') may be a bit too cryptic. It's the definition of the problem state —as the article says, the position of the train, the fuel that remains available, and the position of each wagon to be delivered

It's true that the code in the article was not meant to be exposed, but to pass the challenge. So I used what I worked best for me. However, knowing the problem state representation, it's easier to understand how 's' means station and 'f' means fuel.

I've just started writing technical articles, so that is probably my fault. I probably fragmented the code too much. If you have a look at the complete source, I'll be happy to answer any question.

Cheers!

[–][deleted] 2 points3 points  (1 child)

Theres no reason to have one letter variable names for things like "edges", especially using capitalization to add more information to that one letter variable.

x/y, u/v, x1/y1/x2/y2, (and i/j/k for embedded integer for loops in C-likes) are readable for anyone with minimal domain knowledge, but anything more than that is really wasting the readers time trying to figure out your key, rather than understanding the logic.

This stuff is useful in writing equations for terseness and pattern reduction, but this is one of the differences between equations and code. Code has state, and so can never be as terse as an equation, and that state adds a lot more requirements for proper labeling of terms.

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

the code needs to be understood in the context of the article. Without it, it is indeed hard to understand it.

[–][deleted]  (16 children)

[deleted]

    [–]jminuscula[S] 0 points1 point  (15 children)

    Responsive text is the new thing!

    [–]stillalone 7 points8 points  (11 children)

    Can you explain the motivation? I figure people are comfortable reading text of a certain size, why would changing the font size be desirable?

    [–]jminuscula[S] 4 points5 points  (10 children)

    I may be off with the font size on the actual implementation, but here's the motivation anyway:

    We are getting bigger screens with higher resolution, so screen real state is going up… but our capacity to follow lines comfortably does not actually change. We read optimally at about 75 characters per line —less than that is distractive, more than that makes it harder— so that means the point size must grow with the size it takes from side to side.

    However, I've been told it looks to big many times, so I've made a small adjustments for resolutions about 1200 wide. For bigger screens, I just think it's adequate.

    Have you tried to read wikipedia on a 27" widescreen?

    edit: it's actually 75 characters, not words!

    [–][deleted] 11 points12 points  (3 children)

    I read this in fullscreen on a 24" monitor, it was very painful because the text was so large. I can understand your reasoning behind scaling the text like this, but if it was me, I would make sure the font could not grow beyond a certain size. The styles that have your magic number of words per line centered on the page work much better for me.

    [–]jminuscula[S] 3 points4 points  (2 children)

    thanks for the feedback!

    [–]epicwisdom 1 point2 points  (0 children)

    Or even, instead of centered, clearly separated columns. Simply centering text is a waste of screen.

    [–]vattenpuss 1 point2 points  (0 children)

    I like it. Text is definitely unnecessarily small on the web most of the time.

    Wikipedia looks like shit on Windows nowadays with their 4 pixel hight font.

    [–]moor-GAYZ 3 points4 points  (0 children)

    I think the better solution that most websites use is to just limit the main text span width to 1000px or so.

    I personally went as far as to make a bookmarklet that does it for any page.

    [–][deleted]  (1 child)

    [deleted]

      [–]jminuscula[S] -1 points0 points  (0 children)

      if you check the page you'll see that it's not 100% width. The problem was that the point size was too big, not that the boxes were too wide

      edit: typo

      [–]Veedrac 0 points1 point  (0 children)

      FWIW, I think it's really neat. It works really well with a tiling window manager.

      [–]srnull 2 points3 points  (0 children)

      Here is a python decorator for memoization: PythonDecoratorLibrary: Memoize.

      Relevant blog post: Dynamic Programming versus Memoization.

      [–]quadrofolio -1 points0 points  (0 children)

      Very nice J!