Skip to main content

Posts

Venturing into Number Theory

In attempt to solve a maths problem with Ruby, I discovered the benefits of going beyond simple arithmetic. Perhaps surprisingly, many seemingly complex mathematical problems can be solved using basic arithmetic and raw computing power. Most of the time this doesn't pose a problem. However, as the values involved grow larger, the demands on the computer's memory reaches a critical point beyond which you risk crashing your computer.  The problem I was trying to solve was the following:    What is the smallest positive number that is evenly divisible  by all of the numbers from 1 to 20? After causing my computer to hang for several minutes, I realized I had to rewrite the program I was working on. The program had to take shortcuts, so that instead of testing every single value between 1 and 1 million, it only tested likely values. With the help of my lovely wife (a Maths teacher) I rewrote the program using prime numbers.   class SmallestProduct requ...

Einstein's Logic Puzzle (SPOILER ALERT!)

On Monday I began working through a Discrete Math textbook in preparation for some courses I'll be taking in January. There was a beautiful logic problem in Chapter 1, apparently created by Einstein. This is one version of it: Five men with  different nationalities and with different jobs live in  con secutive houses on a street. These houses are painted  dif ferent colors. The men have different pets and have   dif ferent favorite drinks.  Determine who owns a zebra and  whose favorite drink is mineral water (which is one of the  favorite drinks) given these clues:  The Englishman lives  in the red house.  The Spaniard owns a dog.  The Japanese  man is a painter.  The Italian drinks tea.  The Norwegian  lives in the first house on the left.  The green house is  immediately to the right of the white one. The photogra pher  breeds snails.  The diplomat lives in the yellow house. ...

Object Oriented Design- Wading into Deeper Waters

Objects, classes, inheritance, polymorphism- it sounds a little like Biology, and in some ways, object oriented programming (OOP) mirrors the natural world.  I've finally reached the OOP section in the Odin Project's Ruby Programming course. Many of the concepts are straightforward-especially to anyone who has read a little philosophy or studied evolutionary biology. The difficult part is translating the concepts into actual functioning OOP applications.  I've started reading what looks to be a promising book on OOP design in Ruby. I've learned something already that may improve my code. Here's an example from chapter 2:  class Gear    attr_reader :chainring, :cog,     def initialize(chainring, cog)      @chainring = chainring      @cog = cog    end    def ratio      (chainring / cog.to_f).round(2)    end end This is the 'good' way to create a class....

Programming vs Learning to Program

This is a multi-faceted topic, I want to look at one aspect in this post: effort vs. efficiency. After creating a Caesar cipher in Ruby  a few days ago, I looked at some other student's solutions. Some students were clearly experienced programmers- their code was 5 lines of densely packed recursive algorithms.  At first I was discouraged and thought "What can't I do that ?", and "Why doesn't my code look that ?".  Then I reconsidered. My solution to the Caesar Cipher represents my  single handed efforts at solving a problem. The solution was based on the 4 weeks of experience I have with Ruby.  Sure, there are built in methods that would have accomplished the task more elegantly (like the .modulo method).  Sure, I could refactor my code making it shorter and making it run faster. But, until I learn those methods and refactoring techniques, using them because someone else told me to would short circuit my learning. When I do search on StackExcha...

7th Week-Progress

I have entered the 7th week since my fatal decision to become a master coder. What progress can I report?    I finished The Odin Project's Web Development 101 course on Monday and began the third course in curriculum : "Ruby Programming". Although I completed the Codecademy Ruby course and did some other Ruby work a few weeks ago, I felt I needed a review.  To this end I am redoing the Codecademy course, I completed Chris Pine's book  Learn to Program,  and I reread Chs.2 + 3 of Peter Cooper's Beginning Ruby .  Needless to say, the revision was worth it- I have a much clearer understanding of blocks and procs, as well as hashes and arrays. Concurrent with the Odin Project I am working through the  Epicodus curriculum . It is always helpful to have multiple perspectives on a subject. I have also discovered an intriguing course called FreeCodeCamp . It isn't complete yet, but the aim is to train students to write code for non-profits. Much of t...

Git

I have being using Git for version control since I began my study 6 weeks ago. I am finally beginning to understand its more advanced functionality. As I am now working on two different computers, I needed to figure out how to coordinate repositories between them. This is what I did. Setup a remote repository on Github. On my computer, create a directory and initialize an empty repository.                   $ git init      3. Link the local repo to the remote repo.                   $ git remote add origin <repo address>      4.  Then, add new files from local computer, commit, push. (Note to self, don't forget!)

Programming vs Web Development

No doubt others have commented on this before, but it seems that web development and programming aren't the same thing. The last two days I built a few simple Rails applications. The second one is relatively impressive ( a blogger site with authentication, image uploading, tagging and commenting). While I learned a great deal about MVC, Rails and even some new features of Git, I learned little programming.  Most of the problems I encountered had to do with gem version incompatibilities. I had to update this, rollback that, edit the Gemfile, precompile for Heroku deployment, reset the database, reset Heroku, etc. Most of the problems were solved through brute force trial and error and googling. The final product was impressive, but Rails did most of the programming for me. Previous exercises involving Project Euler, writing sort algorithms or programs to solve mechanics problems in Physics, required deep thought and abstraction.  No doubt problem solving (in the sense ...