Skip to content

Instantly share code, notes, and snippets.

@thagomizer
Created December 13, 2017 17:32
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 thagomizer/5ae141ea49c8a48a0c14b67a45b975f7 to your computer and use it in GitHub Desktop.
Save thagomizer/5ae141ea49c8a48a0c14b67a45b975f7 to your computer and use it in GitHub Desktop.
data = File.read(ARGV[0]).split("\n").map { |l| l.split(": ").map(&:to_i) }
layers = {}
data.each do |a, b|
layers[a] = b
end
max = ARGV[1].to_i
t = 0
i = 0
score = 0
while i <= max do
l = layers[i]
if l
thingy = (l - 1) * 2
if t % thingy == 0
score += i * l
end
end
i += 1
t += 1
end
puts "Star 1 #{score}"
delay = 0
loop do
delay += 1
t = delay
i = 0
caught = false
while i <= max do
l = layers[i]
if l
thingy = (l - 1) * 2
if t % thingy == 0
caught = true
break
end
end
i += 1
t += 1
end
unless caught
puts "Star 2 #{delay}"
exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment