
Ankit Pariyar
Posted on • Edited on
Advent of Code 2022 with Ruby day 01
Problem
- We have text file which look like this
451480096703181148813905
Above number represents Calories of the food carried by 3 Elves. Blank line separate the food carried by each Elves
We have to find total Calories of the food carried by Elf carrying the most Calories
Solution
First let's break down problem
- Reading text file
- Find out total calories carried by each Elves
- Find out maximum out of that calories
calories_carried_by_each_elves=0max_calories=0File.foreach('day_01.txt')do|calories|ifcalories.to_i.positive?calories_carried_by_each_elves+=calories.to_ielsemax_calories=calories_carried_by_each_elvesifcalories_carried_by_each_elves>max_caloriescalories_carried_by_each_elves=0endendputsmax_calories
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse