Update

So I have some half written #100DaysOfCode entries but this is me getting back on the band wagon. I am heading off to RubyConf Thailand 2022 and anyway who said these 100 days have to be contiguous.

It also happens to be AdventOfCode so day 1 it is. I didn’t do well timing wise and got quite bogged down in my “process” I have a make file and a set of sepcs and named files and heredocs for the code to go in but somehow under pressure of coding and pressure of listening out for delayed flight gate changes I lost my ability to write anything. I put my laptop away got a drink and worked out I actually have more time than I thought. Maybe time pressure just does not do my coding all that well. With time on my side I could

export my session key

export SESSION=536...956

use my make file to fetch the appropriate puzzle input for my code

# Makefile excerpt
.PHONY: puzzle-input
puzzle-input:
	curl "https://adventofcode.com/$(year)/day/$(day)/input" \
  	-H "cookie: session=${SESSION}" > inputs/$(year)_$(day)_input.txt
make puzzle-input year=2022 day=1

update my tests with input and output

generate_file_with_contents("input.txt") do
  <<~EO_REPORT
    1000
    2000
    3000

    4000

    5000
    6000

    7000
    8000
    9000

    10000
  EO_REPORT
end

test for part I eq 24_000 test for part II eq 41_000

once I wrote some code that mapped with object to keep track of current, max and all “calorie” values for “elves” in the prescribed problem https://adventofcode.com/2022/day/1 j

file_to_numbers(report_filename)
  ...
  .with_object(
    {
      max: 0,
      all: [],
      current: 0,
    },
  ) do |number, totals|
    ...
    totals[:all] ...
    totals[:max] ...
    ...
    totals[:current] += number

then I could finally run using the real input

bundle exec ruby -I lib -e "require 'day_01_calorie_counter'; \
  puts Day01CalorieCounter.new.perform(ARGV[0])" inputs/2022_1_input.txt

bundle exec ruby -I lib -e "require 'day_01_calorie_counter'; \
  puts Day01CalorieCounter.new.perform_pII(ARGV[0])" inputs/2022_1_input.txt

not really that thrilled with my setup for

  1. downloading puzzle input
  2. testing on sample
  3. switching to real data

but if I am not rushing it seems to work well

if you are intrested in my solution it can be found here -> https://github.com/saramic/100-days-of-code/blob/main/AdventOfCode/2022/lib/day_01_calorie_counter.rb