Comments (2)
Input range problem
I think it's important to decide the structure of the underlying graph. Will it have one or more cycles? Will it have multiple connected components? Should the solution accept units not given in the graph?
My personal pick would be no cycles and single connected component. The main reasons are:
- The solution is guaranteed to be unique as long as both units exist in the graph
- If there is a cycle and the cycle's product is different from 1, there are infinitely many possible answers
- If there are multiple connected components, no solution is possible even if both units are present
- For the single kind of measure (in this case, length), this is closest to real-life scenarios (IMO)
- The amount of conversions is fixed, unless an edge is traversed back and forth
Missing conversions might be fine, as many languages can handle it by null values or option types.
Handling rounding errors in test cases
This is usually done using absolute/relative error margin. For this particular problem, relative error should be sufficient since 1) all input/output/intermediate values must be positive and 2) only multiplication and division are used. The test roughly looks like this:
# test if `actual` is close to `expected` within `threshold` (relative error)
assert (1 - threshold) * expected <= actual <= (1 + threshold) * expected
# test if `actual` is close to `expected` within `threshold` (absolute error)
assert expected - threshold <= actual <= expected + threshold
Common choice of threshold is 1e-6
.
(Another option would be to return the sequence of units involved in the conversion, though it slightly obscures the intent of the problem.)
Input format
The most sensible choice would be a list of triples [unit_from, unit_to, ratio]
, presented in the most natural data type for each language.
Modeling vs. Implementation
My position is slightly towards modeling rather than implementation. Students are free to use an existing library or solve without one, and IMO neither should be considered superior to the other.
from julia.
I think it's important to decide the structure of the underlying graph. Will it have one or more cycles? Will it have multiple connected components? Should the solution accept units not given in the graph?
I don't like forcing a certain implementation/model upon the student, so I don't think that's something we have to decide.
However, test cases could be arranged in increasing complexity, e.g. the first tests have input that can be followed linearly to convert the units, then more complex test inputs for a more "realistic" exercise.
My personal pick would be no cycles and single connected component.
I feel like if this was a "real world" problem, cycles would be rather common in input data, so I'm not sure I agree on not having them, at least for more complex test cases.
A single connected component seems fine to me to keep the exercise simple. If a student solves that case, they're probably "fluent" enough to adapt it to handle multiple components anyway.
The most sensible choice would be a list of triples [unit_from, unit_to, ratio], presented in the most natural data type for each language.
For easier testing across tracks, it might be useful to store them in a simple text file and then provide the student with a parser in the stub files or generate the representation in code from that.
I'll put together an example implementation and some tests in Julia in the next few days.
from julia.
Related Issues (20)
- stage-heralding: add introduction
- vehicle-purchase: update introduction HOT 3
- some admonitions use unsupported syntax
- Exercises are listed on website despite not being in `config.json` nor `exercises/concept` HOT 4
- Concept exercise progress
- Buggy tets for Binary Search with multiple targets HOT 1
- Adding the square-root exercise HOT 1
- Link not showing properly in secret-handshake exercise
- Convert remaining mentoring notes to dig-deeper pages
- rational-numbers Ordering testset too hard
- Binary search too hard
- Rational numbers wants an approaches and better instructions
- Write dig-deeper page for darts and talk about hypot
- New practice exercise about Perceptron HOT 1
- Building a training set of tags for julia HOT 21
- Port additional exercises? HOT 2
- Progress of Verbose Unit Testing for Comprehensive Testing Summary HOT 4
- Add new exercise related to Plotting? HOT 1
- Where to add the exercise? HOT 1
- perfect-numbers: stub implementation passes all tests HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.