0a4ebc2eb6
Signed-off-by: Christina Sørensen <christina@cafkafk.com> |
||
---|---|---|
.. | ||
.exercism | ||
assembly-line.jq | ||
bats-extra.bash | ||
bats-jq.bash | ||
HELP.md | ||
HINTS.md | ||
README.md | ||
test-assembly-line.bats |
Assembly Line
Welcome to Assembly Line on Exercism's jq Track.
If you need help running the tests or submitting your code, check out HELP.md
.
If you get stuck on the exercise, check out HINTS.md
, but try and solve it without using those first :)
Introduction
Numbers
From the manual
jq supports the same set of datatypes as JSON - numbers, strings, booleans, arrays, objects (which in JSON-speak are hashes with only string keys), and "null".
Let's focus on numbers.
Numbers and numeric operators
All numbers, whether integers or otherwise, are IEEE754 double precision floating point numbers. This limits us to 53 bits of precision.
The usual operators are available to use with numbers:
-
arithmetic:
+
,-
,*
,/
,%
-
comparison:
==
,!=
,<
,<=
,>=
,>
-
standard math functions
For one-input functions, pipe the value into the function
$ jq -n '(1 | atan) * 4' 3.141592653589793
For two-input functions, the functions will ignore input and expect the inputs as parameters (recall parameters are separated by semicolons)
$ jq -n 'pow(2; 10)' 1024
Semi-colon is the separator for function arguments, not comma.
Other jq
expressions
To solve the exercise, you will need to know about conditional expressions.
Conditional Expressions
jq
uses an if-then-else
expression for conditional expressions.
As an expression, it is placed in a pipeline.
Then syntax is: if CONDITION then TRUE_EXPR else FALSE_EXPR end
.
The else
clause is optional in jq v1.7, but it is required in jq v1.6.
42 | if . < 33 then "small" else "larger" end
# => "larger"
Additional conditions use elif
42 | if . < 33 then "small"
elif . < 67 then "medium"
else "large"
end
# => "medium"
Instructions
In this exercise you'll be writing code to analyze the production of an assembly line in a car factory.
The assembly line's speed can range from 0
(off) to 10
(maximum).
At its slowest speed (1
), 221
cars are produced each hour.
The production increases linearly with the speed.
So with the speed set to 4
, it should produce 4 * 221 = 884
cars per hour.
However, higher speeds increase the likelihood that faulty cars are produced, which then have to be discarded.
The following table shows how speed influences the success rate:
1
to4
: 100% success rate.5
to8
: 90% success rate.9
: 80% success rate.10
: 77% success rate.
You have two tasks.
1. Calculate the production rate per hour
Calculate the assembly line's production rate per hour, taking into account its success rate.
2. Calculate the number of working items produced per minute
Calculate how many completed, working cars are produced per minute.
Source
Created by
- @glennj