073 Counting fractions in a range.sf 367 B

1234567891011121314151617181920
  1. #!/usr/bin/ruby
  2. # Author: Trizen
  3. # Date: 21 March 2023
  4. # https://github.com/trizen
  5. # https://projecteuler.net/problem=73
  6. # Runtime: 31.865s
  7. func count_frac(max_d, min, max) {
  8. (min+max .. max_d) -> sum {|n|
  9. RangeNum(idiv(n,min)+1, idiv(n-1, max)).count_by {|k| n.is_coprime(k) }
  10. }
  11. }
  12. assert_eq(count_frac(8, 3, 2), 3)
  13. say count_frac(12_000, 3, 2)