Hey Y'all!!! I thought I'd actually try making this happen this year and I completed the first challenges today!! I think in later challenges I'll actually try importing the text file as it is, but I wanted to make it fun for myself. I did the solution this time in ruby, and its a program you'd run on irb, that asks for the expenses and the factor you need to group to find the magic number (2 or 3) and it prints out the number to enter at the end.
classAdventAccountdefinitialize(expenses,factor=2)@expenses=expenses@factor=factorenddefperformfilter_big_numswinning_number(do_si_do)endprivatedeffilter_big_nums@expenses.reject!{|expense|expense>=2020}enddeffind_your_partner@expenses.combination(@factor).to_a()enddefwinning_set(group)group.sum==2020enddefdo_si_dofind_your_partner.eachdo|group|puts"Checking group #{group}"returngroupifwinning_set(group)endenddefwinning_number(group)puts"the winning number is #{group.reduce(:*)}"endendputs"Starting up the Advent Account checker"puts"Submit expenses now:"expenses=gets.chomp.split(",").map(&:to_i)puts"Thanks! Now, what factor should we search the expenses with?"factor=gets.chomp.to_itest=AdventAccount.new(expenses,factor)test.perform
Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
Hey Y'all!!! I thought I'd actually try making this happen this year and I completed the first challenges today!! I think in later challenges I'll actually try importing the text file as it is, but I wanted to make it fun for myself. I did the solution this time in ruby, and its a program you'd run on irb, that asks for the expenses and the factor you need to group to find the magic number (2 or 3) and it prints out the number to enter at the end.
Here's the way I solved it:
Ooh filtering out numbers > 2020 is a really nice touch. I hadn’t thought of that 😁