Skip to content

Instantly share code, notes, and snippets.

@creativenucleus
Created July 26, 2012 13:06
Show Gist options
  • Save creativenucleus/3181943 to your computer and use it in GitHub Desktop.
Save creativenucleus/3181943 to your computer and use it in GitHub Desktop.
Ruby Rubbish
```ruby
# Author: JR
isbn_in = IO.readlines( 'books.txt' );
isbn_in.each { |n|
scan_digits = n.scan(/\d/)
scan_filtered = scan_digits.join;
correct_length = [10,13].include? scan_filtered.length
puts "correct length: " + correct_length.to_s
checksum_digit = scan_digits.pop
puts "checksum digit: " + checksum_digit
# This doesn't work
checksum_calc = scan_digits.reduce { |sum, n| sum += n.to_i }
puts 'checksum: ' + checksum_calc
puts '--'
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment