Skip to content

Instantly share code, notes, and snippets.

@ksykulev
Created March 17, 2014 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksykulev/9600433 to your computer and use it in GitHub Desktop.
Save ksykulev/9600433 to your computer and use it in GitHub Desktop.
wildcard problem1
#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