Codewars: Rust workspace for solving the 'Printer Errors' kata
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
1.1 KiB

3 years ago
  1. ## Printer Errors
  2. In a factory a printer prints labels for boxes. For one kind of boxes the printer has to use colors which, for the sake of simplicity, are named with letters from `a` to `m`.
  3. The colors used by the printer are recorded in a control string. For example a *"good"* control string would be `aaabbbbhaijjjm` meaning that the printer used three times color a, four times color b, one time color h then one time color a...
  4. Sometimes there are problems: lack of colors, technical malfunction and a *"bad"* control string is produced e.g. `aaaxbbbbyyhwawiwjjjwwm` with letters not from `a` to `m`.
  5. You have to write a function printer_error which given a string will return the error rate of the printer as a string representing a rational whose numerator is the number of errors and the denominator the length of the control string. Don't reduce this fraction to a simpler expression.
  6. The string has a length greater or equal to one and contains only letters from `a` to `z`.
  7. **Examples:**
  8. ```rust
  9. s = "aaabbbbhaijjjm"
  10. printer_error(s) => "0/14"
  11. s = "aaaxbbbbyyhwawiwjjjwwm"
  12. printer_error(s) => "8/22"
  13. ```