Skip to content

Instantly share code, notes, and snippets.

@hamiltondanielb
Created June 18, 2014 17:11
Show Gist options
  • Save hamiltondanielb/5aad59711ebc6dd1c39f to your computer and use it in GitHub Desktop.
Save hamiltondanielb/5aad59711ebc6dd1c39f to your computer and use it in GitHub Desktop.
Self Describing numbers
filename = ARGV[0]
file = File.new(filename, "r")
while (line = file.gets)
array = line.scan(/./)
new_array = Array.new
array.length.times do |var|
new_array << array.count(var.to_s).to_s
end
if new_array.eql? array
puts "1"
else
puts "0"
end
end
file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment