Created
March 17, 2014 14:38
-
-
Save ksykulev/9600433 to your computer and use it in GitHub Desktop.
wildcard problem1
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
#http://www.trywildcard.com/challenge/problem1 | |
FILE = ARGV[0] #problem1input.txt | |
NUMBEROFCARDS = ARGV[1].to_i #5 | |
def factorial(n) | |
( (1..n).reduce(:*) || 1 ) | |
end | |
columns = [] | |
total = 0 | |
row_total = 0 | |
IO.foreach(FILE) do |line| | |
line.chomp.chars.each_with_index do |char, index| | |
columns[index] = 0 if columns[index].nil? | |
if char == '*' | |
columns[index] += 1 | |
row_total += 1 | |
end | |
end | |
total += factorial(row_total) / factorial(row_total - NUMBEROFCARDS) if(row_total >= NUMBEROFCARDS) | |
row_total = 0 | |
end | |
puts total.inspect | |
puts columns.inspect | |
columns.each do |stars| | |
total += factorial(stars) / factorial(stars - NUMBEROFCARDS) if(stars >= NUMBEROFCARDS) | |
end | |
puts "result #{total}" #167160 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment