From 3ac82ee526a44b7d95f5c4e43c4c2d93b56dc553 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Thu, 10 Oct 2024 15:33:39 +0200 Subject: [PATCH] int_seq.hexagonal() --- src/tools/int_seq.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tools/int_seq.py b/src/tools/int_seq.py index 810a943..8db57da 100644 --- a/src/tools/int_seq.py +++ b/src/tools/int_seq.py @@ -38,3 +38,10 @@ def pentagonal(n: int) -> int: 0, 1, 5, 12, 22, 35, ... """ return ((3 * n * n) - n) // 2 + + +def hexagonal(n: int) -> int: + if n == 1: + return 1 + + return n * 2 + (n - 1) * 2 + (n - 2) * 2 + hexagonal(n - 1)