exercism / exercism/julia

New exercise idea: Unit conversions

Open
#154 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
73
Forks
82
Avg merge
2h 17m
Merged PRs (30d)
5

Description

This post is kept largely language-agnostic so that other tracks can use the exercise if they want. The implementation details for the Julia exercise can be found in a PR once the general exercise idea has been refined.

---

The exercise idea is based on the article [Google Interview Problems: Ratio Finder](https://medium.com/@alexgolec/google-interview-problems-ratio-finder-d7aa8bf201e3) by Alex Golec (scroll down to "The Question" to find the problem).

**General idea**: Given a list of conversion rates between different units, find a way to convert between them.

In the post, he uses distances as an example. The solver has to convert `1 hand` to `light years` given the following conversion rates:

```
1 hand = 4 inch
4 inches = 1/3 feet
1/3 feet = 6.3125e-5 american miles
6.3125e-5 american miles = 1.0737e-17 light years
```

His solution builds a graph from the given conversions and a search algorithm to find the conversion rate. For more details and an example implementation in Python, I suggest reading the post.

---

In an exercism adaptation of this problem, we could also use different kinds of units, e.g. mass or currency rates (the latter is also mentioned in the article). A few story ideas that immediately came to my mind:

- You're on vacation in a country that uses obscure units such as `miles` or `yards` and need to figure out what they mean.
- You want to translate a cooking recipe and it uses a variety of units for mass/volume, such as `cups`, `mugs` or `oz`.

Distance would have the advantage that there's a handy [video guide](https://youtu.be/r7x-RGfd0Yk) the readme could link to and that there is a huge amount of obscure and less obscure ways to represent distances.

One important question: Is this exercise about modelling the problem, i.e. recognising to use a graph to represent the conversions, or implementing a solution, i.e. writing the search algorithm and graph?
In the first case, it's probably helpful to mention that the students are encouraged to use relevant libraries to solve this exercise. In the second case, the exercise description should contain more information on how to approach the problem. Of course, forcing a certain way isn't necessary, but it may influence how the description is written.

**Tests**

There are a number of edge cases to consider when solving the exercise and creating a test suite:
- Does the solution minimise the amount of conversions needed to reduce rounding errors?
- The given problem may not have a unique solution.
- What format are the conversions given in?
- How to handle rounding errors in the test cases?
- How are missing conversions handled?

---

This is meant as a base to start the discussion, so feel free to take apart everything and perhaps we end up with a completely different, but better, exercise idea :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.