Skip to content

Instantly share code, notes, and snippets.

@philcrissman
Created December 13, 2017 19:03
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 philcrissman/71fd827a76dca76d4ba7bf9f1f77b351 to your computer and use it in GitHub Desktop.
Save philcrissman/71fd827a76dca76d4ba7bf9f1f77b351 to your computer and use it in GitHub Desktop.
@data = File.read("./input.txt").split("\n").map{|n| n.split(": ").map(&:to_i)}.to_h
@firewall = Array.new(99)
@firewall = @firewall.each_with_index.map{|n,i| next if @data[i].nil?; ((0..@data[i]-1).to_a + (1..@data[i]-2).to_a.reverse).cycle}
@results = (0..98).map{|n| n if @firewall.map{|e| next if e.nil?; e.next}[n] == 0}.select{|n| n if !n.nil?}
@severity = @results.map{|i| i * @data[i]}.inject(&:+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment