Skip to content

Instantly share code, notes, and snippets.

@basicxman
Created February 24, 2011 23:33
Show Gist options
  • Save basicxman/843134 to your computer and use it in GitHub Desktop.
Save basicxman/843134 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class Influence
def get_data_lines
file_path = File.dirname(__FILE__) + '/input.txt'
input_data = File.read(file_path)
return input_data.split("\n")
end
def initialize
@users = []
get_data_lines.each_with_index do |user_data, user_id|
@users << []
data = user_data.split(//)
data.each_with_index do |cell, index|
@users[user_id] << index if cell == "X"
end
end
user_influence = []
0.upto(@users.length - 1) { |x| user_influence[x] = track_influence(x) }
user_influence.sort!.reverse!
puts "#{user_influence[0]}#{user_influence[1]}#{user_influence[2]}"
end
def track_influence(user_id, current = 0)
added_users = @users[user_id]
influence = current
influence += added_users.length
added_users.each { |new_id| influence += track_influence(new_id) }
return influence
end
end
calculate = Influence.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment