gobanos / cargo-aoc

447 stars 47 forks source link

Getting the part2 result as a by-product of solving part1 #49

Open joncol opened 4 years ago

joncol commented 4 years ago

Does someone have a good suggestion on how to organize the code when your solution of part1 also yields the answer to part2? Would I use a global to store the part2 result, and then just return that in the part2 function? Or is there a cleaner way to do it?

gobanos commented 4 years ago

Your part1 function is a standard function, you should be able to call it from part2

joncol commented 4 years ago

I was just thinking of a nice way to store the result, so I don't have to do the same calculations twice. Maybe there's some nice memoization crate I could use.