123456789101112131415161718192021 |
- #!/usr/bin/ruby
- # Author: Daniel "Trizen" Șuteu
- # License: GPLv3
- # Website: https://github.com/trizen
- # It can be verified that T285 = P165 = H143 = 40755.
- # Find the next triangle number that is also pentagonal and hexagonal.
- # https://projecteuler.net/problem=45
- # Runtime: 0.793s
- for n in (144 .. Inf) {
- var h = n*(2*n - 1);
- if ((sqrt(1 + 24*h).inc %% 6) && (sqrt(1 + 8*h).dec %% 2)) {
- say h;
- break;
- }
- }
|