Given a "T" shape on an x * y number grid, with length W on the top bar and H on the stem of the T, with the bottom of the T on the square numbered n: calculate the total of all of the numbers in the T shape. W must be an odd number and all must be positive integers.
Here are some examples of valid T's on a 9*9 grid:
Looking at the T where
n=32, W=3 & H=4, you can see that the total is:
4 + 5 + 6 + 14 + 23 + 32 = 84.
Your challenge is to create a program which, when given five positive integers, x, y, W, H and n, output the total of the T with those values (W must be odd, given an even number the program can output anything or even crash). The numbers may be inputted in any reasonable format. If the T does not fit on the given grid, then any output is acceptable.
Example Code (Python 3.6.2)
x = int(input()) y = int(input()) W = int(input()) H = int(input()) n = int(input()) total = 0 #"Stem" of the T for i in range(H - 1): total += n - (x * i) #Decrease increment by length of row each time #Top of the T for i in range(-W//2 + 1, W//2 + 1): #Iterate over the width offset so that the center is zero total += (n - (x * (H - 1))) + i #Add the top squares on the T, one less to the left and one more to the right print(total)
As with most challenges here this is code-golf, so the answer with the shortest code in bytes wins.