SlideShare una empresa de Scribd logo
1 de 10
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

Más contenido relacionado

Más de Stephen Parsons

Class 6 truth tables and boolean math
Class 6   truth tables and boolean mathClass 6   truth tables and boolean math
Class 6 truth tables and boolean math
Stephen Parsons
 

Más de Stephen Parsons (14)

Program Renewal for NSCC Schools 2010-11
Program Renewal for NSCC Schools 2010-11Program Renewal for NSCC Schools 2010-11
Program Renewal for NSCC Schools 2010-11
 
Class 6 truth tables and boolean math
Class 6   truth tables and boolean mathClass 6   truth tables and boolean math
Class 6 truth tables and boolean math
 
Class 5 - Set Theory and Venn Diagrams
Class 5 - Set Theory and Venn DiagramsClass 5 - Set Theory and Venn Diagrams
Class 5 - Set Theory and Venn Diagrams
 
Class 4 IPO and Intro to Ruby
Class 4 IPO and Intro to RubyClass 4 IPO and Intro to Ruby
Class 4 IPO and Intro to Ruby
 
Class 3 Binary & Hexadecimal
Class 3 Binary & HexadecimalClass 3 Binary & Hexadecimal
Class 3 Binary & Hexadecimal
 
Class 2 Math I
Class 2 Math IClass 2 Math I
Class 2 Math I
 
Portfolio Of A Community
Portfolio Of A CommunityPortfolio Of A Community
Portfolio Of A Community
 
Cause & effect analysis part 2
Cause & effect analysis part 2Cause & effect analysis part 2
Cause & effect analysis part 2
 
Cause & effect analysis part 1
Cause & effect analysis part 1Cause & effect analysis part 1
Cause & effect analysis part 1
 
Class 11 lecture notes
Class 11 lecture notesClass 11 lecture notes
Class 11 lecture notes
 
Class 10 Lecture Notes
Class 10  Lecture  NotesClass 10  Lecture  Notes
Class 10 Lecture Notes
 
Class 9 Lecture Notes
Class 9 Lecture NotesClass 9 Lecture Notes
Class 9 Lecture Notes
 
Class 8 Lecture Notes
Class 8 Lecture NotesClass 8 Lecture Notes
Class 8 Lecture Notes
 
Deck Project Phase II
Deck Project Phase IIDeck Project Phase II
Deck Project Phase II
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

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