Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CastonPursuit/c4dc3dd6157e68ed55efffbef702b4b1 to your computer and use it in GitHub Desktop.
Save CastonPursuit/c4dc3dd6157e68ed55efffbef702b4b1 to your computer and use it in GitHub Desktop.

Math Basics for Developers

Time: 1 hr 30 mins

๐Ÿ“œ Slides

Link to Slides

๐ŸŽฏ Learning Objectives

By the end of this lesson, participants will be able to:

  • ๐Ÿ’ก Review and reinforce fundamental math concepts that developers are expected to know.
  • ๐Ÿงฎ Understand the concept of NaN (Not a Number) and its implications in mathematical operations.
  • ๐Ÿ“Š Utilize built-in math methods in JavaScript to perform mathematical calculations and solve problems.
  • ๐ŸŽฏ Apply math concepts to solve coding problems and enhance problem-solving skills.

๐Ÿ”ฅ Warmup Activity - Exploring Math Concepts in Software Development

๐Ÿš€ Introduction Explain the purpose of the warmup activity to engage participants in exploring math concepts used in software development. Emphasize the importance of understanding the connection between math and programming for problem-solving and algorithmic thinking.
๐Ÿ“ƒ Activity Instructions and Math Concepts Divide participants into breakout rooms. Assign each breakout room a specific math concept related to software development. Provide a list of suggested math concepts for each group to explore and research. In their breakout discussions, participants should investigate how the assigned math concept is utilized in software development. Encourage participants to explore relevant applications, specific algorithms, or techniques associated with the math topic. Ask participants to document their findings on a shared slide or collaborative document for their group's presentation. Math Concepts and Groups: Group 1: Algebra Explore how algebraic concepts like variables, equations, and formulas are used in programming for tasks such as solving equations, manipulating formulas, or representing mathematical relationships. Research real-world scenarios where algebra is applied in software development and provide examples. Group 2: Geometry Investigate how geometric concepts like points, lines, shapes, and spatial relationships are used in computer graphics, 3D modeling, or game development. Research specific algorithms or techniques in graphics programming that involve geometric calculations. Group 3: Calculus Explore how calculus concepts like derivatives, integrals, and limits are used in physics simulations, optimization algorithms, or data analysis. Research examples of how calculus is applied in software development tasks and provide insights into its significance. Group 4: Linear Algebra Investigate how linear algebra concepts like matrices, vectors, and linear transformations are used in computer graphics, machine learning, or data analysis. Research specific applications or algorithms that leverage linear algebra for problem-solving or data manipulation. Group 5: Discrete Mathematics Explore how discrete mathematics concepts like sets, logic, combinatorics, and graph theory are applied in algorithms, cryptography, or network analysis. Research real-world examples where discrete mathematics plays a crucial role in software development tasks. Group 6: Probability and Statistics Investigate how probability and statistical concepts such as random variables, distributions, and hypothesis testing are applied in data analysis, machine learning, or simulations. Research specific algorithms or techniques that utilize probability and statistics in software development.
๐Ÿ“ข Main Session Presentation Reconvene in the main session where each group will present their findings to the entire group. Each group can share their slide or collaborative document with the information they researched, highlighting the math concept, its relevance in software development, and providing concrete examples and applications. Allow time for questions, discussions, and reflections on the connections between math and software development.

Math Skills for Software Development

Application/Domain Math Skills Required
Basic Web Development Arithmetic, Basic Algebra
Data Analysis and Visualization Statistics, Probability
Machine Learning and Artificial Intelligence Linear Algebra, Calculus, Probability Theory, Optimization Algorithms
Computer Graphics and Game Development Linear Algebra, Geometry
Cryptocurrency and Blockchain Number Theory, Cryptography, Secure Protocols

๐Ÿ“š Introduction to Numeric Data Types

(20 minutes)

1. Introduction to Concepts
  • Explain each concept: Integer, Float/Floating Point, Positive Number, Negative Number, and Non-negative Number.
  • Provide examples and discuss their relevance in programming.

Numeric Data Types

Concept Definition Examples Relevance in Programming
Integer A whole number that is not a fraction 42, 0, -10 Used for counting, indexing, and representing discrete quantities in programming
Float/Floating Point An approximate value for a decimal or fraction 3.14, 2.5, -0.5 Used to represent real-world measurements, scientific calculations, and mathematical ops
Positive Number A value greater than zero 7, 3.6, 100 Used to represent quantities, measurements, and values greater than zero
Negative Number A value less than zero -5, -2.8, -100 Used to represent opposite or inverse quantities, debts, temperature differences, etc.
Non-negative Number A value greater than or equal to zero 0, 12, 3.9 Used when only positive values or zero are valid
๐Ÿ“ Summary and Conclusion
  • Recap the key concepts covered during the lesson.
  • Emphasize the relevance and importance of understanding these numeric data types in programming.
  • Encourage participants to explore further and apply these concepts in their coding practice.

๐Ÿ“š Introduction to NaN

(15 minutes)

1. Introduction
  • Briefly explain what NaN (Not a Number) is and its meaning in programming.
  • Discuss how NaN arises when performing mathematical operations on non-numeric values.
  • Emphasize the importance of proper data handling and avoiding invalid calculations.
2. Breakout Room Activity
  • Divide participants into breakout rooms, ensuring each room has a mix of skill levels and backgrounds.
  • Instruct each breakout room to work collaboratively and come up with 4-6 different ways to produce NaN while programming. They can explore mathematical operations, data conversions, comparisons, or any other relevant programming techniques.
  • Encourage the groups to experiment with different code snippets and discuss their findings within the breakout room.
  • Provide a designated time frame for the activity, such as 10-15 minutes, to allow sufficient time for exploration and discussion.
3. Main Session Debrief
  • Bring the groups back to the main session.
  • Ask each group to take turns presenting their findings to the rest of the class. They can share their code snippets and explain the scenarios in which NaN is produced.
  • Facilitate a brief discussion after each presentation to clarify any questions or highlight interesting insights.
4. Conclusion
  • Recap the key points covered during the lesson.
  • Emphasize the significance of understanding NaN and proper data handling in programming.
  • Encourage participants to further explore the topic and apply their knowledge in practical coding scenarios.

๐Ÿ“š Multiplication for Developers

(15 minutes)

1. Operator: Multiplication
  • The multiplication operator in JavaScript is represented by the asterisk symbol (*).
const a = 5;
const b = 3;
const result1 = a * b;
console.log(result1); // Output: 15
2. Numeric Conversion: Multiplying with Non-Numeric Value JavaScript automatically performs numeric conversion when using the multiplication operator.
const c = 2;
const d = "3";
const result2 = c * d;
console.log(result2); // Output: 6
3. Implicit Type Conversion: Multiplying String with Number JavaScript performs implicit type conversion in some cases, converting the string to a number for multiplication.
const e = "4";
const f = 2;
const result3 = e * f;
console.log(result3); // Output: 8
4. Floating-Point Arithmetic: Multiplying Decimal Numbers JavaScript uses floating-point arithmetic for multiplication, which can lead to imprecise results.
const g = 0.1;
const h = 0.2;
const result4 = g * h;
console.log(result4); // Output: 0.020000000000000004
5. NaN (Not-a-Number): Multiplying Non-Numeric Value If one or both operands in a multiplication expression cannot be converted to a number, JavaScript returns NaN as the result.
const i = "hello";
const j = 2;
const result5 = i * j;
console.log(result5); // Output: NaN
Zoom Quiz 1. What is the output of the following code snippet?
const a = "10";
const b = 5;
const result = a * b;
console.log(result);

A) 10
B) 50
C) "10"
D) NaN

  1. What is the result of the following multiplication operation: 0.1 * 0.2?
    A) 0.02
    B) 0.020000000000000004
    C) 0.3
    D) 0.12

  2. Which of the following will produce NaN as the result?
    A) "hello" * 2
    B) "2" * 2
    C) "NaN" * 2
    D) "true" * 2


๐Ÿ“š PEMDAS for Devs

(15 minutes)

Code Snippets

Example 1: Parentheses

const result1 = (5 + 3) * 2;
console.log(result1); // Output: 16
  
  
const result2 = 2 ** 3 + 1;
console.log(result2); // Output: 9


const result3 = 10 / 5 * 2;
console.log(result3); // Output: 4

  
const result4 = 8 - 4 + 2;
console.log(result4); // Output: 6

