SlideShare uma empresa 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

Mais conteúdo relacionado

Mais 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
 

Mais 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

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.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
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
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...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
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
 
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...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

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