Fun Formulas
Mix.install([
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"},
{:tested_cell, github: "brooklinjazz/tested_cell"},
{:utils, path: "#{__DIR__}/../utils"}
])
Navigation
Setup
Ensure you type the ea
keyboard shortcut to evaluate all Elixir cells before starting. Alternatively you can evaluate the Elixir cells as you read.
Fun Formulas
As developers, it’s our job to translate business requirements into something that the computer understands.
These exercises will have you convert a common formula into an Elixir program.
Loading Bar Percentage
We often need to display loading bars to the user. Loading bars use the current percentage they have finished loading in order to display the loading progress.
You can calculate the percentage with $\frac{actual\ value}{total\ value}\times100$
For example if we complete 7
out of 10
items, we would be 70.0%
complete.
7 / 10 # 70.0
Use arithmetic operators to determine the percentage given we have completed 12
out of 42
items.
Hint
actual = 12
total = 42
actual / total
Enter your solution below.
Rocket Ship
We’re building a rocket ship app to teach people about physics.
Users can enter the mass
and acceleration
of a ship to visualize the force
generated.
Given that ${mass} * {acceleration} = force$, calculate the force when mass is 10
and acceleration is 50
.
Hint
mass = 10
acceleration = 50
mass * acceleration
Enter your solution below.
What Do You Tip?
It’s common in many cultures to leave a tip whenever you buy a meal. It’s common to calculate the tip as a percentage of the meal.
Given the initial cost of a meal is 20
, and you want to leave a 15%
tip, use arithmetic operators to determine the total cost of the meal.
Hint
initial_cost = 20
tip_percent = 1.15
initial_cost * tip_percent
Enter your solution below.
Pythagorean Theorum
To calculate the longest side of a triangle we use $a^2 + b^2 = c^2$
Given a triangle where side $a$ is 4
, and side $b$ is 10
, calculate $c^2$
Hint
a = 4
b = 10
a ** 2 + b ** 2
Enter your solution below.
Bonus: Square Root
Earlier we calculated $c^2$ for pythagoream theorum. Given $c^2$ is 116
determine the square root of $c^2$ to calculate $c$.
Hint
c_squared = 116
:math.sqrt(c_squared)
Enter your solution below.
Commit Your Progress
Run the following in your command line from the beta_curriculum folder to track and save your progress in a Git commit.
$ git add .
$ git commit -m "finish fun formulas exercise"
Up Next
Previous | Next |
---|---|
Match Operator | Card Counting |