const result5 = (4 + 2) * (10 / 2) - 3 ** 2;
console.log(result5); // Output: 16
Summary: Instructor-Led Practice The code snippets above illustrate different scenarios involving PEMDAS. Parentheses take precedence over other operations, followed by exponents. Multiplication and division are performed from left to right, and addition and subtraction are also performed from left to right.
Instructor-Led Challenge

Present the following code snippets to the fellows and ask them to determine the output by applying the PEMDAS rules:

const result1 = 3 + 2 * 4 - 1;
console.log(result1); // Output: ?

const result2 = 2 * (4 - 1) ** 2;
console.log(result2); // Output: ?

Encourage the fellows to think through the order of operations and evaluate the expressions. After giving them some time to solve the problems, discuss the solutions together as a group to reinforce their understanding of PEMDAS.

๐Ÿ“š Math Functions for Devs: max, min, and abs

(15 minutes)

Code Snippets

Example 1: Finding the Maximum Value

const numbers1 = [5, 8, 2, 9, 4];
const max1 = Math.max(...numbers1);
console.log(max1); // Output: 9

Example 2: Finding the Minimum Value

const numbers2 = [5, 8, 2, 9, 4];
const min1 = Math.min(...numbers2);
console.log(min1); // Output: 2

Example 3: Finding the Absolute Value

const number = -7;
const absNumber = Math.abs(number);
console.log(absNumber); // Output: 7
Summary: Instructor-Led Practice The Math.max function is used to find the maximum value among a set of numbers, while the Math.min function is used to find the minimum value. Explain that these functions are part of the JavaScript Math library and are helpful when comparing and evaluating numeric values.

Additionally, introduce the Math.abs function, which returns the absolute (positive) value of a number. Discuss its relevance in various scenarios where the sign of a number is not important.

Demonstrate the code snippets above, showing how to use Math.max, Math.min, and Math.abs to find the maximum, minimum, and absolute values in different contexts.

Instructor-Led Challenge

Present the following code snippet to the fellows and ask them to find the maximum and minimum values in the array. Additionally, request them to log all numbers that are negative with their absolute values:

const numbers = [10, -5, 8, -3, 6];
const max = Math.max(...numbers);
const min = Math.min(...numbers);
const negatives = numbers.filter(num => num < 0).map(Math.abs);
console.log(`Max: ${max}, Min: ${min}`);
console.log(`Negative Numbers with Absolute Values: ${negatives}`);
                                                               

๐Ÿ“š Math Functions for Devs: round/floor/ceil

Math Library: Round/Ceil/Floor for Devs

Math Function: round

Example 1:

const num1 = 4.2;
const roundedNum1 = Math.round(num1);
console.log(roundedNum1); 

const num2 = 7.8;
const roundedNum2 = Math.round(num2);
console.log(roundedNum2); 

Math Function: ceil

Example 1:
const num1 = 2.1;
const ceiledNum1 = Math.ceil(num1);
console.log(ceiledNum1); 

const num2 = 5.9;
const ceiledNum2 = Math.ceil(num2);
console.log(ceiledNum2); 

Math Function: floor

Example 1:

const num1 = 3.7;
const flooredNum1 = Math.floor(num1);
console.log(flooredNum1); 

const num2 = 6.2;
const flooredNum2 = Math.floor(num2);
console.log(flooredNum2); 

Instructor-led Practice: Guess the Output

Example 1:

const num1 = 1.5;
const num2 = 2.8;

console.log(Math.round(num1)); 
console.log(Math.ceil(num2)); 
console.log(Math.floor(num1)); 

๐Ÿ“š Codewars Challenges

Codewars Challenge: Group Coding Session Challenge Objective: Each group should attempt a minimum of 2 Codewars challenges within the next hour. Collaborate as a team to discuss, solve, and learn from each other.

Choose from the following challenges:

  • A Square of Squares
  • Twice as Old
  • Halving Sum
  • Buying a Car
  • Multiplication Table
  • Cat Years, Dog Years
  • Over the Road
  • Get Nth Even Number
  • Deodorant Evaporator
  • Primorial of Number
  • Potion Class
  • Reverse FizzBuzz
  • Is it a Cube?
  • RGB to Hex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment