Created
October 28, 2010 15:11
-
-
Save prakashmurthy/651545 to your computer and use it in GitHub Desktop.
Returns NaN when dealing with large numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Percentage of combinations with only one defect per chip = NaN. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Solution to problem number 307 on Project Euler | |
# http://projecteuler.net/index.php?section=problems&id=307 | |
# prob_307_defective_chips.rb | |
chips = 1_000_000 | |
defects = 20_000 | |
## Each of the defects has 1M options => Total = 1M**20k | |
total_combinations = chips**defects | |
## Combinations with only one defect per chip | |
total_1_defect_per_chip = 1 | |
(1..defects).each do |count| | |
total_1_defect_per_chip *= chips - count + 1 | |
end | |
# puts "#{total_combinations > total_1_defect_per_chip}" | |
puts "Percentage of combinations with only one defect per chip = #{(total_1_defect_per_chip * 100.0 / total_combinations)}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment