Skip to content

Instantly share code, notes, and snippets.

@selman
Created June 26, 2011 19:18
Show Gist options
  • Save selman/1047883 to your computer and use it in GitHub Desktop.
Save selman/1047883 to your computer and use it in GitHub Desktop.
tuxweet hazal
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
class Integer
# sayi basamaklarini array olarak dondurur
def digits
self.to_s.split(//).map!(&:to_i)
end
end
b3_c81 = (1..999).select {|s| s.digits.reduce(:*) == 81}
puts "basamak carpimi 81 olan 3 basamaga kadar #{b3_c81.size} sayi var"
puts "basamak carpimi 81 olan 3 basamaga kadar sayilar #{b3_c81}"
b3_c12_max = (1..999).select {|s| s.digits.reduce(:*) == 12}.max
b3_c12_max_dt = b3_c12_max.digits.reduce(:+)
puts "basamak carpimi 12 olan 3 basamakli en buyuk sayi #{b3_c12_max}"
puts "basamak carpimi 12 olan 3 basamakli en buyuk sayinin basamaklari toplami #{b3_c12_max_dt}"
__END__
basamak carpimi 81 olan 3 basamaga kadar 7 sayi var
basamak carpimi 81 olan 3 basamaga kadar sayilar [99, 199, 339, 393, 919, 933, 991]
basamak carpimi 12 olan 3 basamakli en buyuk sayi 621
basamak carpimi 12 olan 3 basamakli en buyuk sayinin basamaklari toplami 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment