Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
484 B · 27 lines
Ruby
at rust
12345678910111213141516171819202122232425262728#!/usr/bin/env ruby# frozen_string_literal: true
INPUT = ARGV[0] || '0,20,7,16,1,18,15'NUMS = INPUT.split(',').map(&:to_i)
def solve(turns) data = [-1] * turns NUMS[..-2].each_with_index { data[_1] = _2 + 1 }
last, turn = NUMS.last, NUMS.size
while turn < turns first, data[last] = data[last], turn last = first == -1 ? 0 : turn - first turn += 1 end
lastend
if ARGV[1] puts solve2(ARGV[1].to_i)else puts solve(2020) puts solve(30_000_000)end