Thursday, January 29, 2015

Changes 1/29/15 - Printing a heap, Firefox phone

                98
        77              83
    63      70      58      62
  18  7   17  30  28  54  10  22

So I got the formatting to work! Sam gave me a hint--his program based the spacing between each node (Such as the spaces between 77 and 83) on the total number of columns available on the terminal. In my code, the spacing between each node is calculated with the expression:
" " * (str_width // (2**level_index))
where str_width is a constant dependent on the columns in the terminal and level_index is the level of nodes currently being iterated over (so for 98 level_index would equal 0, for 77 and 83 it would equal 1, and so on).

The left offset, or the whitespace to the far left of all the nodes, is calculated by dividing the spacing between each node by two:
(" " * str_width // (2**level_index + 1))

This approach works very well, but I wouldn't have been able to figure it out on my own. I guess it makes sense, but I just have trouble wrapping my head around what I'm doing. The only reason I got this to work at all was because I played around with the math without really understanding what I was doing and happened to eventually hit the right answer.  It's really frustrating though because I'm just not good at thinking in this sort of way.

I also got Firefox Hello to work, since we are going to be videoconferencing with some people over at Mozilla at some point in the future.  I started looking at the oneanddone site, but ran out of time.  If we only have one Firefox phone between the three of us, I don't think we all really need to do these though.

1 comment:

  1. Well we now have two phones among the three of you, so that's a big improvement. Let's see what we can do about getting the 3rd.

    Like with most things you learn, the more experience you have the easier it will be for you to think "in this sort of way". There are frequently occurring patterns in the design of algorithms, and the more of these you put "in your toolbox", the better software carpenter you will be.

    ReplyDelete