made as test task
- Written in Elixir
- Assume this is part of a bigger project rather than a code kata when it comes to design & code quality
- Provides a HTTP Rest or GraphQL API
- Outputs JSON
- No auth necessary
- Should not rely on a database
- Does not require state persistence between restarts
The API should provide the following functionality:
Ability to accept an arbitrary number of digits which should be appended to any previously received digits to form a long number.
Ability to clear the previously received list of digits
Calculates a checksum given the current state and returns it
BONUS - For bonus points return a timeout response if checksum can't be calculated in less than 15ms
- Add up the digits in odd positions and multiply by 3
- Add up the digits in even positions
- Add up the results of 1 and 2
- Divide by 10 and take the remainder.
- If the remainder is 0 final result is 0 otherwise subtract it from 10 for final result
Example:
5 4 8 9 8 5 0 3 5 4
- 5 + 8 + 8 + 0 + 5 = 26 * 3 = 78
- 4 + 9 + 5 + 3 + 4 = 25
- 78 + 25 = 103
- 103 / 10 = 10.3 = 3
- 10 - 3 = 7
- Written in any language except Elixir
- Reads a test input file for commands, each row contains a single command
- Store received checksums and append to final result
- Final output should be concatenated string of checksums
Any unrecognised commands, empty lines or commands that error should be ignored
Add: The row begins with capital letter A
followed by a number of digits, ex: A18237283
Clear: The row begins with capital letter C
Checksum: The row begings with letters CS
C
A24
CS
A47
CS
A1112
CS
C
A90
CS
C
A5218900797
8442
CS
C
A8215529768332323333588123515888912412
CS
C
A11
CS
A11
A11
A11
A11
A11
A11
11
A12
CS
A22222
A33333
CS
A3
CS
- mix phx.server
- ruby test_client
allowed query params *?with_positions=true* - will number positions for current state