DEV Community

Discussion on: AoC Day 1: Chronal Calibration

Collapse
 
dnamsons profile image
Dāvis Namsons

That's a good idea !

Ruby

Part 1

input = File.open('./freqs.in').read

frequency = 0

input.each_line do |line|
  frequency += line.to_i
end

puts frequency

Part 2

input = File.open('./freqs.in').read

frequency_changes = input.scan(/[-+]\d+/).collect! &:to_i

frequency = 0
frequencies = []
i = 0

until frequencies.include?(frequency)
  frequencies << frequency
  frequency += frequency_changes[i]
  i == frequency_changes.length - 1 ? i = 0 : i += 1
end

puts frequency
Collapse
 
arjunrajkumar profile image
Arjun Rajkumar • Edited

Hi Davis.. Just starting on the #adventofcode series.

Just curious how you are reading the inputs. E.g. first problem says the input is on adventofcode.com/2018/day/1/input

Will you be using Nokigiri or something similar to read the URL and parse the page to get the inputs?
Sorry if this sounds dumb.. But am wondering how you going to download the file?

Thanks