1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Disc = Struct.new(:positions, :start_position) do
  def position_at(time)
    (start_position + time) % positions
  end
end

discs = DATA.each_line.map {|line|
  /Disc #\d has (?<positions>\d+) positions; at time=0, it is at position (?<position>\d+)./ =~ line
  Disc.new(positions.to_i, position.to_i)
}
discs << Disc.new(11, 0)

p (0..Float::INFINITY).find {|t|
  discs.each.with_index.all? {|disc, index|
    disc.position_at(t + index) == 0
  }
}

__END__