Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
618 B · 27 lines
Ruby
at rust
12345678910111213141516171819202122232425262728#!/usr/bin/env ruby# frozen_string_literal: true
require 'ostruct'
discs = $stdin.readlines.map do |line| size, start = line.strip.match(/(\d+) positions.+?position (\d+)/).to_a[1..2].map(&:to_i) OpenStruct.new size: size, position: start # rubocop:disable Style/OpenStructUseend
def test?(discs, start) discs.all? { |disc| (disc.position + (start += 1)) % disc.size == 0 }end
start = -1
loop until test? discs, (start += 1)
puts "(1) #{start}"
start = -1
discs.push OpenStruct.new size: 11, position: 0 # rubocop:disable Style/OpenStructUse
loop until test? discs, (start += 1)
puts "(2) #{start}"