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

More from 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
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
 
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
Stephen Parsons
 
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
Stephen Parsons
 
Class 3 Binary & Hexadecimal
Class 3 Binary & HexadecimalClass 3 Binary & Hexadecimal
Class 3 Binary & Hexadecimal
Stephen Parsons
 
Class 2 Math I
Class 2 Math IClass 2 Math I
Class 2 Math I
Stephen Parsons
 
Portfolio Of A Community
Portfolio Of A CommunityPortfolio Of A Community
Portfolio Of A Community
Stephen Parsons
 
Cause & effect analysis part 2
Cause & effect analysis part 2Cause & effect analysis part 2
Cause & effect analysis part 2
Stephen Parsons
 
Cause & effect analysis part 1
Cause & effect analysis part 1Cause & effect analysis part 1
Cause & effect analysis part 1
Stephen Parsons
 
Class 11 lecture notes
Class 11 lecture notesClass 11 lecture notes
Class 11 lecture notes
Stephen Parsons
 
Class 10 Lecture Notes
Class 10  Lecture  NotesClass 10  Lecture  Notes
Class 10 Lecture Notes
Stephen Parsons
 
Class 9 Lecture Notes
Class 9 Lecture NotesClass 9 Lecture Notes
Class 9 Lecture Notes
Stephen Parsons
 
Class 8 Lecture Notes
Class 8 Lecture NotesClass 8 Lecture Notes
Class 8 Lecture Notes
Stephen Parsons
 
Deck Project Phase II
Deck Project Phase IIDeck Project Phase II
Deck Project Phase II
Stephen Parsons
 
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
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
 
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
Stephen Parsons
 
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
Stephen Parsons
 
Class 3 Binary & Hexadecimal
Class 3 Binary & HexadecimalClass 3 Binary & Hexadecimal
Class 3 Binary & Hexadecimal
Stephen Parsons
 
Portfolio Of A Community
Portfolio Of A CommunityPortfolio Of A Community
Portfolio Of A Community
Stephen Parsons
 
Cause & effect analysis part 2
Cause & effect analysis part 2Cause & effect analysis part 2
Cause & effect analysis part 2
Stephen Parsons
 
Cause & effect analysis part 1
Cause & effect analysis part 1Cause & effect analysis part 1
Cause & effect analysis part 1
Stephen Parsons
 

Recently uploaded (20)

Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Quiz-E-Mataram (Under 20 Quiz Set) .pptx
Quiz-E-Mataram (Under 20 Quiz Set) .pptxQuiz-E-Mataram (Under 20 Quiz Set) .pptx
Quiz-E-Mataram (Under 20 Quiz Set) .pptx
SouptikUkil
 
LDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College VolumeLDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College Volume
LDM & Mia eStudios
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
Unit 1 Tools Beneficial for Monitoring the Debugging Process.pdf
Unit 1 Tools Beneficial for Monitoring the Debugging Process.pdfUnit 1 Tools Beneficial for Monitoring the Debugging Process.pdf
Unit 1 Tools Beneficial for Monitoring the Debugging Process.pdf
ChatanBawankar
 
Drug Metabolism advanced medicinal chemistry.pptx
Drug Metabolism advanced medicinal chemistry.pptxDrug Metabolism advanced medicinal chemistry.pptx
Drug Metabolism advanced medicinal chemistry.pptx
pharmaworld
 
QUIZ-O-FORCE 3.0 FINAL SET BY SOURAV .pptx
QUIZ-O-FORCE 3.0 FINAL SET BY SOURAV .pptxQUIZ-O-FORCE 3.0 FINAL SET BY SOURAV .pptx
QUIZ-O-FORCE 3.0 FINAL SET BY SOURAV .pptx
Sourav Kr Podder
 
What are the Features & Functions of Odoo 18 SMS Marketing
What are the Features & Functions of Odoo 18 SMS MarketingWhat are the Features & Functions of Odoo 18 SMS Marketing
What are the Features & Functions of Odoo 18 SMS Marketing
Celine George
 
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
Julián Jesús Pérez Fernández
 
QUIZ-O-FORCE PRELIMINARY ANSWER SLIDE.pptx
QUIZ-O-FORCE PRELIMINARY ANSWER SLIDE.pptxQUIZ-O-FORCE PRELIMINARY ANSWER SLIDE.pptx
QUIZ-O-FORCE PRELIMINARY ANSWER SLIDE.pptx
Sourav Kr Podder
 
Unit 4 Reverse Engineering Tools Functionalities & Use-Cases.pdf
Unit 4  Reverse Engineering Tools  Functionalities & Use-Cases.pdfUnit 4  Reverse Engineering Tools  Functionalities & Use-Cases.pdf
Unit 4 Reverse Engineering Tools Functionalities & Use-Cases.pdf
ChatanBawankar
 
How to create and manage blogs in odoo 18
How to create and manage blogs in odoo 18How to create and manage blogs in odoo 18
How to create and manage blogs in odoo 18
Celine George
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
The Ellipsis Manual Analysis And Engineering Of Human Behavior Chase Hughes
The Ellipsis Manual Analysis And Engineering Of Human Behavior Chase HughesThe Ellipsis Manual Analysis And Engineering Of Human Behavior Chase Hughes
The Ellipsis Manual Analysis And Engineering Of Human Behavior Chase Hughes
pekokmupei
 
KNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted Regression
KNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted RegressionKNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted Regression
KNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted Regression
Global Academy of Technology
 
