Find the thirteen adjacent digits in the 1000-digit number n that have the greatest product and returns it. >>> solution("13978431290823798458352374") 609638400 >>> solution("13978431295823798458352374") 2612736000 >>> solution("1397843129582379841238352374") 209018
(n: str = N)
| 58 | |
| 59 | |
| 60 | def solution(n: str = N) -> int: |
| 61 | """ |
| 62 | Find the thirteen adjacent digits in the 1000-digit number n that have |
| 63 | the greatest product and returns it. |
| 64 | |
| 65 | >>> solution("13978431290823798458352374") |
| 66 | 609638400 |
| 67 | >>> solution("13978431295823798458352374") |
| 68 | 2612736000 |
| 69 | >>> solution("1397843129582379841238352374") |
| 70 | 209018880 |
| 71 | """ |
| 72 | |
| 73 | return max( |
| 74 | # mypy cannot properly interpret reduce |
| 75 | int(reduce(lambda x, y: str(int(x) * int(y)), n[i : i + 13])) |
| 76 | for i in range(len(n) - 12) |
| 77 | ) |
| 78 | |
| 79 | |
| 80 | if __name__ == "__main__": |