Skip to content

Instantly share code, notes, and snippets.

@venelrene
Created November 21, 2019 17:23
Show Gist options
  • Select an option

  • Save venelrene/be8ac216f07134d233c5b5a065bd23d1 to your computer and use it in GitHub Desktop.

Select an option

Save venelrene/be8ac216f07134d233c5b5a065bd23d1 to your computer and use it in GitHub Desktop.
You have to write a function printer_error which given a string will output 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.
def printer_error(s)
"#{s.count('n-z')}/#{s.size}"
end
##### Before refactor #####
def printer_error(s)
error_num = s.split('').count {|s| s =~ /[n-z]/}
"#{error_num}/#{s.size}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment