main.jl 655 B

123456789101112131415161718192021222324
  1. forest_slope_array = open(joinpath(@__DIR__, "input")) |> readlines
  2. function encounter_trees_array(down, step)
  3. trees = 0
  4. position = 1
  5. len = length(forest_slope_array[1])
  6. for line in forest_slope_array[1:down:end]
  7. trees += line[position] == '#' ? 1 : 0
  8. position += step
  9. position = position > len ? position % len : position
  10. end
  11. trees
  12. end
  13. println(encounter_trees_array(1, 3))
  14. product_trees =
  15. encounter_trees_array(1, 1) *
  16. encounter_trees_array(1, 3) *
  17. encounter_trees_array(1, 5) *
  18. encounter_trees_array(1, 7) *
  19. encounter_trees_array(2, 1)
  20. println(product_trees)