Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Fun Formulas

exercises/fun_formulas.livemd

Fun Formulas

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue Match OperatorCard Counting

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) * 100 # 70.0

Use arithmetic operators to determine the percentage given we have completed 12 out of 42 items.

Example solution

actual = 12
total = 42

(actual / total) * 100

Enter your solution below.

(12/42) *100

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.

Example solution

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.

Example solution

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$

Example solution

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$.

Example solution

c_squared = 116
:math.sqrt(c_squared)

Enter your solution below.

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Fun Formulas exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue Match OperatorCard Counting