6 kyu

Counting hexagons

48 of 53vlukyanets

Description:

An equilateral triangle with integer side length n>=3 is divided into n^2 equilateral triangles with side length 1 as shown in the diagram below. The vertices of these triangles constitute a triangular lattice with (n+1)(n+2)/2 lattice points.

Base triangle for n=3: Example

Last regular hexagon for n=6:

Let H(n) be the number of all regular hexagons that can be found by connecting 6 of these points. For example, H(3)=1, H(6)=12 and H(20)=966.

Create function counting_hexagons that calculates H(n) where 3 <= n <= 40000.

Solution size should be less than 8KB.

Javascript: use BigInt

Adopted from projecteuler.net

Mathematics
Puzzles

Stats:

CreatedJul 11, 2021
PublishedJul 21, 2021
Warriors Trained362
Total Skips9
Total Code Submissions516
Total Times Completed53
Python Completions48
JavaScript Completions15
Total Stars19
% of votes with a positive feedback rating85% of 24
Total "Very Satisfied" Votes18
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes1
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • vlukyanets Avatar
  • dolamroth Avatar
Ad