I'll leave the question open, but here are some other attempts. Credit goes to RMartinhoFernandes RMartinhoFernandes for solution3
, which requires his Pointfree module for the /\
combinator.
sumProgressions3 :: Integer -> Integer
sumProgressions3 limit = solve [1 .. limit]
multipleOf n = (== 0) . (`mod` n)
multipleOf3Or5 = uncurry (||) . ((multipleOf 3) /\ (multipleOf 5))
solve = sum . filter multipleOf3Or5
And solution4
is a completely in-lined version of the simplified formula in my question:
sumProgressions4 :: Integer -> Integer -> Integer -> Integer
sumProgressions4 d1 d2 lim = let d3 = d1 * d2
in d1 * (lim `div` d1) * (1 + (lim `div` d1)) `div` 2
+ d2 * (lim `div` d2) * (1 + (lim `div` d2)) `div` 2
- d3 * (lim `div` d3) * (1 + (lim `div` d3)) `div` 2
I've repeated the benchmarks on my machine with the same parameters as above.
I'll leave the question open, but here are some other attempts. Credit goes to RMartinhoFernandes for solution3
, which requires his Pointfree module for the /\
combinator.
sumProgressions3 :: Integer -> Integer
sumProgressions3 limit = solve [1 .. limit]
multipleOf n = (== 0) . (`mod` n)
multipleOf3Or5 = uncurry (||) . ((multipleOf 3) /\ (multipleOf 5))
solve = sum . filter multipleOf3Or5
And solution4
is a completely in-lined version of the simplified formula in my question:
sumProgressions4 :: Integer -> Integer -> Integer -> Integer
sumProgressions4 d1 d2 lim = let d3 = d1 * d2
in d1 * (lim `div` d1) * (1 + (lim `div` d1)) `div` 2
+ d2 * (lim `div` d2) * (1 + (lim `div` d2)) `div` 2
- d3 * (lim `div` d3) * (1 + (lim `div` d3)) `div` 2
I've repeated the benchmarks on my machine with the same parameters as above.
I'll leave the question open, but here are some other attempts. Credit goes to RMartinhoFernandes for solution3
, which requires his Pointfree module for the /\
combinator.
sumProgressions3 :: Integer -> Integer
sumProgressions3 limit = solve [1 .. limit]
multipleOf n = (== 0) . (`mod` n)
multipleOf3Or5 = uncurry (||) . ((multipleOf 3) /\ (multipleOf 5))
solve = sum . filter multipleOf3Or5
And solution4
is a completely in-lined version of the simplified formula in my question:
sumProgressions4 :: Integer -> Integer -> Integer -> Integer
sumProgressions4 d1 d2 lim = let d3 = d1 * d2
in d1 * (lim `div` d1) * (1 + (lim `div` d1)) `div` 2
+ d2 * (lim `div` d2) * (1 + (lim `div` d2)) `div` 2
- d3 * (lim `div` d3) * (1 + (lim `div` d3)) `div` 2
I've repeated the benchmarks on my machine with the same parameters as above.
I'll leave the question open, but here are some other attempts. Credit goes to RMartinhoFernandes for solution3
, which requires his Pointfree module for the /\
combinator.
sumProgressions3 :: Integer -> Integer
sumProgressions3 limit = solve [1 .. limit]
multipleOf n = (== 0) . (`mod` n)
multipleOf3Or5 = uncurry (||) . ((multipleOf 3) /\ (multipleOf 5))
solve = sum . filter multipleOf3Or5
And solution4
is a completely in-lined version of the simplified formula in my question:
sumProgressions4 :: Integer -> Integer -> Integer -> Integer
sumProgressions4 d1 d2 lim = let d3 = d1 * d2
in d1 * (lim `div` d1) * (1 + (lim `div` d1)) `div` 2
+ d2 * (lim `div` d2) * (1 + (lim `div` d2)) `div` 2
- d3 * (lim `div` d3) * (1 + (lim `div` d3)) `div` 2
I've repeated the benchmarks on my machine with the same parameters as above.
I'll leave the question open, but here are some other attempts. Credit goes to RMartinhoFernandes for solution3
, which requires his Pointfree module for the /\
combinator.
sumProgressions3 :: Integer -> Integer
sumProgressions3 limit = solve [1 .. limit]
multipleOf n = (== 0) . (`mod` n)
multipleOf3Or5 = uncurry (||) . ((multipleOf 3) /\ (multipleOf 5))
solve = sum . filter multipleOf3Or5
And solution4
is a completely in-lined version of the simplified formula in my question:
sumProgressions4 :: Integer -> Integer -> Integer -> Integer
sumProgressions4 d1 d2 lim = let d3 = d1 * d2
in d1 * (lim `div` d1) * (1 + (lim `div` d1)) `div` 2
+ d2 * (lim `div` d2) * (1 + (lim `div` d2)) `div` 2
- d3 * (lim `div` d3) * (1 + (lim `div` d3)) `div` 2
I'll leave the question open, but here are some other attempts. Credit goes to RMartinhoFernandes for solution3
, which requires his Pointfree module for the /\
combinator.
sumProgressions3 :: Integer -> Integer
sumProgressions3 limit = solve [1 .. limit]
multipleOf n = (== 0) . (`mod` n)
multipleOf3Or5 = uncurry (||) . ((multipleOf 3) /\ (multipleOf 5))
solve = sum . filter multipleOf3Or5
And solution4
is a completely in-lined version of the simplified formula in my question:
sumProgressions4 :: Integer -> Integer -> Integer -> Integer
sumProgressions4 d1 d2 lim = let d3 = d1 * d2
in d1 * (lim `div` d1) * (1 + (lim `div` d1)) `div` 2
+ d2 * (lim `div` d2) * (1 + (lim `div` d2)) `div` 2
- d3 * (lim `div` d3) * (1 + (lim `div` d3)) `div` 2
I've repeated the benchmarks on my machine with the same parameters as above.
Repeated benchmarks on my machine with the same parameters as above:
benchmarking solution1
mean: 496.9938 ns, lb 467.8051 ns, ub 532.6672 ns, ci 0.950
std dev: 166.0609 ns, lb 142.3465 ns, ub 185.5721 ns, ci 0.950
found 25 outliers among 100 samples (25.0%)
24 (24.0%) high severe
variance introduced by outliers: 97.866%
variance is severely inflated by outliers
benchmarking solution2
mean: 476.2878 ns, lb 455.9949 ns, ub 501.5564 ns, ci 0.950
std dev: 116.3743 ns, lb 95.50535 ns, ub 138.1666 ns, ci 0.950
found 11 outliers among 100 samples (11.0%)
11 (11.0%) high mild
variance introduced by outliers: 95.759%
variance is severely inflated by outliers
benchmarking solution3
mean: 496.9193 ns, lb 485.7492 ns, ub 510.2516 ns, ci 0.950
std dev: 61.94774 ns, lb 47.27249 ns, ub 81.16098 ns, ci 0.950
found 12 outliers among 100 samples (12.0%)
6 (6.0%) low severe
2 (2.0%) high mild
4 (4.0%) high severe
variance introduced by outliers: 86.239%
variance is severely inflated by outliers
benchmarking solution4
mean: 487.7629 ns, lb 457.9013 ns, ub 522.6022 ns, ci 0.950
std dev: 164.0337 ns, lb 143.6491 ns, ub 179.1870 ns, ci 0.950
variance introduced by outliers: 97.867%
variance is severely inflated by outliers
Repeated benchmarks on my machine with the same parameters as above:
benchmarking solution1
mean: 496.9938 ns, lb 467.8051 ns, ub 532.6672 ns, ci 0.950
std dev: 166.0609 ns, lb 142.3465 ns, ub 185.5721 ns, ci 0.950
found 25 outliers among 100 samples (25.0%)
24 (24.0%) high severe
variance introduced by outliers: 97.866%
variance is severely inflated by outliers
benchmarking solution2
mean: 476.2878 ns, lb 455.9949 ns, ub 501.5564 ns, ci 0.950
std dev: 116.3743 ns, lb 95.50535 ns, ub 138.1666 ns, ci 0.950
found 11 outliers among 100 samples (11.0%)
11 (11.0%) high mild
variance introduced by outliers: 95.759%
variance is severely inflated by outliers
benchmarking solution3
mean: 496.9193 ns, lb 485.7492 ns, ub 510.2516 ns, ci 0.950
std dev: 61.94774 ns, lb 47.27249 ns, ub 81.16098 ns, ci 0.950
found 12 outliers among 100 samples (12.0%)
6 (6.0%) low severe
2 (2.0%) high mild
4 (4.0%) high severe
variance introduced by outliers: 86.239%
variance is severely inflated by outliers
benchmarking solution4
mean: 487.7629 ns, lb 457.9013 ns, ub 522.6022 ns, ci 0.950
std dev: 164.0337 ns, lb 143.6491 ns, ub 179.1870 ns, ci 0.950
variance introduced by outliers: 97.867%
variance is severely inflated by outliers