Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
MATH HACKS IN RUBY
Class 6a – Ruby Math
Introduction
 Ruby Basics
 Puts
 Gets
 Some basic math operations
 “+”, “-”, “*”, “/”
 Formatting and Advanced Math
...
Agenda
 Review the Assignment 3 solution
 Add formatting
 to make interface and output more attractive
 To make interf...
Formatting
 Example – our class average assignment
 Preferred format/ line length of 60
Student Marks
Sam 75
Susan 78
Ge...
Demonstration
 IPO
 Input
 Processing
 Output
 Code
Ruby Math: Exponent and Root
 Exponent
 Notation a**b
 a to the power of b
 Example
 Root
 Using Math Object
 Math....
Ruby Math: Absolute & Modulus
 Absolute
 Notation a=x-y.abs
 Example
 Modulus (gizinta, what’s left?)
 Notation a=x%y...
Ruby Math: Random & Pi
 Random
 Use: rand(max_val)
 Result is zero based
 Example
 Math:Pi
 Use Math::Pi*(val)
 Exa...
Summary
 Exponent (a**b)
 Root (sqrt or a**b/c.to_f)
 Absolute (abs)
 Modulus (a%b)
 Random (rand(x))
 Pi (Math::PI)
Project 1: Calculator/Converter
 Objectives
 Apply mathematical formulas to real problems
 Apply a programmatic approac...
Upcoming SlideShare
Loading in …5
×

Class 6a ruby math

2,038 views

Published on

In this second half of Class 6, we will investigate a few of Ruby's capabiities to complete advanced formatting and mathematical calculation.

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Class 6a ruby math

  1. 1. MATH HACKS IN RUBY Class 6a – Ruby Math
  2. 2. Introduction  Ruby Basics  Puts  Gets  Some basic math operations  “+”, “-”, “*”, “/”  Formatting and Advanced Math  Line formatting (right/left justification, centering)  Exponents, roots, the Math Object
  3. 3. Agenda  Review the Assignment 3 solution  Add formatting  to make interface and output more attractive  To make interface more intuitive  To make output more functional  Advanced Math  Exponents and Roots  Absolute and Modulus  Math::pi and rand
  4. 4. Formatting  Example – our class average assignment  Preferred format/ line length of 60 Student Marks Sam 75 Susan 78 George 87 Anne 92 Joe 67 _____ _____ Average 76.5
  5. 5. Demonstration  IPO  Input  Processing  Output  Code
  6. 6. Ruby Math: Exponent and Root  Exponent  Notation a**b  a to the power of b  Example  Root  Using Math Object  Math.sqrt(val)  Using math formula  x**0.5
  7. 7. Ruby Math: Absolute & Modulus  Absolute  Notation a=x-y.abs  Example  Modulus (gizinta, what’s left?)  Notation a=x%y  Example: Kids Inc. Summer Camp
  8. 8. Ruby Math: Random & Pi  Random  Use: rand(max_val)  Result is zero based  Example  Math:Pi  Use Math::Pi*(val)  Example:Volume of a cylinder  IPO first?
  9. 9. Summary  Exponent (a**b)  Root (sqrt or a**b/c.to_f)  Absolute (abs)  Modulus (a%b)  Random (rand(x))  Pi (Math::PI)
  10. 10. Project 1: Calculator/Converter  Objectives  Apply mathematical formulas to real problems  Apply a programmatic approach to a solution  Apply basic ruby mathematical operations  Apply basic ruby formatting  Grading – in 3 parts  Due Date:Week of Nov 15  NextWeek: Part of class for project work, problems, challenges, ideas

×