Skip to content

Instantly share code, notes, and snippets.

@gurgeous
Created December 15, 2020 05:29
Show Gist options
  • Save gurgeous/5636fd2e267bc7ae1ecf9224be20bbf2 to your computer and use it in GitHub Desktop.
Save gurgeous/5636fd2e267bc7ae1ecf9224be20bbf2 to your computer and use it in GitHub Desktop.
15.rb
map = Hash.new { |h, v| h[v] = [] }
val = nil
(0...2020).each do |turns|
val = if turns < data.length
data[turns]
elsif map[val].length >= 2
map[val][-1] - map[val][-2]
else
0
end
map[val] << turns
end
p val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment