SlideShare a Scribd company logo
MATH HACKS IN RUBY
Class 6a – Ruby Math
Introduction
 Ruby Basics
 Puts
 Gets
 Some basic math operations
 “+”, “-”, “*”, “/”
 Formatting and Advanced Math
 Line formatting (right/left justification, centering)
 Exponents, roots, the Math Object
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
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
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.sqrt(val)
 Using math formula
 x**0.5
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
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?
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 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

More Related Content

PDF
Black and White Beamer
ODP
Module 3 Review
PPTX
Linear Regression, Machine learning term
PPT
Class 1 introduction to logic & problem solving
PPT
Class 7 lecture notes
PPTX
PPT
Ruby Hell Yeah
PDF
Ruby training day1
Black and White Beamer
Module 3 Review
Linear Regression, Machine learning term
Class 1 introduction to logic & problem solving
Class 7 lecture notes
Ruby Hell Yeah
Ruby training day1

Similar to Class 6a ruby math (20)

XLS
LoteríA Correcta
PPTX
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
PDF
Jerry Shea Resume And Addendum 5 2 09
PDF
MMBJ Shanzhai Culture
PDF
Agapornis Mansos - www.criadourosudica.blogspot.com
PPTX
Paulo Freire Pedagpogia 1
PDF
Washington Practitioners Significant Changes To Rpc 1.5
PDF
americansyscorp b/o ascitconsultancyservices
PDF
Ruby on Rails for beginners
PDF
Variables, expressions, standard types
PPTX
Ruby from zero to hero
PPTX
Ruby data types and objects
PPTX
Intro to Ruby/Rails at TechLady Hackathon
PDF
Ruby_Basic
PPTX
7 Methods and Functional Programming
PPTX
Ruby Basics
PDF
06 ruby variables
PDF
Arulalan Ruby An Intro
KEY
An introduction to Ruby
LoteríA Correcta
Majlis Persaraan Pn.Hjh.Normah bersama guru-guru Sesi Petang
Jerry Shea Resume And Addendum 5 2 09
MMBJ Shanzhai Culture
Agapornis Mansos - www.criadourosudica.blogspot.com
Paulo Freire Pedagpogia 1
Washington Practitioners Significant Changes To Rpc 1.5
americansyscorp b/o ascitconsultancyservices
Ruby on Rails for beginners
Variables, expressions, standard types
Ruby from zero to hero
Ruby data types and objects
Intro to Ruby/Rails at TechLady Hackathon
Ruby_Basic
7 Methods and Functional Programming
Ruby Basics
06 ruby variables
Arulalan Ruby An Intro
An introduction to Ruby
Ad

More from Stephen Parsons (17)

PPTX
Atlantic Woodworkers Website Strategy
PPTX
Chairs Report to LSCRS 2012 AGM
PPT
Class 10 Arrays
PPT
Program Renewal for NSCC Schools 2010-11
PPTX
Class 6 truth tables and boolean math
PPTX
Class 5 - Set Theory and Venn Diagrams
PPTX
Class 4 IPO and Intro to Ruby
PPTX
Class 3 Binary & Hexadecimal
PPTX
Class 2 Math I
PPTX
Portfolio Of A Community
PPT
Cause & effect analysis part 2
PPT
Cause & effect analysis part 1
PPT
Class 11 lecture notes
PPT
Class 10 Lecture Notes
PPT
Class 9 Lecture Notes
PPT
Class 8 Lecture Notes
PPT
Deck Project Phase II
Atlantic Woodworkers Website Strategy
Chairs Report to LSCRS 2012 AGM
Class 10 Arrays
Program Renewal for NSCC Schools 2010-11
Class 6 truth tables and boolean math
Class 5 - Set Theory and Venn Diagrams
Class 4 IPO and Intro to Ruby
Class 3 Binary & Hexadecimal
Class 2 Math I
Portfolio Of A Community
Cause & effect analysis part 2
Cause & effect analysis part 1
Class 11 lecture notes
Class 10 Lecture Notes
Class 9 Lecture Notes
Class 8 Lecture Notes
Deck Project Phase II
Ad

Recently uploaded (20)

PDF
Pre independence Education in Inndia.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
01-Introduction-to-Information-Management.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Types and Its function , kingdom of life
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Insiders guide to clinical Medicine.pdf
Pre independence Education in Inndia.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
01-Introduction-to-Information-Management.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
VCE English Exam - Section C Student Revision Booklet
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Computing-Curriculum for Schools in Ghana
Cell Types and Its function , kingdom of life
TR - Agricultural Crops Production NC III.pdf
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
GDM (1) (1).pptx small presentation for students
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Classroom Observation Tools for Teachers
Insiders guide to clinical Medicine.pdf

Class 6a ruby math

  • 1. MATH HACKS IN RUBY Class 6a – Ruby Math
  • 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. 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. 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. Demonstration  IPO  Input  Processing  Output  Code
  • 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. 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. 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. Summary  Exponent (a**b)  Root (sqrt or a**b/c.to_f)  Absolute (abs)  Modulus (a%b)  Random (rand(x))  Pi (Math::PI)
  • 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