giulio98/xlcost-single-prompt huggingface dataset:
# generate all integral points lying inside a rectangle | python3 program to implement the above approach ; function to generate coordinates lying within the rectangle ; store all possible coordinates that lie within the rectangle ; stores the number of possible coordinates that lie within the rectangle ; generate all possible coordinates ; generate all possible x - coordinates ; generate all possible y - coordinates ; if coordinates ( x , y ) has not been generated already ; insert the coordinates ( x , y ) ; print the coordinates ; 

import time
import random
random .seed(time .time())


def generatePoints(L, W):
    hash = {}
    total = (L * W)
    for i in range(total):
        X = random .randint(0, L) % L
        Y = random .randint(0, W) % W
        while ((X, Y) in hash):
            X = random .randint(0, L) % L
            Y = random .randint(0, W) % W
        hash[(X, Y)] = 1
    for points in sorted(hash):
        print("(", points[0], ", ", points[1], ") ", end="")


if __name__ == '__main__':
    L, W = 3, 2
    generatePoints(L, W)

# Expected output:
( 0 ,  0 ) ( 0 ,  1 ) ( 1 ,  0 ) ( 1 ,  1 ) ( 2 ,  0 ) ( 2 ,  1 )
# count triangles required to form a house of cards of height n | function to find required number of triangles ; 
def noOfTriangles(n):
    return n * (n + 2) * (2 * n + 1) // 8


n = 3
print(noOfTriangles(n))

# Expected output:
13
# check if n contains all digits as k in base b | python3 program for the above approach ; function to print the number of digits ; calculate log using base change property and then take its floor and then add 1 ; return the output ; function that returns true if n contains all one 's in base b ; calculate the sum ; given number n ; given base b ; 

import math


def findNumberOfDigits(n, base):
    dig = (math .floor(math .log(n) / math .log(base)) + 1)
    return dig


def isAllKs(n, b, k):
    len = findNumberOfDigits(n, b)
    sum = k * (1 - pow(b, len)) / (1 - b)
    return sum == N


