Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
552 B · 37 lines
Ruby
at rust
1234567891011121314151617181920212223242526272829303132333435363738#!/usr/bin/env ruby# frozen_string_literal: true
memory = $<.readline.split.map(&:to_i)
configs = Set.newredists = 0
def redistribute(array) blocks = array.max index = array.index blocks array[index] = 0 while blocks > 0 index = (index + 1) % array.size array[index] += 1 blocks -= 1 endend
until configs.include? memory configs.add memory.clone redistribute memory redists += 1end
p redists
state = memory.clone
steps = 1redistribute memorywhile memory != state redistribute memory steps += 1end
p steps