In this kata, your task is to find the maximum sum of any straight "beam" on a hexagonal grid, where its cell values are determined by a finite integer sequence seq.
In this context, a beam is a linear sequence of cells in any of the 3 pairs of opposing sides of a hexagon. We'll refer to the sum of a beam's integer values as the "beam value".Refer to the example below for further clarification.
Input
Your function will receive two arguments:
n : the length of each side of the hexagonal grid, where 2 <= n < 100
seq : a finite sequence of (positive and/or nonpositive) integers with a length >= 1The sequence is used to populate the cells of the grid and should be repeated as necessary.The sequence type will be dependent on the language (e.g. array for JavaScript, tuple for Python, etc.).
Output
Your function should return the largest beam value as an integer.
Test Example
In our test example, we have the following arguments:
n = 4
seq = [2, 4, 6, 8]
Below is the hexagonal grid determined by our example arguments;
the sequence repeats itself from left to right, then top to bottom.
   2 4 6 8
  2 4 6 8 2
 4 6 8 2 4 6
8 2 4 6 8 2 4
 6 8 2 4 6 8
  2 4 6 8 2
   4 6 8 2
The three diagrams below illustrate the "beams" in the hexagonal grid above.
In the grid on the left, the horizontal beams are highlighted by their likewise colors,
and the value of each beam is given to its right.
In the center grid, the beams highlighted go from upper-right to bottom-left (and vice-versa).
In the grid on the right, the beams highlighted go from upper-left to bottom-right (and vice-versa).
   2 4 6 8 -> 20           2 4 6 8           2 4 6 8
  2 4 6 8 2 -> 22         2 4 6 8 2         2 4 6 8 2
 4 6 8 2 4 6 -> 30       4 6 8 2 4 6       4 6 8 2 4 6
8 2 4 6 8 2 4 -> 34     8 2 4 6 8 2 4     8 2 4 6 8 2 4
 6 8 2 4 6 8 -> 34       6 8 2 4 6 8       6 8 2 4 6 8
  2 4 6 8 2 -> 22         2 4 6 8 2         2 4 6 8 2
   4 6 8 2 -> 20           4 6 8 2           4 6 8 2
The maximum beam value in our example is 34.
Test Specifications
All inputs will be valid
Full Test Suite: 12 fixed tests and 100 random tests
For JavaScript, module and require are disabled [NOTE: if you would like to suggest a module that you think should be permitted for JS, please leave a note in the Discourse section]
If you enjoyed this kata, be sure to check out my other katas
from itertools import cycle

def max_hexagon_beam(n: int,seq: tuple):
    l=n*2-1                                  #the number of rows of the hexagon
    ll =[l-abs(n-i-1) for i in range(l)]     #the lengths of each row
    c=cycle(seq)
    hex = [[next(c) for i in range(j)] for j in ll]    # the hexagon
    sums = [sum(i)for i in hex] # the straight lines
    for index, i in enumerate(ll):
        start_row = [0, index%n + 1][index>=n]
        hex_row=[]
        hex_row2=[]
        for j in range(i):
            y=j+start_row #the y-axis or the row used
            x=index-[0, y%n + 1][y>=n] # the x-axis or the position in the row.
            hex_row.append(hex[y][x]) # the line going right-up
            hex_row2.append(hex[y][-1-x]) # the line going right-down
        sums +=[sum(hex_row), sum(hex_row2)]
    sums.sort()
    return sums[-1]
    
# I also considered extending the hexagon with edges of zeros so the x and y would have less possibility to go out of the list.
    
            

from itertools import cycle

def max_hexagon_beam(n: int,seq: tuple):
    l=n*2-1                                  #the number of rows of the hexagon
    ll =[l-abs(n-i-1) for i in range(l)]     #the lengths of each row
    c=cycle(seq)
    hex = [[next(c) for i in range(j)] for j in ll]    # the hexagon
    sums = [sum(i)for i in hex] # the straight lines
    for index, i in enumerate(ll):
        start_row = [0, index%n + 1][index>=n]
        hex_row=[]
        hex_row2=[]
        for j in range(i):
            y=j+start_row #the y-axis or the row used
            x=index-[0, y%n + 1][y>=n] # the x-axis or the position in the row.
            hex_row.append(hex[y][x]) # the line going right-up
            hex_row2.append(hex[y][-1-x]) # the line going right-down
        sums +=[sum(hex_row), sum(hex_row2)]
    sums.sort()
    return sums[-1]
    
# I also considered extending the hexagon with edges of zeros so the x and y would have less possibility to go out of the list.
    
            
