Skip to content

Instantly share code, notes, and snippets.

@caironoleto
Last active December 16, 2015 09:59
Show Gist options
  • Save caironoleto/5417306 to your computer and use it in GitHub Desktop.
Save caironoleto/5417306 to your computer and use it in GitHub Desktop.
Pis Pasep Generator
#!/bin/ruby
class PisPasepGenerator
INDEX = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
def self.generate!
numbers = []
10.times { numbers << rand(10) }
calculated = numbers.each_with_index { |n, i| PisPasepGenerator::INDEX[i] * n }.inject(:+)
rest = calculated % 11
calculated = 11 - rest
if calculated == 10 || calculated == 11
numbers << 0
else
numbers << calculated
end
numbers.join
end
end
PisPasepGenerator.generate!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment