umd-coding-workshop / website

Hacking the Shell
https://github.com/umd-coding-workshop/website/wiki
29 stars 6 forks source link

Help with Math: Tip #12

Open jennielevineknies opened 11 years ago

jennielevineknies commented 11 years ago

If you're like me, and took your last math class 25 years ago, you may be stumped not so much by the programming in the Python tutorials, but the math itself. I did give some of the equations a true try, but ultimately, I care more about learning the coding than the math equations. If you want to get through the math quickly, try Wolfram Alpha: http://www.wolframalpha.com/ Just type the equations into the input and most of the time, Wolfram will figure it out.

For example, I stared at: -(-(-1)) for a long time before deciding it was "1". But I was wrong. It is, in fact, "-1" And Wolfram is smarter than I am.

spurioso commented 11 years ago

I was ready to throw my computer out the window over the -4**2.

ghost commented 11 years ago

I like the meme promoted by Keith Devlin that Mathematics is the Science of Patterns. Coding is all about the patterns of the language and its syntax, the patterns of the computation, and the patterns of the data being processed so therefore coding is all about mathematics. You won't use all of the arithmetic operators but you may use some of them to support certain patterns of computation. Here is an example pseudo code for generating an html table with rows alternating between three different background colors:

row_track = 0
foreach row in the table:
   if row_track == 0:
      row_color = Blue
   elif row_track == 1:
      row_color = Red
   else row_track == 2:
      row_color = Green

   print row with background color row_color

   row_track = (row_track + 1) % 3

so the arithmetic operator is modulo, but the pattern is an ordered loop through a discrete number of states. What if the loop size was configurable? then you could do:

row_track = (row_track + 1) % loop_size
ghost commented 11 years ago

It may be too late to register, but here is a new coursera course: Introduction to Mathematical Thinking, https://www.coursera.org/course/maththink, from Keith Devlin