Learning to Code: Week 13 – Specialize

August 4, 2016 (Continued)

  • I met with David Felfoldi yesterday.
  • http://stackoverflow.com/questions/6083045/scanf-n-skips-the-2nd-input-but-n-does-not-why
  • Finally watched some of the postmortem videos for the CS50 challenge.
  • Punctuation
    • He used a while loop and a counter.
    • Looked for NULL terminator instead of using strlen
    • Then if it was a . or , he just made the next character an uppercase one. Of course if the next one wasn’t a letter then nothing would happen still.
    • He put single like IF statements all on one line. Never seen that before.
  • Money Money Money
    • He used the pow() function.
    • He didn’t use rounding, just printing to 2 decimal places which also acts as a round.
  • One Day More
    • He did all the boolean expressions in one line, which makes sense. I didn’t think about the logic hard enough.
  • Airport Arbitrage
    • This was way over my head in figuring out how to code it up. I am familiar with the algorithm and logic though thanks to reading Grokking Algorithms.
    • At least it’s cool to know I should be able to solve the problem after I finish CS50.
    • This required a graph to determine the exchange rate consistency.
    • Depth First Search

image01

  • Name Your Cat
    • She thought at this problem completely differently than I did.
    • She looked through the entire string and found the letters that needed to be flipped.
    • I started from the front of the string and found a letter to swap, then started from the back and looked for a letter to swap with.
    • Once the two positions were the same or crossed we’re done.
    • She put the locations of the special characters into another array and then after she swapped the character positions in the array.
  • X
    • He also thought about the problem completely different than I did. I drew the outside of the box first.
    • Then I had a loop that put the X in by decrementing and incrementing at the same time until the X’s finished crossing over each other.
    • He did the top half and bottom half separately.
    • And he also dealt with “side spaces”
    • I believe it would’ve been easier in just one loop if you just check for the top or bottom row, if at the edges, and if not then what row you’re on exactly and that should do it completely which seems much less complex to me.
  • Word Reverse
    • I should’ve taken better advantage of the fact that all that was required was printing a string backwards, not storing it. Meaning I wouldn’t need a temp array, just need to make a function to print backwards from the end point to a starting point.
    • Then I could clear those variables and go again.

August 5, 2016

August 6, 2016

Nothing done today. Out having fun. 🎈

August 7, 2016

  • Maze Runner
    • This problem required Breadth First Search
    • Once again I understand the problem from Grokking Algorithms but the coding is far above my head since I haven’t reached it in CS50.

image00

  • Wait For It
    • This problem is the only one I had no idea where to start with for the logic or recognized the algorithm that would be required.
    • So basically you know the last bus should arrive when the last passenger arrives.
    • Also a bus should arrive at the same time a passenger arrives, so that narrows down the problem even more.
    • Then you can iterate through ALL the possible times to find the optimal times and use that.
    • Since the scope of this problem is small enough it would make sense to just brute force it. I assumed there would be some other complicated algorithm involved here.
  • Trading Up
    • Dynamic programming problem. Blowing my mind.
    • For real though, it’s like he’s speaking Greek with this one.
    • I can’t wait until I can solve a problem like this one.

August 8, 2016

  • Problem: Cookie Party
    • You’re having a cookie party tonight! You’re expecting n guests and you’ve already made m cookies.
    • You want to distribute all the cookies evenly between your guests in such a way that each guest receives the same number of whole cookies. If there are not enough cookies to give everyone the same amount, you must make some number of additional cookies.
    • Given n and m, find and print the minimum number of additional cookies you must make so that everybody receives the same number of cookies.
  • For this problem I first made a while loop and used modulo and just added +1 to m if n < m but that makes the program run incredibly slow for larger numbers.
  • So I looked up a formula to find the next highest multiple and it’s next = ((m/n)+1)*n
  • So if m < n just add n-m cookies. If m > n then find the next highest multiple and subtract m from that to see how many more cookies you need to make. That puts the program in O(1) runtime instead of the long runtime I had before that would timeout.
  • http://boss.blogs.nytimes.com/2014/04/16/software-that-helps-small-businesses-ship-like-amazon/?_r=1
    • He said his biggest challenge now is hiring enough developers to keep up with his company’s growth. “We’re in San Francisco, where everyone wants to build more software,” he said, “so continuing to find good people that are excited about this industry is a challenge. If I had an extra four engineers, I could build a lot more stuff.”
  • https://jaxenter.com/write-less-code-126966.html
    • The best code is no code at all and the fastest code is the code that never gets executed. Our goal should be to keep our solutions as simple as possible and stay away from our natural tendencies to over-engineer, use clever tricks and design patterns until it can be proven that they are absolutely necessary to solve the problem. Complexity is our worst enemy.
    • https://blog.codinghorror.com/the-best-code-is-no-code-at-all/
  • https://www.reddit.com/r/learnprogramming/comments/4wnhj8/best_way_to_learn_programming/
  • Learn to Program With Python (Youtube Playlist)
  • How to get Started in Software Development (blog)
    • The process of software development always begins by first understanding the problem to be solved.
    • This might be as simple as talking with a potential customer and discussing what needs to be built and how it should function, or it could be as formal as creating a fully documented specification.
    • Be specific and work backwards on your goals to create a plan.

August 09, 2016

    • Planning to attend this event on Wednesday
    • Started working on the HackerRank problem: Making Polygons
      • It’s classified as EASY but it doesn’t necessarily seem that way.
      • I worked through the logic on paper.
      • I feel a linked list would work much better than an array in this case, except I don’t really know how to manipulate or create a good working one in C…yet.
      • From writing it out I assume that the longest edge needs to be greater than the sum of the rest of the edges to allow for a valid polygon to be made.
      • If that isn’t the case we can split the largest into two and test again and continue that until we pass the test.
      • Problem being that an array of stick sizes can’t easily be appended because in the example the array would go from 3, 2, 1 to 1, 2, 2, 1. Meaning I would have to either just initialize the array to something stupidly large, or make a linked list.
      • On my way to the gym in the car I couldn’t stop thinking about the problem.
  • Thinking about it more I realized that the only number of cuts ever needed to form a polygon from N sticks in 2, 1 or 0.
  • I don’t need an array, or a list, or anything like that!
    • Knowing that made the problem very simple and took me 5 minutes to code it up and pass all preliminary checks.

August 10, 2016

  • I went to the meetup I mentioned yesterday and it went well.
    • Despite only two people showing up, I learned a lot and the organizer Laura Moore has been a developer for 16 years (Java).
    • She actually took the path to development that I want to take. She started at a bootcamp.
    • She is a big proponent of Extreme Programming and Agile development: https://en.wikipedia.org/wiki/Extreme_programming
    • She also emphasized contributing to open source projects on github (although I don’t know how to do this yet).
    • She was a little surprised that I am learning C and not something else.
    • I will do my best to stay in touch with her.
  • HackerRank Polygons problem preliminary checks passed, but I missed two on the final pass. Problem being I didn’t quite catch all the edge cases. If you have two sticks of the same size you will need 2 cuts, not 1.
  • Not sure if I should start reading the Clean Code book. Would it even help me at this time or is that something to read once I have more experience?