N = 13
B = 3
K = 1
if (isAllKs(N, B, K)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# check if a right | function to check if right - angled triangle can be formed by the given coordinates ; calculate the sides ; check pythagoras formula ; 
def checkRightAngled(X1, Y1, X2, Y2, X3, Y3):
    A = (int(pow((X2 - X1), 2)) + int(pow((Y2 - Y1), 2)))
    B = (int(pow((X3 - X2), 2)) + int(pow((Y3 - Y2), 2)))
    C = (int(pow((X3 - X1), 2)) + int(pow((Y3 - Y1), 2)))
    if ((A > 0 and B > 0 and C > 0) and (
            A == (B + C) or B == (A + C) or C == (A + B))):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    X1 = 0
    X2 = 0
    X3 = 9
    Y1 = 2
    Y2 = 14
    Y3 = 2
    checkRightAngled(X1, Y1, X2, Y2, X3, Y3)

# Expected output:
Yes
# count of rectangles possible from n and m straight lines parallel to x and y axis respectively | function to calculate number of rectangles ; total number of ways to select two lines parallel to x axis ; total number of ways to select two lines parallel to y axis ; total number of rectangles ; 
def count_rectangles(N, M):
    p_x = (N * (N - 1)) // 2
    p_y = (M * (M - 1)) // 2
    return p_x * p_y


N = 3
M = 6
print(count_rectangles(N, M))

# Expected output:
45
# angle between a pair of lines in 3d | python3 program for the above approach ; function to find the angle between the two lines ; find direction ratio of line ab ; find direction ratio of line bc ; find the dotproduct of lines ab & bc ; find magnitude of line ab and bc ; find the cosine of the angle formed by line ab and bc ; find angle in radian ; print angle ; 

import math


def calculateAngle(x1, y1, z1, x2, y2, z2, x3, y3, z3):
    ABx = x1 - x2
    ABy = y1 - y2
    ABz = z1 - z2
    BCx = x3 - x2
    BCy = y3 - y2
    BCz = z3 - z2
    dotProduct = (ABx * BCx + ABy * BCy + ABz * BCz)
    magnitudeAB = (ABx * ABx + ABy * ABy + ABz * ABz)
    magnitudeBC = (BCx * BCx + BCy * BCy + BCz * BCz)
    angle = dotProduct
    angle /= math .sqrt(magnitudeAB * magnitudeBC)
    angle = (angle * 180) / 3.14
    print(round(abs(angle), 4))


if __name__ == '__main__':
    x1, y1, z1 = 1, 3, 3
    x2, y2, z2 = 3, 4, 5
    x3, y3, z3 = 5, 6, 9
    calculateAngle(x1, y1, z1, x2, y2, z2, x3, y3, z3)

# Expected output:
54.6065
# pentadecagonal number | function to find n - th pentadecagonal number ; formula to calculate nth pentadecagonal number ; 
def Pentadecagonal_num(n):
    return (13 * n * n - 11 * n) / 2


n = 3
print(int(Pentadecagonal_num(n)))
n = 10
print(int(Pentadecagonal_num(n)))

# Expected output:
42
595
# octadecagonal number | function to find n - th octadecagonal number ; formula to calculate nth octadecagonal number ; 
def Octadecagonal_num(n):
    return (16 * n * n - 14 * n) / 2


n = 3
print(int(Octadecagonal_num(n)))
n = 10
print(int(Octadecagonal_num(n)))

# Expected output:
51
730
# icositrigonal number | function to find n - th icositrigonal number ; formula to calculate nth icositrigonal number ; 
def IcositrigonalNum(n):
    return (21 * n * n - 19 * n) / 2


n = 3
print(IcositrigonalNum(n))
n = 10
print(IcositrigonalNum(n))

# Expected output:
66.0
955.0
# find the percentage change in the area of a rectangle | function to calculate percentage change in area of rectangle ; 
def calculate_change(length, breadth):
    change = 0
    change = length + breadth + ((length * breadth) // 100)
    return change


if __name__ == "__main__":
    cL = 20
    cB = -10
    cA = calculate_change(cL, cB)
    print(cA)

# Expected output:
8
# minimum number of circular obstacles required to obstruct the path in a grid | function to find the minimum number of obstacles required ; find the minimum rangee required to put obstacles ; sorting the radius ; if val is less than zero then we have find the number of obstacles required ; 
def solve(n, m, obstacles, rangee):
    val = min(n, m)
    rangee = sorted(rangee)
    c = 1
    for i in range(obstacles - 1, -1, -1):
        rangee[i] = 2 * rangee[i]
        val -= rangee[i]
        if (val <= 0):
            return c
        else:
            c += 1
    if (val > 0):
        return -1


n = 4
m = 5
obstacles = 3
rangee = [1.0, 1.25, 1.15]
print(solve(n, m, obstacles, rangee))

# Expected output:
2
# program to calculate area of a rhombus whose one side and diagonal are given | function to calculate the area of the rhombus ; second diagonal ; area of rhombus ; return the area ; 
def area(d1, a):
    d2 = (4 * (a ** 2) - d1 ** 2)**0.5
    area = 0.5 * d1 * d2
    return (area)


d = 7.07
a = 5
print(area(d, a))

# Expected output:
24.999998859949972
# check whether two points ( x1 , y1 ) and ( x2 , y2 ) lie on same side of a given line or not | function to check if two points lie on the same side or not ; fx1 = 0 variable to store a * x1 + b * y1 - c fx2 = 0 variable to store a * x2 + b * y2 - c ; if fx1 and fx2 have same sign ; 
def pointsAreOnSameSideOfLine(a, b, c, x1, y1, x2, y2):
    fx1 = a * x1 + b * y1 - c
    fx2 = a * x2 + b * y2 - c
    if ((fx1 * fx2) > 0):
        return True
    return False


a, b, c = 1, 1, 1
x1, y1 = 1, 1
x2, y2 = 2, 1
if (pointsAreOnSameSideOfLine(a, b, c, x1, y1, x2, y2)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# percentage increase in volume of the cube if a side of cube is increased by a given percentage | python program to find percentage increase in the volume of the cube if a side of cube is increased by a given percentage ; 
def newvol(x):
    print("percentage increase" "in the volume of the cube is ",
          ((x ** (3)) / 10000 + 3 * x + (3 * (x ** (2))) / 100), "%")


x = 10
newvol(x)

# Expected output:
percentage increasein the volume of the cube is  33.1 %
# number of triangles formed by joining vertices of n | function to find the number of triangles ; print the number of triangles having two side common ; print the number of triangles having no side common ; 
def findTriangles(n):
    num = n
    print(num, end=" ")
    print(num * (num - 4) * (num - 5) // 6)


n = 6
findTriangles(n)

# Expected output:
6 2
# find the radii of the circles which are lined in a row , and distance between the centers of first and last circle is given | python program to find radii of the circles which are lined in a row and distance between the centers of first and last circle is given ; 
def radius(n, d):
    print("The radius of each circle is ", d / (2 * n - 2))


d = 42
n = 4
radius(n, d)

# Expected output:
The radius of each circle is  7.0
# find the side of the squares which are lined in a row , and distance between the centers of first and last square is given | python program to find side of the squares which are lined in a row and distance between the centers of first and last squares is given ; 
def radius(n, d):
    print("The side of each square is ", d / (n - 1))


d = 42
n = 4
radius(n, d)

# Expected output:
The side of each square is  14.0
# number of triangles formed by joining vertices of n | function to find the number of triangles ; print the number of triangles ;  ; 
def findTriangles(n):
    num = n * (n - 4)
    print(num)



n = 6
findTriangles(n)

# Expected output:
12
# Find the Diameter or Longest chord of a Circle | Function to find the longest chord ; Get the radius ; Find the diameter
def diameter(r):
    print("The length of the longest chord",
          " or diameter of the circle is ", 2 * r)


r = 4
diameter(r)

# Expected output:
The length of the longest chord  or diameter of the circle is  8
# slope of the line parallel to the line with the given slope | function to return the slope of the line which is parallel to the line with the given slope ; 
def getSlope(m):
    return m


m = 2
print(getSlope(m))

# Expected output:
2
# total number of triangles formed when there are h horizontal and v vertical lines | function to return total triangles ; only possible triangle is the given triangle ; if only vertical lines are present ; if only horizontal lines are present ; return total triangles ; 
def totalTriangles(h, v):
    if (h == 0 and v == 0):
        return 1
    if (h == 0):
        return ((v + 1) * (v + 2) / 2)
    if (v == 0):
        return (h + 1)
    total = (h + 1) * ((v + 1) * (v + 2) / 2)
    return total


h = 2
v = 2
print(int(totalTriangles(h, v)))

# Expected output:
18
# largest sphere that can be inscribed in a right circular cylinder inscribed in a frustum | python3 program to find the biggest sphere that can be inscribed within a right circular cylinder which in turn is inscribed within a frustum ; function to find the biggest sphere ; the radii and height cannot be negative ; radius of the sphere ; volume of the sphere ; 

import math as mt


def sph(r, R, h):
    if (r < 0 and R < 0 and h < 0):
        return -1
    x = r
    V = (4 * 3.14 * pow(r, 3)) / 3
    return V


r, R, h = 5, 8, 11
print(sph(r, R, h))

# Expected output:
523.3333333333334
# check whether two straight lines are orthogonal or not | function to check if two straight lines are orthogonal or not ; both lines have infinite slope ; only line 1 has infinite slope ; only line 2 has infinite slope ; find slopes of the lines ; check if their product is - 1 ; 
def checkOrtho(x1, y1, x2, y2, x3, y3, x4, y4):
    if (x2 - x1 == 0 and x4 - x3 == 0):
        return False
    elif (x2 - x1 == 0):
        m2 = (y4 - y3) / (x4 - x3)
        if (m2 == 0):
            return True
        else:
            return False
    elif (x4 - x3 == 0):
        m1 = (y2 - y1) / (x2 - x1)
        if (m1 == 0):
            return True
        else:
            return False
    else:
        m1 = (y2 - y1) / (x2 - x1)
        m2 = (y4 - y3) / (x4 - x3)
        if (m1 * m2 == -1):
            return True
        else:
            return False


if __name__ == '__main__':
    x1 = 0
    y1 = 4
    x2 = 0
    y2 = -9
    x3 = 2
    y3 = 0
    x4 = -1
    y4 = 0
    if (checkOrtho(x1, y1, x2, y2, x3, y3, x4, y4)):
        print("Yes")
    else:
        print("No")

# Expected output:
Yes
# diagonal of a regular pentagon | function to find the diagonal of a regular pentagon ; side cannot be negative ; length of the diagonal ; 
def pentdiagonal(a):
    if (a < 0):
        return -1
    d = 1.22 * a
    return d


if __name__ == "__main__":
    a = 6
    print(pentdiagonal(a))

# Expected output:
7.32
# area of hexagon with given diagonal length | python3 program to find the area of hexagon with given diagonal ; function to calculate area ; formula to find area ; 

from math import sqrt


def hexagonArea(d):
    return (3 * sqrt(3) * pow(d, 2)) / 8


if __name__ == "__main__":
    d = 10
    print("Area of hexagon:", round(hexagonArea(d), 3))

# Expected output:
Area of hexagon: 64.952
# number of squares of side length required to cover an n * m rectangle | function to find number of squares of a * a required to cover n * m rectangle ; 
def Squares(n, m, a):
    return (((m + a - 1) // a) * ((n + a - 1) // a))


if __name__ == "__main__":
    n = 6
    m = 6
    a = 4
    print(Squares(n, m, a))

# Expected output:
4
# length of the diagonal of the octagon | python3 program to find the diagonal of the octagon ; function to find the diagonal of the octagon ; side cannot be negative ; diagonal of the octagon ; 

import math


def octadiagonal(a):
    if (a < 0):
        return -1
    return a * math .sqrt(4 + (2 * math .sqrt(2)))


if __name__ == '__main__':
    a = 4
    print(octadiagonal(a))

# Expected output:
10.452503719011013
# program to calculate the perimeter of a decagon | function for finding the perimeter ; 
def CalPeri():
    s = 5
    Perimeter = 10 * s
    print("The Perimeter of Decagon is : ", Perimeter)


if __name__ == '__main__':
    CalPeri()

# Expected output:
The Perimeter of Decagon is :  50
# sum of lengths of all 12 edges of any rectangular parallelepiped | python3 program to illustrate the above problem ; function to find the sum of all the edges of parallelepiped ; to calculate the length of one edge ; sum of all the edges of one side ; net sum will be equal to the summation of edges of all the sides ; 

import math


def findEdges(s1, s2, s3):
    a = math .sqrt(s1 * s2 / s3)
    b = math .sqrt(s3 * s1 / s2)
    c = math .sqrt(s3 * s2 / s1)
    sum = a + b + c
    return 4 * sum


if __name__ == '__main__':
    s1 = 65
    s2 = 156
    s3 = 60
    print(int(findEdges(s1, s2, s3)))

# Expected output:
120
# maximum number of pieces in n cuts | function for finding maximum pieces with n cuts . ; to maximize number of pieces x is the horizontal cuts ; now ( x ) is the horizontal cuts and ( n - x ) is vertical cuts , then maximum number of pieces = ( x + 1 ) * ( n - x + 1 ) ; 
def findMaximumPieces(n):
    x = n // 2
    return ((x + 1) * (n - x + 1))


if __name__ == "__main__":
    n = 3
    print("Max number of pieces for n = " +
          str(n) + " is " + str(findMaximumPieces(3)))

# Expected output:
Max number of pieces for n = 3 is 6
# program to check whether 4 points in a 3 | function to find equation of plane . ; checking if the 4 th point satisfies the above equation ; 
def equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3, x, y, z):
    a1 = x2 - x1
    b1 = y2 - y1
    c1 = z2 - z1
    a2 = x3 - x1
    b2 = y3 - y1
    c2 = z3 - z1
    a = b1 * c2 - b2 * c1
    b = a2 * c1 - a1 * c2
    c = a1 * b2 - b1 * a2
    d = (-a * x1 - b * y1 - c * z1)
    if (a * x + b * y + c * z + d == 0):
        print("Coplanar")
    else:
        print("Not Coplanar")


x1 = 3
y1 = 2
z1 = -5
x2 = -1
y2 = 4
z2 = -3
x3 = -3
y3 = 8
z3 = -5
x4 = -3
y4 = 2
z4 = 1
equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)

# Expected output:
Coplanar
# angle between two planes in 3d | python program to find the angle between two planes in 3 d . ; function to find angle ; 

import math


def distance(a1, b1, c1, a2, b2, c2):
    d = (a1 * a2 + b1 * b2 + c1 * c2)
    e1 = math .sqrt(a1 * a1 + b1 * b1 + c1 * c1)
    e2 = math .sqrt(a2 * a2 + b2 * b2 + c2 * c2)
    d = d / (e1 * e2)
    A = math .degrees(math .acos(d))
    print("Angle is"), A, ("degree")


a1 = 1
b1 = 1
c1 = 2
d1 = 1
a2 = 2
b2 = -1
c2 = 1
d2 = -4
distance(a1, b1, c1, a2, b2, c2)

# Expected output:
Angle is
# mirror of a point through a 3 d plane | function to mirror image ; 
def mirror_point(a, b, c, d, x1, y1, z1):
    k = (-a * x1 - b * y1 - c * z1 - d) / float((a * a + b * b + c * c))
    x2 = a * k + x1
    y2 = b * k + y1
    z2 = c * k + z1
    x3 = 2 * x2 - x1
    y3 = 2 * y2 - y1
    z3 = 2 * z2 - z1
    print("x3 =", x3)
    print("y3 =", y3)
    print("z3 =", z3)


a = 1
b = -2
c = 0
d = 0
x1 = -1
y1 = 3
z1 = 4
mirror_point(a, b, c, d, x1, y1, z1)

# Expected output:
x3 = 1.7999999999999998
y3 = -2.5999999999999996
z3 = 4.0
# Number of rectangles in a circle of radius R | Function to return the total possible rectangles that can be cut from the circle ; Diameter = 2 * Radius ; Square of diameter which is the square of the maximum length diagonal ; generate all combinations of a and b in the range ( 1 , ( 2 * Radius - 1 ) ) ( Both inclusive ) ; Calculate the Diagonal length of this rectangle ; If this rectangle 's Diagonal  Length is less than the  Diameter, it is a valid  rectangle, thus increment counter ; Radius of the circle
def countRectangles(radius):
    rectangles = 0
    diameter = 2 * radius
    diameterSquare = diameter * diameter
    for a in range(1, 2 * radius):
        for b in range(1, 2 * radius):
            diagonalLengthSquare = (a * a + b * b)
            if (diagonalLengthSquare <= diameterSquare):
                rectangles += 1
    return rectangles


radius = 2
totalRectangles = countRectangles(radius)
print(totalRectangles, "rectangles can be",
      "cut from a circle of Radius", radius)

# Expected output:
8 rectangles can be cut from a circle of Radius 2
# centered pentadecagonal number | centered pentadecagonal function ; formula to calculate nth centered pentadecagonal number ; 
def center_pentadecagonal_num(n):
    return (15 * n * n - 15 * n + 2) // 2


if __name__ == '__main__':
    n = 3
    print(n, "rd number : ", center_pentadecagonal_num(n))
    n = 10
    print(n, "th number : ", center_pentadecagonal_num(n))

# Expected output:
3 rd number :  46
10 th number :  676
# centered nonadecagonal number | centered nonadecagonal function ; formula to calculate nth centered nonadecagonal number & return it into main function . ; 
def center_nonadecagon_num(n):
    return (19 * n * n - 19 * n + 2) // 2


if __name__ == '__main__':
    n = 2
    print(n, "nd centered nonadecagonal " +
          "number : ", center_nonadecagon_num(n))
    n = 7
    print(n, "nd centered nonadecagonal " +
          "number : ", center_nonadecagon_num(n))

# Expected output:
2 nd centered nonadecagonal number :  20
7 nd centered nonadecagonal number :  400
# hendecagonal number | function of hendecagonal number ; formula to calculate nth hendecagonal number & return it into main function . ; 
def hendecagonal_num(n):
    return (9 * n * n - 7 * n) // 2


if __name__ == '__main__':
    n = 3
    print(n, "rd Hendecagonal number : ", hendecagonal_num(n))
    n = 10
    print(n, "th Hendecagonal number : ", hendecagonal_num(n))

# Expected output:
3 rd Hendecagonal number :  30
10 th Hendecagonal number :  415
# centered octagonal number | function to find centered octagonal number ; formula to calculate nth centered octagonal number ; 
def cen_octagonalnum(n):
    return (4 * n * n - 4 * n + 1)


if __name__ == '__main__':
    n = 6
    print(n, "th Centered", "octagonal number: ", cen_octagonalnum(n))
    n = 11
    print(n, "th Centered", "octagonal number: ", cen_octagonalnum(n))

# Expected output:
6 th Centered octagonal number:  121
11 th Centered octagonal number:  441
# number of ordered points pair satisfying line equation | checks if ( i , j ) is valid , a point ( i , j ) is valid if point ( arr [ i ] , arr [ j ] ) satisfies the equation y = mx + c and i is not equal to j ; check if i equals to j ; equation lhs = y , and rhs = mx + c ; returns the number of ordered pairs ( i , j ) for which point ( arr [ i ] , arr [ j ] ) satisfies the equation of the line y = mx + c ; for every possible ( i , j ) check if ( a [ i ] , a [ j ] ) satisfies the equation y = mx + c ; ( firstindex , secondindex ) is same as ( i , j ) ; check if ( firstindex , secondindex ) is a valid point ; 
def isValid(arr, i, j, m, c):
    if (i == j):
        return False
    lhs = arr[j]
    rhs = m * arr[i] + c
    return (lhs == rhs)


def findOrderedPoints(arr, n, m, c):
    counter = 0
    for i in range(0, n):
        for j in range(0, n):
            firstIndex = i
            secondIndex = j
            if (isValid(arr, firstIndex, secondIndex, m, c)):
                counter = counter + 1
    return counter


arr = [1, 2, 3, 4, 2]
n = len(arr)
m = 1
c = 1
print(findOrderedPoints(arr, n, m, c))

# Expected output:
5
# check if a 

import math


def checkcircle(r, R, r1, x1, y1):
    dis = int(math .sqrt(x1 * x1 + y1 * y1))
    return (dis - r1 >= R and dis + r1 <= r)


r = 8
R = 4
r1 = 2
x1 = 6
y1 = 0
if (checkcircle(r, R, r1, x1, y1)):
    print("yes")
else:
    print("no")

# Expected output:
yes
# program for surface area of octahedron | python program to calculate surface area of octahedron . ; utility function ; 

import math


def surface_area_octahedron(side):
    return (2 * (math .sqrt(3)) * (side * side))


side = 7
print("Surface area of octahedron =", surface_area_octahedron(side))

# Expected output:
Surface area of octahedron = 169.74097914174996
# count of different straight lines with total n points with m collinear | returns value of binomial coefficient code taken from https : goo . gl / vhy4jp ; c [ 0 ] = 1 nc0 is 1 ; compute next row of pascal triangle using the previous row ; function to calculate number of straight lines can be formed ; 
def nCk(n, k):
    C = [0] * (k + 1)
    for i in range(1, n + 1):
        j = min(i, k)
        while (j > 0):
            C[j] = C[j] + C[j - 1]
            j = j - 1
    return C[k]


def count_Straightlines(n, m):
    return (nCk(n, 2) - nCk(m, 2) + 1)


n = 4
m = 3
print(count_Straightlines(n, m))

# Expected output:
1
# calculate volume of dodecahedron | python3 program to calculate volume of dodecahedron ; utility function ; 

import math


def vol_of_dodecahedron(side):
    return (((15 + (7 * (math .sqrt(5)))) / 4) * (math .pow(side, 3)))


side = 4
print("Volume of dodecahedron =", round(vol_of_dodecahedron(side), 2))

# Expected output:
Volume of dodecahedron = 490.44
# program to check if water tank overflows when n solid balls are dipped in the water tank | function to find if tak will overflow or not ; cylinder capacity ; volume of water in tank ; volume of n balls ; total volume of water and n dipped balls ; condition to check if tank is in overflow state or not ; giving dimensions ; 
def overflow(H, r, h, N, R):
    tank_cap = 3.14 * r * r * H
    water_vol = 3.14 * r * r * h
    balls_vol = N * (4 / 3) * 3.14 * R * R * R
    vol = water_vol + balls_vol
    if vol > tank_cap:
        print("Overflow")
    else:
        print("Not in overflow state")


H = 10
r = 5
h = 5
N = 2
R = 2
overflow(H, r, h, N, R)

# Expected output:
Not in overflow state
# program to find third side of triangle using law of cosines | python3 program to find third side of triangle using law of cosines ; function to calculate cos value of angle c ; converting degrees to radian ; maps the sum along the series ; holds the actual value of sin ( n ) ; function to find third side ; 

import math as mt


def cal_cos(n):
    accuracy = 0.0001
    x1, denominator, cosx, cosval = 0, 0, 0, 0
    n = n * (3.142 / 180.0)
    x1 = 1
    cosx = x1
    cosval = mt .cos(n)
    i = 1
    while (accuracy <= abs(cosval - cosx)):
        denominator = 2 * i * (2 * i - 1)
        x1 = -x1 * n * n / denominator
        cosx = cosx + x1
        i = i + 1
    return cosx


def third_side(a, b, c):
    angle = cal_cos(c)
    return mt .sqrt((a * a) + (b * b) - 2 * a * b * angle)


c = 49
a, b = 5, 8
print(third_side(a, b, c))

# Expected output:
6.043387862121523