5503 Course Proposal Online Computer Middle School Course Wood M.pdf
5503 Course Proposal Online Computer Middle School Course Wood M.pdf5503 Course Proposal Online Computer Middle School Course Wood M.pdf
5503 Course Proposal Online Computer Middle School Course Wood M.pdf
Melanie Wood
 
Sri Guru Arjun Dev Ji .
Sri Guru Arjun Dev Ji                   .Sri Guru Arjun Dev Ji                   .
Sri Guru Arjun Dev Ji .
Balvir Singh
 
[2025] Qualtric XM-EX-EXPERT Study Plan | Practice Questions + Exam Details
[2025] Qualtric XM-EX-EXPERT Study Plan | Practice Questions + Exam Details[2025] Qualtric XM-EX-EXPERT Study Plan | Practice Questions + Exam Details
[2025] Qualtric XM-EX-EXPERT Study Plan | Practice Questions + Exam Details
Jenny408767
 
Unit Kali NetHunter is the official Kali Linux penetration testing platform f...
Unit Kali NetHunter is the official Kali Linux penetration testing platform f...Unit Kali NetHunter is the official Kali Linux penetration testing platform f...
Unit Kali NetHunter is the official Kali Linux penetration testing platform f...
ChatanBawankar
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Quiz-E-Mataram (Under 20 Quiz Set) .pptx
Quiz-E-Mataram (Under 20 Quiz Set) .pptxQuiz-E-Mataram (Under 20 Quiz Set) .pptx
Quiz-E-Mataram (Under 20 Quiz Set) .pptx
SouptikUkil
 
LDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College VolumeLDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College Volume
LDM & Mia eStudios
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
Unit 1 Tools Beneficial for Monitoring the Debugging Process.pdf
Unit 1 Tools Beneficial for Monitoring the Debugging Process.pdfUnit 1 Tools Beneficial for Monitoring the Debugging Process.pdf
Unit 1 Tools Beneficial for Monitoring the Debugging Process.pdf
ChatanBawankar
 
Drug Metabolism advanced medicinal chemistry.pptx
Drug Metabolism advanced medicinal chemistry.pptxDrug Metabolism advanced medicinal chemistry.pptx
Drug Metabolism advanced medicinal chemistry.pptx
pharmaworld
 
QUIZ-O-FORCE 3.0 FINAL SET BY SOURAV .pptx
QUIZ-O-FORCE 3.0 FINAL SET BY SOURAV .pptxQUIZ-O-FORCE 3.0 FINAL SET BY SOURAV .pptx
QUIZ-O-FORCE 3.0 FINAL SET BY SOURAV .pptx
Sourav Kr Podder
 
What are the Features & Functions of Odoo 18 SMS Marketing
What are the Features & Functions of Odoo 18 SMS MarketingWhat are the Features & Functions of Odoo 18 SMS Marketing
What are the Features & Functions of Odoo 18 SMS Marketing
Celine George
 
QUIZ-O-FORCE PRELIMINARY ANSWER SLIDE.pptx
QUIZ-O-FORCE PRELIMINARY ANSWER SLIDE.pptxQUIZ-O-FORCE PRELIMINARY ANSWER SLIDE.pptx
QUIZ-O-FORCE PRELIMINARY ANSWER SLIDE.pptx
Sourav Kr Podder
 
Unit 4 Reverse Engineering Tools Functionalities & Use-Cases.pdf
Unit 4  Reverse Engineering Tools  Functionalities & Use-Cases.pdfUnit 4  Reverse Engineering Tools  Functionalities & Use-Cases.pdf
Unit 4 Reverse Engineering Tools Functionalities & Use-Cases.pdf
ChatanBawankar
 
How to create and manage blogs in odoo 18
How to create and manage blogs in odoo 18How to create and manage blogs in odoo 18
How to create and manage blogs in odoo 18
Celine George
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
The Ellipsis Manual Analysis And Engineering Of Human Behavior Chase Hughes
The Ellipsis Manual Analysis And Engineering Of Human Behavior Chase HughesThe Ellipsis Manual Analysis And Engineering Of Human Behavior Chase Hughes
The Ellipsis Manual Analysis And Engineering Of Human Behavior Chase Hughes
pekokmupei
 
KNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted Regression
KNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted RegressionKNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted Regression
KNN,Weighted KNN,Nearest Centroid Classifier,Locally Weighted Regression
Global Academy of Technology
 
5503 Course Proposal Online Computer Middle School Course Wood M.pdf
5503 Course Proposal Online Computer Middle School Course Wood M.pdf5503 Course Proposal Online Computer Middle School Course Wood M.pdf
5503 Course Proposal Online Computer Middle School Course Wood M.pdf
Melanie Wood
 
Sri Guru Arjun Dev Ji .
Sri Guru Arjun Dev Ji                   .Sri Guru Arjun Dev Ji                   .
Sri Guru Arjun Dev Ji .
Balvir Singh
 
[2025] Qualtric XM-EX-EXPERT Study Plan | Practice Questions + Exam Details
[2025] Qualtric XM-EX-EXPERT Study Plan | Practice Questions + Exam Details[2025] Qualtric XM-EX-EXPERT Study Plan | Practice Questions + Exam Details
[2025] Qualtric XM-EX-EXPERT Study Plan | Practice Questions + Exam Details
Jenny408767
 
Unit Kali NetHunter is the official Kali Linux penetration testing platform f...
Unit Kali NetHunter is the official Kali Linux penetration testing platform f...Unit Kali NetHunter is the official Kali Linux penetration testing platform f...
Unit Kali NetHunter is the official Kali Linux penetration testing platform f...
ChatanBawankar
 

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